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,637 @@
1
+ import { POPartStatusEnum } from "../../enums/code-enums";
2
+ import { Add, Multiply, Subtract } from "../../shared/math-operations";
3
+ import { TrUtils } from "../../utils/tr-utils";
4
+
5
+
6
+
7
+
8
+ export class PurchaseOrderTotalsService {
9
+
10
+ static GetTaxAmountFromTaxes(item: any, taxCode: string) {
11
+ const taxes = Array.isArray(item?.Taxes) ? item.Taxes : [];
12
+ const matchedTaxes = taxes.filter((tax: any) => tax?.Code === taxCode);
13
+ if (matchedTaxes.length !== 0) {
14
+ return matchedTaxes.reduce((total: number, tax: any) => Add(total, tax?.Amt), 0);
15
+ }
16
+ return 0;
17
+ }
18
+
19
+ static GetTaxRateFromTaxes(item: any, taxCode: string) {
20
+ const taxes = Array.isArray(item?.Taxes) ? item.Taxes : [];
21
+ const matchedTaxes = taxes.filter((tax: any) => tax?.Code === taxCode);
22
+ if (matchedTaxes.length !== 0) {
23
+ return matchedTaxes.reduce((total: number, tax: any) => Add(total, tax?.Rate), 0);
24
+ }
25
+ return 0;
26
+ }
27
+
28
+ static GetTCodeFromTaxes(item: any) {
29
+ const taxes = Array.isArray(item?.Taxes) ? item.Taxes : [];
30
+ const matchedTax = taxes.find((tax: any) => !TrUtils.IsNull(tax?.TaxCodeId));
31
+ if (!TrUtils.IsNull(matchedTax?.TaxCodeId)) {
32
+ return matchedTax.TaxCodeId;
33
+ }
34
+ return item?.TCode;
35
+ }
36
+
37
+ static GetTotalsValue(opCodesList: any, argPartsList: any, IsTaxable: boolean, DetailedTotalsInfo: boolean,
38
+ TaxCodes: any, Tax: any, ReturnPartsAlso: boolean, HasNoTax: boolean, GetSubTotal: boolean, Discount: number, DiscInPerc: boolean, Adjust: number, EntitySettings: any) {
39
+ let PartsList: any[] = TrUtils.IsNull(argPartsList) ? [] : TrUtils.Stringify(argPartsList);
40
+
41
+ // PartsList = this.ResetPartValuesIfInvalid(PartsList);
42
+
43
+ // PartsList = this.GetPartsDiscountPrice(PartsList);
44
+
45
+ // PartsList = this.GetPartsAfterDiscount(PartsList);
46
+
47
+ if (TrUtils.IsNull(opCodesList)) {
48
+ opCodesList = [];
49
+ }
50
+
51
+ opCodesList = this.CalculateLaborValues(opCodesList, IsTaxable, EntitySettings.DecimalsNumber);
52
+
53
+ PartsList = this.GetPartsTaxAmount(PartsList, IsTaxable, TaxCodes, EntitySettings.DecimalsNumber);
54
+
55
+ // PartsList = this.GetPartsAfterTax(PartsList);
56
+
57
+ let finalTotalsData: any = this.GetTotalsInfo(PartsList, opCodesList, IsTaxable, TaxCodes, HasNoTax, GetSubTotal, Discount, DiscInPerc, Adjust, EntitySettings.DecimalsNumber);
58
+
59
+ if (ReturnPartsAlso) {
60
+ finalTotalsData.Ops = opCodesList;
61
+ finalTotalsData.Items = PartsList;
62
+ }
63
+
64
+ if (DetailedTotalsInfo === true) {
65
+ finalTotalsData = this.GetDetailedTotalsData(finalTotalsData, IsTaxable, PartsList, opCodesList, TaxCodes, Tax, HasNoTax, EntitySettings.DecimalsNumber);
66
+ }
67
+
68
+ return finalTotalsData;
69
+ }
70
+
71
+ static CalculateLaborValues(opCodesList: any, IsIndependentTax: boolean, DecimalsNumber: number) {
72
+ opCodesList = this.ResetLaborValues(opCodesList, IsIndependentTax, DecimalsNumber);
73
+
74
+ // opCodesList = this.GetOperationsDiscountPrice(opCodesList);
75
+
76
+ // opCodesList = this.GetOperationsAfterDiscount(opCodesList,IsIndependentTax);
77
+
78
+ // opCodesList = this.GetOperationsAfterTax(opCodesList, IsIndependentTax);
79
+
80
+ return opCodesList;
81
+ }
82
+
83
+ static ResetLaborValues(opCodesList: any, IsIndependentTax: boolean, DecimalsNumber: number) {
84
+ opCodesList.forEach((Operation: any) => {
85
+ Operation = this.ResetLaborValueIfInvalid(Operation);
86
+ Operation.DiscountedPrice = Add(Operation.Disc, Operation.RecDisc);
87
+ if (TrUtils.IsNull(Operation.Amt)) {
88
+ Operation.Amt = Operation.UnCo;
89
+ }
90
+ Operation.GSTAmt = Add(Operation.SGST, Operation.CGST, Operation.IGST);
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);
97
+ Operation.AfterLaborTax = Operation.AfterLaborDisc;
98
+ }
99
+ let Price: any = 0;
100
+ Price = Multiply(Operation.UnCo, Operation.Qty)
101
+ if (IsIndependentTax) {
102
+ Operation.LineTotal = TrUtils.FixedTo(Add(Subtract(Price, Operation.Disc), Operation.GSTAmt), DecimalsNumber);
103
+
104
+ } else {
105
+ Operation.LineTotal = TrUtils.FixedTo(Subtract(Price, Operation.Disc), DecimalsNumber);
106
+ }
107
+ });
108
+ return opCodesList;
109
+ }
110
+
111
+ static ResetLaborValueIfInvalid(Operation: any) {
112
+ Operation.UnCo = TrUtils.SetValueToZeroIfNull(Operation.UnCo);
113
+ Operation.RecDisc = TrUtils.SetValueToZeroIfNull(Operation.RecDisc);
114
+ Operation.Disc = TrUtils.SetValueToZeroIfNull(Operation.Disc);
115
+ Operation.CGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Operation, 'CGST') || Operation.CGST);
116
+ Operation.SGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Operation, 'SGST') || Operation.SGST);
117
+ Operation.IGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Operation, 'IGST') || Operation.IGST);
118
+ Operation.TCode = this.GetTCodeFromTaxes(Operation);
119
+ return Operation;
120
+ }
121
+
122
+ static CheckPartStatusAndReturn(PartsList: any) {
123
+ PartsList = PartsList.filter((Part: any) => {
124
+ return Part.Sts !== POPartStatusEnum.Del && Part.Sts !== POPartStatusEnum.Deleted;
125
+ });
126
+ return PartsList;
127
+ }
128
+
129
+ static ResetPartValueIfInvalid(Part: any) {
130
+ // if (TrUtils.IsNull(Part.Ind)) {
131
+ if (TrUtils.IsNull(Part.UnCo)) {
132
+ Part.UnCo = TrUtils.SetValueToZeroIfNull(Part.UnPr);
133
+ }
134
+ Part.UnCo = TrUtils.SetValueToZeroIfNull(Part.UnCo);
135
+ Part.Disc = TrUtils.SetValueToZeroIfNull(Part.Disc);
136
+ Part.SGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Part, 'SGST') || Part.SGST);
137
+ Part.IGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Part, 'IGST') || Part.IGST);
138
+ Part.CGST = TrUtils.SetValueToZeroIfNull(this.GetTaxAmountFromTaxes(Part, 'CGST') || Part.CGST);
139
+ Part.TCode = this.GetTCodeFromTaxes(Part);
140
+ // }
141
+ return Part;
142
+ }
143
+
144
+ static GetPartDiscountedPrice(Disc: any, RecDisc: any) {
145
+ // if (DiscInPerc) {
146
+ // return TrUtils.FixedTo(((Price * Qty) * Disc) / 100);
147
+ // } else {
148
+ return Add(Disc, TrUtils.SetValueToZeroIfNull(RecDisc));
149
+ // }
150
+ }
151
+
152
+ static GetPartsTaxAmount(Items: any, IsTaxable: boolean, TaxCodes: any, DecimalsNumber: number) {
153
+ Items.forEach((Part: any) => {
154
+ Part = this.ResetPartValueIfInvalid(Part);
155
+ // Part.CGSTAmt = this.GetCGSTTaxAmount(Part.AfterDiscountPrice, IsTaxable, Part.TCode, TaxCodes);
156
+ // Part.IGSTAmt = this.GetIGSTTaxAmount(Part.AfterDiscountPrice, IsTaxable, Part.TCode, TaxCodes);
157
+ // Part.SGSTAmt = this.GetSGSTTaxAmount(Part.AfterDiscountPrice, IsTaxable, Part.TCode, TaxCodes);
158
+ if (TrUtils.IsNull(Part.Ind)) {
159
+ Part.DiscountedPrice = this.GetPartDiscountedPrice(Part.Disc, Part.RecDisc);
160
+ // Part.AfterDiscountPrice = Part.NetAmt;
161
+ Part.AfterDiscountPrice = Subtract(Part.UnAmt, Part.Disc, Part.RecDisc);
162
+ }
163
+ Part.GSTAmt = Add(Part.SGST, Part.CGST, Part.IGST);
164
+ Part.Desc = Part.Name;
165
+ let Price: any = 0;
166
+ if (IsTaxable) {
167
+ // if (!TrUtils(Part.Perc)) {
168
+ Price = Multiply(Part.UnCo, Part.Qty)
169
+ Part.LineTotal = TrUtils.FixedTo(Add(Subtract(Price, Part.Disc), Part.GSTAmt), DecimalsNumber);
170
+ // } else {
171
+ // Part.LineTotal = TrUtils.FixedTo((Part.UnPr - Part.Disc) + Part.GSTAmt);
172
+ // }
173
+ } else {
174
+ // let DiscPrice: any = 0;
175
+ // if (Part.Perc) {
176
+ Price = Multiply(Part.UnCo, Part.Qty)
177
+ Part.LineTotal = TrUtils.FixedTo(Subtract(Price, Part.Disc), DecimalsNumber);
178
+ // } else {
179
+ // Part.LineTotal = TrUtils.FixedTo((Part.UnPr - Part.Disc));
180
+ // }
181
+ }
182
+ Part.AfterTax = Add(Part.AfterDiscountPrice, Part.GSTAmt);
183
+ });
184
+ return Items;
185
+ }
186
+
187
+ static GetGSTValueBasedOnTaxCode(TCode: any, argTaxCodes: any) {
188
+ if (TrUtils.IsNull(TCode)) {
189
+ return [0, 0, 0];
190
+ }
191
+ let TaxCodes: any = TrUtils.Stringify(argTaxCodes);
192
+ let TCodeIndex: any = TaxCodes.findIndex((TaxCode: any) => {
193
+ return TaxCode._id === Number(TCode);
194
+ });
195
+ if (TCodeIndex !== -1) {
196
+ // // if (TrUtils.IsNull(TaxCodes[TCodeIndex].CGST)) {
197
+ // // return 0;
198
+ // // } else {
199
+ // return [TaxCodes[TCodeIndex].CGST, TaxCodes[TCodeIndex].SGST, TaxCodes[TCodeIndex].IGST];
200
+ // // }
201
+ if (TaxCodes[TCodeIndex].Type === 'Intra') {
202
+ return [TaxCodes[TCodeIndex].CGST, TaxCodes[TCodeIndex].SGST, 0];
203
+ } else {
204
+ return [0, 0, TaxCodes[TCodeIndex].IGST];
205
+ }
206
+ } else {
207
+ return [0, 0, 0];
208
+ }
209
+ }
210
+
211
+ static GetTotalsInfo(PartsList: any, LaborList: any, IsTaxable: boolean, TaxCodes: any, HasNoTax: boolean, GetSubTotal: boolean, Discount: number, DiscInPerc: boolean, Adjust: number, DecimalsNumber: number) {
212
+
213
+ let finalTotalsData: any = {};
214
+ let PartsInfo: any = this.GetPartsTotalTaxAndAfterDiscount(PartsList);
215
+ let PartsTotalAfterDisc: any = TrUtils.SetValueToZeroIfNull(PartsInfo[0]);
216
+ let PartsDiscTotal = TrUtils.SetValueToZeroIfNull(PartsInfo[1]);
217
+
218
+ let PartsTaxTotal = TrUtils.SetValueToZeroIfNull(PartsInfo[2]);
219
+
220
+ let ServicesInfo: any = this.GetServiceTotalTaxAndAfterDiscount(LaborList);
221
+ let ServicesTotalAfterDisc: any = TrUtils.SetValueToZeroIfNull(ServicesInfo[0]);
222
+ let ServicesDiscTotal = TrUtils.SetValueToZeroIfNull(ServicesInfo[1]);
223
+
224
+ let ServicesTaxTotal: any = TrUtils.SetValueToZeroIfNull(ServicesInfo[2]);
225
+ finalTotalsData.SubTotal = Add(PartsTotalAfterDisc, PartsDiscTotal, ServicesTotalAfterDisc, ServicesDiscTotal);
226
+ finalTotalsData.Adj = TrUtils.FixPriceValue(Adjust, DecimalsNumber);
227
+ // if (GetSubTotal) {
228
+ // finalTotalsData.SubTotal = this.GetTotalBasedOnTaxType(PartsTotalAfterDisc, PartsTaxTotal,
229
+ // IsTaxable);
230
+ // let Total: number = finalTotalsData.SubTotal;
231
+ // if (HasNoTax && !TrUtils.IsNull(Discount)) {
232
+ // if (DiscInPerc) {
233
+ // Total = TrUtils.FixedTo(((finalTotalsData.SubTotal) -
234
+ // ((finalTotalsData.SubTotal) * Discount) / 100));
235
+ // } else {
236
+ // Total = TrUtils.FixedTo((finalTotalsData.SubTotal) - Discount);
237
+ // }
238
+ // }
239
+ // finalTotalsData.Total = Total;
240
+ // } else {
241
+ finalTotalsData.Total = this.GetTotalBasedOnTaxType(PartsTotalAfterDisc, PartsTaxTotal, ServicesTotalAfterDisc, ServicesTaxTotal,
242
+ IsTaxable, Adjust, DecimalsNumber);
243
+ // }
244
+ // finalTotalsData.Round = TrUtils.FixedTo(Math.round(finalTotalsData.Total) - finalTotalsData.Total);
245
+
246
+ // finalTotalsData.Total = Math.round(finalTotalsData.Total);
247
+ return finalTotalsData;
248
+ }
249
+
250
+ static GetServiceTotalTaxAndAfterDiscount(LaborList: any) {
251
+ let ServicesTotalAfterDisc: any = 0;
252
+ let ServicesDiscountedTotal: number = 0;
253
+ let TotalTaxAmt: number = 0;
254
+ LaborList.forEach((Part: any) => {
255
+ ServicesTotalAfterDisc = Add(ServicesTotalAfterDisc, Part.AfterLaborDisc);
256
+ ServicesDiscountedTotal = Add(ServicesDiscountedTotal, Part.DiscountedPrice);
257
+ TotalTaxAmt = Add(TotalTaxAmt, Part.GSTAmt);
258
+ });
259
+ return [ServicesTotalAfterDisc, ServicesDiscountedTotal, TotalTaxAmt];
260
+ }
261
+
262
+ static GetPartsTotalTaxAndAfterDiscount(PartsList: any) {
263
+ let PartsTotalAfterDisc: any = 0;
264
+ let PartsDiscountedTotal: number = 0;
265
+ let TotalTaxAmt: number = 0;
266
+ PartsList.forEach((Part: any) => {
267
+ PartsTotalAfterDisc = Add(PartsTotalAfterDisc, Part.AfterDiscountPrice);
268
+ PartsDiscountedTotal = Add(PartsDiscountedTotal, Part.DiscountedPrice);
269
+ TotalTaxAmt = Add(TotalTaxAmt, Part.GSTAmt);
270
+ });
271
+ return [PartsTotalAfterDisc, PartsDiscountedTotal, TotalTaxAmt];
272
+ }
273
+
274
+ static GetTotalBasedOnTaxType(PartsTotalAfterDisc: number, PartsTaxAmount: number,
275
+ ServicesTotalAfterDisc: number, ServicesTaxTotal: number, IsTaxable: boolean, Adjust: number, DecimalsNumber: number) {
276
+
277
+ let Total: number = 0;
278
+
279
+ if (IsTaxable) {
280
+ Total = Add(PartsTotalAfterDisc, PartsTaxAmount, ServicesTotalAfterDisc, ServicesTaxTotal);
281
+ } else {
282
+ Total = Add(PartsTotalAfterDisc, ServicesTotalAfterDisc);
283
+ }
284
+
285
+ let finalTotal: any = Add(Total, TrUtils.SetValueToZeroIfNull(Adjust));
286
+ return TrUtils.FixedTo(finalTotal, DecimalsNumber);
287
+ }
288
+
289
+ static GetDetailedTotalsData(finalTotalsData: any, IsTaxable: boolean, PartsList: any, LaborList: any, TaxCodes: any, Tax: any, HasNoTax: boolean, DecimalsNumber: number) {
290
+ let PartsInfo: any = this.GetPartsTotalTaxAndAfterDiscount(PartsList);
291
+ let ServicesInfo: any = this.GetServiceTotalTaxAndAfterDiscount(LaborList);
292
+
293
+ finalTotalsData.PartsDiscTotal = TrUtils.SetValueToZeroIfNull(PartsInfo[1]);
294
+
295
+ finalTotalsData.PartsTotalAfterDisc = TrUtils.SetValueToZeroIfNull(PartsInfo[0]);
296
+
297
+ finalTotalsData.PartsTotalBeforeDisc = Add(finalTotalsData.PartsTotalAfterDisc
298
+ , finalTotalsData.PartsDiscTotal);
299
+
300
+ // finalTotalsData.TaxTotal = this.GetPartsTaxTotal(PartsList);
301
+ finalTotalsData.TaxTotal = Add(TrUtils.SetValueToZeroIfNull(PartsInfo[2]), TrUtils.SetValueToZeroIfNull(ServicesInfo[2]));
302
+
303
+ finalTotalsData.ServiceTotalAfterDisc = TrUtils.SetValueToZeroIfNull(ServicesInfo[0]);
304
+ finalTotalsData.ServiceDiscTotal = TrUtils.SetValueToZeroIfNull(ServicesInfo[1]);
305
+
306
+ finalTotalsData.ServiceTaxTotal = TrUtils.SetValueToZeroIfNull(ServicesInfo[2]);
307
+
308
+ finalTotalsData.ServiceTotalBeforeDisc = Add(finalTotalsData.ServiceTotalAfterDisc
309
+ , finalTotalsData.ServiceDiscTotal);
310
+
311
+ let TaxAmt: any = this.GetPartGSTTaxTotal(PartsList);
312
+ // finalTotalsData.PartCGST = this.GetPartCGSTTaxTotal(PartsList);
313
+ // finalTotalsData.PartIGST = this.GetPartIGSTTaxTotal(PartsList);
314
+ // finalTotalsData.PartSGST = this.GetPartSGSTTaxTotal(PartsList);
315
+
316
+ finalTotalsData.PartCGST = TrUtils.SetValueToZeroIfNull(TaxAmt[0]);
317
+ finalTotalsData.PartSGST = TrUtils.SetValueToZeroIfNull(TaxAmt[1]);
318
+ finalTotalsData.PartIGST = TrUtils.SetValueToZeroIfNull(TaxAmt[2]);
319
+
320
+ let ServiceTaxAmt: any = this.GetServicesGSTTaxTotal(LaborList);
321
+ finalTotalsData.ServieCGST = TrUtils.SetValueToZeroIfNull(ServiceTaxAmt[0]);
322
+ finalTotalsData.ServieSGST = TrUtils.SetValueToZeroIfNull(ServiceTaxAmt[1]);
323
+ finalTotalsData.ServieIGST = TrUtils.SetValueToZeroIfNull(ServiceTaxAmt[2]);
324
+
325
+ finalTotalsData.PartAfterTax = Add(finalTotalsData.PartsTotalAfterDisc, finalTotalsData.TaxTotal);
326
+ finalTotalsData.ServiceAfterTax = Add(finalTotalsData.ServiceTotalAfterDisc, finalTotalsData.ServiceTaxTotal);
327
+
328
+ finalTotalsData.IsTaxable = IsTaxable;
329
+
330
+ finalTotalsData.Tax = Tax;
331
+
332
+ finalTotalsData.HasNoTax = HasNoTax;
333
+
334
+ finalTotalsData.TaxGroupData = this.GetPartsTaxGroupingFor(PartsList, TaxCodes, DecimalsNumber);
335
+ finalTotalsData.CustTaxGroupDataByPerc = this.GetTaxGroupingForPartsByPerc(PartsList, TaxCodes, DecimalsNumber);
336
+ finalTotalsData.CustLaborTaxGroupDataByPerc = this.GetTaxGroupingForLaborByPerc(LaborList, TaxCodes, DecimalsNumber);
337
+ finalTotalsData.TaxSummary = this.groupTaxData(finalTotalsData.CustTaxGroupData, finalTotalsData.CustLaborTaxGroupDataByPerc);
338
+
339
+
340
+ // finalTotalsData.TotalRoundedBy = TrUtils.FixedTo(Math.round(finalTotalsData.Total) - finalTotalsData.Total);
341
+
342
+ finalTotalsData.RoundedTotal = Math.round(finalTotalsData.Total);
343
+
344
+ // finalTotalsData.Round = TrUtils.FixedTo(Math.round(finalTotalsData.Total) - finalTotalsData.Total);
345
+
346
+ // finalTotalsData.Total = Math.round(finalTotalsData.Total);
347
+
348
+ return finalTotalsData;
349
+ }
350
+
351
+ static groupTaxData(
352
+ items: any[],
353
+ ops: any[]
354
+ ): any[] {
355
+ if (TrUtils.IsNull(items)) {
356
+ items = [];
357
+ }
358
+ if (TrUtils.IsNull(ops)) {
359
+ ops = [];
360
+ }
361
+ const combined = [...items, ...ops];
362
+
363
+ const groupedMap = new Map<number, { CombinedTaxPercentage: number; CGSTAmt: number; SGSTAmt: number; IGSTAmt?: number, TotalTaxAmount: number, TotalTaxableAmount: number }>();
364
+
365
+ combined.forEach(item => {
366
+ if (groupedMap.has(item.CombinedTaxPercentage)) {
367
+ const existing = groupedMap.get(item.CombinedTaxPercentage)!;
368
+ existing.CGSTAmt = Add(existing.CGSTAmt, item.CGSTAmt);
369
+ existing.SGSTAmt = Add(existing.SGSTAmt, item.SGSTAmt);
370
+
371
+ // Sum IGST if present
372
+ if (item.IGSTAmt !== undefined) {
373
+ existing.IGSTAmt = Add(existing.IGSTAmt || 0, item.IGSTAmt);
374
+ }
375
+
376
+ existing.TotalTaxAmount = Add(existing.TotalTaxAmount || 0, item.TotalTaxAmount || 0);
377
+ existing.TotalTaxableAmount = Add(existing.TotalTaxableAmount || 0, item.TotalTaxableAmount || 0);
378
+ } else {
379
+ // Clone the object to avoid mutation
380
+ groupedMap.set(item.CombinedTaxPercentage, { ...item });
381
+ }
382
+ });
383
+
384
+ return Array.from(groupedMap.values());
385
+ }
386
+
387
+ static GetTaxGroupingForLaborByPerc(opCodesList: any, TaxCodes: any, DecimalsNumber: any) {
388
+ opCodesList = this.GetCombinedTaxPercentage(TrUtils.Stringify(opCodesList), TaxCodes);
389
+ // opCodesList = this.ResetPartsHSNIfInvalid(opCodesList);
390
+
391
+ let FinalMatchedParts: any[] = this.CompareLaborByPerc(opCodesList, TaxCodes);
392
+
393
+ return this.GetTaxGroupingInfoBySAC(FinalMatchedParts, TaxCodes, DecimalsNumber);
394
+ }
395
+
396
+ static GetTaxGroupingForPartsByPerc(Parts: any, TaxCodes: any, DecimalsNumber: any) {
397
+ Parts = this.GetCombinedTaxPercentage(TrUtils.Stringify(Parts), TaxCodes);
398
+ // Parts = this.ResetPartsHSNIfInvalid(Parts);
399
+
400
+ let FinalMatchedParts: any[] = this.ComparePartsByPerc(Parts, TaxCodes);
401
+ return this.GetTaxGroupingInfoByHSN(FinalMatchedParts, TaxCodes, DecimalsNumber);
402
+ }
403
+
404
+ static GetTaxGroupingInfoBySAC(FinalMatchedLabors: any, TaxCodes: any, DecimalsNumber: any) {
405
+ let SACTaxInfo: any[] = [];
406
+ FinalMatchedLabors?.forEach((MatchedLabor: any) => {
407
+ let TaxInfo: any = {};
408
+ let TaxOnAmount: any = 0;
409
+ let TaxAmount: any = 0;
410
+ let CGSTAmt: any = 0;
411
+ let SGSTAmt: any = 0;
412
+ let IGSTAmt: any = 0;
413
+ let SAC: any = MatchedLabor[0].SAC;
414
+ TaxInfo.CombinedTaxPercentage = MatchedLabor[0].CombinedTaxPercentage;
415
+ MatchedLabor?.forEach((argMatchedGSTLabor: any) => {
416
+ TaxOnAmount = Add(TaxOnAmount, TrUtils.FixedTo(argMatchedGSTLabor.AfterLaborDisc, DecimalsNumber));
417
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTLabor.CGST, DecimalsNumber));
418
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTLabor.IGST, DecimalsNumber));
419
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTLabor.SGST, DecimalsNumber));
420
+ CGSTAmt = Add(CGSTAmt, TrUtils.FixedTo(argMatchedGSTLabor.CGST, DecimalsNumber));
421
+ SGSTAmt = Add(SGSTAmt, TrUtils.FixedTo(argMatchedGSTLabor.SGST, DecimalsNumber));
422
+ IGSTAmt = Add(IGSTAmt, TrUtils.FixedTo(argMatchedGSTLabor.IGST, DecimalsNumber));
423
+ });
424
+ TaxInfo.SAC = SAC;
425
+
426
+ TaxInfo.CGSTAmt = CGSTAmt;
427
+ TaxInfo.SGSTAmt = SGSTAmt;
428
+ TaxInfo.IGSTAmt = IGSTAmt;
429
+
430
+ TaxInfo.TotalTaxableAmount = TrUtils.FixPriceValue(TaxOnAmount, DecimalsNumber);
431
+ TaxInfo.TotalTaxAmount = TrUtils.FixPriceValue(TaxAmount, DecimalsNumber);
432
+ TaxInfo.ItemsCount = MatchedLabor.length;
433
+ let GSTValues: any[] = this.GetGSTValueBasedOnTaxCode(MatchedLabor[0].TCode, TaxCodes);
434
+ TaxInfo.CGST = GSTValues[0];
435
+ TaxInfo.SGST = GSTValues[1];
436
+ TaxInfo.IGST = GSTValues[2];
437
+ if (TaxOnAmount !== 0) {
438
+ SACTaxInfo.push(TaxInfo);
439
+ }
440
+ });
441
+ return SACTaxInfo;
442
+ }
443
+
444
+ static CompareLaborByPerc(opCodesList: any, TaxCodes: any) {
445
+ let FinalMatchedLabors: any[] = [];
446
+ opCodesList?.forEach((Labor: any) => {
447
+ let MatchedLaborsBasedOnPerc = opCodesList.filter((argLabor: any) => {
448
+ let PartFound: boolean = false;
449
+ FinalMatchedLabors.forEach((FinalArgLabors: any) => {
450
+ let PartIndex: any = FinalArgLabors.findIndex((FinalArgPart: any) => {
451
+ return FinalArgPart._id === argLabor._id;
452
+ });
453
+ if (PartIndex !== -1) {
454
+ PartFound = true;
455
+ }
456
+ });
457
+
458
+ // let argGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(argLabor.TCode, TaxCodes);
459
+ // let argCGST = argGSTValues[0];
460
+ // let argSGST = argGSTValues[1];
461
+ // let argIGST = argGSTValues[2];
462
+
463
+ // let laborGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(Labor.TCode, TaxCodes);
464
+ // let laborCGST = laborGSTValues[0];
465
+ // let laborSGST = laborGSTValues[1];
466
+ // let laborIGST = laborGSTValues[2];
467
+ return (!PartFound) &&
468
+ (argLabor.CGSTAmt === Labor.CGSTAmt) && (argLabor.IGSTAmt === Labor.IGSTAmt) &&
469
+ (argLabor.SGSTAmt === Labor.SGSTAmt);
470
+ });
471
+ if (MatchedLaborsBasedOnPerc.length !== 0) {
472
+ FinalMatchedLabors.push(MatchedLaborsBasedOnPerc);
473
+ }
474
+ });
475
+ return FinalMatchedLabors;
476
+ }
477
+
478
+ static ComparePartsByPerc(Parts: any, TaxCodes: any) {
479
+ let FinalMatchedParts: any[] = [];
480
+ Parts?.forEach((Part: any) => {
481
+ let MatchedPartsBasedOnHSN = Parts.filter((argPart: any) => {
482
+ let PartFound: boolean = false;
483
+ FinalMatchedParts.forEach((FinalArgParts: any) => {
484
+ let PartIndex: any = FinalArgParts.findIndex((FinalArgPart: any) => {
485
+ return FinalArgPart._id === argPart._id;
486
+ });
487
+ if (PartIndex !== -1) {
488
+ PartFound = true;
489
+ }
490
+ });
491
+
492
+ // let argGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(argPart.TCode, TaxCodes);
493
+ // let argCGST = argGSTValues[0];
494
+ // let argSGST = argGSTValues[1];
495
+ // let argIGST = argGSTValues[2];
496
+
497
+ // let partGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(Part.TCode, TaxCodes);
498
+ // let partCGST = partGSTValues[0];
499
+ // let partSGST = partGSTValues[1];
500
+ // let partIGST = partGSTValues[2];
501
+
502
+ return (!PartFound) &&
503
+ (argPart.CGSTAmt === Part.CGSTAmt) && (argPart.IGSTAmt === Part.IGSTAmt) &&
504
+ (argPart.SGSTAmt === Part.SGSTAmt);
505
+ });
506
+ if (MatchedPartsBasedOnHSN.length !== 0) {
507
+ FinalMatchedParts.push(MatchedPartsBasedOnHSN);
508
+ }
509
+ });
510
+ return FinalMatchedParts;
511
+ }
512
+
513
+ static GetPartGSTTaxTotal(PartsList: Array<any>) {
514
+ let CGSTAmt: number = 0;
515
+ let SGSTAmt: number = 0;
516
+ let IGSTAmt: number = 0;
517
+ PartsList.forEach((Part: any) => {
518
+ CGSTAmt = Add(CGSTAmt, Part.CGST);
519
+ SGSTAmt = Add(SGSTAmt, Part.SGST);
520
+ IGSTAmt = Add(IGSTAmt, Part.IGST);
521
+ });
522
+ return [CGSTAmt, SGSTAmt, IGSTAmt];
523
+ }
524
+
525
+ static GetServicesGSTTaxTotal(ServicesList: Array<any>) {
526
+ let CGSTAmt: number = 0;
527
+ let SGSTAmt: number = 0;
528
+ let IGSTAmt: number = 0;
529
+ ServicesList.forEach((labor: any) => {
530
+ CGSTAmt = Add(CGSTAmt, labor.CGST);
531
+ SGSTAmt = Add(SGSTAmt, labor.SGST);
532
+ IGSTAmt = Add(IGSTAmt, labor.IGST);
533
+ });
534
+ return [CGSTAmt, SGSTAmt, IGSTAmt];
535
+ }
536
+
537
+ static GetPartsTaxGroupingFor(PartsList: any, TaxCodes: any, DecimalsNumber: number) {
538
+ return this.GetTaxGroupingForPartsByHSN(TrUtils.Stringify(PartsList), TaxCodes, DecimalsNumber);
539
+ }
540
+
541
+ static GetTaxGroupingForPartsByHSN(Items: any, TaxCodes: any, DecimalsNumber: number) {
542
+ Items = this.GetCombinedTaxPercentage(Items, TaxCodes);
543
+ // Items = this.ResetPartsHSNIfInvalid(Items);
544
+ let FinalMatchedParts: any[] = this.ComparePartsByHSN(Items, TaxCodes);
545
+ return this.GetTaxGroupingInfoByHSN(FinalMatchedParts, TaxCodes, DecimalsNumber);
546
+ }
547
+
548
+ static GetCombinedTaxPercentage(Items: any, TaxCodes: any) {
549
+ Items.forEach((Part: any) => {
550
+ if (TrUtils.IsNull(Part.HSN)) {
551
+ Part.HSN = '';
552
+ }
553
+ Part.TCode = this.GetTCodeFromTaxes(Part);
554
+ Part.CGSTAmt = TrUtils.SetValueToZeroIfNull(this.GetTaxRateFromTaxes(Part, 'CGST'));
555
+ Part.SGSTAmt = TrUtils.SetValueToZeroIfNull(this.GetTaxRateFromTaxes(Part, 'SGST'));
556
+ Part.IGSTAmt = TrUtils.SetValueToZeroIfNull(this.GetTaxRateFromTaxes(Part, 'IGST'));
557
+ Part.CombinedTaxPercentage = Add(Part.CGSTAmt, Part.SGSTAmt, Part.IGSTAmt);
558
+ });
559
+ return Items;
560
+ }
561
+
562
+ static ComparePartsByHSN(Items: any, TaxCodes: any) {
563
+ let FinalMatchedParts: any[] = [];
564
+ Items.forEach((Part: any) => {
565
+ let MatchedPartsBasedOnHSN = Items.filter((argPart: any) => {
566
+ let PartFound: boolean = false;
567
+ FinalMatchedParts.forEach((FinalArgParts: any) => {
568
+ let PartIndex: any = FinalArgParts.findIndex((FinalArgPart: any) => {
569
+ return FinalArgPart._id === argPart._id;
570
+ });
571
+ if (PartIndex !== -1) {
572
+ PartFound = true;
573
+ }
574
+ });
575
+ // let argCGST = this.GetCGSTValueBasedOnTaxCode(argPart.TCode, TaxCodes);
576
+ // let argSGST = this.GetSGSTValueBasedOnTaxCode(argPart.TCode, TaxCodes);
577
+ // let argIGST = this.GetIGSTValueBasedOnTaxCode(argPart.TCode, TaxCodes);
578
+ // let partCGST = this.GetCGSTValueBasedOnTaxCode(Part.TCode, TaxCodes);
579
+ // let partSGST = this.GetSGSTValueBasedOnTaxCode(Part.TCode, TaxCodes);
580
+ // let partIGST = this.GetIGSTValueBasedOnTaxCode(Part.TCode, TaxCodes);
581
+ return (argPart.HSN === Part.HSN) && (!PartFound) &&
582
+ (argPart.CGSTAmt === Part.CGSTAmt) && (argPart.IGSTAmt === Part.IGSTAmt) &&
583
+ (argPart.SGSTAmt === Part.SGSTAmt);
584
+ });
585
+ if (MatchedPartsBasedOnHSN.length !== 0) {
586
+ FinalMatchedParts.push(MatchedPartsBasedOnHSN);
587
+ }
588
+ });
589
+ return FinalMatchedParts;
590
+ }
591
+
592
+ static GetTaxGroupingInfoByHSN(FinalMatchedParts: any, TaxCodes: any, DecimalsNumber: any) {
593
+ let HSNTaxInfo: any[] = [];
594
+ FinalMatchedParts.forEach((MatchedPart: any) => {
595
+ let TaxInfo: any = {};
596
+ let TaxOnAmount: any = 0;
597
+ let TaxAmount: any = 0;
598
+
599
+ let CGSTAmt: any = 0;
600
+ let SGSTAmt: any = 0;
601
+ let IGSTAmt: any = 0;
602
+
603
+ let HSN: any = MatchedPart[0].HSN;
604
+ TaxInfo.CombinedTaxPercentage = MatchedPart[0].CombinedTaxPercentage;
605
+ MatchedPart.forEach((argMatchedGSTPart: any) => {
606
+ TaxOnAmount = Add(TaxOnAmount, TrUtils.FixedTo(argMatchedGSTPart.AfterDiscountPrice, DecimalsNumber));
607
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CGST, DecimalsNumber));
608
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.IGST, DecimalsNumber));
609
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.SGST, DecimalsNumber));
610
+ CGSTAmt = Add(CGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.CGST, DecimalsNumber));
611
+ SGSTAmt = Add(SGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.SGST, DecimalsNumber));
612
+ IGSTAmt = Add(IGSTAmt, TrUtils.FixedTo(argMatchedGSTPart.IGST, DecimalsNumber));
613
+ });
614
+ TaxInfo.HSN = HSN;
615
+
616
+ TaxInfo.CGSTAmt = CGSTAmt;
617
+ TaxInfo.SGSTAmt = SGSTAmt;
618
+ TaxInfo.IGSTAmt = IGSTAmt;
619
+
620
+ TaxInfo.TotalTaxableAmount = TrUtils.FixPriceValue(TaxOnAmount, DecimalsNumber);
621
+ TaxInfo.TotalTaxAmount = TrUtils.FixPriceValue(TaxAmount, DecimalsNumber);
622
+ TaxInfo.ItemsCount = MatchedPart.length;
623
+ // let GSTValues: any[] = this.GetGSTValueBasedOnTaxCode(MatchedPart[0].TCode, TaxCodes);
624
+ // TaxInfo.CGST = GSTValues[0];
625
+ // TaxInfo.SGST = GSTValues[1];
626
+ // TaxInfo.IGST = GSTValues[2];
627
+ TaxInfo.CGST = MatchedPart[0].CGSTAmt;
628
+ TaxInfo.IGST = MatchedPart[0].IGSTAmt;
629
+ TaxInfo.SGST = MatchedPart[0].SGSTAmt;
630
+ if (TaxOnAmount !== 0) {
631
+ HSNTaxInfo.push(TaxInfo);
632
+ }
633
+ });
634
+ return HSNTaxInfo;
635
+ }
636
+
637
+ }