@bookipi/htmlgenerator 1.14.1-alpha.5 → 1.14.1-alpha.6
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 +68 -22
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +68 -22
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -11975,7 +11975,8 @@ var DEFAULT_CONFIG = {
|
|
|
11975
11975
|
|
|
11976
11976
|
/** French e-invoice rules; other French documents use the default config. */
|
|
11977
11977
|
var FRANCE_E_INVOICE_CONFIG = {
|
|
11978
|
-
// Our server rejects a negative subtotal before the PDP
|
|
11978
|
+
// Our server rejects a negative subtotal before the PDP, so a line discount stops at 0. A
|
|
11979
|
+
// negative price stays a negative line; Factur-X writes it as a negative quantity (BR-27).
|
|
11979
11980
|
allowNegativeLines: false,
|
|
11980
11981
|
// Factur-X has no after-tax discount, so the app hides "After-tax" on French e-invoices.
|
|
11981
11982
|
allowDiscountAfterTax: false,
|
|
@@ -12061,7 +12062,9 @@ var getCountryConfig = function getCountryConfig(countryCode, _temp) {
|
|
|
12061
12062
|
var code = (countryCode || "").toUpperCase();
|
|
12062
12063
|
return _extends$1({}, DEFAULT_CONFIG, COUNTRY_CONFIGS[code] && _extends$1({
|
|
12063
12064
|
countryCode: code
|
|
12064
|
-
}, COUNTRY_CONFIGS[code]), eInvoice && E_INVOICE_CONFIGS[code]
|
|
12065
|
+
}, COUNTRY_CONFIGS[code]), eInvoice && E_INVOICE_CONFIGS[code] && _extends$1({
|
|
12066
|
+
countryCode: code
|
|
12067
|
+
}, E_INVOICE_CONFIGS[code]));
|
|
12065
12068
|
};
|
|
12066
12069
|
|
|
12067
12070
|
/** E-invoice tax codes per country; a country listed here taxes its e-invoices by code. */
|
|
@@ -13866,9 +13869,10 @@ var currencies = {
|
|
|
13866
13869
|
|
|
13867
13870
|
var currencyTable = currencies;
|
|
13868
13871
|
|
|
13869
|
-
/** The code when it is a known currency, otherwise USD. */
|
|
13872
|
+
/** The upper-case code when it is a known currency, otherwise USD. */
|
|
13870
13873
|
var getCurrencyCode = function getCurrencyCode(currencyCode) {
|
|
13871
|
-
|
|
13874
|
+
var code = (currencyCode || "").toUpperCase();
|
|
13875
|
+
return currencyTable[code] ? code : "USD";
|
|
13872
13876
|
};
|
|
13873
13877
|
|
|
13874
13878
|
/** Digits after the decimal point. Unknown codes use USD. */
|
|
@@ -13984,14 +13988,29 @@ var calculateAdjustment = function calculateAdjustment(adjustment, base) {
|
|
|
13984
13988
|
};
|
|
13985
13989
|
|
|
13986
13990
|
/**
|
|
13987
|
-
* Splits `amount` across `weights` pro rata; no share exceeds its weight, and weights
|
|
13991
|
+
* Splits `amount` across `weights` pro rata; no share exceeds its weight, and weights of the
|
|
13992
|
+
* other sign (or 0) get none. A negative amount (a discount on a negative document) is split
|
|
13993
|
+
* over the negative weights the same way.
|
|
13988
13994
|
* With `decimals`, shares are rounded so they still add up exactly (largest remainder method).
|
|
13989
13995
|
*/
|
|
13990
|
-
var
|
|
13996
|
+
var _allocateProportionally = function allocateProportionally(amount, weights, decimals) {
|
|
13997
|
+
if (amount.lt(0)) {
|
|
13998
|
+
var _allocateProportional = _allocateProportionally(amount.neg(), weights.map(function (weight) {
|
|
13999
|
+
return weight.neg();
|
|
14000
|
+
}), decimals),
|
|
14001
|
+
shares = _allocateProportional.shares,
|
|
14002
|
+
excess = _allocateProportional.excess;
|
|
14003
|
+
return {
|
|
14004
|
+
shares: shares.map(function (share) {
|
|
14005
|
+
return share.neg();
|
|
14006
|
+
}),
|
|
14007
|
+
excess: excess.neg()
|
|
14008
|
+
};
|
|
14009
|
+
}
|
|
13991
14010
|
var noShares = weights.map(function () {
|
|
13992
14011
|
return ZERO;
|
|
13993
14012
|
});
|
|
13994
|
-
if (amount.
|
|
14013
|
+
if (amount.eq(0)) return {
|
|
13995
14014
|
shares: noShares,
|
|
13996
14015
|
excess: ZERO
|
|
13997
14016
|
};
|
|
@@ -14059,10 +14078,11 @@ var allocateDocumentDiscount = function allocateDocumentDiscount(_ref) {
|
|
|
14059
14078
|
shipping = _ref.shipping,
|
|
14060
14079
|
decimals = _ref.decimals;
|
|
14061
14080
|
var taxableDiscount = documentDiscount != null && documentDiscount.afterTax ? ZERO : discount;
|
|
14062
|
-
var _allocateProportional =
|
|
14081
|
+
var _allocateProportional = _allocateProportionally(taxableDiscount, lineAmounts, decimals),
|
|
14063
14082
|
shares = _allocateProportional.shares,
|
|
14064
14083
|
excess = _allocateProportional.excess;
|
|
14065
|
-
|
|
14084
|
+
// Only a positive discount left over lowers a positive shipping cost.
|
|
14085
|
+
var shippingShare = shipping.gt(0) && excess.gt(0) ? excess.gt(shipping) ? shipping : excess : ZERO;
|
|
14066
14086
|
return {
|
|
14067
14087
|
lineShares: shares,
|
|
14068
14088
|
shippingShare: shippingShare
|
|
@@ -14092,6 +14112,7 @@ var calculatePaymentSummary = function calculatePaymentSummary(_ref) {
|
|
|
14092
14112
|
total = _ref.total,
|
|
14093
14113
|
decimals = _ref.decimals,
|
|
14094
14114
|
isInvoice = _ref.isInvoice,
|
|
14115
|
+
hasLines = _ref.hasLines,
|
|
14095
14116
|
round = _ref.round;
|
|
14096
14117
|
var surchargeRate;
|
|
14097
14118
|
var totalPayment = round(sumMonetaryDecimals(payments.map(function (payment) {
|
|
@@ -14108,9 +14129,9 @@ var calculatePaymentSummary = function calculatePaymentSummary(_ref) {
|
|
|
14108
14129
|
var amountAfterPayment = amountBeforePayment.minus(totalPayment);
|
|
14109
14130
|
|
|
14110
14131
|
// Within one minor unit counts as fully paid, matching the legacy +0.01 tolerance.
|
|
14111
|
-
//
|
|
14132
|
+
// Nothing owed (e.g. a 100% discount) is paid; an empty document with no payment is not.
|
|
14112
14133
|
var tolerance = new MonetaryDecimal(10).pow(-decimals);
|
|
14113
|
-
var isPaid = totalPayment.gt(0) && totalPayment.plus(tolerance).gte(amountBeforePayment);
|
|
14134
|
+
var isPaid = (totalPayment.gt(0) || hasLines && amountBeforePayment.lte(0)) && totalPayment.plus(tolerance).gte(amountBeforePayment);
|
|
14114
14135
|
var paymentStatus = isPaid ? 2 : totalPayment.eq(0) ? 0 : 1;
|
|
14115
14136
|
return {
|
|
14116
14137
|
totalPayment: totalPayment,
|
|
@@ -14401,6 +14422,7 @@ var calculate = function calculate(document, options) {
|
|
|
14401
14422
|
total: total,
|
|
14402
14423
|
decimals: decimals,
|
|
14403
14424
|
isInvoice: !!document.isInvoice,
|
|
14425
|
+
hasLines: lineItems.length > 0,
|
|
14404
14426
|
round: round
|
|
14405
14427
|
});
|
|
14406
14428
|
return {
|
|
@@ -14764,21 +14786,43 @@ var calculateEN16931Totals = function calculateEN16931Totals(document, company)
|
|
|
14764
14786
|
if (eInvoiceStandard !== "en16931") {
|
|
14765
14787
|
throw new Error("calculateEN16931Totals: \"" + (countryCode || "") + "\" has no EN 16931 e-invoice.");
|
|
14766
14788
|
}
|
|
14789
|
+
var taxCodes = getTaxCodes(countryCode);
|
|
14790
|
+
var findTaxCode = function findTaxCode(code) {
|
|
14791
|
+
return taxCodes.find(function (taxCode) {
|
|
14792
|
+
return taxCode.code === code;
|
|
14793
|
+
});
|
|
14794
|
+
};
|
|
14795
|
+
// Every amount needs a listed code: an uncoded line has no VAT breakdown, and an unlisted
|
|
14796
|
+
// code has no VAT category, so the totals would not reconcile. Untaxed shipping keeps no
|
|
14797
|
+
// code (toCalcDocument drops it; it is reported as untaxedChargeTaxCode), so it is not checked.
|
|
14798
|
+
var lineItems = readField(document.it, document.items) || [];
|
|
14799
|
+
var shippingNonTaxable = !!readField(document.sntx, document.shippingNonTax);
|
|
14800
|
+
var shippingTaxCode = shippingNonTaxable ? null : document.shippingTaxCode;
|
|
14801
|
+
var unlistedCodes = [].concat(lineItems.map(function (lineItem) {
|
|
14802
|
+
return lineItem.taxCode;
|
|
14803
|
+
}), shippingTaxCode || !shippingNonTaxable && toMonetaryDecimal(readField(document.sp, document.shippingCost)).gt(0) ? [shippingTaxCode] : []).filter(function (code) {
|
|
14804
|
+
return !findTaxCode(code);
|
|
14805
|
+
});
|
|
14806
|
+
if (unlistedCodes.length > 0) {
|
|
14807
|
+
throw new Error("calculateEN16931Totals: every line needs a \"" + countryCode + "\" tax code; got " + unlistedCodes.map(function (code) {
|
|
14808
|
+
return JSON.stringify(code != null ? code : null);
|
|
14809
|
+
}).join(", ") + ".");
|
|
14810
|
+
}
|
|
14767
14811
|
var _calculateDocumentWit = calculateDocumentWith(document, company, {}, {
|
|
14768
14812
|
eInvoice: true,
|
|
14769
14813
|
taxCodeRates: getTaxCodeRates(countryCode)
|
|
14770
14814
|
}),
|
|
14771
14815
|
calculation = _calculateDocumentWit.result;
|
|
14816
|
+
// A discount past the items and shipping leaves a negative total on zero tax bases, which
|
|
14817
|
+
// cannot reconcile (BT-112 = BT-109 + BT-110); that is a credit note, not an invoice.
|
|
14818
|
+
var discountable = new MonetaryDecimal(calculation.subtotal).plus(calculation.shipping);
|
|
14819
|
+
if (new MonetaryDecimal(calculation.discount).gt(discountable)) {
|
|
14820
|
+
throw new Error("calculateEN16931Totals: the discount (" + calculation.discount + ") is more than the items and shipping (" + discountable.toNumber() + ").");
|
|
14821
|
+
}
|
|
14772
14822
|
var decimals = calculation.decimals;
|
|
14773
14823
|
var round = function round(amount) {
|
|
14774
14824
|
return roundMonetaryDecimal(amount, decimals, calculation.config.roundingMethod);
|
|
14775
14825
|
};
|
|
14776
|
-
var taxCodes = getTaxCodes(countryCode);
|
|
14777
|
-
var findTaxCode = function findTaxCode(code) {
|
|
14778
|
-
return taxCodes.find(function (taxCode) {
|
|
14779
|
-
return taxCode.code === code;
|
|
14780
|
-
});
|
|
14781
|
-
};
|
|
14782
14826
|
|
|
14783
14827
|
// EN 16931 needs the line nets to add up to their tax code's basis to the cent.
|
|
14784
14828
|
var lineNets = calculation.lines.map(function (line) {
|
|
@@ -14853,15 +14897,15 @@ var calculateEN16931Totals = function calculateEN16931Totals(document, company)
|
|
|
14853
14897
|
return {
|
|
14854
14898
|
currency: calculation.currency,
|
|
14855
14899
|
decimals: decimals,
|
|
14900
|
+
// Every line has exactly one tax: its code, checked above.
|
|
14856
14901
|
lines: calculation.lines.map(function (line) {
|
|
14857
|
-
var _line$taxes$, _line$taxes$0$rate, _line$taxes$2, _line$taxes$3;
|
|
14858
14902
|
return {
|
|
14859
14903
|
index: line.index,
|
|
14860
14904
|
net: lineNets[line.index].toNumber(),
|
|
14861
14905
|
documentDiscount: line.documentDiscount,
|
|
14862
|
-
taxCode:
|
|
14863
|
-
rate:
|
|
14864
|
-
inclusive:
|
|
14906
|
+
taxCode: line.taxes[0].code,
|
|
14907
|
+
rate: line.taxes[0].rate,
|
|
14908
|
+
inclusive: line.taxes[0].inclusive
|
|
14865
14909
|
};
|
|
14866
14910
|
}),
|
|
14867
14911
|
shipping: shipping,
|
|
@@ -14920,11 +14964,13 @@ var calculateProposal = function calculateProposal(proposal, company) {
|
|
|
14920
14964
|
company = {};
|
|
14921
14965
|
}
|
|
14922
14966
|
var decimals = getCurrencyDecimals(company.cr || company.currency);
|
|
14967
|
+
var _getCountryConfig = getCountryConfig(company.co || company.country),
|
|
14968
|
+
roundingMethod = _getCountryConfig.roundingMethod;
|
|
14923
14969
|
var serviceItems = proposal.serviceItems,
|
|
14924
14970
|
proposalFields = _objectWithoutPropertiesLoose(proposal, _excluded$1);
|
|
14925
14971
|
var lineItems = (serviceItems || []).map(function (serviceItem) {
|
|
14926
14972
|
var discountPercentage = toMonetaryDecimal(serviceItem.discountPercentage);
|
|
14927
|
-
var discount = discountPercentage.gt(0) ? roundMonetaryDecimal(toMonetaryDecimal(serviceItem.price).times(toMonetaryDecimal(isBlank(serviceItem.quantity) ? 1 : serviceItem.quantity)).times(discountPercentage).div(100), decimals,
|
|
14973
|
+
var discount = discountPercentage.gt(0) ? roundMonetaryDecimal(toMonetaryDecimal(serviceItem.price).times(toMonetaryDecimal(isBlank(serviceItem.quantity) ? 1 : serviceItem.quantity)).times(discountPercentage).div(100), decimals, roundingMethod).toNumber() : serviceItem.discount;
|
|
14928
14974
|
return {
|
|
14929
14975
|
price: serviceItem.price,
|
|
14930
14976
|
quantity: serviceItem.quantity,
|