Update Sales.tsx
This commit is contained in:
1 parent
5dcc4f946f
commit
54e5b52562
1 file changed
+27
-25
+27
-25
@@ -118,34 +118,35 @@ const Sales = () => {
|
||||
};
|
||||
|
||||
const submitUpdate = async () => {
|
||||
if (!selectedSale || !selectedSale.id) return;
|
||||
setProcessing(true);
|
||||
if (!selectedSale?.id) return;
|
||||
setProcessing(true);
|
||||
|
||||
try {
|
||||
const newStatus: "void" | "refunded" =
|
||||
actionType === "void" ? "void" : "refunded";
|
||||
try {
|
||||
const newStatus: "void" | "refunded" = actionType === "void" ? "void" : "refunded";
|
||||
|
||||
// --- UPDATE STOCK BACK ---
|
||||
for (const item of selectedSale.items) {
|
||||
await updateProductStock(item.product_id, item.quantity);
|
||||
// Update stock only on refund
|
||||
if (actionType === "refund") {
|
||||
for (const item of selectedSale.items) {
|
||||
await updateProductStock(item.product_id, item.quantity);
|
||||
}
|
||||
}
|
||||
|
||||
await updateSaleStatus(selectedSale.id, newStatus, reason);
|
||||
|
||||
setSelectedSale({
|
||||
...selectedSale,
|
||||
status: newStatus,
|
||||
refund_reason: reason,
|
||||
refunded_at: new Date().toISOString(),
|
||||
});
|
||||
|
||||
loadData();
|
||||
setActionType("view");
|
||||
setShowModal(false);
|
||||
} finally {
|
||||
setProcessing(false);
|
||||
}
|
||||
|
||||
await updateSaleStatus(selectedSale.id, newStatus, reason);
|
||||
|
||||
const updatedSale: Sale = {
|
||||
...selectedSale,
|
||||
status: newStatus,
|
||||
refund_reason: reason,
|
||||
refunded_at: new Date().toISOString(),
|
||||
};
|
||||
|
||||
setSelectedSale(updatedSale);
|
||||
loadData();
|
||||
setActionType("view");
|
||||
} finally {
|
||||
setProcessing(false);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const handlePrint = () => {
|
||||
window.print();
|
||||
@@ -761,3 +762,4 @@ const Sales = () => {
|
||||
export default Sales;
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user