From 4fec7cf1867c191f13bd444113b5014b27859b85 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Fri, 19 Mar 2021 12:04:34 -0700 Subject: [PATCH] IO-791 Bill edit deduct from labor WIP. --- .../bill-detail-edit.container.jsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx b/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx index bf4467758..8d764bb5e 100644 --- a/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx +++ b/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx @@ -31,6 +31,8 @@ export default function BillDetailEditcontainer() { const handleFinish = async (values) => { setUpdateLoading(true); + //let adjustmentsToInsert = {}; + const { billlines, upload, ...bill } = values; const updates = []; updates.push( @@ -39,8 +41,22 @@ export default function BillDetailEditcontainer() { }) ); - billlines.forEach((il) => { + billlines.forEach((billline) => { + const { deductfromlabor, ...il } = billline; delete il.__typename; + + //Need to compare this line to the previous version of the line to see if there is a change in the adjustments. + const theOldBillLine = data.bills_by_pk.billlines.find( + (bl) => bl.id === billline.id + ); + + if (theOldBillLine) { + //It was there! Need to change the diff. + if (theOldBillLine.deductfromlabor !== deductfromlabor) { + //There's a different + } + } + if (il.id) { updates.push( updateBillLine({ @@ -48,6 +64,7 @@ export default function BillDetailEditcontainer() { billLineId: il.id, billLine: { ...il, + deductedfromlbr: deductfromlabor, joblineid: il.joblineid === "noline" ? null : il.joblineid, }, }, @@ -61,6 +78,7 @@ export default function BillDetailEditcontainer() { billLines: [ { ...il, + deductedfromlbr: deductfromlabor, billid: search.billid, joblineid: il.joblineid === "noline" ? null : il.joblineid, },