shareneus 1.7.4 → 1.7.6

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.
Files changed (212) hide show
  1. package/README.md +1 -0
  2. package/dist/accounting/invoice/invoice-pdf/invoice-pdf.service.js +18 -45
  3. package/dist/accounting/invoice/reports/excel/analysis-excel.service.js +17 -7
  4. package/dist/accounting/invoice/reports/excel/category-wise-item-excel.service.js +17 -7
  5. package/dist/accounting/invoice/reports/excel/cust-wise-sales-details.js +17 -7
  6. package/dist/accounting/invoice/reports/excel/cust-wise-sales-summary-excel.service.js +17 -7
  7. package/dist/accounting/invoice/reports/excel/invoice-wise-excel.service.js +17 -7
  8. package/dist/accounting/invoice/reports/excel/item-wise-doctor-sale-excel.service.js +17 -7
  9. package/dist/accounting/invoice/reports/excel/items-wise-sales-excel.service.js +17 -7
  10. package/dist/accounting/invoice/reports/excel/manf-wise-sales-excel.service.js +17 -7
  11. package/dist/accounting/invoice/reports/excel/operator-wise-details.js +17 -7
  12. package/dist/accounting/invoice/reports/excel/operator-wise-summary.js +17 -7
  13. package/dist/accounting/invoice/reports/excel/sa-wise-labor-sales-excel.service.js +17 -7
  14. package/dist/accounting/invoice/reports/excel/sa-wise-part-sales-excel.service.js +17 -7
  15. package/dist/accounting/invoice/reports/excel/sale-summary-excel.service.js +17 -7
  16. package/dist/accounting/invoice/reports/excel/sales-by-service-summary-excel.service.js +17 -7
  17. package/dist/accounting/invoice/reports/excel/scheduled-drug-summary-excel.service.js +17 -7
  18. package/dist/accounting/invoice/reports/excel/scheduled-drugs-excel.service.js +17 -7
  19. package/dist/accounting/invoice/unified-invoice-pdf.service.d.ts +1 -1
  20. package/dist/accounting/payment-receive/reports/excel/cust-balance-excel.service.js +17 -7
  21. package/dist/accounting/payment-receive/reports/excel/payment-receive-excel.service.js +17 -7
  22. package/dist/common/reports/excel/product-without-owner-excel.service.js +17 -7
  23. package/dist/gst/excel/GSTR-RO-excel.service.js +17 -7
  24. package/dist/gst/excel/GSTR1-excel.service.js +17 -7
  25. package/dist/gst/excel/GSTR2-excel.service.js +17 -7
  26. package/dist/gst/excel/hsn-summary.js +17 -7
  27. package/dist/gst/excel/tally-sales-import.service.js +17 -7
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +6 -6
  30. package/dist/inventory/items/reports/excel/expiring-drugs-excel.service.js +17 -7
  31. package/dist/inventory/items/reports/excel/item-wise-mout-details.js +17 -7
  32. package/dist/inventory/items/reports/excel/item-wise-mout-summary.js +17 -7
  33. package/dist/inventory/items/reports/excel/spares-issue-excel.service.js +17 -7
  34. package/dist/inventory/items/reports/excel/stock-excel.service.js +17 -7
  35. package/dist/purchases/payment-made/reports/excel/payments-made-excel.service.js +17 -7
  36. package/dist/purchases/payment-made/reports/excel/ven-balance-excel.service.js +17 -7
  37. package/dist/services/reports/excel/insurance-expire-excel.service.js +17 -7
  38. package/dist/services/reports/excel/next-service-date-excel.service.js +17 -7
  39. package/dist/services/reports/excel/repair-orders-excel.service.js +17 -7
  40. package/dist/shared/table-section/pdf-table.header.d.ts +1 -1
  41. package/dist/shared/table-section/pdf-table.header.js +14 -2
  42. package/dist/shared/table-section/pdf-table.section.js +6 -13
  43. package/dist/{accounting/invoice/invoice-pdf.service.js → shared/transactions-pdf.service.js} +15 -15
  44. package/package.json +1 -1
  45. package/src/accounting/counter-sales/auto-sales-receipt-pdf.service.ts +569 -0
  46. package/src/accounting/counter-sales/pos-receipt-pdf.ts +577 -0
  47. package/src/accounting/counter-sales/sales-receipt-pdf.service.ts +628 -0
  48. package/src/accounting/counter-sales/sales-receipt-print.service.ts +506 -0
  49. package/src/accounting/credit-note/cn-print.service.ts +264 -0
  50. package/src/accounting/credit-note/credit-note-pdf.service.ts +602 -0
  51. package/src/accounting/credit-note/credit-note-totals.service.ts +424 -0
  52. package/src/accounting/debit-note/debit-note-pdf.service.ts +681 -0
  53. package/src/accounting/debit-note/debit-note-print.service.ts +276 -0
  54. package/src/accounting/debit-note/debit-note-totals.service.ts +361 -0
  55. package/src/accounting/invoice/hc-inv-pdf.service.ts +880 -0
  56. package/src/accounting/invoice/inv-pdf.service.ts +812 -0
  57. package/src/accounting/invoice/inv-print.service.ts +532 -0
  58. package/src/accounting/invoice/invoice-landscape-pdf.service.ts +947 -0
  59. package/src/accounting/invoice/invoice-letterhead-pdf.service.ts +813 -0
  60. package/src/accounting/invoice/invoice-pdf/invoice-pdf.service.ts +359 -0
  61. package/src/accounting/invoice/invoice-portrait-pdf.ts +972 -0
  62. package/src/accounting/invoice/invoice-print.service.ts +2906 -0
  63. package/src/accounting/invoice/invoice-total.service.ts +834 -0
  64. package/src/accounting/invoice/reports/excel/analysis-excel.service.ts +291 -0
  65. package/src/accounting/invoice/reports/excel/category-wise-item-excel.service.ts +267 -0
  66. package/src/accounting/invoice/reports/excel/cust-wise-sales-details.ts +321 -0
  67. package/src/accounting/invoice/reports/excel/cust-wise-sales-summary-excel.service.ts +300 -0
  68. package/src/accounting/invoice/reports/excel/invoice-wise-excel.service.ts +859 -0
  69. package/src/accounting/invoice/reports/excel/item-wise-doctor-sale-excel.service.ts +255 -0
  70. package/src/accounting/invoice/reports/excel/items-wise-sales-excel.service.ts +312 -0
  71. package/src/accounting/invoice/reports/excel/manf-wise-sales-excel.service.ts +273 -0
  72. package/src/accounting/invoice/reports/excel/operator-wise-details.ts +258 -0
  73. package/src/accounting/invoice/reports/excel/operator-wise-summary.ts +259 -0
  74. package/src/accounting/invoice/reports/excel/sa-wise-labor-sales-excel.service.ts +230 -0
  75. package/src/accounting/invoice/reports/excel/sa-wise-part-sales-excel.service.ts +231 -0
  76. package/src/accounting/invoice/reports/excel/sale-summary-excel.service.ts +326 -0
  77. package/src/accounting/invoice/reports/excel/sales-by-service-details-excel.service.ts +0 -0
  78. package/src/accounting/invoice/reports/excel/sales-by-service-summary-excel.service.ts +432 -0
  79. package/src/accounting/invoice/reports/excel/scheduled-drug-summary-excel.service.ts +373 -0
  80. package/src/accounting/invoice/reports/excel/scheduled-drugs-excel.service.ts +372 -0
  81. package/src/accounting/invoice/reports/pdf/analysis-pdf.service.ts +113 -0
  82. package/src/accounting/invoice/reports/pdf/category-wise-item-pdf.service.ts +107 -0
  83. package/src/accounting/invoice/reports/pdf/cust-wise-sales-details-pdf.service.ts +125 -0
  84. package/src/accounting/invoice/reports/pdf/cust-wise-sales-summary-pdf.service.ts +119 -0
  85. package/src/accounting/invoice/reports/pdf/item-wise-doctor-sale-pdf.service.ts +180 -0
  86. package/src/accounting/invoice/reports/pdf/item-wise-sales-pdf.service.ts +193 -0
  87. package/src/accounting/invoice/reports/pdf/manf-wise-sales-pdf.service.ts +188 -0
  88. package/src/accounting/invoice/reports/pdf/operator-wise-details-pdf.service.ts +118 -0
  89. package/src/accounting/invoice/reports/pdf/operator-wise-summary-pdf.ts +116 -0
  90. package/src/accounting/invoice/reports/pdf/sales-by-service-pdf.service.ts +132 -0
  91. package/src/accounting/invoice/reports/pdf/scheduled-drug-pdf.service.ts +191 -0
  92. package/src/accounting/invoice/reports/pdf/scheduled-drug-summary-pdf.service.ts +202 -0
  93. package/src/accounting/invoice/shared-inv-pdf.service.ts +787 -0
  94. package/src/accounting/invoice/unified-invoice-pdf.service.ts +937 -0
  95. package/src/accounting/payment-receive/payment-pdf.service.ts +410 -0
  96. package/src/accounting/payment-receive/payment-receipt-pdf/receipt-pdf.service.ts +470 -0
  97. package/src/accounting/payment-receive/receipt-print.service.ts +71 -0
  98. package/src/accounting/payment-receive/reports/excel/cust-balance-excel.service.ts +298 -0
  99. package/src/accounting/payment-receive/reports/excel/payment-receive-excel.service.ts +221 -0
  100. package/src/accounting/payment-receive/reports/pdf/customer-balances-pdf.service.ts +182 -0
  101. package/src/accounting/payment-receive/reports/pdf/payment-report-pdf.service.ts +116 -0
  102. package/src/aggregation/aggregation.ts +58 -0
  103. package/src/appointments/appointments/appointment-total.service.ts +298 -0
  104. package/src/appointments/consultations/consultation-fee-receipt.service.ts +407 -0
  105. package/src/appointments/consultations/consultation-full-pdf.service.ts +238 -0
  106. package/src/appointments/consultations/consultation-letterhead-pdf.service.ts +430 -0
  107. package/src/appointments/consultations/consultation-pdf.service.ts +417 -0
  108. package/src/common/reports/excel/product-without-owner-excel.service.ts +308 -0
  109. package/src/common/reports/pdf/product-without-owner-pdf.service.ts +146 -0
  110. package/src/enums/cache-enums.ts +33 -0
  111. package/src/enums/code-enums.ts +291 -0
  112. package/src/enums/country-enums.ts +9 -0
  113. package/src/enums/enums.ts +364 -0
  114. package/src/enums/industry-enums.ts +26 -0
  115. package/src/enums/treatment-enums.ts +9 -0
  116. package/src/gst/excel/GSTR-RO-excel.service.ts +926 -0
  117. package/src/gst/excel/GSTR1-excel.service.ts +313 -0
  118. package/src/gst/excel/GSTR2-excel.service.ts +314 -0
  119. package/src/gst/excel/hsn-summary.ts +314 -0
  120. package/src/gst/excel/tally-sales-import.service.ts +767 -0
  121. package/src/gst/pdf/hsn-summary-pdf.ts +176 -0
  122. package/src/index.ts +194 -0
  123. package/src/inventory/items/adjustment-pdf.service.ts +177 -0
  124. package/src/inventory/items/issue-parts-pdf.service.ts +795 -0
  125. package/src/inventory/items/item-bar-code-label-pdf.ts +194 -0
  126. package/src/inventory/items/item-detais-pdf.ts +141 -0
  127. package/src/inventory/items/item-price-for-pricelist.ts +368 -0
  128. package/src/inventory/items/reports/excel/expiring-drugs-excel.service.ts +290 -0
  129. package/src/inventory/items/reports/excel/item-wise-mout-details.ts +284 -0
  130. package/src/inventory/items/reports/excel/item-wise-mout-summary.ts +279 -0
  131. package/src/inventory/items/reports/excel/spares-issue-excel.service.ts +494 -0
  132. package/src/inventory/items/reports/excel/stock-excel.service.ts +319 -0
  133. package/src/inventory/items/reports/pdf/expiring-drugs-pdf.service.ts +172 -0
  134. package/src/inventory/items/reports/pdf/item-wise-mout-details-pdf.ts +122 -0
  135. package/src/inventory/items/reports/pdf/item-wise-mout-summary-pdf.ts +115 -0
  136. package/src/inventory/items/reports/pdf/reorder-point-pdf.service.ts +163 -0
  137. package/src/inventory/material-out/mout-pdf.service.ts +545 -0
  138. package/src/inventory/transfer-order/transfer-order-pdf.service.ts +154 -0
  139. package/src/purchases/bills/bill-pdf/bill-pdf.service.ts +211 -0
  140. package/src/purchases/bills/bill-pdf.service.ts +21 -0
  141. package/src/purchases/payment-made/reports/excel/payments-made-excel.service.ts +313 -0
  142. package/src/purchases/payment-made/reports/excel/ven-balance-excel.service.ts +307 -0
  143. package/src/purchases/payment-made/reports/pdf/vendor-balances-pdf.service.ts +114 -0
  144. package/src/purchases/purchase-order/po-totals.service.ts +343 -0
  145. package/src/purchases/purchase-order/purchase-order-pdf.service.ts +1016 -0
  146. package/src/purchases/purchase-order/purchase-order-print.service.ts +279 -0
  147. package/src/purchases/purchase-order/purchase-order-totals.service.ts +637 -0
  148. package/src/purchases/vendor-credit-note/vendor-credit-note-pdf.service.ts +1055 -0
  149. package/src/purchases/vendor-credit-note/vendor-credit-note-print.service.ts +145 -0
  150. package/src/purchases/vendor-credit-note/vendor-credit-note-totals.service.ts +399 -0
  151. package/src/purchases/vendor-debit-note/vendor-debit-note-pdf.service.ts +582 -0
  152. package/src/purchases/vendor-debit-note/vendor-debit-note-print.service.ts +295 -0
  153. package/src/purchases/vendor-debit-note/vendor-debit-note-totals.service.ts +377 -0
  154. package/src/sales/delivery-challan/dc-landscape-pdf.service.ts +922 -0
  155. package/src/sales/delivery-challan/dc-landscape-without-price-pdf.service.ts +869 -0
  156. package/src/sales/delivery-challan/dc-without-price-pdf.service.ts +505 -0
  157. package/src/sales/delivery-challan/delivery-challan-pdf.service.ts +461 -0
  158. package/src/sales/delivery-challan/delivery-challan-print.service.ts +229 -0
  159. package/src/sales/delivery-challan/delivery-challan-totals.ts +466 -0
  160. package/src/sales/sales/equipment-design-pdf.service.ts +153 -0
  161. package/src/sales/sales/pack-ship-pdf.service.ts +128 -0
  162. package/src/sales/sales/pack-ship-print.service.ts +198 -0
  163. package/src/sales/sales/sales-pdf.service.ts +658 -0
  164. package/src/sales/sales/sales-print.service.ts +376 -0
  165. package/src/sales/sales/sales-totals.service.ts +500 -0
  166. package/src/sales-receive/sales-receive-pdf.service.ts +602 -0
  167. package/src/sales-receive/sales-receive-print.service.ts +242 -0
  168. package/src/sales-receive/sales-receive-totals.service.ts +651 -0
  169. package/src/services/checklist-pdf.ts +151 -0
  170. package/src/services/checklists-pdf.ts +133 -0
  171. package/src/services/est.print-service.ts +1155 -0
  172. package/src/services/reports/excel/insurance-expire-excel.service.ts +292 -0
  173. package/src/services/reports/excel/next-service-date-excel.service.ts +317 -0
  174. package/src/services/reports/excel/repair-orders-excel.service.ts +249 -0
  175. package/src/services/reports/pdf/insurance-expire-pdf.service.ts +115 -0
  176. package/src/services/reports/pdf/next-service-date-pdf.service.ts +198 -0
  177. package/src/services/reports/pdf/repair-orders-pdf.service.ts +184 -0
  178. package/src/services/ro-pdf.service.ts +1917 -0
  179. package/src/services/ro-print-service.ts +881 -0
  180. package/src/services/ro-totals.service.ts +1314 -0
  181. package/src/services/separate-wo-print.service.ts +396 -0
  182. package/src/services/service-history-pdf.service.ts +145 -0
  183. package/src/services/service-price-for-pricelist.ts +649 -0
  184. package/src/services/technician-pdf.service.ts +234 -0
  185. package/src/services/technician-print.service.ts +95 -0
  186. package/src/shared/header-footer-section/pdf-header-footer.section.ts +519 -0
  187. package/src/shared/header-footer-section/pdf-shared.utils.ts +46 -0
  188. package/src/shared/math-operations.ts +208 -0
  189. package/src/shared/party-details-section/pdf-party-details.section.ts +602 -0
  190. package/src/shared/shared-pdf.service.ts +3042 -0
  191. package/src/shared/shared-print.service.ts +879 -0
  192. package/src/shared/table-section/pdf-table.config.ts +8 -0
  193. package/src/shared/table-section/pdf-table.header.ts +396 -0
  194. package/src/shared/table-section/pdf-table.row.ts +248 -0
  195. package/src/shared/table-section/pdf-table.section.ts +447 -0
  196. package/src/shared/totals-section/pdf-totals.section.ts +921 -0
  197. package/src/shared/transactions-pdf.service.ts +191 -0
  198. package/src/shared/util.ts +101 -0
  199. package/src/tasks/meetings/meeting-pdf.ts +410 -0
  200. package/src/tasks/tasks/task-pdf.service.ts +238 -0
  201. package/src/tasks/tasks/task-reports-pdf.service.ts +313 -0
  202. package/src/tax/index.ts +86 -0
  203. package/src/tax/tax-calculator.ts +1025 -0
  204. package/src/tax/tax.types.ts +535 -0
  205. package/src/transaction-calculations/discounts-distribution.ts +343 -0
  206. package/src/transaction-calculations/index.ts +3 -0
  207. package/src/transaction-calculations/total-calculation.ts +443 -0
  208. package/src/transaction-calculations/transaction-calculation-engine.ts +903 -0
  209. package/src/utils/my-date.ts +111 -0
  210. package/src/utils/tr-utils.ts +104 -0
  211. package/tsconfig.json +2 -2
  212. /package/dist/{accounting/invoice/invoice-pdf.service.d.ts → shared/transactions-pdf.service.d.ts} +0 -0
