timesheet approval

This commit is contained in:
2025-06-18 16:30:39 +08:00
parent 039c7914a0
commit 3603dcf472

View File

@@ -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();