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,1314 @@
1
+ import { LaborStatusEnum, PayTypeEnum } from "../enums/enums";
2
+ import { Add, Divide, Subtract } from "../shared/math-operations";
3
+ import { TrUtils } from "../utils/tr-utils";
4
+
5
+
6
+ export class ROTotalsService {
7
+
8
+ static GetTaxAmountFromGroup(item: any, taxGroupKey: string, taxCode: string, fallbackKey: string) {
9
+ const groupedTaxes = item?.[taxGroupKey];
10
+ if (Array.isArray(groupedTaxes)) {
11
+ const matchedTaxes = groupedTaxes.filter((tax: any) => tax?.Code === taxCode);
12
+ if (matchedTaxes.length !== 0) {
13
+ return matchedTaxes.reduce((total: number, tax: any) => Add(total, tax?.Amt), 0);
14
+ }
15
+ }
16
+ return TrUtils.SetValueToZeroIfNull(item?.[fallbackKey]);
17
+ }
18
+
19
+ static GetTotalsValue(OriRecordData: any, TaxCodes: any[], isWorkOrder: boolean, detailedInfo: boolean, withItems: boolean, isRoundable: boolean, EntitySettings: any) {
20
+
21
+ let dupRecordData: any = TrUtils.Stringify(OriRecordData);
22
+ let argRecordData: any = {};
23
+ dupRecordData.Ops = this.CalculateLaborValues(dupRecordData.Ops, isWorkOrder, TrUtils.isTaxable(dupRecordData.Settings.Tax));
24
+ dupRecordData.Parts = this.CalculatePartValues(dupRecordData.Parts, dupRecordData.Ops, isWorkOrder, TrUtils.isTaxable(dupRecordData.Settings.Tax));
25
+ argRecordData = this.GetROTotalsData(argRecordData, dupRecordData, TaxCodes, withItems, detailedInfo, isWorkOrder, isRoundable, EntitySettings.DecimalsNumber);
26
+
27
+ return argRecordData;
28
+ }
29
+
30
+ static CalculateLaborValues(opCodesList: any, isWorkOrder: boolean, isTaxable: boolean) {
31
+
32
+ opCodesList = this.FilterValidLaborItems(opCodesList);
33
+ opCodesList = this.ResetLaborValuesIfInvalid(opCodesList, isWorkOrder);
34
+ opCodesList = this.GetOperationsDiscountPrice(opCodesList, isWorkOrder);
35
+ opCodesList = this.GetOperationsAfterDiscount(opCodesList, isWorkOrder);
36
+ opCodesList = this.GetOperationsAfterTax(opCodesList, isWorkOrder, isTaxable);
37
+
38
+ return opCodesList;
39
+ }
40
+
41
+ static FilterValidLaborItems(opCodesList: any[]) {
42
+ opCodesList = opCodesList.filter((Labor: any) => {
43
+ return Labor.Sts !== LaborStatusEnum.Cancelled && Labor.Sts !== LaborStatusEnum.Declined;
44
+ });
45
+ return opCodesList;
46
+ }
47
+
48
+ static ResetLaborValuesIfInvalid(opCodesList: any, isWorkOrder: boolean) {
49
+ opCodesList.forEach((Operation: any) => {
50
+ Operation = this.ResetLaborValueIfInvalid(Operation, isWorkOrder);
51
+ });
52
+ return opCodesList;
53
+ }
54
+
55
+ static ResetLaborValueIfInvalid(Operation: any, isWorkOrder: boolean) {
56
+ Operation.Perc = TrUtils.SetPercToStringIfNull(Operation.Perc);
57
+ Operation.Disc = TrUtils.SetValueToZeroIfNull(Operation.Disc);
58
+ Operation.Pr = TrUtils.SetValueToZeroIfNull(Operation.Pr);
59
+ Operation.AssPr = TrUtils.SetValueToZeroIfNull(Operation.AssPr);
60
+ Operation.ACGST = this.GetTaxAmountFromGroup(Operation, 'ATaxes', 'CGST', 'ACGST');
61
+ Operation.ASGST = this.GetTaxAmountFromGroup(Operation, 'ATaxes', 'SGST', 'ASGST');
62
+ Operation.AIGST = this.GetTaxAmountFromGroup(Operation, 'ATaxes', 'IGST', 'AIGST');
63
+ Operation.CCGST = this.GetTaxAmountFromGroup(Operation, 'CTaxes', 'CGST', 'CCGST');
64
+ Operation.CSGST = this.GetTaxAmountFromGroup(Operation, 'CTaxes', 'SGST', 'CSGST');
65
+ Operation.CIGST = this.GetTaxAmountFromGroup(Operation, 'CTaxes', 'IGST', 'CIGST');
66
+ Operation.NetAmt = TrUtils.SetValueToZeroIfNull(Operation.NetAmt);
67
+ Operation.RecDisc = TrUtils.SetValueToZeroIfNull(Operation.RecDisc);
68
+
69
+ if (!isWorkOrder) {
70
+ Operation.EstPr = TrUtils.SetValueToZeroIfNull(Operation.EstPr);
71
+ Operation.ECGST = this.GetTaxAmountFromGroup(Operation, 'ETaxes', 'CGST', 'ECGST');
72
+ Operation.ESGST = this.GetTaxAmountFromGroup(Operation, 'ETaxes', 'SGST', 'ESGST');
73
+ Operation.EIGST = this.GetTaxAmountFromGroup(Operation, 'ETaxes', 'IGST', 'EIGST');
74
+ }
75
+ return Operation;
76
+ }
77
+
78
+ static GetOperationsDiscountPrice(OperationsList: any, isWorkOrder: boolean) {
79
+ OperationsList.forEach((Operation: any) => {
80
+ if (isWorkOrder) {
81
+ Operation.CustDiscountedPrice = Add(Operation.Disc, Operation.RecDisc);
82
+ } else {
83
+ if (Operation.Sts === LaborStatusEnum.New || Operation.Sts === LaborStatusEnum.WtngForAppr) {
84
+ Operation.CustDiscountedPrice = 0;
85
+ } else {
86
+ Operation.CustDiscountedPrice = Add(Operation.Disc, Operation.RecDisc);
87
+ }
88
+ }
89
+ });
90
+ return OperationsList;
91
+ }
92
+
93
+ static GetOperationsAfterDiscount(OperationsList: any, isWorkOrder: boolean) {
94
+ OperationsList.forEach((Operation: any) => {
95
+ let CustAfterLaborDisc: number = 0;
96
+ let InsAfterLaborDisc: number = 0;
97
+ if (Operation.PBy === PayTypeEnum.Customer) {
98
+ if (isWorkOrder) {
99
+ CustAfterLaborDisc = Operation.NetAmt;
100
+ } else {
101
+ if (Operation.Sts === LaborStatusEnum.New || Operation.Sts === LaborStatusEnum.WtngForAppr) {
102
+ CustAfterLaborDisc = Operation.EstPr;
103
+ } else {
104
+ CustAfterLaborDisc = Operation.NetAmt;
105
+ }
106
+ }
107
+ } else {
108
+ if (isWorkOrder) {
109
+ CustAfterLaborDisc = Operation.NetAmt;
110
+ InsAfterLaborDisc = Operation.AssPr;
111
+ } else {
112
+ if (Operation.Sts === LaborStatusEnum.New || Operation.Sts === LaborStatusEnum.WtngForAppr) {
113
+ InsAfterLaborDisc = Operation.EstPr;
114
+ } else {
115
+ CustAfterLaborDisc = Operation.NetAmt;
116
+ InsAfterLaborDisc = Operation.AssPr;
117
+ }
118
+ }
119
+ }
120
+ Operation.CustAfterLaborDisc = CustAfterLaborDisc;
121
+ Operation.InsAfterLaborDisc = InsAfterLaborDisc;
122
+ });
123
+ return OperationsList;
124
+ }
125
+
126
+ static GetOperationsAfterTax(OperationsList: any, isWorkOrder: boolean, isTaxable: boolean) {
127
+ OperationsList.forEach((Operation: any) => {
128
+ if (!isTaxable) {
129
+ Operation.CustAfterTax = Operation.CustAfterLaborDisc;
130
+ Operation.InsAfterTax = Operation.InsAfterLaborDisc;
131
+ } else {
132
+ if (Operation.PBy === PayTypeEnum.Customer) {
133
+ if (isWorkOrder) {
134
+ Operation.CustAfterTax = Add(Operation.CustAfterLaborDisc, Operation.CCGST, Operation.CSGST, Operation.CIGST);
135
+ } else {
136
+ if (Operation.Sts !== LaborStatusEnum.New && Operation.Sts !== LaborStatusEnum.WtngForAppr) {
137
+ Operation.CustAfterTax = Add(Operation.CustAfterLaborDisc, Operation.CCGST, Operation.CSGST, Operation.CIGST);
138
+ } else {
139
+ Operation.CustAfterTax = Add(Operation.CustAfterLaborDisc, Operation.ECGST, Operation.ESGST, Operation.EIGST);
140
+ }
141
+ }
142
+ Operation.InsAfterTax = 0;
143
+ } else {
144
+ if (isWorkOrder) {
145
+ Operation.CustAfterTax = Add(Operation.CustAfterLaborDisc, Operation.CCGST, Operation.CSGST, Operation.CIGST);
146
+ Operation.InsAfterTax = Add(Operation.InsAfterLaborDisc, Operation.ACGST, Operation.ASGST, Operation.AIGST);
147
+ } else {
148
+ if (Operation.Sts !== LaborStatusEnum.New && Operation.Sts !== LaborStatusEnum.WtngForAppr) {
149
+ Operation.CustAfterTax = Add(Operation.CustAfterLaborDisc, Operation.CCGST, Operation.CSGST, Operation.CIGST);
150
+ Operation.InsAfterTax = Add(Operation.InsAfterLaborDisc, Operation.ACGST, Operation.ASGST, Operation.AIGST);
151
+ } else {
152
+ Operation.CustAfterTax = 0;
153
+ Operation.InsAfterTax = Add(Operation.InsAfterLaborDisc, Operation.ECGST, Operation.ESGST, Operation.EIGST);
154
+ }
155
+ }
156
+ }
157
+ }
158
+ });
159
+ return OperationsList;
160
+ }
161
+
162
+ static CalculatePartValues(PartsList: any, LaborList: any, isWorkOrder: boolean, isTaxable: boolean) {
163
+
164
+ PartsList = this.FilterValidPartItems(PartsList);
165
+
166
+ PartsList = this.ResetPartValuesIfInvalid(PartsList, isWorkOrder);
167
+
168
+ PartsList = this.GetPartsDiscountPrice(PartsList, LaborList, isWorkOrder);
169
+
170
+ PartsList = this.GetPartsAfterDiscount(PartsList, LaborList, isWorkOrder);
171
+
172
+ PartsList = this.GetPartsAfterTax(PartsList, LaborList, isWorkOrder, isTaxable);
173
+
174
+ PartsList = this.GetPartsPerItemAfterTax(PartsList);
175
+
176
+ return PartsList;
177
+ }
178
+
179
+ static FilterValidPartItems(PartsList: any[]) {
180
+ PartsList = PartsList.filter((Part: any) => {
181
+ if (TrUtils.IsNull(Part.CollId)) {
182
+ return Part;
183
+ } else {
184
+ return Part.Sts !== LaborStatusEnum.Cancelled && Part.Sts !== LaborStatusEnum.Declined;
185
+ }
186
+ });
187
+ return PartsList;
188
+ }
189
+
190
+ static ResetPartValuesIfInvalid(PartsList: any, isWorkOrder: boolean) {
191
+ PartsList.forEach((Part: any) => {
192
+ Part = this.ResetPartValueIfInvalid(Part, isWorkOrder);
193
+ });
194
+ return PartsList;
195
+ }
196
+
197
+ static ResetPartValueIfInvalid(Part: any, isWorkOrder: boolean) {
198
+ Part.Perc = TrUtils.SetPercToStringIfNull(Part.Perc);
199
+ Part.Disc = TrUtils.SetValueToZeroIfNull(Part.Disc);
200
+ Part.UnPr = TrUtils.SetValueToZeroIfNull(Part.UnPr);
201
+ Part.AssPr = TrUtils.SetValueToZeroIfNull(Part.AssPr);
202
+ Part.ACGST = this.GetTaxAmountFromGroup(Part, 'ATaxes', 'CGST', 'ACGST');
203
+ Part.ASGST = this.GetTaxAmountFromGroup(Part, 'ATaxes', 'SGST', 'ASGST');
204
+ Part.AIGST = this.GetTaxAmountFromGroup(Part, 'ATaxes', 'IGST', 'AIGST');
205
+ Part.CCGST = this.GetTaxAmountFromGroup(Part, 'CTaxes', 'CGST', 'CCGST');
206
+ Part.CSGST = this.GetTaxAmountFromGroup(Part, 'CTaxes', 'SGST', 'CSGST');
207
+ Part.CIGST = this.GetTaxAmountFromGroup(Part, 'CTaxes', 'IGST', 'CIGST');
208
+ Part.UnAmt = TrUtils.SetValueToZeroIfNull(Part.UnAmt);
209
+ Part.AssAmt = TrUtils.SetValueToZeroIfNull(Part.AssAmt);
210
+ Part.NetAmt = TrUtils.SetValueToZeroIfNull(Part.NetAmt);
211
+ Part.RecDisc = TrUtils.SetValueToZeroIfNull(Part.RecDisc);
212
+ if (!isWorkOrder) {
213
+ Part.EstPr = TrUtils.SetValueToZeroIfNull(Part.EstPr);
214
+ Part.ECGST = this.GetTaxAmountFromGroup(Part, 'ETaxes', 'CGST', 'ECGST');
215
+ Part.ESGST = this.GetTaxAmountFromGroup(Part, 'ETaxes', 'SGST', 'ESGST');
216
+ Part.EIGST = this.GetTaxAmountFromGroup(Part, 'ETaxes', 'IGST', 'EIGST');
217
+ Part.EstAmt = TrUtils.SetValueToZeroIfNull(Part.EstAmt);
218
+ }
219
+ return Part;
220
+ }
221
+
222
+ static GetPartsDiscountPrice(PartsList: any, LaborList: any, isWorkOrder: boolean) {
223
+ PartsList.forEach((Part: any) => {
224
+ if (TrUtils.IsNull(Part.CollId)) {
225
+ if (isWorkOrder) {
226
+ Part.CustDiscountedPrice = Add(Part.Disc, Part.RecDisc);
227
+ } else {
228
+ let LaborSts: string = this.GetPartParentStatus(Part, LaborList);
229
+ if (LaborSts === LaborStatusEnum.New || LaborSts === LaborStatusEnum.WtngForAppr) {
230
+ Part.CustDiscountedPrice = 0;
231
+ } else {
232
+ Part.CustDiscountedPrice = Add(Part.Disc, Part.RecDisc);
233
+ }
234
+ }
235
+ } else {
236
+ if (isWorkOrder) {
237
+ Part.CustDiscountedPrice = Add(Part.Disc, Part.RecDisc);
238
+ } else {
239
+ if (Part.Sts === LaborStatusEnum.New || Part.Sts === LaborStatusEnum.WtngForAppr) {
240
+ Part.CustDiscountedPrice = 0;
241
+ } else {
242
+ Part.CustDiscountedPrice = Add(Part.Disc, Part.RecDisc);
243
+ }
244
+ }
245
+ }
246
+ });
247
+ return PartsList;
248
+ }
249
+
250
+ static GetPartParentStatus(Part: any, LaborList: any) {
251
+ if (!TrUtils.IsNull(Part.OpId)) {
252
+ let index: number = LaborList.findIndex((Labor: any) => {
253
+ return Labor._id === Part.OpId;
254
+ });
255
+ return LaborList[index].Sts;
256
+ } else {
257
+ return Part.Sts;
258
+ }
259
+
260
+ }
261
+
262
+ static GetPartsAfterDiscount(PartsList: any, LaborList: any, isWorkOrder: boolean) {
263
+ PartsList.forEach((Part: any) => {
264
+ if (TrUtils.IsNull(Part.CollId)) {
265
+ let CustAfterPartDisc: number = 0;
266
+ let InsAfterPartDisc: number = 0;
267
+ if (isWorkOrder) {
268
+ CustAfterPartDisc = Part.NetAmt;
269
+ if (TrUtils.IsNull(Part.OpId)) {
270
+ InsAfterPartDisc = Part.AssAmt;
271
+ }
272
+ } else {
273
+ let LaborSts: string = this.GetPartParentStatus(Part, LaborList);
274
+ if (LaborSts === LaborStatusEnum.New || LaborSts === LaborStatusEnum.WtngForAppr) {
275
+ CustAfterPartDisc = Part.EstAmt;
276
+ } else {
277
+ CustAfterPartDisc = Part.NetAmt;
278
+ if (TrUtils.IsNull(Part.OpId)) {
279
+ InsAfterPartDisc = Part.AssAmt;
280
+ }
281
+ }
282
+ }
283
+ Part.CustAfterPartDisc = CustAfterPartDisc;
284
+ Part.InsAfterPartDisc = InsAfterPartDisc;
285
+ } else {
286
+ let CustAfterPartDisc: number = 0;
287
+ let InsAfterPartDisc: number = 0;
288
+ if (Part.PBy === PayTypeEnum.Customer) {
289
+ if (isWorkOrder) {
290
+ CustAfterPartDisc = Part.NetAmt;
291
+ } else {
292
+ if (Part.Sts === LaborStatusEnum.New || Part.Sts === LaborStatusEnum.WtngForAppr) {
293
+ CustAfterPartDisc = Part.EstAmt;
294
+ } else {
295
+ CustAfterPartDisc = Part.NetAmt;
296
+ }
297
+ }
298
+ } else {
299
+ if (isWorkOrder) {
300
+ CustAfterPartDisc = Part.NetAmt;
301
+ InsAfterPartDisc = Part.AssAmt;
302
+ } else {
303
+ if (Part.Sts === LaborStatusEnum.New || Part.Sts === LaborStatusEnum.WtngForAppr) {
304
+ InsAfterPartDisc = Part.EstAmt;
305
+ } else {
306
+ CustAfterPartDisc = Part.NetAmt;
307
+ InsAfterPartDisc = Part.AssAmt;
308
+ }
309
+ }
310
+ }
311
+ Part.CustAfterPartDisc = CustAfterPartDisc;
312
+ Part.InsAfterPartDisc = InsAfterPartDisc;
313
+ }
314
+ });
315
+ return PartsList;
316
+ }
317
+
318
+ static GetPartsAfterTax(PartsList: any, LaborList: any, isWorkOrder: boolean, isTaxable: boolean) {
319
+ PartsList.forEach((Part: any) => {
320
+ if (!isTaxable) {
321
+ Part.CustAfterTax = Part.CustAfterPartDisc;
322
+ Part.InsAfterTax = Part.InsAfterPartDisc;
323
+ } else {
324
+ if (TrUtils.IsNull(Part.CollId)) {
325
+ if (isWorkOrder) {
326
+ Part.CustAfterTax = Add(Part.CustAfterPartDisc, Part.CCGST, Part.CSGST, Part.CIGST);
327
+ if (TrUtils.IsNull(Part.OpId)) {
328
+ Part.InsAfterTax = Add(Part.InsAfterPartDisc, Part.ACGST, Part.ASGST, Part.AIGST);
329
+ }
330
+ } else {
331
+ let LaborSts: string = this.GetPartParentStatus(Part, LaborList);
332
+ if (LaborSts === LaborStatusEnum.New || LaborSts === LaborStatusEnum.WtngForAppr) {
333
+ Part.CustAfterTax = Add(Part.CustAfterPartDisc, Part.ECGST, Part.ESGST, Part.EIGST);
334
+ } else {
335
+ Part.CustAfterTax = Add(Part.CustAfterPartDisc, Part.CCGST, Part.CSGST, Part.CIGST);
336
+ if (TrUtils.IsNull(Part.OpId)) {
337
+ Part.InsAfterTax = Add(Part.InsAfterPartDisc, Part.ACGST, Part.ASGST, Part.AIGST);
338
+ }
339
+ }
340
+ }
341
+ // Part.InsAfterTax = 0;
342
+
343
+ } else {
344
+ if (Part.PBy === PayTypeEnum.Customer) {
345
+ if (isWorkOrder) {
346
+ Part.CustAfterTax = Add(Part.CustAfterPartDisc, Part.CCGST, Part.CSGST, Part.CIGST);
347
+ } else {
348
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
349
+ Part.CustAfterTax = Add(Part.CustAfterPartDisc, Part.CCGST, Part.CSGST, Part.CIGST);
350
+ } else {
351
+ Part.CustAfterTax = Add(Part.CustAfterPartDisc, Part.ECGST, Part.ESGST, Part.EIGST);
352
+ }
353
+ }
354
+ Part.InsAfterTax = 0;
355
+ } else {
356
+ if (isWorkOrder) {
357
+ Part.CustAfterTax = Add(Part.CustAfterPartDisc, Part.CCGST, Part.CSGST, Part.CIGST);
358
+ Part.InsAfterTax = Add(Part.InsAfterPartDisc, Part.ACGST, Part.ASGST, Part.AIGST);
359
+ } else {
360
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
361
+ Part.CustAfterTax = Add(Part.CustAfterPartDisc, Part.CCGST, Part.CSGST, Part.CIGST);
362
+ Part.InsAfterTax = Add(Part.InsAfterPartDisc, Part.ACGST, Part.ASGST, Part.AIGST);
363
+ } else {
364
+ Part.CustAfterTax = 0;
365
+ Part.InsAfterTax = Add(Part.InsAfterPartDisc, Part.ECGST, Part.ESGST, Part.EIGST);
366
+ }
367
+ }
368
+ }
369
+ }
370
+ }
371
+ });
372
+ return PartsList;
373
+ }
374
+
375
+ static GetPartsPerItemAfterTax(PartsList: any) {
376
+ PartsList.forEach((Part: any) => {
377
+ Part.CustAfterTaxPerItem = Divide(Part.CustAfterTax, Part.Qty);
378
+ Part.InsAfterTaxPerItem = Divide(Part.InsAfterTax, Part.Qty);
379
+ });
380
+ return PartsList;
381
+ }
382
+
383
+ static GetROTotalsData(argRecordData: any, dupRecordData: any, TaxCodes: any, withItems: boolean, detailedInfo: any, isWorkOrder: boolean, isRoundable: boolean, DecimalsNumber: number) {
384
+
385
+ dupRecordData = this.ResetDiscountValuesIfInvalid(dupRecordData);
386
+ argRecordData = this.SetMainDiscountValues(argRecordData, dupRecordData, detailedInfo);
387
+ argRecordData = this.GetFinalCustomerTotalsData(argRecordData, dupRecordData, isWorkOrder, detailedInfo, isRoundable, DecimalsNumber);
388
+ argRecordData = this.GetFinalInsuranceTotalsData(argRecordData, dupRecordData, detailedInfo, isWorkOrder, DecimalsNumber);
389
+ if (detailedInfo) {
390
+ argRecordData = this.GetDetailedTotalsData(argRecordData, dupRecordData, TaxCodes, isWorkOrder, DecimalsNumber);
391
+ }
392
+ if (withItems) {
393
+ argRecordData.Ops = dupRecordData.Ops;
394
+ argRecordData.Parts = dupRecordData.Parts;
395
+ argRecordData.Colli = dupRecordData.Colli;
396
+ }
397
+ return argRecordData;
398
+ }
399
+
400
+ static ResetDiscountValuesIfInvalid(dupRecordData: any) {
401
+ dupRecordData.LPerc = TrUtils.SetPercToStringIfNull(dupRecordData.LPerc);
402
+ dupRecordData.PPerc = TrUtils.SetPercToStringIfNull(dupRecordData.PPerc);
403
+ dupRecordData.Perc = TrUtils.SetPercToStringIfNull(dupRecordData.Perc);
404
+ dupRecordData.LDisc = TrUtils.SetValueToZeroIfNull(dupRecordData.LDisc);
405
+ dupRecordData.PDisc = TrUtils.SetValueToZeroIfNull(dupRecordData.PDisc);
406
+ dupRecordData.Disc = TrUtils.SetValueToZeroIfNull(dupRecordData.Disc);
407
+ return dupRecordData;
408
+ }
409
+
410
+ static SetMainDiscountValues(argRecordData: any, dupRecordData: any, detailedInfo: boolean) {
411
+ argRecordData.LDisc = dupRecordData.LDisc;
412
+ argRecordData.LPerc = dupRecordData.LPerc;
413
+ argRecordData.PDisc = dupRecordData.PDisc;
414
+ argRecordData.PPerc = dupRecordData.PPerc;
415
+ argRecordData.Disc = dupRecordData.Disc;
416
+ argRecordData.Perc = dupRecordData.Perc;
417
+ if (detailedInfo) {
418
+ argRecordData.FixedLDisc = dupRecordData.LDisc;
419
+ argRecordData.FixedPDisc = dupRecordData.PDisc;
420
+ argRecordData.FixedDisc = dupRecordData.Disc;
421
+ }
422
+ return argRecordData;
423
+ }
424
+
425
+ static GetFinalCustomerTotalsData(argRecordData: any, dupRecordData: any, isWorkOrder: boolean, detailedInfo: boolean, isRoundable: boolean, DecimalsNumber: number) {
426
+ let CustomerAfterDiscTotals: number = this.GetCustSubTotal(dupRecordData.Ops, dupRecordData.Parts);
427
+ let CustLaborTaxTotal = this.GetCustLaborTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
428
+ let CustPartTaxTotal = this.GetCustPartsTaxTotal(dupRecordData.Ops, dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
429
+ let CustLaborDiscTotal: any = this.GetCustLaborDiscountedTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), dupRecordData);
430
+ let CustPartsDiscTotal: any = this.GetCustPartDiscountedTotal(dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), dupRecordData);
431
+ let CustLaborTotalAfterDisc: any = this.GetCustLaborTotalAfterDiscount(dupRecordData.Ops);
432
+ let CustPartsTotalAfterDisc: any = this.GetCustPartsTotalAfterDiscount(dupRecordData.Parts);
433
+ argRecordData.STotal = Add(CustLaborDiscTotal, CustPartsDiscTotal, CustLaborTotalAfterDisc, CustPartsTotalAfterDisc)
434
+ argRecordData.CustLaborTotalBeforeDisc = Add(argRecordData.CustLaborTotalAfterDisc
435
+ , argRecordData.CustLaborDiscTotal);
436
+ argRecordData.CustPartsTotalBeforeDisc = Add(argRecordData.CustPartsTotalAfterDisc
437
+ , argRecordData.CustPartsDiscTotal);
438
+ argRecordData.SubTotal = TrUtils.FixedTo(CustomerAfterDiscTotals, DecimalsNumber);
439
+ let CustTotal: any = this.GetCustomerTotalBasedOnTaxType(dupRecordData, CustLaborTaxTotal, CustPartTaxTotal, dupRecordData.Ops, dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax));
440
+ argRecordData.TaxTotal = Add(CustLaborTaxTotal, CustPartTaxTotal);
441
+ if (detailedInfo) {
442
+ argRecordData.FixedSubTotal = TrUtils.FixedTo(CustomerAfterDiscTotals, DecimalsNumber);
443
+ argRecordData.FixedTotal = TrUtils.FixedTo(CustTotal, DecimalsNumber);
444
+ }
445
+
446
+ if (isRoundable) {
447
+ argRecordData.Round = Subtract(Math.round(CustTotal), CustTotal);
448
+ argRecordData.Total = Math.round(CustTotal);
449
+ } else {
450
+ argRecordData.Total = TrUtils.FixedTo(CustTotal, DecimalsNumber);
451
+ }
452
+
453
+
454
+
455
+ return argRecordData;
456
+ }
457
+
458
+ static GetCustSubTotal(LaborList: any, PartsList: any) {
459
+ let LaborTotalAfterDisc: any = this.GetCustLaborTotalAfterDiscount(LaborList);
460
+ let PartsTotalAfterDisc: any = this.GetCustPartsTotalAfterDiscount(PartsList);
461
+ return Add(LaborTotalAfterDisc, PartsTotalAfterDisc);
462
+ }
463
+
464
+ static GetCustLaborTotalAfterDiscount(LaborList: any) {
465
+ let LaborTotalAfterDisc: any = 0;
466
+ LaborList.forEach((Labor: any) => {
467
+ LaborTotalAfterDisc = Add(LaborTotalAfterDisc, Labor.CustAfterLaborDisc);
468
+ });
469
+ return LaborTotalAfterDisc;
470
+ }
471
+
472
+ static GetCustPartsTotalAfterDiscount(PartsList: any) {
473
+ let PartsTotalAfterDisc: any = 0;
474
+ PartsList.forEach((Part: any) => {
475
+ PartsTotalAfterDisc = Add(PartsTotalAfterDisc, Part.CustAfterPartDisc);
476
+ });
477
+ return PartsTotalAfterDisc;
478
+ }
479
+
480
+ static GetCustLaborTaxTotal(opCodesList: any, IsTaxable: boolean, isWorkOrder: boolean) {
481
+ let TotalTaxAmt: any = 0;
482
+ if (IsTaxable) {
483
+ opCodesList.forEach((Labor: any) => {
484
+ if (isWorkOrder) {
485
+ // if (Labor.PBy === PayTypeEnum.Customer) {
486
+ if ((Labor.PBy === PayTypeEnum.Customer || Labor.PBy === PayTypeEnum.Shared)) {
487
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CCGST, Labor.CSGST, Labor.CIGST);
488
+ }
489
+ // }else{
490
+ // TotalTaxAmt = Add(TotalTaxAmt , Labor.ACGST , Labor.ASGST , Labor.AIGST);
491
+ // }
492
+ } else {
493
+ if (Labor.Sts !== LaborStatusEnum.New && Labor.Sts !== LaborStatusEnum.WtngForAppr) {
494
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CCGST, Labor.CSGST, Labor.CIGST);
495
+ } else {
496
+ if (Labor.PBy === PayTypeEnum.Customer) {
497
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ECGST, Labor.ESGST, Labor.EIGST);
498
+ }
499
+ }
500
+ }
501
+ });
502
+ }
503
+ return TotalTaxAmt;
504
+ }
505
+
506
+ static GetCustPartsTaxTotal(OpsList: any, PartsList: any, IsTaxable: boolean, isWorkOrder: boolean) {
507
+ let TotalTaxAmt: any = 0;
508
+ if (IsTaxable) {
509
+ PartsList.forEach((Part: any) => {
510
+ if (!TrUtils.IsNull(Part.CollId)) {
511
+ if (isWorkOrder) {
512
+ if ((Part.PBy === PayTypeEnum.Customer || Part.PBy === PayTypeEnum.Shared)) {
513
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST, Part.CSGST, Part.CIGST);
514
+ }
515
+ } else {
516
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
517
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST, Part.CSGST, Part.CIGST);
518
+ } else {
519
+ if (Part.PBy === PayTypeEnum.Customer) {
520
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ECGST, Part.ESGST, Part.EIGST);
521
+ }
522
+ }
523
+ }
524
+ } else {
525
+ if (isWorkOrder) {
526
+ // if (Part.PBy === PayTypeEnum.Customer) {
527
+ if ((Part.PBy === PayTypeEnum.Customer || Part.PBy === PayTypeEnum.Shared)) {
528
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST, Part.CSGST, Part.CIGST);
529
+ }
530
+ // }else{
531
+ // TotalTaxAmt = Add(TotalTaxAmt , Part.ACGST , Part.ASGST , Part.AIGST);
532
+ // }
533
+ } else {
534
+ let Index: any = OpsList.findIndex((labor: any) => {
535
+ return labor._id === Part.OpId;
536
+ });
537
+ if (Index !== -1) {
538
+ if (OpsList[Index].Sts !== LaborStatusEnum.New && OpsList[Index].Sts !== LaborStatusEnum.WtngForAppr) {
539
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST, Part.CSGST, Part.CIGST);
540
+ } else {
541
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ECGST, Part.ESGST, Part.EIGST);
542
+ }
543
+ } else {
544
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST, Part.CSGST, Part.CIGST);
545
+ }
546
+ }
547
+ }
548
+ });
549
+ }
550
+ return TotalTaxAmt;
551
+ }
552
+
553
+ static GetCustomerTotalBasedOnTaxType(dupRecordData: any, LaborTaxAmount: number, PartsTaxAmount: number, LaborList: any, PartsList: any, IsTaxable: boolean) {
554
+
555
+ let SubTotalWithTax: any = 0;
556
+ let LaborTotalAfterDisc: any = this.GetCustLaborTotalAfterDiscount(LaborList);
557
+ let PartsTotalAfterDisc: any = this.GetCustPartsTotalAfterDiscount(PartsList);
558
+
559
+ if (IsTaxable) {
560
+ SubTotalWithTax = Add(LaborTotalAfterDisc, PartsTotalAfterDisc, LaborTaxAmount, PartsTaxAmount);
561
+ } else {
562
+ SubTotalWithTax = Add(LaborTotalAfterDisc, PartsTotalAfterDisc);
563
+ }
564
+
565
+ return SubTotalWithTax;
566
+ }
567
+
568
+ static GetFinalInsuranceTotalsData(argRecordData: any, dupRecordData: any, detailedInfo: boolean, isWorkOrder: boolean, DecimalsNumber: number) {
569
+ let InsuranceAfterDiscTotals: number = this.GetInsSubTotal(dupRecordData.Ops, dupRecordData.Parts);
570
+
571
+ let InsLaborTaxTotal = this.GetInsLaborTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
572
+
573
+ let InsPartTaxTotal = this.GetInsPartsTaxTotal(dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
574
+
575
+ let InsTotal: any = this.GetInsuranceTotalBasedOnTaxType(InsuranceAfterDiscTotals, InsLaborTaxTotal, InsPartTaxTotal,
576
+ TrUtils.isTaxable(dupRecordData.Settings.Tax));
577
+
578
+ argRecordData.InsTaxTotal = Add(InsLaborTaxTotal, InsPartTaxTotal);
579
+ argRecordData.InsTotal = TrUtils.FixedTo(InsTotal, DecimalsNumber);
580
+
581
+ if (detailedInfo) {
582
+ argRecordData.FixedInsTotal = TrUtils.FixedTo(InsTotal, DecimalsNumber);
583
+ }
584
+
585
+ return argRecordData;
586
+ }
587
+
588
+ static GetInsSubTotal(LaborList: any, PartsList: any) {
589
+ let LaborTotalAfterDisc: any = this.GetInsLaborTotalAfterDiscount(LaborList);
590
+ let PartsTotalAfterDisc: any = this.GetInsPartsTotalAfterDiscount(PartsList);
591
+ return Add(LaborTotalAfterDisc, PartsTotalAfterDisc);
592
+ }
593
+
594
+ static GetInsLaborTotalAfterDiscount(LaborList: any) {
595
+ let LaborTotalAfterDisc: any = 0;
596
+ LaborList.forEach((Labor: any) => {
597
+ LaborTotalAfterDisc = Add(LaborTotalAfterDisc, Labor.InsAfterLaborDisc);
598
+ });
599
+ return LaborTotalAfterDisc;
600
+ }
601
+
602
+ static GetInsPartsTotalAfterDiscount(PartsList: any) {
603
+ let PartsTotalAfterDisc: any = 0;
604
+ PartsList.forEach((Part: any) => {
605
+ PartsTotalAfterDisc = Add(PartsTotalAfterDisc, Part.InsAfterPartDisc);
606
+ });
607
+ return PartsTotalAfterDisc;
608
+ }
609
+
610
+ static GetInsLaborTaxTotal(opCodesList: any, IsTaxable: boolean, isWorkOrder: boolean) {
611
+ let TotalTaxAmt: any = 0;
612
+ if (IsTaxable) {
613
+ opCodesList.forEach((Labor: any) => {
614
+ if (isWorkOrder) {
615
+ if ((Labor.PBy === PayTypeEnum.Insurance || Labor.PBy === PayTypeEnum.Shared)) {
616
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ACGST, Labor.ASGST, Labor.AIGST);
617
+ }
618
+ } else {
619
+ if (Labor.Sts !== LaborStatusEnum.New && Labor.Sts !== LaborStatusEnum.WtngForAppr) {
620
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ACGST, Labor.ASGST, Labor.AIGST);
621
+ } else {
622
+ if (Labor.PBy === PayTypeEnum.Insurance || Labor.PBy === PayTypeEnum.Shared) {
623
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ECGST, Labor.ESGST, Labor.EIGST);
624
+ }
625
+ }
626
+ }
627
+ });
628
+ }
629
+ return TotalTaxAmt;
630
+ }
631
+
632
+ static GetInsPartsTaxTotal(PartsList: any, IsTaxable: boolean, isWorkOrder: boolean) {
633
+ let TotalTaxAmt: any = 0;
634
+ if (IsTaxable) {
635
+ PartsList.forEach((Part: any) => {
636
+ if (!TrUtils.IsNull(Part.CollId) || Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) {
637
+ if (isWorkOrder) {
638
+ if ((Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared)) {
639
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ACGST, Part.ASGST, Part.AIGST);
640
+ }
641
+ } else {
642
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
643
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ACGST, Part.ASGST, Part.AIGST);
644
+ } else {
645
+ if (Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) {
646
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ECGST, Part.ESGST, Part.EIGST);
647
+ }
648
+ }
649
+ }
650
+ }
651
+ });
652
+ }
653
+ return TotalTaxAmt;
654
+ }
655
+
656
+ static GetInsuranceTotalBasedOnTaxType(SubTotal: number, LaborTaxAmount: number, PartsTaxAmount: number, IsTaxable: boolean) {
657
+ let InsTotal: any = 0;
658
+ if (IsTaxable) {
659
+ InsTotal = Add(SubTotal, LaborTaxAmount, PartsTaxAmount);
660
+ } else {
661
+ InsTotal = (SubTotal);
662
+ }
663
+ return InsTotal;
664
+ }
665
+
666
+ static GetDetailedTotalsData(argRecordData: any, dupRecordData: any, TaxCodes: any, isWorkOrder: boolean, DecimalsNumber: number) {
667
+ argRecordData.InsLaborDiscTotal = 0;
668
+ argRecordData.InsPartsDiscTotal = 0;
669
+
670
+ argRecordData.InsLaborTotalAfterDisc = this.GetInsLaborTotalAfterDiscount(dupRecordData.Ops);
671
+ argRecordData.InsPartsTotalAfterDisc = this.GetInsPartsTotalAfterDiscount(dupRecordData.Parts);
672
+
673
+ argRecordData.InsLaborTotalBeforeDisc = Add(argRecordData.InsLaborTotalAfterDisc
674
+ , argRecordData.InsLaborDiscTotal);
675
+ argRecordData.InsPartsTotalBeforeDisc = Add(argRecordData.InsPartsTotalAfterDisc
676
+ , argRecordData.InsPartsDiscTotal);
677
+
678
+ argRecordData.InsLaborITax = this.GetInsLaborTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
679
+ argRecordData.InsLaborCGST = this.GetInsLaborCGSTTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
680
+ argRecordData.InsLaborIGST = this.GetInsLaborIGSTTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
681
+ argRecordData.InsLaborSGST = this.GetInsLaborSGSTTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
682
+
683
+ argRecordData.InsPartITax = this.GetInsPartsTaxTotal(dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
684
+ argRecordData.InsPartCGST = this.GetInsPartCGSTTaxTotal(dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
685
+ argRecordData.InsPartIGST = this.GetInsPartIGSTTaxTotal(dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
686
+ argRecordData.InsPartSGST = this.GetInsPartSGSTTaxTotal(dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
687
+
688
+ argRecordData.InsLaborTotalAfterTax = Add(argRecordData.InsLaborTotalAfterDisc,
689
+ argRecordData.InsLaborITax);
690
+ argRecordData.InsPartsTotalAfterTax = Add(argRecordData.InsPartsTotalAfterDisc,
691
+ argRecordData.InsPartITax);
692
+
693
+ argRecordData.CustLaborDiscTotal = this.GetCustLaborDiscountedTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), dupRecordData);
694
+ argRecordData.CustPartsDiscTotal = this.GetCustPartDiscountedTotal(dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), dupRecordData);
695
+
696
+ argRecordData.CustLaborTotalAfterDisc = this.GetCustLaborTotalAfterDiscount(dupRecordData.Ops);
697
+ argRecordData.CustPartsTotalAfterDisc = this.GetCustPartsTotalAfterDiscount(dupRecordData.Parts);
698
+
699
+ argRecordData.CustLaborTotalBeforeDisc = Add(argRecordData.CustLaborTotalAfterDisc
700
+ , argRecordData.CustLaborDiscTotal);
701
+ argRecordData.CustPartsTotalBeforeDisc = Add(argRecordData.CustPartsTotalAfterDisc
702
+ , argRecordData.CustPartsDiscTotal);
703
+
704
+ argRecordData.CustLaborITax = this.GetCustLaborTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
705
+ argRecordData.CustLaborSGST = this.GetCustLaborSGSTTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
706
+ argRecordData.CustLaborCGST = this.GetCustLaborCGSTTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
707
+ argRecordData.CustLaborIGST = this.GetCustLaborIGSTTaxTotal(dupRecordData.Ops, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
708
+
709
+ argRecordData.CustPartITax = this.GetCustPartsTaxTotal(dupRecordData.Ops, dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
710
+ argRecordData.CustPartCGST = this.GetCustPartCGSTTaxTotal(dupRecordData.Ops, dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
711
+ argRecordData.CustPartIGST = this.GetCustPartIGSTTaxTotal(dupRecordData.Ops, dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
712
+ argRecordData.CustPartSGST = this.GetCustPartSGSTTaxTotal(dupRecordData.Ops, dupRecordData.Parts, TrUtils.isTaxable(dupRecordData.Settings.Tax), isWorkOrder);
713
+
714
+
715
+ argRecordData.CustLaborLDiscAmount = this.GetLaborLDiscAmount(argRecordData.CustLaborTotalAfterDisc, argRecordData.LDisc);
716
+ argRecordData.CustPartsPDiscAmount = this.GetPartsPDiscAmount(argRecordData.CustPartsTotalAfterDisc, argRecordData.PDisc);
717
+
718
+ argRecordData.CustLaborAfterLDisc = argRecordData.CustLaborTotalAfterDisc;
719
+ argRecordData.CustPartsAfterPDisc = argRecordData.CustPartsTotalAfterDisc;
720
+
721
+ argRecordData.CustLaborAfterTax = Add(argRecordData.CustLaborITax, argRecordData.CustLaborAfterLDisc);
722
+ argRecordData.CustPartAfterTax = Add(argRecordData.CustPartITax, argRecordData.CustPartsAfterPDisc);
723
+
724
+ argRecordData.CustTaxGroupData = this.GetCustPartsTaxGrouping(dupRecordData.Parts, TaxCodes, isWorkOrder, DecimalsNumber);
725
+ argRecordData.InsTaxGroupData = this.GetInsPartsTaxGrouping(dupRecordData.Parts, TaxCodes, DecimalsNumber);
726
+
727
+ argRecordData.CustTotalRoundedBy = argRecordData.Round;
728
+ argRecordData.InsTotalRoundedBy = TrUtils.FixedTo(Subtract(Math.round(argRecordData.InsTotal), argRecordData.InsTotal), DecimalsNumber);
729
+
730
+ argRecordData.CustRoundedTotal = argRecordData.Total;
731
+ argRecordData.InsRoundedTotal = Math.round(argRecordData.InsTotal);
732
+
733
+ for (var key in argRecordData) {
734
+ if (key !== 'Total' && key !== 'InsTotal' && key !== 'SubTotal' &&
735
+ key !== 'LDisc' && key !== 'LPerc' && key !== 'PDisc' &&
736
+ key !== 'PPerc' && key !== 'Disc' && key !== 'Perc' && key !== 'Tax'
737
+ && typeof argRecordData[key] === 'number') {
738
+ argRecordData[key] = TrUtils.FixPriceValue(argRecordData[key], DecimalsNumber);
739
+ }
740
+ }
741
+
742
+ return argRecordData;
743
+ }
744
+
745
+ static GetCustLaborDiscountedTotal(LaborList: any, isTaxable: boolean, finalTotalsData: any) {
746
+ let LaborDiscountedTotal: any = 0;
747
+ let overallLaborDisc: number = 0;
748
+ if (!isTaxable) {
749
+ overallLaborDisc = TrUtils.SetValueToZeroIfNull(finalTotalsData.LDisc)
750
+ }
751
+ LaborList.forEach((Labor: any) => {
752
+ LaborDiscountedTotal = Add(LaborDiscountedTotal, Labor.CustDiscountedPrice);
753
+ });
754
+ return Add(LaborDiscountedTotal, overallLaborDisc);
755
+ }
756
+
757
+ static GetCustPartDiscountedTotal(PartsList: any, isTaxable: boolean, finalTotalsData: any) {
758
+ let PartsDiscountedTotal: any = 0;
759
+ let overallPartDisc: number = 0;
760
+ if (!isTaxable) {
761
+ overallPartDisc = TrUtils.SetValueToZeroIfNull(finalTotalsData.PDisc)
762
+ }
763
+ PartsList.forEach((Part: any) => {
764
+ PartsDiscountedTotal = Add(PartsDiscountedTotal, Part.CustDiscountedPrice);
765
+ });
766
+ return Add(PartsDiscountedTotal, overallPartDisc);
767
+ }
768
+
769
+ static GetCustLaborCGSTTaxTotal(opCodesList: any, IsTaxable: boolean, isWorkOrder: boolean) {
770
+ let TotalTaxAmt: any = 0;
771
+ if (IsTaxable) {
772
+ opCodesList.forEach((Labor: any) => {
773
+ if (isWorkOrder) {
774
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CCGST);
775
+ } else {
776
+ if (Labor.Sts !== LaborStatusEnum.New && Labor.Sts !== LaborStatusEnum.WtngForAppr) {
777
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CCGST);
778
+ } else {
779
+ if (Labor.PBy === PayTypeEnum.Customer) {
780
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ECGST);
781
+ }
782
+ }
783
+ }
784
+ });
785
+ }
786
+ return TotalTaxAmt;
787
+ }
788
+
789
+ static GetCustLaborIGSTTaxTotal(opCodesList: any, IsTaxable: boolean, isWorkOrder: boolean) {
790
+ let TotalTaxAmt: any = 0;
791
+ if (IsTaxable) {
792
+ opCodesList.forEach((Labor: any) => {
793
+ if (isWorkOrder) {
794
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CIGST);
795
+ } else {
796
+ if (Labor.Sts !== LaborStatusEnum.New && Labor.Sts !== LaborStatusEnum.WtngForAppr) {
797
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CIGST);
798
+ } else {
799
+ if (Labor.PBy === PayTypeEnum.Customer) {
800
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.EIGST);
801
+ }
802
+ }
803
+ }
804
+ });
805
+ }
806
+ return TotalTaxAmt;
807
+ }
808
+
809
+ static GetCustLaborSGSTTaxTotal(opCodesList: any, IsTaxable: boolean, isWorkOrder: boolean) {
810
+ let TotalTaxAmt: any = 0;
811
+ if (IsTaxable) {
812
+ opCodesList.forEach((Labor: any) => {
813
+ if (isWorkOrder) {
814
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CSGST);
815
+ } else {
816
+ if (Labor.Sts !== LaborStatusEnum.New && Labor.Sts !== LaborStatusEnum.WtngForAppr) {
817
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.CSGST);
818
+ } else {
819
+ if (Labor.PBy === PayTypeEnum.Customer) {
820
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ESGST);
821
+ }
822
+ }
823
+ }
824
+ });
825
+ }
826
+ return TotalTaxAmt;
827
+ }
828
+
829
+ static GetCustPartCGSTTaxTotal(OpsList: any, PartsList: any, IsTaxable: boolean, isWorkOrder: boolean) {
830
+ let TotalTaxAmt: any = 0;
831
+ if (IsTaxable) {
832
+ PartsList.forEach((Part: any) => {
833
+ if (!TrUtils.IsNull(Part.CollId)) {
834
+ if (isWorkOrder) {
835
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST);
836
+ } else {
837
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
838
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST);
839
+ } else {
840
+ if (Part.PBy === PayTypeEnum.Customer) {
841
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ECGST);
842
+ }
843
+ }
844
+ }
845
+ } else {
846
+ if (isWorkOrder) {
847
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST);
848
+ } else {
849
+ let Index: any = OpsList.findIndex((labor: any) => {
850
+ return labor._id === Part.OpId;
851
+ });
852
+ if (Index !== -1) {
853
+ if (OpsList[Index].Sts !== LaborStatusEnum.New && OpsList[Index].Sts !== LaborStatusEnum.WtngForAppr) {
854
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST);
855
+ } else {
856
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ECGST);
857
+ }
858
+ } else {
859
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CCGST);
860
+ }
861
+ }
862
+ }
863
+ });
864
+ }
865
+ return TotalTaxAmt;
866
+ }
867
+
868
+ static GetCustPartIGSTTaxTotal(OpsList: any, PartsList: any, IsTaxable: boolean, isWorkOrder: boolean) {
869
+ let TotalTaxAmt: any = 0;
870
+ if (IsTaxable) {
871
+ PartsList.forEach((Part: any) => {
872
+ if (!TrUtils.IsNull(Part.CollId)) {
873
+ if (isWorkOrder) {
874
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CIGST);
875
+ } else {
876
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
877
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CIGST);
878
+ } else {
879
+ if (Part.PBy === PayTypeEnum.Customer) {
880
+ TotalTaxAmt = Add(TotalTaxAmt, Part.EIGST);
881
+ }
882
+ }
883
+ }
884
+ } else {
885
+ if (isWorkOrder) {
886
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CIGST);
887
+ } else {
888
+ let Index: any = OpsList.findIndex((labor: any) => {
889
+ return labor._id === Part.OpId;
890
+ });
891
+ if (Index !== -1) {
892
+ if (OpsList[Index].Sts !== LaborStatusEnum.New && OpsList[Index].Sts !== LaborStatusEnum.WtngForAppr) {
893
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CIGST);
894
+ } else {
895
+ TotalTaxAmt = Add(TotalTaxAmt, Part.EIGST);
896
+ }
897
+ } else {
898
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CIGST);
899
+ }
900
+ }
901
+ }
902
+ });
903
+ }
904
+ return TotalTaxAmt;
905
+ }
906
+
907
+ static GetCustPartSGSTTaxTotal(OpsList: any, PartsList: any, IsTaxable: boolean, isWorkOrder: boolean) {
908
+ let TotalTaxAmt: any = 0;
909
+ if (IsTaxable) {
910
+ PartsList.forEach((Part: any) => {
911
+ if (!TrUtils.IsNull(Part.CollId)) {
912
+ if (isWorkOrder) {
913
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CSGST);
914
+ } else {
915
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
916
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CSGST);
917
+ } else {
918
+ if (Part.PBy === PayTypeEnum.Customer) {
919
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ESGST);
920
+ }
921
+ }
922
+ }
923
+ } else {
924
+ if (isWorkOrder) {
925
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CSGST);
926
+ } else {
927
+ let Index: any = OpsList.findIndex((labor: any) => {
928
+ return labor._id === Part.OpId;
929
+ });
930
+ if (Index !== -1) {
931
+ if (OpsList[Index].Sts !== LaborStatusEnum.New && OpsList[Index].Sts !== LaborStatusEnum.WtngForAppr) {
932
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CSGST);
933
+ } else {
934
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ESGST);
935
+ }
936
+ } else {
937
+ TotalTaxAmt = Add(TotalTaxAmt, Part.CSGST);
938
+ }
939
+ }
940
+ }
941
+ });
942
+ }
943
+ return TotalTaxAmt;
944
+ }
945
+
946
+ static GetInsLaborCGSTTaxTotal(opCodesList: any, IsTaxable: boolean, isWorkOrder: boolean) {
947
+ let TotalTaxAmt: any = 0;
948
+ if (IsTaxable) {
949
+ opCodesList.forEach((Labor: any) => {
950
+ if (isWorkOrder) {
951
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ACGST);
952
+ } else {
953
+ if (Labor.Sts !== LaborStatusEnum.New && Labor.Sts !== LaborStatusEnum.WtngForAppr) {
954
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ACGST);
955
+ } else {
956
+ if (Labor.PBy === PayTypeEnum.Insurance || Labor.PBy === PayTypeEnum.Shared) {
957
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ECGST);
958
+ }
959
+ }
960
+ }
961
+ });
962
+ }
963
+ return TotalTaxAmt;
964
+ }
965
+
966
+ static GetInsLaborIGSTTaxTotal(opCodesList: any, IsTaxable: boolean, isWorkOrder: boolean) {
967
+ let TotalTaxAmt: any = 0;
968
+ if (IsTaxable) {
969
+ opCodesList.forEach((Labor: any) => {
970
+ if (isWorkOrder) {
971
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.AIGST);
972
+ } else {
973
+ if (Labor.Sts !== LaborStatusEnum.New && Labor.Sts !== LaborStatusEnum.WtngForAppr) {
974
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.AIGST);
975
+ } else {
976
+ if (Labor.PBy === PayTypeEnum.Insurance || Labor.PBy === PayTypeEnum.Shared) {
977
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.EIGST);
978
+ }
979
+ }
980
+ }
981
+ });
982
+ }
983
+ return TotalTaxAmt;
984
+ }
985
+
986
+ static GetInsLaborSGSTTaxTotal(opCodesList: any, IsTaxable: boolean, isWorkOrder: boolean) {
987
+ let TotalTaxAmt: any = 0;
988
+ if (IsTaxable) {
989
+ opCodesList.forEach((Labor: any) => {
990
+ if (isWorkOrder) {
991
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ASGST);
992
+ } else {
993
+ if (Labor.Sts !== LaborStatusEnum.New && Labor.Sts !== LaborStatusEnum.WtngForAppr) {
994
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ASGST);
995
+ } else {
996
+ if (Labor.PBy === PayTypeEnum.Insurance || Labor.PBy === PayTypeEnum.Shared) {
997
+ TotalTaxAmt = Add(TotalTaxAmt, Labor.ESGST);
998
+ }
999
+ }
1000
+ }
1001
+ });
1002
+ }
1003
+ return TotalTaxAmt;
1004
+ }
1005
+
1006
+ static GetInsPartCGSTTaxTotal(PartsList: any, IsTaxable: boolean, isWorkOrder: boolean) {
1007
+ let TotalTaxAmt: any = 0;
1008
+ if (IsTaxable) {
1009
+ PartsList.forEach((Part: any) => {
1010
+ if (!TrUtils.IsNull(Part.CollId) || Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) {
1011
+ if (isWorkOrder) {
1012
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ACGST);
1013
+ } else {
1014
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
1015
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ACGST);
1016
+ } else {
1017
+ if (Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) {
1018
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ECGST);
1019
+ }
1020
+ }
1021
+ }
1022
+ }
1023
+ });
1024
+ }
1025
+ return TotalTaxAmt;
1026
+ }
1027
+
1028
+ static GetInsPartIGSTTaxTotal(PartsList: any, IsTaxable: boolean, isWorkOrder: boolean) {
1029
+ let TotalTaxAmt: any = 0;
1030
+ if (IsTaxable) {
1031
+ PartsList.forEach((Part: any) => {
1032
+ if (!TrUtils.IsNull(Part.CollId) || Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) {
1033
+ if (isWorkOrder) {
1034
+ TotalTaxAmt = Add(TotalTaxAmt, Part.AIGST);
1035
+ } else {
1036
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
1037
+ TotalTaxAmt = Add(TotalTaxAmt, Part.AIGST);
1038
+ } else {
1039
+ if (Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) {
1040
+ TotalTaxAmt = Add(TotalTaxAmt, Part.EIGST);
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+ });
1046
+ }
1047
+ return TotalTaxAmt;
1048
+ }
1049
+
1050
+ static GetInsPartSGSTTaxTotal(PartsList: any, IsTaxable: boolean, isWorkOrder: boolean) {
1051
+ let TotalTaxAmt: any = 0;
1052
+ if (IsTaxable) {
1053
+ PartsList.forEach((Part: any) => {
1054
+ if (!TrUtils.IsNull(Part.CollId) || Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) {
1055
+ if (isWorkOrder) {
1056
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ASGST);
1057
+ } else {
1058
+ if (Part.Sts !== LaborStatusEnum.New && Part.Sts !== LaborStatusEnum.WtngForAppr) {
1059
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ASGST);
1060
+ } else {
1061
+ if (Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) {
1062
+ TotalTaxAmt = Add(TotalTaxAmt, Part.ESGST);
1063
+ }
1064
+ }
1065
+ }
1066
+ }
1067
+ });
1068
+ }
1069
+ return TotalTaxAmt;
1070
+ }
1071
+
1072
+ static GetLaborLDiscAmount(LaborTotalAfterDisc: any, LDisc: any) {
1073
+ let LaborLDiscAmt: any = 0;
1074
+
1075
+ if (!TrUtils.IsZero(LaborTotalAfterDisc)) {
1076
+ LaborLDiscAmt = LDisc;
1077
+ }
1078
+ return LaborLDiscAmt;
1079
+ }
1080
+
1081
+ static GetPartsPDiscAmount(PartsTotalAfterDisc: any, PDisc: any) {
1082
+ let PartsPDiscAmt: any = 0;
1083
+
1084
+ if (!TrUtils.IsZero(PartsTotalAfterDisc)) {
1085
+ PartsPDiscAmt = PDisc;
1086
+ }
1087
+
1088
+ return PartsPDiscAmt;
1089
+ }
1090
+
1091
+ static GetCustPartsTaxGrouping(PartsList: any, TaxCodes: any, isWorkOrder: boolean, DecimalsNumber: number) {
1092
+ let FilteredPartsList = this.GetCustParts(PartsList);
1093
+ return this.GetCustTaxGroupingForPartsByHSN(FilteredPartsList, TaxCodes, isWorkOrder, DecimalsNumber);
1094
+ }
1095
+
1096
+ static GetCustParts(PartsList: any) {
1097
+ let FilteredPartsList: any[] = PartsList.filter((Part: any) => {
1098
+ return Part.PBy === PayTypeEnum.Customer || Part.PBy === PayTypeEnum.Shared;
1099
+ });
1100
+ return FilteredPartsList;
1101
+ }
1102
+
1103
+ static GetCustTaxGroupingForPartsByHSN(Parts: any, TaxCodes: any, isWorkOrder: boolean, DecimalsNumber: number) {
1104
+ Parts = this.GetCombinedTaxPercentage(Parts, TaxCodes);
1105
+ Parts = this.ResetPartsHSNIfInvalid(Parts);
1106
+
1107
+ let FinalMatchedParts: any[] = this.ComparePartsByHSN(Parts, TaxCodes);
1108
+
1109
+ return this.GetCustTaxGroupingInfoByHSN(FinalMatchedParts, TaxCodes, isWorkOrder, DecimalsNumber);
1110
+ }
1111
+
1112
+ static GetCustTaxGroupingInfoByHSN(FinalMatchedParts: any, TaxCodes: any, isWorkOrder: boolean, DecimalsNumber: number) {
1113
+ let HSNTaxInfo: any[] = [];
1114
+ FinalMatchedParts.forEach((MatchedPart: any) => {
1115
+ let TaxInfo: any = {};
1116
+ let TaxOnAmount: any = 0;
1117
+ let TaxAmount: any = 0;
1118
+ let HSN: any = MatchedPart[0].HSN;
1119
+ TaxInfo.CombinedTaxPercentage = MatchedPart[0].CombinedTaxPercentage;
1120
+ MatchedPart.forEach((argMatchedGSTPart: any) => {
1121
+ TaxOnAmount = Add(TaxOnAmount, TrUtils.FixedTo(argMatchedGSTPart.CustAfterPartDisc, DecimalsNumber));
1122
+ if (isWorkOrder) {
1123
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CCGST, DecimalsNumber));
1124
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CIGST, DecimalsNumber));
1125
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CSGST, DecimalsNumber));
1126
+ } else {
1127
+ if (argMatchedGSTPart.Sts !== LaborStatusEnum.New && argMatchedGSTPart.Sts !== LaborStatusEnum.WtngForAppr) {
1128
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CCGST, DecimalsNumber));
1129
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CIGST, DecimalsNumber));
1130
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.CSGST, DecimalsNumber));
1131
+ } else {
1132
+ if (argMatchedGSTPart.PBy === PayTypeEnum.Customer) {
1133
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.ECGST, DecimalsNumber));
1134
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.EIGST, DecimalsNumber));
1135
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.ESGST, DecimalsNumber));
1136
+ }
1137
+ }
1138
+ }
1139
+ });
1140
+ TaxInfo.HSN = HSN;
1141
+ TaxInfo.TotalTaxableAmount = TrUtils.FixPriceValue(TaxOnAmount, DecimalsNumber);
1142
+ TaxInfo.TotalTaxAmount = TrUtils.FixPriceValue(TaxAmount, DecimalsNumber);
1143
+ TaxInfo.PartsCount = MatchedPart.length;
1144
+ let GSTValues: any[] = this.GetGSTValueBasedOnTaxCode(MatchedPart[0], TaxCodes);
1145
+ TaxInfo.CGST = GSTValues[0];
1146
+ TaxInfo.SGST = GSTValues[1];
1147
+ TaxInfo.IGST = GSTValues[2];
1148
+ if (TaxOnAmount !== 0) {
1149
+ HSNTaxInfo.push(TaxInfo);
1150
+ }
1151
+ });
1152
+ return HSNTaxInfo;
1153
+ }
1154
+
1155
+ static GetInsPartsTaxGrouping(PartsList: any, TaxCodes: any, DecimalsNumber: number) {
1156
+ let FilteredPartsList = this.GetInsParts(PartsList);
1157
+ return this.GetInsTaxGroupingForPartsByHSN(FilteredPartsList, TaxCodes, DecimalsNumber);
1158
+ }
1159
+
1160
+ static GetInsParts(PartsList: any) {
1161
+ let FilteredPartsList: any[] = PartsList.filter((Part: any) => {
1162
+ return Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared;
1163
+ });
1164
+ return FilteredPartsList;
1165
+ }
1166
+
1167
+ static GetInsTaxGroupingForPartsByHSN(Parts: any, TaxCodes: any, DecimalsNumber: number) {
1168
+ Parts = this.GetCombinedTaxPercentage(Parts, TaxCodes);
1169
+ Parts = this.ResetPartsHSNIfInvalid(Parts);
1170
+
1171
+ let FinalMatchedParts: any[] = this.ComparePartsByHSN(Parts, TaxCodes);
1172
+
1173
+ return this.GetInsTaxGroupingInfoByHSN(FinalMatchedParts, TaxCodes, DecimalsNumber);
1174
+ }
1175
+
1176
+ static GetInsTaxGroupingInfoByHSN(FinalMatchedParts: any, TaxCodes: any, DecimalsNumber: number) {
1177
+ let HSNTaxInfo: any[] = [];
1178
+ FinalMatchedParts.forEach((MatchedPart: any) => {
1179
+ let TaxInfo: any = {};
1180
+ let TaxOnAmount: any = 0;
1181
+ let TaxAmount: any = 0;
1182
+ let HSN: any = MatchedPart[0].HSN;
1183
+ TaxInfo.CombinedTaxPercentage = MatchedPart[0].CombinedTaxPercentage;
1184
+ MatchedPart.forEach((argMatchedGSTPart: any) => {
1185
+ TaxOnAmount = Add(TaxOnAmount, TrUtils.FixedTo(argMatchedGSTPart.InsAfterPartDisc, DecimalsNumber));
1186
+ if (argMatchedGSTPart.PBy === PayTypeEnum.Insurance || argMatchedGSTPart.PBy === PayTypeEnum.Shared) {
1187
+ if (argMatchedGSTPart.Sts !== LaborStatusEnum.New && argMatchedGSTPart.Sts !== LaborStatusEnum.WtngForAppr) {
1188
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.ACGST, DecimalsNumber));
1189
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.AIGST, DecimalsNumber));
1190
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.ASGST, DecimalsNumber));
1191
+ } else {
1192
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.ECGST, DecimalsNumber));
1193
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.EIGST, DecimalsNumber));
1194
+ TaxAmount = Add(TaxAmount, TrUtils.FixedTo(argMatchedGSTPart.ESGST, DecimalsNumber));
1195
+ }
1196
+ }
1197
+ });
1198
+ TaxInfo.HSN = HSN;
1199
+ TaxInfo.TotalTaxableAmount = TrUtils.FixPriceValue(TaxOnAmount, DecimalsNumber);
1200
+ TaxInfo.TotalTaxAmount = TrUtils.FixPriceValue(TaxAmount, DecimalsNumber);
1201
+ TaxInfo.PartsCount = MatchedPart.length;
1202
+ let GSTValues: any[] = this.GetGSTValueBasedOnTaxCode(MatchedPart[0], TaxCodes);
1203
+ TaxInfo.CGST = GSTValues[0];
1204
+ TaxInfo.SGST = GSTValues[1];
1205
+ TaxInfo.IGST = GSTValues[2];
1206
+ if (TaxOnAmount !== 0) {
1207
+ HSNTaxInfo.push(TaxInfo);
1208
+ }
1209
+ });
1210
+ return HSNTaxInfo;
1211
+ }
1212
+
1213
+ static GetGSTValueBasedOnTaxCode(item: any, TaxCodes: any) {
1214
+ let CGST: number = 0;
1215
+ let SGST: number = 0;
1216
+ let IGST: number = 0;
1217
+ const taxGroupKeys: string[] = ['Taxes', 'CTaxes', 'ATaxes', 'ETaxes'];
1218
+
1219
+ for (const taxGroupKey of taxGroupKeys) {
1220
+ const groupedTaxes = item?.[taxGroupKey];
1221
+ if (!Array.isArray(groupedTaxes) || groupedTaxes.length === 0) {
1222
+ continue;
1223
+ }
1224
+
1225
+ CGST = groupedTaxes
1226
+ .filter((tax: any) => tax?.Code === 'CGST')
1227
+ .reduce((total: number, tax: any) => Add(total, tax?.Rate), 0);
1228
+ SGST = groupedTaxes
1229
+ .filter((tax: any) => tax?.Code === 'SGST')
1230
+ .reduce((total: number, tax: any) => Add(total, tax?.Rate), 0);
1231
+ IGST = groupedTaxes
1232
+ .filter((tax: any) => tax?.Code === 'IGST')
1233
+ .reduce((total: number, tax: any) => Add(total, tax?.Rate), 0);
1234
+
1235
+ if (!TrUtils.IsZero(Add(CGST, SGST, IGST))) {
1236
+ return [CGST, SGST, IGST];
1237
+ }
1238
+ }
1239
+
1240
+ const TCode = item?.TCode;
1241
+ if (TrUtils.IsNull(TCode)) {
1242
+ return [CGST, SGST, IGST];
1243
+ }
1244
+ let TCodeIndex: any = TaxCodes.findIndex((TaxCode: any) => {
1245
+ return TaxCode._id === Number(TCode);
1246
+ });
1247
+ if (TCodeIndex !== -1) {
1248
+ if (TaxCodes[TCodeIndex].Type === 'Intra') {
1249
+ return [TaxCodes[TCodeIndex].CGST, TaxCodes[TCodeIndex].SGST, 0];
1250
+ } else {
1251
+ return [0, 0, TaxCodes[TCodeIndex].IGST];
1252
+ }
1253
+ } else {
1254
+ return [CGST, SGST, IGST];
1255
+ }
1256
+ }
1257
+
1258
+ static GetCombinedTaxPercentage(Parts: any, TaxCodes: any) {
1259
+ Parts.forEach((Part: any) => {
1260
+ let GSTValues: any[] = this.GetGSTValueBasedOnTaxCode(Part, TaxCodes);
1261
+ let CGST = GSTValues[0];
1262
+ let SGST = GSTValues[1];
1263
+ let IGST = GSTValues[2];
1264
+
1265
+ Part.CombinedTaxPercentage = Add(CGST, SGST, IGST);
1266
+ });
1267
+ return Parts;
1268
+ }
1269
+
1270
+ static ResetPartsHSNIfInvalid(Parts: any) {
1271
+ Parts.forEach((Part: any) => {
1272
+ if (TrUtils.IsNull(Part.HSN)) {
1273
+ Part.HSN = '';
1274
+ }
1275
+ });
1276
+ return Parts;
1277
+ }
1278
+
1279
+ static ComparePartsByHSN(Parts: any, TaxCodes: any) {
1280
+ let FinalMatchedParts: any[] = [];
1281
+ Parts.forEach((Part: any) => {
1282
+ let MatchedPartsBasedOnHSN = Parts.filter((argPart: any) => {
1283
+ let PartFound: boolean = false;
1284
+ FinalMatchedParts.forEach((FinalArgParts: any) => {
1285
+ let PartIndex: any = FinalArgParts.findIndex((FinalArgPart: any) => {
1286
+ return FinalArgPart._id === argPart._id;
1287
+ });
1288
+ if (PartIndex !== -1) {
1289
+ PartFound = true;
1290
+ }
1291
+ });
1292
+
1293
+ let argGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(argPart, TaxCodes);
1294
+ let argCGST = argGSTValues[0];
1295
+ let argSGST = argGSTValues[1];
1296
+ let argIGST = argGSTValues[2];
1297
+
1298
+ let partGSTValues: any[] = this.GetGSTValueBasedOnTaxCode(Part, TaxCodes);
1299
+ let partCGST = partGSTValues[0];
1300
+ let partSGST = partGSTValues[1];
1301
+ let partIGST = partGSTValues[2];
1302
+
1303
+ return (argPart.HSN === Part.HSN) && (!PartFound) &&
1304
+ (argCGST === partCGST) && (argIGST === partIGST) &&
1305
+ (argSGST === partSGST);
1306
+ });
1307
+ if (MatchedPartsBasedOnHSN.length !== 0) {
1308
+ FinalMatchedParts.push(MatchedPartsBasedOnHSN);
1309
+ }
1310
+ });
1311
+ return FinalMatchedParts;
1312
+ }
1313
+
1314
+ }