Untitled

mail@pastecode.io avatar
unknown
typescript
a month ago
1.6 kB
1
Indexable
Never
  const sumDiscountAmountRat = sumValues(items.map(item => item.discount_amount_rat));
  const sumAdditionalAmountRat = sumValues(items.map(item => item.addition_amount_rat));

  console.log("*****");
  console.log(`Soma do rateio - desconto: ${sumDiscountAmountRat} / Valor esperado: ${DISCOUNT_AMOUNT_ORDER}`);
  console.log(`Soma do rateio - acréscimo: ${sumAdditionalAmountRat} / Valor esperado: ${ADDITIONAL_AMOUNT_ORDER}`);
  console.log("*****");

  const LAST_INDEX_ITEMS = items.length - 1;

  if (sumDiscountAmountRat !== DISCOUNT_AMOUNT_ORDER) {
    console.log('Ocorreu um ajuste no valor do rateio de desconto do último produto');
    console.log(`Valor antigo: ${items[LAST_INDEX_ITEMS].discount_amount_rat}`);

    const adjustmentValue = abntRounding(sumDiscountAmountRat - DISCOUNT_AMOUNT_ORDER);

    items[LAST_INDEX_ITEMS].discount_amount_rat = abntRounding(items[LAST_INDEX_ITEMS].discount_amount_rat - adjustmentValue);

    console.log(`Valor novo: ${items[LAST_INDEX_ITEMS].discount_amount_rat}`);
  }

  if (sumAdditionalAmountRat !== ADDITIONAL_AMOUNT_ORDER) {
    console.log('Ocorreu um ajuste no valor do rateio de acréscimo do último produto');
    console.log(`Valor antigo: ${items[LAST_INDEX_ITEMS].addition_amount_rat}`);

    const adjustmentValue = abntRounding(sumAdditionalAmountRat - ADDITIONAL_AMOUNT_ORDER);

    items[LAST_INDEX_ITEMS].addition_amount_rat = abntRounding(items[LAST_INDEX_ITEMS].addition_amount_rat - adjustmentValue);

    console.log(`Valor novo: ${items[LAST_INDEX_ITEMS].addition_amount_rat}`);
  }
Leave a Comment