Add regression check.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Collapse, Form, InputNumber, Switch } from "antd";
|
import { Collapse, Form, Input, InputNumber, Switch } from "antd";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
@@ -563,6 +563,13 @@ export function JobsDetailRatesParts({
|
|||||||
>
|
>
|
||||||
<Switch />
|
<Switch />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
style={{ display: "none" }}
|
||||||
|
label={t("jobs.fields.parts_tax_rates.prt_tx_ty1")}
|
||||||
|
name={["parts_tax_rates", "PAN", "prt_tx_ty1"]}
|
||||||
|
>
|
||||||
|
<Input />
|
||||||
|
</Form.Item>
|
||||||
</LayoutFormRow>
|
</LayoutFormRow>
|
||||||
<LayoutFormRow header={t("joblines.fields.part_types.PAO")}>
|
<LayoutFormRow header={t("joblines.fields.part_types.PAO")}>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -793,128 +793,188 @@ function CalculateTaxesTotals(job, otherTotals) {
|
|||||||
PAM: Dinero(),
|
PAM: Dinero(),
|
||||||
};
|
};
|
||||||
|
|
||||||
//For each line, determine if it's taxable, and if it is, add the line amount to the taxable amounts total.
|
if (
|
||||||
job.joblines
|
job.parts_tax_rates.PAN.prt_tx_ty1 &&
|
||||||
.filter((jl) => !jl.removed)
|
job.parts_tax_rates.PAN.prt_tx_ty1 !== ""
|
||||||
.forEach((val) => {
|
) {
|
||||||
if (!val.tax_part) return;
|
//For each line, determine if it's taxable, and if it is, add the line amount to the taxable amounts total.
|
||||||
if (!val.part_type && IsAdditionalCost(val)) {
|
job.joblines
|
||||||
taxableAmounts.PAO = taxableAmounts.PAO.add(
|
.filter((jl) => !jl.removed)
|
||||||
Dinero({ amount: Math.round((val.act_price || 0) * 100) }).multiply(
|
.forEach((val) => {
|
||||||
val.part_qty || 0
|
if (!val.tax_part) return;
|
||||||
)
|
if (!val.part_type && IsAdditionalCost(val)) {
|
||||||
);
|
taxableAmounts.PAO = taxableAmounts.PAO.add(
|
||||||
} else if (!val.part_type) {
|
Dinero({ amount: Math.round((val.act_price || 0) * 100) }).multiply(
|
||||||
//Do nothing for now.
|
val.part_qty || 0
|
||||||
} else {
|
|
||||||
const typeOfPart = val.part_type === "PAM" ? "PAC" : 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)
|
|
||||||
? val.prt_dsmk_m
|
|
||||||
? Dinero({ amount: Math.round(val.prt_dsmk_m * 100) })
|
|
||||||
: Dinero({
|
|
||||||
amount: Math.round(val.act_price * 100),
|
|
||||||
})
|
|
||||||
.multiply(val.part_qty || 0)
|
|
||||||
.percentage(Math.abs(val.prt_dsmk_p || 0))
|
|
||||||
.multiply(val.prt_dsmk_p > 0 ? 1 : -1)
|
|
||||||
: Dinero()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
} else if (!val.part_type) {
|
||||||
});
|
//Do nothing for now.
|
||||||
|
} else {
|
||||||
|
const typeOfPart = val.part_type === "PAM" ? "PAC" : 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)
|
||||||
|
? val.prt_dsmk_m
|
||||||
|
? Dinero({ amount: Math.round(val.prt_dsmk_m * 100) })
|
||||||
|
: Dinero({
|
||||||
|
amount: Math.round(val.act_price * 100),
|
||||||
|
})
|
||||||
|
.multiply(val.part_qty || 0)
|
||||||
|
.percentage(Math.abs(val.prt_dsmk_p || 0))
|
||||||
|
.multiply(val.prt_dsmk_p > 0 ? 1 : -1)
|
||||||
|
: Dinero()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Taxable amounts should match with what is in the STL file.
|
//Taxable amounts should match with what is in the STL file.
|
||||||
//Now that we have the taxable amounts, apply the tax.
|
//Now that we have the taxable amounts, apply the tax.
|
||||||
|
|
||||||
const tieredTaxAmounts = {
|
const tieredTaxAmounts = {
|
||||||
ty1Tax: Dinero(),
|
ty1Tax: Dinero(),
|
||||||
ty2Tax: Dinero(),
|
ty2Tax: Dinero(),
|
||||||
ty3Tax: Dinero(),
|
ty3Tax: Dinero(),
|
||||||
ty4Tax: Dinero(),
|
ty4Tax: Dinero(),
|
||||||
ty5Tax: Dinero(),
|
ty5Tax: Dinero(),
|
||||||
ty6Tax: Dinero(),
|
ty6Tax: Dinero(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const remainingTaxableAmounts = taxableAmounts;
|
const remainingTaxableAmounts = taxableAmounts;
|
||||||
console.log("Taxable Amounts");
|
console.log("Taxable Amounts");
|
||||||
console.table(JSON.parse(JSON.stringify(taxableAmounts)));
|
console.table(JSON.parse(JSON.stringify(taxableAmounts)));
|
||||||
Object.keys(taxableAmounts).forEach((part_type) => {
|
Object.keys(taxableAmounts).forEach((part_type) => {
|
||||||
//Check it's taxability in the PFP
|
//Check it's taxability in the PFP
|
||||||
try {
|
try {
|
||||||
const pfp = job.parts_tax_rates;
|
const pfp = job.parts_tax_rates;
|
||||||
|
|
||||||
const typeOfPart = part_type === "PAM" ? "PAC" : part_type;
|
const typeOfPart = part_type === "PAM" ? "PAC" : part_type;
|
||||||
if (IsTrueOrYes(pfp[typeOfPart].prt_tax_in)) {
|
if (IsTrueOrYes(pfp[typeOfPart].prt_tax_in)) {
|
||||||
//At least one of these scenarios must be taxable.
|
//At least one of these scenarios must be taxable.
|
||||||
for (let tyCounter = 1; tyCounter <= 5; tyCounter++) {
|
for (let tyCounter = 1; tyCounter <= 5; tyCounter++) {
|
||||||
if (IsTrueOrYes(pfp[typeOfPart][`prt_tx_in${tyCounter}`])) {
|
if (IsTrueOrYes(pfp[typeOfPart][`prt_tx_in${tyCounter}`])) {
|
||||||
//i represents the tax number. If we got here, this type of tax is applicable. Now we need to add based on the thresholds.
|
//i represents the tax number. If we got here, this type of tax is applicable. Now we need to add based on the thresholds.
|
||||||
for (let threshCounter = 1; threshCounter <= 5; threshCounter++) {
|
for (let threshCounter = 1; threshCounter <= 5; threshCounter++) {
|
||||||
const thresholdAmount = parseFloat(
|
const thresholdAmount = parseFloat(
|
||||||
job.cieca_pft[`ty${tyCounter}_thres${threshCounter}`]
|
job.cieca_pft[`ty${tyCounter}_thres${threshCounter}`]
|
||||||
);
|
);
|
||||||
const thresholdTaxRate = parseFloat(
|
const thresholdTaxRate = parseFloat(
|
||||||
job.cieca_pft[`ty${tyCounter}_rate${threshCounter}`]
|
job.cieca_pft[`ty${tyCounter}_rate${threshCounter}`]
|
||||||
);
|
);
|
||||||
|
|
||||||
let taxableAmountInThisThreshold;
|
let taxableAmountInThisThreshold;
|
||||||
if (thresholdAmount === 9999.99) {
|
if (thresholdAmount === 9999.99) {
|
||||||
// THis is the last threshold. Tax the entire remaining amount.
|
// THis is the last threshold. Tax the entire remaining amount.
|
||||||
taxableAmountInThisThreshold =
|
|
||||||
remainingTaxableAmounts[typeOfPart];
|
|
||||||
remainingTaxableAmounts[typeOfPart] = Dinero();
|
|
||||||
} else {
|
|
||||||
if (
|
|
||||||
thresholdAmount >=
|
|
||||||
remainingTaxableAmounts[typeOfPart].getAmount() / 100
|
|
||||||
) {
|
|
||||||
//This threshold is bigger than the remaining taxable balance. Add it all.
|
|
||||||
taxableAmountInThisThreshold =
|
taxableAmountInThisThreshold =
|
||||||
remainingTaxableAmounts[typeOfPart];
|
remainingTaxableAmounts[typeOfPart];
|
||||||
remainingTaxableAmounts[typeOfPart] = Dinero();
|
remainingTaxableAmounts[typeOfPart] = Dinero();
|
||||||
} else {
|
} else {
|
||||||
//Take the size of the threshold from the remaining amount, tax it, and do it all over.
|
if (
|
||||||
taxableAmountInThisThreshold = Dinero({
|
thresholdAmount >=
|
||||||
amount: Math.round(thresholdAmount * 100),
|
remainingTaxableAmounts[typeOfPart].getAmount() / 100
|
||||||
});
|
) {
|
||||||
remainingTaxableAmounts[typeOfPart] = remainingTaxableAmounts[
|
//This threshold is bigger than the remaining taxable balance. Add it all.
|
||||||
typeOfPart
|
taxableAmountInThisThreshold =
|
||||||
].subtract(
|
remainingTaxableAmounts[typeOfPart];
|
||||||
Dinero({
|
remainingTaxableAmounts[typeOfPart] = Dinero();
|
||||||
amount: Math.round(taxableAmountInThisThreshold * 100),
|
} else {
|
||||||
})
|
//Take the size of the threshold from the remaining amount, tax it, and do it all over.
|
||||||
);
|
taxableAmountInThisThreshold = Dinero({
|
||||||
|
amount: Math.round(thresholdAmount * 100),
|
||||||
|
});
|
||||||
|
remainingTaxableAmounts[typeOfPart] =
|
||||||
|
remainingTaxableAmounts[typeOfPart].subtract(
|
||||||
|
Dinero({
|
||||||
|
amount: Math.round(
|
||||||
|
taxableAmountInThisThreshold * 100
|
||||||
|
),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const taxAmountToAdd =
|
||||||
|
taxableAmountInThisThreshold.percentage(thresholdTaxRate);
|
||||||
|
|
||||||
|
tieredTaxAmounts[`ty${tyCounter}Tax`] =
|
||||||
|
tieredTaxAmounts[`ty${tyCounter}Tax`].add(taxAmountToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
const taxAmountToAdd =
|
|
||||||
taxableAmountInThisThreshold.percentage(thresholdTaxRate);
|
|
||||||
|
|
||||||
tieredTaxAmounts[`ty${tyCounter}Tax`] =
|
|
||||||
tieredTaxAmounts[`ty${tyCounter}Tax`].add(taxAmountToAdd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Shit the bed.");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
});
|
||||||
console.error("Shit the bed.");
|
|
||||||
}
|
statePartsTax = statePartsTax
|
||||||
});
|
.add(tieredTaxAmounts.ty1Tax)
|
||||||
|
.add(tieredTaxAmounts.ty2Tax)
|
||||||
|
.add(tieredTaxAmounts.ty3Tax)
|
||||||
|
.add(tieredTaxAmounts.ty4Tax)
|
||||||
|
.add(tieredTaxAmounts.ty5Tax)
|
||||||
|
.add(tieredTaxAmounts.ty6Tax);
|
||||||
|
console.log("Tiered Taxes Total for Parts", statePartsTax.toFormat());
|
||||||
|
} else {
|
||||||
|
//Use the old thing.
|
||||||
|
job.joblines
|
||||||
|
.filter((jl) => !jl.removed)
|
||||||
|
.forEach((val) => {
|
||||||
|
if (!val.tax_part) return;
|
||||||
|
if (!val.part_type && IsAdditionalCost(val)) {
|
||||||
|
additionalItemsTax = additionalItemsTax.add(
|
||||||
|
Dinero({ amount: Math.round((val.act_price || 0) * 100) })
|
||||||
|
.multiply(val.part_qty || 0)
|
||||||
|
.percentage(
|
||||||
|
((job.parts_tax_rates &&
|
||||||
|
job.parts_tax_rates["PAN"] &&
|
||||||
|
job.parts_tax_rates["PAN"].prt_tax_rt) ||
|
||||||
|
0) * 100
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
statePartsTax = statePartsTax.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)
|
||||||
|
? val.prt_dsmk_m
|
||||||
|
? Dinero({ amount: Math.round(val.prt_dsmk_m * 100) })
|
||||||
|
: Dinero({
|
||||||
|
amount: Math.round(val.act_price * 100),
|
||||||
|
})
|
||||||
|
.multiply(val.part_qty || 0)
|
||||||
|
.percentage(Math.abs(val.prt_dsmk_p || 0))
|
||||||
|
.multiply(val.prt_dsmk_p > 0 ? 1 : -1)
|
||||||
|
: Dinero()
|
||||||
|
)
|
||||||
|
.percentage(
|
||||||
|
((job.parts_tax_rates &&
|
||||||
|
job.parts_tax_rates[val.part_type] &&
|
||||||
|
job.parts_tax_rates[val.part_type].prt_tax_rt) ||
|
||||||
|
(val.part_type &&
|
||||||
|
val.part_type.startsWith("PAG") &&
|
||||||
|
BackupGlassTax &&
|
||||||
|
BackupGlassTax.prt_tax_rt) ||
|
||||||
|
(!val.part_type &&
|
||||||
|
val.db_ref === "900510" &&
|
||||||
|
job.parts_tax_rates["PAN"] &&
|
||||||
|
job.parts_tax_rates["PAN"].prt_tax_rt) ||
|
||||||
|
0) * 100
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log(statePartsTax.toFormat(), val.line_desc);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
statePartsTax = statePartsTax
|
|
||||||
.add(tieredTaxAmounts.ty1Tax)
|
|
||||||
.add(tieredTaxAmounts.ty2Tax)
|
|
||||||
.add(tieredTaxAmounts.ty3Tax)
|
|
||||||
.add(tieredTaxAmounts.ty4Tax)
|
|
||||||
.add(tieredTaxAmounts.ty5Tax)
|
|
||||||
.add(tieredTaxAmounts.ty6Tax);
|
|
||||||
console.log("Tiered Taxes Total for Parts", statePartsTax.toFormat());
|
|
||||||
let laborTaxTotal = Dinero();
|
let laborTaxTotal = Dinero();
|
||||||
|
|
||||||
if (Object.keys(job.cieca_pfl).length > 0) {
|
if (Object.keys(job.cieca_pfl).length > 0) {
|
||||||
@@ -975,7 +1035,7 @@ function CalculateTaxesTotals(job, otherTotals) {
|
|||||||
.add(
|
.add(
|
||||||
otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100)
|
otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100)
|
||||||
)
|
)
|
||||||
// .add(additionalItemsTax)
|
.add(additionalItemsTax) // 0 if using PFP method.
|
||||||
.add(
|
.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.hasMapaLine === false //If parts and materials were not added as lines, we must calculate the taxes on them.
|
||||||
? otherTotals.rates.mapa.total.percentage(
|
? otherTotals.rates.mapa.total.percentage(
|
||||||
|
|||||||
Reference in New Issue
Block a user