shareneus 1.4.99 → 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.
@@ -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
- total = roundedTotal;
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 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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareneus",
3
- "version": "1.4.99",
3
+ "version": "1.5.00",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",