ofpos-shared-core 1.1.0

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 (143) hide show
  1. package/README.md +37 -0
  2. package/dist/AdapterRegistry.d.ts +83 -0
  3. package/dist/DomainServices.d.ts +151 -0
  4. package/dist/IntegrationServices.d.ts +75 -0
  5. package/dist/PosCore.d.ts +216 -0
  6. package/dist/contracts/contractVersioning.d.ts +6 -0
  7. package/dist/contracts/crossDomainPrimitives.d.ts +5 -0
  8. package/dist/contracts/responseEnvelope.d.ts +6 -0
  9. package/dist/contracts/syncProtocol.d.ts +8 -0
  10. package/dist/data/DbAdapter.d.ts +7 -0
  11. package/dist/data/applyPendingMigrations.d.ts +18 -0
  12. package/dist/data/inMemoryDbAdapter.d.ts +65 -0
  13. package/dist/data/migrations.d.ts +12 -0
  14. package/dist/data/relations.d.ts +3 -0
  15. package/dist/data/schema.d.ts +9 -0
  16. package/dist/data/seed.d.ts +370 -0
  17. package/dist/index.browser.mjs +18 -0
  18. package/dist/index.browser.mjs.LEGAL.txt +46 -0
  19. package/dist/index.cjs.js +18 -0
  20. package/dist/index.cjs.js.LEGAL.txt +46 -0
  21. package/dist/index.d.ts +116 -0
  22. package/dist/index.esm.js +18 -0
  23. package/dist/index.esm.js.LEGAL.txt +46 -0
  24. package/dist/index.umd.js +18 -0
  25. package/dist/index.umd.js.LEGAL.txt +46 -0
  26. package/dist/integration/NotificationAdapter.d.ts +69 -0
  27. package/dist/integration/activityLogger.d.ts +44 -0
  28. package/dist/integration/activitySink.d.ts +8 -0
  29. package/dist/integration/apiService.d.ts +255 -0
  30. package/dist/integration/authorizationService.d.ts +225 -0
  31. package/dist/integration/backupScheduler.d.ts +75 -0
  32. package/dist/integration/checksum.d.ts +9 -0
  33. package/dist/integration/checksumAdapter.d.ts +8 -0
  34. package/dist/integration/configService.d.ts +431 -0
  35. package/dist/integration/defaultChecksumAdapter.d.ts +6 -0
  36. package/dist/integration/defaultEncryptionAdapter.d.ts +9 -0
  37. package/dist/integration/encryption.d.ts +95 -0
  38. package/dist/integration/encryptionAdapter.d.ts +8 -0
  39. package/dist/integration/httpAdapter.d.ts +9 -0
  40. package/dist/integration/loggerAdapter.d.ts +45 -0
  41. package/dist/integration/notificationService.d.ts +45 -0
  42. package/dist/integration/ofauthBridge.d.ts +29 -0
  43. package/dist/integration/ofauthCoreBridge.d.ts +19 -0
  44. package/dist/integration/platformAdapter.d.ts +8 -0
  45. package/dist/integration/roleAdapter.d.ts +61 -0
  46. package/dist/integration/socket.d.ts +60 -0
  47. package/dist/integration/socketAdapter.d.ts +8 -0
  48. package/dist/integration/userService.d.ts +126 -0
  49. package/dist/models/Bom.d.ts +17 -0
  50. package/dist/models/Category.d.ts +13 -0
  51. package/dist/models/Customer.d.ts +17 -0
  52. package/dist/models/CustomerGroup.d.ts +11 -0
  53. package/dist/models/Expense.d.ts +19 -0
  54. package/dist/models/FinancialSetting.d.ts +14 -0
  55. package/dist/models/History.d.ts +18 -0
  56. package/dist/models/InventoryLog.d.ts +23 -0
  57. package/dist/models/InventoryLot.d.ts +34 -0
  58. package/dist/models/KitchenTicket.d.ts +13 -0
  59. package/dist/models/KitchenTicketItem.d.ts +12 -0
  60. package/dist/models/LoyaltyAccount.d.ts +12 -0
  61. package/dist/models/LoyaltyLedger.d.ts +17 -0
  62. package/dist/models/Order.d.ts +45 -0
  63. package/dist/models/OrderItem.d.ts +19 -0
  64. package/dist/models/Payable.d.ts +23 -0
  65. package/dist/models/PriceHistory.d.ts +17 -0
  66. package/dist/models/PriceTier.d.ts +19 -0
  67. package/dist/models/Product.d.ts +25 -0
  68. package/dist/models/Promotion.d.ts +25 -0
  69. package/dist/models/Purchase.d.ts +29 -0
  70. package/dist/models/PurchaseItem.d.ts +21 -0
  71. package/dist/models/PurchaseOrder.d.ts +23 -0
  72. package/dist/models/PurchaseOrderItem.d.ts +19 -0
  73. package/dist/models/Receivable.d.ts +23 -0
  74. package/dist/models/ReportSchedule.d.ts +21 -0
  75. package/dist/models/Return.d.ts +57 -0
  76. package/dist/models/ReturnItem.d.ts +31 -0
  77. package/dist/models/Role.d.ts +13 -0
  78. package/dist/models/Sale.d.ts +43 -0
  79. package/dist/models/SaleItem.d.ts +19 -0
  80. package/dist/models/Settlement.d.ts +23 -0
  81. package/dist/models/Shift.d.ts +41 -0
  82. package/dist/models/StockAdjustment.d.ts +21 -0
  83. package/dist/models/StockOpname.d.ts +22 -0
  84. package/dist/models/StockOpnameItem.d.ts +27 -0
  85. package/dist/models/Supplier.d.ts +19 -0
  86. package/dist/models/TaxRate.d.ts +13 -0
  87. package/dist/models/Transaction.d.ts +32 -0
  88. package/dist/models/Uom.d.ts +15 -0
  89. package/dist/models/User.d.ts +21 -0
  90. package/dist/services/bomService.d.ts +71 -0
  91. package/dist/services/cartService.d.ts +65 -0
  92. package/dist/services/categoryService.d.ts +54 -0
  93. package/dist/services/customerGroupService.d.ts +47 -0
  94. package/dist/services/customerService.d.ts +133 -0
  95. package/dist/services/documentNumberPolicy.d.ts +15 -0
  96. package/dist/services/expenseService.d.ts +47 -0
  97. package/dist/services/exportAdapter.d.ts +48 -0
  98. package/dist/services/exportService.d.ts +263 -0
  99. package/dist/services/financialSettingService.d.ts +47 -0
  100. package/dist/services/historyService.d.ts +60 -0
  101. package/dist/services/inventoryLogService.d.ts +47 -0
  102. package/dist/services/inventoryService.d.ts +43 -0
  103. package/dist/services/orderItemService.d.ts +47 -0
  104. package/dist/services/orderService.d.ts +161 -0
  105. package/dist/services/payableService.d.ts +51 -0
  106. package/dist/services/priceHistoryService.d.ts +61 -0
  107. package/dist/services/priceTierService.d.ts +47 -0
  108. package/dist/services/pricingService.d.ts +192 -0
  109. package/dist/services/productService.d.ts +59 -0
  110. package/dist/services/promotionService.d.ts +47 -0
  111. package/dist/services/purchaseItemService.d.ts +47 -0
  112. package/dist/services/purchaseOrderItemService.d.ts +47 -0
  113. package/dist/services/purchaseOrderService.d.ts +47 -0
  114. package/dist/services/purchaseService.d.ts +130 -0
  115. package/dist/services/receivableService.d.ts +47 -0
  116. package/dist/services/reportScheduleService.d.ts +47 -0
  117. package/dist/services/reportingService.d.ts +251 -0
  118. package/dist/services/returnItemService.d.ts +47 -0
  119. package/dist/services/returnService.d.ts +123 -0
  120. package/dist/services/roleService.d.ts +47 -0
  121. package/dist/services/saleItemService.d.ts +47 -0
  122. package/dist/services/saleService.d.ts +154 -0
  123. package/dist/services/settlementService.d.ts +68 -0
  124. package/dist/services/shiftService.d.ts +92 -0
  125. package/dist/services/stockAdjustmentService.d.ts +47 -0
  126. package/dist/services/stockOpnameItemService.d.ts +47 -0
  127. package/dist/services/stockOpnameService.d.ts +51 -0
  128. package/dist/services/stockTransferService.d.ts +67 -0
  129. package/dist/services/supplierService.d.ts +51 -0
  130. package/dist/services/taxRateService.d.ts +47 -0
  131. package/dist/services/taxService.d.ts +63 -0
  132. package/dist/services/transactionService.d.ts +109 -0
  133. package/dist/services/uiProductService.d.ts +102 -0
  134. package/dist/services/uiTransactionService.d.ts +68 -0
  135. package/dist/services/uomService.d.ts +53 -0
  136. package/dist/services/userService.d.ts +47 -0
  137. package/dist/stores/cartStore.d.ts +109 -0
  138. package/dist/stores/eventBus.d.ts +55 -0
  139. package/dist/stores/sessionStore.d.ts +108 -0
  140. package/dist/stores/storageAdapter.d.ts +44 -0
  141. package/dist/stores/syncService.d.ts +90 -0
  142. package/dist/stores/syncStore.d.ts +163 -0
  143. package/package.json +82 -0
