fix: totalAmount always stores grand total including GST
manager-line-edit-actions: add gstRate to lineItemSchema; recalculate newTotal as sum(qty * unitPrice * (1 + gstRate)) and persist gstRate on recreated line items. seed: patch existing POs totalAmount to grand total (taxable * 1.18): PO-2026-00001: 8450 -> 9971 PO-2026-00002: 3200 -> 3776 PO-2026-00003: 950 -> 1121
This commit is contained in:
parent
bde7fc9842
commit
ac584bce2f
2 changed files with 12 additions and 7 deletions
|
|
@ -14,6 +14,7 @@ const lineItemSchema = z.object({
|
|||
unit: z.string().min(1),
|
||||
size: z.string().optional(),
|
||||
unitPrice: z.coerce.number().nonnegative(),
|
||||
gstRate: z.coerce.number().min(0).max(1).default(0.18),
|
||||
});
|
||||
|
||||
export async function managerEditLineItems({
|
||||
|
|
@ -46,7 +47,10 @@ export async function managerEditLineItems({
|
|||
unitPrice: Number(li.unitPrice),
|
||||
}));
|
||||
|
||||
const newTotal = parsed.data.reduce((sum, item) => sum + item.quantity * item.unitPrice, 0);
|
||||
const newTotal = parsed.data.reduce(
|
||||
(sum, item) => sum + item.quantity * item.unitPrice * (1 + item.gstRate),
|
||||
0
|
||||
);
|
||||
|
||||
await db.purchaseOrder.update({
|
||||
where: { id: poId },
|
||||
|
|
@ -61,6 +65,7 @@ export async function managerEditLineItems({
|
|||
size: item.size ?? null,
|
||||
unitPrice: item.unitPrice,
|
||||
totalPrice: item.quantity * item.unitPrice,
|
||||
gstRate: item.gstRate,
|
||||
sortOrder: idx,
|
||||
})),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -188,12 +188,12 @@ async function main() {
|
|||
// Sample POs — upsert so re-running seed is safe
|
||||
const po1 = await db.purchaseOrder.upsert({
|
||||
where: { poNumber: "PO-2026-00001" },
|
||||
update: { currency: "INR" },
|
||||
update: { currency: "INR", totalAmount: 9971.0 },
|
||||
create: {
|
||||
poNumber: "PO-2026-00001",
|
||||
title: "Engine Room Spare Parts — MV Pelagia Star",
|
||||
status: "MGR_REVIEW",
|
||||
totalAmount: 8450.0,
|
||||
totalAmount: 9971.0, // 8450 taxable × 1.18 GST
|
||||
currency: "INR",
|
||||
submittedAt: new Date(),
|
||||
submitterId: technical.id,
|
||||
|
|
@ -218,12 +218,12 @@ async function main() {
|
|||
|
||||
await db.purchaseOrder.upsert({
|
||||
where: { poNumber: "PO-2026-00002" },
|
||||
update: { currency: "INR" },
|
||||
update: { currency: "INR", totalAmount: 3776.0 },
|
||||
create: {
|
||||
poNumber: "PO-2026-00002",
|
||||
title: "Crew Safety Equipment — MV Aegean Wind",
|
||||
status: "DRAFT",
|
||||
totalAmount: 3200.0,
|
||||
totalAmount: 3776.0, // 3200 taxable × 1.18 GST
|
||||
currency: "INR",
|
||||
submitterId: technical.id,
|
||||
vesselId: mv2.id,
|
||||
|
|
@ -242,12 +242,12 @@ async function main() {
|
|||
|
||||
await db.purchaseOrder.upsert({
|
||||
where: { poNumber: "PO-2026-00003" },
|
||||
update: { currency: "INR" },
|
||||
update: { currency: "INR", totalAmount: 1121.0 },
|
||||
create: {
|
||||
poNumber: "PO-2026-00003",
|
||||
title: "Navigation Charts Update — Fleet",
|
||||
status: "MGR_APPROVED",
|
||||
totalAmount: 950.0,
|
||||
totalAmount: 1121.0, // 950 taxable × 1.18 GST
|
||||
currency: "INR",
|
||||
submittedAt: new Date(Date.now() - 5 * 86400000),
|
||||
approvedAt: new Date(Date.now() - 2 * 86400000),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue