Enhanced payroll deduct from labor correction.

This commit is contained in:
Patrick Fic
2023-10-17 10:45:16 -07:00
parent f9c8f53474
commit acc9145d52

View File

@@ -98,6 +98,7 @@ function BillEnterModalContainer({
} = values;
let adjustmentsToInsert = {};
let payrollAdjustmentsToInsert = [];
const r1 = await insertBill({
variables: {
@@ -121,6 +122,24 @@ function BillEnterModalContainer({
(adjustmentsToInsert[lbr_adjustment.mod_lbr_ty] || 0) -
restI.actual_price / lbr_adjustment.rate;
}
//If deduct from labor has lines,
//
if (
deductedfromlbr &&
true //payroll is on
) {
payrollAdjustmentsToInsert.push({
id: i.joblineid,
convertedtolbr: true,
convertedtolbr_data: {
mod_lb_hrs:
(restI.actual_price / lbr_adjustment.rate) * -1,
mod_lbr_ty: lbr_adjustment.mod_lbr_ty,
},
});
}
return {
...restI,
deductedfromlbr: deductedfromlbr,
@@ -146,6 +165,20 @@ function BillEnterModalContainer({
refetchQueries: ["QUERY_PARTS_BILLS_BY_JOBID"],
});
await Promise.all(
payrollAdjustmentsToInsert.map((li) => {
return updateJobLines({
variables: {
lineId: li.id,
line: {
convertedtolbr: li.convertedtolbr,
convertedtolbr_data: li.convertedtolbr_data,
},
},
});
})
);
const adjKeys = Object.keys(adjustmentsToInsert);
if (adjKeys.length > 0) {
//Query the adjustments, merge, and update them.