diff --git a/src/routes/backoffice/timesheets/+page.svelte b/src/routes/backoffice/timesheets/+page.svelte index 56412ab..0a5a9a8 100644 --- a/src/routes/backoffice/timesheets/+page.svelte +++ b/src/routes/backoffice/timesheets/+page.svelte @@ -90,17 +90,28 @@ { label: "Guest", value: "Guest" }, ]; + + let currentUserId: string | null = null; + + onMount(async () => { + const { + data: { user }, + } = await supabase.auth.getUser(); + + currentUserId = user?.id ?? null; + }); + type Villa = { id: string; - name: string; + villa_name: string; }; let dataVilla: Villa[] = []; onMount(async () => { const { data, error } = await supabase - .from("villas") - .select("id, name"); + .from("vb_villas") + .select("id, villa_name"); if (error) { console.error("Error fetching villas:", error); @@ -172,7 +183,7 @@ ]; const { data: villas, error: villaError } = await supabase - .from("villas") + .from("vb_villas") .select("*") .in("id", villaIds); @@ -208,15 +219,15 @@ date_out: new Date(issue.datetime_out), type_of_work: issue.type_of_work, category_of_work: issue.category_of_work, - villa_name: villa ? villa.name : "Unknown Villa", + villa_name: villa ? villa.villa_name : "Unknown Villa", approval: issue.approval == null ? "PENDING" : issue.approval ? "APPROVED" : "REJECTED", // or map as needed - approved_by: undefined, // Set as needed - approved_date: undefined, // Set as needed + approved_by: issue.approved_by ?? null, + approved_date: issue.approved_date ? new Date(issue.approved_date) : null, total_hours_work: Math.abs( new Date(issue.datetime_out).getTime() - @@ -379,9 +390,16 @@ id: string, status: string, ): Promise { + const approved = status === "true"; + const approved_by = currentUserId; + const approved_date = new Date().toISOString(); const { error } = await supabase .from("vb_timesheet") - .update({ approval: status }) + .update({ + approval: status , + approved_by, + approved_date, + }) .eq("id", id); if (error) { @@ -703,7 +721,7 @@ >Select Villa {#each dataVilla as villa} - + {/each} {#if $formErrors[col.key]}