From ad9f3631663876fb3a83d6080f19a02a3d769d55 Mon Sep 17 00:00:00 2001 From: arteons Date: Mon, 7 Jul 2025 03:57:20 +0800 Subject: [PATCH] rev timesheet & project --- src/lib/CurrencyInput.svelte | 32 ++++ src/routes/backoffice/issue/+page.svelte | 175 +++++++----------- .../backoffice/purchaseorder/+page.svelte | 70 ++++--- 3 files changed, 147 insertions(+), 130 deletions(-) create mode 100644 src/lib/CurrencyInput.svelte diff --git a/src/lib/CurrencyInput.svelte b/src/lib/CurrencyInput.svelte new file mode 100644 index 0000000..69437cf --- /dev/null +++ b/src/lib/CurrencyInput.svelte @@ -0,0 +1,32 @@ + + + + + \ No newline at end of file diff --git a/src/routes/backoffice/issue/+page.svelte b/src/routes/backoffice/issue/+page.svelte index 4f88317..c9146e8 100644 --- a/src/routes/backoffice/issue/+page.svelte +++ b/src/routes/backoffice/issue/+page.svelte @@ -2,6 +2,7 @@ import { supabase } from "$lib/supabaseClient"; import { onMount } from "svelte"; import { writable } from "svelte/store"; + import Pagination from "$lib/Pagination.svelte"; const priority = [ { label: "Low", value: "Low" }, @@ -137,8 +138,9 @@ { label: "Water Feature", value: "Water Feature" } ]; const columns: columns[] = [ - { key: "description_of_the_issue", title: "Description of The Issue" }, + { key: "issue_number", title: "Issue Number" }, + { key: "description_of_the_issue", title: "Description of The Issue" }, { key: "villa_name", title: "Villa Name" }, { key: "villa_id", title: "Villa ID" }, { key: "input_by", title: "Input By" }, @@ -253,7 +255,7 @@ }; // Reactive variables - let currentVillaFilter: string | null = null; + let currentVillaFilter: string | null = ""; let currentSearchTerm: string | null = null; let showProjectModal = false; let selectedIssueId: string | null = null; @@ -295,8 +297,31 @@ let totalItems = 0; let currentPage = offset + 1; let rowsPerPage = limit; - $: totalPages = Math.ceil(totalItems / rowsPerPage); + let filteredRows: Issue[] = []; + $: paginatedRows = filteredRows.slice( + (currentPage - 1) * rowsPerPage, + currentPage * rowsPerPage + ); + $: totalItems = filteredRows.length; + $: totalPages = Math.ceil(totalItems / rowsPerPage); + $: { + let rows = allRows; + + if (currentVillaFilter) { + rows = rows.filter(r => r.villa_id === currentVillaFilter); + } + + if (currentSearchTerm && currentSearchTerm.trim() !== "") { + const term = currentSearchTerm.toLowerCase(); + rows = rows.filter(r => + (r.description_of_the_issue || "").toLowerCase().includes(term) + ); + } + + filteredRows = rows; + currentPage = 1; // Optional: reset page when filter/search changes + } // Fetch existing project links and purchase orders async function fetchExistingProjectLinks() { const { data, error } = await supabase @@ -319,49 +344,21 @@ if (data) poItems = data; } // Fetch issues with optional filters - async function fetchIssues( - search: string | null = null, - villaNameFilter: string | null = null, - sort: string | null = "created_at", - order: "asc" | "desc" = "desc", - offset: number = 0, - limit: number = 10, - ) { + async function fetchIssues() { let query = supabase .from("vb_issues_data") - .select("*", { count: "exact" }) - .order(sort || "created_at", { ascending: order === "asc" }) - .range(offset, offset + limit - 1); + .select("*").order("issue_number", { ascending: true }); - if (villaNameFilter) { - const villa = dataVilla.find(v => v.villa_name === villaNameFilter); - if (villa) { - query = query.eq("villa_id", villa.id); - } - } + const { data: issues, error } = await query; - if (search) { - query = query.ilike("description_of_the_issue", `%${search}%`); - } - - const { data: issues, error, count } = await query; if (error) { - console.error("Error fetching issues:", error); + console.error(error); return; } - if (count !== undefined) { - totalItems = count ?? 0; - } - - if (!issues || issues.length === 0) { - allRows = []; - return; - } - - // Gabungkan data villa ke dalam setiap issue - allRows = issues; + allRows = issues || []; } + // Function to handle form submission and save issue async function saveIssue(event: Event) { const session = await supabase.auth.getSession(); @@ -610,8 +607,6 @@ requested_by: "", requested_date: formatDate(today), po_due: formatDate(dueDate), - po_item: "", - po_quantity: "", po_type: "" }; @@ -748,39 +743,24 @@ id="issue-search" placeholder="🔍 Search by Issue..." class="border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none px-4 py-2 rounded-xl text-sm w-64 transition" - on:input={(e) => { - currentSearchTerm = (e.target as HTMLInputElement).value.toLowerCase(); - fetchIssues( currentSearchTerm, currentVillaFilter); - }} + bind:value={currentSearchTerm} + /> - {#each Array(totalPages) - .fill(0) - .map((_, i) => i + 1) as page} - - {/each} - + + +
+ + + +
@@ -1486,21 +1458,6 @@ - - - -