shareneus 1.5.94 → 1.5.95
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.d.ts +1 -1
- package/dist/index.js +12 -12
- package/dist/tax/index.d.ts +2 -2
- package/dist/tax/index.js +15 -13
- package/dist/tax/tax-calculator.d.ts +73 -31
- package/dist/tax/tax-calculator.js +135 -60
- package/dist/tax/tax.types.d.ts +23 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -141,5 +141,5 @@ export { GetBillPdfDataUrl } from "./purchases/bills/bill-pdf/bill-pdf.service";
|
|
|
141
141
|
export { GetInvoicePrintInfo } from "./accounting/invoice/inv-print.service";
|
|
142
142
|
export { CreateReceiptPDFService } from "./accounting/payment-receive/payment-receipt-pdf/receipt-pdf.service";
|
|
143
143
|
export { CreateInvoicePDFService } from "./accounting/invoice/invoice-pdf/invoice-pdf.service";
|
|
144
|
-
export {
|
|
144
|
+
export { CalculateLineTax, ExtractNetFromInclusive, SumTaxComponents, ComputeTaxSummary, DetermineSupplyType, FindTaxCodeByRateAndSupplyType, CalculateWithholding, RoundAmount, ValidateTaxId, ValidateHSNSACLength, ConvertFlatToTaxes, } from "./tax";
|
|
145
145
|
export type { TaxComponentType, CalcMethod, AppliedOn, RoundingMethod, TaxCategory, SupplyType, ResolvedSupplyType, WithholdingType, ResolverType, IRegimeComponent, IRegimeFeatures, IRounding, ITreatment, ITaxRegime, ITaxCodeComponent, ITaxCode, ITaxComponent, ITaxSummaryLine, ITaxSummary, IWithholding, IWithholdingCalcInput, ITaxCalcLineInput, ITaxSummaryInput, IRoundingConfig, IInclusiveResult, ITaxExemption, ITaxAuthority, IExternalProvider, } from "./tax";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DebitNotePdfService = exports.DCWithoutPricePdfService = exports.DCLandscapeWithoutPricePdfService = exports.DCLandscapePdfService = exports.CustomerBalancesService = exports.SalesByCustomerPDFService = exports.CustWiseSalesDetailsService = exports.CreditNoteTotalsService = exports.CreditNotePdfService = exports.ConsultationPDFService = exports.ConsultationFullPrintService = exports.ConsultationFeeReceiptPrintService = exports.CNPrintService = exports.ChecklistsPDFService = exports.CheckListPrintService = exports.CategoryWiseItemPDFService = exports.SalesReceiptprintService = exports.AppointmentTotalsService = exports.AnalysisPDFService = exports.VenBalanceXlsxFileService = exports.TallySalesImportXlsxFileService = exports.StockXlsxFileService = exports.IssueSparesXlsxFileService = exports.ScheduledDrugXlsxFileService = exports.ScheduledDrugSummaryXlsxFileService = exports.SalesByServiceSummaryXlsxFileService = exports.SummaryXlsxFileService = exports.ServiceAdvisorWisePartXlsxFileService = exports.ServiceAdvisorWiseLaborXlsxFileService = exports.RepairOrdersXlsxFileService = exports.PaymentsMadeXlsxFileService = exports.PaymentReceiveXlsxFileService = exports.OperatorWiseSummaryXlsxFileService = exports.OperatorWiseDetailsXlsxFileService = exports.ManfWiseSalesXlsxFileService = exports.ItemsWiseSalesXlsxFileService = exports.ItemWiseMOSummaryXlsxFileService = exports.ItemWiseMODetailsXlsxFileService = exports.ItemWiseDoctorSaleXlsxFileService = exports.InvoicesWiseXlsxFileService = exports.InsuranceExpireXlsxFileService = exports.GSTR2ExcelService = exports.GSTR1ExcelService = exports.GSTROXlsxFileService = exports.ExpiringDrugsXlsxFileService = exports.SalesByCustomerXlsxFileService = exports.CustWiseSalesXlsxFileService = exports.CustBalanceXlsxFileService = exports.CategoryWiseItemXlsxFileService = exports.AnalysisXlsxFileService = void 0;
|
|
4
4
|
exports.TaskPDfService = exports.PrintSharedService = exports.SharedPDFService = exports.SharedInvoiceprintService = exports.WOPrintService = exports.ScheduledDrugSummaryPDFService = exports.ScheduledDrugPDFService = exports.SalesTotalsService = exports.SaleReceiptPrintService = exports.SalesReceiptpdfService = exports.SalesPrintService = exports.SalesPdfService = exports.SalesByServiceSummaryPDF = exports.ROTotalsService = exports.ROPrintService = exports.RoprintService = exports.RepairOrdersReportsPDFService = exports.ReorderPointPDFService = exports.ReceiptPrintService = exports.PurchaseOrderPDFService = exports.PurchaseOrderTotalsService = exports.PurchaseOrderPrintService = exports.PosReceiptPrintService = exports.POTotalsService = exports.PaymentsReportPDFService = exports.ReceiptPDFService = exports.PackShipPrintService = exports.PackShipPDFService = exports.OperatorWiseSalesSummaryPDF = exports.OperatorWiseSalesDetailsPDF = exports.MaterialOutprintService = exports.MeetingPdfService = exports.ManfWiseSalesService = exports.ItemWiseSalesPDFService = exports.ItemWiseMOSummaryPDF = exports.ItemWiseMODetailsPDF = exports.ItemWiseDoctorSalePDFService = exports.ItemDetaisPdf = exports.IssuePartsprintService = exports.InvoiceTotalsService = exports.InvoiceLandscapePdfService = exports.InsuranceExpirePDF = exports.ExpiringDrugPDFService = exports.EstPrintService = exports.EquipmentDesignPdf = exports.DeliveryChallanTotalsService = exports.DeliveryChallanPrintService = exports.DeliveryChallanPdfService = exports.DebitNoteTotalsService = exports.DebitNotePrintService = void 0;
|
|
5
5
|
exports.CreateInvoicePDFService = exports.CreateReceiptPDFService = exports.GetInvoicePrintInfo = exports.GetBillPdfDataUrl = exports.GetBillPDF = exports.GetInvoicePDF = exports.ProductWithoutOwnerPDFService = exports.ProductWithoutOwnerXlsxFileService = exports.Divide = exports.Multiply = exports.Subtract = exports.Add = exports.ServiceHistoryPDFService = exports.SalesTotalCalculationsWithDecimals = exports.GetNumber = exports.GetAgeString = exports.IsNull = exports.IsNotNull = exports.GetServicePriceForPriceList = exports.ApplyServicePriceListToOpcode = exports.ApplyServicePriceListToProcedure = exports.CalcItemFinalSalePrice = exports.GetItemPriceForPriceList = exports.SalesReceiveTotalsService = exports.SalesReceivePrintService = exports.SalesReceivePdfService = exports.AdjustmentDrugPDFService = exports.HSNSummaryPDFService = exports.HSNSummaryExcelService = exports.ItemBarCodeLabelPdf = exports.NextServiceDatePDFService = exports.NextServiceDateXlsxFileService = exports.ConsultationLetterHeadPDFService = exports.InvoiceLetterheadPdfService = exports.InvoicePortraitPrintService = exports.HCInvoiceprintService = exports.InvoiceprintService = exports.MyDate = exports.TrUtils = exports.VendorDebitNoteTotalsService = exports.VendorDebitNotePrintService = exports.VendorDebitNotePdfService = exports.VendorCreditNoteTotalsService = exports.VendorCreditNotePrintService = exports.VendorCreditNotePDFService = exports.VendorBalancesService = exports.TransferOrderPrintService = exports.TechnicianPrintService = exports.TechnicianpdfService = exports.TaskReportsPDfService = void 0;
|
|
6
|
-
exports.
|
|
6
|
+
exports.ConvertFlatToTaxes = exports.ValidateHSNSACLength = exports.ValidateTaxId = exports.RoundAmount = exports.CalculateWithholding = exports.FindTaxCodeByRateAndSupplyType = exports.DetermineSupplyType = exports.ComputeTaxSummary = exports.SumTaxComponents = exports.ExtractNetFromInclusive = exports.CalculateLineTax = void 0;
|
|
7
7
|
var analysis_excel_service_1 = require("./accounting/invoice/reports/excel/analysis-excel.service");
|
|
8
8
|
Object.defineProperty(exports, "AnalysisXlsxFileService", { enumerable: true, get: function () { return analysis_excel_service_1.AnalysisXlsxFileService; } });
|
|
9
9
|
var category_wise_item_excel_service_1 = require("./accounting/invoice/reports/excel/category-wise-item-excel.service");
|
|
@@ -300,14 +300,14 @@ var invoice_pdf_service_2 = require("./accounting/invoice/invoice-pdf/invoice-pd
|
|
|
300
300
|
Object.defineProperty(exports, "CreateInvoicePDFService", { enumerable: true, get: function () { return invoice_pdf_service_2.CreateInvoicePDFService; } });
|
|
301
301
|
// Tax System — Calculation functions
|
|
302
302
|
var tax_1 = require("./tax");
|
|
303
|
-
Object.defineProperty(exports, "
|
|
304
|
-
Object.defineProperty(exports, "
|
|
305
|
-
Object.defineProperty(exports, "
|
|
306
|
-
Object.defineProperty(exports, "
|
|
307
|
-
Object.defineProperty(exports, "
|
|
308
|
-
Object.defineProperty(exports, "
|
|
309
|
-
Object.defineProperty(exports, "
|
|
310
|
-
Object.defineProperty(exports, "
|
|
311
|
-
Object.defineProperty(exports, "
|
|
312
|
-
Object.defineProperty(exports, "
|
|
313
|
-
Object.defineProperty(exports, "
|
|
303
|
+
Object.defineProperty(exports, "CalculateLineTax", { enumerable: true, get: function () { return tax_1.CalculateLineTax; } });
|
|
304
|
+
Object.defineProperty(exports, "ExtractNetFromInclusive", { enumerable: true, get: function () { return tax_1.ExtractNetFromInclusive; } });
|
|
305
|
+
Object.defineProperty(exports, "SumTaxComponents", { enumerable: true, get: function () { return tax_1.SumTaxComponents; } });
|
|
306
|
+
Object.defineProperty(exports, "ComputeTaxSummary", { enumerable: true, get: function () { return tax_1.ComputeTaxSummary; } });
|
|
307
|
+
Object.defineProperty(exports, "DetermineSupplyType", { enumerable: true, get: function () { return tax_1.DetermineSupplyType; } });
|
|
308
|
+
Object.defineProperty(exports, "FindTaxCodeByRateAndSupplyType", { enumerable: true, get: function () { return tax_1.FindTaxCodeByRateAndSupplyType; } });
|
|
309
|
+
Object.defineProperty(exports, "CalculateWithholding", { enumerable: true, get: function () { return tax_1.CalculateWithholding; } });
|
|
310
|
+
Object.defineProperty(exports, "RoundAmount", { enumerable: true, get: function () { return tax_1.RoundAmount; } });
|
|
311
|
+
Object.defineProperty(exports, "ValidateTaxId", { enumerable: true, get: function () { return tax_1.ValidateTaxId; } });
|
|
312
|
+
Object.defineProperty(exports, "ValidateHSNSACLength", { enumerable: true, get: function () { return tax_1.ValidateHSNSACLength; } });
|
|
313
|
+
Object.defineProperty(exports, "ConvertFlatToTaxes", { enumerable: true, get: function () { return tax_1.ConvertFlatToTaxes; } });
|
package/dist/tax/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* This is the entry point for all tax-related functionality.
|
|
5
5
|
* Import from "shareneus/tax" in both UI and API code.
|
|
6
6
|
*/
|
|
7
|
-
export type { TaxComponentType, CalcMethod, AppliedOn, RoundingMethod, TaxCategory, SupplyType, ResolvedSupplyType, WithholdingType, ResolverType, IRegimeComponent, IRegimeFeatures, IRounding, ITreatment, ITaxRegime, ITaxCodeComponent, ITaxCode, ITaxComponent, ITaxSummaryLine, ITaxSummary, IWithholding, IWithholdingCalcInput, IComponentOverride, ITaxCalcLineInput, ITaxSummaryInput, IRoundingConfig, IDocumentTotalsInput, IDocumentTotals, ITaxExemption, ITaxAuthority, IExternalProvider, } from "./tax.types";
|
|
7
|
+
export type { TaxComponentType, CalcMethod, AppliedOn, RoundingMethod, TaxCategory, SupplyType, ResolvedSupplyType, WithholdingType, ResolverType, IRegimeComponent, IRegimeFeatures, IRounding, ITreatment, ITaxRegime, ITaxCodeComponent, ITaxCode, ITaxComponent, ITaxSummaryLine, ITaxSummary, IWithholding, IWithholdingCalcInput, IComponentOverride, ITaxCalcLineInput, ITaxSummaryInput, IRoundingConfig, IDocumentTotalsInput, IDocumentTotals, ITaxIdLabel, ITaxIdEntry, ITaxExemption, ITaxAuthority, IExternalProvider, } from "./tax.types";
|
|
8
8
|
export type { IInclusiveResult } from "./tax-calculator";
|
|
9
|
-
export {
|
|
9
|
+
export { CalculateLineTax, ExtractNetFromInclusive, SumTaxComponents, ComputeTaxSummary, ComputeDocumentTotals, DetermineSupplyType, FindTaxCodeByRateAndSupplyType, CalculateWithholding, RoundAmount, ValidateTaxId, ValidateHSNSACLength, ConvertFlatToTaxes, GetDefaultTaxIdLabels, GetPrintableTaxIds, } from "./tax-calculator";
|
package/dist/tax/index.js
CHANGED
|
@@ -6,17 +6,19 @@
|
|
|
6
6
|
* Import from "shareneus/tax" in both UI and API code.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
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 = void 0;
|
|
10
10
|
var tax_calculator_1 = require("./tax-calculator");
|
|
11
|
-
Object.defineProperty(exports, "
|
|
12
|
-
Object.defineProperty(exports, "
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
Object.defineProperty(exports, "
|
|
15
|
-
Object.defineProperty(exports, "
|
|
16
|
-
Object.defineProperty(exports, "
|
|
17
|
-
Object.defineProperty(exports, "
|
|
18
|
-
Object.defineProperty(exports, "
|
|
19
|
-
Object.defineProperty(exports, "
|
|
20
|
-
Object.defineProperty(exports, "
|
|
21
|
-
Object.defineProperty(exports, "
|
|
22
|
-
Object.defineProperty(exports, "
|
|
11
|
+
Object.defineProperty(exports, "CalculateLineTax", { enumerable: true, get: function () { return tax_calculator_1.CalculateLineTax; } });
|
|
12
|
+
Object.defineProperty(exports, "ExtractNetFromInclusive", { enumerable: true, get: function () { return tax_calculator_1.ExtractNetFromInclusive; } });
|
|
13
|
+
Object.defineProperty(exports, "SumTaxComponents", { enumerable: true, get: function () { return tax_calculator_1.SumTaxComponents; } });
|
|
14
|
+
Object.defineProperty(exports, "ComputeTaxSummary", { enumerable: true, get: function () { return tax_calculator_1.ComputeTaxSummary; } });
|
|
15
|
+
Object.defineProperty(exports, "ComputeDocumentTotals", { enumerable: true, get: function () { return tax_calculator_1.ComputeDocumentTotals; } });
|
|
16
|
+
Object.defineProperty(exports, "DetermineSupplyType", { enumerable: true, get: function () { return tax_calculator_1.DetermineSupplyType; } });
|
|
17
|
+
Object.defineProperty(exports, "FindTaxCodeByRateAndSupplyType", { enumerable: true, get: function () { return tax_calculator_1.FindTaxCodeByRateAndSupplyType; } });
|
|
18
|
+
Object.defineProperty(exports, "CalculateWithholding", { enumerable: true, get: function () { return tax_calculator_1.CalculateWithholding; } });
|
|
19
|
+
Object.defineProperty(exports, "RoundAmount", { enumerable: true, get: function () { return tax_calculator_1.RoundAmount; } });
|
|
20
|
+
Object.defineProperty(exports, "ValidateTaxId", { enumerable: true, get: function () { return tax_calculator_1.ValidateTaxId; } });
|
|
21
|
+
Object.defineProperty(exports, "ValidateHSNSACLength", { enumerable: true, get: function () { return tax_calculator_1.ValidateHSNSACLength; } });
|
|
22
|
+
Object.defineProperty(exports, "ConvertFlatToTaxes", { enumerable: true, get: function () { return tax_calculator_1.ConvertFlatToTaxes; } });
|
|
23
|
+
Object.defineProperty(exports, "GetDefaultTaxIdLabels", { enumerable: true, get: function () { return tax_calculator_1.GetDefaultTaxIdLabels; } });
|
|
24
|
+
Object.defineProperty(exports, "GetPrintableTaxIds", { enumerable: true, get: function () { return tax_calculator_1.GetPrintableTaxIds; } });
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* IMPORTANT: All monetary calculations use Big.js to avoid floating-point
|
|
15
15
|
* precision issues. Never use plain JS arithmetic (* / + -) for money.
|
|
16
16
|
*/
|
|
17
|
-
import { ITaxCode, ITaxComponent, ITaxSummary, ITaxCalcLineInput, ITaxSummaryInput, IRoundingConfig, IDocumentTotalsInput, IDocumentTotals, ResolvedSupplyType, IWithholding, IWithholdingCalcInput } from "./tax.types";
|
|
17
|
+
import { ITaxCode, ITaxComponent, ITaxSummary, ITaxCalcLineInput, ITaxSummaryInput, IRoundingConfig, IDocumentTotalsInput, IDocumentTotals, ResolvedSupplyType, IWithholding, IWithholdingCalcInput, ITaxIdLabel, ITaxIdEntry } from "./tax.types";
|
|
18
18
|
/**
|
|
19
19
|
* Calculates tax for a single line item based on the provided TaxCode.
|
|
20
20
|
*
|
|
@@ -27,7 +27,7 @@ import { ITaxCode, ITaxComponent, ITaxSummary, ITaxCalcLineInput, ITaxSummaryInp
|
|
|
27
27
|
*
|
|
28
28
|
* @example
|
|
29
29
|
* // India GST 18% Intra-State on Rs 5,000 item
|
|
30
|
-
* const result =
|
|
30
|
+
* const result = CalculateLineTax({
|
|
31
31
|
* NetAmt: 5000,
|
|
32
32
|
* TaxCode: gst18IntraTaxCode,
|
|
33
33
|
* });
|
|
@@ -38,7 +38,7 @@ import { ITaxCode, ITaxComponent, ITaxSummary, ITaxCalcLineInput, ITaxSummaryInp
|
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* // India GST 28% + Specific Cess (Rs 12/liter) on 100 liters
|
|
41
|
-
* const result =
|
|
41
|
+
* const result = CalculateLineTax({
|
|
42
42
|
* NetAmt: 10000,
|
|
43
43
|
* Qty: 100,
|
|
44
44
|
* TaxCode: gst28CessDrinkTaxCode,
|
|
@@ -49,7 +49,7 @@ import { ITaxCode, ITaxComponent, ITaxSummary, ITaxCalcLineInput, ITaxSummaryInp
|
|
|
49
49
|
* // { Code: "CESS", Rate: 0, Amt: 1200, TaxCodeId: 201 },
|
|
50
50
|
* // ]
|
|
51
51
|
*/
|
|
52
|
-
export declare function
|
|
52
|
+
export declare function CalculateLineTax(input: ITaxCalcLineInput, rounding?: IRoundingConfig): ITaxComponent[];
|
|
53
53
|
/**
|
|
54
54
|
* Extracts the pre-tax (net) amount from a tax-inclusive price.
|
|
55
55
|
*
|
|
@@ -71,7 +71,7 @@ export declare function calculateLineTax(input: ITaxCalcLineInput, rounding?: IR
|
|
|
71
71
|
*
|
|
72
72
|
* @example
|
|
73
73
|
* // Price Rs 5,900 inclusive of GST 18%
|
|
74
|
-
* const netAmt =
|
|
74
|
+
* const netAmt = ExtractNetFromInclusive(5900, gst18IntraTaxCode);
|
|
75
75
|
* // Returns: 5000 (because 5000 + 18% = 5900)
|
|
76
76
|
*/
|
|
77
77
|
/**
|
|
@@ -87,7 +87,7 @@ export interface IInclusiveResult {
|
|
|
87
87
|
/** If set, the back-calculation is approximate — component structure doesn't support exact inversion */
|
|
88
88
|
Warning?: string;
|
|
89
89
|
}
|
|
90
|
-
export declare function
|
|
90
|
+
export declare function ExtractNetFromInclusive(inclusivePrice: number, taxCode: ITaxCode, qty?: number, rounding?: IRoundingConfig): IInclusiveResult;
|
|
91
91
|
/**
|
|
92
92
|
* Sums the Amt of all tax components on a line item.
|
|
93
93
|
*
|
|
@@ -95,10 +95,10 @@ export declare function extractNetFromInclusive(inclusivePrice: number, taxCode:
|
|
|
95
95
|
* @returns Total tax amount
|
|
96
96
|
*
|
|
97
97
|
* @example
|
|
98
|
-
* const totalTax =
|
|
98
|
+
* const totalTax = SumTaxComponents(lineItem.Taxes);
|
|
99
99
|
* // CGST 450 + SGST 450 = 900
|
|
100
100
|
*/
|
|
101
|
-
export declare function
|
|
101
|
+
export declare function SumTaxComponents(taxes: ITaxComponent[] | undefined | null): number;
|
|
102
102
|
/**
|
|
103
103
|
* Computes the document-level TaxSummary by aggregating all line items' Taxes[].
|
|
104
104
|
*
|
|
@@ -111,13 +111,13 @@ export declare function sumTaxComponents(taxes: ITaxComponent[] | undefined | nu
|
|
|
111
111
|
*
|
|
112
112
|
* Rounding behavior (via input.Rounding):
|
|
113
113
|
* - TaxComponentTotal ON: each bucket's Amt is rounded to Precision
|
|
114
|
-
* - Otherwise: Amts are at currency precision (from
|
|
114
|
+
* - Otherwise: Amts are at currency precision (from CalculateLineTax)
|
|
115
115
|
*
|
|
116
116
|
* @param input - All line items with Taxes[] and NetAmt, plus regime code and optional rounding
|
|
117
117
|
* @returns ITaxSummary — the aggregated summary (stored on the document)
|
|
118
118
|
*
|
|
119
119
|
* @example
|
|
120
|
-
* const summary =
|
|
120
|
+
* const summary = ComputeTaxSummary({
|
|
121
121
|
* Lines: invoice.Items.map(item => ({
|
|
122
122
|
* Taxes: item.Taxes,
|
|
123
123
|
* NetAmt: item.UnAmt - item.Disc - item.RecDisc,
|
|
@@ -135,7 +135,7 @@ export declare function sumTaxComponents(taxes: ITaxComponent[] | undefined | nu
|
|
|
135
135
|
* // RegimeCode: "IN_GST"
|
|
136
136
|
* // }
|
|
137
137
|
*/
|
|
138
|
-
export declare function
|
|
138
|
+
export declare function ComputeTaxSummary(input: ITaxSummaryInput): ITaxSummary;
|
|
139
139
|
/**
|
|
140
140
|
* Computes all document-level totals in one call: SubTotal, TaxTotal,
|
|
141
141
|
* TaxSummary, Round, and Total.
|
|
@@ -160,7 +160,7 @@ export declare function computeTaxSummary(input: ITaxSummaryInput): ITaxSummary;
|
|
|
160
160
|
*
|
|
161
161
|
* @example
|
|
162
162
|
* // India GST invoice with 2 lines
|
|
163
|
-
* const totals =
|
|
163
|
+
* const totals = ComputeDocumentTotals({
|
|
164
164
|
* Lines: [
|
|
165
165
|
* { NetAmt: 5000, Taxes: [{ Code: "CGST", Rate: 9, Amt: 450, TaxCodeId: 1 },
|
|
166
166
|
* { Code: "SGST", Rate: 9, Amt: 450, TaxCodeId: 1 }] },
|
|
@@ -179,7 +179,7 @@ export declare function computeTaxSummary(input: ITaxSummaryInput): ITaxSummary;
|
|
|
179
179
|
* // ]
|
|
180
180
|
* // }
|
|
181
181
|
*/
|
|
182
|
-
export declare function
|
|
182
|
+
export declare function ComputeDocumentTotals(input: IDocumentTotalsInput): IDocumentTotals;
|
|
183
183
|
/**
|
|
184
184
|
* Determines Intra-State or Inter-State based on seller and buyer state codes.
|
|
185
185
|
*
|
|
@@ -193,11 +193,11 @@ export declare function computeDocumentTotals(input: IDocumentTotalsInput): IDoc
|
|
|
193
193
|
* @returns "Intra" if same state, "Inter" if different states, "Unknown" if data missing
|
|
194
194
|
*
|
|
195
195
|
* @example
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
196
|
+
* DetermineSupplyType("29", "29"); // "Intra" — both Karnataka
|
|
197
|
+
* DetermineSupplyType("29", "33"); // "Inter" — Karnataka to Tamil Nadu
|
|
198
|
+
* DetermineSupplyType("", "33"); // "Unknown" — seller state missing
|
|
199
199
|
*/
|
|
200
|
-
export declare function
|
|
200
|
+
export declare function DetermineSupplyType(sellerStateCode: string, buyerStateCode: string): ResolvedSupplyType;
|
|
201
201
|
/**
|
|
202
202
|
* Finds a TaxCode by combined rate and supply type.
|
|
203
203
|
*
|
|
@@ -212,9 +212,9 @@ export declare function determineSupplyType(sellerStateCode: string, buyerStateC
|
|
|
212
212
|
*
|
|
213
213
|
* @example
|
|
214
214
|
* // Find GST 18% Inter-State (simple percentage-only tax code)
|
|
215
|
-
* const interCode =
|
|
215
|
+
* const interCode = FindTaxCodeByRateAndSupplyType(allTaxCodes, 18, "Inter");
|
|
216
216
|
*/
|
|
217
|
-
export declare function
|
|
217
|
+
export declare function FindTaxCodeByRateAndSupplyType(taxCodes: ITaxCode[], combinedRate: number, supplyType: "Intra" | "Inter"): ITaxCode | undefined;
|
|
218
218
|
/**
|
|
219
219
|
* Rounds a number according to the specified rounding configuration.
|
|
220
220
|
*
|
|
@@ -223,7 +223,7 @@ export declare function findTaxCodeByRateAndSupplyType(taxCodes: ITaxCode[], com
|
|
|
223
223
|
* - Japan: truncate (floor) to whole numbers
|
|
224
224
|
* - Some EU countries: banker's rounding
|
|
225
225
|
*/
|
|
226
|
-
export declare function
|
|
226
|
+
export declare function RoundAmount(value: number, config: IRoundingConfig): number;
|
|
227
227
|
/**
|
|
228
228
|
* Validates a tax identification number against the regime's format regex.
|
|
229
229
|
*
|
|
@@ -233,10 +233,10 @@ export declare function roundAmount(value: number, config: IRoundingConfig): num
|
|
|
233
233
|
*
|
|
234
234
|
* @example
|
|
235
235
|
* // Validate Indian GSTIN
|
|
236
|
-
*
|
|
236
|
+
* ValidateTaxId("29ABCDE1234F1Z5", "^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$");
|
|
237
237
|
* // Returns: true
|
|
238
238
|
*/
|
|
239
|
-
export declare function
|
|
239
|
+
export declare function ValidateTaxId(taxId: string, formatRegex: string): boolean;
|
|
240
240
|
/**
|
|
241
241
|
* Validates HSN/SAC code length against entity settings.
|
|
242
242
|
*
|
|
@@ -245,10 +245,52 @@ export declare function validateTaxId(taxId: string, formatRegex: string): boole
|
|
|
245
245
|
* @returns true if valid, false if invalid
|
|
246
246
|
*
|
|
247
247
|
* @example
|
|
248
|
-
*
|
|
249
|
-
*
|
|
248
|
+
* ValidateHSNSACLength("8471", "4"); // true
|
|
249
|
+
* ValidateHSNSACLength("8471", "6"); // false — needs 6 digits
|
|
250
250
|
*/
|
|
251
|
-
export declare function
|
|
251
|
+
export declare function ValidateHSNSACLength(code: string, requiredLength: string): boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Returns default TaxIdLabels for a given country.
|
|
254
|
+
*
|
|
255
|
+
* Used as seed data when creating TaxRegime records. The returned array is
|
|
256
|
+
* stored on TaxRegime.Features.TaxIdLabels[], which becomes the source of truth.
|
|
257
|
+
* At runtime, UI reads TaxIdLabels from TaxRegime — NOT from this function.
|
|
258
|
+
*
|
|
259
|
+
* @param country - ISO 3166-1 alpha-2 country code ("IN", "AU", "US", etc.)
|
|
260
|
+
* @returns Array of ITaxIdLabel — default tax ID definitions for the country
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* // When seeding India GST regime:
|
|
264
|
+
* const labels = GetDefaultTaxIdLabels("IN");
|
|
265
|
+
* // Returns: [
|
|
266
|
+
* // { Label: "GSTIN", Primary: true, Required: false, RegexValidate: "..." },
|
|
267
|
+
* // { Label: "PAN", Primary: false, Required: true, RegexValidate: "..." },
|
|
268
|
+
* // { Label: "CIN", Primary: false, Required: false },
|
|
269
|
+
* // ]
|
|
270
|
+
*/
|
|
271
|
+
export declare function GetDefaultTaxIdLabels(country: string): ITaxIdLabel[];
|
|
272
|
+
/**
|
|
273
|
+
* Filters TaxIds[] entries to only those marked for printing.
|
|
274
|
+
*
|
|
275
|
+
* Print logic: include if `Print` is `true` or `undefined` (default = print).
|
|
276
|
+
* Exclude only when `Print` is explicitly `false`.
|
|
277
|
+
*
|
|
278
|
+
* Used by invoice/PDF templates to determine which entity and
|
|
279
|
+
* customer/vendor tax IDs to render.
|
|
280
|
+
*
|
|
281
|
+
* @param taxIds - The TaxIds[] array from Entity Settings, Customer, or Vendor
|
|
282
|
+
* @returns Filtered array of printable entries
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* const entityTaxIds = [
|
|
286
|
+
* { Label: "GSTIN", Value: "29ABCDE1234F1Z5", Print: true },
|
|
287
|
+
* { Label: "PAN", Value: "ABCDE1234F", Print: false },
|
|
288
|
+
* { Label: "CIN", Value: "U12345MH2020PTC123456" }, // Print undefined = include
|
|
289
|
+
* ];
|
|
290
|
+
* GetPrintableTaxIds(entityTaxIds);
|
|
291
|
+
* // Returns: [{ Label: "GSTIN", Value: "29ABCDE1234F1Z5" }, { Label: "CIN", Value: "U12345MH2020PTC123456" }]
|
|
292
|
+
*/
|
|
293
|
+
export declare function GetPrintableTaxIds(taxIds: ITaxIdEntry[] | undefined): ITaxIdEntry[];
|
|
252
294
|
/**
|
|
253
295
|
* Calculates a withholding tax entry.
|
|
254
296
|
*
|
|
@@ -267,7 +309,7 @@ export declare function validateHSNSACLength(code: string, requiredLength: strin
|
|
|
267
309
|
*
|
|
268
310
|
* @example
|
|
269
311
|
* // India GST TDS — 2% on Rs 3,00,000 taxable value
|
|
270
|
-
* const tds =
|
|
312
|
+
* const tds = CalculateWithholding({
|
|
271
313
|
* Type: "Deducted",
|
|
272
314
|
* Section: "51",
|
|
273
315
|
* Rate: 2,
|
|
@@ -278,7 +320,7 @@ export declare function validateHSNSACLength(code: string, requiredLength: strin
|
|
|
278
320
|
*
|
|
279
321
|
* @example
|
|
280
322
|
* // India GST TCS — 1% on Rs 5,00,000 net value
|
|
281
|
-
* const tcs =
|
|
323
|
+
* const tcs = CalculateWithholding({
|
|
282
324
|
* Type: "Collected",
|
|
283
325
|
* Section: "52",
|
|
284
326
|
* Rate: 1,
|
|
@@ -289,7 +331,7 @@ export declare function validateHSNSACLength(code: string, requiredLength: strin
|
|
|
289
331
|
*
|
|
290
332
|
* @example
|
|
291
333
|
* // US Federal Withholding — 24% backup withholding
|
|
292
|
-
* const wht =
|
|
334
|
+
* const wht = CalculateWithholding({
|
|
293
335
|
* Type: "Deducted",
|
|
294
336
|
* Section: "FITW",
|
|
295
337
|
* Rate: 24,
|
|
@@ -298,7 +340,7 @@ export declare function validateHSNSACLength(code: string, requiredLength: strin
|
|
|
298
340
|
* });
|
|
299
341
|
* // Returns: { Type: "Deducted", Section: "FITW", Rate: 24, BaseAmt: 10000, Amt: 2400, PartyLiable: "Buyer" }
|
|
300
342
|
*/
|
|
301
|
-
export declare function
|
|
343
|
+
export declare function CalculateWithholding(input: IWithholdingCalcInput, rounding?: IRoundingConfig): IWithholding;
|
|
302
344
|
/**
|
|
303
345
|
* Converts legacy flat CGST/SGST/IGST fields to a Taxes[] array.
|
|
304
346
|
*
|
|
@@ -310,12 +352,12 @@ export declare function calculateWithholding(input: IWithholdingCalcInput, round
|
|
|
310
352
|
* @returns Array of ITaxComponent
|
|
311
353
|
*
|
|
312
354
|
* @example
|
|
313
|
-
* const taxes =
|
|
355
|
+
* const taxes = ConvertFlatToTaxes(
|
|
314
356
|
* { CGST: 450, SGST: 450, IGST: 0, TCode: 106, NetAmt: 5000 },
|
|
315
357
|
* gst18IntraTaxCode
|
|
316
358
|
* );
|
|
317
359
|
*/
|
|
318
|
-
export declare function
|
|
360
|
+
export declare function ConvertFlatToTaxes(lineItem: {
|
|
319
361
|
CGST?: number;
|
|
320
362
|
SGST?: number;
|
|
321
363
|
IGST?: number;
|
|
@@ -19,18 +19,20 @@ 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.
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.
|
|
30
|
-
exports.
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
33
|
-
exports.
|
|
22
|
+
exports.CalculateLineTax = CalculateLineTax;
|
|
23
|
+
exports.ExtractNetFromInclusive = ExtractNetFromInclusive;
|
|
24
|
+
exports.SumTaxComponents = SumTaxComponents;
|
|
25
|
+
exports.ComputeTaxSummary = ComputeTaxSummary;
|
|
26
|
+
exports.ComputeDocumentTotals = ComputeDocumentTotals;
|
|
27
|
+
exports.DetermineSupplyType = DetermineSupplyType;
|
|
28
|
+
exports.FindTaxCodeByRateAndSupplyType = FindTaxCodeByRateAndSupplyType;
|
|
29
|
+
exports.RoundAmount = RoundAmount;
|
|
30
|
+
exports.ValidateTaxId = ValidateTaxId;
|
|
31
|
+
exports.ValidateHSNSACLength = ValidateHSNSACLength;
|
|
32
|
+
exports.GetDefaultTaxIdLabels = GetDefaultTaxIdLabels;
|
|
33
|
+
exports.GetPrintableTaxIds = GetPrintableTaxIds;
|
|
34
|
+
exports.CalculateWithholding = CalculateWithholding;
|
|
35
|
+
exports.ConvertFlatToTaxes = ConvertFlatToTaxes;
|
|
34
36
|
const big_js_1 = __importDefault(require("big.js"));
|
|
35
37
|
const util_1 = require("../shared/util");
|
|
36
38
|
const math_operations_1 = require("../shared/math-operations");
|
|
@@ -49,7 +51,7 @@ const math_operations_1 = require("../shared/math-operations");
|
|
|
49
51
|
*
|
|
50
52
|
* @example
|
|
51
53
|
* // India GST 18% Intra-State on Rs 5,000 item
|
|
52
|
-
* const result =
|
|
54
|
+
* const result = CalculateLineTax({
|
|
53
55
|
* NetAmt: 5000,
|
|
54
56
|
* TaxCode: gst18IntraTaxCode,
|
|
55
57
|
* });
|
|
@@ -60,7 +62,7 @@ const math_operations_1 = require("../shared/math-operations");
|
|
|
60
62
|
*
|
|
61
63
|
* @example
|
|
62
64
|
* // India GST 28% + Specific Cess (Rs 12/liter) on 100 liters
|
|
63
|
-
* const result =
|
|
65
|
+
* const result = CalculateLineTax({
|
|
64
66
|
* NetAmt: 10000,
|
|
65
67
|
* Qty: 100,
|
|
66
68
|
* TaxCode: gst28CessDrinkTaxCode,
|
|
@@ -71,7 +73,7 @@ const math_operations_1 = require("../shared/math-operations");
|
|
|
71
73
|
* // { Code: "CESS", Rate: 0, Amt: 1200, TaxCodeId: 201 },
|
|
72
74
|
* // ]
|
|
73
75
|
*/
|
|
74
|
-
function
|
|
76
|
+
function CalculateLineTax(input, rounding = { Method: "Round", Precision: 2 }) {
|
|
75
77
|
const { TaxCode, RCM, ComponentOverrides } = input;
|
|
76
78
|
const netAmt = (0, util_1.GetNumber)(input.NetAmt);
|
|
77
79
|
const qty = (0, util_1.GetNumber)(input.Qty, 1);
|
|
@@ -95,21 +97,21 @@ function calculateLineTax(input, rounding = { Method: "Round", Precision: 2 }) {
|
|
|
95
97
|
for (const comp of TaxCode.Components) {
|
|
96
98
|
if (comp.AppliedOn !== "PostTax") {
|
|
97
99
|
// Apply ComponentOverrides if provided (e.g., CESS Rate/PerUnitAmt from item master)
|
|
98
|
-
const effectiveComp =
|
|
99
|
-
const calculated =
|
|
100
|
+
const effectiveComp = ApplyComponentOverride(comp, ComponentOverrides);
|
|
101
|
+
const calculated = CalculateSingleComponent(effectiveComp, netAmt, qty, lineRounding);
|
|
100
102
|
if (comp.Type === "Tax") {
|
|
101
103
|
primaryTaxTotal = (0, math_operations_1.Add)(primaryTaxTotal, calculated.Amt);
|
|
102
104
|
}
|
|
103
|
-
result.push(
|
|
105
|
+
result.push(BuildTaxComponent(effectiveComp, calculated.Amt, TaxCode._id));
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
// Second pass: calculate components that apply on PostTax (tax-on-tax)
|
|
107
109
|
for (const comp of TaxCode.Components) {
|
|
108
110
|
if (comp.AppliedOn === "PostTax") {
|
|
109
|
-
const effectiveComp =
|
|
111
|
+
const effectiveComp = ApplyComponentOverride(comp, ComponentOverrides);
|
|
110
112
|
const postTaxBase = (0, math_operations_1.Add)(netAmt, primaryTaxTotal);
|
|
111
|
-
const calculated =
|
|
112
|
-
result.push(
|
|
113
|
+
const calculated = CalculateSingleComponent(effectiveComp, postTaxBase, qty, lineRounding);
|
|
114
|
+
result.push(BuildTaxComponent(effectiveComp, calculated.Amt, TaxCode._id));
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
return result;
|
|
@@ -123,7 +125,7 @@ function calculateLineTax(input, rounding = { Method: "Round", Precision: 2 }) {
|
|
|
123
125
|
* Primary use case: CESS components where the TaxCode has placeholder values
|
|
124
126
|
* (Rate: 0, PerUnitAmt: 0) and the actual values come from the item master.
|
|
125
127
|
*/
|
|
126
|
-
function
|
|
128
|
+
function ApplyComponentOverride(comp, overrides) {
|
|
127
129
|
var _a, _b, _c;
|
|
128
130
|
if (!overrides)
|
|
129
131
|
return comp;
|
|
@@ -144,7 +146,7 @@ function applyComponentOverride(comp, overrides) {
|
|
|
144
146
|
* MaxOfPercentOrPerUnit is used for India CESS on tobacco categories where
|
|
145
147
|
* the cess is "X% or ₹Y per unit, whichever is higher" (CBIC notification).
|
|
146
148
|
*/
|
|
147
|
-
function
|
|
149
|
+
function CalculateSingleComponent(comp, baseAmt, qty, rounding) {
|
|
148
150
|
const method = comp.CalcMethod || "Percent";
|
|
149
151
|
let amt = 0;
|
|
150
152
|
let taxableAmt = baseAmt;
|
|
@@ -183,7 +185,7 @@ function calculateSingleComponent(comp, baseAmt, qty, rounding) {
|
|
|
183
185
|
}
|
|
184
186
|
}
|
|
185
187
|
// Apply rounding
|
|
186
|
-
amt =
|
|
188
|
+
amt = RoundAmount(amt, rounding);
|
|
187
189
|
return { Amt: amt, taxableAmt };
|
|
188
190
|
}
|
|
189
191
|
/**
|
|
@@ -201,7 +203,7 @@ function calculateSingleComponent(comp, baseAmt, qty, rounding) {
|
|
|
201
203
|
* TaxableAmt is NOT stored — it's derivable from line item fields (Qty × UnitPrice - Discount).
|
|
202
204
|
* TaxAmt (sum of Taxes[].Amt) is NOT stored — it's a simple addition, computed on the fly.
|
|
203
205
|
*/
|
|
204
|
-
function
|
|
206
|
+
function BuildTaxComponent(comp, amt, taxCodeId) {
|
|
205
207
|
const result = {
|
|
206
208
|
Code: comp.Code,
|
|
207
209
|
Rate: comp.Rate,
|
|
@@ -222,7 +224,7 @@ function buildTaxComponent(comp, amt, taxCodeId) {
|
|
|
222
224
|
}
|
|
223
225
|
return result;
|
|
224
226
|
}
|
|
225
|
-
function
|
|
227
|
+
function ExtractNetFromInclusive(inclusivePrice, taxCode, qty = 1, rounding = { Method: "Round", Precision: 2 }) {
|
|
226
228
|
if (!taxCode.Components || taxCode.Components.length === 0) {
|
|
227
229
|
return { NetAmt: inclusivePrice };
|
|
228
230
|
}
|
|
@@ -262,10 +264,10 @@ function extractNetFromInclusive(inclusivePrice, taxCode, qty = 1, rounding = {
|
|
|
262
264
|
let netAmt;
|
|
263
265
|
if (totalPercentRate > 0) {
|
|
264
266
|
const divisor = new big_js_1.default(1).plus(new big_js_1.default(totalPercentRate).div(100));
|
|
265
|
-
netAmt =
|
|
267
|
+
netAmt = RoundAmount(new big_js_1.default(priceAfterFixedDeduction).div(divisor).toNumber(), rounding);
|
|
266
268
|
}
|
|
267
269
|
else {
|
|
268
|
-
netAmt =
|
|
270
|
+
netAmt = RoundAmount(priceAfterFixedDeduction, rounding);
|
|
269
271
|
}
|
|
270
272
|
return { NetAmt: netAmt, Warning: warning };
|
|
271
273
|
}
|
|
@@ -279,10 +281,10 @@ function extractNetFromInclusive(inclusivePrice, taxCode, qty = 1, rounding = {
|
|
|
279
281
|
* @returns Total tax amount
|
|
280
282
|
*
|
|
281
283
|
* @example
|
|
282
|
-
* const totalTax =
|
|
284
|
+
* const totalTax = SumTaxComponents(lineItem.Taxes);
|
|
283
285
|
* // CGST 450 + SGST 450 = 900
|
|
284
286
|
*/
|
|
285
|
-
function
|
|
287
|
+
function SumTaxComponents(taxes) {
|
|
286
288
|
if (!taxes || taxes.length === 0)
|
|
287
289
|
return 0;
|
|
288
290
|
let total = 0;
|
|
@@ -306,13 +308,13 @@ function sumTaxComponents(taxes) {
|
|
|
306
308
|
*
|
|
307
309
|
* Rounding behavior (via input.Rounding):
|
|
308
310
|
* - TaxComponentTotal ON: each bucket's Amt is rounded to Precision
|
|
309
|
-
* - Otherwise: Amts are at currency precision (from
|
|
311
|
+
* - Otherwise: Amts are at currency precision (from CalculateLineTax)
|
|
310
312
|
*
|
|
311
313
|
* @param input - All line items with Taxes[] and NetAmt, plus regime code and optional rounding
|
|
312
314
|
* @returns ITaxSummary — the aggregated summary (stored on the document)
|
|
313
315
|
*
|
|
314
316
|
* @example
|
|
315
|
-
* const summary =
|
|
317
|
+
* const summary = ComputeTaxSummary({
|
|
316
318
|
* Lines: invoice.Items.map(item => ({
|
|
317
319
|
* Taxes: item.Taxes,
|
|
318
320
|
* NetAmt: item.UnAmt - item.Disc - item.RecDisc,
|
|
@@ -330,7 +332,7 @@ function sumTaxComponents(taxes) {
|
|
|
330
332
|
* // RegimeCode: "IN_GST"
|
|
331
333
|
* // }
|
|
332
334
|
*/
|
|
333
|
-
function
|
|
335
|
+
function ComputeTaxSummary(input) {
|
|
334
336
|
const { Lines, RegimeCode, Rounding } = input;
|
|
335
337
|
// Group by Code+Rate (more granular than Code-only for rate-wise reporting)
|
|
336
338
|
const groupMap = new Map();
|
|
@@ -370,7 +372,7 @@ function computeTaxSummary(input) {
|
|
|
370
372
|
let amt = group.Amt;
|
|
371
373
|
// If TaxComponentTotal rounding is active, round each bucket's Amt
|
|
372
374
|
if (Rounding === null || Rounding === void 0 ? void 0 : Rounding.TaxComponentTotal) {
|
|
373
|
-
amt =
|
|
375
|
+
amt = RoundAmount(amt, { Method: Rounding.Method, Precision: Rounding.Precision });
|
|
374
376
|
}
|
|
375
377
|
summaryLines.push({
|
|
376
378
|
Code: group.Code,
|
|
@@ -414,7 +416,7 @@ function computeTaxSummary(input) {
|
|
|
414
416
|
*
|
|
415
417
|
* @example
|
|
416
418
|
* // India GST invoice with 2 lines
|
|
417
|
-
* const totals =
|
|
419
|
+
* const totals = ComputeDocumentTotals({
|
|
418
420
|
* Lines: [
|
|
419
421
|
* { NetAmt: 5000, Taxes: [{ Code: "CGST", Rate: 9, Amt: 450, TaxCodeId: 1 },
|
|
420
422
|
* { Code: "SGST", Rate: 9, Amt: 450, TaxCodeId: 1 }] },
|
|
@@ -433,7 +435,7 @@ function computeTaxSummary(input) {
|
|
|
433
435
|
* // ]
|
|
434
436
|
* // }
|
|
435
437
|
*/
|
|
436
|
-
function
|
|
438
|
+
function ComputeDocumentTotals(input) {
|
|
437
439
|
const { Lines, Rounding, RegimeCode } = input;
|
|
438
440
|
// 1. SubTotal = sum of line NetAmts
|
|
439
441
|
let subTotal = 0;
|
|
@@ -441,7 +443,7 @@ function computeDocumentTotals(input) {
|
|
|
441
443
|
subTotal = (0, math_operations_1.Add)(subTotal, (0, util_1.GetNumber)(line.NetAmt));
|
|
442
444
|
}
|
|
443
445
|
// 2. TaxSummary (handles TaxComponentTotal rounding internally)
|
|
444
|
-
const taxSummary =
|
|
446
|
+
const taxSummary = ComputeTaxSummary({
|
|
445
447
|
Lines,
|
|
446
448
|
RegimeCode,
|
|
447
449
|
Rounding,
|
|
@@ -454,7 +456,7 @@ function computeDocumentTotals(input) {
|
|
|
454
456
|
let roundedTotal = grandTotal;
|
|
455
457
|
let roundAdj = 0;
|
|
456
458
|
if (Rounding.DocTotal !== false) { // default true
|
|
457
|
-
roundedTotal =
|
|
459
|
+
roundedTotal = RoundAmount(grandTotal, { Method: Rounding.Method, Precision: Rounding.Precision });
|
|
458
460
|
roundAdj = (0, math_operations_1.Subtract)(roundedTotal, grandTotal);
|
|
459
461
|
}
|
|
460
462
|
return {
|
|
@@ -482,11 +484,11 @@ function computeDocumentTotals(input) {
|
|
|
482
484
|
* @returns "Intra" if same state, "Inter" if different states, "Unknown" if data missing
|
|
483
485
|
*
|
|
484
486
|
* @example
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
487
|
+
* DetermineSupplyType("29", "29"); // "Intra" — both Karnataka
|
|
488
|
+
* DetermineSupplyType("29", "33"); // "Inter" — Karnataka to Tamil Nadu
|
|
489
|
+
* DetermineSupplyType("", "33"); // "Unknown" — seller state missing
|
|
488
490
|
*/
|
|
489
|
-
function
|
|
491
|
+
function DetermineSupplyType(sellerStateCode, buyerStateCode) {
|
|
490
492
|
if (!sellerStateCode || !buyerStateCode) {
|
|
491
493
|
return "Unknown";
|
|
492
494
|
}
|
|
@@ -506,9 +508,9 @@ function determineSupplyType(sellerStateCode, buyerStateCode) {
|
|
|
506
508
|
*
|
|
507
509
|
* @example
|
|
508
510
|
* // Find GST 18% Inter-State (simple percentage-only tax code)
|
|
509
|
-
* const interCode =
|
|
511
|
+
* const interCode = FindTaxCodeByRateAndSupplyType(allTaxCodes, 18, "Inter");
|
|
510
512
|
*/
|
|
511
|
-
function
|
|
513
|
+
function FindTaxCodeByRateAndSupplyType(taxCodes, combinedRate, supplyType) {
|
|
512
514
|
return taxCodes.find(tc => tc.IsActive &&
|
|
513
515
|
tc.CombinedRate === combinedRate &&
|
|
514
516
|
(tc.SupplyType === supplyType || tc.SupplyType === "All"));
|
|
@@ -524,7 +526,7 @@ function findTaxCodeByRateAndSupplyType(taxCodes, combinedRate, supplyType) {
|
|
|
524
526
|
* - Japan: truncate (floor) to whole numbers
|
|
525
527
|
* - Some EU countries: banker's rounding
|
|
526
528
|
*/
|
|
527
|
-
function
|
|
529
|
+
function RoundAmount(value, config) {
|
|
528
530
|
var _a;
|
|
529
531
|
const precision = (_a = config.Precision) !== null && _a !== void 0 ? _a : 2;
|
|
530
532
|
const big = new big_js_1.default((0, util_1.GetNumber)(value));
|
|
@@ -553,10 +555,10 @@ function roundAmount(value, config) {
|
|
|
553
555
|
*
|
|
554
556
|
* @example
|
|
555
557
|
* // Validate Indian GSTIN
|
|
556
|
-
*
|
|
558
|
+
* ValidateTaxId("29ABCDE1234F1Z5", "^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$");
|
|
557
559
|
* // Returns: true
|
|
558
560
|
*/
|
|
559
|
-
function
|
|
561
|
+
function ValidateTaxId(taxId, formatRegex) {
|
|
560
562
|
if (!taxId || !formatRegex)
|
|
561
563
|
return false;
|
|
562
564
|
try {
|
|
@@ -575,10 +577,10 @@ function validateTaxId(taxId, formatRegex) {
|
|
|
575
577
|
* @returns true if valid, false if invalid
|
|
576
578
|
*
|
|
577
579
|
* @example
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
+
* ValidateHSNSACLength("8471", "4"); // true
|
|
581
|
+
* ValidateHSNSACLength("8471", "6"); // false — needs 6 digits
|
|
580
582
|
*/
|
|
581
|
-
function
|
|
583
|
+
function ValidateHSNSACLength(code, requiredLength) {
|
|
582
584
|
if (!code)
|
|
583
585
|
return false;
|
|
584
586
|
const trimmed = code.trim();
|
|
@@ -587,6 +589,79 @@ function validateHSNSACLength(code, requiredLength) {
|
|
|
587
589
|
return false;
|
|
588
590
|
return trimmed.length >= len;
|
|
589
591
|
}
|
|
592
|
+
/**
|
|
593
|
+
* Returns default TaxIdLabels for a given country.
|
|
594
|
+
*
|
|
595
|
+
* Used as seed data when creating TaxRegime records. The returned array is
|
|
596
|
+
* stored on TaxRegime.Features.TaxIdLabels[], which becomes the source of truth.
|
|
597
|
+
* At runtime, UI reads TaxIdLabels from TaxRegime — NOT from this function.
|
|
598
|
+
*
|
|
599
|
+
* @param country - ISO 3166-1 alpha-2 country code ("IN", "AU", "US", etc.)
|
|
600
|
+
* @returns Array of ITaxIdLabel — default tax ID definitions for the country
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* // When seeding India GST regime:
|
|
604
|
+
* const labels = GetDefaultTaxIdLabels("IN");
|
|
605
|
+
* // Returns: [
|
|
606
|
+
* // { Label: "GSTIN", Primary: true, Required: false, RegexValidate: "..." },
|
|
607
|
+
* // { Label: "PAN", Primary: false, Required: true, RegexValidate: "..." },
|
|
608
|
+
* // { Label: "CIN", Primary: false, Required: false },
|
|
609
|
+
* // ]
|
|
610
|
+
*/
|
|
611
|
+
function GetDefaultTaxIdLabels(country) {
|
|
612
|
+
switch (country) {
|
|
613
|
+
case "IN": return [
|
|
614
|
+
{ Label: "GSTIN", Required: false, Primary: true, RegexValidate: "^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$" },
|
|
615
|
+
{ Label: "PAN", Required: true, Primary: false, RegexValidate: "^[A-Z]{5}[0-9]{4}[A-Z]{1}$" },
|
|
616
|
+
{ Label: "CIN", Required: false, Primary: false },
|
|
617
|
+
];
|
|
618
|
+
case "AU": return [
|
|
619
|
+
{ Label: "ABN", Required: true, Primary: true, RegexValidate: "^[0-9]{11}$" },
|
|
620
|
+
];
|
|
621
|
+
case "US": return [
|
|
622
|
+
{ Label: "EIN", Required: false, Primary: true, RegexValidate: "^[0-9]{2}-[0-9]{7}$" },
|
|
623
|
+
];
|
|
624
|
+
case "GB": return [
|
|
625
|
+
{ Label: "VAT No", Required: true, Primary: true, RegexValidate: "^GB[0-9]{9}$" },
|
|
626
|
+
];
|
|
627
|
+
case "AE": return [
|
|
628
|
+
{ Label: "TRN", Required: true, Primary: true, RegexValidate: "^[0-9]{15}$" },
|
|
629
|
+
];
|
|
630
|
+
case "CA": return [
|
|
631
|
+
{ Label: "BN", Required: true, Primary: true },
|
|
632
|
+
{ Label: "GST/HST No", Required: false, Primary: false },
|
|
633
|
+
];
|
|
634
|
+
default: return [
|
|
635
|
+
{ Label: "Tax ID", Required: false, Primary: true },
|
|
636
|
+
];
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Filters TaxIds[] entries to only those marked for printing.
|
|
641
|
+
*
|
|
642
|
+
* Print logic: include if `Print` is `true` or `undefined` (default = print).
|
|
643
|
+
* Exclude only when `Print` is explicitly `false`.
|
|
644
|
+
*
|
|
645
|
+
* Used by invoice/PDF templates to determine which entity and
|
|
646
|
+
* customer/vendor tax IDs to render.
|
|
647
|
+
*
|
|
648
|
+
* @param taxIds - The TaxIds[] array from Entity Settings, Customer, or Vendor
|
|
649
|
+
* @returns Filtered array of printable entries
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* const entityTaxIds = [
|
|
653
|
+
* { Label: "GSTIN", Value: "29ABCDE1234F1Z5", Print: true },
|
|
654
|
+
* { Label: "PAN", Value: "ABCDE1234F", Print: false },
|
|
655
|
+
* { Label: "CIN", Value: "U12345MH2020PTC123456" }, // Print undefined = include
|
|
656
|
+
* ];
|
|
657
|
+
* GetPrintableTaxIds(entityTaxIds);
|
|
658
|
+
* // Returns: [{ Label: "GSTIN", Value: "29ABCDE1234F1Z5" }, { Label: "CIN", Value: "U12345MH2020PTC123456" }]
|
|
659
|
+
*/
|
|
660
|
+
function GetPrintableTaxIds(taxIds) {
|
|
661
|
+
if (!taxIds || taxIds.length === 0)
|
|
662
|
+
return [];
|
|
663
|
+
return taxIds.filter(t => t.Print !== false);
|
|
664
|
+
}
|
|
590
665
|
// ============================================================
|
|
591
666
|
// Withholding Tax — Generic TDS/TCS for all countries
|
|
592
667
|
// ============================================================
|
|
@@ -608,7 +683,7 @@ function validateHSNSACLength(code, requiredLength) {
|
|
|
608
683
|
*
|
|
609
684
|
* @example
|
|
610
685
|
* // India GST TDS — 2% on Rs 3,00,000 taxable value
|
|
611
|
-
* const tds =
|
|
686
|
+
* const tds = CalculateWithholding({
|
|
612
687
|
* Type: "Deducted",
|
|
613
688
|
* Section: "51",
|
|
614
689
|
* Rate: 2,
|
|
@@ -619,7 +694,7 @@ function validateHSNSACLength(code, requiredLength) {
|
|
|
619
694
|
*
|
|
620
695
|
* @example
|
|
621
696
|
* // India GST TCS — 1% on Rs 5,00,000 net value
|
|
622
|
-
* const tcs =
|
|
697
|
+
* const tcs = CalculateWithholding({
|
|
623
698
|
* Type: "Collected",
|
|
624
699
|
* Section: "52",
|
|
625
700
|
* Rate: 1,
|
|
@@ -630,7 +705,7 @@ function validateHSNSACLength(code, requiredLength) {
|
|
|
630
705
|
*
|
|
631
706
|
* @example
|
|
632
707
|
* // US Federal Withholding — 24% backup withholding
|
|
633
|
-
* const wht =
|
|
708
|
+
* const wht = CalculateWithholding({
|
|
634
709
|
* Type: "Deducted",
|
|
635
710
|
* Section: "FITW",
|
|
636
711
|
* Rate: 24,
|
|
@@ -639,10 +714,10 @@ function validateHSNSACLength(code, requiredLength) {
|
|
|
639
714
|
* });
|
|
640
715
|
* // Returns: { Type: "Deducted", Section: "FITW", Rate: 24, BaseAmt: 10000, Amt: 2400, PartyLiable: "Buyer" }
|
|
641
716
|
*/
|
|
642
|
-
function
|
|
717
|
+
function CalculateWithholding(input, rounding = { Method: "Round", Precision: 2 }) {
|
|
643
718
|
const baseAmt = (0, util_1.GetNumber)(input.BaseAmt);
|
|
644
719
|
const rate = (0, util_1.GetNumber)(input.Rate);
|
|
645
|
-
const amt =
|
|
720
|
+
const amt = RoundAmount((0, math_operations_1.Multiply)(baseAmt, (0, math_operations_1.Divide)(rate, 100)), rounding);
|
|
646
721
|
return {
|
|
647
722
|
Type: input.Type,
|
|
648
723
|
Section: input.Section,
|
|
@@ -666,12 +741,12 @@ function calculateWithholding(input, rounding = { Method: "Round", Precision: 2
|
|
|
666
741
|
* @returns Array of ITaxComponent
|
|
667
742
|
*
|
|
668
743
|
* @example
|
|
669
|
-
* const taxes =
|
|
744
|
+
* const taxes = ConvertFlatToTaxes(
|
|
670
745
|
* { CGST: 450, SGST: 450, IGST: 0, TCode: 106, NetAmt: 5000 },
|
|
671
746
|
* gst18IntraTaxCode
|
|
672
747
|
* );
|
|
673
748
|
*/
|
|
674
|
-
function
|
|
749
|
+
function ConvertFlatToTaxes(lineItem, taxCode) {
|
|
675
750
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
676
751
|
const taxes = [];
|
|
677
752
|
const netAmt = (0, util_1.GetNumber)(lineItem.NetAmt);
|
|
@@ -683,7 +758,7 @@ function convertFlatToTaxes(lineItem, taxCode) {
|
|
|
683
758
|
const rate = (_c = (_b = (_a = taxCode === null || taxCode === void 0 ? void 0 : taxCode.Components) === null || _a === void 0 ? void 0 : _a.find(c => c.Code === "CGST")) === null || _b === void 0 ? void 0 : _b.Rate) !== null && _c !== void 0 ? _c : (netAmt > 0 ? (0, math_operations_1.Multiply)((0, math_operations_1.Divide)(cgst, netAmt), 100) : 0);
|
|
684
759
|
taxes.push({
|
|
685
760
|
Code: "CGST",
|
|
686
|
-
Rate:
|
|
761
|
+
Rate: RoundAmount(rate, { Method: "Round", Precision: 4 }),
|
|
687
762
|
Amt: cgst,
|
|
688
763
|
TaxCodeId: taxCodeId,
|
|
689
764
|
});
|
|
@@ -692,7 +767,7 @@ function convertFlatToTaxes(lineItem, taxCode) {
|
|
|
692
767
|
const rate = (_f = (_e = (_d = taxCode === null || taxCode === void 0 ? void 0 : taxCode.Components) === null || _d === void 0 ? void 0 : _d.find(c => c.Code === "SGST")) === null || _e === void 0 ? void 0 : _e.Rate) !== null && _f !== void 0 ? _f : (netAmt > 0 ? (0, math_operations_1.Multiply)((0, math_operations_1.Divide)(sgst, netAmt), 100) : 0);
|
|
693
768
|
taxes.push({
|
|
694
769
|
Code: "SGST",
|
|
695
|
-
Rate:
|
|
770
|
+
Rate: RoundAmount(rate, { Method: "Round", Precision: 4 }),
|
|
696
771
|
Amt: sgst,
|
|
697
772
|
TaxCodeId: taxCodeId,
|
|
698
773
|
});
|
|
@@ -701,7 +776,7 @@ function convertFlatToTaxes(lineItem, taxCode) {
|
|
|
701
776
|
const rate = (_j = (_h = (_g = taxCode === null || taxCode === void 0 ? void 0 : taxCode.Components) === null || _g === void 0 ? void 0 : _g.find(c => c.Code === "IGST")) === null || _h === void 0 ? void 0 : _h.Rate) !== null && _j !== void 0 ? _j : (netAmt > 0 ? (0, math_operations_1.Multiply)((0, math_operations_1.Divide)(igst, netAmt), 100) : 0);
|
|
702
777
|
taxes.push({
|
|
703
778
|
Code: "IGST",
|
|
704
|
-
Rate:
|
|
779
|
+
Rate: RoundAmount(rate, { Method: "Round", Precision: 4 }),
|
|
705
780
|
Amt: igst,
|
|
706
781
|
TaxCodeId: taxCodeId,
|
|
707
782
|
});
|
package/dist/tax/tax.types.d.ts
CHANGED
|
@@ -40,8 +40,10 @@ export interface IRegimeFeatures {
|
|
|
40
40
|
HasWithholding: boolean;
|
|
41
41
|
HasHSN: boolean;
|
|
42
42
|
HasSAC: boolean;
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
/** Tax ID field definitions for this regime.
|
|
44
|
+
* UI reads this to build tax ID forms on Entity Settings, Customer, and Vendor screens.
|
|
45
|
+
* Only Primary entries are shown on Customer/Vendor; all shown on Entity Settings. */
|
|
46
|
+
TaxIdLabels?: ITaxIdLabel[];
|
|
45
47
|
}
|
|
46
48
|
/** Rounding rules for a regime.
|
|
47
49
|
* Three rounding points control WHERE in the calculation chain rounding is applied.
|
|
@@ -326,6 +328,25 @@ export interface IDocumentTotals {
|
|
|
326
328
|
/** Final amount: GrandTotal + Round */
|
|
327
329
|
Total: number;
|
|
328
330
|
}
|
|
331
|
+
/** Defines a tax ID field on TaxRegime — the source of truth for what tax IDs a regime needs.
|
|
332
|
+
* UI reads TaxRegime.Features.TaxIdLabels[] to build form fields dynamically.
|
|
333
|
+
* Entity Settings shows all entries; Customer/Vendor shows only Primary entries. */
|
|
334
|
+
export interface ITaxIdLabel {
|
|
335
|
+
/** Display label — "GSTIN", "PAN", "CIN", "ABN", "EIN", "VAT No" */
|
|
336
|
+
Label: string;
|
|
337
|
+
/** Regex pattern for format validation (e.g., "^[0-9]{2}[A-Z]{5}..." for GSTIN) */
|
|
338
|
+
RegexValidate?: string;
|
|
339
|
+
/** UI hint — should the form field be required? (not a mongoose-level required) */
|
|
340
|
+
Required?: boolean;
|
|
341
|
+
/** Show on Customer/Vendor screens too? If false/undefined, only shown on Entity Settings. */
|
|
342
|
+
Primary?: boolean;
|
|
343
|
+
}
|
|
344
|
+
/** A stored tax ID entry on Entity Settings, Customer, or Vendor */
|
|
345
|
+
export interface ITaxIdEntry {
|
|
346
|
+
Label: string;
|
|
347
|
+
Value: string;
|
|
348
|
+
Print?: boolean;
|
|
349
|
+
}
|
|
329
350
|
/**
|
|
330
351
|
* Tax exemption reasons — used when a line item or contact is exempt from tax.
|
|
331
352
|
*
|