ofpos-shared-core 2.0.0-alpha.0 → 2.0.0-alpha.1

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.
@@ -46,6 +46,7 @@ import { IReportingService } from './services/reportingService';
46
46
  import { ICartService } from './services/cartService';
47
47
  import { ITaxService } from './services/taxService';
48
48
  import { IStockTransferService } from './services/stockTransferService';
49
+ import type { ServiceRuntimeOptions } from './services/runtimeSupport';
49
50
  /**
50
51
  * Override type for domain services, allowing custom implementations.
51
52
  */
@@ -147,5 +148,5 @@ export declare class DomainServices {
147
148
  * @param context The PosCore context.
148
149
  * @param overrides Optional overrides for domain services.
149
150
  */
150
- constructor(context: PosCore, overrides?: Partial<DomainServicesOverride>);
151
+ constructor(context: PosCore, overrides?: Partial<DomainServicesOverride>, runtimeOptions?: Partial<ServiceRuntimeOptions>);
151
152
  }
package/dist/PosCore.d.ts CHANGED
@@ -6,6 +6,7 @@ import { AdapterRegistry, AdapterRegistryOptions } from './AdapterRegistry';
6
6
  import { IntegrationServices, IntegrationServicesOverride } from './IntegrationServices';
7
7
  import { DbAdapter } from 'ofcore';
8
8
  import { SessionStore } from './stores/sessionStore';
9
+ import type { ServiceRuntimeOptions } from './services/runtimeSupport';
9
10
  /**
10
11
  * Opsi untuk memulai PosCore.
11
12
  * @property runMigrations Jika true, jalankan migrasi database sebelum inisialisasi plugin.
@@ -48,6 +49,8 @@ export declare class PosCore {
48
49
  domainServiceOverrides: Partial<DomainServicesOverride>;
49
50
  /** Override untuk integration services sebelum inisialisasi. */
50
51
  integrationServiceOverrides: Partial<IntegrationServicesOverride>;
52
+ /** Runtime options lintas service (mis. finance projection sink). */
53
+ serviceRuntimeOptions: Partial<ServiceRuntimeOptions>;
51
54
  private runtime;
52
55
  private pluginSpecs;
53
56
  private authBridgePolicyMode;
