From 3603dcf47242fb04064cc6a723011c8629b1940f Mon Sep 17 00:00:00 2001 From: arteons Date: Wed, 18 Jun 2025 16:30:39 +0800 Subject: [PATCH] timesheet approval --- src/routes/backoffice/timesheets/+page.svelte | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/routes/backoffice/timesheets/+page.svelte b/src/routes/backoffice/timesheets/+page.svelte index f2dbf1d..fdf25f2 100644 --- a/src/routes/backoffice/timesheets/+page.svelte +++ b/src/routes/backoffice/timesheets/+page.svelte @@ -191,6 +191,14 @@ return; } + const { data: approvers, error: approverError } = await supabase + .from("vb_users") // or vb_employee if you store them there + .select("id, full_name"); + + if (approverError) { + console.error("Error fetching approvers:", approverError); + } + let reportedBy: { label: string; value: string }[] = []; const { data: staffData, error: staffError } = await supabase .from("vb_employee") @@ -209,7 +217,8 @@ const villa = villas.find((v) => v.id === issue.villa_id); // Map entered_by to staff_id const staff = reportedBy.find((s) => s.value === issue.entered_by); - + const approver = approvers?.find(u => u.id === issue.approved_by); + return { id: issue.id, name: issue.work_description, // Map work_description to name @@ -231,6 +240,8 @@ new Date(issue.datetime_in).getTime(), ) / (1000 * 60 * 60), // Convert milliseconds to hours + approved_by: approver?.full_name ?? "Not Approved", + approved_date: issue.approved_date, remarks: issue.remarks, created_at: issue.created_at ? new Date(issue.created_at) @@ -271,7 +282,18 @@ if (issue) { isEditing = true; currentEditingId = issue.id; - newIssue = { ...issue }; + + newIssue = { + work_description: issue.name, + entered_by: issue.entered_by || "", // you may need to store the UUID if not already + type_of_work: issue.type_of_work, + category_of_work: issue.category_of_work, + villa_id: dataVilla.find(v => v.villa_name === issue.villa_name)?.id || "", + date_in: issue.date_in?.toISOString().slice(0, 16), // for datetime-local + date_out: issue.date_out?.toISOString().slice(0, 16), + remarks: issue.remarks, + total_work_hour: issue.total_hours_work, + }; } else { isEditing = false; currentEditingId = null; @@ -280,6 +302,7 @@ showModal = true; } + async function saveIssue(event: Event) { event.preventDefault();