@@ -0,0 +1,263 @@
1
+ import type { PosCore } from '../PosCore';
2
+ export type TaxReadyExportParams = {
3
+ from?: string;
4
+ to?: string;
5
+ periodLabel?: string;
6
+ baseCurrencyCode?: string;
7
+ compatibilityTarget?: 'N' | 'N-1';
8
+ };
9
+ export type TaxReadyExportRecordSets = {
10
+ sales: Array<{
11
+ id: string;
12
+ date: string;
13
+ total: number;
14
+ discount: number;
15
+ ppn: number;
16
+ pph: number;
17
+ finalTotal: number;
18
+ status: string;
19
+ customerId: string | null;
20
+ userId: string;
21
+ }>;
22
+ returns: Array<{
23
+ id: string;
24
+ date: string;
25
+ type: string;
26
+ refundAmount: number;
27
+ actualRefund: number;
28
+ status: string;
29
+ saleId: string | null;
30
+ purchaseId: string | null;
31
+ userId: string;
32
+ }>;
33
+ purchases: Array<{
34
+ id: string;
35
+ date: string;
36
+ total: number;
37
+ supplierId: string;
38
+ userId: string;
39
+ purchaseOrderId: string | null;
40
+ }>;
41
+ payments: Array<{
42
+ id: string;
43
+ date: string;
44
+ amount: number;
45
+ method: string;
46
+ direction: 'in' | 'out';
47
+ receivableId: string | null;
48
+ payableId: string | null;
49
+ reference: string | null;
50
+ userId: string;
51
+ }>;
52
+ };
53
+ export type TaxReadyExportSummary = {
54
+ salesFinalTotal: number;
55
+ salesPpnTotal: number;
56
+ salesPphTotal: number;
57
+ returnsActualRefundTotal: number;
58
+ purchasesTotal: number;
59
+ paymentInTotal: number;
60
+ paymentOutTotal: number;
61
+ };
62
+ export type TaxReadyExportContract = {
63
+ contractVersion: 'tex-v1';
64
+ generatedAt: string;
65
+ sourceVersion: string;
66
+ period: {
67
+ from: string | null;
68
+ to: string | null;
69
+ label: string | null;
70
+ };
71
+ currency: {
72
+ baseCurrencyCode: string;
73
+ };
74
+ records: TaxReadyExportRecordSets;
75
+ summary: TaxReadyExportSummary;
76
+ };
77
+ export type TaxReadyExportContractV0 = {
78
+ contractVersion: 'tex-v0';
79
+ generatedAt: string;
80
+ sourceVersion: string;
81
+ period: {
82
+ from: string | null;
83
+ to: string | null;
84
+ label: string | null;
85
+ };
86
+ currency: {
87
+ baseCurrencyCode: string;
88
+ };
89
+ records: {
90
+ sales: Array<{
91
+ id: string;
92
+ date: string;
93
+ total: number;
94
+ discount: number;
95
+ taxTotal: number;
96
+ finalTotal: number;
97
+ status: string;
98
+ customerId: string | null;
99
+ userId: string;
100
+ }>;
101
+ returns: TaxReadyExportRecordSets['returns'];
102
+ purchases: TaxReadyExportRecordSets['purchases'];
103
+ payments: Array<{
104
+ id: string;
105
+ date: string;
106
+ amount: number;
107
+ method: string;
108
+ flow: 'receipt' | 'disbursement';
109
+ receivableId: string | null;
110
+ payableId: string | null;
111
+ reference: string | null;
112
+ userId: string;
113
+ }>;
114
+ };
115
+ summary: {
116
+ salesFinalTotal: number;
117
+ salesTaxTotal: number;
118
+ returnsActualRefundTotal: number;
119
+ purchasesTotal: number;
120
+ paymentInTotal: number;
121
+ paymentOutTotal: number;
122
+ };
123
+ };
124
+ export type TaxReadyExportContractAny = TaxReadyExportContract | TaxReadyExportContractV0;
125
+ export type FiscalArchiveSnapshot = {
126
+ archiveId: string;
127
+ generatedAt: string;
128
+ period: {
129
+ from: string | null;
130
+ to: string | null;
131
+ label: string | null;
132
+ };
133
+ files: Record<string, string>;
134
+ manifest: {
135
+ archiveId: string;
136
+ generatedAt: string;
137
+ contractVersion: 'tex-v1' | 'tex-v0';
138
+ sourceVersion: string;
139
+ period: {
140
+ from: string | null;
141
+ to: string | null;
142
+ label: string | null;
143
+ };
144
+ currency: {
145
+ baseCurrencyCode: string;
146
+ };
147
+ summary: TaxReadyExportSummary;
148
+ checksum: string;
149
+ actorId: string;
150
+ reason: string;
151
+ };
152
+ };
153
+ /**
154
+ * Layanan ekspor data ke format CSV.
155
+ */
156
+ export interface IExportService {
157
+ /**
158
+ * Mengubah header dan baris menjadi string CSV.
159
+ * @param headers Daftar nama kolom
160
+ * @param rows Daftar baris data
161
+ * @returns CSV sebagai string
162
+ */
163
+ toCsv(headers: string[], rows: string[][]): string;
164
+ /**
165
+ * Mengekspor laporan penjualan sebagai CSV dan membagikannya.
166
+ * @param params Parameter filter tanggal (date tunggal atau rentang from/to)
167
+ */
168
+ exportSalesReportCSV(params?: {
169
+ date?: string;
170
+ from?: string;
171
+ to?: string;
172
+ }): Promise<void>;
173
+ /**
174
+ * Mengekspor laporan stok produk sebagai CSV dan membagikannya.
175
+ */
176
+ exportStockCSV(): Promise<void>;
177
+ /**
178
+ * Mengekspor daftar pelanggan sebagai CSV dan membagikannya.
179
+ */
180
+ exportCustomersCSV(): Promise<void>;
181
+ /**
182
+ * Membuat snapshot backup lokal seluruh tabel domain dalam format JSON.
183
+ */
184
+ createLocalBackupSnapshot(): Promise<string>;
185
+ /**
186
+ * Me-restore snapshot backup lokal JSON ke database aktif.
187
+ * Seluruh data saat ini akan diganti oleh isi snapshot.
188
+ */
189
+ restoreLocalBackupSnapshot(snapshotJson: string): Promise<void>;
190
+ /**
191
+ * Membuat kontrak export netral-regulasi untuk kebutuhan laporan pajak/keuangan.
192
+ */
193
+ createTaxReadyExportContract(params?: TaxReadyExportParams): Promise<TaxReadyExportContractAny>;
194
+ /**
195
+ * Menormalkan kontrak export `N` atau `N-1` ke struktur canonical terbaru (`tex-v1`).
196
+ */
197
+ normalizeTaxReadyExportContract(contract: TaxReadyExportContractAny): TaxReadyExportContract;
198
+ /**
199
+ * Membuat paket CSV-ready dari kontrak export netral-regulasi.
200
+ * Tiap key pada hasil mewakili nama file dan value berisi isi file.
201
+ */
202
+ createTaxReadyExportCsvBundle(params?: TaxReadyExportParams): Promise<Record<string, string>>;
203
+ /**
204
+ * Membuat snapshot arsip dokumen fiskal + jejak audit.
205
+ */
206
+ createFiscalArchiveSnapshot(input: {
207
+ actorId: string;
208
+ reason: string;
209
+ } & TaxReadyExportParams): Promise<FiscalArchiveSnapshot>;
210
+ }
211
+ /**
212
+ * Implementasi layanan ekspor data ke CSV menggunakan DbAdapter dan ExportAdapter.
213
+ */
214
+ export declare class ExportService implements IExportService {
215
+ private context;
216
+ private readonly dbAdapter;
217
+ private readonly exportAdapter;
218
+ private readonly inventoryService;
219
+ /**
220
+ * @param context Konteks aplikasi PosCore yang menyediakan dependensi
221
+ */
222
+ constructor(context: PosCore);
223
+ /**
224
+ * Mengubah header dan baris menjadi string CSV.
225
+ * @param headers Daftar nama kolom
226
+ * @param rows Daftar baris data
227
+ * @returns CSV sebagai string
228
+ */
229
+ toCsv(headers: string[], rows: string[][]): string;
230
+ /**
231
+ * Mengekspor laporan penjualan sebagai CSV dan membagikannya.
232
+ * @param params Parameter filter tanggal (date tunggal atau rentang from/to)
233
+ */
234
+ exportSalesReportCSV(params?: {
235
+ date?: string;
236
+ from?: string;
237
+ to?: string;
238
+ }): Promise<void>;
239
+ /**
240
+ * Mengekspor laporan stok produk sebagai CSV dan membagikannya.
241
+ */
242
+ exportStockCSV(): Promise<void>;
243
+ /**
244
+ * Mengekspor daftar pelanggan sebagai CSV dan membagikannya.
245
+ */
246
+ exportCustomersCSV(): Promise<void>;
247
+ /**
248
+ * Membuat snapshot backup lokal seluruh tabel domain.
249
+ */
250
+ createLocalBackupSnapshot(): Promise<string>;
251
+ /**
252
+ * Restore snapshot backup lokal ke DB aktif.
253
+ */
254
+ restoreLocalBackupSnapshot(snapshotJson: string): Promise<void>;
255
+ createTaxReadyExportContract(params?: TaxReadyExportParams): Promise<TaxReadyExportContractAny>;
256
+ createTaxReadyExportCsvBundle(params?: TaxReadyExportParams): Promise<Record<string, string>>;
257
+ normalizeTaxReadyExportContract(contract: TaxReadyExportContractAny): TaxReadyExportContract;
258
+ createFiscalArchiveSnapshot(input: {
259
+ actorId: string;
260
+ reason: string;
261
+ } & TaxReadyExportParams): Promise<FiscalArchiveSnapshot>;
262
+ private isWithinPeriod;
263
+ }
@@ -0,0 +1,47 @@
1
+ import { PosCore } from '../PosCore';
2
+ import { DbAdapter, QueryOptions } from 'ofcore';
3
+ import { FinancialSetting, FinancialSettingData } from '../models/FinancialSetting';
4
+ /** Service interface for FinancialSetting operations. */
5
+ export interface IFinancialSettingService {
6
+ /** Add new FinancialSetting. */
7
+ addFinancialSetting(data: FinancialSettingData, tx?: DbAdapter): Promise<FinancialSetting>;
8
+ /** Update existing FinancialSetting. */
9
+ updateFinancialSetting(id: string, data: Partial<FinancialSettingData>): Promise<FinancialSetting>;
10
+ /** Get all FinancialSettings with complex options. */
11
+ getFinancialSettings(options?: QueryOptions, tx?: DbAdapter): Promise<FinancialSetting[]>;
12
+ /** Get FinancialSetting by ID or options. */
13
+ getFinancialSetting(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<FinancialSetting | null>;
14
+ /** Delete FinancialSetting (logical). */
15
+ deleteFinancialSetting(id: string, tx?: DbAdapter): Promise<{
16
+ id: string;
17
+ queued: boolean;
18
+ }>;
19
+ /** Duplicate FinancialSetting by ID. */
20
+ duplicateFinancialSetting(originalId: string, tx?: DbAdapter): Promise<FinancialSetting>;
21
+ }
22
+ /** Service implementation for FinancialSetting operations. */
23
+ export declare class FinancialSettingService implements IFinancialSettingService {
24
+ private context;
25
+ private dbAdapter;
26
+ private syncStore?;
27
+ /**
28
+ * Initialize FinancialSettingService.
29
+ * @param context - PosCore context
30
+ */
31
+ constructor(context: PosCore);
32
+ /** Add new FinancialSetting. */
33
+ addFinancialSetting(data: FinancialSettingData, tx?: DbAdapter): Promise<FinancialSetting>;
34
+ /** Update existing FinancialSetting. */
35
+ updateFinancialSetting(id: string, data: Partial<FinancialSettingData>, tx?: DbAdapter): Promise<FinancialSetting>;
36
+ /** Get all FinancialSettings with complex options. */
37
+ getFinancialSettings(options?: QueryOptions, tx?: DbAdapter): Promise<FinancialSetting[]>;
38
+ /** Get FinancialSetting by ID or options. */
39
+ getFinancialSetting(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<FinancialSetting | null>;
40
+ /** Delete FinancialSetting (logical). */
41
+ deleteFinancialSetting(id: string, tx?: DbAdapter): Promise<{
42
+ id: string;
43
+ queued: boolean;
44
+ }>;
45
+ /** Duplicate FinancialSetting by ID. */
46
+ duplicateFinancialSetting(originalId: string, tx?: DbAdapter): Promise<FinancialSetting>;
47
+ }
@@ -0,0 +1,60 @@
1
+ import { PosCore } from '../PosCore';
2
+ import { DbAdapter, QueryOptions } from 'ofcore';
3
+ import { History, HistoryData } from '../models/History';
4
+ /** Service interface for History operations. */
5
+ export interface IHistoryService {
6
+ /** Add new History. */
7
+ addHistory(data: HistoryData, tx?: DbAdapter): Promise<History>;
8
+ /** Update existing History. */
9
+ updateHistory(id: string, data: Partial<HistoryData>): Promise<History>;
10
+ /** Get all Histories with complex options. */
11
+ getHistories(options?: QueryOptions, tx?: DbAdapter): Promise<History[]>;
12
+ /** Get History by ID or options. */
13
+ getHistory(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<History | null>;
14
+ /** Delete History (logical). */
15
+ deleteHistory(id: string, tx?: DbAdapter): Promise<{
16
+ id: string;
17
+ queued: boolean;
18
+ }>;
19
+ /** Duplicate History by ID. */
20
+ duplicateHistory(originalId: string, tx?: DbAdapter): Promise<History>;
21
+ /** Enforce retention: archive then purge old audit logs according to config. */
22
+ enforceRetentionPolicy(now?: Date): Promise<{
23
+ scanned: number;
24
+ archived: number;
25
+ purged: number;
26
+ archiveKey: string | null;
27
+ }>;
28
+ }
29
+ /** Service implementation for History operations. */
30
+ export declare class HistoryService implements IHistoryService {
31
+ private context;
32
+ private dbAdapter;
33
+ private syncStore?;
34
+ /**
35
+ * Initialize HistoryService.
36
+ * @param context - PosCore context
37
+ */
38
+ constructor(context: PosCore);
39
+ /** Add new History. */
40
+ addHistory(data: HistoryData, tx?: DbAdapter): Promise<History>;
41
+ /** Update existing History. */
42
+ updateHistory(id: string, data: Partial<HistoryData>, tx?: DbAdapter): Promise<History>;
43
+ /** Get all Histories with complex options. */
44
+ getHistories(options?: QueryOptions, tx?: DbAdapter): Promise<History[]>;
45
+ /** Get History by ID or options. */
46
+ getHistory(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<History | null>;
47
+ /** Delete History (logical). */
48
+ deleteHistory(id: string, tx?: DbAdapter): Promise<{
49
+ id: string;
50
+ queued: boolean;
51
+ }>;
52
+ /** Duplicate History by ID. */
53
+ duplicateHistory(originalId: string, tx?: DbAdapter): Promise<History>;
54
+ enforceRetentionPolicy(now?: Date): Promise<{
55
+ scanned: number;
56
+ archived: number;
57
+ purged: number;
58
+ archiveKey: string | null;
59
+ }>;
60
+ }
@@ -0,0 +1,47 @@
1
+ import { PosCore } from '../PosCore';
2
+ import { DbAdapter, QueryOptions } from 'ofcore';
3
+ import { InventoryLog, InventoryLogData } from '../models/InventoryLog';
4
+ /** Service interface for InventoryLog operations. */
5
+ export interface IInventoryLogService {
6
+ /** Add new InventoryLog. */
7
+ addInventoryLog(data: InventoryLogData, tx?: DbAdapter): Promise<InventoryLog>;
8
+ /** Update existing InventoryLog. */
9
+ updateInventoryLog(id: string, data: Partial<InventoryLogData>): Promise<InventoryLog>;
10
+ /** Get all InventoryLogs with complex options. */
11
+ getInventoryLogs(options?: QueryOptions, tx?: DbAdapter): Promise<InventoryLog[]>;
12
+ /** Get InventoryLog by ID or options. */
13
+ getInventoryLog(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<InventoryLog | null>;
14
+ /** Delete InventoryLog (logical). */
15
+ deleteInventoryLog(id: string, tx?: DbAdapter): Promise<{
16
+ id: string;
17
+ queued: boolean;
18
+ }>;
19
+ /** Duplicate InventoryLog by ID. */
20
+ duplicateInventoryLog(originalId: string, tx?: DbAdapter): Promise<InventoryLog>;
21
+ }
22
+ /** Service implementation for InventoryLog operations. */
23
+ export declare class InventoryLogService implements IInventoryLogService {
24
+ private context;
25
+ private dbAdapter;
26
+ private syncStore?;
27
+ /**
28
+ * Initialize InventoryLogService.
29
+ * @param context - PosCore context
30
+ */
31
+ constructor(context: PosCore);
32
+ /** Add new InventoryLog. */
33
+ addInventoryLog(data: InventoryLogData, tx?: DbAdapter): Promise<InventoryLog>;
34
+ /** Update existing InventoryLog. */
35
+ updateInventoryLog(id: string, data: Partial<InventoryLogData>, tx?: DbAdapter): Promise<InventoryLog>;
36
+ /** Get all InventoryLogs with complex options. */
37
+ getInventoryLogs(options?: QueryOptions, tx?: DbAdapter): Promise<InventoryLog[]>;
38
+ /** Get InventoryLog by ID or options. */
39
+ getInventoryLog(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<InventoryLog | null>;
40
+ /** Delete InventoryLog (logical). */
41
+ deleteInventoryLog(id: string, tx?: DbAdapter): Promise<{
42
+ id: string;
43
+ queued: boolean;
44
+ }>;
45
+ /** Duplicate InventoryLog by ID. */
46
+ duplicateInventoryLog(originalId: string, tx?: DbAdapter): Promise<InventoryLog>;
47
+ }
@@ -0,0 +1,43 @@
1
+ import { PosCore } from '../PosCore';
2
+ import { DbAdapter } from 'ofcore';
3
+ import { Product } from '../models/Product';
4
+ /**
5
+ * Layanan manajemen stok inventori untuk membaca dan memperbarui catatan stok.
6
+ */
7
+ export interface IInventoryService {
8
+ getStock(productId: string): Promise<number>;
9
+ updateStock(productId: string, change: number, reason: string, referenceType?: string, referenceId?: string, tx?: DbAdapter): Promise<void>;
10
+ /** Baru: untuk host app */
11
+ rebuildStockCache(): Promise<void>;
12
+ clearStockCache(): void;
13
+ getLowStockProducts(threshold?: number, limit?: number): Promise<Array<{
14
+ productId: string;
15
+ stock: number;
16
+ product: Product;
17
+ }>>;
18
+ }
19
+ export declare class InventoryService implements IInventoryService {
20
+ private context;
21
+ private adapter;
22
+ private syncStore;
23
+ private stockCache;
24
+ private isRebuilding;
25
+ constructor(context: PosCore);
26
+ /** API publik paling simpel: langsung return number */
27
+ getStock(productId: string): Promise<number>;
28
+ /** Update stok + update cache secara atomik (pasti sinkron!) */
29
+ updateStock(productId: string, change: number, reason: string, referenceType?: string, referenceId?: string, tx?: DbAdapter): Promise<void>;
30
+ /** Untuk host app: rebuild cache saat startup atau setelah sync besar */
31
+ rebuildStockCache(): Promise<void>;
32
+ clearStockCache(): void;
33
+ private computeStockFromLogs;
34
+ /**
35
+ * Daftar produk dengan stock rendah — OPTIMIZED untuk offline-first
36
+ * Menggunakan cache stok langsung → tidak perlu hitung ulang dari logs
37
+ */
38
+ getLowStockProducts(threshold?: number, limit?: number): Promise<Array<{
39
+ productId: string;
40
+ stock: number;
41
+ product: Product;
42
+ }>>;
43
+ }
@@ -0,0 +1,47 @@
1
+ import { PosCore } from '../PosCore';
2
+ import { DbAdapter, QueryOptions } from 'ofcore';
3
+ import { OrderItem, OrderItemData } from '../models/OrderItem';
4
+ /** Service interface for OrderItem operations. */
5
+ export interface IOrderItemService {
6
+ /** Add new OrderItem. */
7
+ addOrderItem(data: OrderItemData, tx?: DbAdapter): Promise<OrderItem>;
8
+ /** Update existing OrderItem. */
9
+ updateOrderItem(id: string, data: Partial<OrderItemData>): Promise<OrderItem>;
10
+ /** Get all OrderItems with complex options. */
11
+ getOrderItems(options?: QueryOptions, tx?: DbAdapter): Promise<OrderItem[]>;
12
+ /** Get OrderItem by ID or options. */
13
+ getOrderItem(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<OrderItem | null>;
14
+ /** Delete OrderItem (logical). */
15
+ deleteOrderItem(id: string, tx?: DbAdapter): Promise<{
16
+ id: string;
17
+ queued: boolean;
18
+ }>;
19
+ /** Duplicate OrderItem by ID. */
20
+ duplicateOrderItem(originalId: string, tx?: DbAdapter): Promise<OrderItem>;
21
+ }
22
+ /** Service implementation for OrderItem operations. */
23
+ export declare class OrderItemService implements IOrderItemService {
24
+ private context;
25
+ private dbAdapter;
26
+ private syncStore?;
27
+ /**
28
+ * Initialize OrderItemService.
29
+ * @param context - PosCore context
30
+ */
31
+ constructor(context: PosCore);
32
+ /** Add new OrderItem. */
33
+ addOrderItem(data: OrderItemData, tx?: DbAdapter): Promise<OrderItem>;
34
+ /** Update existing OrderItem. */
35
+ updateOrderItem(id: string, data: Partial<OrderItemData>, tx?: DbAdapter): Promise<OrderItem>;
36
+ /** Get all OrderItems with complex options. */
37
+ getOrderItems(options?: QueryOptions, tx?: DbAdapter): Promise<OrderItem[]>;
38
+ /** Get OrderItem by ID or options. */
39
+ getOrderItem(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<OrderItem | null>;
40
+ /** Delete OrderItem (logical). */
41
+ deleteOrderItem(id: string, tx?: DbAdapter): Promise<{
42
+ id: string;
43
+ queued: boolean;
44
+ }>;
45
+ /** Duplicate OrderItem by ID. */
46
+ duplicateOrderItem(originalId: string, tx?: DbAdapter): Promise<OrderItem>;
47
+ }
@@ -0,0 +1,161 @@
1
+ import { PosCore } from '../PosCore';
2
+ import { DbAdapter, QueryOptions } from 'ofcore';
3
+ import { Order, OrderData } from '../models/Order';
4
+ import { KitchenTicketItem } from '../models/KitchenTicketItem';
5
+ import { KitchenTicket } from '../models/KitchenTicket';
6
+ type OrderLifecycleStatus = 'draft' | 'confirmed' | 'preparing' | 'ready' | 'out_for_delivery' | 'completed' | 'canceled' | 'merged';
7
+ /** Service interface for Order operations. */
8
+ export interface IOrderService {
9
+ /** Add new Order. */
10
+ addOrder(data: OrderData, tx?: DbAdapter): Promise<Order>;
11
+ /** Update existing Order. */
12
+ updateOrder(id: string, data: Partial<OrderData>): Promise<Order>;
13
+ /** Get all Orders with complex options. */
14
+ getOrders(options?: QueryOptions, tx?: DbAdapter): Promise<Order[]>;
15
+ /** Get Order by ID or options. */
16
+ getOrder(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<Order | null>;
17
+ /** Delete Order (logical). */
18
+ deleteOrder(id: string, tx?: DbAdapter): Promise<{
19
+ id: string;
20
+ queued: boolean;
21
+ }>;
22
+ /** Duplicate Order by ID. */
23
+ duplicateOrder(originalId: string, tx?: DbAdapter): Promise<Order>;
24
+ /** Finalize order by ID */
25
+ finalizeOrder(orderId: string): Promise<{
26
+ id: string;
27
+ queued: boolean;
28
+ }>;
29
+ /** Transition lifecycle status for omnichannel order. */
30
+ transitionOrderLifecycle(input: {
31
+ orderId: string;
32
+ toStatus: OrderLifecycleStatus;
33
+ actorId: string;
34
+ reason?: string | null;
35
+ }): Promise<Order>;
36
+ /** Build kitchen ticket and route order items to station/course buckets. */
37
+ createKitchenTicket(input: {
38
+ orderId: string;
39
+ station: string;
40
+ actorId: string;
41
+ note?: string | null;
42
+ items: Array<{
43
+ orderItemId: string;
44
+ course?: string | null;
45
+ note?: string | null;
46
+ }>;
47
+ }): Promise<{
48
+ ticket: KitchenTicket;
49
+ items: KitchenTicketItem[];
50
+ }>;
51
+ /** Split bill by moving selected order items to child orders. */
52
+ splitOrderBill(input: {
53
+ orderId: string;
54
+ actorId: string;
55
+ splits: Array<{
56
+ label: string;
57
+ orderItemIds: string[];
58
+ }>;
59
+ }): Promise<{
60
+ parentOrderId: string;
61
+ childOrderIds: string[];
62
+ }>;
63
+ /** Merge source orders into target order by moving all items. */
64
+ mergeOrderBills(input: {
65
+ targetOrderId: string;
66
+ sourceOrderIds: string[];
67
+ actorId: string;
68
+ }): Promise<{
69
+ targetOrderId: string;
70
+ mergedOrderIds: string[];
71
+ }>;
72
+ /** Apply service charge and gratuity policy onto order total. */
73
+ applyServiceChargeAndGratuity(input: {
74
+ orderId: string;
75
+ actorId: string;
76
+ serviceChargeRate: number;
77
+ gratuityRate: number;
78
+ }): Promise<Order>;
79
+ }
80
+ /** Service implementation for Order operations. */
81
+ export declare class OrderService implements IOrderService {
82
+ private context;
83
+ private dbAdapter;
84
+ private syncStore?;
85
+ private docNumberPolicy;
86
+ /**
87
+ * Initialize OrderService.
88
+ * @param context - PosCore context
89
+ */
90
+ constructor(context: PosCore);
91
+ private runInTransaction;
92
+ private validateOmnichannelInput;
93
+ private isValidTransition;
94
+ private recalculateOrderTotals;
95
+ /** Add new Order. */
96
+ addOrder(data: OrderData, tx?: DbAdapter): Promise<Order>;
97
+ /** Update existing Order. */
98
+ updateOrder(id: string, data: Partial<OrderData>, tx?: DbAdapter): Promise<Order>;
99
+ /** Get all Orders with complex options. */
100
+ getOrders(options?: QueryOptions, tx?: DbAdapter): Promise<Order[]>;
101
+ /** Get Order by ID or options. */
102
+ getOrder(idOrOptions: string | QueryOptions, tx?: DbAdapter): Promise<Order | null>;
103
+ /** Delete Order (logical). */
104
+ deleteOrder(id: string, tx?: DbAdapter): Promise<{
105
+ id: string;
106
+ queued: boolean;
107
+ }>;
108
+ /** Duplicate Order by ID. */
109
+ duplicateOrder(originalId: string, tx?: DbAdapter): Promise<Order>;
110
+ /** Finalize order by ID */
111
+ finalizeOrder(orderId: string): Promise<{
112
+ id: string;
113
+ queued: boolean;
114
+ }>;
115
+ transitionOrderLifecycle(input: {
116
+ orderId: string;
117
+ toStatus: OrderLifecycleStatus;
118
+ actorId: string;
119
+ reason?: string | null;
120
+ }): Promise<Order>;
121
+ createKitchenTicket(input: {
122
+ orderId: string;
123
+ station: string;
124
+ actorId: string;
125
+ note?: string | null;
126
+ items: Array<{
127
+ orderItemId: string;
128
+ course?: string | null;
129
+ note?: string | null;
130
+ }>;
131
+ }): Promise<{
132
+ ticket: KitchenTicket;
133
+ items: KitchenTicketItem[];
134
+ }>;
135
+ splitOrderBill(input: {
136
+ orderId: string;
137
+ actorId: string;
138
+ splits: Array<{
139
+ label: string;
140
+ orderItemIds: string[];
141
+ }>;
142
+ }): Promise<{
143
+ parentOrderId: string;
144
+ childOrderIds: string[];
145
+ }>;
146
+ mergeOrderBills(input: {
147
+ targetOrderId: string;
148
+ sourceOrderIds: string[];
149
+ actorId: string;
150
+ }): Promise<{
151
+ targetOrderId: string;
152
+ mergedOrderIds: string[];
153
+ }>;
154
+ applyServiceChargeAndGratuity(input: {
155
+ orderId: string;
156
+ actorId: string;
157
+ serviceChargeRate: number;
158
+ gratuityRate: number;
159
+ }): Promise<Order>;
160
+ }
161
+ export {};