Updates to QuickBooks and DMS export.
This commit is contained in:
@@ -483,24 +483,25 @@ function CalculatePartsTotals(jobLines, parts_tax_rates, job) {
|
||||
value.db_ref !== "900511"
|
||||
)
|
||||
return acc;
|
||||
|
||||
const discountAmount =
|
||||
((value.prt_dsmk_m && value.prt_dsmk_m !== 0) ||
|
||||
(value.prt_dsmk_p && value.prt_dsmk_p !== 0)) &&
|
||||
DiscountNotAlreadyCounted(value, jl)
|
||||
? value.prt_dsmk_m
|
||||
? Dinero({ amount: Math.round(value.prt_dsmk_m * 100) })
|
||||
: Dinero({
|
||||
amount: Math.round(value.act_price * 100),
|
||||
})
|
||||
.multiply(value.part_qty || 0)
|
||||
.percentage(Math.abs(value.prt_dsmk_p || 0))
|
||||
.multiply(value.prt_dsmk_p > 0 ? 1 : -1)
|
||||
: Dinero();
|
||||
return {
|
||||
...acc,
|
||||
parts: {
|
||||
...acc.parts,
|
||||
prt_dsmk_total: acc.parts.prt_dsmk_total.add(
|
||||
((value.prt_dsmk_m && value.prt_dsmk_m !== 0) ||
|
||||
(value.prt_dsmk_p && value.prt_dsmk_p !== 0)) &&
|
||||
DiscountNotAlreadyCounted(value, jl)
|
||||
? value.prt_dsmk_m
|
||||
? Dinero({ amount: Math.round(value.prt_dsmk_m * 100) })
|
||||
: Dinero({
|
||||
amount: Math.round(value.act_price * 100),
|
||||
})
|
||||
.multiply(value.part_qty || 0)
|
||||
.percentage(Math.abs(value.prt_dsmk_p || 0))
|
||||
.multiply(value.prt_dsmk_p > 0 ? 1 : -1)
|
||||
: Dinero()
|
||||
),
|
||||
prt_dsmk_total: acc.parts.prt_dsmk_total.add(discountAmount),
|
||||
...(value.part_type
|
||||
? {
|
||||
list: {
|
||||
@@ -509,20 +510,24 @@ function CalculatePartsTotals(jobLines, parts_tax_rates, job) {
|
||||
acc.parts.list[value.part_type] &&
|
||||
acc.parts.list[value.part_type].total
|
||||
? {
|
||||
total: acc.parts.list[value.part_type].total.add(
|
||||
Dinero({
|
||||
amount: Math.round(
|
||||
(value.act_price || 0) * 100
|
||||
),
|
||||
}).multiply(value.part_qty || 0)
|
||||
),
|
||||
total: acc.parts.list[value.part_type].total
|
||||
.add(
|
||||
Dinero({
|
||||
amount: Math.round(
|
||||
(value.act_price || 0) * 100
|
||||
),
|
||||
}).multiply(value.part_qty || 0)
|
||||
)
|
||||
.add(discountAmount),
|
||||
}
|
||||
: {
|
||||
total: Dinero({
|
||||
amount: Math.round(
|
||||
(value.act_price || 0) * 100
|
||||
),
|
||||
}).multiply(value.part_qty || 0),
|
||||
})
|
||||
.multiply(value.part_qty || 0)
|
||||
.add(discountAmount),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -624,7 +629,7 @@ function CalculatePartsTotals(jobLines, parts_tax_rates, job) {
|
||||
);
|
||||
|
||||
//If the difference is greater than a penny, fix it.
|
||||
|
||||
//This usually ties into whether or not the profile has part type discounts overall in the PFP.
|
||||
if (
|
||||
correspondingCiecaStlTotalLine &&
|
||||
Math.abs(
|
||||
@@ -663,7 +668,7 @@ function CalculatePartsTotals(jobLines, parts_tax_rates, job) {
|
||||
// ret.parts.list[key].total = ret.parts.list[key]?.total.subtract(
|
||||
// totalDiscountToAdjustBy
|
||||
// );
|
||||
ret.parts.prt_dsmk_total = ret.parts.prt_dsmk_total.add(
|
||||
ret.parts.prt_dsmk_total = ret.parts.prt_dsmk_total.subtract(
|
||||
totalDiscountToAdjustBy
|
||||
);
|
||||
ret.parts.subtotal = ret.parts.subtotal.subtract(totalDiscountToAdjustBy);
|
||||
@@ -671,7 +676,7 @@ function CalculatePartsTotals(jobLines, parts_tax_rates, job) {
|
||||
}
|
||||
});
|
||||
|
||||
//UpdateJobLines(linesToAdjustForDiscount.filter((l) => l.prt_dsmk_m !== 0));
|
||||
UpdateJobLines(linesToAdjustForDiscount.filter((l) => l.prt_dsmk_m !== 0));
|
||||
|
||||
return {
|
||||
adjustments,
|
||||
@@ -804,6 +809,9 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
LAM: Dinero(),
|
||||
LAR: Dinero(),
|
||||
LAS: Dinero(),
|
||||
|
||||
MAPA: Dinero(),
|
||||
MASH: Dinero(),
|
||||
};
|
||||
|
||||
if (
|
||||
@@ -824,14 +832,14 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
} else if (!val.part_type) {
|
||||
//Do nothing for now.
|
||||
} else {
|
||||
const typeOfPart = val.part_type; // === "PAM" ? "PAC" : val.part_type;
|
||||
const typeOfPart = val.part_type;
|
||||
taxableAmounts[typeOfPart] = taxableAmounts[typeOfPart].add(
|
||||
Dinero({ amount: Math.round((val.act_price || 0) * 100) })
|
||||
.multiply(val.part_qty || 0)
|
||||
.add(
|
||||
val.prt_dsmk_m &&
|
||||
val.prt_dsmk_m !== 0 &&
|
||||
DiscountNotAlreadyCounted(val, job.joblines)
|
||||
DiscountNotAlreadyCounted(val, job.joblines) // DO WE NEED TO COUNT PFP DISCOUNT HERE?
|
||||
? val.prt_dsmk_m
|
||||
? Dinero({ amount: Math.round(val.prt_dsmk_m * 100) })
|
||||
: Dinero({
|
||||
@@ -858,6 +866,17 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
}
|
||||
});
|
||||
|
||||
Object.keys(taxableAmounts)
|
||||
.filter((key) => key.startsWith("MA"))
|
||||
.map((key) => {
|
||||
const isTypeTaxable = job.materials[key]?.tax_ind;
|
||||
if (isTypeTaxable) {
|
||||
taxableAmounts[key] = taxableAmounts[key].add(
|
||||
otherTotals.rates[key.toLowerCase()].total
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("*** Taxable Amounts***");
|
||||
console.table(JSON.parse(JSON.stringify(taxableAmounts)));
|
||||
|
||||
@@ -883,6 +902,7 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
|
||||
const pfp = job.parts_tax_rates;
|
||||
const pfl = job.cieca_pfl;
|
||||
const pfm = job.materials;
|
||||
Object.keys(taxableAmounts).map((key) => {
|
||||
try {
|
||||
if (key.startsWith("PA")) {
|
||||
@@ -896,6 +916,16 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
].add(taxableAmounts[typeOfPart]);
|
||||
}
|
||||
}
|
||||
} else if (key.startsWith("MA")) {
|
||||
//Materials Handling
|
||||
for (let tyCounter = 1; tyCounter <= 5; tyCounter++) {
|
||||
if (IsTrueOrYes(pfm[key][`mat_tx_in${tyCounter}`])) {
|
||||
//This amount is taxable for this type.
|
||||
taxableAmountsByTier[`ty${tyCounter}Tax`] = taxableAmountsByTier[
|
||||
`ty${tyCounter}Tax`
|
||||
].add(taxableAmounts[key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//Labor.
|
||||
for (let tyCounter = 1; tyCounter <= 5; tyCounter++) {
|
||||
@@ -1060,7 +1090,7 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
statePartsTax,
|
||||
us_sales_tax_breakdown,
|
||||
state_tax: statePartsTax
|
||||
.add(laborTaxTotal)
|
||||
//.add(laborTaxTotal)
|
||||
.add(
|
||||
otherTotals.additional.adjustments.percentage(
|
||||
(job.tax_lbr_rt || 0) * 100
|
||||
@@ -1071,22 +1101,22 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
)
|
||||
.add(
|
||||
otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100)
|
||||
)
|
||||
.add(additionalItemsTax) // 0 if using PFP method.
|
||||
.add(
|
||||
otherTotals.rates.mapa.hasMapaLine === false //If parts and materials were not added as lines, we must calculate the taxes on them.
|
||||
? otherTotals.rates.mapa.total.percentage(
|
||||
(job.tax_paint_mat_rt || 0) * 100
|
||||
)
|
||||
: Dinero()
|
||||
)
|
||||
.add(
|
||||
otherTotals.rates.mash.hasMashLine === false //If parts and materials were not added as lines, we must calculate the taxes on them.
|
||||
? otherTotals.rates.mash.total.percentage(
|
||||
(job.tax_shop_mat_rt || 0) * 100
|
||||
)
|
||||
: Dinero()
|
||||
),
|
||||
// .add(additionalItemsTax) // 0 if using PFP method.
|
||||
// .add(
|
||||
// otherTotals.rates.mapa.hasMapaLine === false //If parts and materials were not added as lines, we must calculate the taxes on them.
|
||||
// ? otherTotals.rates.mapa.total.percentage(
|
||||
// (job.tax_paint_mat_rt || 0) * 100
|
||||
// )
|
||||
// : Dinero()
|
||||
// )
|
||||
// .add(
|
||||
// otherTotals.rates.mash.hasMashLine === false //If parts and materials were not added as lines, we must calculate the taxes on them.
|
||||
// ? otherTotals.rates.mash.total.percentage(
|
||||
// (job.tax_shop_mat_rt || 0) * 100
|
||||
// )
|
||||
// : Dinero()
|
||||
// )
|
||||
local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),
|
||||
};
|
||||
ret.total_repairs = ret.subtotal
|
||||
@@ -1132,14 +1162,12 @@ function DiscountNotAlreadyCounted(jobline, joblines) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check it against the database price too? If it's an OE part.
|
||||
// if (
|
||||
// Math.abs(jobline.db_price - jobline.act_price) -
|
||||
// Math.abs(jobline.prt_dsmk_m) <
|
||||
// 0.01
|
||||
// ) {
|
||||
// return false;
|
||||
// }
|
||||
if (
|
||||
jobline.db_price !== jobline.act_price &&
|
||||
jobline.db_price - jobline.act_price - Math.abs(jobline.prt_dsmk_m) < 0.02
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
//If it's not a discount line, then it definitely hasn't been counted yet.
|
||||
|
||||
Reference in New Issue
Block a user