perbaikan data
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import Select from "svelte-select";
|
||||
import { supabase } from "$lib/supabaseClient";
|
||||
import { timestampToDateTime } from "$lib/utils/conversion";
|
||||
import { getSessionAuthId } from "$lib/utils/authUtil";
|
||||
|
||||
type PurchaseOrderInsert = {
|
||||
issue_id: string;
|
||||
@@ -11,6 +12,9 @@
|
||||
po_quantity: number;
|
||||
po_price: number;
|
||||
po_total_price: number;
|
||||
input_by: string;
|
||||
updated_by: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
let purchaseOrderInsert: PurchaseOrderInsert = {
|
||||
@@ -20,6 +24,9 @@
|
||||
po_quantity: 0,
|
||||
po_price: 0,
|
||||
po_total_price: 0,
|
||||
input_by: "",
|
||||
updated_by: "",
|
||||
updated_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
type PurchaseOrders = {
|
||||
@@ -72,6 +79,11 @@
|
||||
received: boolean;
|
||||
received_by: string;
|
||||
created_at: string;
|
||||
updated_at?: string;
|
||||
updated_by?: string;
|
||||
updated_name?: string;
|
||||
input_by?: string;
|
||||
input_name?: string;
|
||||
};
|
||||
|
||||
let allRows: PurchaseOrderDisplay[] = [];
|
||||
@@ -95,8 +107,8 @@
|
||||
{ key: "proses_to_approval", title: "PROSES TO APPROVAL" },
|
||||
{ key: "approved_vendor", title: "Approved Vendor" },
|
||||
{ key: "acknowledged", title: "Acknowledged" },
|
||||
{ key: "acknowledge_by", title: "Acknowledged By" },
|
||||
{ key: "approved_by", title: "Approved By" },
|
||||
{ key: "acknowledged_name", title: "Acknowledged By" },
|
||||
{ key: "approved_name", title: "Approved By" },
|
||||
{ key: "approved_price", title: "Approved Price" },
|
||||
{ key: "approved_quantity", title: "Approved Quantity" },
|
||||
{
|
||||
@@ -106,7 +118,10 @@
|
||||
{ key: "approval", title: "Approval" },
|
||||
{ key: "completed_status", title: "Completed Status" },
|
||||
{ key: "received", title: "Received" },
|
||||
{ key: "received_by", title: "Received By" },
|
||||
{ key: "received_name", title: "Received By" },
|
||||
{ key: "inputed_name", title: "Input By" },
|
||||
{ key: "updated_name", title: "Updated By" },
|
||||
{ key: "updated_at", title: "Updated At" },
|
||||
{ key: "created_at", title: "Created At" },
|
||||
{ key: "actions", title: "Actions" }, // For edit/delete buttons
|
||||
];
|
||||
@@ -265,6 +280,10 @@
|
||||
"total_approved_order_amount",
|
||||
"approved_vendor",
|
||||
"approved_price",
|
||||
"updated_at",
|
||||
"updated_by",
|
||||
"updated_name",
|
||||
"inputed_name",
|
||||
];
|
||||
const formColumns = columns.filter(
|
||||
(col) => !excludedKeys.includes(col.key),
|
||||
@@ -285,6 +304,18 @@
|
||||
}
|
||||
|
||||
async function saveProject() {
|
||||
// session check
|
||||
const session = await supabase.auth.getSession();
|
||||
|
||||
if (!session.data.session) {
|
||||
alert("You must be logged in to perform this action.");
|
||||
return;
|
||||
}
|
||||
|
||||
const user = session.data.session.user;
|
||||
|
||||
const inputBy = user.id;
|
||||
|
||||
if (!validateInput()) {
|
||||
return;
|
||||
}
|
||||
@@ -297,6 +328,9 @@
|
||||
po_price: newPurchaseOrders.po_price || 0,
|
||||
po_total_price:
|
||||
newPurchaseOrders.po_quantity * newPurchaseOrders.po_price || 0,
|
||||
input_by: inputBy,
|
||||
updated_by: inputBy,
|
||||
updated_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
if (isEditing && currentEditingId) {
|
||||
@@ -400,13 +434,24 @@
|
||||
}
|
||||
|
||||
async function updateProsesToApproval(id: string, status: boolean) {
|
||||
const sessionId = await getSessionAuthId();
|
||||
if (!sessionId) {
|
||||
alert("You must be logged in to perform this action.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!validateInputProsesToAprroval()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("vb_purchase_orders")
|
||||
.update({ proses_to_approval: status, po_status: "REQUESTED" })
|
||||
.update({
|
||||
proses_to_approval: status,
|
||||
po_status: "REQUESTED",
|
||||
updated_by: sessionId,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq("id", id);
|
||||
|
||||
if (error) {
|
||||
@@ -425,6 +470,11 @@
|
||||
id: string,
|
||||
row: PurchaseOrderDisplay,
|
||||
) {
|
||||
const sessionId = await getSessionAuthId();
|
||||
if (!sessionId) {
|
||||
alert("You must be logged in to perform this action.");
|
||||
return;
|
||||
}
|
||||
const selectedOption = (e.target as HTMLSelectElement)?.value ?? "";
|
||||
const option = getStatusOption(selectedOption);
|
||||
|
||||
@@ -454,9 +504,19 @@
|
||||
}
|
||||
|
||||
async function acknowledgedOk(id: string, status: boolean) {
|
||||
const sessionId = await getSessionAuthId();
|
||||
if (!sessionId) {
|
||||
alert("You must be logged in to perform this action.");
|
||||
return;
|
||||
}
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("vb_purchase_orders")
|
||||
.update({ acknowledged: status })
|
||||
.update({
|
||||
acknowledged: status,
|
||||
updated_by: sessionId,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq("id", id);
|
||||
|
||||
if (error) {
|
||||
@@ -468,9 +528,19 @@
|
||||
}
|
||||
|
||||
async function receivedOk(id: string, status: boolean) {
|
||||
const sessionId = await getSessionAuthId();
|
||||
if (!sessionId) {
|
||||
alert("You must be logged in to perform this action.");
|
||||
return;
|
||||
}
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("vb_purchase_orders")
|
||||
.update({ receivedOk: status })
|
||||
.update({
|
||||
receivedOk: status,
|
||||
updated_by: sessionId,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq("id", id);
|
||||
|
||||
if (error) {
|
||||
@@ -486,6 +556,11 @@
|
||||
id: string,
|
||||
row: PurchaseOrderDisplay,
|
||||
) {
|
||||
const sessionId = await getSessionAuthId();
|
||||
if (!sessionId) {
|
||||
alert("You must be logged in to perform this action.");
|
||||
return;
|
||||
}
|
||||
const selectedOption = (e.target as HTMLSelectElement)?.value ?? "";
|
||||
const option = getStatusOption(selectedOption);
|
||||
|
||||
@@ -503,7 +578,11 @@
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from("vb_purchase_orders")
|
||||
.update({ approval: newPurchaseOrders.approval })
|
||||
.update({
|
||||
approval: newPurchaseOrders.approval,
|
||||
updated_by: sessionId,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq("id", id);
|
||||
|
||||
if (error) {
|
||||
@@ -515,9 +594,18 @@
|
||||
}
|
||||
|
||||
async function completedStatusOk(id: string, status: string) {
|
||||
const sessionId = await getSessionAuthId();
|
||||
if (!sessionId) {
|
||||
alert("You must be logged in to perform this action.");
|
||||
return;
|
||||
}
|
||||
const { data, error } = await supabase
|
||||
.from("vb_purchase_orders")
|
||||
.update({ completed_status: status })
|
||||
.update({
|
||||
completed_status: status,
|
||||
updated_by: sessionId,
|
||||
updated_at: new Date().toISOString(),
|
||||
})
|
||||
.eq("id", id);
|
||||
|
||||
if (error) {
|
||||
@@ -753,6 +841,14 @@
|
||||
>
|
||||
</select>
|
||||
</td>
|
||||
{:else if col.key === "updated_at"}
|
||||
<td class="px-4 py-2 text-gray-500"
|
||||
>{new Date(
|
||||
row[
|
||||
col.key as keyof PurchaseOrderDisplay
|
||||
] as string,
|
||||
).toLocaleString()}</td
|
||||
>
|
||||
{:else if col.key === "actions"}
|
||||
<td class="px-4 py-2">
|
||||
<button
|
||||
@@ -770,11 +866,11 @@
|
||||
</td>
|
||||
{:else if col.key === "created_at"}
|
||||
<td class="px-4 py-2 text-gray-500"
|
||||
>{timestampToDateTime(
|
||||
>{new Date(
|
||||
row[
|
||||
col.key as keyof PurchaseOrderDisplay
|
||||
] as string,
|
||||
)}</td
|
||||
).toLocaleString()}</td
|
||||
>
|
||||
{:else}
|
||||
<td class="px-4 py-2 text-gray-700"
|
||||
|
||||
Reference in New Issue
Block a user