shareneus 1.4.99 → 1.5.1
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.
|
@@ -3,7 +3,7 @@ export declare class SalesReceivePrintService {
|
|
|
3
3
|
static GetPrintConditionsBasedOnInput(SalesReceivePrintData: any, IncludeGST: boolean, ConsolidateGST: boolean, ForInsurance: boolean, SType: any, OriginalSalesReceiveData: any, IsProforma: boolean): any;
|
|
4
4
|
static GetSalesReceiveTypeHeading(SalesReceivePrintData: any, OriginalSalesReceiveData: any, IncludeGST: boolean, ConsolidateGST: boolean, IsProforma: boolean): any;
|
|
5
5
|
static GetSalesReceiveOtherDetailsForPrint(SalesReceivePrintData: any, OriginalSalesReceiveData: any): any;
|
|
6
|
-
static GetItemsPrintInfo(Items: any, Consolidate: boolean, TaxCodes: any, LineTotal: string, DecimalsNumber: number): any;
|
|
6
|
+
static GetItemsPrintInfo(Items: any, Consolidate: boolean, TaxCodes: any, LineTotal: string, IsTaxable: boolean, DecimalsNumber: number): any;
|
|
7
7
|
static ReverseItemsForSalesReceivePrint(argSalesReceiveData: any): any;
|
|
8
8
|
static PrepareFormatForSalesReceivePrint(SalesReceivePrintData: any, ROType: any, InvoiceStatus: any): any[];
|
|
9
9
|
static GetFormattedProductDataForPrint(OriginalSalesReceiveData: any, SalesReceivePrintData: any): any;
|
|
@@ -4,7 +4,6 @@ exports.SalesReceivePrintService = void 0;
|
|
|
4
4
|
const aggregation_1 = require("../aggregation/aggregation");
|
|
5
5
|
const code_enums_1 = require("../enums/code-enums");
|
|
6
6
|
const enums_1 = require("../enums/enums");
|
|
7
|
-
const math_operations_1 = require("../shared/math-operations");
|
|
8
7
|
const shared_print_service_1 = require("../shared/shared-print.service");
|
|
9
8
|
const my_date_1 = require("../utils/my-date");
|
|
10
9
|
const tr_utils_1 = require("../utils/tr-utils");
|
|
@@ -21,6 +20,7 @@ class SalesReceivePrintService {
|
|
|
21
20
|
SalesReceivePrintData.IsProforma = IsProforma;
|
|
22
21
|
SalesReceivePrintData.Settings = tr_utils_1.TrUtils.Stringify(argSalesReceiveData.Settings);
|
|
23
22
|
SalesReceivePrintData.SType = tr_utils_1.TrUtils.Stringify(argSalesReceiveData.SType);
|
|
23
|
+
SalesReceivePrintData.Items = tr_utils_1.TrUtils.Stringify(argSalesReceiveData.Items);
|
|
24
24
|
let SType = tr_utils_1.TrUtils.IsNull(argSalesReceiveData.SType) ? null : argSalesReceiveData.SType;
|
|
25
25
|
SalesReceivePrintData = this.GetPrintConditionsBasedOnInput(SalesReceivePrintData, IncludeGST, ConsolidateGST, ForInsurance, SType, argSalesReceiveData, IsProforma);
|
|
26
26
|
SalesReceivePrintData.Entity = shared_print_service_1.PrintSharedService.GetFormattedEntityDataForPrint(OriginalEntityData, "Invoice", OriginalSalesReceiveData);
|
|
@@ -30,14 +30,14 @@ class SalesReceivePrintService {
|
|
|
30
30
|
// let finalTotalsData: any = SalesReceiveTotalsService.GetTotalsValue([], argSalesReceiveData.Items, IsTaxable,
|
|
31
31
|
// true,
|
|
32
32
|
// argSalesReceiveData.Disc, argSalesReceiveData.Perc, TaxCodes, true, argSalesReceiveData.Settings, SalesReceivePrintData.Entity);
|
|
33
|
-
let finalTotalsData = (0, sales_total_calculation_1.SalesTotalCalculationsWithDecimals)(argSalesReceiveData.Items, [], IsTaxable, argSalesReceiveData.DecimalsNumber);
|
|
33
|
+
let finalTotalsData = (0, sales_total_calculation_1.SalesTotalCalculationsWithDecimals)(argSalesReceiveData.Items, [], IsTaxable, TaxCodes, argSalesReceiveData.DecimalsNumber);
|
|
34
34
|
if (ConsolidateGST) {
|
|
35
35
|
// finalTotalsData.CustLaborTotalBeforeDisc = finalTotalsData.CustLaborAfterTax;
|
|
36
36
|
// finalTotalsData.CustPartsTotalBeforeDisc = finalTotalsData.CustPartAfterTax;
|
|
37
|
-
finalTotalsData.CustPartsTotalBeforeDisc = (0,
|
|
37
|
+
finalTotalsData.CustPartsTotalBeforeDisc = (0, aggregation_1.addition)(finalTotalsData.totalTaxOnItems, (0, aggregation_1.subtraction)(finalTotalsData.subtotalOnItems, finalTotalsData.totalDiscountOnItems));
|
|
38
38
|
}
|
|
39
39
|
SalesReceivePrintData = tr_utils_1.TrUtils.ConcatObjects(SalesReceivePrintData, finalTotalsData);
|
|
40
|
-
SalesReceivePrintData.Items = this.GetItemsPrintInfo(SalesReceivePrintData.Items, ConsolidateGST, TaxCodes, (_b = (_a = OriginalEntityData.Entity.Settings) === null || _a === void 0 ? void 0 : _a.Acc) === null || _b === void 0 ? void 0 : _b.LTot, SalesReceivePrintData.Entity.DecimalsNumber);
|
|
40
|
+
SalesReceivePrintData.Items = this.GetItemsPrintInfo(SalesReceivePrintData.Items, ConsolidateGST, TaxCodes, (_b = (_a = OriginalEntityData.Entity.Settings) === null || _a === void 0 ? void 0 : _a.Acc) === null || _b === void 0 ? void 0 : _b.LTot, IsTaxable, SalesReceivePrintData.Entity.DecimalsNumber);
|
|
41
41
|
argSalesReceiveData = this.ReverseItemsForSalesReceivePrint(argSalesReceiveData);
|
|
42
42
|
SalesReceivePrintData.PrintInfo = this.PrepareFormatForSalesReceivePrint(SalesReceivePrintData, code_enums_1.ROTypeEnum.Invoice, argSalesReceiveData.Sts);
|
|
43
43
|
SalesReceivePrintData = this.GetFormattedProductDataForPrint(argSalesReceiveData, SalesReceivePrintData);
|
|
@@ -69,10 +69,11 @@ class SalesReceivePrintService {
|
|
|
69
69
|
SalesReceivePrintData.CrDate = my_date_1.MyDate.ConvertUTCDateToReadable(OriginalSalesReceiveData.CrDate);
|
|
70
70
|
return SalesReceivePrintData;
|
|
71
71
|
}
|
|
72
|
-
static GetItemsPrintInfo(Items, Consolidate, TaxCodes, LineTotal, DecimalsNumber) {
|
|
72
|
+
static GetItemsPrintInfo(Items, Consolidate, TaxCodes, LineTotal, IsTaxable, DecimalsNumber) {
|
|
73
73
|
Items.forEach((Item) => {
|
|
74
74
|
if (Consolidate) {
|
|
75
|
-
let
|
|
75
|
+
let AfterPartDisc = (0, aggregation_1.subtraction)(Item.UnAmt, Item.Disc, Item.RecDisc);
|
|
76
|
+
let AfterDiscForEach = (0, aggregation_1.division)(AfterPartDisc, Item.Qty);
|
|
76
77
|
let CTaxAmtPerItem = (0, aggregation_1.division)(Item.CGST, Item.Qty);
|
|
77
78
|
let STaxAmtPerItem = (0, aggregation_1.division)(Item.SGST, Item.Qty);
|
|
78
79
|
let ITaxAmtPerItem = (0, aggregation_1.division)(Item.IGST, Item.Qty);
|
|
@@ -87,6 +88,13 @@ class SalesReceivePrintService {
|
|
|
87
88
|
Item.CGSTPerc = shared_print_service_1.PrintSharedService.GetCGSTValueBasedOnTaxCode(Item.TCode, TaxCodes);
|
|
88
89
|
Item.SGSTPerc = shared_print_service_1.PrintSharedService.GetSGSTValueBasedOnTaxCode(Item.TCode, TaxCodes);
|
|
89
90
|
Item.IGSTPerc = shared_print_service_1.PrintSharedService.GetIGSTValueBasedOnTaxCode(Item.TCode, TaxCodes);
|
|
91
|
+
// Calculate amount after tax based on tax type
|
|
92
|
+
if (IsTaxable) {
|
|
93
|
+
Item.AfterPartTax = (0, aggregation_1.addition)(Item.AfterPartDisc, Item.CGST, Item.SGST, Item.IGST);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
Item.AfterPartTax = Item.AfterPartDisc;
|
|
97
|
+
}
|
|
90
98
|
if (LineTotal === 'AT') {
|
|
91
99
|
Item.LineTotal = tr_utils_1.TrUtils.FixPriceValue(Item.AfterPartTax, DecimalsNumber);
|
|
92
100
|
}
|
|
@@ -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;
|
|
@@ -90,12 +92,11 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false) {
|
|
|
90
92
|
const netAmountAfterDiscount = (0, math_operations_1.Subtract)(subtotal, totalDiscount);
|
|
91
93
|
// Step 2: Add tax if taxable
|
|
92
94
|
total = isTaxable ? (0, math_operations_1.Add)(netAmountAfterDiscount, totalTax) : netAmountAfterDiscount;
|
|
93
|
-
totalAfterRounded = isTaxable ? (0, math_operations_1.Add)(netAmountAfterDiscount, totalTax) : netAmountAfterDiscount;
|
|
94
95
|
// FIXED ROUNDING: Use Math.round instead of Math.floor
|
|
95
96
|
const roundedTotal = Math.round(total);
|
|
96
97
|
roundOff = (0, math_operations_1.Subtract)(roundedTotal, total);
|
|
97
98
|
// Update total to rounded value
|
|
98
|
-
|
|
99
|
+
totalAfterRounded = roundedTotal;
|
|
99
100
|
// Base return object
|
|
100
101
|
const result = {
|
|
101
102
|
total,
|
|
@@ -109,10 +110,9 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false) {
|
|
|
109
110
|
totalDiscountOnLabor,
|
|
110
111
|
netAmountAfterDiscount
|
|
111
112
|
};
|
|
112
|
-
// Only include tax fields if taxable
|
|
113
|
+
// Only include tax fields and taxSummary if taxable
|
|
113
114
|
if (isTaxable) {
|
|
114
115
|
result.totalTax = totalTax;
|
|
115
|
-
result.totalAfterRounded = totalAfterRounded;
|
|
116
116
|
result.totalTaxOnItems = totalTaxOnItems;
|
|
117
117
|
result.totalTaxOnLabor = totalTaxOnLabor;
|
|
118
118
|
result.totalSGST = totalSGST;
|
|
@@ -124,14 +124,17 @@ function SalesTotalCalculations(items = [], ops = [], isTaxable = false) {
|
|
|
124
124
|
result.totalSGSTOnLabor = totalSGSTOnLabor;
|
|
125
125
|
result.totalCGSTOnLabor = totalCGSTOnLabor;
|
|
126
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) : [];
|
|
127
130
|
}
|
|
128
131
|
return result;
|
|
129
132
|
}
|
|
130
133
|
/**
|
|
131
134
|
* Enhanced version with decimal places control
|
|
132
135
|
*/
|
|
133
|
-
function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = false, decimalPlaces = 2) {
|
|
134
|
-
const result = SalesTotalCalculations(items, ops, isTaxable);
|
|
136
|
+
function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = false, taxCodes = [], decimalPlaces = 2) {
|
|
137
|
+
const result = SalesTotalCalculations(items, ops, isTaxable, taxCodes);
|
|
135
138
|
// Round all values to specified decimal places
|
|
136
139
|
const roundToDecimals = (num) => Math.round(num * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces);
|
|
137
140
|
// Base rounded result
|
|
@@ -147,7 +150,7 @@ function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = fa
|
|
|
147
150
|
totalDiscountOnLabor: roundToDecimals(result.totalDiscountOnLabor),
|
|
148
151
|
netAmountAfterDiscount: roundToDecimals(result.netAmountAfterDiscount)
|
|
149
152
|
};
|
|
150
|
-
// Only include tax fields if taxable
|
|
153
|
+
// Only include tax fields and taxSummary if taxable
|
|
151
154
|
if (isTaxable) {
|
|
152
155
|
roundedResult.totalTax = roundToDecimals(result.totalTax);
|
|
153
156
|
roundedResult.totalTaxOnItems = roundToDecimals(result.totalTaxOnItems);
|
|
@@ -161,6 +164,41 @@ function SalesTotalCalculationsWithDecimals(items = [], ops = [], isTaxable = fa
|
|
|
161
164
|
roundedResult.totalSGSTOnLabor = roundToDecimals(result.totalSGSTOnLabor);
|
|
162
165
|
roundedResult.totalCGSTOnLabor = roundToDecimals(result.totalCGSTOnLabor);
|
|
163
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
|
+
}
|
|
164
174
|
}
|
|
165
175
|
return roundedResult;
|
|
166
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 percent = (tax.IGST || (tax.CGST || 0) + (tax.SGST || 0)) + "%";
|
|
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[percent]) {
|
|
188
|
+
acc[percent] = {
|
|
189
|
+
Tax: percent,
|
|
190
|
+
TaxableAmount: 0,
|
|
191
|
+
TaxAmount: 0,
|
|
192
|
+
CGSTAmount: 0,
|
|
193
|
+
SGSTAmount: 0,
|
|
194
|
+
IGSTAmount: 0
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
acc[percent].TaxableAmount = (0, math_operations_1.Add)(acc[percent].TaxableAmount, taxable);
|
|
198
|
+
acc[percent].TaxAmount = (0, math_operations_1.Add)(acc[percent].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[percent].CGSTAmount = (0, math_operations_1.Add)(acc[percent].CGSTAmount, (0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.CGST)), 100));
|
|
200
|
+
acc[percent].SGSTAmount = (0, math_operations_1.Add)(acc[percent].SGSTAmount, (0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.SGST)), 100));
|
|
201
|
+
acc[percent].IGSTAmount = (0, math_operations_1.Add)(acc[percent].IGSTAmount, (0, math_operations_1.Divide)((0, math_operations_1.Multiply)(taxable, (0, util_1.GetNumber)(tax.IGST)), 100));
|
|
202
|
+
return acc;
|
|
203
|
+
}, {}));
|
|
204
|
+
}
|