SSR-1412 Fix pricing issues
This commit is contained in:
parent
626fffb2af
commit
efbf65c4c9
3 changed files with 49 additions and 2 deletions
|
|
@ -12,6 +12,15 @@ export function getPriceOfLineItem(lineItem) {
|
|||
return price;
|
||||
}
|
||||
|
||||
export function getSalesTaxOfLineItem(lineItem) {
|
||||
let price = lineItem.salesTax ?? 0;
|
||||
if (lineItem.childParts && lineItem.childParts.length !== 0) {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
price += getTaxOfLineItems(lineItem.childParts);
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price for the given array of line items. Will include sales tax if includeTax is true
|
||||
* @param {Array} lineItems array of line items to be priced
|
||||
|
|
@ -27,5 +36,5 @@ export function getPriceOfLineItems(lineItems) {
|
|||
* @returns {number} sales tax of the line items
|
||||
*/
|
||||
export function getTaxOfLineItems(lineItems) {
|
||||
return lineItems?.reduce((accumulator, lineItem) => accumulator + (lineItem.salesTax ?? 0), 0) ?? 0;
|
||||
return lineItems?.reduce((accumulator, lineItem) => accumulator + getSalesTaxOfLineItem(lineItem), 0) ?? 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,5 +210,42 @@ describe('price-calculator', () => {
|
|||
// Assert
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
|
||||
test('Returns expected with child line items', () => {
|
||||
// Arrange
|
||||
const lineItems = [
|
||||
{
|
||||
kitPrice: 1,
|
||||
laborAmount: 2,
|
||||
sellingPrice: 3,
|
||||
salesTax: 4,
|
||||
childParts: [
|
||||
{
|
||||
kitPrice: 10,
|
||||
laborAmount: 20,
|
||||
sellingPrice: 30,
|
||||
salesTax: 40
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
kitPrice: 1,
|
||||
salesTax: 2
|
||||
},
|
||||
{
|
||||
kitPrice: 10,
|
||||
laborAmount: 100,
|
||||
sellingPrice: 1000,
|
||||
salesTax: 50
|
||||
}
|
||||
];
|
||||
const expected = 96;
|
||||
|
||||
// Act
|
||||
const result = getTaxOfLineItems(lineItems);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1286,6 +1286,7 @@ export const useMainStore = defineStore({
|
|||
const payloadGlassParts = setClearOnSubmit(lineItems.glassParts, shouldClearOnSubmit);
|
||||
const payloadSupportingItems = setClearOnSubmit(lineItems.supportingItems, shouldClearOnSubmit);
|
||||
const payloadVapsItems = setClearOnSubmit(lineItems.vaps, shouldClearOnSubmit);
|
||||
const payloadFeeItems = setClearOnSubmit(lineItems.feeItems, shouldClearOnSubmit);
|
||||
|
||||
const payload = {
|
||||
applicationUser: {
|
||||
|
|
@ -1352,7 +1353,7 @@ export const useMainStore = defineStore({
|
|||
lineItems: {
|
||||
glassParts: payloadGlassParts,
|
||||
serverData: lineItems.serverData,
|
||||
supportingItems: payloadSupportingItems,
|
||||
supportingItems: [...payloadSupportingItems, ...payloadFeeItems],
|
||||
vaps: payloadVapsItems
|
||||
},
|
||||
insuranceCoverage: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue