shareneus 1.4.98 → 1.5.0
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.
|
@@ -563,7 +563,7 @@ class SalesReceivePdfService {
|
|
|
563
563
|
}
|
|
564
564
|
static CommonTotalDetails(SRPrintData, moreDiscDetails) {
|
|
565
565
|
let CommonDetails = [
|
|
566
|
-
shared_pdf_service_1.SharedPDFService.GetDebitTotalDetails(SRPrintData, 0, 0, 0, 0, 0, SRPrintData.
|
|
566
|
+
shared_pdf_service_1.SharedPDFService.GetDebitTotalDetails(SRPrintData, 0, 0, 0, 0, 0, SRPrintData.totalIGST, SRPrintData.ShowIGST, SRPrintData.ShowTaxColumn, SRPrintData.subtotal, SRPrintData.totalDiscount, SRPrintData.totalCGST, SRPrintData.totalSGST, SRPrintData.CustTaxGroupData, SRPrintData.ShowAccParts, SRPrintData.CustLaborAfterTax, SRPrintData.CustPartAfterTax, SRPrintData.FixedDisc, SRPrintData.For, SRPrintData.total, SRPrintData.roundOff, SRPrintData.totalAfterRounded, SRPrintData.ShowTaxColumn, SRPrintData.ShowTaxColumn, tr_utils_1.TrUtils.isTaxable(SRPrintData.Settings.Tax), SRPrintData.CustLaborITax, SRPrintData.totalTax, SRPrintData.Consolidate, SRPrintData.From, moreDiscDetails),
|
|
567
567
|
shared_pdf_service_1.SharedPDFService.InvoiceDueStatus(SRPrintData.Type, SRPrintData.Paid, SRPrintData.Due, SRPrintData.Sts, false, SRPrintData.Entity.DecimalsNumber),
|
|
568
568
|
shared_pdf_service_1.SharedPDFService.GetTemsAndConditions(SRPrintData.Entity.Terms),
|
|
569
569
|
shared_pdf_service_1.SharedPDFService.GetUnderLine(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export declare function SalesTotalCalculations(items?: any[], ops?: any[], isTaxable?: boolean): any;
|
|
1
|
+
export declare function SalesTotalCalculations(items?: any[], ops?: any[], isTaxable?: boolean, taxCodes?: any[]): any;
|
|
2
2
|
/**
|
|
3
3
|
* Enhanced version with decimal places control
|
|
4
4
|
*/
|
|
5
|
-
export declare function SalesTotalCalculationsWithDecimals(items?: any[], ops?: any[], isTaxable?: boolean, decimalPlaces?: number): any;
|
|
5
|
+
export declare function SalesTotalCalculationsWithDecimals(items?: any[], ops?: any[], isTaxable?: boolean, taxCodes?: any[], decimalPlaces?: number): any;
|
|
6
|
+
export declare function CalculateTaxSummary(items: any[], taxCodes: any[]): unknown[];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SalesTotalCalculations = SalesTotalCalculations;
|
|
4
4
|
exports.SalesTotalCalculationsWithDecimals = SalesTotalCalculationsWithDecimals;
|
|
5
|
+
exports.CalculateTaxSummary = CalculateTaxSummary;
|
|
5
6
|
const math_operations_1 = require("../shared/math-operations");
|
|
6
7
|
const util_1 = require("../shared/util");
|
|
7
8
|
/**
|
|
@@ -10,10 +11,11 @@ const util_1 = require("../shared/util");
|
|
|
10
11
|
function safeArray(arr) {
|
|
11
12
|
return Array.isArray(arr) ? arr : [];
|
|
12
13
|
}
|
|
13
|
-
function SalesTotalCalculations(items = [], ops = [], isTaxable = false) {
|
|
14
|
+
function SalesTotalCalculations(items = [], ops = [], isTaxable = false, taxCodes = []) {
|
|
14
15
|
// Handle null/undefined arrays
|
|
15
16
|
const safeItems = safeArray(items);
|
|
16
17
|
const safeOps = safeArray(ops);
|
|
18
|
+
const safeTaxCodes = safeArray(taxCodes);
|
|
17
19
|
// Initialize all totals
|
|
18
20
|
let total = 0;
|
|
19
21
|
let subtotalOnItems = 0;
|
|
@@ -26,6 +28,7 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false) {
|
|
|
26
28
|
let totalDiscountOnItems = 0;
|
|
27
29
|
let totalDiscountOnLabor = 0;
|
|
28
30
|
let roundOff = 0;
|
|
31
|
+
let totalAfterRounded = 0;
|
|
29
32
|
// Tax breakdown totals - only calculate if taxable
|
|
30
33
|
let totalSGST = 0;
|
|
31
34
|
let totalCGST = 0;
|
|
@@ -93,10 +96,11 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false) {
|
|
|
93
96
|
const roundedTotal = Math.round(total);
|
|
94
97
|
roundOff = (0, math_operations_1.Subtract)(roundedTotal, total);
|
|
95
98
|
// Update total to rounded value
|
|
96
|
-
|
|
99
|
+
totalAfterRounded = roundedTotal;
|
|
97
100
|
// Base return object
|
|
98
101
|
const result = {
|
|
99
102
|
total,
|
|
103
|
+
totalAfterRounded,
|
|
100
104
|
subtotal,
|
|
101
105
|
totalDiscount,
|
|
102
106
|
roundOff,
|
|
@@ -106,7 +110,7 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false) {
|
|
|
106
110
|
totalDiscountOnLabor,
|
|
107
111
|
netAmountAfterDiscount
|
|
108
112
|
};
|
|
109
|
-
// Only include tax fields if taxable
|
|
113
|
+
// Only include tax fields and taxSummary if taxable
|
|
110
114
|
if (isTaxable) {
|
|
111
115
|
result.totalTax = totalTax;
|
|
112
116
|
result.totalTaxOnItems = totalTaxOnItems;
|
|
@@ -120,19 +124,23 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false) {
|
|
|
120
124
|
result.totalSGSTOnLabor = totalSGSTOnLabor;
|
|
121
125
|
result.totalCGSTOnLabor = totalCGSTOnLabor;
|
|
122
126
|
result.totalIGSTOnLabor = totalIGSTOnLabor;
|
|
127
|
+
// Calculate tax summary only if taxable and taxCodes provided
|
|
128
|
+
result.itemsTaxSummary = safeTaxCodes.length > 0 ? CalculateTaxSummary(safeItems, safeTaxCodes) : [];
|
|
129
|
+
result.opsTaxSummary = safeTaxCodes.length > 0 ? CalculateTaxSummary(safeOps, safeTaxCodes) : [];
|
|
123
130
|
}
|
|
124
131
|
return result;
|
|
125
132
|
}
|
|
126
133
|
/**
|
|
127
134
|
* Enhanced version with decimal places control
|
|
128
135
|
*/
|
|
129
|
-
function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = false, decimalPlaces = 2) {
|
|
130
|
-
const result = SalesTotalCalculations(items, ops, isTaxable);
|
|
136
|
+
function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = false, taxCodes = [], decimalPlaces = 2) {
|
|
137
|
+
const result = SalesTotalCalculations(items, ops, isTaxable, taxCodes);
|
|
131
138
|
// Round all values to specified decimal places
|
|
132
139
|
const roundToDecimals = (num) => Math.round(num * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces);
|
|
133
140
|
// Base rounded result
|
|
134
141
|
const roundedResult = {
|
|
135
142
|
total: roundToDecimals(result.total),
|
|
143
|
+
totalAfterRounded: roundToDecimals(result.totalAfterRounded),
|
|
136
144
|
subtotal: roundToDecimals(result.subtotal),
|
|
137
145
|
totalDiscount: roundToDecimals(result.totalDiscount),
|
|
138
146
|
roundOff: roundToDecimals(result.roundOff),
|
|
@@ -142,7 +150,7 @@ function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = fa
|
|
|
142
150
|
totalDiscountOnLabor: roundToDecimals(result.totalDiscountOnLabor),
|
|
143
151
|
netAmountAfterDiscount: roundToDecimals(result.netAmountAfterDiscount)
|
|
144
152
|
};
|
|
145
|
-
// Only include tax fields if taxable
|
|
153
|
+
// Only include tax fields and taxSummary if taxable
|
|
146
154
|
if (isTaxable) {
|
|
147
155
|
roundedResult.totalTax = roundToDecimals(result.totalTax);
|
|
148
156
|
roundedResult.totalTaxOnItems = roundToDecimals(result.totalTaxOnItems);
|
|
@@ -156,6 +164,41 @@ function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = fa
|
|
|
156
164
|
roundedResult.totalSGSTOnLabor = roundToDecimals(result.totalSGSTOnLabor);
|
|
157
165
|
roundedResult.totalCGSTOnLabor = roundToDecimals(result.totalCGSTOnLabor);
|
|
158
166
|
roundedResult.totalIGSTOnLabor = roundToDecimals(result.totalIGSTOnLabor);
|
|
167
|
+
// Round tax summary only if it exists
|
|
168
|
+
if (result.itemsTaxSummary) {
|
|
169
|
+
roundedResult.itemsTaxSummary = result.itemsTaxSummary.map((tax) => (Object.assign(Object.assign({}, tax), { TaxableAmount: roundToDecimals(tax.TaxableAmount), TaxAmount: roundToDecimals(tax.TaxAmount), CGSTAmount: roundToDecimals(tax.CGSTAmount), SGSTAmount: roundToDecimals(tax.SGSTAmount), IGSTAmount: roundToDecimals(tax.IGSTAmount) })));
|
|
170
|
+
}
|
|
171
|
+
if (result.opsTaxSummary) {
|
|
172
|
+
roundedResult.opsTaxSummary = result.opsTaxSummary.map((tax) => (Object.assign(Object.assign({}, tax), { TaxableAmount: roundToDecimals(tax.TaxableAmount), TaxAmount: roundToDecimals(tax.TaxAmount), CGSTAmount: roundToDecimals(tax.CGSTAmount), SGSTAmount: roundToDecimals(tax.SGSTAmount), IGSTAmount: roundToDecimals(tax.IGSTAmount) })));
|
|
173
|
+
}
|
|
159
174
|
}
|
|
160
175
|
return roundedResult;
|
|
161
176
|
}
|
|
177
|
+
function CalculateTaxSummary(items, taxCodes) {
|
|
178
|
+
// Create lookup for tax codes
|
|
179
|
+
const taxMap = Object.fromEntries(taxCodes.map(tc => [tc._id, tc]));
|
|
180
|
+
return Object.values(items.reduce((acc, item) => {
|
|
181
|
+
const tax = taxMap[item.TCode];
|
|
182
|
+
if (!tax)
|
|
183
|
+
return acc;
|
|
184
|
+
const key = tax.Code;
|
|
185
|
+
// taxable value after discounts
|
|
186
|
+
const taxable = (0, math_operations_1.Subtract)((0, util_1.GetNumber)(item.UnAmt), (0, math_operations_1.Add)((0, util_1.GetNumber)(item.Disc), (0, util_1.GetNumber)(item.RecDisc)));
|
|
187
|
+
if (!acc[key]) {
|
|
188
|
+
acc[key] = {
|
|
189
|
+
Tax: key,
|
|
190
|
+
TaxableAmount: 0,
|
|
191
|
+
TaxAmount: 0,
|
|
192
|
+
CGSTAmount: 0,
|
|
193
|
+
SGSTAmount: 0,
|
|
194
|
+
IGSTAmount: 0
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
acc[key].TaxableAmount = (0, math_operations_1.Add)(acc[key].TaxableAmount, taxable);
|
|
198
|
+
acc[key].TaxAmount = (0, math_operations_1.Add)(acc[key].TaxAmount, (0, math_operations_1.Add)((0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.CGST)), 100), (0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.SGST)), 100), (0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.IGST)), 100)));
|
|
199
|
+
acc[key].CGSTAmount = (0, math_operations_1.Add)(acc[key].CGSTAmount, (0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.CGST)), 100));
|
|
200
|
+
acc[key].SGSTAmount = (0, math_operations_1.Add)(acc[key].SGSTAmount, (0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.SGST)), 100));
|
|
201
|
+
acc[key].IGSTAmount = (0, math_operations_1.Add)(acc[key].IGSTAmount, (0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.IGST)), 100));
|
|
202
|
+
return acc;
|
|
203
|
+
}, {}));
|
|
204
|
+
}
|