shareneus 1.7.335 → 1.7.337
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.
|
@@ -55,7 +55,6 @@ class InvoiceTotalsService {
|
|
|
55
55
|
}
|
|
56
56
|
static CalculateLaborValues(opCodesList, IsIndependentTax) {
|
|
57
57
|
opCodesList = this.ResetLaborValues(opCodesList, IsIndependentTax);
|
|
58
|
-
console.log('opCodesList', opCodesList);
|
|
59
58
|
// opCodesList = this.GetOperationsDiscountPrice(opCodesList);
|
|
60
59
|
// opCodesList = this.GetOperationsAfterDiscount(opCodesList,IsIndependentTax);
|
|
61
60
|
// opCodesList = this.GetOperationsAfterTax(opCodesList, IsIndependentTax);
|
|
@@ -78,7 +78,7 @@ function DiscountAndTaxCalculation(recordData, isTaxable, taxcodes = []) {
|
|
|
78
78
|
labor.RecDisc = totalTransactionDiscount;
|
|
79
79
|
const laborafterDiscPrice = (0, math_operations_1.Subtract)(labor.Amt, labor.Disc);
|
|
80
80
|
const afterDisc = (0, math_operations_1.Subtract)(laborafterDiscPrice, totalTransactionDiscount);
|
|
81
|
-
labor.Taxes = recalculateTaxes(afterDisc, labor.TCode, taxcodes, labor.Taxes);
|
|
81
|
+
labor.Taxes = recalculateTaxes(afterDisc, labor.TCode, taxcodes, labor.Taxes, labor.Qty || 1);
|
|
82
82
|
return labor;
|
|
83
83
|
});
|
|
84
84
|
// ---------- STEP 8: PROCESS INVENTORY ITEMS ----------
|
|
@@ -99,7 +99,7 @@ function DiscountAndTaxCalculation(recordData, isTaxable, taxcodes = []) {
|
|
|
99
99
|
item.RecDisc = totalTransactionDiscount;
|
|
100
100
|
const ItemafterDiscPrice = (0, math_operations_1.Subtract)(item.UnAmt, item.Disc);
|
|
101
101
|
const afterDisc = (0, math_operations_1.Subtract)(ItemafterDiscPrice, totalTransactionDiscount);
|
|
102
|
-
item.Taxes = recalculateTaxes(afterDisc, item.TCode, taxcodes, item.Taxes);
|
|
102
|
+
item.Taxes = recalculateTaxes(afterDisc, item.TCode, taxcodes, item.Taxes, item.Qty);
|
|
103
103
|
return item;
|
|
104
104
|
});
|
|
105
105
|
// ---------- STEP 9: FINALIZE ----------
|
|
@@ -107,18 +107,48 @@ function DiscountAndTaxCalculation(recordData, isTaxable, taxcodes = []) {
|
|
|
107
107
|
recordData.Ops = [...finalServices, ...nonDiscountableOps];
|
|
108
108
|
return recordData;
|
|
109
109
|
}
|
|
110
|
-
function recalculateTaxes(amount, taxCode, taxCodes = [], existingTaxes = []) {
|
|
110
|
+
function recalculateTaxes(amount, taxCode, taxCodes = [], existingTaxes = [], qty = 1) {
|
|
111
111
|
const normalizedTaxCode = tr_utils_1.TrUtils.IsNull(taxCode) ? null : Number(taxCode);
|
|
112
112
|
const defaultRates = getDefaultTaxRates(taxCode, taxCodes);
|
|
113
|
+
const normalizedQty = toFiniteNumber(qty, 1);
|
|
113
114
|
return (Array.isArray(existingTaxes) ? existingTaxes : []).map((tax) => {
|
|
115
|
+
var _a, _b;
|
|
114
116
|
const code = tax === null || tax === void 0 ? void 0 : tax.Code;
|
|
115
117
|
const rate = Number(tax === null || tax === void 0 ? void 0 : tax.Rate);
|
|
116
118
|
const normalizedRate = Number.isFinite(rate) ? rate : (defaultRates[code] || 0);
|
|
117
|
-
|
|
119
|
+
const calcMethod = normalizeCalcMethod(tax === null || tax === void 0 ? void 0 : tax.CalcMethod);
|
|
120
|
+
return Object.assign(Object.assign({}, tax), { Rate: normalizedRate, Amt: calculateComponentTaxAmount(amount, normalizedRate, tax, normalizedQty), TaxCodeId: !tr_utils_1.TrUtils.IsNull(tax === null || tax === void 0 ? void 0 : tax.TaxCodeId)
|
|
118
121
|
? Number(tax.TaxCodeId)
|
|
119
|
-
: normalizedTaxCode });
|
|
122
|
+
: normalizedTaxCode, PerUnitAmt: (tax === null || tax === void 0 ? void 0 : tax.PerUnitAmt) || undefined, CalcMethod: calcMethod, Unit: (_b = (_a = tax === null || tax === void 0 ? void 0 : tax.Unit) !== null && _a !== void 0 ? _a : tax === null || tax === void 0 ? void 0 : tax.Units) !== null && _b !== void 0 ? _b : undefined });
|
|
120
123
|
});
|
|
121
124
|
}
|
|
125
|
+
function calculateComponentTaxAmount(amount, rate, tax, qty) {
|
|
126
|
+
const baseAmt = toFiniteNumber(amount);
|
|
127
|
+
const calcMethod = normalizeCalcMethod(tax === null || tax === void 0 ? void 0 : tax.CalcMethod);
|
|
128
|
+
const perUnitAmt = toFiniteNumber(tax === null || tax === void 0 ? void 0 : tax.PerUnitAmt);
|
|
129
|
+
const perUnitResult = (0, math_operations_1.Multiply)(perUnitAmt, qty);
|
|
130
|
+
const percentResult = (0, math_operations_1.Multiply)(baseAmt, (0, math_operations_1.Divide)(rate, 100));
|
|
131
|
+
switch (calcMethod) {
|
|
132
|
+
case 'PerUnit':
|
|
133
|
+
return perUnitResult;
|
|
134
|
+
case 'PerUnitPlusPercent':
|
|
135
|
+
return (0, math_operations_1.Add)(perUnitResult, percentResult);
|
|
136
|
+
case 'MaxOfPercentOrPerUnit':
|
|
137
|
+
return Math.max(perUnitResult, percentResult);
|
|
138
|
+
case 'Percent':
|
|
139
|
+
default:
|
|
140
|
+
return percentResult;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function normalizeCalcMethod(calcMethod) {
|
|
144
|
+
return calcMethod === 'Percentage' || tr_utils_1.TrUtils.IsNull(calcMethod)
|
|
145
|
+
? 'Percent'
|
|
146
|
+
: calcMethod;
|
|
147
|
+
}
|
|
148
|
+
function toFiniteNumber(value, fallback = 0) {
|
|
149
|
+
const normalized = Number(value);
|
|
150
|
+
return Number.isFinite(normalized) ? normalized : fallback;
|
|
151
|
+
}
|
|
122
152
|
function getDefaultTaxRates(taxCode, taxCodes = []) {
|
|
123
153
|
const normalizedTaxCode = tr_utils_1.TrUtils.IsNull(taxCode) ? null : taxCode;
|
|
124
154
|
const taxCodeRow = Array.isArray(taxCodes)
|
|
@@ -139,6 +169,7 @@ function getDefaultTaxRates(taxCode, taxCodes = []) {
|
|
|
139
169
|
let CGST = getComponentRate('CGST');
|
|
140
170
|
let SGST = getComponentRate('SGST');
|
|
141
171
|
let IGST = getComponentRate('IGST');
|
|
172
|
+
const CESS = getComponentRate('CESS');
|
|
142
173
|
if (CGST === 0 && SGST === 0 && IGST === 0) {
|
|
143
174
|
const gstRateSum = transaction_calculation_engine_1.TransactionCalculationEngine.getGSTRateSumByTaxCode(normalizedTaxCode, taxCodes);
|
|
144
175
|
if (components.length === 1) {
|
|
@@ -149,7 +180,7 @@ function getDefaultTaxRates(taxCode, taxCodes = []) {
|
|
|
149
180
|
SGST = gstRateSum / 2;
|
|
150
181
|
}
|
|
151
182
|
}
|
|
152
|
-
return { CGST, SGST, IGST };
|
|
183
|
+
return { CGST, SGST, IGST, CESS };
|
|
153
184
|
}
|
|
154
185
|
/**
|
|
155
186
|
* Calculates the record-level discount amount (RecDisc) for a single line.
|
package/package.json
CHANGED
|
@@ -71,7 +71,7 @@ export class InvoiceTotalsService {
|
|
|
71
71
|
|
|
72
72
|
static CalculateLaborValues(opCodesList: any, IsIndependentTax: boolean) {
|
|
73
73
|
opCodesList = this.ResetLaborValues(opCodesList, IsIndependentTax);
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
// opCodesList = this.GetOperationsDiscountPrice(opCodesList);
|
|
76
76
|
|
|
77
77
|
// opCodesList = this.GetOperationsAfterDiscount(opCodesList,IsIndependentTax);
|
|
@@ -101,7 +101,7 @@ export function DiscountAndTaxCalculation(recordData: any, isTaxable: boolean, t
|
|
|
101
101
|
const laborafterDiscPrice = Subtract(labor.Amt, labor.Disc);
|
|
102
102
|
const afterDisc = Subtract(laborafterDiscPrice, totalTransactionDiscount);
|
|
103
103
|
|
|
104
|
-
labor.Taxes = recalculateTaxes(afterDisc, labor.TCode, taxcodes, labor.Taxes);
|
|
104
|
+
labor.Taxes = recalculateTaxes(afterDisc, labor.TCode, taxcodes, labor.Taxes, labor.Qty || 1);
|
|
105
105
|
|
|
106
106
|
return labor;
|
|
107
107
|
});
|
|
@@ -134,7 +134,7 @@ export function DiscountAndTaxCalculation(recordData: any, isTaxable: boolean, t
|
|
|
134
134
|
const ItemafterDiscPrice = Subtract(item.UnAmt, item.Disc);
|
|
135
135
|
const afterDisc = Subtract(ItemafterDiscPrice, totalTransactionDiscount);
|
|
136
136
|
|
|
137
|
-
item.Taxes = recalculateTaxes(afterDisc, item.TCode, taxcodes, item.Taxes);
|
|
137
|
+
item.Taxes = recalculateTaxes(afterDisc, item.TCode, taxcodes, item.Taxes, item.Qty);
|
|
138
138
|
|
|
139
139
|
return item;
|
|
140
140
|
});
|
|
@@ -146,26 +146,62 @@ export function DiscountAndTaxCalculation(recordData: any, isTaxable: boolean, t
|
|
|
146
146
|
return recordData;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
function recalculateTaxes(amount: any, taxCode: any, taxCodes: any[] = [], existingTaxes: any[] = []): any[] {
|
|
149
|
+
function recalculateTaxes(amount: any, taxCode: any, taxCodes: any[] = [], existingTaxes: any[] = [], qty: any = 1): any[] {
|
|
150
150
|
const normalizedTaxCode = TrUtils.IsNull(taxCode) ? null : Number(taxCode);
|
|
151
151
|
const defaultRates = getDefaultTaxRates(taxCode, taxCodes);
|
|
152
|
+
const normalizedQty = toFiniteNumber(qty, 1);
|
|
152
153
|
|
|
153
154
|
return (Array.isArray(existingTaxes) ? existingTaxes : []).map((tax: any) => {
|
|
154
155
|
const code = tax?.Code;
|
|
155
156
|
const rate = Number(tax?.Rate);
|
|
156
157
|
const normalizedRate = Number.isFinite(rate) ? rate : (defaultRates[code] || 0);
|
|
158
|
+
const calcMethod = normalizeCalcMethod(tax?.CalcMethod);
|
|
157
159
|
|
|
158
160
|
return {
|
|
159
161
|
...tax,
|
|
160
162
|
Rate: normalizedRate,
|
|
161
|
-
Amt:
|
|
163
|
+
Amt: calculateComponentTaxAmount(amount, normalizedRate, tax, normalizedQty),
|
|
162
164
|
TaxCodeId: !TrUtils.IsNull(tax?.TaxCodeId)
|
|
163
165
|
? Number(tax.TaxCodeId)
|
|
164
|
-
: normalizedTaxCode
|
|
166
|
+
: normalizedTaxCode,
|
|
167
|
+
PerUnitAmt: tax?.PerUnitAmt || undefined,
|
|
168
|
+
CalcMethod: calcMethod,
|
|
169
|
+
Unit: tax?.Unit ?? tax?.Units ?? undefined,
|
|
165
170
|
};
|
|
166
171
|
});
|
|
167
172
|
}
|
|
168
173
|
|
|
174
|
+
function calculateComponentTaxAmount(amount: any, rate: number, tax: any, qty: number): number {
|
|
175
|
+
const baseAmt = toFiniteNumber(amount);
|
|
176
|
+
const calcMethod = normalizeCalcMethod(tax?.CalcMethod);
|
|
177
|
+
const perUnitAmt = toFiniteNumber(tax?.PerUnitAmt);
|
|
178
|
+
const perUnitResult = Multiply(perUnitAmt, qty);
|
|
179
|
+
const percentResult = Multiply(baseAmt, Divide(rate, 100));
|
|
180
|
+
|
|
181
|
+
switch (calcMethod) {
|
|
182
|
+
case 'PerUnit':
|
|
183
|
+
return perUnitResult;
|
|
184
|
+
case 'PerUnitPlusPercent':
|
|
185
|
+
return Add(perUnitResult, percentResult);
|
|
186
|
+
case 'MaxOfPercentOrPerUnit':
|
|
187
|
+
return Math.max(perUnitResult, percentResult);
|
|
188
|
+
case 'Percent':
|
|
189
|
+
default:
|
|
190
|
+
return percentResult;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function normalizeCalcMethod(calcMethod: any): string {
|
|
195
|
+
return calcMethod === 'Percentage' || TrUtils.IsNull(calcMethod)
|
|
196
|
+
? 'Percent'
|
|
197
|
+
: calcMethod;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function toFiniteNumber(value: any, fallback = 0): number {
|
|
201
|
+
const normalized = Number(value);
|
|
202
|
+
return Number.isFinite(normalized) ? normalized : fallback;
|
|
203
|
+
}
|
|
204
|
+
|
|
169
205
|
function getDefaultTaxRates(taxCode: any, taxCodes: any[] = []): any {
|
|
170
206
|
const normalizedTaxCode = TrUtils.IsNull(taxCode) ? null : taxCode;
|
|
171
207
|
const taxCodeRow = Array.isArray(taxCodes)
|
|
@@ -187,6 +223,7 @@ function getDefaultTaxRates(taxCode: any, taxCodes: any[] = []): any {
|
|
|
187
223
|
let CGST = getComponentRate('CGST');
|
|
188
224
|
let SGST = getComponentRate('SGST');
|
|
189
225
|
let IGST = getComponentRate('IGST');
|
|
226
|
+
const CESS = getComponentRate('CESS');
|
|
190
227
|
|
|
191
228
|
if (CGST === 0 && SGST === 0 && IGST === 0) {
|
|
192
229
|
const gstRateSum =
|
|
@@ -202,7 +239,7 @@ function getDefaultTaxRates(taxCode: any, taxCodes: any[] = []): any {
|
|
|
202
239
|
}
|
|
203
240
|
}
|
|
204
241
|
|
|
205
|
-
return { CGST, SGST, IGST };
|
|
242
|
+
return { CGST, SGST, IGST, CESS };
|
|
206
243
|
}
|
|
207
244
|
|
|
208
245
|
/**
|