@bookipi/htmlgenerator 1.12.0-alpha7 → 1.12.0-alpha9

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.
@@ -140,6 +140,7 @@ var en = (_deposit_due$terms$pr = {
140
140
  enter_date: 'Enter date',
141
141
  add_customer: 'Add Customer',
142
142
  item: 'Item',
143
+ items: 'Items',
143
144
  add_item: 'Add Item',
144
145
  total: 'Total',
145
146
  subtotal: 'Subtotal',
@@ -11835,6 +11836,11 @@ var util = {
11835
11836
  parseCurrencyString: parseCurrencyString,
11836
11837
  formatterBuilder: formatterBuilder
11837
11838
  };
11839
+
11840
+ var index = {
11841
+ currencies: currencies,
11842
+ numberFormat: numberFormat
11843
+ };
11838
11844
  //# sourceMappingURL=index.modern.js.map
11839
11845
 
11840
11846
  var TWO_DECIMAL_TOLERANCE = 0.01;
@@ -11890,6 +11896,12 @@ var getEInvoiceTaxLabel = function getEInvoiceTaxLabel(company, defaultLang) {
11890
11896
  return (_ref = (_ref2 = configLabel != null ? configLabel : defaultLang === null || defaultLang === void 0 ? void 0 : defaultLang.vat) != null ? _ref2 : defaultLang === null || defaultLang === void 0 ? void 0 : defaultLang.tax) != null ? _ref : 'Tax';
11891
11897
  };
11892
11898
 
11899
+ var currencies$1 = index.currencies;
11900
+ var roundNumber$1 = function roundNumber(number, scale) {
11901
+ var multiplier = Math.pow(10, scale);
11902
+ return Math.round((number + Number.EPSILON) * multiplier) / multiplier;
11903
+ };
11904
+
11893
11905
  var checkHasShippingTaxRate = function checkHasShippingTaxRate(document) {
11894
11906
  return document.shippingTaxRate != null && document.shippingTaxRate !== '';
11895
11907
  };
@@ -11901,25 +11913,74 @@ var computeShippingTax = function computeShippingTax(document) {
11901
11913
  }
11902
11914
  return document.ti ? shipping * (1 - 1 / (1 + rate / 100)) : shipping * rate / 100;
11903
11915
  };
11904
- var getShippingTaxBreakdown = function getShippingTaxBreakdown(document) {
11916
+ var computeItemTaxes = function computeItemTaxes(document) {
11917
+ var taxPercent1 = document.tp ? parseFloat(document.tp) : 0;
11918
+ var taxPercent2 = document.tp2 ? parseFloat(document.tp2) : 0;
11919
+ var itemTax1 = 0;
11920
+ var itemTax2 = 0;
11921
+ var items = Array.isArray(document.it) ? document.it : [];
11922
+ items.forEach(function (item) {
11923
+ var amount = Number(item === null || item === void 0 ? void 0 : item.t) || 0;
11924
+ var isTaxed1 = (item === null || item === void 0 ? void 0 : item.tx) != null ? item.tx : true;
11925
+ var isTaxed2 = (item === null || item === void 0 ? void 0 : item.tx2) != null ? item.tx2 : true;
11926
+ if (taxPercent1 > 0 && isTaxed1) {
11927
+ if (document.ti && !document.t1d) {
11928
+ var alsoTaxed2 = document.ttx && taxPercent2 > 0 && isTaxed2 && !document.t2d;
11929
+ var totalTaxRate = alsoTaxed2 ? taxPercent1 + taxPercent2 : taxPercent1;
11930
+ itemTax1 += amount * (1 - 1 / (1 + totalTaxRate / 100)) * (taxPercent1 / totalTaxRate);
11931
+ } else {
11932
+ itemTax1 += amount * taxPercent1 / 100;
11933
+ }
11934
+ }
11935
+ if (document.ttx && taxPercent2 > 0 && isTaxed2) {
11936
+ if (document.ti && !document.t2d) {
11937
+ var _totalTaxRate = isTaxed1 ? taxPercent1 + taxPercent2 : taxPercent2;
11938
+ itemTax2 += amount * (1 - 1 / (1 + _totalTaxRate / 100)) * (taxPercent2 / _totalTaxRate);
11939
+ } else {
11940
+ itemTax2 += amount * taxPercent2 / 100;
11941
+ }
11942
+ }
11943
+ });
11944
+ return {
11945
+ itemTax1: itemTax1,
11946
+ itemTax2: itemTax2
11947
+ };
11948
+ };
11949
+ var getShippingTaxBreakdown = function getShippingTaxBreakdown(document, currencyCode) {
11905
11950
  var hasShippingTaxRate = checkHasShippingTaxRate(document);
11906
11951
  var shippingTaxRate = hasShippingTaxRate ? parseFloat(document.shippingTaxRate) : 0;
11952
+ var shipping = document.sp ? parseFloat(document.sp) : 0;
11953
+ var tax1 = document.tx ? parseFloat(document.tx) : 0;
11954
+ var tax2 = document.tx2 ? parseFloat(document.tx2) : 0;
11955
+ var _computeItemTaxes = computeItemTaxes(document),
11956
+ itemTax1 = _computeItemTaxes.itemTax1,
11957
+ itemTax2 = _computeItemTaxes.itemTax2;
11958
+ var _ref = currencies$1[currencyCode] || currencies$1.USD,
11959
+ decimal_digits = _ref.decimal_digits;
11907
11960
  var shippingTax = computeShippingTax(document);
11908
- var itemTax1 = document.tx ? parseFloat(document.tx) : 0;
11909
- var itemTax2 = document.tx2 ? parseFloat(document.tx2) : 0;
11910
- var shippingMatchesTax1 = hasShippingTaxRate && shippingTaxRate > 0 && !document.sntx && shippingTaxRate === parseFloat(document.tp || 0);
11911
- var shippingMatchesTax2 = hasShippingTaxRate && shippingTaxRate > 0 && !document.sntx && !!document.ttx && shippingTaxRate === parseFloat(document.tp2 || 0) && !shippingMatchesTax1;
11912
- var showTax1SubBreakdown = shippingMatchesTax1 && !!shippingTax;
11913
- var showTax2SubBreakdown = shippingMatchesTax2 && !!shippingTax;
11961
+ shippingTax = roundNumber$1(shippingTax, decimal_digits);
11962
+ var shippingMatchesTax1 = hasShippingTaxRate && shippingTaxRate > 0 && !document.sntx && shippingTaxRate === parseFloat(document.tp || 0) && tax1 > 0;
11963
+ var shippingMatchesTax2 = hasShippingTaxRate && shippingTaxRate > 0 && !document.sntx && !!document.ttx && shippingTaxRate === parseFloat(document.tp2 || 0) && tax2 > 0 && !shippingMatchesTax1;
11964
+ var shippingFoldedIn = !hasShippingTaxRate && !!shipping && !document.sntx;
11965
+ var showTax1SubBreakdown = shippingFoldedIn && tax1 > itemTax1 || shippingMatchesTax1 && !!shippingTax;
11966
+ var showTax2SubBreakdown = shippingFoldedIn && !(document.t2d && document.t2di) && tax2 > itemTax2 || shippingMatchesTax2 && !!shippingTax;
11914
11967
  var showSeparateShippingLine = hasShippingTaxRate && shippingTaxRate > 0 && !document.sntx && !shippingMatchesTax1 && !shippingMatchesTax2 && !!shippingTax;
11915
11968
  return {
11916
11969
  hasShippingTaxRate: hasShippingTaxRate,
11917
11970
  shippingTaxRate: shippingTaxRate,
11918
11971
  shippingTax: shippingTax,
11972
+ tax1: tax1,
11973
+ tax2: tax2,
11919
11974
  itemTax1: itemTax1,
11920
11975
  itemTax2: itemTax2,
11921
11976
  shippingMatchesTax1: shippingMatchesTax1,
11922
11977
  shippingMatchesTax2: shippingMatchesTax2,
11978
+ tax1Amount: shippingMatchesTax1 ? tax1 + shippingTax : tax1,
11979
+ tax2Amount: shippingMatchesTax2 ? tax2 + shippingTax : tax2,
11980
+ tax1ItemsAmount: shippingMatchesTax1 ? tax1 : itemTax1,
11981
+ tax1ShippingAmount: shippingMatchesTax1 ? shippingTax : tax1 - itemTax1,
11982
+ tax2ItemsAmount: shippingMatchesTax2 ? tax2 : itemTax2,
11983
+ tax2ShippingAmount: shippingMatchesTax2 ? shippingTax : tax2 - itemTax2,
11923
11984
  showTax1SubBreakdown: showTax1SubBreakdown,
11924
11985
  showTax2SubBreakdown: showTax2SubBreakdown,
11925
11986
  showSeparateShippingLine: showSeparateShippingLine
@@ -12053,15 +12114,15 @@ var InvoiceContent = function InvoiceContent(_ref) {
12053
12114
  var effectiveCurrency = document.currency || company.cr;
12054
12115
  var eInvoiceTaxLines = getEInvoiceTaxLines(document);
12055
12116
  var eInvoiceTaxRowLabel = getEInvoiceTaxLabel(company, defaultLang);
12056
- var shippingBreakdown = getShippingTaxBreakdown(document);
12117
+ var shippingBreakdown = getShippingTaxBreakdown(document, effectiveCurrency);
12057
12118
  var formatAmount = function formatAmount(amount) {
12058
12119
  return FormatCurrency$3(amount, effectiveCurrency, company.la, company.cf);
12059
12120
  };
12060
12121
  var shippingLabel = company.r_sp ? company.r_sp : defaultLang['shipping'];
12061
12122
  var subBreakdownRows = function subBreakdownRows(itemsAmount, shippingAmount) {
12062
- return "<tr>\n <td class=\"text-md-right\" width=\"22%\" style=\"padding-left: 24px;\">" + defaultLang['item'] + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(itemsAmount) + "</td>\n </tr>\n <tr>\n <td class=\"text-md-right\" width=\"22%\" style=\"padding-left: 24px;\">" + shippingLabel + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(shippingAmount) + "</td>\n </tr>";
12123
+ return "<tr>\n <td class=\"text-md-right\" width=\"22%\" style=\"padding-left: 24px;\">" + defaultLang['items'] + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(itemsAmount) + "</td>\n </tr>\n <tr>\n <td class=\"text-md-right\" width=\"22%\" style=\"padding-left: 24px;\">" + shippingLabel + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(shippingAmount) + "</td>\n </tr>";
12063
12124
  };
12064
- var defaultTaxRows = "" + (document.tx != 0 ? "<tr>\n <td class=\"text-md-right\" width=\"22%\">" + ("" + displayTaxName1 + taxIncluded1 + "(" + document.tp + "%)") + "</td>\n <td class=\"text-right\" width=\"22%\">" + ("" + (document.t1d ? '(' : '') + formatAmount(shippingBreakdown.shippingMatchesTax1 ? shippingBreakdown.itemTax1 + shippingBreakdown.shippingTax : document.tx) + (document.t1d ? ')' : '')) + "</td>\n </tr>" + (shippingBreakdown.showTax1SubBreakdown ? subBreakdownRows(shippingBreakdown.itemTax1, shippingBreakdown.shippingTax) : '') : '') + (document.ttx && document.tx2 != 0 ? "<tr>\n <td class=\"text-md-right\" width=\"22%\">" + ("" + displayTaxName2 + taxIncluded2 + "(" + document.tp2 + "%)") + "</td>\n <td class=\"text-right\" width=\"22%\">" + ("" + (document.t2d ? '(' : '') + formatAmount(shippingBreakdown.shippingMatchesTax2 ? shippingBreakdown.itemTax2 + shippingBreakdown.shippingTax : document.tx2) + (document.t2d ? ')' : '')) + "</td>\n </tr>" + (shippingBreakdown.showTax2SubBreakdown ? subBreakdownRows(shippingBreakdown.itemTax2, shippingBreakdown.shippingTax) : '') : '') + (shippingBreakdown.showSeparateShippingLine ? "<tr>\n <td class=\"text-md-right\" width=\"22%\">" + (shippingLabel + " " + defaultLang['tax'] + (document.ti ? ' ' + defaultLang['included'] : '') + " (" + formatTaxRate(shippingBreakdown.shippingTaxRate, company.la) + "%)") + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(shippingBreakdown.shippingTax) + "</td>\n </tr>" : '');
12125
+ var defaultTaxRows = "" + (document.tx != 0 ? "<tr>\n <td class=\"text-md-right\" width=\"22%\">" + ("" + displayTaxName1 + taxIncluded1 + "(" + document.tp + "%)") + "</td>\n <td class=\"text-right\" width=\"22%\">" + ("" + (document.t1d ? '(' : '') + formatAmount(shippingBreakdown.tax1Amount) + (document.t1d ? ')' : '')) + "</td>\n </tr>" + (shippingBreakdown.showTax1SubBreakdown ? subBreakdownRows(shippingBreakdown.tax1ItemsAmount, shippingBreakdown.tax1ShippingAmount) : '') : '') + (document.ttx && document.tx2 != 0 ? "<tr>\n <td class=\"text-md-right\" width=\"22%\">" + ("" + displayTaxName2 + taxIncluded2 + "(" + document.tp2 + "%)") + "</td>\n <td class=\"text-right\" width=\"22%\">" + ("" + (document.t2d ? '(' : '') + formatAmount(shippingBreakdown.tax2Amount) + (document.t2d ? ')' : '')) + "</td>\n </tr>" + (shippingBreakdown.showTax2SubBreakdown ? subBreakdownRows(shippingBreakdown.tax2ItemsAmount, shippingBreakdown.tax2ShippingAmount) : '') : '') + (shippingBreakdown.showSeparateShippingLine ? "<tr>\n <td class=\"text-md-right\" width=\"22%\">" + (shippingLabel + " " + defaultLang['tax'] + (document.ti ? ' ' + defaultLang['included'] : '') + " (" + formatTaxRate(shippingBreakdown.shippingTaxRate, company.la) + "%)") + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(shippingBreakdown.shippingTax) + "</td>\n </tr>" : '');
12065
12126
  var taxBreakdownRows = !eInvoiceTaxLines ? defaultTaxRows : isTaxSummaryMatching(eInvoiceTaxLines, document) ? eInvoiceTaxLines.map(function (line) {
12066
12127
  return "<tr>\n <td class=\"text-md-right\" width=\"22%\">" + (eInvoiceTaxRowLabel + " (" + formatTaxRate(line.rate, company.la) + "%)") + "</td>\n <td class=\"text-right\" width=\"22%\">" + FormatCurrency$3(line.taxAmount, effectiveCurrency, company.la, company.cf) + "</td>\n </tr>";
12067
12128
  }).join('') : "<tr>\n <td class=\"text-md-right\" width=\"22%\">" + (defaultLang['total_tax'] || 'Total tax') + "</td>\n <td class=\"text-right\" width=\"22%\">" + FormatCurrency$3(document.tx || 0, effectiveCurrency, company.la, company.cf) + "</td>\n </tr>";
@@ -12431,6 +12492,7 @@ var getDefaultLang = function getDefaultLang(t, lang) {
12431
12492
  price: t ? t('Price') : lang['price'],
12432
12493
  quantity: t ? t('Quantity') : lang['quantity'],
12433
12494
  item: t ? t('Item') : lang['item'],
12495
+ items: t ? t('Items') : lang['items'] || lang['item'],
12434
12496
  number: t ? t('Number') : lang['number'],
12435
12497
  po_number: t ? t('PO Number') : lang['po_number'],
12436
12498
  due_date: t ? t('Due date') : lang['due_date'],
@@ -12900,15 +12962,15 @@ var InvoiceContent$1 = function InvoiceContent(_ref) {
12900
12962
  var effectiveCurrency = document.currency || company.cr;
12901
12963
  var eInvoiceTaxLines = getEInvoiceTaxLines(document);
12902
12964
  var eInvoiceTaxRowLabel = getEInvoiceTaxLabel(company, defaultLang);
12903
- var shippingBreakdown = getShippingTaxBreakdown(document);
12965
+ var shippingBreakdown = getShippingTaxBreakdown(document, effectiveCurrency);
12904
12966
  var formatAmount = function formatAmount(amount) {
12905
12967
  return FormatCurrency$7(amount, effectiveCurrency, company.la, company.cf);
12906
12968
  };
12907
12969
  var shippingLabel = company.r_sp ? company.r_sp : defaultLang['shipping'];
12908
12970
  var subBreakdownRows = function subBreakdownRows(itemsAmount, shippingAmount) {
12909
- return "<tr>\n <td width=\"22%\" style=\"padding-left: 24px;\">" + defaultLang['item'] + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(itemsAmount) + "</td>\n </tr>\n <tr>\n <td width=\"22%\" style=\"padding-left: 24px;\">" + shippingLabel + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(shippingAmount) + "</td>\n </tr>";
12971
+ return "<tr>\n <td width=\"22%\" style=\"padding-left: 24px;\">" + defaultLang['items'] + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(itemsAmount) + "</td>\n </tr>\n <tr>\n <td width=\"22%\" style=\"padding-left: 24px;\">" + shippingLabel + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(shippingAmount) + "</td>\n </tr>";
12910
12972
  };
12911
- var defaultTaxRows = "" + (document.tx != 0 ? "<tr>\n <td width=\"22%\">" + (displayTaxName1 + taxIncluded1 + '(' + document.tp + '%)') + "</td>\n <td class=\"text-right\" width=\"22%\">" + ((document.t1d ? '(' : '') + formatAmount(shippingBreakdown.shippingMatchesTax1 ? shippingBreakdown.itemTax1 + shippingBreakdown.shippingTax : document.tx) + (document.t1d ? ')' : '')) + "</td>\n </tr>" + (shippingBreakdown.showTax1SubBreakdown ? subBreakdownRows(shippingBreakdown.itemTax1, shippingBreakdown.shippingTax) : '') : '') + (document.ttx && document.tx2 != 0 ? "<tr>\n <td width=\"22%\">" + (displayTaxName2 + taxIncluded2 + '(' + document.tp2 + '%)') + "</td>\n <td class=\"text-right\" width=\"22%\">" + ((document.t2d ? '(' : '') + formatAmount(shippingBreakdown.shippingMatchesTax2 ? shippingBreakdown.itemTax2 + shippingBreakdown.shippingTax : document.tx2) + (document.t2d ? ')' : '')) + "</td>\n </tr>" + (shippingBreakdown.showTax2SubBreakdown ? subBreakdownRows(shippingBreakdown.itemTax2, shippingBreakdown.shippingTax) : '') : '') + (shippingBreakdown.showSeparateShippingLine ? "<tr>\n <td width=\"22%\">" + (shippingLabel + ' ' + defaultLang['tax'] + (document.ti ? ' ' + defaultLang['included'] : '') + ' (' + formatTaxRate(shippingBreakdown.shippingTaxRate, company.la) + '%)') + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(shippingBreakdown.shippingTax) + "</td>\n </tr>" : '');
12973
+ var defaultTaxRows = "" + (document.tx != 0 ? "<tr>\n <td width=\"22%\">" + (displayTaxName1 + taxIncluded1 + '(' + document.tp + '%)') + "</td>\n <td class=\"text-right\" width=\"22%\">" + ((document.t1d ? '(' : '') + formatAmount(shippingBreakdown.tax1Amount) + (document.t1d ? ')' : '')) + "</td>\n </tr>" + (shippingBreakdown.showTax1SubBreakdown ? subBreakdownRows(shippingBreakdown.tax1ItemsAmount, shippingBreakdown.tax1ShippingAmount) : '') : '') + (document.ttx && document.tx2 != 0 ? "<tr>\n <td width=\"22%\">" + (displayTaxName2 + taxIncluded2 + '(' + document.tp2 + '%)') + "</td>\n <td class=\"text-right\" width=\"22%\">" + ((document.t2d ? '(' : '') + formatAmount(shippingBreakdown.tax2Amount) + (document.t2d ? ')' : '')) + "</td>\n </tr>" + (shippingBreakdown.showTax2SubBreakdown ? subBreakdownRows(shippingBreakdown.tax2ItemsAmount, shippingBreakdown.tax2ShippingAmount) : '') : '') + (shippingBreakdown.showSeparateShippingLine ? "<tr>\n <td width=\"22%\">" + (shippingLabel + ' ' + defaultLang['tax'] + (document.ti ? ' ' + defaultLang['included'] : '') + ' (' + formatTaxRate(shippingBreakdown.shippingTaxRate, company.la) + '%)') + "</td>\n <td class=\"text-right\" width=\"22%\">" + formatAmount(shippingBreakdown.shippingTax) + "</td>\n </tr>" : '');
12912
12974
  var taxBreakdownRows = !eInvoiceTaxLines ? defaultTaxRows : isTaxSummaryMatching(eInvoiceTaxLines, document) ? eInvoiceTaxLines.map(function (line) {
12913
12975
  return "<tr>\n <td width=\"22%\">" + (eInvoiceTaxRowLabel + ' (' + formatTaxRate(line.rate, company.la) + '%)') + "</td>\n <td class=\"text-right\" width=\"22%\">" + FormatCurrency$7(line.taxAmount, effectiveCurrency, company.la, company.cf) + "</td>\n </tr>";
12914
12976
  }).join('') : "<tr>\n <td width=\"22%\">" + (defaultLang['total_tax'] || 'Total tax') + "</td>\n <td class=\"text-right\" width=\"22%\">" + FormatCurrency$7(document.tx || 0, effectiveCurrency, company.la, company.cf) + "</td>\n </tr>";
@@ -13989,6 +14051,7 @@ var langJP = (_document$invoice$est = {
13989
14051
  amount: '金額',
13990
14052
  price: '価格',
13991
14053
  item: '項目',
14054
+ items: '項目',
13992
14055
  po_number: '発注番号',
13993
14056
  due_date: '支払期限',
13994
14057
  due: '期限'