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,535 @@
1
+ /**
2
+ * Tax System - Shared Type Definitions
3
+ *
4
+ * These types are used by both the UI (Angular) for tax calculation
5
+ * and the API (Node.js) for validation and future server-side calculation.
6
+ *
7
+ * IMPORTANT: This file has NO dependencies on Angular, Mongoose, or any
8
+ * framework-specific code. Pure TypeScript interfaces and types only.
9
+ */
10
+
11
+ // ============================================================
12
+ // Core Union Types
13
+ // ============================================================
14
+
15
+ /** Tax component types — what kind of tax is this? */
16
+ export type TaxComponentType = "Tax" | "Cess" | "Levy" | "Excise" | "Surcharge" | "Duty";
17
+
18
+ /** How the tax is calculated */
19
+ export type CalcMethod = "Percent" | "PerUnit" | "PerUnitPlusPercent" | "MaxOfPercentOrPerUnit";
20
+
21
+ /** What base amount the tax applies to */
22
+ export type AppliedOn = "NetAmt" | "PostTax" | "Qty";
23
+
24
+ /** Rounding methods */
25
+ export type RoundingMethod = "Round" | "Floor" | "Ceil" | "BankersRound";
26
+
27
+ /** Tax code categories */
28
+ export type TaxCategory = "Standard" | "Reduced" | "Zero" | "Exempt" | "Nil" | "NonTaxable" | "ReverseCharge" | "Export";
29
+
30
+ /** Supply type for a transaction or tax code */
31
+ export type SupplyType = "Intra" | "Inter" | "All";
32
+
33
+ /** Resolved supply type — includes "Unknown" for missing state data */
34
+ export type ResolvedSupplyType = "Intra" | "Inter" | "Unknown";
35
+
36
+ /** Withholding type — Deducted (TDS) or Collected (TCS) */
37
+ export type WithholdingType = "Deducted" | "Collected";
38
+
39
+ /** External tax engine resolver type */
40
+ export type ResolverType = "Internal" | "External";
41
+
42
+ // ============================================================
43
+ // TaxRegime — Country-level tax system configuration
44
+ // ============================================================
45
+
46
+ /** A tax component defined by the regime (e.g., CGST, SGST, IGST, GST, VAT, STATE_TAX) */
47
+ export interface IRegimeComponent {
48
+ Code: string; // "CGST", "SGST", "GST", "VAT", "STATE_TAX"
49
+ Name: string; // "Central GST", "Value Added Tax"
50
+ Type: TaxComponentType; // "Tax", "Cess", "Levy", etc.
51
+ }
52
+
53
+ /** Feature flags — UI visibility toggles + feature gating.
54
+ * These flags tell the UI WHAT to show. The Country field determines HOW each feature behaves.
55
+ * Treatment-driven behavior (e.g., Composition scheme) is handled in code per Country + Treatment. */
56
+ export interface IRegimeFeatures {
57
+ HasPlaceOfSupply: boolean;
58
+ HasReverseCharge: boolean;
59
+ HasWithholding: boolean; // TDS/TCS (India), Withholding Tax (US/UK/etc.)
60
+ HasHSN: boolean;
61
+ HasSAC: boolean;
62
+
63
+ /** Tax ID field definitions for this regime.
64
+ * UI reads this to build tax ID forms on Entity Settings, Customer, and Vendor screens.
65
+ * Only Primary entries are shown on Customer/Vendor; all shown on Entity Settings. */
66
+ TaxIdLabels?: ITaxIdLabel[];
67
+ }
68
+
69
+ /** Rounding rules for a regime.
70
+ * Three rounding points control WHERE in the calculation chain rounding is applied.
71
+ * LineTax and TaxComponentTotal are mutually exclusive in practice (line-level OR document-level tax rounding).
72
+ * DocTotal controls whether the grand total is rounded independently.
73
+ *
74
+ * Country presets:
75
+ * India GST: { Method: "Round", Precision: 0, TaxComponentTotal: true, DocTotal: true }
76
+ * US Sales Tax: { Method: "Round", Precision: 2, LineTax: true, DocTotal: true }
77
+ * Japan CT: { Method: "Floor", Precision: 0, TaxComponentTotal: true }
78
+ * EU/UK/AU: { Method: "Round", Precision: 2, DocTotal: true }
79
+ */
80
+ export interface IRounding {
81
+ Method: RoundingMethod;
82
+ Precision: number; // Decimal places: 0 for INR/JPY, 2 for USD/EUR/GBP
83
+ LineTax: boolean; // Round each Taxes[].Amt per line item (US states)
84
+ TaxComponentTotal: boolean; // Round each tax component sum across lines — CGST total, SGST total (India Section 170)
85
+ DocTotal: boolean; // Round the grand total (most countries)
86
+ }
87
+
88
+ /** A registration/treatment type valid for this regime */
89
+ export interface ITreatment {
90
+ Code: string; // "REGULAR", "COMPOSITION", "UNREGISTERED"
91
+ Name: string; // "GST Registered - Regular"
92
+ Description?: string;
93
+ ApplicableTo: "Seller" | "Buyer" | "Both";
94
+ }
95
+
96
+ /** The full TaxRegime object */
97
+ export interface ITaxRegime {
98
+ _id: number;
99
+ OId: number;
100
+ EId: number;
101
+ Country: string; // ISO 3166-1 alpha-2: "IN", "AU", "US"
102
+ Region?: string; // State/Province (null = national)
103
+ Code: string; // "IN_GST", "AU_GST"
104
+ Name: string; // "India GST"
105
+ Currency?: string; // "INR", "AUD"
106
+ Components?: IRegimeComponent[]; // Optional — vocabulary of allowed component codes
107
+ Features: IRegimeFeatures;
108
+ Rounding: IRounding;
109
+ Treatments: ITreatment[];
110
+ IsActive: boolean;
111
+ }
112
+
113
+ // ============================================================
114
+ // TaxCode — Tax rate definitions with flexible components
115
+ // ============================================================
116
+
117
+ /** A single component within a tax code (rate definition) */
118
+ export interface ITaxCodeComponent {
119
+ Code: string; // "CGST", "SGST", "IGST", "CESS", "GST"
120
+ Name: string; // "Central GST"
121
+ Rate: number; // 9, 14, 10, 6.25
122
+ Type: TaxComponentType;
123
+ CalcMethod: CalcMethod;
124
+ PerUnitAmt?: number; // For PerUnit: Rs 5/ml, $2/unit
125
+ Unit?: string; // Unit of measure for PerUnitAmt: "sticks", "ml", "kg" — when different from line UoM
126
+ AppliedOn: AppliedOn; // "NetAmt", "PostTax", "Qty"
127
+ }
128
+
129
+ /** The full TaxCode object */
130
+ export interface ITaxCode {
131
+ _id: number;
132
+ OId: number;
133
+ EId: number;
134
+ RegimeId: number;
135
+ Code: string; // "GST_18_INTRA"
136
+ Name: string; // "GST 18% (Intra-State)"
137
+ Category: TaxCategory;
138
+ Components: ITaxCodeComponent[];
139
+
140
+ /**
141
+ * Pre-computed sum of PERCENTAGE-based rates.
142
+ *
143
+ * DISPLAY HINT ONLY — do NOT use for matching logic.
144
+ * When PerUnit or PostTax components exist, CombinedRate does NOT represent
145
+ * the true effective tax burden. Use Code/_id for programmatic matching.
146
+ */
147
+ CombinedRate: number;
148
+
149
+ SupplyType: SupplyType;
150
+
151
+ EffectiveFrom?: Date | string;
152
+ EffectiveTo?: Date | string;
153
+ IsActive: boolean;
154
+
155
+ // Deprecated fields (kept during migration)
156
+ Agency?: string;
157
+ Type?: string;
158
+ CGST?: number;
159
+ SGST?: number;
160
+ IGST?: number;
161
+ }
162
+
163
+ // ============================================================
164
+ // TaxComponent — Immutable snapshot on line items (Taxes[])
165
+ // ============================================================
166
+
167
+ /**
168
+ * Lean tax component snapshot stored on each line item.
169
+ *
170
+ * DESIGN PRINCIPLE: Store results of multiplications, not additions.
171
+ * - Amt = Rate × TaxableAmt (multiplication → stored)
172
+ * - TaxableAmt is derivable from line item fields (Qty × UnitPrice - Discount)
173
+ * so NOT stored here — line item is the source of truth.
174
+ * - TaxAmt (sum of Taxes[].Amt) is a simple addition → computed on the fly via sumTaxComponents().
175
+ *
176
+ * CalcMethod and PerUnitAmt are optional snapshot fields for non-percent cess.
177
+ * They capture the resolved calculation parameters at save time so the invoice
178
+ * remains self-contained and reproducible even if item cess config changes later.
179
+ * For standard percent-based components (CGST, SGST, IGST), these are omitted.
180
+ *
181
+ * NOTE: ITC is NOT stored here. ITC is at the line-item and document
182
+ * level (purchase-side only).
183
+ */
184
+ export interface ITaxComponent {
185
+ Code: string; // "CGST", "SGST", "IGST", "CESS"
186
+ Rate: number; // 9, 14, 10 — historical snapshot for rate-wise GST return grouping
187
+ Amt: number; // Calculated tax amount (Rate × TaxableAmt)
188
+ TaxCodeId?: number; // Audit trail — which TaxCode was used
189
+
190
+ // Optional snapshot fields — only stored for non-percent components (PerUnit, PerUnitPlusPercent, MaxOfPercentOrPerUnit)
191
+ CalcMethod?: CalcMethod; // "PerUnit", "MaxOfPercentOrPerUnit", etc. — omitted when "Percent" (default)
192
+ PerUnitAmt?: number; // The resolved per-unit amount (may come from item CessConfig override)
193
+ Unit?: string; // Unit of measure for PerUnitAmt when it differs from line item UoM (e.g., "sticks" when line is "Box")
194
+ }
195
+
196
+ // ============================================================
197
+ // TaxSummary — Document-level aggregated totals
198
+ // ============================================================
199
+
200
+ /**
201
+ * TaxSummary is computed by shareneus at save time and stored on the document.
202
+ * Line-item Taxes[] remains the source of truth. TaxSummary is a materialized
203
+ * snapshot for reporting efficiency — avoids complex $unwind/$group in aggregation.
204
+ *
205
+ * Grouped by Code+Rate (e.g., CGST@9, CGST@14 are separate entries).
206
+ * Rounding is applied per the RoundingConfig:
207
+ * - If TaxComponentTotal ON: each entry's Amt is rounded to Precision
208
+ * - If LineTax ON: Amts are already rounded at line level, summary just sums them
209
+ * - Otherwise: Amts are at currency precision (2 decimals)
210
+ */
211
+
212
+ /** One line in the TaxSummary — grouped by Code+Rate */
213
+ export interface ITaxSummaryLine {
214
+ Code: string; // "CGST", "SGST", "IGST", "VAT", "STATE_TAX"
215
+ Rate: number; // Tax rate for this bucket (grouping key)
216
+ TaxableAmt: number; // Sum of line-item taxable amounts (NetAmts) for this bucket
217
+ Amt: number; // Tax amount for this bucket (rounded per config)
218
+ }
219
+
220
+ /** Document-level tax summary — stored on Invoice, Bill, CreditNote, etc. */
221
+ export interface ITaxSummary {
222
+ Lines: ITaxSummaryLine[];
223
+ TotalTaxable: number; // Sum of unique line-item taxable amounts (not double-counted across components)
224
+ TotalTax: number; // Total tax — sum of per-component rounded amounts
225
+ RegimeCode?: string; // "IN_GST" snapshot
226
+ }
227
+
228
+ // ============================================================
229
+ // Withholding — Generic TDS/TCS for all countries
230
+ // ============================================================
231
+
232
+ /**
233
+ * Withholding tax is a generic concept covering:
234
+ * - India: TDS (Section 51) and TCS (Section 52)
235
+ * - USA: Federal/State withholding tax
236
+ * - UK: CIS (Construction Industry Scheme)
237
+ * - Australia: PAYG withholding
238
+ * - Brazil: IRRF
239
+ *
240
+ * Stored on: Invoice, Bill, SalesReceipt — at document level.
241
+ * A document can have multiple withholding entries (e.g., TDS + TCS,
242
+ * or federal + state withholding in the US).
243
+ *
244
+ * The Withholding[] array replaces the old separate TDS/TCS sub-schemas.
245
+ */
246
+ export interface IWithholding {
247
+ /** "Deducted" = TDS/Withholding (buyer deducts from payment to seller)
248
+ * "Collected" = TCS (seller collects from buyer and deposits to govt) */
249
+ Type: WithholdingType;
250
+
251
+ /** Legal section or code reference
252
+ * India TDS: "51" (GST) or "194C", "194J" (Income Tax)
253
+ * India TCS: "52" (GST) or "206C(1H)" (Income Tax)
254
+ * US: "FITW" (Federal Income Tax Withholding) */
255
+ Section: string;
256
+
257
+ /** Tax rate — total withholding rate */
258
+ Rate: number;
259
+
260
+ /** Base amount on which withholding is calculated */
261
+ BaseAmt: number;
262
+
263
+ /** Calculated withholding amount */
264
+ Amt: number;
265
+
266
+ /** Who is liable to deduct/collect and deposit
267
+ * "Buyer" for TDS, "Seller" for TCS */
268
+ PartyLiable?: "Buyer" | "Seller";
269
+ }
270
+
271
+ /** Input for withholding calculation */
272
+ export interface IWithholdingCalcInput {
273
+ Type: WithholdingType;
274
+ Section: string;
275
+ Rate: number;
276
+ BaseAmt: number;
277
+ PartyLiable?: "Buyer" | "Seller";
278
+ }
279
+
280
+ // ============================================================
281
+ // Input types for tax calculation
282
+ // ============================================================
283
+
284
+ /**
285
+ * Component-level overrides for tax calculation.
286
+ *
287
+ * Keyed by component Code (e.g., "CESS"). When provided, these values
288
+ * replace the TaxCode component's defaults at calculation time.
289
+ *
290
+ * Primary use case: CESS rates are HSN-specific, so the TaxCode defines
291
+ * the structure (CalcMethod, AppliedOn) while the actual Rate/PerUnitAmt
292
+ * comes from the item master's CessConfig.
293
+ *
294
+ * Only Rate and PerUnitAmt can be overridden — structural fields (Code,
295
+ * Name, Type, CalcMethod, AppliedOn) always come from the TaxCode.
296
+ */
297
+ export interface IComponentOverride {
298
+ Rate?: number;
299
+ PerUnitAmt?: number;
300
+ Unit?: string; // Override unit when cess basis differs from line UoM (e.g., "sticks" for "₹X per 1000 sticks")
301
+ }
302
+
303
+ /**
304
+ * Base fields for computing taxable amount (NetAmt) from line item quantities and prices.
305
+ * NetAmt = (Qty × UnitPrice) - Disc - RecDisc
306
+ *
307
+ * Generic across both goods and services:
308
+ * For Items (goods): UnitPrice maps to UnPr (unit price)
309
+ * For Ops (services): UnitPrice maps to Pr (operation rate)
310
+ */
311
+ export interface ILineAmountFields {
312
+ /** Quantity */
313
+ Qty: number;
314
+
315
+ /** Unit price — Items: UnPr, Ops: Pr */
316
+ UnitPrice: number;
317
+
318
+ /** Line-level discount amount */
319
+ Disc?: number;
320
+
321
+ /** Record-level (document-level) discount allocated to this line */
322
+ RecDisc?: number;
323
+ }
324
+
325
+ /** Input context for calculating tax on a single line item */
326
+ export interface ITaxCalcLineInput extends ILineAmountFields {
327
+ /** The TaxCode to apply */
328
+ TaxCode: ITaxCode;
329
+
330
+ /** Is this a reverse charge line? */
331
+ RCM?: boolean;
332
+
333
+ /**
334
+ * Optional component-level overrides, keyed by component Code.
335
+ *
336
+ * Used when CESS Rate/PerUnitAmt comes from item master (CessConfig)
337
+ * rather than the TaxCode itself (which has placeholder values like Rate: 0).
338
+ *
339
+ * @example
340
+ * // Item has CessRate: 12 (percent cess from HSN config)
341
+ * ComponentOverrides: { CESS: { Rate: 12 } }
342
+ *
343
+ * @example
344
+ * // Item has CessPerUnitAmt: 5 (₹5/liter from HSN config)
345
+ * ComponentOverrides: { CESS: { PerUnitAmt: 5 } }
346
+ */
347
+ ComponentOverrides?: Record<string, IComponentOverride>;
348
+ }
349
+
350
+ /** Input context for computing document-level TaxSummary.
351
+ *
352
+ * Since TaxableAmt is NOT stored on TaxComponent (it's derivable from line item fields),
353
+ * each line provides Qty/UnitPrice/Disc/RecDisc and shareneus computes NetAmt internally.
354
+ */
355
+ export interface ITaxSummaryInput {
356
+ /** All line items with amount fields and calculated Taxes[] arrays */
357
+ Lines: Array<ILineAmountFields & { Taxes?: ITaxComponent[] }>;
358
+
359
+ /** Tax regime code for the snapshot */
360
+ RegimeCode?: string;
361
+
362
+ /** Rounding config — if provided, applies TaxComponentTotal rounding to summary Amts */
363
+ Rounding?: IRoundingConfig;
364
+ }
365
+
366
+ /**
367
+ * Rounding settings passed to calculator functions.
368
+ *
369
+ * Method + Precision define HOW to round.
370
+ * LineTax / TaxComponentTotal / DocTotal define WHERE (which rounding points are active).
371
+ *
372
+ * When passed to calculateLineTax:
373
+ * - LineTax ON → round each Taxes[].Amt to Precision
374
+ * - LineTax OFF → round to standard currency precision (2 decimals)
375
+ *
376
+ * When passed to computeTaxSummary:
377
+ * - TaxComponentTotal ON → round each Code+Rate bucket's Amt to Precision
378
+ *
379
+ * When passed to computeDocumentTotals:
380
+ * - DocTotal ON → round the grand total to Precision
381
+ */
382
+ export interface IRoundingConfig {
383
+ Method: RoundingMethod;
384
+ Precision: number;
385
+ LineTax?: boolean; // default false
386
+ TaxComponentTotal?: boolean; // default false
387
+ DocTotal?: boolean; // default true
388
+ }
389
+
390
+ // ============================================================
391
+ // Document Totals — Full document computation input/output
392
+ // ============================================================
393
+
394
+ /** Input for computing all document-level totals in one call */
395
+ export interface IDocumentTotalsInput {
396
+ /** All line items with amount fields (Qty, UnitPrice, Disc, RecDisc) and Taxes[] */
397
+ Lines: Array<ILineAmountFields & { Taxes?: ITaxComponent[] }>;
398
+
399
+ /** Rounding configuration (from TaxRegime.Rounding or Entity Settings) */
400
+ Rounding: IRoundingConfig;
401
+
402
+ /** Tax regime code for the TaxSummary snapshot */
403
+ RegimeCode?: string;
404
+ }
405
+
406
+ /** Result of full document totals computation */
407
+ export interface IDocumentTotals {
408
+ /** Sum of all gross line values before discounts and tax */
409
+ SubTotal: number;
410
+
411
+ /** Sum of line discounts + prorated record/document discount allocations */
412
+ Discount: number;
413
+
414
+ /** Sum of all line NetAmts after discount allocation, before tax */
415
+ TaxableAmount: number;
416
+
417
+ /** Total tax amount — sum of rounded component Amts per RoundingConfig */
418
+ TaxTotal: number;
419
+
420
+ /** Rate-wise tax breakdown — grouped by Code+Rate, rounded per config */
421
+ TaxSummary: ITaxSummaryLine[];
422
+
423
+ /** TaxableAmount + TaxTotal (before DocTotal rounding) */
424
+ GrandTotal: number;
425
+
426
+ /** Rounding adjustment: RoundedTotal - GrandTotal (0 if DocTotal is off) */
427
+ Round: number;
428
+
429
+ /** Final amount: GrandTotal + Round */
430
+ Total: number;
431
+ }
432
+
433
+ // ============================================================
434
+ // TaxId — Tax identification numbers per country
435
+ // ============================================================
436
+
437
+ /** Defines a tax ID field on TaxRegime — the source of truth for what tax IDs a regime needs.
438
+ * UI reads TaxRegime.Features.TaxIdLabels[] to build form fields dynamically.
439
+ * Entity Settings shows all entries; Customer/Vendor shows only Primary entries. */
440
+ export interface ITaxIdLabel {
441
+ /** Display label — "GSTIN", "PAN", "CIN", "ABN", "EIN", "VAT No" */
442
+ Label: string;
443
+ /** Regex pattern for format validation (e.g., "^[0-9]{2}[A-Z]{5}..." for GSTIN) */
444
+ RegexValidate?: string;
445
+ /** UI hint — should the form field be required? (not a mongoose-level required) */
446
+ Required?: boolean;
447
+ /** Show on Customer/Vendor screens too? If false/undefined, only shown on Entity Settings. */
448
+ Primary?: boolean;
449
+ }
450
+
451
+ /** A stored tax ID entry on Entity Settings, Customer, or Vendor */
452
+ export interface ITaxIdEntry {
453
+ Label: string; // "GSTIN", "PAN", "ABN"
454
+ Value: string; // The actual tax ID value
455
+ Print?: boolean; // Show on invoice/PDF? Default: true (print if undefined)
456
+ }
457
+
458
+ // ============================================================
459
+ // TaxExemption — Named reasons for tax exemption (v2 master)
460
+ // ============================================================
461
+
462
+ /**
463
+ * Tax exemption reasons — used when a line item or contact is exempt from tax.
464
+ *
465
+ * v1 approach: Store ExmReason directly on transaction lines/headers.
466
+ * v2 approach: Create TaxExemption master collection for standardized reasons.
467
+ *
468
+ * In India GST, the reason matters for return filing:
469
+ * - "EXPORT_WO_PAY" -> Export without payment of tax (GSTR1 Table 6A)
470
+ * - "SEZ_WO_PAY" -> Supply to SEZ without payment
471
+ * - "NIL_RATED" -> Goods/services that are nil rated (0% by law)
472
+ * - "EXEMPT" -> Goods/services specifically exempt from GST
473
+ * - "NON_GST" -> Outside the scope of GST entirely
474
+ *
475
+ * In US, the reason matters for audit:
476
+ * - "RESALE" -> Buyer has a resale certificate
477
+ * - "GOVT" -> Government entity (exempt in most states)
478
+ * - "NONPROFIT" -> Registered nonprofit organization
479
+ */
480
+ export interface ITaxExemption {
481
+ _id: number;
482
+ OId: number;
483
+ EId: number;
484
+ RegimeId?: number;
485
+ Code: string; // "EXPORT_WO_PAY", "SEZ_WO_PAY", "RESALE", "GOVT"
486
+ Name: string; // "Export without payment of tax"
487
+ Description?: string;
488
+ AppliesTo: "Item" | "Contact" | "Both";
489
+ Category: TaxCategory; // "Exempt", "Zero", "Nil", "NonTaxable"
490
+ IsActive: boolean;
491
+ }
492
+
493
+ // ============================================================
494
+ // TaxAuthority — Tax jurisdictions (v2, primarily for US)
495
+ // ============================================================
496
+
497
+ /**
498
+ * Tax Authority represents a government body that levies and collects tax.
499
+ *
500
+ * Not needed for India v1. Critical for US sales tax where each
501
+ * state, county, city, and special district can levy tax independently.
502
+ */
503
+ export interface ITaxAuthority {
504
+ _id: number;
505
+ OId: number;
506
+ EId: number;
507
+ Name: string; // "Texas Comptroller of Public Accounts"
508
+ Jurisdiction: "Federal" | "State" | "County" | "City" | "District";
509
+ Country: string; // "US"
510
+ State?: string; // "TX"
511
+ County?: string; // "Travis"
512
+ City?: string; // "Austin"
513
+ TaxIdLabel?: string; // "State Tax ID"
514
+ IsActive: boolean;
515
+ }
516
+
517
+ // ============================================================
518
+ // ExternalProvider — Hook for external tax engines (v2)
519
+ // ============================================================
520
+
521
+ /**
522
+ * Configuration for an external tax calculation provider
523
+ * (Avalara, TaxJar, Vertex). Not implemented in v1.
524
+ */
525
+ export interface IExternalProvider {
526
+ _id: number;
527
+ OId: number;
528
+ EId: number;
529
+ Engine: "Avalara" | "TaxJar" | "Vertex" | "Custom";
530
+ Name: string; // "Avalara AvaTax"
531
+ ApiUrl?: string; // Base URL (for Custom)
532
+ ApiKeyRef?: string; // Reference to secret store (NOT the actual key)
533
+ Country?: string; // "US" — scope the provider to a country
534
+ IsActive: boolean;
535
+ }