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