perbaikan data

This commit is contained in:
aji@catalis.app
2025-07-12 09:24:22 +07:00
parent 8657680261
commit 2e4e583029
3 changed files with 85 additions and 326 deletions

View File

@@ -7,7 +7,7 @@
| "vb_issues"
| "vb_villas"
| "vb_timesheet"
| "vb_inventories"
| "vb_inventory"
| "vb_projects"
| "vb_vendors"
| "vb_employee"
@@ -20,7 +20,7 @@
vb_issues: 0,
vb_villas: 0,
vb_timesheet: 0,
vb_inventories: 0,
vb_inventory: 0,
vb_projects: 0,
vb_vendors: 0,
vb_employee: 0,
@@ -67,7 +67,7 @@
},
{
label: "Total Inventories",
key: "vb_inventories",
key: "vb_inventory",
color: "text-yellow-600",
icon: "cube",
},

View File

@@ -143,13 +143,26 @@
unit_price: 0,
description: "",
};
let selectedYear: number | null = new Date().getFullYear(); // Current year
let selectedYear: number | null = null;
$: if (selectedYear) {
fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
offset,
limit,
);
}
export let data;
async function fetchInventory(
searchTerm: string | null = "",
searchedVillaId: string | null = null,
year: number | null = null,
sortBy = "created_at",
sortOrder = "desc",
offset = 0,
@@ -169,6 +182,10 @@
query = query.eq("villa_id", searchedVillaId);
}
if (year) {
query = query.or(`year.eq.${year},year.eq.0`);
}
const { data, error, count } = await query;
if (error) {
@@ -257,7 +274,15 @@
}
onMount(async () => {
await fetchInventory();
await fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
offset,
limit,
);
// Fetch villa names for dropdown
const { data: villaData, error: villaError } = await supabase
@@ -309,7 +334,15 @@
} else {
alert("Item updated successfully!");
showModal = false;
await fetchInventory();
await fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
offset,
limit,
);
}
} else {
// Insert new item
@@ -324,7 +357,15 @@
} else {
alert("New item added successfully!");
showModal = false;
await fetchInventory();
await fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
offset,
limit,
);
}
}
}
@@ -335,6 +376,8 @@
fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
(currentPage - 1) * rowsPerPage,
@@ -375,6 +418,8 @@
fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
(currentPage - 1) * rowsPerPage,
@@ -408,7 +453,15 @@
const searchTerm = (
e.target as HTMLInputElement
).value.toLowerCase();
fetchInventory(null, "created_at", "desc", 0, 10);
fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
offset,
limit,
);
}}
/>
<!-- dropdown villa -->
@@ -419,14 +472,15 @@
fetchInventory(
searchTerm,
selectedVillaId,
"created_at",
"desc",
selectedYear,
sortBy,
sortOrder,
offset,
limit,
);
}}
>
<option value="" disabled selected>Select Villa</option>
<option value="" selected>All Villa</option>
{#each villaItems as villa}
<option value={villa.id}>{villa.villa_name}</option>
{/each}
@@ -444,7 +498,15 @@
<button
class="bg-gray-200 text-gray-700 px-4 py-2 rounded-xl hover:bg-gray-300 text-sm transition"
on:click={() =>
fetchInventory(null, "created_at", "desc", 0, 10)}
fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
offset,
limit,
)}
>
🔄 Reset
</button>
@@ -566,7 +628,15 @@
alert(
"Item deleted successfully!",
);
await fetchInventory();
await fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
offset,
limit,
);
}
}}
>
@@ -609,9 +679,10 @@
fetchInventory(
searchTerm,
selectedVillaId,
selectedYear,
sortBy,
sortOrder,
0,
(currentPage - 1) * rowsPerPage,
rowsPerPage,
);
}}