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,834 @@
1
+ import { Add, Divide, Multiply, Subtract } from "../../shared/math-operations";
2
+ import { TrUtils } from "../../utils/tr-utils";
3
+
4
+
5
+
6
+ export class InvoiceTotalsService {
7
+
8
+ static GetTaxAmountFromTaxes(item: any, taxCode: string) {
9
+ const taxes = Array.isArray(item?.Taxes) ? item.Taxes : [];
10
+ const matchedTaxes = taxes.filter((tax: any) => tax?.Code === taxCode);
11
+ if (matchedTaxes.length !== 0) {
12
+ return matchedTaxes.reduce((total: number, tax: any) => Add(total, tax?.Amt), 0);
13
+ }
14
+ return 0;
15
+ }
16
+
17
+ static GetTaxRateFromTaxes(item: any, taxCode: string) {
18
+ const taxes = Array.isArray(item?.Taxes) ? item.Taxes : [];
19
+ const matchedTaxes = taxes.filter((tax: any) => tax?.Code === taxCode);
20
+ if (matchedTaxes.length !== 0) {
21
+ return matchedTaxes.reduce((total: number, tax: any) => Add(total, tax?.Rate), 0);
22
+ }
23
+ return 0;
24
+ }
25
+
26
+ static GetTCodeFromTaxes(item: any) {
27
+ const taxes = Array.isArray(item?.Taxes) ? item.Taxes : [];
28
+ const matchedTax = taxes.find((tax: any) => !TrUtils.IsNull(tax?.TaxCodeId));
29
+ if (!TrUtils.IsNull(matchedTax?.TaxCodeId)) {
30
+ return matchedTax.TaxCodeId;
31
+ }
32
+ return item?.TCode;
33
+ }
34
+
35
+ static GetTotalsValue(opCodesList: any, PartsList: any, IsIndependentTax: boolean, DetailedInfo: boolean,
36
+ LDisc: any, LPerc: string, PDisc: any, PPerc: string, Disc: any, Perc: string,
37
+ TaxCodes: any, WithItems: boolean, Settings: any, Adjust: number, isRoundable: boolean, EntitySettings: any) {
38
+
39
+ LPerc = TrUtils.SetPercToStringIfNull(LPerc);
40
+ PPerc = TrUtils.SetPercToStringIfNull(PPerc);
41
+ Perc = TrUtils.SetPercToStringIfNull(Perc);
42
+ LDisc = TrUtils.SetValueToZeroIfNull(LDisc);
43
+ PDisc = TrUtils.SetValueToZeroIfNull(PDisc);
44
+ Disc = TrUtils.SetValueToZeroIfNull(Disc);
45
+ if (TrUtils.IsNull(opCodesList)) {
46
+ opCodesList = [];
47
+ }
48
+
49
+ if (TrUtils.IsNull(PartsList)) {
50
+ PartsList = [];
51
+ }
52
+
53
+ opCodesList = this.CalculateLaborValues(opCodesList, IsIndependentTax);
54
+
55
+ PartsList = this.CalculateLaborPartValues(PartsList, IsIndependentTax);
56
+
57
+ let finalTotalsData: any = this.GetFinalRODataForSave(opCodesList, PartsList, IsIndependentTax, LDisc, LPerc,
58
+ PDisc, PPerc, Disc, Perc, DetailedInfo, Settings, TrUtils.SetValueToZeroIfNull(Adjust), isRoundable, EntitySettings.DecimalsNumber);
59
+
60
+ if (DetailedInfo) {
61
+ finalTotalsData = this.GetDetailedTotalsData(finalTotalsData,
62
+ IsIndependentTax, opCodesList, PartsList, TaxCodes, EntitySettings.DecimalsNumber);
63
+ }
64
+
65
+ if (WithItems) {
66
+ finalTotalsData.Ops = opCodesList;
67
+ finalTotalsData.Items = PartsList;
68
+ }
69
+ return finalTotalsData;
70
+ }
71
+
72
+ static CalculateLaborValues(opCodesList: any, IsIndependentTax: boolean) {
73
+ opCodesList = this.ResetLaborValues(opCodesList, IsIndependentTax);
74
+
75
+ // opCodesList = this.GetOperationsDiscountPrice(opCodesList);
76
+
77
+ // opCodesList = this.GetOperationsAfterDiscount(opCodesList,IsIndependentTax);
78
+
79
+ // opCodesList = this.GetOperationsAfterTax(opCodesList, IsIndependentTax);
80
+
81
+ return opCodesList;
82
+ }
83
+
84
+ static ResetLaborValues(opCodesList: any, IsIndependentTax: boolean) {
85
+ opCodesList.forEach((Operation: any) => {
86
+ Operation = this.ResetLaborValueIfInvalid(Operation);
87
+ Operation.DiscountedPrice = Add(Operation.Disc, Operation.RecDisc);
88
+ if (TrUtils.IsNull(Operation.Amt)) {
89
+ Operation.Amt = Operation.Pr;
90
+ }
91
+ if (IsIndependentTax) {
92
+ let NetAmt: number = Subtract(Operation.Amt, Operation.Disc, Operation.RecDisc);
93
+ Operation.AfterLaborDisc = NetAmt;
94
+ Operation.AfterLaborTax = Add(Operation.AfterLaborDisc, Operation.CGST, Operation.SGST, Operation.IGST);
95
+ } else {
96
+ Operation.AfterLaborDisc = Subtract(Operation.Amt, Operation.Disc, Operation.RecDisc);
97
+ Operation.AfterLaborTax = Operation.AfterLaborDisc;
98
+ }
99
+ });
100
+ return opCodesList;
101
+ }
102
+
103
+ static ResetLaborValueIfInvalid(Operation: any) {
104
+ Operation.Pr = TrUtils.SetValueToZeroIfNull(Operation.Pr);
105
+ Operation.RecDisc = TrUtils.SetValueToZeroIfNull(Operation.RecDisc);
106
+ Operation.Disc = TrUtils.SetValueToZeroIfNull(Operation.Disc);
107
+ Operation.CGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Operation, 'CGST'));
108
+ Operation.SGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Operation, 'SGST'));
109
+ Operation.IGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Operation, 'IGST'));
110
+ Operation.TCode = this.GetTCodeFromTaxes(Operation);
111
+ return Operation;
112
+ }
113
+
114
+ static CalculateLaborPartValues(PartsList: any, IsIndependentTax: boolean) {
115
+ PartsList = this.ResetLaborPartValues(PartsList, IsIndependentTax);
116
+
117
+ // PartsList = this.GetLaborPartsDiscountPrice(PartsList);
118
+
119
+ // PartsList = this.GetLaborPartsAfterDiscount(PartsList,IsIndependentTax);
120
+
121
+ // PartsList = this.GetPartsAfterTax(PartsList, IsIndependentTax);
122
+
123
+ return PartsList;
124
+ }
125
+
126
+ static ResetLaborPartValues(PartsList: any, IsIndependentTax: boolean) {
127
+ PartsList.forEach((Part: any) => {
128
+ Part = this.ResetLaborPartValueIfInvalid(Part);
129
+ Part.DiscountedPrice = Add(Part.Disc, Part.RecDisc);
130
+
131
+ if (IsIndependentTax) {
132
+ let NetAmt: number = Subtract(Part.UnAmt, Part.Disc, Part.RecDisc);
133
+ Part.AfterPartDisc = NetAmt;
134
+ Part.AfterPartTax = Add(Part.AfterPartDisc, Part.CGST, Part.SGST, Part.IGST);
135
+ } else {
136
+ Part.AfterPartDisc = Subtract(Part.UnAmt, Part.Disc, Part.RecDisc);
137
+ Part.AfterPartTax = Part.AfterPartDisc;
138
+
139
+ }
140
+ });
141
+ return PartsList;
142
+ }
143
+
144
+ static ResetLaborPartValueIfInvalid(Part: any) {
145
+ Part.UnPr = TrUtils.SetValueToZeroIfNull(Part.UnPr);
146
+ Part.Disc = TrUtils.SetValueToZeroIfNull(Part.Disc);
147
+ Part.RecDisc = TrUtils.SetValueToZeroIfNull(Part.RecDisc);
148
+ Part.CGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Part, 'CGST'));
149
+ Part.SGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Part, 'SGST'));
150
+ Part.IGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Part, 'IGST'));
151
+ Part.TCode = this.GetTCodeFromTaxes(Part);
152
+ return Part;
153
+ }
154
+
155
+ static GetFinalRODataForSave(LaborList: any, PartsList: any, IsIndependentTax: boolean,
156
+ LDisc: any, LPerc: string, PDisc: string, PPerc: string, Disc: any, Perc: string,
157
+ DetailedInfo: boolean, Settings: any, Adjust: number, isRoundable: boolean, DecimalsNumber: any) {
158
+
159
+ let finalTotalsData: any = {};
160
+
161
+ finalTotalsData = this.SetMainDiscountValues(LPerc, PPerc, LDisc, PDisc, Disc, Perc, finalTotalsData, DetailedInfo);
162
+
163
+ finalTotalsData.Settings = Settings;
164
+
165
+ finalTotalsData = this.GetFinalCustomerTotalsData(finalTotalsData, LaborList, PartsList,
166
+ IsIndependentTax, DetailedInfo, Adjust, isRoundable, DecimalsNumber);
167
+
168
+ return finalTotalsData;
169
+ }
170
+
171
+ static SetMainDiscountValues(LPerc: string, PPerc: string, LDisc: any,
172
+ PDisc: any, Disc: any, Perc: string, finalTotalsData: any, DetailedInfo: boolean) {
173
+ finalTotalsData.LDisc = LDisc;
174
+ finalTotalsData.LPerc = LPerc;
175
+
176
+ finalTotalsData.PDisc = PDisc;
177
+ finalTotalsData.PPerc = PPerc;
178
+
179
+ finalTotalsData.Disc = Disc;
180
+ finalTotalsData.Perc = Perc;
181
+
182
+ if (DetailedInfo) {
183
+ finalTotalsData.FixedLDisc = LDisc;
184
+ finalTotalsData.FixedPDisc = PDisc;
185
+ finalTotalsData.FixedDisc = Disc;
186
+ }
187
+ return finalTotalsData;
188
+ }
189
+
190
+ static GetPartsAfterDiscount1(PartsList: any) {
191
+ let AfterIndvidualDisc: number = 0;
192
+ PartsList.forEach((Part: any) => {
193
+ if (!Part.Ret) {
194
+ AfterIndvidualDisc = Add(AfterIndvidualDisc, Subtract(Part.UnAmt, Part.Disc));
195
+ }
196
+ });
197
+ return AfterIndvidualDisc;
198
+ }
199
+
200
+ static GetLaborTotalAfterDiscount1(OperationsList: any) {
201
+ let AfterIndvidualDisc: number = 0;
202
+ OperationsList.forEach((Operation: any) => {
203
+ if (TrUtils.IsNull(Operation.Amt)) {
204
+ Operation.Amt = Operation.Pr;
205
+ }
206
+ AfterIndvidualDisc = Add(AfterIndvidualDisc, Subtract(Operation.Amt, Operation.Disc));
207
+ });
208
+ return AfterIndvidualDisc;
209
+ }
210
+
211
+ static GetFinalCustomerTotalsData(finalTotalsData: any, LaborList: any, PartsList: any, IsIndependentTax: boolean,
212
+ DetailedInfo: boolean, Adjust: number, isRoundable: boolean, DecimalsNumber: any) {
213
+ let CustomerAfterDiscTotals: number = this.GetSubTotalFor(LaborList, PartsList);
214
+
215
+ let CustLaborTaxTotal = this.GetLaborTaxTotalFor(LaborList, IsIndependentTax);
216
+
217
+ let CustPartTaxTotal = this.GetPartsTaxTotalFor(PartsList, IsIndependentTax);
218
+ let RetCustParrtTaxTotal = this.GetRetPartsTaxTotalFor(PartsList, IsIndependentTax);
219
+ let NonRetCustParrtTaxTotal = this.GetNonRetPartsTaxTotalFor(PartsList, IsIndependentTax);
220
+
221
+ finalTotalsData.SubTotal = TrUtils.FixedTo(CustomerAfterDiscTotals, DecimalsNumber);
222
+ let CustLaborDiscTotal = this.GetLaborDiscountedTotal(LaborList, IsIndependentTax, finalTotalsData);
223
+
224
+ let CustPartsDiscTotal = this.GetPartDiscountedTotal(PartsList, IsIndependentTax, finalTotalsData);
225
+
226
+ let CustLaborTotalAfterDisc = this.GetLaborTotalAfterDiscount(LaborList);
227
+ let CustPartsTotalAfterDisc = this.GetPartsTotalAfterDiscount(PartsList);
228
+ // if (IsIndependentTax) {
229
+ finalTotalsData.STotal = Add(CustLaborDiscTotal, CustPartsDiscTotal, CustLaborTotalAfterDisc, CustPartsTotalAfterDisc);
230
+ // } else {
231
+ // finalTotalsData.STotal = Add(CustLaborTotalAfterDisc, CustPartsTotalAfterDisc);
232
+ // }
233
+ let CustLaborTotalAfterDisc1: number = this.GetLaborTotalAfterDiscount1(LaborList);
234
+ let CustPartsTotalAfterDisc1: number = this.GetPartsAfterDiscount1(PartsList);
235
+ let AmtAfterIndvidualItemDisc: number = Add(CustLaborTotalAfterDisc1, CustPartsTotalAfterDisc1);
236
+ finalTotalsData.SIndTotal = AmtAfterIndvidualItemDisc;
237
+ // finalTotalsData.Disc = !TrUtils.IsZero(finalTotalsData.Perc) ? TrUtils.ConvertPercToVal(finalTotalsData.Perc, AmtAfterIndvidualItemDisc, DecimalsNumber) : finalTotalsData.Disc;
238
+
239
+ let CustTotal: any = this.GetCustomerTotalBasedOnTaxType(finalTotalsData, CustLaborTaxTotal, CustPartTaxTotal, LaborList, PartsList, IsIndependentTax, Adjust);
240
+ let RetCustTotal: any = this.GetRetCustomerTotalBasedOnTaxType(finalTotalsData, CustLaborTaxTotal, RetCustParrtTaxTotal, LaborList, PartsList, IsIndependentTax, Adjust, DecimalsNumber);
241
+ let NonRetCustTotal: any = this.GetNonRetCustomerTotalBasedOnTaxType(finalTotalsData, CustLaborTaxTotal, NonRetCustParrtTaxTotal, LaborList, PartsList, IsIndependentTax, Adjust, DecimalsNumber);
242
+
243
+ if (isRoundable) {
244
+ finalTotalsData.Round = Subtract(Math.round(CustTotal), CustTotal);
245
+ finalTotalsData.Total = Math.round(CustTotal);
246
+ } else {
247
+ finalTotalsData.Total = TrUtils.FixedTo(CustTotal, DecimalsNumber);
248
+ }
249
+
250
+ finalTotalsData.RetTotal = TrUtils.FixedTo(RetCustTotal, DecimalsNumber);
251
+ finalTotalsData.NonRetTotal = TrUtils.FixedTo(NonRetCustTotal, DecimalsNumber);
252
+
253
+ if (DetailedInfo) {
254
+ finalTotalsData.FixedSubTotal = TrUtils.FixedTo(CustomerAfterDiscTotals, DecimalsNumber);
255
+ finalTotalsData.FixedTotal = TrUtils.FixedTo(CustTotal, DecimalsNumber);
256
+ finalTotalsData.Adj = TrUtils.FixedTo(Adjust, DecimalsNumber);
257
+ }
258
+
259
+ return finalTotalsData;
260
+ }
261
+
262
+ static GetSubTotalFor(LaborList: any, PartsList: any) {
263
+ let LaborTotalAfterDisc: any = this.GetLaborTotalAfterDiscount(LaborList);
264
+ let PartsTotalAfterDisc: any = this.GetPartsTotalAfterDiscount(PartsList);
265
+ return Add(LaborTotalAfterDisc, PartsTotalAfterDisc);
266
+ }
267
+
268
+ static GetLaborTotalAfterDiscount(LaborList: any) {
269
+ let LaborTotalAfterDisc: any = 0;
270
+ LaborList.forEach((Labor: any) => {
271
+ LaborTotalAfterDisc = Add(LaborTotalAfterDisc, Labor.AfterLaborDisc);
272
+ });
273
+ return LaborTotalAfterDisc;
274
+ }
275
+
276
+ static GetPartsTotalAfterDiscount(PartsList: any) {
277
+ let PartsTotalAfterDisc: any = 0;
278
+ let RetPartsTotalAfterDisc: any = 0;
279
+ PartsList.forEach((Part: any) => {
280
+ if (Part.Ret === true) {
281
+ RetPartsTotalAfterDisc = Add(RetPartsTotalAfterDisc, Part.AfterPartDisc);
282
+ } else {
283
+ PartsTotalAfterDisc = Add(PartsTotalAfterDisc, Part.AfterPartDisc);
284
+ }
285
+ });
286
+ return Subtract(PartsTotalAfterDisc, RetPartsTotalAfterDisc);
287
+ }
288
+
289
+ static GetRetPartsTotalAfterDiscount(PartsList: any) {
290
+ let RetPartsTotalAfterDisc: any = 0;
291
+ PartsList.forEach((Part: any) => {
292
+ if (Part.Ret === true) {
293
+ RetPartsTotalAfterDisc = Add(RetPartsTotalAfterDisc, Part.AfterPartDisc);
294
+ }
295
+ });
296
+ return RetPartsTotalAfterDisc;
297
+ }
298
+
299
+ static GetNonRetPartsTotalAfterDiscount(PartsList: any) {
300
+ let NonRetPartsTotalAfterDisc: any = 0;
301
+ PartsList.forEach((Part: any) => {
302
+ if (TrUtils.IsNull(Part.Ret) || Part.Ret === false) {
303
+ NonRetPartsTotalAfterDisc = Add(NonRetPartsTotalAfterDisc, Part.AfterPartDisc);
304
+ }
305
+ });
306
+ return NonRetPartsTotalAfterDisc;
307
+ }
308
+
309
+ static GetDetailedTotalsData(finalTotalsData: any, IsIndependentTax: boolean, opCodesList: any, PartsList: any, TaxCodes: any, DecimalsNumber: any) {
310
+ finalTotalsData.CustLaborDiscTotal = this.GetLaborDiscountedTotal(opCodesList, IsIndependentTax, finalTotalsData);
311
+
312
+ finalTotalsData.CustPartsDiscTotal = this.GetPartDiscountedTotal(PartsList, IsIndependentTax, finalTotalsData);
313
+
314
+ finalTotalsData.CustLaborTotalAfterDisc = this.GetLaborTotalAfterDiscount(opCodesList);
315
+ finalTotalsData.CustPartsTotalAfterDisc = this.GetPartsTotalAfterDiscount(PartsList);
316
+
317
+ finalTotalsData.CustLaborTotalBeforeDisc = Add(finalTotalsData.CustLaborTotalAfterDisc
318
+ , finalTotalsData.CustLaborDiscTotal);
319
+ if (IsIndependentTax) {
320
+ finalTotalsData.CustPartsTotalBeforeDisc = Add(finalTotalsData.CustPartsTotalAfterDisc
321
+ , finalTotalsData.CustPartsDiscTotal);
322
+ } else {
323
+ finalTotalsData.CustPartsTotalBeforeDisc = finalTotalsData.CustPartsTotalAfterDisc;
324
+ }
325
+
326
+ let LaborTaxInfo: any = this.GetLaborGSTTaxTotal(opCodesList, IsIndependentTax);
327
+ finalTotalsData.CustLaborITax = TrUtils.SetValueToZeroIfNull(LaborTaxInfo[3]);
328
+ finalTotalsData.CustLaborSGST = TrUtils.SetValueToZeroIfNull(LaborTaxInfo[1]);
329
+ finalTotalsData.CustLaborCGST = TrUtils.SetValueToZeroIfNull(LaborTaxInfo[0]);
330
+ finalTotalsData.CustLaborIGST = TrUtils.SetValueToZeroIfNull(LaborTaxInfo[2]);
331
+
332
+ let PartTaxInfo: any = this.GetPartGSTTaxTotal(PartsList, IsIndependentTax);
333
+ finalTotalsData.CustPartITax = this.GetPartsTaxTotalFor(PartsList, IsIndependentTax);
334
+ finalTotalsData.CustPartCGST = TrUtils.SetValueToZeroIfNull(PartTaxInfo[0]);
335
+ finalTotalsData.CustPartIGST = TrUtils.SetValueToZeroIfNull(PartTaxInfo[2]);
336
+ finalTotalsData.CustPartSGST = TrUtils.SetValueToZeroIfNull(PartTaxInfo[1]);
337
+
338
+ finalTotalsData.CustLaborAfterTax = Add(finalTotalsData.CustLaborITax, finalTotalsData.CustLaborTotalAfterDisc);
339
+ finalTotalsData.CustPartAfterTax = Add(finalTotalsData.CustPartITax, finalTotalsData.CustPartsTotalAfterDisc);
340
+
341
+ finalTotalsData.CustTaxGroupData = this.GetTaxGroupingForPartsByHSN(PartsList, TaxCodes, DecimalsNumber);
342
+ finalTotalsData.CustTaxGroupDataByPerc = this.GetTaxGroupingForPartsByPerc(PartsList, TaxCodes, DecimalsNumber);
343
+ finalTotalsData.CustLaborTaxGroupDataByPerc = this.GetTaxGroupingForLaborByPerc(opCodesList, TaxCodes, DecimalsNumber);
344
+ finalTotalsData.TaxSummary = this.groupTaxData(finalTotalsData.CustTaxGroupData, finalTotalsData.CustLaborTaxGroupDataByPerc);
345
+ finalTotalsData.CustTotalRoundedBy = TrUtils.FixedTo(finalTotalsData.Round, DecimalsNumber);
346
+
347
+ finalTotalsData.CustRoundedTotal = TrUtils.FixedTo(finalTotalsData.Total, DecimalsNumber);
348
+ finalTotalsData.CustRetRoundedTotal = TrUtils.FixedTo(finalTotalsData.RetTotal, DecimalsNumber);
349
+ finalTotalsData.CustNonRetRoundedTotal = TrUtils.FixedTo(finalTotalsData.NonRetTotal, DecimalsNumber);
350
+
351
+ for (var key in finalTotalsData) {
352
+ if (key !== 'Total' && key !== 'SubTotal' &&
353
+ key !== 'LDisc' && key !== 'LPerc' && key !== 'PDisc' &&
354
+ key !== 'PPerc' && key !== 'Disc' && key !== 'Perc' && key !== 'Tax'
355
+ && typeof finalTotalsData[key] === 'number') {
356
+ finalTotalsData[key] = TrUtils.FixPriceValue(finalTotalsData[key], DecimalsNumber);
357
+ }
358
+ }
359
+
360
+ return finalTotalsData;
361
+ }
362
+
363
+ static groupTaxData(
364
+ items: any[],
365
+ ops: any[]
366
+ ): any[] {
367
+
368
+ if (TrUtils.IsNull(items)) {
369
+ items = [];
370
+ }
371
+ if (TrUtils.IsNull(ops)) {
372
+ ops = [];
373
+ }
374
+ const combined = [...items, ...ops];
375
+
376
+ const groupedMap = new Map<number, { CombinedTaxPercentage: number; CGSTAmt: number; SGSTAmt: number; IGSTAmt?: number, TotalTaxAmount: number, TotalTaxableAmount: number }>();
377
+
378
+ combined.forEach(item => {
379
+ if (groupedMap.has(item.CombinedTaxPercentage)) {
380
+ const existing = groupedMap.get(item.CombinedTaxPercentage)!;
381
+ existing.CGSTAmt = Add(existing.CGSTAmt, item.CGSTAmt);
382
+ existing.SGSTAmt = Add(existing.SGSTAmt, item.SGSTAmt);
383
+
384
+ // Sum IGST if present
385
+ if (item.IGSTAmt !== undefined) {
386
+ existing.IGSTAmt = Add(existing.IGSTAmt || 0, item.IGSTAmt);
387
+ }
388
+
389
+ existing.TotalTaxAmount = Add(existing.TotalTaxAmount || 0, item.TotalTaxAmount || 0);
390
+ existing.TotalTaxableAmount = Add(existing.TotalTaxableAmount || 0, item.TotalTaxableAmount || 0);
391
+ } else {
392
+ // Clone the object to avoid mutation
393
+ groupedMap.set(item.CombinedTaxPercentage, { ...item });
394
+ }
395
+ });
396
+
397
+ return Array.from(groupedMap.values());
398
+ }
399
+
400
+ static GetTaxGroupingForLaborByPerc(opCodesList: any, TaxCodes: any, DecimalsNumber: any) {
401
+ opCodesList = this.GetCombinedTaxPercentage(TrUtils.Stringify(opCodesList), TaxCodes);
402
+ // opCodesList = this.ResetPartsHSNIfInvalid(opCodesList);
403
+
404
+ let FinalMatchedParts: any[] = this.CompareLaborByPerc(opCodesList, TaxCodes);
405
+
406
+ return this.GetTaxGroupingInfoBySAC(FinalMatchedParts, TaxCodes, DecimalsNumber);
407
+ }
408
+
409
+ static GetTaxGroupingForPartsByPerc(Parts: any, TaxCodes: any, DecimalsNumber: any) {
410
+ Parts = this.GetCombinedTaxPercentage(TrUtils.Stringify(Parts), TaxCodes);
411
+ // Parts = this.ResetPartsHSNIfInvalid(Parts);
412
+
413
+ let FinalMatchedParts: any[] = this.ComparePartsByPerc(Parts, TaxCodes);
414
+
415
+ return this.GetTaxGroupingInfoByHSN(FinalMatchedParts, TaxCodes, DecimalsNumber);
416
+ }
417
+
418
+ static GetTaxGroupingInfoBySAC(FinalMatchedLabors: any, TaxCodes: any, DecimalsNumber: any) {
419
+ let SACTaxInfo: any[] = [];
420
+ FinalMatchedLabors?.forEach((MatchedLabor: any) => {
421
+ let TaxInfo: any = {};
422
+ let TaxOnAmount: any = 0;
423
+ let TaxAmount: any = 0;
424
+ let CGSTAmt: any = 0;
425
+ let SGSTAmt: any = 0;
426
+ let IGSTAmt: any = 0;
427
+ let SAC: any = MatchedLabor[0].SAC;
428
+ TaxInfo.CombinedTaxPercentage = MatchedLabor[0].CombinedTaxPercentage;
429
+ MatchedLabor?.forEach((argMatchedGSTLabor: any) => {
430
+ TaxOnAmount = Add(TaxOnAmount, TrUtils.FixedTo(argMatchedGSTLabor.AfterLaborDisc, DecimalsNumber));
431
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTLabor.CGST, DecimalsNumber));
432
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTLabor.IGST, DecimalsNumber));
433
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTLabor.SGST, DecimalsNumber));
434
+ CGSTAmt = Add(CGSTAmt, TrUtils.FixedTo(argMatchedGSTLabor.CGST, DecimalsNumber));
435
+ SGSTAmt = Add(SGSTAmt, TrUtils.FixedTo(argMatchedGSTLabor.SGST, DecimalsNumber));
436
+ IGSTAmt = Add(IGSTAmt, TrUtils.FixedTo(argMatchedGSTLabor.IGST, DecimalsNumber));
437
+ });
438
+ TaxInfo.SAC = SAC;
439
+
440
+ TaxInfo.CGSTAmt = CGSTAmt;
441
+ TaxInfo.SGSTAmt = SGSTAmt;
442
+ TaxInfo.IGSTAmt = IGSTAmt;
443
+
444
+ TaxInfo.TotalTaxableAmount = TrUtils.FixPriceValue(TaxOnAmount, DecimalsNumber);
445
+ TaxInfo.TotalTaxAmount = TrUtils.FixPriceValue(TaxAmount, DecimalsNumber);
446
+ TaxInfo.ItemsCount = MatchedLabor.length;
447
+ TaxInfo.CGST = this.GetTaxRateFromTaxes(MatchedLabor[0], 'CGST');
448
+ TaxInfo.SGST = this.GetTaxRateFromTaxes(MatchedLabor[0], 'SGST');
449
+ TaxInfo.IGST = this.GetTaxRateFromTaxes(MatchedLabor[0], 'IGST');
450
+ if (TaxOnAmount !== 0) {
451
+ SACTaxInfo.push(TaxInfo);
452
+ }
453
+ });
454
+ return SACTaxInfo;
455
+ }
456
+
457
+ static CompareLaborByPerc(opCodesList: any, TaxCodes: any) {
458
+ let FinalMatchedLabors: any[] = [];
459
+ opCodesList?.forEach((Labor: any) => {
460
+ let MatchedLaborsBasedOnPerc = opCodesList.filter((argLabor: any) => {
461
+ let PartFound: boolean = false;
462
+ FinalMatchedLabors.forEach((FinalArgLabors: any) => {
463
+ let PartIndex: any = FinalArgLabors.findIndex((FinalArgPart: any) => {
464
+ return FinalArgPart._id === argLabor._id;
465
+ });
466
+ if (PartIndex !== -1) {
467
+ PartFound = true;
468
+ }
469
+ });
470
+
471
+ // let argGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(argLabor.TCode, TaxCodes);
472
+ // let argCGST = argGSTValues[0];
473
+ // let argSGST = argGSTValues[1];
474
+ // let argIGST = argGSTValues[2];
475
+
476
+ // let laborGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(Labor.TCode, TaxCodes);
477
+ // let laborCGST = laborGSTValues[0];
478
+ // let laborSGST = laborGSTValues[1];
479
+ // let laborIGST = laborGSTValues[2];
480
+ return (!PartFound) &&
481
+ (argLabor.CGSTAmt === Labor.CGSTAmt) && (argLabor.IGSTAmt === Labor.IGSTAmt) &&
482
+ (argLabor.SGSTAmt === Labor.SGSTAmt);
483
+ });
484
+ if (MatchedLaborsBasedOnPerc.length !== 0) {
485
+ FinalMatchedLabors.push(MatchedLaborsBasedOnPerc);
486
+ }
487
+ });
488
+ return FinalMatchedLabors;
489
+ }
490
+
491
+ static ComparePartsByPerc(Parts: any, TaxCodes: any) {
492
+ let FinalMatchedParts: any[] = [];
493
+ Parts?.forEach((Part: any) => {
494
+ let MatchedPartsBasedOnHSN = Parts.filter((argPart: any) => {
495
+ let PartFound: boolean = false;
496
+ FinalMatchedParts.forEach((FinalArgParts: any) => {
497
+ let PartIndex: any = FinalArgParts.findIndex((FinalArgPart: any) => {
498
+ return FinalArgPart._id === argPart._id;
499
+ });
500
+ if (PartIndex !== -1) {
501
+ PartFound = true;
502
+ }
503
+ });
504
+
505
+ // let argGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(argPart.TCode, TaxCodes);
506
+ // let argCGST = argGSTValues[0];
507
+ // let argSGST = argGSTValues[1];
508
+ // let argIGST = argGSTValues[2];
509
+
510
+ // let partGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(Part.TCode, TaxCodes);
511
+ // let partCGST = partGSTValues[0];
512
+ // let partSGST = partGSTValues[1];
513
+ // let partIGST = partGSTValues[2];
514
+
515
+ return (!PartFound) &&
516
+ (argPart.CGSTAmt === Part.CGSTAmt) && (argPart.IGSTAmt === Part.IGSTAmt) &&
517
+ (argPart.SGSTAmt === Part.SGSTAmt);
518
+ });
519
+ if (MatchedPartsBasedOnHSN.length !== 0) {
520
+ FinalMatchedParts.push(MatchedPartsBasedOnHSN);
521
+ }
522
+ });
523
+ return FinalMatchedParts;
524
+ }
525
+
526
+ static GetLaborDiscountedTotal(LaborList: any, isTaxable: boolean, finalTotalsData: any) {
527
+ let LaborDiscountedTotal: any = 0;
528
+ let overallLaborDisc: number = 0;
529
+ // if (!isTaxable) {
530
+ // overallLaborDisc = TrUtils.SetValueToZeroIfNull(finalTotalsData.LDisc)
531
+ // } else {
532
+ LaborList.forEach((Labor: any) => {
533
+ LaborDiscountedTotal = Add(LaborDiscountedTotal, Labor.DiscountedPrice);
534
+ });
535
+ // }
536
+
537
+ return Add(LaborDiscountedTotal, overallLaborDisc);
538
+ }
539
+
540
+ static GetPartDiscountedTotal(PartsList: any, isTaxable: boolean, finalTotalsData: any) {
541
+ let PartsDiscountedTotal: any = 0;
542
+ let RetPartsDiscountedTotal: any = 0;
543
+ let overallPartDisc: number = 0;
544
+ // if (!isTaxable) {
545
+ // overallPartDisc = TrUtils.SetValueToZeroIfNull(finalTotalsData.PDisc)
546
+ // } else {
547
+ PartsList.forEach((Part: any) => {
548
+ if (Part.Ret === true) {
549
+ RetPartsDiscountedTotal = Add(RetPartsDiscountedTotal, Part.DiscountedPrice);
550
+ } else {
551
+ PartsDiscountedTotal = Add(PartsDiscountedTotal, Part.DiscountedPrice);
552
+ }
553
+ });
554
+ // }
555
+
556
+ return Add(Subtract(PartsDiscountedTotal, RetPartsDiscountedTotal), overallPartDisc);
557
+ }
558
+
559
+ static GetLaborTaxTotalFor(opCodesList: any, IsIndependentTax: boolean) {
560
+ let TotalTaxAmt: any = 0;
561
+ if (IsIndependentTax) {
562
+ opCodesList.forEach((Labor: any) => {
563
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CGST, Labor.SGST, Labor.IGST);
564
+ });
565
+ }
566
+ return TotalTaxAmt;
567
+ }
568
+
569
+ static GetPartsTaxTotalFor(PartsList: any, IsIndependentTax: boolean) {
570
+ let TotalTaxAmt: any = 0;
571
+ let RetTotalTaxAmt: any = 0;
572
+ if (IsIndependentTax) {
573
+ PartsList.forEach((Part: any) => {
574
+ if (Part.Ret === true) {
575
+ RetTotalTaxAmt = Add(RetTotalTaxAmt, Part.CGST, Part.SGST, Part.IGST);
576
+ } else {
577
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CGST, Part.SGST, Part.IGST);
578
+ }
579
+ });
580
+ }
581
+ return Subtract(TotalTaxAmt, RetTotalTaxAmt);
582
+ }
583
+
584
+ static GetRetPartsTaxTotalFor(PartsList: any, IsIndependentTax: boolean) {
585
+ let RetTotalTaxAmt: any = 0;
586
+ if (IsIndependentTax) {
587
+ PartsList.forEach((Part: any) => {
588
+ if (Part.Ret === true) {
589
+ RetTotalTaxAmt = Add(RetTotalTaxAmt, Part.CGST, Part.SGST, Part.IGST);
590
+ }
591
+ });
592
+ }
593
+ return RetTotalTaxAmt;
594
+ }
595
+
596
+ static GetNonRetPartsTaxTotalFor(PartsList: any, IsIndependentTax: boolean) {
597
+ let NonRetTotalTaxAmt: any = 0;
598
+ if (IsIndependentTax) {
599
+ PartsList.forEach((Part: any) => {
600
+ if (TrUtils.IsNull(Part.Ret) || Part.Ret === false) {
601
+ NonRetTotalTaxAmt = Add(NonRetTotalTaxAmt, Part.CGST, Part.SGST, Part.IGST);
602
+ }
603
+ });
604
+ }
605
+ return NonRetTotalTaxAmt;
606
+ }
607
+
608
+ static GetCustomerTotalBasedOnTaxType(finalTotalsData: any, LaborTaxAmount: number, PartsTaxAmount: number
609
+ , LaborList: any, PartsList: any,
610
+ IsIndependentTax: boolean, Adjust: any) {
611
+ let LaborTotalAfterDisc: any = this.GetLaborTotalAfterDiscount(LaborList);
612
+ let PartsTotalAfterDisc: any = this.GetPartsTotalAfterDiscount(PartsList);
613
+ if (IsIndependentTax) {
614
+ return Add(LaborTotalAfterDisc, PartsTotalAfterDisc, LaborTaxAmount, PartsTaxAmount, Adjust);
615
+ } else {
616
+ return Add(LaborTotalAfterDisc, PartsTotalAfterDisc, Adjust);
617
+ }
618
+ }
619
+
620
+ static GetRetLaborTotalAfterDiscount(LaborList: any) {
621
+ return 0;
622
+ }
623
+
624
+ static GetRetCustomerTotalBasedOnTaxType(finalTotalsData: any, LaborTaxAmount: number, PartsTaxAmount: number
625
+ , LaborList: any, PartsList: any,
626
+ IsIndependentTax: boolean, Adjust: any, DecimalsNumber: any) {
627
+ LaborTaxAmount = 0;
628
+ let LaborTotalAfterDisc: any = this.GetRetLaborTotalAfterDiscount(LaborList);
629
+ let PartsTotalAfterDisc: any = this.GetRetPartsTotalAfterDiscount(PartsList);
630
+ if (IsIndependentTax) {
631
+ return Add(LaborTotalAfterDisc, PartsTotalAfterDisc, LaborTaxAmount, PartsTaxAmount);
632
+ } else {
633
+ return TrUtils.FixedTo(Add(LaborTotalAfterDisc, PartsTotalAfterDisc), DecimalsNumber);
634
+ }
635
+ }
636
+
637
+ static GetNonRetCustomerTotalBasedOnTaxType(finalTotalsData: any, LaborTaxAmount: number, PartsTaxAmount: number
638
+ , LaborList: any, PartsList: any,
639
+ IsIndependentTax: boolean, Adjust: any, DecimalsNumber: any) {
640
+ let LaborTotalAfterDisc: any = this.GetLaborTotalAfterDiscount(LaborList);
641
+ let PartsTotalAfterDisc: any = this.GetNonRetPartsTotalAfterDiscount(PartsList);
642
+ if (IsIndependentTax) {
643
+ return Add(LaborTotalAfterDisc, PartsTotalAfterDisc, LaborTaxAmount, PartsTaxAmount);
644
+ } else {
645
+ return TrUtils.FixedTo(Add(LaborTotalAfterDisc, PartsTotalAfterDisc), DecimalsNumber);
646
+ }
647
+ }
648
+
649
+ static LaborTotalAfterDiscount(LaborTotalAfterDisc: number, LaborTaxAmount: number, MainLDisc: number, LDiscInPerc: string) {
650
+ let LaborTotal: number = Add(LaborTotalAfterDisc, LaborTaxAmount);
651
+ if (!TrUtils.IsZero(MainLDisc)) {
652
+ if (!TrUtils.IsEmpty(LDiscInPerc)) {
653
+ LaborTotal = Subtract(LaborTotal, Divide(Multiply(LaborTotal, Number(LDiscInPerc)), 100));
654
+ } else {
655
+ LaborTotal = Subtract(LaborTotal, MainLDisc);
656
+ }
657
+ }
658
+ return LaborTotal;
659
+ }
660
+
661
+ static ItemsTotalAfterDiscount(PartsTotalAfterDisc: number, PartsTaxAmount: number, MainPDisc: number, PDiscInPerc: string) {
662
+ let ItemsTotal: number = Add(PartsTotalAfterDisc, PartsTaxAmount);
663
+ if (!TrUtils.IsZero(MainPDisc)) {
664
+ if (!TrUtils.IsEmpty(PDiscInPerc)) {
665
+ ItemsTotal = Subtract(ItemsTotal, Divide(Multiply(ItemsTotal, Number(PDiscInPerc)), 100));
666
+ } else {
667
+ ItemsTotal = Subtract(ItemsTotal, MainPDisc);
668
+ }
669
+ }
670
+ return ItemsTotal;
671
+ }
672
+
673
+ static GetLaborGSTTaxTotal(opCodesList: any, IsIndependentTax: boolean) {
674
+ let TotalCGSTAmt: number = 0;
675
+ let TotalSGSTAmt: number = 0;
676
+ let TotalIGSTAmt: number = 0;
677
+ let TotalTaxAmt: number = 0;
678
+ if (IsIndependentTax) {
679
+ opCodesList.forEach((Labor: any) => {
680
+ TotalCGSTAmt = Add(TotalCGSTAmt, Labor.CGST);
681
+ TotalSGSTAmt = Add(TotalSGSTAmt, Labor.SGST);
682
+ TotalIGSTAmt = Add(TotalIGSTAmt, Labor.IGST);
683
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CGST, Labor.SGST, Labor.IGST);
684
+ });
685
+ }
686
+ return [TotalCGSTAmt, TotalSGSTAmt, TotalIGSTAmt, TotalTaxAmt];
687
+ }
688
+
689
+ static GetPartGSTTaxTotal(PartsList: any, IsIndependentTax: boolean) {
690
+ let TotalCGSTAmt: number = 0;
691
+ let RetTotalCGSTAmt: number = 0;
692
+ let RetTotalIGSTAmt: number = 0;
693
+ let TotalIGSTAmt: number = 0;
694
+ let TotalSGSTAmt: number = 0;
695
+ let RetTotalSGSTAmt: number = 0;
696
+ if (IsIndependentTax) {
697
+ PartsList.forEach((Part: any) => {
698
+ if (Part.Ret === true) {
699
+ RetTotalCGSTAmt = Add(RetTotalCGSTAmt, Part.CGST);
700
+ RetTotalSGSTAmt = Add(RetTotalSGSTAmt, Part.SGST);
701
+ RetTotalIGSTAmt = Add(RetTotalIGSTAmt, Part.IGST);
702
+ } else {
703
+ TotalCGSTAmt = Add(TotalCGSTAmt, Part.CGST);
704
+ TotalSGSTAmt = Add(TotalSGSTAmt, Part.SGST);
705
+ TotalIGSTAmt = Add(TotalIGSTAmt, Part.IGST);
706
+ }
707
+ });
708
+ }
709
+ return [TotalCGSTAmt, TotalSGSTAmt, TotalIGSTAmt];
710
+ }
711
+
712
+ static GetTaxGroupingForPartsByHSN(Parts: any, TaxCodes: any, DecimalsNumber: any) {
713
+ Parts = this.GetCombinedTaxPercentage(TrUtils.Stringify(Parts), TaxCodes);
714
+ // Parts = this.ResetPartsHSNIfInvalid(Parts);
715
+ let FinalMatchedParts: any[] = this.ComparePartsByHSN(Parts, TaxCodes);
716
+ return this.GetTaxGroupingInfoByHSN(FinalMatchedParts, TaxCodes, DecimalsNumber);
717
+ }
718
+
719
+ static GetCombinedTaxPercentage(Parts: any, TaxCodes: any) {
720
+ Parts.forEach((Part: any) => {
721
+ if (TrUtils.IsNull(Part.HSN)) {
722
+ Part.HSN = '';
723
+ }
724
+ Part.CGSTAmt = TrUtils.SetValueToZeroIfNull(this.GetTaxRateFromTaxes(Part, 'CGST'));
725
+ Part.SGSTAmt = TrUtils.SetValueToZeroIfNull(this.GetTaxRateFromTaxes(Part, 'SGST'));
726
+ Part.IGSTAmt = TrUtils.SetValueToZeroIfNull(this.GetTaxRateFromTaxes(Part, 'IGST'));
727
+
728
+ Part.CombinedTaxPercentage = Add(Part.CGSTAmt, Part.SGSTAmt, Part.IGSTAmt);
729
+ });
730
+ return Parts;
731
+ }
732
+
733
+ static ComparePartsByHSN(Parts: any, TaxCodes: any) {
734
+ let FinalMatchedParts: any[] = [];
735
+ Parts.forEach((Part: any) => {
736
+ let MatchedPartsBasedOnHSN = Parts.filter((argPart: any) => {
737
+ let PartFound: boolean = false;
738
+ FinalMatchedParts.forEach((FinalArgParts: any) => {
739
+ let PartIndex: any = FinalArgParts.findIndex((FinalArgPart: any) => {
740
+ return FinalArgPart._id === argPart._id;
741
+ });
742
+ if (PartIndex !== -1) {
743
+ PartFound = true;
744
+ }
745
+ });
746
+
747
+ // let argGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(argPart.TCode, TaxCodes);
748
+ // let argCGST = argGSTValues[0];
749
+ // let argSGST = argGSTValues[1];
750
+ // let argIGST = argGSTValues[2];
751
+
752
+ // let partGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(Part.TCode, TaxCodes);
753
+ // let partCGST = partGSTValues[0];
754
+ // let partSGST = partGSTValues[1];
755
+ // let partIGST = partGSTValues[2];
756
+
757
+ return (argPart.HSN === Part.HSN) && (!PartFound) &&
758
+ (argPart.CGSTAmt === Part.CGSTAmt) && (argPart.IGSTAmt === Part.IGSTAmt) &&
759
+ (argPart.SGSTAmt === Part.SGSTAmt);
760
+ });
761
+ if (MatchedPartsBasedOnHSN.length !== 0) {
762
+ FinalMatchedParts.push(MatchedPartsBasedOnHSN);
763
+ }
764
+ });
765
+ return FinalMatchedParts;
766
+ }
767
+
768
+ static GetTaxGroupingInfoByHSN(FinalMatchedParts: any, TaxCodes: any, DecimalsNumber: any) {
769
+ let HSNTaxInfo: any[] = [];
770
+ FinalMatchedParts.forEach((MatchedPart: any) => {
771
+ let TaxInfo: any = {};
772
+ let TaxOnAmount: any = 0;
773
+ let TaxAmount: any = 0;
774
+
775
+ let CGSTAmt: any = 0;
776
+ let SGSTAmt: any = 0;
777
+ let IGSTAmt: any = 0;
778
+
779
+ let HSN: any = MatchedPart[0].HSN;
780
+ TaxInfo.CombinedTaxPercentage = MatchedPart[0].CombinedTaxPercentage;
781
+ MatchedPart.forEach((argMatchedGSTPart: any) => {
782
+ TaxOnAmount = Add(TaxOnAmount, TrUtils.FixedTo(argMatchedGSTPart.AfterPartDisc, DecimalsNumber));
783
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CGST, DecimalsNumber));
784
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.IGST, DecimalsNumber));
785
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.SGST, DecimalsNumber));
786
+ CGSTAmt = Add(CGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.CGST, DecimalsNumber));
787
+ SGSTAmt = Add(SGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.SGST, DecimalsNumber));
788
+ IGSTAmt = Add(IGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.IGST, DecimalsNumber));
789
+ });
790
+ TaxInfo.HSN = HSN;
791
+
792
+ TaxInfo.CGSTAmt = CGSTAmt;
793
+ TaxInfo.SGSTAmt = SGSTAmt;
794
+ TaxInfo.IGSTAmt = IGSTAmt;
795
+
796
+ TaxInfo.TotalTaxableAmount = TrUtils.FixPriceValue(TaxOnAmount, DecimalsNumber);
797
+ TaxInfo.TotalTaxAmount = TrUtils.FixPriceValue(TaxAmount, DecimalsNumber);
798
+ TaxInfo.ItemsCount = MatchedPart.length;
799
+ // let GSTValues: any[] = this.GetGSTValueBasedOnTaxCode(MatchedPart[0].TCode, TaxCodes);
800
+ // TaxInfo.CGST = GSTValues[0];
801
+ // TaxInfo.SGST = GSTValues[1];
802
+ // TaxInfo.IGST = GSTValues[2];
803
+ TaxInfo.CGST = MatchedPart[0].CGSTAmt;
804
+ TaxInfo.IGST = MatchedPart[0].IGSTAmt;
805
+ TaxInfo.SGST = MatchedPart[0].SGSTAmt;
806
+ if (TaxOnAmount !== 0) {
807
+ HSNTaxInfo.push(TaxInfo);
808
+ }
809
+ });
810
+ return HSNTaxInfo;
811
+ }
812
+
813
+ static GetGSTValueBasedOnTaxCode(TCode: any, TaxCodes: any) {
814
+ let CGST: number = 0;
815
+ let SGST: number = 0;
816
+ let IGST: number = 0;
817
+ if (TrUtils.IsNull(TCode)) {
818
+ return [CGST, SGST, IGST];
819
+ }
820
+ let TCodeIndex: any = TaxCodes.findIndex((TaxCode: any) => {
821
+ return TaxCode._id === Number(TCode);
822
+ });
823
+ if (TCodeIndex !== -1) {
824
+ if (TaxCodes[TCodeIndex].Type === 'Intra') {
825
+ return [TaxCodes[TCodeIndex].CGST, TaxCodes[TCodeIndex].SGST, 0];
826
+ } else {
827
+ return [0, 0, TaxCodes[TCodeIndex].IGST];
828
+ }
829
+ } else {
830
+ return [CGST, SGST, IGST];
831
+ }
832
+ }
833
+
834
+ }