@shushed/helpers 0.0.205-fix-erp-729-20251209153416 → 0.0.205-fix-erp-729-20251209155235

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -464,7 +464,24 @@ function transformMasterOrder(payload) {
464
464
  const invoicesGrossMinorWithDelivery = toMinorUnits((payload.invoices || []).reduce((acc, inv) => acc + (inv.amount_incl_vat || 0), 0));
465
465
  let nonInvSalesNetMinorWithDelivery = 0;
466
466
  let nonInvSalesGrossMinorWithDelivery = 0;
467
- if (sale0 && (sale0.amount_excl_vat || sale0.amount_incl_vat)) {
467
+ if (sale0?.sale_lines && sale0.sale_lines.length > 0) {
468
+ const allSaleLinesWithDelivery = (sale0.sale_lines || []).filter((l) => {
469
+ if (String(l?.type || '').toLowerCase() !== 'item')
470
+ return false;
471
+ return true;
472
+ });
473
+ const totalSaleNetMinorWithDelivery = toMinorUnits(allSaleLinesWithDelivery.reduce((acc, l) => acc + (Number(l?.amount || 0)), 0));
474
+ const totalSaleGrossMinorWithDelivery = toMinorUnits(allSaleLinesWithDelivery.reduce((acc, l) => acc + (Number(l?.amount_including_vat || 0)), 0));
475
+ if (invoicesGrossMinorWithDelivery > 0) {
476
+ nonInvSalesNetMinorWithDelivery = Math.max(0, totalSaleNetMinorWithDelivery - invoicesNetMinorWithDelivery);
477
+ nonInvSalesGrossMinorWithDelivery = Math.max(0, totalSaleGrossMinorWithDelivery - invoicesGrossMinorWithDelivery);
478
+ }
479
+ else {
480
+ nonInvSalesNetMinorWithDelivery = totalSaleNetMinorWithDelivery;
481
+ nonInvSalesGrossMinorWithDelivery = totalSaleGrossMinorWithDelivery;
482
+ }
483
+ }
484
+ else if (sale0 && (sale0.amount_excl_vat || sale0.amount_incl_vat)) {
468
485
  const saleNetMinor = toMinorUnits(sale0.amount_excl_vat || 0);
469
486
  const saleGrossMinor = toMinorUnits(sale0.amount_incl_vat || 0);
470
487
  if (invoicesGrossMinorWithDelivery > 0) {
@@ -476,6 +493,16 @@ function transformMasterOrder(payload) {
476
493
  nonInvSalesGrossMinorWithDelivery = saleGrossMinor;
477
494
  }
478
495
  }
496
+ else {
497
+ const nonInvoicedSalesWithDelivery = (sale0?.sale_lines || []).filter((l) => {
498
+ if (String(l?.type || '').toLowerCase() !== 'item')
499
+ return false;
500
+ const lineNo = Number(l?.line_no || -1);
501
+ return !invoicedLineNos.has(lineNo);
502
+ });
503
+ nonInvSalesNetMinorWithDelivery = toMinorUnits(nonInvoicedSalesWithDelivery.reduce((acc, l) => acc + (Number(l?.amount || 0)), 0));
504
+ nonInvSalesGrossMinorWithDelivery = toMinorUnits(nonInvoicedSalesWithDelivery.reduce((acc, l) => acc + (Number(l?.amount_including_vat || 0)), 0));
505
+ }
479
506
  const totalNetMinorWithDelivery = invoicesNetMinorWithDelivery + nonInvSalesNetMinorWithDelivery;
480
507
  const totalGrossMinorWithDelivery = invoicesGrossMinorWithDelivery + nonInvSalesGrossMinorWithDelivery;
481
508
  const total = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.205-fix-erp-729-20251209153416",
3
+ "version": "0.0.205-fix-erp-729-20251209155235",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",