@@ -0,0 +1,651 @@
1
+ import { Add, Divide, Multiply, Subtract } from "../shared/math-operations";
2
+ import { TrUtils } from "../utils/tr-utils";
3
+
4
+ /**
5
+ * Service class for calculating sales receive totals including taxes, discounts and final amounts
6
+ */
7
+ export class SalesReceiveTotalsService {
8
+
9
+ /**
10
+ * Main method to calculate totals for sales receive operations
11
+ * @param opCodesList - Array of operation codes/labor items
12
+ * @param PartsList - Array of parts/items to be processed
13
+ * @param IsIndependentTax - Whether tax is calculated independently
14
+ * @param DetailedInfo - Whether to include detailed breakdown information
15
+ * @param Disc - Discount amount
16
+ * @param Perc - Discount percentage
17
+ * @param TaxCodes - Available tax codes for GST calculations
18
+ * @param WithItems - Whether to include items in the response
19
+ * @param Settings - General settings object
20
+ * @param EntitySettings - Entity-specific settings including decimal places
21
+ * @returns Object containing calculated totals and breakdown information
22
+ */
23
+ static GetTotalsValue(opCodesList: any, PartsList: any, IsIndependentTax: boolean, DetailedInfo: boolean,
24
+ Disc: any, Perc: string,
25
+ TaxCodes: any, WithItems: boolean, Settings: any, EntitySettings: any = {}) {
26
+
27
+ // Sanitize input parameters to ensure valid values
28
+ Perc = TrUtils.SetPercToStringIfNull(Perc);
29
+ Disc = TrUtils.SetValueToZeroIfNull(Disc);
30
+
31
+ // Calculate labor part values with tax considerations
32
+ PartsList = this.CalculateLaborPartValues(PartsList, IsIndependentTax);
33
+
34
+ // Get the main totals data
35
+ let finalTotalsData: any = this.GetFinalRODataForSave(opCodesList, PartsList, IsIndependentTax, Disc, Perc, DetailedInfo, Settings, EntitySettings.DecimalsNumber);
36
+
37
+ // Add detailed breakdown if requested
38
+ if (DetailedInfo) {
39
+ finalTotalsData = this.GetDetailedTotalsData(finalTotalsData,
40
+ IsIndependentTax, opCodesList, PartsList, TaxCodes, EntitySettings.DecimalsNumber);
41
+ }
42
+
43
+ // Include items in response if requested
44
+ if (WithItems) {
45
+ finalTotalsData.Items = PartsList;
46
+ }
47
+ return finalTotalsData;
48
+ }
49
+
50
+ /**
51
+ * Calculates labor part values including discounts and taxes
52
+ * @param PartsList - Array of parts to be processed
53
+ * @param IsIndependentTax - Whether tax is calculated independently
54
+ * @returns Processed parts list with calculated values
55
+ */
56
+ static CalculateLaborPartValues(PartsList: any, IsIndependentTax: boolean) {
57
+ PartsList = this.ResetLaborPartValues(PartsList, IsIndependentTax);
58
+ return PartsList;
59
+ }
60
+
61
+ /**
62
+ * Resets and recalculates labor part values including discounts and taxes
63
+ * @param PartsList - Array of parts to be processed
64
+ * @param IsIndependentTax - Whether tax is calculated independently
65
+ * @returns Parts list with reset and recalculated values
66
+ */
67
+ static ResetLaborPartValues(PartsList: any, IsIndependentTax: boolean) {
68
+ PartsList.forEach((Part: any) => {
69
+ // Reset invalid values to defaults
70
+ Part = this.ResetLaborPartValueIfInvalid(Part);
71
+
72
+ // Set minimum quantity to 1 if zero
73
+ if (TrUtils.IsZero(Part.Qty)) {
74
+ Part.Qty = 1;
75
+ }
76
+
77
+ // Calculate total discounted price
78
+ Part.DiscountedPrice = Add(Part.Disc, Part.RecDisc);
79
+
80
+ // Calculate amount after discount
81
+ Part.AfterPartDisc = Subtract(Part.UnAmt, Part.Disc, Part.RecDisc);
82
+
83
+ // Calculate amount after tax based on tax type
84
+ if (IsIndependentTax) {
85
+ Part.AfterPartTax = Add(Part.AfterPartDisc, Part.CGST, Part.SGST, Part.IGST);
86
+ } else {
87
+ Part.AfterPartTax = Part.AfterPartDisc;
88
+ }
89
+ });
90
+ return PartsList;
91
+ }
92
+
93
+ /**
94
+ * Resets part values to zero if they are null or invalid
95
+ * @param Part - Individual part item to reset
96
+ * @returns Part with reset values
97
+ */
98
+ static ResetLaborPartValueIfInvalid(Part: any) {
99
+ Part.UnPr = TrUtils.SetValueToZeroIfNull(Part.UnPr);
100
+ Part.Disc = TrUtils.SetValueToZeroIfNull(Part.Disc);
101
+ Part.RecDisc = TrUtils.SetValueToZeroIfNull(Part.RecDisc);
102
+ Part.CGST = TrUtils.SetValueToZeroIfNull(Part.CGST);
103
+ Part.SGST = TrUtils.SetValueToZeroIfNull(Part.SGST);
104
+ Part.IGST = TrUtils.SetValueToZeroIfNull(Part.IGST);
105
+ return Part;
106
+ }
107
+
108
+ /**
109
+ * Prepares final repair order data for saving with calculated totals
110
+ * @param LaborList - Array of labor items
111
+ * @param PartsList - Array of parts
112
+ * @param IsIndependentTax - Whether tax is calculated independently
113
+ * @param Disc - Discount amount
114
+ * @param Perc - Discount percentage
115
+ * @param DetailedInfo - Whether to include detailed information
116
+ * @param Settings - General settings
117
+ * @param DecimalsNumber - Number of decimal places for calculations
118
+ * @returns Final totals data object ready for saving
119
+ */
120
+ static GetFinalRODataForSave(LaborList: any, PartsList: any, IsIndependentTax: boolean, Disc: any, Perc: string,
121
+ DetailedInfo: boolean, Settings: any, DecimalsNumber: any) {
122
+ let finalTotalsData: any = {};
123
+
124
+ // Set discount values
125
+ finalTotalsData = this.SetMainDiscountValues(Disc, Perc, finalTotalsData, DetailedInfo);
126
+
127
+ // Add settings to response
128
+ finalTotalsData.Settings = Settings;
129
+
130
+ // Calculate customer totals
131
+ finalTotalsData = this.GetFinalCustomerTotalsData(finalTotalsData, [], PartsList,
132
+ IsIndependentTax, DetailedInfo, DecimalsNumber);
133
+ return finalTotalsData;
134
+ }
135
+
136
+ /**
137
+ * Sets main discount values in the totals data object
138
+ * @param Disc - Discount amount
139
+ * @param Perc - Discount percentage
140
+ * @param finalTotalsData - Totals data object to update
141
+ * @param DetailedInfo - Whether to include detailed information
142
+ * @returns Updated totals data with discount values
143
+ */
144
+ static SetMainDiscountValues(Disc: string, Perc: string, finalTotalsData: any, DetailedInfo: boolean) {
145
+ finalTotalsData.Disc = Disc;
146
+ finalTotalsData.Perc = Perc;
147
+ if (DetailedInfo) {
148
+ finalTotalsData.FixedDisc = Disc;
149
+ }
150
+ return finalTotalsData;
151
+ }
152
+
153
+ /**
154
+ * Calculates final customer totals including subtotals, taxes, and rounded amounts
155
+ * @param finalTotalsData - Existing totals data object
156
+ * @param LaborList - Array of labor items
157
+ * @param PartsList - Array of parts
158
+ * @param IsIndependentTax - Whether tax is calculated independently
159
+ * @param DetailedInfo - Whether to include detailed information
160
+ * @param DecimalsNumber - Number of decimal places for calculations
161
+ * @returns Updated totals data with customer calculations
162
+ */
163
+ static GetFinalCustomerTotalsData(finalTotalsData: any, LaborList: any, PartsList: any, IsIndependentTax: boolean,
164
+ DetailedInfo: boolean, DecimalsNumber: number = 2) {
165
+ // Calculate subtotal after discounts
166
+ let CustomerAfterDiscTotals: number = this.GetSubTotalFor([], PartsList);
167
+
168
+ // Calculate parts tax total
169
+ let CustPartTaxTotal = this.GetPartsTaxTotalFor(PartsList, IsIndependentTax);
170
+
171
+ // Set subtotal with proper decimal formatting
172
+ finalTotalsData.SubTotal = TrUtils.FixedTo(CustomerAfterDiscTotals, DecimalsNumber);
173
+
174
+ // Calculate discount totals
175
+ let CustPartsDiscTotal = this.GetPartDiscountedTotal(PartsList, IsIndependentTax, finalTotalsData);
176
+ let CustPartsTotalAfterDisc = this.GetPartsTotalAfterDiscount(PartsList);
177
+
178
+ // Calculate sum total
179
+ finalTotalsData.STotal = Add(CustPartsDiscTotal, CustPartsTotalAfterDisc);
180
+
181
+ // Calculate final customer total
182
+ let CustTotal: any = this.GetCustomerTotalBasedOnTaxType(finalTotalsData, 0, CustPartTaxTotal, [], PartsList, IsIndependentTax);
183
+
184
+ // Calculate rounding difference and final total
185
+ finalTotalsData.Round = Subtract(Math.round(CustTotal), CustTotal);
186
+ finalTotalsData.Total = Math.round(CustTotal);
187
+
188
+ // Add detailed information if requested
189
+ if (DetailedInfo) {
190
+ finalTotalsData.FixedSubTotal = TrUtils.FixedTo(CustomerAfterDiscTotals, DecimalsNumber);
191
+ finalTotalsData.FixedTotal = TrUtils.FixedTo(CustTotal, DecimalsNumber);
192
+ }
193
+ return finalTotalsData;
194
+ }
195
+
196
+ /**
197
+ * Calculates subtotal for labor and parts combined
198
+ * @param LaborList - Array of labor items
199
+ * @param PartsList - Array of parts
200
+ * @returns Calculated subtotal amount
201
+ */
202
+ static GetSubTotalFor(LaborList: any, PartsList: any) {
203
+ let PartsTotalAfterDisc: any = this.GetPartsTotalAfterDiscount(PartsList);
204
+ return PartsTotalAfterDisc;
205
+ }
206
+
207
+ /**
208
+ * Calculates total amount for parts after applying discounts
209
+ * @param PartsList - Array of parts
210
+ * @returns Total parts amount after discounts
211
+ */
212
+ static GetPartsTotalAfterDiscount(PartsList: any) {
213
+ let PartsTotalAfterDisc: any = 0;
214
+ PartsList.forEach((Part: any) => {
215
+ PartsTotalAfterDisc = Add(PartsTotalAfterDisc, Part.AfterPartDisc);
216
+ });
217
+ return PartsTotalAfterDisc;
218
+ }
219
+
220
+ /**
221
+ * Generates detailed totals data including tax breakdowns and groupings
222
+ * @param finalTotalsData - Existing totals data
223
+ * @param IsIndependentTax - Whether tax is calculated independently
224
+ * @param opCodesList - Array of operation codes
225
+ * @param PartsList - Array of parts
226
+ * @param TaxCodes - Available tax codes
227
+ * @param DecimalsNumber - Number of decimal places
228
+ * @returns Enhanced totals data with detailed breakdowns
229
+ */
230
+ static GetDetailedTotalsData(finalTotalsData: any, IsIndependentTax: boolean, opCodesList: any, PartsList: any, TaxCodes: any, DecimalsNumber: number = 2) {
231
+ // Add parts discount and total information
232
+ finalTotalsData.CustPartsDiscTotal = this.GetPartDiscountedTotal(PartsList, IsIndependentTax, finalTotalsData);
233
+ finalTotalsData.CustPartsTotalAfterDisc = this.GetPartsTotalAfterDiscount(PartsList);
234
+ finalTotalsData.CustPartsTotalBeforeDisc = Add(finalTotalsData.CustPartsTotalAfterDisc
235
+ , finalTotalsData.CustPartsDiscTotal);
236
+
237
+ // Get GST tax breakdown
238
+ let TaxInfo: any = this.GetPartGSTTaxTotal(PartsList, IsIndependentTax);
239
+ finalTotalsData.CustPartITax = TrUtils.SetValueToZeroIfNull(TaxInfo[3]);
240
+ finalTotalsData.CustPartCGST = TrUtils.SetValueToZeroIfNull(TaxInfo[0]);
241
+ finalTotalsData.CustPartIGST = TrUtils.SetValueToZeroIfNull(TaxInfo[2]);
242
+ finalTotalsData.CustPartSGST = TrUtils.SetValueToZeroIfNull(TaxInfo[1]);
243
+
244
+ // Calculate after tax amount
245
+ finalTotalsData.CustPartAfterTax = Add(finalTotalsData.CustPartITax, finalTotalsData.CustPartsTotalAfterDisc);
246
+
247
+ // Add tax grouping information
248
+ finalTotalsData.CustTaxGroupData = this.GetTaxGroupingForPartsByHSN(TrUtils.Stringify(PartsList), TaxCodes, DecimalsNumber);
249
+ finalTotalsData.CustTaxGroupDataByPerc = this.GetTaxGroupingForPartsByPerc(PartsList, TaxCodes, DecimalsNumber);
250
+
251
+ // Add rounding information
252
+ finalTotalsData.CustTotalRoundedBy = TrUtils.FixedTo(finalTotalsData.Round, DecimalsNumber);
253
+ finalTotalsData.CustRoundedTotal = TrUtils.FixedTo(finalTotalsData.Total, DecimalsNumber);
254
+
255
+ // Format all numeric values to proper decimal places
256
+ for (var key in finalTotalsData) {
257
+ if (key !== 'Total' && key !== 'SubTotal' &&
258
+ key !== 'LDisc' && key !== 'LPerc' && key !== 'PDisc' &&
259
+ key !== 'PPerc' && key !== 'Disc' && key !== 'Perc' && key !== 'Tax'
260
+ && typeof finalTotalsData[key] === 'number') {
261
+ finalTotalsData[key] = TrUtils.FixPriceValue(finalTotalsData[key], DecimalsNumber);
262
+ }
263
+ }
264
+
265
+ return finalTotalsData;
266
+ }
267
+
268
+ /**
269
+ * Groups parts by tax percentage for consolidated tax reporting
270
+ * @param Parts - Array of parts to group
271
+ * @param TaxCodes - Available tax codes
272
+ * @param DecimalsNumber - Number of decimal places
273
+ * @returns Array of parts grouped by tax percentage
274
+ */
275
+ static GetTaxGroupingForPartsByPerc(Parts: any, TaxCodes: any, DecimalsNumber: any) {
276
+ // Add combined tax percentage to each part
277
+ Parts = this.GetCombinedTaxPercentage(TrUtils.Stringify(Parts), TaxCodes);
278
+
279
+ // Group parts with same tax percentages
280
+ let FinalMatchedParts: any[] = this.ComparePartsByPerc(Parts, TaxCodes);
281
+
282
+ // Generate tax grouping information
283
+ return this.GetTaxGroupingInfoByHSN(FinalMatchedParts, TaxCodes, DecimalsNumber);
284
+ }
285
+
286
+ /**
287
+ * Compares and groups parts by tax percentage rates
288
+ * @param Parts - Array of parts to compare
289
+ * @param TaxCodes - Available tax codes
290
+ * @returns Array of grouped parts with same tax percentages
291
+ */
292
+ static ComparePartsByPerc(Parts: any, TaxCodes: any) {
293
+ let FinalMatchedParts: any[] = [];
294
+ Parts?.forEach((Part: any) => {
295
+ // Find parts with matching tax amounts that haven't been grouped yet
296
+ let MatchedPartsBasedOnHSN = Parts.filter((argPart: any) => {
297
+ let PartFound: boolean = false;
298
+
299
+ // Check if part is already in a group
300
+ FinalMatchedParts.forEach((FinalArgParts: any) => {
301
+ let PartIndex: any = FinalArgParts.findIndex((FinalArgPart: any) => {
302
+ return FinalArgPart._id === argPart._id;
303
+ });
304
+ if (PartIndex !== -1) {
305
+ PartFound = true;
306
+ }
307
+ });
308
+
309
+ // Return parts with same tax percentages that aren't already grouped
310
+ return (!PartFound) &&
311
+ (argPart.CGSTAmt === Part.CGSTAmt) && (argPart.IGSTAmt === Part.IGSTAmt) &&
312
+ (argPart.SGSTAmt === Part.SGSTAmt);
313
+ });
314
+
315
+ // Add group if it contains parts
316
+ if (MatchedPartsBasedOnHSN.length !== 0) {
317
+ FinalMatchedParts.push(MatchedPartsBasedOnHSN);
318
+ }
319
+ });
320
+ return FinalMatchedParts;
321
+ }
322
+
323
+ /**
324
+ * Calculates total discounted amount for all parts
325
+ * @param PartsList - Array of parts
326
+ * @param isTaxable - Whether parts are taxable
327
+ * @param finalTotalsData - Existing totals data
328
+ * @returns Total discounted amount including overall part discount
329
+ */
330
+ static GetPartDiscountedTotal(PartsList: any, isTaxable: boolean, finalTotalsData: any) {
331
+ let PartsDiscountedTotal: any = 0;
332
+ let overallPartDisc: number = 0;
333
+
334
+ // Add overall part discount if not taxable
335
+ if (!isTaxable) {
336
+ overallPartDisc = TrUtils.SetValueToZeroIfNull(finalTotalsData.PDisc)
337
+ }
338
+
339
+ // Sum up individual part discounts
340
+ PartsList.forEach((Part: any) => {
341
+ PartsDiscountedTotal = Add(PartsDiscountedTotal, Part.DiscountedPrice);
342
+ });
343
+
344
+ return Add(PartsDiscountedTotal, overallPartDisc);
345
+ }
346
+
347
+ /**
348
+ * Calculates total tax amount for all parts
349
+ * @param PartsList - Array of parts
350
+ * @param IsIndependentTax - Whether tax is calculated independently
351
+ * @returns Total tax amount for all parts
352
+ */
353
+ static GetPartsTaxTotalFor(PartsList: any, IsIndependentTax: boolean) {
354
+ let TotalTaxAmt: any = 0;
355
+ if (IsIndependentTax) {
356
+ PartsList.forEach((Part: any) => {
357
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CGST, Part.SGST, Part.IGST);
358
+ });
359
+ }
360
+ return TotalTaxAmt;
361
+ }
362
+
363
+ /**
364
+ * Calculates customer total based on tax calculation type
365
+ * @param finalTotalsData - Existing totals data
366
+ * @param LaborTaxAmount - Total labor tax amount
367
+ * @param PartsTaxAmount - Total parts tax amount
368
+ * @param LaborList - Array of labor items
369
+ * @param PartsList - Array of parts
370
+ * @param IsIndependentTax - Whether tax is calculated independently
371
+ * @returns Final customer total based on tax type
372
+ */
373
+ static GetCustomerTotalBasedOnTaxType(finalTotalsData: any, LaborTaxAmount: number, PartsTaxAmount: number
374
+ , LaborList: any, PartsList: any,
375
+ IsIndependentTax: boolean) {
376
+ let PartsTotalAfterDisc: any = this.GetPartsTotalAfterDiscount(PartsList);
377
+
378
+ if (IsIndependentTax) {
379
+ // Add tax amounts to the total
380
+ return Add(PartsTotalAfterDisc, LaborTaxAmount, PartsTaxAmount);
381
+ } else {
382
+ // Subtract discount from the total
383
+ return Subtract(PartsTotalAfterDisc, finalTotalsData.Disc);
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Calculates items total after applying discounts (percentage or fixed)
389
+ * @param PartsTotalAfterDisc - Parts total after discount
390
+ * @param PartsTaxAmount - Parts tax amount
391
+ * @param MainPDisc - Main parts discount amount
392
+ * @param PDiscInPerc - Parts discount percentage
393
+ * @returns Final items total after all discounts
394
+ */
395
+ static ItemsTotalAfterDiscount(PartsTotalAfterDisc: number, PartsTaxAmount: number, MainPDisc: number, PDiscInPerc: string) {
396
+ let ItemsTotal: number = Add(PartsTotalAfterDisc, PartsTaxAmount);
397
+
398
+ // Apply discount if present
399
+ if (!TrUtils.IsZero(MainPDisc)) {
400
+ if (!TrUtils.IsEmpty(PDiscInPerc)) {
401
+ // Apply percentage discount
402
+ ItemsTotal = Subtract(ItemsTotal, Divide(Multiply(ItemsTotal, Number(PDiscInPerc)), 100));
403
+ } else {
404
+ // Apply fixed discount
405
+ ItemsTotal = Subtract(ItemsTotal, MainPDisc);
406
+ }
407
+ }
408
+ return ItemsTotal;
409
+ }
410
+
411
+ /**
412
+ * Calculates total CGST tax amount for labor items
413
+ * @param opCodesList - Array of operation codes/labor
414
+ * @param IsIndependentTax - Whether tax is calculated independently
415
+ * @returns Total CGST amount for labor
416
+ */
417
+ static GetLaborCGSTTaxTotal(opCodesList: any, IsIndependentTax: boolean) {
418
+ let TotalTaxAmt: any = 0;
419
+ if (IsIndependentTax) {
420
+ opCodesList.forEach((Labor: any) => {
421
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CGST);
422
+ });
423
+ }
424
+ return TotalTaxAmt;
425
+ }
426
+
427
+ /**
428
+ * Calculates total IGST tax amount for labor items
429
+ * @param opCodesList - Array of operation codes/labor
430
+ * @param IsIndependentTax - Whether tax is calculated independently
431
+ * @returns Total IGST amount for labor
432
+ */
433
+ static GetLaborIGSTTaxTotal(opCodesList: any, IsIndependentTax: boolean) {
434
+ let TotalTaxAmt: any = 0;
435
+ if (IsIndependentTax) {
436
+ opCodesList.forEach((Labor: any) => {
437
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.IGST);
438
+ });
439
+ }
440
+ return TotalTaxAmt;
441
+ }
442
+
443
+ /**
444
+ * Calculates total SGST tax amount for labor items
445
+ * @param opCodesList - Array of operation codes/labor
446
+ * @param IsIndependentTax - Whether tax is calculated independently
447
+ * @returns Total SGST amount for labor
448
+ */
449
+ static GetLaborSGSTTaxTotal(opCodesList: any, IsIndependentTax: boolean) {
450
+ let TotalTaxAmt: any = 0;
451
+ if (IsIndependentTax) {
452
+ opCodesList.forEach((Labor: any) => {
453
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.SGST);
454
+ });
455
+ }
456
+ return TotalTaxAmt;
457
+ }
458
+
459
+ /**
460
+ * Calculates GST tax breakdown for all parts (CGST, SGST, IGST, Total)
461
+ * @param PartsList - Array of parts
462
+ * @param IsIndependentTax - Whether tax is calculated independently
463
+ * @returns Array containing [CGST, SGST, IGST, Total Tax] amounts
464
+ */
465
+ static GetPartGSTTaxTotal(PartsList: any, IsIndependentTax: boolean) {
466
+ let TotalCGSTAmt: number = 0;
467
+ let TotalSGSTAmt: number = 0;
468
+ let TotalIGSTAmt: number = 0;
469
+ let TotalTaxAmt: number = 0;
470
+
471
+ if (IsIndependentTax) {
472
+ PartsList.forEach((Part: any) => {
473
+ TotalCGSTAmt = Add(TotalCGSTAmt, Part.CGST);
474
+ TotalIGSTAmt = Add(TotalIGSTAmt, Part.IGST);
475
+ TotalSGSTAmt = Add(TotalSGSTAmt, Part.SGST);
476
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CGST, Part.SGST, Part.IGST);
477
+ });
478
+ }
479
+ return [TotalCGSTAmt, TotalSGSTAmt, TotalIGSTAmt, TotalTaxAmt];
480
+ }
481
+
482
+ /**
483
+ * Groups parts by HSN code for tax reporting and compliance
484
+ * @param Parts - Array of parts to group
485
+ * @param TaxCodes - Available tax codes
486
+ * @param DecimalsNumber - Number of decimal places
487
+ * @returns Tax grouping information organized by HSN codes
488
+ */
489
+ static GetTaxGroupingForPartsByHSN(Parts: any, TaxCodes: any, DecimalsNumber: number) {
490
+ // Add combined tax percentage to parts
491
+ Parts = this.GetCombinedTaxPercentage(Parts, TaxCodes);
492
+
493
+ // Group parts by HSN code
494
+ let FinalMatchedParts: any[] = this.ComparePartsByHSN(Parts, TaxCodes);
495
+
496
+ // Generate HSN-based tax grouping information
497
+ return this.GetTaxGroupingInfoByHSN(FinalMatchedParts, TaxCodes, DecimalsNumber);
498
+ }
499
+
500
+ /**
501
+ * Adds combined tax percentage calculation to each part based on tax codes
502
+ * @param Parts - Array of parts to process
503
+ * @param TaxCodes - Available tax codes for lookup
504
+ * @returns Parts array with added tax percentage information
505
+ */
506
+ static GetCombinedTaxPercentage(Parts: any, TaxCodes: any) {
507
+ Parts.forEach((Part: any) => {
508
+ // Ensure HSN is not null
509
+ if (TrUtils.IsNull(Part.HSN)) {
510
+ Part.HSN = '';
511
+ }
512
+
513
+ // Get GST values based on tax code
514
+ let GSTValues: any[] = this.GetGSTValueBasedOnTaxCode(Part.TCode, TaxCodes);
515
+ Part.CGSTAmt = TrUtils.SetValueToZeroIfNull(GSTValues[0]);
516
+ Part.SGSTAmt = TrUtils.SetValueToZeroIfNull(GSTValues[1]);
517
+ Part.IGSTAmt = TrUtils.SetValueToZeroIfNull(GSTValues[2]);
518
+
519
+ // Calculate combined tax percentage
520
+ Part.CombinedTaxPercentage = Add(Part.CGSTAmt, Part.SGSTAmt, Part.IGSTAmt);
521
+ });
522
+ return Parts;
523
+ }
524
+
525
+ /**
526
+ * Compares and groups parts by HSN code and tax rates
527
+ * @param Parts - Array of parts to compare
528
+ * @param TaxCodes - Available tax codes
529
+ * @returns Array of parts grouped by HSN code and tax rates
530
+ */
531
+ static ComparePartsByHSN(Parts: any, TaxCodes: any) {
532
+ let FinalMatchedParts: any[] = [];
533
+ Parts.forEach((Part: any) => {
534
+ // Find parts with same HSN and tax rates that haven't been grouped
535
+ let MatchedPartsBasedOnHSN = Parts.filter((argPart: any) => {
536
+ let PartFound: boolean = false;
537
+
538
+ // Check if part is already in a group
539
+ FinalMatchedParts.forEach((FinalArgParts: any) => {
540
+ let PartIndex: any = FinalArgParts.findIndex((FinalArgPart: any) => {
541
+ return FinalArgPart._id === argPart._id;
542
+ });
543
+ if (PartIndex !== -1) {
544
+ PartFound = true;
545
+ }
546
+ });
547
+
548
+ // Return parts with same HSN and tax rates that aren't grouped yet
549
+ return (argPart.HSN === Part.HSN) && (!PartFound) &&
550
+ (argPart.CGSTAmt === Part.CGSTAmt) && (argPart.IGSTAmt === Part.IGSTAmt) &&
551
+ (argPart.SGSTAmt === Part.SGSTAmt);
552
+ });
553
+
554
+ // Add group if it contains parts
555
+ if (MatchedPartsBasedOnHSN.length !== 0) {
556
+ FinalMatchedParts.push(MatchedPartsBasedOnHSN);
557
+ }
558
+ });
559
+ return FinalMatchedParts;
560
+ }
561
+
562
+ /**
563
+ * Generates detailed tax information grouped by HSN codes for compliance reporting
564
+ * @param FinalMatchedParts - Array of grouped parts by HSN
565
+ * @param TaxCodes - Available tax codes
566
+ * @param DecimalsNumber - Number of decimal places for formatting
567
+ * @returns Array of HSN-wise tax information objects
568
+ */
569
+ static GetTaxGroupingInfoByHSN(FinalMatchedParts: any, TaxCodes: any, DecimalsNumber: any) {
570
+ let HSNTaxInfo: any[] = [];
571
+
572
+ FinalMatchedParts.forEach((MatchedPart: any) => {
573
+ let TaxInfo: any = {};
574
+ let TaxOnAmount: any = 0;
575
+ let TaxAmount: any = 0;
576
+ let CGSTAmt: any = 0;
577
+ let SGSTAmt: any = 0;
578
+ let IGSTAmt: any = 0;
579
+
580
+ // Get HSN code and tax percentage from first item
581
+ let HSN: any = MatchedPart[0].HSN;
582
+ TaxInfo.CombinedTaxPercentage = MatchedPart[0].CombinedTaxPercentage;
583
+
584
+ // Calculate totals for all parts in this HSN group
585
+ MatchedPart.forEach((argMatchedGSTPart: any) => {
586
+ TaxOnAmount = Add(TaxOnAmount, TrUtils.FixedTo(argMatchedGSTPart.AfterPartDisc, DecimalsNumber));
587
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CGST, DecimalsNumber));
588
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.IGST, DecimalsNumber));
589
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.SGST, DecimalsNumber));
590
+ CGSTAmt = Add(CGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.CGST, DecimalsNumber));
591
+ SGSTAmt = Add(SGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.SGST, DecimalsNumber));
592
+ IGSTAmt = Add(IGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.IGST, DecimalsNumber));
593
+ });
594
+
595
+ // Build tax information object
596
+ TaxInfo.HSN = HSN;
597
+ TaxInfo.CGSTAmt = CGSTAmt;
598
+ TaxInfo.SGSTAmt = SGSTAmt;
599
+ TaxInfo.IGSTAmt = IGSTAmt;
600
+ TaxInfo.TotalTaxableAmount = TrUtils.FixPriceValue(TaxOnAmount, DecimalsNumber);
601
+ TaxInfo.TotalTaxAmount = TrUtils.FixPriceValue(TaxAmount, DecimalsNumber);
602
+ TaxInfo.ItemsCount = MatchedPart.length;
603
+ TaxInfo.CGST = MatchedPart[0].CGSTAmt;
604
+ TaxInfo.IGST = MatchedPart[0].IGSTAmt;
605
+ TaxInfo.SGST = MatchedPart[0].SGSTAmt;
606
+
607
+ // Only add if there's a taxable amount
608
+ if (TaxOnAmount !== 0) {
609
+ HSNTaxInfo.push(TaxInfo);
610
+ }
611
+ });
612
+ return HSNTaxInfo;
613
+ }
614
+
615
+ /**
616
+ * Retrieves GST values (CGST, SGST, IGST) based on tax code lookup
617
+ * @param TCode - Tax code identifier
618
+ * @param TaxCodes - Array of available tax codes
619
+ * @returns Array containing [CGST, SGST, IGST] values for the tax code
620
+ */
621
+ static GetGSTValueBasedOnTaxCode(TCode: any, TaxCodes: any) {
622
+ let CGST: number = 0;
623
+ let SGST: number = 0;
624
+ let IGST: number = 0;
625
+
626
+ // Return zeros if tax code is null
627
+ if (TrUtils.IsNull(TCode)) {
628
+ return [CGST, SGST, IGST];
629
+ }
630
+
631
+ // Find tax code in the array
632
+ let TCodeIndex: any = TaxCodes.findIndex((TaxCode: any) => {
633
+ return TaxCode._id === Number(TCode);
634
+ });
635
+
636
+ // Return appropriate tax values based on tax type
637
+ if (TCodeIndex !== -1) {
638
+ if (TaxCodes[TCodeIndex].Type === 'Intra') {
639
+ // Intra-state: CGST + SGST
640
+ return [TaxCodes[TCodeIndex].CGST, TaxCodes[TCodeIndex].SGST, 0];
641
+ } else {
642
+ // Inter-state: IGST only
643
+ return [0, 0, TaxCodes[TCodeIndex].IGST];
644
+ }
645
+ } else {
646
+ // Tax code not found, return zeros
647
+ return [CGST, SGST, IGST];
648
+ }
649
+ }
650
+
651
+ }