shareneus 1.6.25 → 1.6.26
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/tax/index.d.ts +1 -1
- package/dist/tax/index.js +2 -1
- package/dist/tax/tax-calculator.d.ts +28 -11
- package/dist/tax/tax-calculator.js +51 -25
- package/dist/tax/tax.types.d.ts +6 -2
- package/package.json +1 -1
package/dist/tax/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export type { TaxComponentType, CalcMethod, AppliedOn, RoundingMethod, TaxCategory, SupplyType, ResolvedSupplyType, WithholdingType, ResolverType, IRegimeComponent, IRegimeFeatures, IRounding, ITreatment, ITaxRegime, ITaxCodeComponent, ITaxCode, ITaxComponent, ITaxSummaryLine, ITaxSummary, IWithholding, IWithholdingCalcInput, ILineAmountFields, IComponentOverride, ITaxCalcLineInput, ITaxSummaryInput, IRoundingConfig, IDocumentTotalsInput, IDocumentTotals, ITaxIdLabel, ITaxIdEntry, ITaxExemption, ITaxAuthority, IExternalProvider, } from "./tax.types";
|
|
8
8
|
export type { IInclusiveResult } from "./tax-calculator";
|
|
9
|
-
export { CalculateNetAmt, CalculateLineTax, ExtractNetFromInclusive, SumTaxComponents, ComputeTaxSummary, ComputeDocumentTotals, DetermineSupplyType, FindTaxCodeByRateAndSupplyType, CalculateWithholding, RoundAmount, ValidateTaxId, ValidateHSNSACLength, ConvertFlatToTaxes, GetDefaultTaxIdLabels, GetPrintableTaxIds, } from "./tax-calculator";
|
|
9
|
+
export { CalculateGrossAmt, CalculateNetAmt, CalculateLineTax, ExtractNetFromInclusive, SumTaxComponents, ComputeTaxSummary, ComputeDocumentTotals, DetermineSupplyType, FindTaxCodeByRateAndSupplyType, CalculateWithholding, RoundAmount, ValidateTaxId, ValidateHSNSACLength, ConvertFlatToTaxes, GetDefaultTaxIdLabels, GetPrintableTaxIds, } from "./tax-calculator";
|
package/dist/tax/index.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* Import from "shareneus/tax" in both UI and API code.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.GetPrintableTaxIds = exports.GetDefaultTaxIdLabels = exports.ConvertFlatToTaxes = exports.ValidateHSNSACLength = exports.ValidateTaxId = exports.RoundAmount = exports.CalculateWithholding = exports.FindTaxCodeByRateAndSupplyType = exports.DetermineSupplyType = exports.ComputeDocumentTotals = exports.ComputeTaxSummary = exports.SumTaxComponents = exports.ExtractNetFromInclusive = exports.CalculateLineTax = exports.CalculateNetAmt = void 0;
|
|
9
|
+
exports.GetPrintableTaxIds = exports.GetDefaultTaxIdLabels = exports.ConvertFlatToTaxes = exports.ValidateHSNSACLength = exports.ValidateTaxId = exports.RoundAmount = exports.CalculateWithholding = exports.FindTaxCodeByRateAndSupplyType = exports.DetermineSupplyType = exports.ComputeDocumentTotals = exports.ComputeTaxSummary = exports.SumTaxComponents = exports.ExtractNetFromInclusive = exports.CalculateLineTax = exports.CalculateNetAmt = exports.CalculateGrossAmt = void 0;
|
|
10
10
|
var tax_calculator_1 = require("./tax-calculator");
|
|
11
|
+
Object.defineProperty(exports, "CalculateGrossAmt", { enumerable: true, get: function () { return tax_calculator_1.CalculateGrossAmt; } });
|
|
11
12
|
Object.defineProperty(exports, "CalculateNetAmt", { enumerable: true, get: function () { return tax_calculator_1.CalculateNetAmt; } });
|
|
12
13
|
Object.defineProperty(exports, "CalculateLineTax", { enumerable: true, get: function () { return tax_calculator_1.CalculateLineTax; } });
|
|
13
14
|
Object.defineProperty(exports, "ExtractNetFromInclusive", { enumerable: true, get: function () { return tax_calculator_1.ExtractNetFromInclusive; } });
|
|
@@ -15,6 +15,18 @@
|
|
|
15
15
|
* precision issues. Never use plain JS arithmetic (* / + -) for money.
|
|
16
16
|
*/
|
|
17
17
|
import { ITaxCode, ITaxComponent, ITaxSummary, ILineAmountFields, ITaxCalcLineInput, ITaxSummaryInput, IRoundingConfig, IDocumentTotalsInput, IDocumentTotals, ResolvedSupplyType, IWithholding, IWithholdingCalcInput, ITaxIdLabel, ITaxIdEntry } from "./tax.types";
|
|
18
|
+
/**
|
|
19
|
+
* Computes the gross line amount before discounts and tax.
|
|
20
|
+
*
|
|
21
|
+
* Formula: GrossAmt = Qty × UnitPrice
|
|
22
|
+
*
|
|
23
|
+
* If `UnAmt` / `Amt` is already present on the line, that value is treated as
|
|
24
|
+
* the line's gross amount source of truth.
|
|
25
|
+
*
|
|
26
|
+
* This is the amount used for document `SubTotal` under the standard:
|
|
27
|
+
* SubTotal = sum of line values before line/document discounts and before tax.
|
|
28
|
+
*/
|
|
29
|
+
export declare function CalculateGrossAmt(input: ILineAmountFields): number;
|
|
18
30
|
/**
|
|
19
31
|
* Computes the net taxable amount from line item fields.
|
|
20
32
|
*
|
|
@@ -159,22 +171,27 @@ export declare function SumTaxComponents(taxes: ITaxComponent[] | undefined | nu
|
|
|
159
171
|
*/
|
|
160
172
|
export declare function ComputeTaxSummary(input: ITaxSummaryInput): ITaxSummary;
|
|
161
173
|
/**
|
|
162
|
-
* Computes all document-level totals in one call: SubTotal,
|
|
163
|
-
* TaxSummary, Round, and Total.
|
|
174
|
+
* Computes all document-level totals in one call: SubTotal, Discount,
|
|
175
|
+
* TaxableAmount, TaxTotal, TaxSummary, Round, and Total.
|
|
164
176
|
*
|
|
165
177
|
* This is the primary function UI/API should call at save time to produce
|
|
166
178
|
* the stored financial fields. All rounding is applied per the RoundingConfig.
|
|
167
179
|
*
|
|
168
180
|
* Flow:
|
|
169
|
-
* 1. SubTotal = sum of line
|
|
170
|
-
* 2.
|
|
171
|
-
* 3.
|
|
172
|
-
* 4.
|
|
173
|
-
* 5.
|
|
174
|
-
* 6.
|
|
181
|
+
* 1. SubTotal = sum of gross line values before discounts/tax
|
|
182
|
+
* 2. Discount = sum of line discount + prorated record discount allocations
|
|
183
|
+
* 3. TaxableAmount = sum of line NetAmts
|
|
184
|
+
* 4. TaxSummary = grouped by Code+Rate (rounded per TaxComponentTotal)
|
|
185
|
+
* 5. TaxTotal = sum of TaxSummary Amts
|
|
186
|
+
* 6. GrandTotal = TaxableAmount + TaxTotal
|
|
187
|
+
* 7. If DocTotal ON: round GrandTotal, compute Round adjustment
|
|
188
|
+
* 8. Total = GrandTotal + Round
|
|
175
189
|
*
|
|
176
190
|
* NOTE: Document-level Discount, Adjust, and Withholding are NOT handled here.
|
|
177
|
-
*
|
|
191
|
+
* If a document-level discount exists (e.g. India GST invoice discount), the
|
|
192
|
+
* caller must prorate it into line `RecDisc` values before calling this
|
|
193
|
+
* function so each line's taxable base is correct.
|
|
194
|
+
* Additional final settlement adjustments are applied after this function:
|
|
178
195
|
* FinalPayable = Total + Adjust - Withholding.Amt
|
|
179
196
|
*
|
|
180
197
|
* @param input - Line items with Qty/UnitPrice/Disc/RecDisc and Taxes[], plus RoundingConfig
|
|
@@ -195,8 +212,8 @@ export declare function ComputeTaxSummary(input: ITaxSummaryInput): ITaxSummary;
|
|
|
195
212
|
* RegimeCode: "IN_GST",
|
|
196
213
|
* });
|
|
197
214
|
* // Returns: {
|
|
198
|
-
* // SubTotal: 8000,
|
|
199
|
-
* // GrandTotal: 9440,
|
|
215
|
+
* // SubTotal: 8000, Discount: 0, TaxableAmount: 8000,
|
|
216
|
+
* // TaxTotal: 1440, Round: 0, Total: 9440, GrandTotal: 9440,
|
|
200
217
|
* // TaxSummary: [
|
|
201
218
|
* // { Code: "CGST", Rate: 9, TaxableAmt: 8000, Amt: 720 },
|
|
202
219
|
* // { Code: "SGST", Rate: 9, TaxableAmt: 8000, Amt: 720 },
|
|
@@ -19,6 +19,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.CalculateGrossAmt = CalculateGrossAmt;
|
|
22
23
|
exports.CalculateNetAmt = CalculateNetAmt;
|
|
23
24
|
exports.CalculateLineTax = CalculateLineTax;
|
|
24
25
|
exports.ExtractNetFromInclusive = ExtractNetFromInclusive;
|
|
@@ -40,6 +41,30 @@ const math_operations_1 = require("../shared/math-operations");
|
|
|
40
41
|
// ============================================================
|
|
41
42
|
// Net Amount Calculation
|
|
42
43
|
// ============================================================
|
|
44
|
+
/**
|
|
45
|
+
* Computes the gross line amount before discounts and tax.
|
|
46
|
+
*
|
|
47
|
+
* Formula: GrossAmt = Qty × UnitPrice
|
|
48
|
+
*
|
|
49
|
+
* If `UnAmt` / `Amt` is already present on the line, that value is treated as
|
|
50
|
+
* the line's gross amount source of truth.
|
|
51
|
+
*
|
|
52
|
+
* This is the amount used for document `SubTotal` under the standard:
|
|
53
|
+
* SubTotal = sum of line values before line/document discounts and before tax.
|
|
54
|
+
*/
|
|
55
|
+
function CalculateGrossAmt(input) {
|
|
56
|
+
var _a, _b, _c;
|
|
57
|
+
const line = input;
|
|
58
|
+
if (line.UnAmt != null || line.Amt != null) {
|
|
59
|
+
return (0, util_1.GetNumber)((_a = line.UnAmt) !== null && _a !== void 0 ? _a : line.Amt);
|
|
60
|
+
}
|
|
61
|
+
const unitPrice = (_c = (_b = line.UnitPrice) !== null && _b !== void 0 ? _b : line.UnPr) !== null && _c !== void 0 ? _c : line.Pr;
|
|
62
|
+
if (unitPrice != null) {
|
|
63
|
+
const qty = input.Qty == null ? 1 : (0, util_1.GetNumber)(input.Qty);
|
|
64
|
+
return (0, math_operations_1.Multiply)(qty, (0, util_1.GetNumber)(unitPrice));
|
|
65
|
+
}
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
43
68
|
/**
|
|
44
69
|
* Computes the net taxable amount from line item fields.
|
|
45
70
|
*
|
|
@@ -63,19 +88,9 @@ const math_operations_1 = require("../shared/math-operations");
|
|
|
63
88
|
* // Returns: 3000
|
|
64
89
|
*/
|
|
65
90
|
function CalculateNetAmt(input) {
|
|
66
|
-
var _a, _b, _c;
|
|
67
|
-
const line = input;
|
|
68
91
|
const disc = (0, util_1.GetNumber)(input.Disc);
|
|
69
92
|
const recDisc = (0, util_1.GetNumber)(input.RecDisc);
|
|
70
|
-
|
|
71
|
-
return (0, math_operations_1.Subtract)((0, util_1.GetNumber)((_a = line.UnAmt) !== null && _a !== void 0 ? _a : line.Amt), disc, recDisc);
|
|
72
|
-
}
|
|
73
|
-
const unitPrice = (_c = (_b = line.UnitPrice) !== null && _b !== void 0 ? _b : line.UnPr) !== null && _c !== void 0 ? _c : line.Pr;
|
|
74
|
-
if (unitPrice != null) {
|
|
75
|
-
const qty = input.Qty == null ? 1 : (0, util_1.GetNumber)(input.Qty);
|
|
76
|
-
return (0, math_operations_1.Subtract)((0, math_operations_1.Multiply)(qty, (0, util_1.GetNumber)(unitPrice)), disc, recDisc);
|
|
77
|
-
}
|
|
78
|
-
return 0;
|
|
93
|
+
return (0, math_operations_1.Subtract)(CalculateGrossAmt(input), disc, recDisc);
|
|
79
94
|
}
|
|
80
95
|
// ============================================================
|
|
81
96
|
// Core Tax Calculation
|
|
@@ -433,22 +448,27 @@ function ComputeTaxSummary(input) {
|
|
|
433
448
|
// Document Totals — Full document computation
|
|
434
449
|
// ============================================================
|
|
435
450
|
/**
|
|
436
|
-
* Computes all document-level totals in one call: SubTotal,
|
|
437
|
-
* TaxSummary, Round, and Total.
|
|
451
|
+
* Computes all document-level totals in one call: SubTotal, Discount,
|
|
452
|
+
* TaxableAmount, TaxTotal, TaxSummary, Round, and Total.
|
|
438
453
|
*
|
|
439
454
|
* This is the primary function UI/API should call at save time to produce
|
|
440
455
|
* the stored financial fields. All rounding is applied per the RoundingConfig.
|
|
441
456
|
*
|
|
442
457
|
* Flow:
|
|
443
|
-
* 1. SubTotal = sum of line
|
|
444
|
-
* 2.
|
|
445
|
-
* 3.
|
|
446
|
-
* 4.
|
|
447
|
-
* 5.
|
|
448
|
-
* 6.
|
|
458
|
+
* 1. SubTotal = sum of gross line values before discounts/tax
|
|
459
|
+
* 2. Discount = sum of line discount + prorated record discount allocations
|
|
460
|
+
* 3. TaxableAmount = sum of line NetAmts
|
|
461
|
+
* 4. TaxSummary = grouped by Code+Rate (rounded per TaxComponentTotal)
|
|
462
|
+
* 5. TaxTotal = sum of TaxSummary Amts
|
|
463
|
+
* 6. GrandTotal = TaxableAmount + TaxTotal
|
|
464
|
+
* 7. If DocTotal ON: round GrandTotal, compute Round adjustment
|
|
465
|
+
* 8. Total = GrandTotal + Round
|
|
449
466
|
*
|
|
450
467
|
* NOTE: Document-level Discount, Adjust, and Withholding are NOT handled here.
|
|
451
|
-
*
|
|
468
|
+
* If a document-level discount exists (e.g. India GST invoice discount), the
|
|
469
|
+
* caller must prorate it into line `RecDisc` values before calling this
|
|
470
|
+
* function so each line's taxable base is correct.
|
|
471
|
+
* Additional final settlement adjustments are applied after this function:
|
|
452
472
|
* FinalPayable = Total + Adjust - Withholding.Amt
|
|
453
473
|
*
|
|
454
474
|
* @param input - Line items with Qty/UnitPrice/Disc/RecDisc and Taxes[], plus RoundingConfig
|
|
@@ -469,8 +489,8 @@ function ComputeTaxSummary(input) {
|
|
|
469
489
|
* RegimeCode: "IN_GST",
|
|
470
490
|
* });
|
|
471
491
|
* // Returns: {
|
|
472
|
-
* // SubTotal: 8000,
|
|
473
|
-
* // GrandTotal: 9440,
|
|
492
|
+
* // SubTotal: 8000, Discount: 0, TaxableAmount: 8000,
|
|
493
|
+
* // TaxTotal: 1440, Round: 0, Total: 9440, GrandTotal: 9440,
|
|
474
494
|
* // TaxSummary: [
|
|
475
495
|
* // { Code: "CGST", Rate: 9, TaxableAmt: 8000, Amt: 720 },
|
|
476
496
|
* // { Code: "SGST", Rate: 9, TaxableAmt: 8000, Amt: 720 },
|
|
@@ -479,10 +499,14 @@ function ComputeTaxSummary(input) {
|
|
|
479
499
|
*/
|
|
480
500
|
function ComputeDocumentTotals(input) {
|
|
481
501
|
const { Lines, Rounding, RegimeCode } = input;
|
|
482
|
-
// 1. SubTotal = sum of line
|
|
502
|
+
// 1. SubTotal = sum of gross line values before discounts/tax
|
|
483
503
|
let subTotal = 0;
|
|
504
|
+
let discount = 0;
|
|
505
|
+
let taxableAmount = 0;
|
|
484
506
|
for (const line of Lines) {
|
|
485
|
-
subTotal = (0, math_operations_1.Add)(subTotal,
|
|
507
|
+
subTotal = (0, math_operations_1.Add)(subTotal, CalculateGrossAmt(line));
|
|
508
|
+
discount = (0, math_operations_1.Add)(discount, (0, util_1.GetNumber)(line.Disc), (0, util_1.GetNumber)(line.RecDisc));
|
|
509
|
+
taxableAmount = (0, math_operations_1.Add)(taxableAmount, CalculateNetAmt(line));
|
|
486
510
|
}
|
|
487
511
|
// 2. TaxSummary (handles TaxComponentTotal rounding internally)
|
|
488
512
|
const taxSummary = ComputeTaxSummary({
|
|
@@ -493,7 +517,7 @@ function ComputeDocumentTotals(input) {
|
|
|
493
517
|
// 3. TaxTotal from the (potentially rounded) summary
|
|
494
518
|
const taxTotal = taxSummary.TotalTax;
|
|
495
519
|
// 4. GrandTotal before doc-level rounding
|
|
496
|
-
const grandTotal = (0, math_operations_1.Add)(
|
|
520
|
+
const grandTotal = (0, math_operations_1.Add)(taxableAmount, taxTotal);
|
|
497
521
|
// 5. DocTotal rounding
|
|
498
522
|
let roundedTotal = grandTotal;
|
|
499
523
|
let roundAdj = 0;
|
|
@@ -503,6 +527,8 @@ function ComputeDocumentTotals(input) {
|
|
|
503
527
|
}
|
|
504
528
|
return {
|
|
505
529
|
SubTotal: subTotal,
|
|
530
|
+
Discount: discount,
|
|
531
|
+
TaxableAmount: taxableAmount,
|
|
506
532
|
TaxTotal: taxTotal,
|
|
507
533
|
TaxSummary: taxSummary.Lines,
|
|
508
534
|
GrandTotal: grandTotal,
|
package/dist/tax/tax.types.d.ts
CHANGED
|
@@ -326,13 +326,17 @@ export interface IDocumentTotalsInput {
|
|
|
326
326
|
}
|
|
327
327
|
/** Result of full document totals computation */
|
|
328
328
|
export interface IDocumentTotals {
|
|
329
|
-
/** Sum of all line
|
|
329
|
+
/** Sum of all gross line values before discounts and tax */
|
|
330
330
|
SubTotal: number;
|
|
331
|
+
/** Sum of line discounts + prorated record/document discount allocations */
|
|
332
|
+
Discount: number;
|
|
333
|
+
/** Sum of all line NetAmts after discount allocation, before tax */
|
|
334
|
+
TaxableAmount: number;
|
|
331
335
|
/** Total tax amount — sum of rounded component Amts per RoundingConfig */
|
|
332
336
|
TaxTotal: number;
|
|
333
337
|
/** Rate-wise tax breakdown — grouped by Code+Rate, rounded per config */
|
|
334
338
|
TaxSummary: ITaxSummaryLine[];
|
|
335
|
-
/**
|
|
339
|
+
/** TaxableAmount + TaxTotal (before DocTotal rounding) */
|
|
336
340
|
GrandTotal: number;
|
|
337
341
|
/** Rounding adjustment: RoundedTotal - GrandTotal (0 if DocTotal is off) */
|
|
338
342
|
Round: number;
|