Merge release & add time ticket calculations.
This commit is contained in:
@@ -79,40 +79,78 @@ exports.default = async function (socket, jobid) {
|
||||
bill_val.billlines.map((line_val) => {
|
||||
if (!bill_acc[line_val.cost_center])
|
||||
bill_acc[line_val.cost_center] = Dinero();
|
||||
const lineDinero = Dinero({
|
||||
|
||||
let lineDinero = Dinero({
|
||||
amount: Math.round((line_val.actual_cost || 0) * 100),
|
||||
})
|
||||
.multiply(line_val.quantity)
|
||||
.multiply(bill_val.is_credit_memo ? -1 : 1);
|
||||
|
||||
bill_acc[line_val.cost_center] =
|
||||
bill_acc[line_val.cost_center].add(lineDinero);
|
||||
|
||||
//Add appropriate tax amounts.
|
||||
const {
|
||||
applicable_taxes: { local, state, federal },
|
||||
} = line_val;
|
||||
|
||||
if (local) {
|
||||
taxAllocations.local.cost = taxAllocations.local.cost.add(
|
||||
if (bodyshop.cdk_configuration.itc_local)
|
||||
taxAllocations.local.cost = taxAllocations.local.cost.add(
|
||||
lineDinero.percentage(bill_val.local_tax_rate || 0)
|
||||
);
|
||||
lineDinero = lineDinero.add(
|
||||
lineDinero.percentage(bill_val.local_tax_rate || 0)
|
||||
);
|
||||
}
|
||||
if (state) {
|
||||
taxAllocations.state.cost = taxAllocations.state.cost.add(
|
||||
if (bodyshop.cdk_configuration.itc_state)
|
||||
taxAllocations.state.cost = taxAllocations.state.cost.add(
|
||||
lineDinero.percentage(bill_val.state_tax_rate || 0)
|
||||
);
|
||||
lineDinero = lineDinero.add(
|
||||
lineDinero.percentage(bill_val.state_tax_rate || 0)
|
||||
);
|
||||
}
|
||||
if (federal) {
|
||||
taxAllocations.federal.cost = taxAllocations.federal.cost.add(
|
||||
//If it's an ITC, add it as a negative cost, otherwise add it to the item cost.
|
||||
if (bodyshop.cdk_configuration.itc_federal)
|
||||
taxAllocations.federal.cost = taxAllocations.federal.cost.add(
|
||||
lineDinero.percentage(bill_val.federal_tax_rate || 0)
|
||||
);
|
||||
|
||||
lineDinero = lineDinero.add(
|
||||
lineDinero.percentage(bill_val.federal_tax_rate || 0)
|
||||
);
|
||||
|
||||
// bill_acc[line_val.cost_center] = bill_acc[line_val.cost_center].add(
|
||||
// lineDinero.percentage(bill_val.federal_tax_rate || 0)
|
||||
// );
|
||||
}
|
||||
|
||||
bill_acc[line_val.cost_center] =
|
||||
bill_acc[line_val.cost_center].add(lineDinero);
|
||||
return null;
|
||||
});
|
||||
return bill_acc;
|
||||
}, {});
|
||||
|
||||
job.timetickets.forEach((ticket) => {
|
||||
//Get the total amount of the ticket.
|
||||
let TicketTotal = Dinero({
|
||||
amount: Math.round(
|
||||
ticket.rate *
|
||||
(ticket.employee && ticket.employee.flat_rate
|
||||
? ticket.productivehrs || 0
|
||||
: ticket.actualhrs || 0) *
|
||||
100
|
||||
),
|
||||
});
|
||||
//Add it to the right cost center.
|
||||
if (!costCenterHash[ticket.cost_center])
|
||||
costCenterHash[ticket.cost_center] = Dinero();
|
||||
|
||||
costCenterHash[ticket.cost_center] =
|
||||
costCenterHash[ticket.cost_center].add(TicketTotal);
|
||||
});
|
||||
|
||||
const jobAllocations = _.union(
|
||||
Object.keys(profitCenterHash),
|
||||
Object.keys(costCenterHash)
|
||||
|
||||
Reference in New Issue
Block a user