add relasi villa dan employee ke timesheet
This commit is contained in:
@@ -90,17 +90,28 @@
|
|||||||
{ label: "Guest", value: "Guest" },
|
{ label: "Guest", value: "Guest" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
let currentUserId: string | null = null;
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const {
|
||||||
|
data: { user },
|
||||||
|
} = await supabase.auth.getUser();
|
||||||
|
|
||||||
|
currentUserId = user?.id ?? null;
|
||||||
|
});
|
||||||
|
|
||||||
type Villa = {
|
type Villa = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
villa_name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
let dataVilla: Villa[] = [];
|
let dataVilla: Villa[] = [];
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from("villas")
|
.from("vb_villas")
|
||||||
.select("id, name");
|
.select("id, villa_name");
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Error fetching villas:", error);
|
console.error("Error fetching villas:", error);
|
||||||
@@ -172,7 +183,7 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
const { data: villas, error: villaError } = await supabase
|
const { data: villas, error: villaError } = await supabase
|
||||||
.from("villas")
|
.from("vb_villas")
|
||||||
.select("*")
|
.select("*")
|
||||||
.in("id", villaIds);
|
.in("id", villaIds);
|
||||||
|
|
||||||
@@ -208,15 +219,15 @@
|
|||||||
date_out: new Date(issue.datetime_out),
|
date_out: new Date(issue.datetime_out),
|
||||||
type_of_work: issue.type_of_work,
|
type_of_work: issue.type_of_work,
|
||||||
category_of_work: issue.category_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:
|
approval:
|
||||||
issue.approval == null
|
issue.approval == null
|
||||||
? "PENDING"
|
? "PENDING"
|
||||||
: issue.approval
|
: issue.approval
|
||||||
? "APPROVED"
|
? "APPROVED"
|
||||||
: "REJECTED", // or map as needed
|
: "REJECTED", // or map as needed
|
||||||
approved_by: undefined, // Set as needed
|
approved_by: issue.approved_by ?? null,
|
||||||
approved_date: undefined, // Set as needed
|
approved_date: issue.approved_date ? new Date(issue.approved_date) : null,
|
||||||
total_hours_work:
|
total_hours_work:
|
||||||
Math.abs(
|
Math.abs(
|
||||||
new Date(issue.datetime_out).getTime() -
|
new Date(issue.datetime_out).getTime() -
|
||||||
@@ -379,9 +390,16 @@
|
|||||||
id: string,
|
id: string,
|
||||||
status: string,
|
status: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const approved = status === "true";
|
||||||
|
const approved_by = currentUserId;
|
||||||
|
const approved_date = new Date().toISOString();
|
||||||
const { error } = await supabase
|
const { error } = await supabase
|
||||||
.from("vb_timesheet")
|
.from("vb_timesheet")
|
||||||
.update({ approval: status })
|
.update({
|
||||||
|
approval: status ,
|
||||||
|
approved_by,
|
||||||
|
approved_date,
|
||||||
|
})
|
||||||
.eq("id", id);
|
.eq("id", id);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -703,7 +721,7 @@
|
|||||||
>Select Villa</option
|
>Select Villa</option
|
||||||
>
|
>
|
||||||
{#each dataVilla as villa}
|
{#each dataVilla as villa}
|
||||||
<option value={villa.id}>{villa.name}</option>
|
<option value={villa.id}>{villa.villa_name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
{#if $formErrors[col.key]}
|
{#if $formErrors[col.key]}
|
||||||
|
|||||||
Reference in New Issue
Block a user