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,368 @@
1
+ import { CalcDiscPrice, GetMarginValue } from "../../shared/math-operations";
2
+ import { IsNotNull, IsNull } from "../../shared/util";
3
+
4
+ export function GetItemPriceForPriceList(
5
+ item: any,
6
+ priceList: any,
7
+ includeMargin: boolean = false,
8
+ quantity: number = 1,
9
+ pricingContext: any = {}
10
+ ): any {
11
+ if (!priceList) {
12
+ return item;
13
+ }
14
+
15
+ const resolvedQty = Math.max(1, Number(quantity) || 1);
16
+ const calcDisc: any = priceList.CalcDisc ?? {};
17
+ const markUp: boolean = calcDisc.Mark ?? false;
18
+ const priceListId = priceList?._id?.toString?.();
19
+
20
+ let salePricesByPriceListId: any[] = [];
21
+
22
+ if (priceListId && IsNotNull(item.SalePrices) && item.SalePrices.length > 0) {
23
+ salePricesByPriceListId = item.SalePrices.filter(
24
+ (price: any) => price?.PrListId && price.PrListId.toString() === priceListId
25
+ );
26
+ }
27
+
28
+ item.PriceTiers = priceList?.QtyTiers ?? undefined;
29
+ item.AppliedPriceTier = undefined;
30
+
31
+ if (salePricesByPriceListId.length > 0) {
32
+ item.SalePrices = salePricesByPriceListId;
33
+ const activeSalePrice = salePricesByPriceListId[0];
34
+ const activeTierList = activeSalePrice?.QtyTiers ?? priceList?.QtyTiers;
35
+ if (activeTierList) {
36
+ item.PriceTiers = activeTierList;
37
+ }
38
+
39
+ if (item.Track === "TR" || item.Track === "SN") {
40
+ item.Sale["MRP"] = item.Sale.Price;
41
+ const tier = ResolveTier(resolvedQty, activeSalePrice?.QtyTiers);
42
+
43
+ if (tier) {
44
+ const baseForTier = IsNotNull(activeSalePrice.Price) ? activeSalePrice.Price : item.Sale.Price;
45
+ item.Sale.Price = ApplyTierAdjustment(baseForTier, tier, priceList, false);
46
+ item.AppliedPriceTier = BuildAppliedTierMeta("ITEM", tier);
47
+ } else if (IsNotNull(activeSalePrice.Price) && IsNotNull(activeSalePrice.Disc)) {
48
+ item.Sale.Price = CalcItemFinalSalePrice(activeSalePrice.Price, activeSalePrice.Disc, priceList, markUp);
49
+ } else if (IsNotNull(activeSalePrice.Price) && IsNull(activeSalePrice.Disc)) {
50
+ item.Sale.Price = ApplyRounding(activeSalePrice.Price, priceList);
51
+ } else if (IsNull(activeSalePrice.Price) && IsNotNull(activeSalePrice.Disc)) {
52
+ item.Sale.Price = CalcItemFinalSalePrice(item.Sale.Price, activeSalePrice.Disc, priceList, markUp);
53
+ }
54
+
55
+ if (includeMargin && IsNotNull(item.Pur) && IsNotNull(item.Pur.Cost)) {
56
+ item.Margin = GetMarginValue(item.Sale.Price, item.Pur.Cost);
57
+ }
58
+ } else if (item.Track === "BN" && Array.isArray(item.Batches)) {
59
+ for (const element of item.Batches) {
60
+ const batchSalePrice = item.SalePrices.filter(
61
+ (batch: any) =>
62
+ priceListId === batch?.PrListId?.toString() &&
63
+ (element.BN === batch.BN || batch.BN == null)
64
+ );
65
+
66
+ const activeBatchSale = batchSalePrice.length > 0 ? batchSalePrice[0] : undefined;
67
+ const tierList =
68
+ activeBatchSale?.QtyTiers ?? activeSalePrice?.QtyTiers ?? priceList?.QtyTiers;
69
+ if (tierList) {
70
+ element.PriceTiers = tierList;
71
+ }
72
+
73
+ element.MRP = element.Price;
74
+
75
+ const tier = ResolveTier(resolvedQty, activeBatchSale?.QtyTiers ?? activeSalePrice?.QtyTiers);
76
+
77
+ if (tier) {
78
+ const baseForTier = IsNotNull(activeBatchSale?.Price) ? activeBatchSale.Price : element.Price;
79
+ element.Price = ApplyTierAdjustment(baseForTier, tier, priceList, false);
80
+ element.AppliedPriceTier = BuildAppliedTierMeta("ITEM", tier);
81
+ } else if (activeBatchSale) {
82
+ if (IsNotNull(activeBatchSale.Price) && IsNotNull(activeBatchSale.Disc)) {
83
+ element.Price = CalcItemFinalSalePrice(activeBatchSale.Price, activeBatchSale.Disc, priceList, markUp);
84
+ } else if (IsNotNull(activeBatchSale.Price) && IsNull(activeBatchSale.Disc)) {
85
+ element.Price = ApplyRounding(activeBatchSale.Price, priceList);
86
+ } else if (IsNull(activeBatchSale.Price) && IsNotNull(activeBatchSale.Disc)) {
87
+ element.Price = CalcItemFinalSalePrice(element.Price, activeBatchSale.Disc, priceList, markUp);
88
+ }
89
+ }
90
+
91
+ if (includeMargin && IsNotNull(element.Cost)) {
92
+ element.Margin = GetMarginValue(element.Price, element.Cost);
93
+ }
94
+ }
95
+ }
96
+
97
+ return item;
98
+ }
99
+
100
+ return CalculatePriceBasedOnPriceList(item, priceList, includeMargin, resolvedQty);
101
+ }
102
+
103
+ /**
104
+ * Calculates the final sale price of an item after applying a discount and optional markup.
105
+ * Optionally includes margin calculation based on cost.
106
+ *
107
+ * @param price - The original price of the item.
108
+ * @param disc - The discount percentage to apply.
109
+ * @param priceList - The price list object containing rounding and other configurations.
110
+ * @param markup - Whether to apply markup instead of discount (default is false).
111
+ * @param includeMargin - Whether to include margin calculation in the result (default is false).
112
+ * @param cost - The cost of the item, used for margin calculation (default is 0).
113
+ * @returns The final price or an object containing margin and final price if includeMargin is true.
114
+ */
115
+ export function CalcItemFinalSalePrice(
116
+ price: number,
117
+ disc: number,
118
+ priceList: any,
119
+ markup: boolean = false,
120
+ includeMargin: boolean = false,
121
+ cost: number = 0
122
+ ): any {
123
+ const calculatedPrice = CalcDiscPrice(price, disc, markup);
124
+ const finalPrice = ApplyRounding(calculatedPrice, priceList);
125
+
126
+ if (includeMargin) {
127
+ const margin = GetMarginValue(finalPrice, cost);
128
+ return { margin: margin, finalPrice: finalPrice };
129
+ }
130
+
131
+ return finalPrice;
132
+ }
133
+
134
+ function CalculatePriceBasedOnPriceList(
135
+ item: any,
136
+ priceList: any,
137
+ includeMargin: boolean,
138
+ quantity: number
139
+ ): any {
140
+ if (!priceList) {
141
+ return item;
142
+ }
143
+
144
+ const calcDisc: any = priceList.CalcDisc ?? {};
145
+ const markUp: boolean = calcDisc.Mark ?? false;
146
+ const resolvedQty = Math.max(1, Number(quantity) || 1);
147
+ const tier = ResolveTier(resolvedQty, priceList.QtyTiers);
148
+
149
+ if (tier) {
150
+ item.PriceTiers = priceList.QtyTiers ?? undefined;
151
+
152
+ if (item.Track === "TR" || item.Track === "SN") {
153
+ item.Sale["MRP"] = item.Sale.Price;
154
+ const basePrice = DetermineBasePriceForTier(item, priceList);
155
+ item.Sale.Price = ApplyTierAdjustment(basePrice, tier, priceList, markUp);
156
+ item.AppliedPriceTier = BuildAppliedTierMeta("PRICELIST", tier);
157
+
158
+ if (includeMargin && IsNotNull(item.Pur) && IsNotNull(item.Pur.Cost)) {
159
+ item.Margin = GetMarginValue(item.Sale.Price, item.Pur.Cost);
160
+ }
161
+ } else if (item.Track === "BN" && Array.isArray(item.Batches)) {
162
+ for (const batch of item.Batches) {
163
+ batch.MRP = batch.Price;
164
+ const basePrice = DetermineBatchBasePriceForTier(batch, item, priceList);
165
+ batch.Price = ApplyTierAdjustment(basePrice, tier, priceList, markUp);
166
+ batch.AppliedPriceTier = BuildAppliedTierMeta("PRICELIST", tier);
167
+
168
+ if (includeMargin && IsNotNull(batch.Cost)) {
169
+ batch.Margin = GetMarginValue(batch.Price, batch.Cost);
170
+ }
171
+ }
172
+ }
173
+
174
+ return item;
175
+ }
176
+
177
+ if (priceList.PrCalc === "FIXED") {
178
+ if (priceList.Fixed && IsNotNull(priceList.Fixed.Price)) {
179
+ const fixedPrice = priceList.Fixed.Price;
180
+ const fixedDisc = priceList.Fixed.Disc || 0;
181
+
182
+ if (item.Track === "TR" || item.Track === "SN") {
183
+ item.Sale["MRP"] = item.Sale.Price;
184
+ if (IsNotNull(fixedDisc) && fixedDisc > 0) {
185
+ item.Sale.Price = CalcItemFinalSalePrice(fixedPrice, fixedDisc, priceList);
186
+ } else {
187
+ item.Sale.Price = ApplyRounding(fixedPrice, priceList);
188
+ }
189
+
190
+ if (includeMargin && IsNotNull(item.Pur) && IsNotNull(item.Pur.Cost)) {
191
+ item.Margin = GetMarginValue(item.Sale.Price, item.Pur.Cost);
192
+ }
193
+ } else if (item.Track === "BN" && Array.isArray(item.Batches)) {
194
+ for (const batch of item.Batches) {
195
+ batch.MRP = batch.Price;
196
+ if (IsNotNull(fixedDisc) && fixedDisc > 0) {
197
+ batch.Price = CalcItemFinalSalePrice(fixedPrice, fixedDisc, priceList);
198
+ } else {
199
+ batch.Price = ApplyRounding(fixedPrice, priceList);
200
+ }
201
+ if (includeMargin && IsNotNull(batch.Cost)) {
202
+ batch.Margin = GetMarginValue(batch.Price, batch.Cost);
203
+ }
204
+ }
205
+ }
206
+ }
207
+ } else if (priceList.PrCalc === "DISC") {
208
+ const discPerc: number = calcDisc.Perc || 0;
209
+
210
+ if (priceList.BasedOn === "SP") {
211
+ if (item.Track === "TR" || item.Track === "SN") {
212
+ item.Sale["MRP"] = item.Sale.Price;
213
+ item.Sale.Price = CalcItemFinalSalePrice(item.Sale.Price, discPerc, priceList, markUp);
214
+
215
+ if (includeMargin && IsNotNull(item.Pur) && IsNotNull(item.Pur.Cost)) {
216
+ item.Margin = GetMarginValue(item.Sale.Price, item.Pur.Cost);
217
+ }
218
+ } else if (item.Track === "BN" && Array.isArray(item.Batches)) {
219
+ for (const batch of item.Batches) {
220
+ batch.MRP = batch.Price;
221
+ batch.Price = CalcItemFinalSalePrice(batch.Price, discPerc, priceList, markUp);
222
+
223
+ if (includeMargin && IsNotNull(batch.Cost)) {
224
+ batch.Margin = GetMarginValue(batch.Price, batch.Cost);
225
+ }
226
+ }
227
+ }
228
+ } else if (priceList.BasedOn === "PC") {
229
+ if (item.Track === "TR" || item.Track === "SN") {
230
+ item.Sale["MRP"] = item.Sale.Price;
231
+ if (IsNotNull(item.Pur) && IsNotNull(item.Pur.Cost)) {
232
+ item.Sale.Price = CalcItemFinalSalePrice(item.Pur.Cost, discPerc, priceList, markUp);
233
+
234
+ if (includeMargin) {
235
+ item.Margin = GetMarginValue(item.Sale.Price, item.Pur.Cost);
236
+ }
237
+ }
238
+ } else if (item.Track === "BN" && Array.isArray(item.Batches)) {
239
+ for (const batch of item.Batches) {
240
+ batch.MRP = batch.Price;
241
+ if (IsNotNull(batch.Cost)) {
242
+ batch.Price = CalcItemFinalSalePrice(batch.Cost, discPerc, priceList, markUp);
243
+
244
+ if (includeMargin) {
245
+ batch.Margin = GetMarginValue(batch.Price, batch.Cost);
246
+ }
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ return item;
254
+ }
255
+
256
+ function ApplyRounding(price: number, priceList: any): number {
257
+ if (!priceList || !priceList.Round) return price;
258
+
259
+ switch (priceList.Round) {
260
+ case "-1":
261
+ return price;
262
+ case "0":
263
+ return Math.round(price);
264
+ case "0.99":
265
+ return Math.floor(price) + 0.99;
266
+ case "0.50":
267
+ return Math.round(price * 2) / 2;
268
+ case "0.49":
269
+ return Math.floor(price) + 0.49;
270
+ case "Dec":
271
+ if (IsNotNull(priceList.Deci)) {
272
+ const factor = Math.pow(10, priceList.Deci);
273
+ return Math.round(price * factor) / factor;
274
+ }
275
+ return price;
276
+ default:
277
+ return price;
278
+ }
279
+ }
280
+
281
+ function ResolveTier(quantity: number, tiers: any[] | undefined): any | null {
282
+ if (!Array.isArray(tiers) || tiers.length === 0) {
283
+ return null;
284
+ }
285
+
286
+ const sorted = [...tiers]
287
+ .filter((tier: any) => IsNotNull(tier) && IsNotNull(tier.MinQty))
288
+ .sort((a: any, b: any) => a.MinQty - b.MinQty);
289
+
290
+ let selected: any | null = null;
291
+
292
+ for (const tier of sorted) {
293
+ if (quantity >= tier.MinQty) {
294
+ selected = tier;
295
+ } else {
296
+ break;
297
+ }
298
+ }
299
+
300
+ return selected;
301
+ }
302
+
303
+ function ApplyTierAdjustment(
304
+ basePrice: number,
305
+ tier: any,
306
+ priceList: any,
307
+ markUp: boolean
308
+ ): number {
309
+ if (IsNotNull(tier?.Price)) {
310
+ return ApplyRounding(tier.Price, priceList);
311
+ }
312
+
313
+ if (IsNotNull(tier?.Disc)) {
314
+ const targetBase = IsNotNull(basePrice) ? basePrice : 0;
315
+ return CalcItemFinalSalePrice(targetBase, tier.Disc, priceList, markUp);
316
+ }
317
+
318
+ return ApplyRounding(basePrice, priceList);
319
+ }
320
+
321
+ function BuildAppliedTierMeta(source: "ITEM" | "PRICELIST", tier: any) {
322
+ if (!tier) {
323
+ return undefined;
324
+ }
325
+
326
+ return {
327
+ Source: source,
328
+ MinQty: IsNotNull(tier.MinQty) ? tier.MinQty : null,
329
+ Price: IsNotNull(tier.Price) ? tier.Price : null,
330
+ Disc: IsNotNull(tier.Disc) ? tier.Disc : null,
331
+ };
332
+ }
333
+
334
+ function DetermineBasePriceForTier(item: any, priceList: any): number {
335
+ if (priceList.PrCalc === "FIXED") {
336
+ if (IsNotNull(priceList.Fixed?.Price)) {
337
+ return priceList.Fixed.Price;
338
+ }
339
+ return item.Sale.Price;
340
+ }
341
+
342
+ if (priceList.PrCalc === "DISC") {
343
+ if (priceList.BasedOn === "PC" && IsNotNull(item.Pur) && IsNotNull(item.Pur.Cost)) {
344
+ return item.Pur.Cost;
345
+ }
346
+ return item.Sale.Price;
347
+ }
348
+
349
+ return item.Sale.Price;
350
+ }
351
+
352
+ function DetermineBatchBasePriceForTier(batch: any, item: any, priceList: any): number {
353
+ if (priceList.PrCalc === "FIXED") {
354
+ if (IsNotNull(priceList.Fixed?.Price)) {
355
+ return priceList.Fixed.Price;
356
+ }
357
+ return batch.Price;
358
+ }
359
+
360
+ if (priceList.PrCalc === "DISC") {
361
+ if (priceList.BasedOn === "PC" && IsNotNull(batch.Cost)) {
362
+ return batch.Cost;
363
+ }
364
+ return batch.Price;
365
+ }
366
+
367
+ return batch.Price;
368
+ }
@@ -0,0 +1,290 @@
1
+ import * as XLSX from 'xlsx';
2
+ import { MyDate } from '../../../../utils/my-date';
3
+ import { TrUtils } from '../../../../utils/tr-utils';
4
+ import { Multiply } from '../../../../shared/math-operations';
5
+
6
+ export class ExpiringDrugsXlsxFileService {
7
+ static wb: any = {};
8
+ static Row: any = 2;
9
+ static MergeArray: any[] = [];
10
+ static range = { s: { c: 0, r: 0 }, e: { c: 0, r: 0 } };
11
+ static ws: any = {};
12
+
13
+ static GetExpiringDrugsExcelData(MainData: any, isSale: boolean, searchValue: any, HeaderName: any, EntitySettings: any) {
14
+ this.wb = {};
15
+ this.ws = {};
16
+ this.Row = 0;
17
+ this.range = { s: { c: 0, r: 0 }, e: { c: 0, r: 0 } };
18
+ this.MergeArray = [];
19
+ let ws_name = HeaderName;
20
+ this.wb.Sheets = {};
21
+ this.wb.Props = {};
22
+ this.wb.SSF = {};
23
+ this.wb.SheetNames = [];
24
+
25
+ // MainData = this.GetTotals(MainData);
26
+ let showSearch: any = [];
27
+ for (const key in searchValue) {
28
+ if (!TrUtils.IsNull(searchValue[key]) && key !== 'Date' && key !== 'CustCntrlId') {
29
+ showSearch.push([{
30
+ text: (key === 'StDate') ? 'Start Date' : (key === 'EnDate') ? 'End Date' : (key === 'CustCntrl') ? isSale ? 'Customer' : 'Vendor' : key,
31
+ ColRange: 1,
32
+ bold: true,
33
+ ChildHeadings: [
34
+ // { text: 'Central Tax', ColRange: 1 },
35
+ // { text: 'State Tax', ColRange: 1 },
36
+ // { text: 'IGST Tax', ColRange: 1 },
37
+ ],
38
+ }, {
39
+ text: (key === 'StDate') ? MyDate.ConvertUTCDateToReadable(searchValue[key]) : (key === 'EnDate') ? MyDate.ConvertUTCDateToReadable(searchValue[key]) : searchValue[key],
40
+ ColRange: 7,
41
+ bold: true,
42
+ ChildHeadings: [
43
+ // { text: 'Central Tax', ColRange: 1 },
44
+ // { text: 'State Tax', ColRange: 1 },
45
+ // { text: 'IGST Tax', ColRange: 1 },
46
+ ],
47
+ }]);
48
+ }
49
+
50
+ // console.log(`${key}: ${searchValue[key]}`);
51
+ }
52
+
53
+ this.setHeadingInCell(HeaderName, showSearch);
54
+
55
+ this.setInvoiceDetailsInCell(MainData, isSale, EntitySettings.DecimalsNumber);
56
+
57
+ this.ws['!ref'] = XLSX.utils.encode_range(this.range);
58
+
59
+ this.ws['!merges'] = this.MergeArray;
60
+ this.ws["!cols"] = [{ wch: 50 }, { wch: 10 }, { wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }, { wch: 15 }];
61
+
62
+ this.wb.SheetNames.push(ws_name);
63
+
64
+ this.wb.Sheets[ws_name] = this.ws;
65
+
66
+ return this.wb;
67
+ }
68
+
69
+ static setHeadingInCell(HeaderName: any, showSearch: any) {
70
+
71
+ let MainHeadings: any[] = [
72
+ // {
73
+ // text: 'SNo',
74
+ // ColRange: 1,
75
+ // bold: true,
76
+ // ChildHeadings: []
77
+ // },
78
+ {
79
+ text: 'Name',
80
+ ColRange: 1,
81
+ bold: true,
82
+ ChildHeadings: [],
83
+ },
84
+ // {
85
+ // text: 'Location',
86
+ // ColRange: 1,
87
+ // bold: true,
88
+ // ChildHeadings: [
89
+ // // { text: 'No', ColRange: 1 },
90
+ // // { text: 'Date', ColRange: 1 },
91
+ // // { text: 'Invoice Total', ColRange: 1 }
92
+ // ],
93
+ // },
94
+
95
+ {
96
+ text: 'Batch No',
97
+ ColRange: 1,
98
+ bold: true,
99
+ ChildHeadings: [
100
+ // { text: 'Central Tax', ColRange: 1 },
101
+ // { text: 'State Tax', ColRange: 1 },
102
+ // { text: 'IGST Tax', ColRange: 1 },
103
+ ],
104
+ },
105
+ {
106
+ text: 'Exp Date',
107
+ ColRange: 1,
108
+ bold: true,
109
+ ChildHeadings: [
110
+ // { text: 'Central Tax', ColRange: 1 },
111
+ // { text: 'State Tax', ColRange: 1 },
112
+ // { text: 'IGST Tax', ColRange: 1 },
113
+ ],
114
+ },
115
+ {
116
+ text: 'Qty',
117
+ ColRange: 1,
118
+ bold: true,
119
+ ChildHeadings: [
120
+ // { text: 'Central Tax', ColRange: 1 },
121
+ // { text: 'State Tax', ColRange: 1 },
122
+ // { text: 'IGST Tax', ColRange: 1 },
123
+ ],
124
+ },
125
+ {
126
+ text: 'Rate',
127
+ ColRange: 1,
128
+ bold: true,
129
+ ChildHeadings: [
130
+ // { text: 'Central Tax', ColRange: 1 },
131
+ // { text: 'State Tax', ColRange: 1 },
132
+ // { text: 'IGST Tax', ColRange: 1 },
133
+ ],
134
+ },
135
+ {
136
+ text: 'Value',
137
+ ColRange: 1,
138
+ bold: true,
139
+ ChildHeadings: [
140
+ // { text: 'Central Tax', ColRange: 1 },
141
+ // { text: 'State Tax', ColRange: 1 },
142
+ // { text: 'IGST Tax', ColRange: 1 },
143
+ ],
144
+ },
145
+
146
+
147
+ ];
148
+
149
+ this.SetDataInCell(HeaderName, 0, this.Row);
150
+ this.MergeArray.push({
151
+ s: { r: this.Row, c: 0 },
152
+ e: { r: this.Row, c: 0 + 8 - 1 },
153
+ });
154
+ this.Row += 2;
155
+ // console.log('showSearch', showSearch);
156
+ showSearch.forEach((search: any) => {
157
+ let ColStart: any = 0;
158
+ // console.log('search', search, ColStart);
159
+ search.forEach((item: any) => {
160
+ // console.log('text', oyo.text, ColStart);
161
+ this.SetDataInCell(item.text, ColStart, this.Row);
162
+ this.MergeArray.push({
163
+ s: { r: this.Row, c: ColStart },
164
+ e: { r: this.Row, c: ColStart + item.ColRange - 1 },
165
+ });
166
+ ColStart += item.ColRange;
167
+ });
168
+ this.Row += 1;
169
+ });
170
+ this.Row += 1;
171
+ let MainColStart: any = 0;
172
+ MainHeadings.forEach((MainHeader: any) => {
173
+ this.SetDataInCell(MainHeader.text, MainColStart, this.Row);
174
+ this.MergeArray.push({
175
+ s: { r: this.Row, c: MainColStart },
176
+ e: { r: this.Row, c: MainColStart + MainHeader.ColRange - 1 },
177
+ });
178
+ MainColStart += MainHeader.ColRange;
179
+ });
180
+
181
+ this.Row += 2;
182
+ }
183
+
184
+ static setInvoiceDetailsInCell(MainData: any, isSale: boolean, DecimalsNumber: number) {
185
+ MainData.forEach((InvoiceList: any) => {
186
+ this.SetInvoiceDataInExcel(InvoiceList, isSale, DecimalsNumber);
187
+ });
188
+ }
189
+
190
+ static SetInvoiceDataInExcel(InvoiceInfo: any, isSale: boolean, DecimalsNumber: number) {
191
+ InvoiceInfo.CrDate = this.ConvertDateToReadableFormat(InvoiceInfo.CrDate);
192
+
193
+ let InvoiceData: any = [
194
+ { text: InvoiceInfo.Name, ColRange: 1, IsString: true },
195
+ { text: InvoiceInfo.Batch.BN, ColRange: 1, IsString: true },
196
+ { text: MyDate.ConvertUTCDateToReadableExDateTxt(InvoiceInfo.Batch.ExDt), ColRange: 1, IsString: true },
197
+ { text: InvoiceInfo.Batch.Qty, ColRange: 1, IsString: true },
198
+ { text: TrUtils.FixPriceValue(InvoiceInfo.Batch.Cost, DecimalsNumber), ColRange: 1, IsString: true },
199
+ { text: TrUtils.FixPriceValue(Multiply(InvoiceInfo.Batch.Qty, InvoiceInfo.Batch.Cost), DecimalsNumber), ColRange: 1, IsString: true },
200
+ // { text: InvoiceInfo.Round, ColRange: 1, IsString: true },
201
+ // { text: InvoiceInfo.Total, ColRange: 1, IsString: false }
202
+ ];
203
+ let ColStart: any = 0;
204
+ InvoiceData.forEach((InvData: any) => {
205
+ InvData.text = this.ConvertToString(InvData.text, InvData.IsString, DecimalsNumber);
206
+ this.SetDataInCell(InvData.text, ColStart, this.Row);
207
+ this.MergeArray.push({
208
+ s: { r: this.Row, c: ColStart },
209
+ e: { r: this.Row, c: ColStart + InvData.ColRange - 1 },
210
+ });
211
+ ColStart += InvData.ColRange;
212
+ });
213
+
214
+ this.Row += 1;
215
+ }
216
+
217
+ static ConvertToString(Text: any, IsString: any, DecimalsNumber: number) {
218
+ if (IsString) {
219
+ if (Text == null) {
220
+ Text = '';
221
+ }
222
+ } else {
223
+ if (Text == null) {
224
+ Text = 0;
225
+ }
226
+ }
227
+ if (typeof Text === 'number') {
228
+ return Number(TrUtils.FixedTo(Text, DecimalsNumber));
229
+ } else {
230
+ return Text;
231
+ }
232
+ }
233
+
234
+ static SetDataInCell(Data: any, ColRange: number, RowNum: any) {
235
+ // console.log(ColRange, RowNum);
236
+ var cell = { v: Data, bold: true };
237
+ var cell_ref = XLSX.utils.encode_cell({ c: ColRange, r: RowNum });
238
+ if (this.range.e.c < ColRange) {
239
+ this.range.e.c = ColRange;
240
+ }
241
+ if (this.range.e.r < RowNum) {
242
+ this.range.e.r = RowNum;
243
+ }
244
+ cell = this.getcelltype(cell);
245
+ this.ws[cell_ref] = cell;
246
+ }
247
+
248
+ static getcelltype(cell: any) {
249
+ if (typeof cell.v === 'number') cell.t = 'n';
250
+ else if (typeof cell.v === 'boolean') cell.t = 'b';
251
+ else cell.t = 's';
252
+ return cell;
253
+ }
254
+
255
+ static ConvertDateToReadableFormat(DateObject: any) {
256
+ if (!TrUtils.IsEmpty(DateObject)) {
257
+ let date: any = new Date(DateObject);
258
+ let Month: any;
259
+ let Day: any;
260
+
261
+ let MonthName = new Array();
262
+ MonthName[0] = 'Jan';
263
+ MonthName[1] = 'Feb';
264
+ MonthName[2] = 'Mar';
265
+ MonthName[3] = 'Apr';
266
+ MonthName[4] = 'May';
267
+ MonthName[5] = 'Jun';
268
+ MonthName[6] = 'Jul';
269
+ MonthName[7] = 'Aug';
270
+ MonthName[8] = 'Sept';
271
+ MonthName[9] = 'Oct';
272
+ MonthName[10] = 'Nov';
273
+ MonthName[11] = 'Dec';
274
+
275
+ Month = MonthName[date.getMonth()];
276
+
277
+ if (date.getDate() < 10) {
278
+ Day = '0' + date.getDate();
279
+ } else {
280
+ Day = date.getDate();
281
+ }
282
+
283
+ date = Day + '-' + Month + '-' + date.getFullYear();
284
+ return date;
285
+ } else {
286
+ return null;
287
+ }
288
+ }
289
+
290
+ }