@bookipi/htmlgenerator 1.13.0-alpha.3 → 1.13.0-alpha.4

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.
package/dist/index.js CHANGED
@@ -11966,7 +11966,11 @@ var getTaxCodeBreakdown = function getTaxCodeBreakdown(document, company, curren
11966
11966
  return (_ref2 = (_config$taxCodeRates$ = (_config$taxCodeRates = config.taxCodeRates) === null || _config$taxCodeRates === void 0 ? void 0 : _config$taxCodeRates[taxCode]) != null ? _config$taxCodeRates$ : Number(taxRate)) != null ? _ref2 : 0;
11967
11967
  };
11968
11968
  var items = Array.isArray(document === null || document === void 0 ? void 0 : document.it) ? document.it : [];
11969
- var inclusive = !!(document !== null && document !== void 0 && document.ti);
11969
+ var documentInclusive = !!(document !== null && document !== void 0 && document.ti);
11970
+ var isLineInclusive = function isLineInclusive(item) {
11971
+ return (item === null || item === void 0 ? void 0 : item.ti) != null ? !!item.ti : documentInclusive;
11972
+ };
11973
+ var shippingInclusive = (document === null || document === void 0 ? void 0 : document.shippingTi) != null ? !!document.shippingTi : documentInclusive;
11970
11974
  var itemsSubtotal = items.reduce(function (sum, item) {
11971
11975
  return sum + (Number(item === null || item === void 0 ? void 0 : item.t) || 0);
11972
11976
  }, 0);
@@ -11983,16 +11987,22 @@ var getTaxCodeBreakdown = function getTaxCodeBreakdown(document, company, curren
11983
11987
  return share;
11984
11988
  });
11985
11989
  var buckets = new Map();
11986
- var bucketFor = function bucketFor(taxCode, ratePercent) {
11987
- if (!buckets.has(taxCode)) {
11988
- buckets.set(taxCode, {
11990
+ var bucketFor = function bucketFor(taxCode, ratePercent, inclusive) {
11991
+ var key = taxCode + "|" + (inclusive ? 'in' : 'on');
11992
+ if (!buckets.has(key)) {
11993
+ buckets.set(key, {
11989
11994
  taxCode: taxCode,
11990
11995
  ratePercent: ratePercent,
11996
+ inclusive: inclusive,
11991
11997
  itemsAmount: 0,
11992
11998
  shippingAmount: 0
11993
11999
  });
11994
12000
  }
11995
- return buckets.get(taxCode);
12001
+ return buckets.get(key);
12002
+ };
12003
+ var addToBucket = function addToBucket(taxCode, rate, base, inclusive, key) {
12004
+ var mode = rate > 0 && inclusive;
12005
+ bucketFor(taxCode, rate, mode)[key] += vatOnBase(base, rate, mode);
11996
12006
  };
11997
12007
  items.forEach(function (item, index) {
11998
12008
  if (!(item !== null && item !== void 0 && item.taxCode)) {
@@ -12001,25 +12011,26 @@ var getTaxCodeBreakdown = function getTaxCodeBreakdown(document, company, curren
12001
12011
  var base = Number(item.t) || 0;
12002
12012
  var share = discountShares[index];
12003
12013
  var rate = rateFor(item.taxCode, item.taxRate) || 0;
12004
- bucketFor(item.taxCode, rate).itemsAmount += vatOnBase(base - share, rate, inclusive);
12014
+ addToBucket(item.taxCode, rate, base - share, isLineInclusive(item), 'itemsAmount');
12005
12015
  });
12006
12016
  var shipping = document !== null && document !== void 0 && document.sp && !(document !== null && document !== void 0 && document.sntx) ? parseFloat(document.sp) : 0;
12007
12017
  if (shipping && document !== null && document !== void 0 && document.shippingTaxCode) {
12008
12018
  var rate = rateFor(document.shippingTaxCode, document.shippingTaxRate) || 0;
12009
- bucketFor(document.shippingTaxCode, rate).shippingAmount += vatOnBase(shipping, rate, inclusive);
12019
+ addToBucket(document.shippingTaxCode, rate, shipping, shippingInclusive, 'shippingAmount');
12010
12020
  }
12011
12021
  return Array.from(buckets.values()).map(function (bucket) {
12012
12022
  var itemsAmount = round(bucket.itemsAmount);
12013
12023
  var shippingAmount = round(bucket.shippingAmount);
12024
+ var amount = round(itemsAmount + shippingAmount);
12014
12025
  return _extends({}, bucket, {
12015
12026
  itemsAmount: itemsAmount,
12016
12027
  shippingAmount: shippingAmount,
12017
- amount: round(itemsAmount + shippingAmount),
12018
- included: inclusive,
12028
+ amount: amount,
12029
+ included: bucket.inclusive,
12019
12030
  showSubBreakdown: itemsAmount > 0 && shippingAmount > 0
12020
12031
  });
12021
12032
  }).sort(function (a, b) {
12022
- return b.ratePercent - a.ratePercent;
12033
+ return b.ratePercent - a.ratePercent || Number(b.included) - Number(a.included);
12023
12034
  });
12024
12035
  };
12025
12036
  var getTaxCodeRowLabel = function getTaxCodeRowLabel(entry, _ref3) {