@@ -78,6 +81,7 @@ export declare class PosCore {
78
81
  */
79
82
  removeDomainQueuedChange(changeId: string): void;
80
83
  setDomainChangeSink(sink?: DomainChangeSink): void;
84
+ withServiceRuntimeOptions(options: Partial<ServiceRuntimeOptions>): this;
81
85
  /**
82
86
  * Dapatkan instansi SessionStore untuk update status login.
83
87
  */
@@ -229,6 +233,7 @@ export declare class PosCoreBuilder {
229
233
  * Override default integration services.
230
234
  */
231
235
  overrideIntegrationServices(overrides?: Partial<IntegrationServicesOverride>): this;
236
+ withServiceRuntimeOptions(options?: Partial<ServiceRuntimeOptions>): this;
232
237
  /**
233
238
  * Pilih mode orchestration sinkronisasi.
234
239
  * Saat ini hanya `host-managed` yang didukung:
@@ -1,4 +1,9 @@
1
1
  import type { Sale } from '../models/Sale';
2
+ import type { Purchase } from '../models/Purchase';
3
+ import type { Return } from '../models/Return';
4
+ import type { Expense } from '../models/Expense';
5
+ import { type FinanceAccount, type FinanceDbAdapterLike, type FinanceProjectionServicesRef, type FinanceSyncEnqueuer, type JournalDraftInput } from 'offinance-shared-core';
6
+ import type { ServiceRuntimeOptions } from '../services/runtimeSupport';
2
7
  export interface ScopedAccountMapping<TMapping> {
3
8
  default: TMapping;
4
9
  byTenant?: Record<string, Partial<TMapping>>;
@@ -10,6 +15,30 @@ export interface PosSaleAccountMapping {
10
15
  discountAccountId?: string;
11
16
  taxPayableAccountId?: string;
12
17
  }
18
+ export interface PosPurchaseAccountMapping {
19
+ inventoryAccountId: string;
20
+ paymentAccountId?: string;
21
+ payableAccountId?: string;
22
+ }
23
+ export interface PosReturnAccountMapping {
24
+ salesReturnAccountId: string;
25
+ purchaseReturnAccountId: string;
26
+ settlementAccountId: string;
27
+ }
28
+ export interface PosExpenseAccountMapping {
29
+ expenseAccountId: string;
30
+ paymentAccountId: string;
31
+ }
32
+ export interface PosSettlementAccountMapping {
33
+ cashAccountId: string;
34
+ receivableAccountId: string;
35
+ payableAccountId: string;
36
+ }
37
+ export interface PosCashAdjustmentAccountMapping {
38
+ cashAccountId: string;
39
+ cashOverShortIncomeAccountId: string;
40
+ cashOverShortExpenseAccountId: string;
41
+ }
13
42
  export interface PosFinanceAdapterContext {
14
43
  journalId: string;
15
44
  tenantId: string;
@@ -18,6 +47,7 @@ export interface PosFinanceAdapterContext {
18
47
  reference?: string;
19
48
  }
20
49
  export interface ScopedPosSaleFinanceProjection {
50
+ kind?: 'sale';
21
51
  context: PosFinanceAdapterContext;
22
52
  input: {
23
53
  grossAmount: number;
@@ -26,6 +56,55 @@ export interface ScopedPosSaleFinanceProjection {
26
56
  scopedAccountMapping: ScopedAccountMapping<PosSaleAccountMapping>;
27
57
  };
28
58
  }
59
+ export interface PosPurchaseFinanceProjection {
60
+ kind: 'purchase';
61
+ context: PosFinanceAdapterContext;
62
+ input: {
63
+ totalAmount: number;
64
+ paymentMethod: 'cash' | 'card' | 'bank_transfer' | 'tempo';
65
+ scopedAccountMapping: ScopedAccountMapping<PosPurchaseAccountMapping>;
66
+ };
67
+ }
68
+ export interface PosReturnFinanceProjection {
69
+ kind: 'sale_return' | 'purchase_return';
70
+ context: PosFinanceAdapterContext;
71
+ input: {
72
+ actualRefund: number;
73
+ scopedAccountMapping: ScopedAccountMapping<PosReturnAccountMapping>;
74
+ };
75
+ }
76
+ export interface PosExpenseFinanceProjection {
77
+ kind: 'expense';
78
+ context: PosFinanceAdapterContext;
79
+ input: {
80
+ amount: number;
81
+ category?: string | null;
82
+ description?: string | null;
83
+ scopedAccountMapping: ScopedAccountMapping<PosExpenseAccountMapping>;
84
+ };
85
+ }
86
+ export interface PosSettlementFinanceProjection {
87
+ kind: 'receivable_payment' | 'payable_payment';
88
+ context: PosFinanceAdapterContext;
89
+ input: {
90
+ amount: number;
91
+ method: string;
92
+ receivableId?: string | null;
93
+ payableId?: string | null;
94
+ scopedAccountMapping: ScopedAccountMapping<PosSettlementAccountMapping>;
95
+ };
96
+ }
97
+ export interface PosCashAdjustmentFinanceProjection {
98
+ kind: 'cash_adjustment';
99
+ context: PosFinanceAdapterContext;
100
+ input: {
101
+ amount: number;
102
+ direction: 'in' | 'out';
103
+ reason?: string | null;
104
+ scopedAccountMapping: ScopedAccountMapping<PosCashAdjustmentAccountMapping>;
105
+ };
106
+ }
107
+ export type ScopedPosFinanceProjection = ScopedPosSaleFinanceProjection | PosPurchaseFinanceProjection | PosReturnFinanceProjection | PosExpenseFinanceProjection | PosSettlementFinanceProjection | PosCashAdjustmentFinanceProjection;
29
108
  export interface ProjectScopedPosSaleFinanceInput {
30
109
  sale: Pick<Sale, 'id' | 'date' | 'total' | 'discount' | 'ppn' | 'finalTotal'>;
31
110
  tenantId: string;
@@ -34,4 +113,84 @@ export interface ProjectScopedPosSaleFinanceInput {
34
113
  journalId?: string;
35
114
  referencePrefix?: string;
36
115
  }
116
+ export interface ProjectPosPurchaseFinanceInput {
117
+ purchase: Pick<Purchase, 'id' | 'date' | 'total'>;
118
+ tenantId: string;
119
+ branchId?: string;
120
+ paymentMethod: 'cash' | 'card' | 'bank_transfer' | 'tempo';
121
+ scopedAccountMapping: ScopedAccountMapping<PosPurchaseAccountMapping>;
122
+ journalId?: string;
123
+ referencePrefix?: string;
124
+ }
125
+ export interface ProjectPosReturnFinanceInput {
126
+ returnEntry: Pick<Return, 'id' | 'date' | 'type' | 'actualRefund'>;
127
+ tenantId: string;
128
+ branchId?: string;
129
+ scopedAccountMapping: ScopedAccountMapping<PosReturnAccountMapping>;
130
+ journalId?: string;
131
+ referencePrefix?: string;
132
+ }
133
+ export interface ProjectPosExpenseFinanceInput {
134
+ expense: Pick<Expense, 'id' | 'date' | 'amount' | 'category' | 'description'>;
135
+ tenantId: string;
136
+ branchId?: string;
137
+ scopedAccountMapping: ScopedAccountMapping<PosExpenseAccountMapping>;
138
+ journalId?: string;
139
+ referencePrefix?: string;
140
+ }
141
+ export interface ProjectPosSettlementFinanceInput {
142
+ settlement: {
143
+ id: string;
144
+ date?: string | null;
145
+ amount: number;
146
+ method: string;
147
+ receivableId?: string | null;
148
+ payableId?: string | null;
149
+ };
150
+ tenantId: string;
151
+ branchId?: string;
152
+ scopedAccountMapping: ScopedAccountMapping<PosSettlementAccountMapping>;
153
+ journalId?: string;
154
+ referencePrefix?: string;
155
+ }
156
+ export interface ProjectPosCashAdjustmentFinanceInput {
157
+ adjustment: {
158
+ id: string;
159
+ date?: string | null;
160
+ amount: number;
161
+ direction: 'in' | 'out';
162
+ reason?: string | null;
163
+ };
164
+ tenantId: string;
165
+ branchId?: string;
166
+ scopedAccountMapping: ScopedAccountMapping<PosCashAdjustmentAccountMapping>;
167
+ journalId?: string;
168
+ referencePrefix?: string;
169
+ }
170
+ export interface CreatePosFinanceRuntimeOptions {
171
+ dbAdapter: FinanceDbAdapterLike;
172
+ resolveFinanceServices: () => FinanceProjectionServicesRef | null;
173
+ resolveLedgerProfileId: () => string;
174
+ resolveSyncEnqueuer?: () => FinanceSyncEnqueuer | null;
175
+ requiredAccounts: FinanceAccount[];
176
+ saleAccountMapping: ScopedAccountMapping<PosSaleAccountMapping>;
177
+ purchaseAccountMapping?: ScopedAccountMapping<PosPurchaseAccountMapping>;
178
+ returnAccountMapping?: ScopedAccountMapping<PosReturnAccountMapping>;
179
+ expenseAccountMapping?: ScopedAccountMapping<PosExpenseAccountMapping>;
180
+ settlementAccountMapping?: ScopedAccountMapping<PosSettlementAccountMapping>;
181
+ cashAdjustmentAccountMapping?: ScopedAccountMapping<PosCashAdjustmentAccountMapping>;
182
+ financeDomainId?: string;
183
+ missingServicesErrorCode?: string;
184
+ missingLedgerProfileErrorCode?: string;
185
+ }
37
186
  export declare function projectScopedPosSaleFinance(input: ProjectScopedPosSaleFinanceInput): ScopedPosSaleFinanceProjection;
187
+ export declare function projectPosPurchaseFinance(input: ProjectPosPurchaseFinanceInput): PosPurchaseFinanceProjection;
188
+ export declare function projectPosReturnFinance(input: ProjectPosReturnFinanceInput): PosReturnFinanceProjection;
189
+ export declare function projectPosExpenseFinance(input: ProjectPosExpenseFinanceInput): PosExpenseFinanceProjection;
190
+ export declare function projectPosSettlementFinance(input: ProjectPosSettlementFinanceInput): PosSettlementFinanceProjection;
191
+ export declare function projectPosCashAdjustmentFinance(input: ProjectPosCashAdjustmentFinanceInput): PosCashAdjustmentFinanceProjection;
192
+ export declare function buildJournalDraftFromPosFinanceProjection(projection: ScopedPosFinanceProjection, options: {
193
+ ledgerProfileId: string;
194
+ financeDomainId?: string;
195
+ }): JournalDraftInput;
196
+ export declare function createPosFinanceRuntimeOptions(options: CreatePosFinanceRuntimeOptions): Partial<ServiceRuntimeOptions>;