@tallyui/pos 0.1.0 → 3.0.0-next.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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +2031 -43
- package/dist/index.js +4629 -205
- package/package.json +23 -12
- package/src/currency/currency-provider.tsx +12 -4
- package/src/currency/index.ts +1 -2
- package/src/index.ts +53 -4
- package/src/order/allocate-order-discount.ts +34 -0
- package/src/order/index.ts +8 -0
- package/src/order/order-builder.ts +256 -95
- package/src/order/order-manager.ts +26 -43
- package/src/order/tax-figures.ts +23 -0
- package/src/order/types.ts +73 -15
- package/src/outbox/backend-not-found.ts +27 -0
- package/src/outbox/http-transport.ts +67 -0
- package/src/outbox/index.ts +9 -0
- package/src/outbox/logger.ts +3 -0
- package/src/outbox/order-outbox.ts +502 -0
- package/src/outbox/register-outbox.ts +250 -0
- package/src/outbox/types.test-d.ts +22 -0
- package/src/outbox/types.ts +36 -0
- package/src/outbox/use-order-outbox.ts +175 -0
- package/src/pos-order/__fixtures__/order-create-v3.json +97 -0
- package/src/pos-order/command.ts +123 -0
- package/src/pos-order/device-id.ts +23 -0
- package/src/pos-order/finalize.ts +219 -0
- package/src/pos-order/index.ts +10 -0
- package/src/pos-order/needs-attention.ts +16 -0
- package/src/pos-order/open.ts +269 -0
- package/src/pos-order/same-sale.ts +26 -0
- package/src/pos-order/schema.ts +130 -0
- package/src/pos-order/types.ts +93 -0
- package/src/pos-order/uuidv7.ts +54 -0
- package/src/product/index.ts +2 -0
- package/src/product/search-products.ts +32 -0
- package/src/product/stock.ts +25 -0
- package/src/receipt/build-receipt-data.ts +39 -23
- package/src/receipt/types.ts +17 -10
- package/src/register/__fixtures__/closure-local-row.json +61 -0
- package/src/register/__fixtures__/closure.json +197 -0
- package/src/register/__fixtures__/corrections-dst.json +63 -0
- package/src/register/closure-document.ts +277 -0
- package/src/register/closure-rows.ts +65 -0
- package/src/register/document-labels.ts +46 -0
- package/src/register/expected.ts +66 -0
- package/src/register/export-csv.ts +74 -0
- package/src/register/facts.ts +109 -0
- package/src/register/index.ts +32 -0
- package/src/register/money.ts +18 -0
- package/src/register/movement-input.ts +59 -0
- package/src/register/register-commands.ts +147 -0
- package/src/register/register-count.denominations.ts +11 -0
- package/src/register/register-count.helpers.ts +64 -0
- package/src/register/register-document.ts +268 -0
- package/src/register/schemas.ts +175 -0
- package/src/register/session-store.ts +570 -0
- package/src/register/settled-figures.ts +98 -0
- package/src/register/use-register-session.ts +469 -0
- package/src/rxdb/index.ts +2 -0
- package/src/sale/cart.ts +23 -0
- package/src/sale/catalogue.ts +21 -0
- package/src/sale/index.ts +5 -0
- package/src/sale/use-sale.ts +394 -0
- package/src/store-settings/index.ts +5 -0
- package/src/store-settings/map-store-settings.ts +18 -0
- package/src/store-settings/resolve-store-settings.ts +65 -0
- package/src/store-settings/use-store-settings.ts +84 -0
- package/src/tax/exact.ts +218 -0
- package/src/tax/index.ts +4 -3
- package/src/tax/tax-provider.tsx +35 -12
- package/src/tax/types.ts +8 -6
- package/src/tender/index.ts +2 -0
- package/src/tender/tender-state.ts +326 -0
- package/src/currency/currency-provider.test.tsx +0 -36
- package/src/currency/format-currency.test.ts +0 -36
- package/src/currency/format-currency.ts +0 -18
- package/src/logging/logger.test.ts +0 -154
- package/src/logging/sinks.test.ts +0 -60
- package/src/order/discount-engine.test.ts +0 -152
- package/src/order/order-builder.test.ts +0 -246
- package/src/order/order-manager.test.ts +0 -209
- package/src/order/payment.test.ts +0 -91
- package/src/receipt/build-receipt-data.test.ts +0 -166
- package/src/repository/create-repository.test.ts +0 -166
- package/src/tax/calculate.test.ts +0 -59
- package/src/tax/calculate.ts +0 -32
- package/src/tax/tax-provider.test.tsx +0 -51
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The register's local collections (ADR-032): sessions, cash movements and closures. Port
|
|
3
|
+
* provenance (ADR-032 amendment 1): WCPOS `next` `3b5331b5c`, where they are at versions 1, 0
|
|
4
|
+
* and 1; each starts at version 0 here.
|
|
5
|
+
*
|
|
6
|
+
* All three are local only, like `pos_orders`: the app creates them and never replicates them
|
|
7
|
+
* (a replicated collection must never take local writes, #53). WCPOS's outbox fields
|
|
8
|
+
* (`sync_status`, attempts, next time, error) and closures' server and receipt fields are gone;
|
|
9
|
+
* sending sessions to a server is registers job c.
|
|
10
|
+
*
|
|
11
|
+
* Money is integer minor units: WCPOS's decimal strings become `*_minor` integers (`amountMinor`
|
|
12
|
+
* on a movement, matching `Movement`), and a tender map (`counted`, `expected`, `variance`, keyed
|
|
13
|
+
* by method) holds integers. People (`opened_by`, `created_by`, ...) are the backend's user id
|
|
14
|
+
* as a string, since not every backend's is a number.
|
|
15
|
+
*/
|
|
16
|
+
import { addRxPlugin, type JsonSchema, type RxJsonSchema } from 'rxdb';
|
|
17
|
+
import { RxDBLocalDocumentsPlugin } from 'rxdb/plugins/local-documents';
|
|
18
|
+
|
|
19
|
+
type TenderMap = Record<string, number>;
|
|
20
|
+
|
|
21
|
+
export interface RegisterSession {
|
|
22
|
+
id: string;
|
|
23
|
+
register_id: string;
|
|
24
|
+
/** The app's neutral store key (see `bindRegister`). */
|
|
25
|
+
store_key?: string | null;
|
|
26
|
+
status: 'open' | 'counting' | 'closed';
|
|
27
|
+
/** The store's day the session opened, `yyyy-MM-dd`. */
|
|
28
|
+
business_day?: string;
|
|
29
|
+
opened_at_gmt: string;
|
|
30
|
+
opened_by?: string | null;
|
|
31
|
+
expected_float_minor?: number | null;
|
|
32
|
+
counted_float_minor: number;
|
|
33
|
+
opening_variance_minor?: number | null;
|
|
34
|
+
counting_started_at_gmt?: string | null;
|
|
35
|
+
closed_at_gmt?: string | null;
|
|
36
|
+
closed_by?: string | null;
|
|
37
|
+
approval_required?: boolean;
|
|
38
|
+
approved_by?: string | null;
|
|
39
|
+
counted?: TenderMap | null;
|
|
40
|
+
closure_id?: string | null;
|
|
41
|
+
/** The last local transition, kept for a server to acknowledge (job c). */
|
|
42
|
+
pending_status?: string | null;
|
|
43
|
+
server_status?: string | null;
|
|
44
|
+
status_at?: string | null;
|
|
45
|
+
approver_token?: string | null;
|
|
46
|
+
/** A server's expected figures; cleared before every money action (`requireOpenSession`). */
|
|
47
|
+
server_expected?: TenderMap | null;
|
|
48
|
+
server_sales_count?: number | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface CashMovement {
|
|
52
|
+
id: string;
|
|
53
|
+
session_id: string;
|
|
54
|
+
type: 'paid_in' | 'paid_out' | 'no_sale' | 'void';
|
|
55
|
+
amountMinor: number;
|
|
56
|
+
reason: string;
|
|
57
|
+
created_at_gmt: string;
|
|
58
|
+
created_by?: string | null;
|
|
59
|
+
/** On a `void` row: the movement it reverses. */
|
|
60
|
+
voids?: string | null;
|
|
61
|
+
/** On a reversed movement: its `void` row. */
|
|
62
|
+
voided_by?: string | null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface Closure {
|
|
66
|
+
id: string;
|
|
67
|
+
session_id: string;
|
|
68
|
+
register_id: string;
|
|
69
|
+
store_key?: string | null;
|
|
70
|
+
business_day?: string;
|
|
71
|
+
closed_by?: string | null;
|
|
72
|
+
corrections_count?: number;
|
|
73
|
+
number: number;
|
|
74
|
+
opened_at: string;
|
|
75
|
+
closed_at: string;
|
|
76
|
+
till_expected: TenderMap;
|
|
77
|
+
expected: TenderMap;
|
|
78
|
+
counted: TenderMap;
|
|
79
|
+
variance: TenderMap;
|
|
80
|
+
period_sales_total_minor: number;
|
|
81
|
+
/** Always 0 until TallyUI has a refund model (ADR-032 amendment 1). */
|
|
82
|
+
period_refunds_total_minor: number;
|
|
83
|
+
perpetual_sales_total_minor: number;
|
|
84
|
+
perpetual_refunds_total_minor: number;
|
|
85
|
+
/** This session's orders still waiting for the outbox, and their payments' total. */
|
|
86
|
+
unsynced_count: number;
|
|
87
|
+
unsynced_total_minor: number;
|
|
88
|
+
software_version: string;
|
|
89
|
+
breakdowns: Record<string, unknown>;
|
|
90
|
+
order_ids: string[];
|
|
91
|
+
movement_ids: string[];
|
|
92
|
+
server_closure_id?: string | null;
|
|
93
|
+
printed_at?: string | null;
|
|
94
|
+
print_count: number;
|
|
95
|
+
number_retried?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const id: JsonSchema = { type: 'string', maxLength: 36 };
|
|
99
|
+
const text: JsonSchema = { type: 'string' };
|
|
100
|
+
const nullableText: JsonSchema = { type: ['string', 'null'] };
|
|
101
|
+
const minor: JsonSchema = { type: 'integer' };
|
|
102
|
+
const nullableMinor: JsonSchema = { type: ['integer', 'null'] };
|
|
103
|
+
const tenders: JsonSchema = { type: 'object', additionalProperties: minor };
|
|
104
|
+
|
|
105
|
+
export const registerSessionSchema: RxJsonSchema<RegisterSession> = {
|
|
106
|
+
title: 'Register sessions', version: 0, primaryKey: 'id', type: 'object', additionalProperties: false,
|
|
107
|
+
properties: {
|
|
108
|
+
id, register_id: id, store_key: nullableText,
|
|
109
|
+
status: { type: 'string', enum: ['open', 'counting', 'closed'], maxLength: 8 },
|
|
110
|
+
business_day: { type: 'string', maxLength: 10 },
|
|
111
|
+
opened_at_gmt: text, opened_by: nullableText,
|
|
112
|
+
expected_float_minor: nullableMinor, counted_float_minor: minor, opening_variance_minor: nullableMinor,
|
|
113
|
+
counting_started_at_gmt: nullableText, closed_at_gmt: nullableText, closed_by: nullableText,
|
|
114
|
+
approval_required: { type: 'boolean', default: false }, approved_by: nullableText,
|
|
115
|
+
counted: { type: ['object', 'null'], additionalProperties: minor },
|
|
116
|
+
closure_id: nullableText,
|
|
117
|
+
pending_status: { ...nullableText, default: null },
|
|
118
|
+
server_status: { ...nullableText, default: null },
|
|
119
|
+
status_at: { ...nullableText, default: null },
|
|
120
|
+
approver_token: { ...nullableText, default: null },
|
|
121
|
+
server_expected: { type: ['object', 'null'], additionalProperties: minor, default: null },
|
|
122
|
+
server_sales_count: { type: ['integer', 'null'], default: null },
|
|
123
|
+
},
|
|
124
|
+
required: ['id', 'register_id', 'status', 'opened_at_gmt', 'counted_float_minor'],
|
|
125
|
+
indexes: [['register_id', 'status']],
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Create `register_sessions` with this: the register document (`register-document.ts`) is a
|
|
130
|
+
* local document on this collection, since a Tally database has no database-level ones.
|
|
131
|
+
*/
|
|
132
|
+
export function registerSessionCollection() {
|
|
133
|
+
// addRxPlugin ignores a plugin it already has.
|
|
134
|
+
addRxPlugin(RxDBLocalDocumentsPlugin);
|
|
135
|
+
return { schema: registerSessionSchema, localDocuments: true } as const;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export const cashMovementSchema: RxJsonSchema<CashMovement> = {
|
|
139
|
+
title: 'Cash movements', version: 0, primaryKey: 'id', type: 'object', additionalProperties: false,
|
|
140
|
+
properties: {
|
|
141
|
+
id, session_id: id,
|
|
142
|
+
type: { type: 'string', enum: ['paid_in', 'paid_out', 'no_sale', 'void'] },
|
|
143
|
+
amountMinor: minor, reason: text, created_at_gmt: text, created_by: nullableText,
|
|
144
|
+
voids: nullableText, voided_by: nullableText,
|
|
145
|
+
},
|
|
146
|
+
required: ['id', 'session_id', 'type', 'amountMinor', 'reason', 'created_at_gmt'],
|
|
147
|
+
indexes: [['session_id']],
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const closureSchema: RxJsonSchema<Closure> = {
|
|
151
|
+
title: 'Register closures', version: 0, primaryKey: 'id', type: 'object', additionalProperties: false,
|
|
152
|
+
properties: {
|
|
153
|
+
id, session_id: id, register_id: id, store_key: nullableText,
|
|
154
|
+
business_day: { type: 'string', maxLength: 10 },
|
|
155
|
+
closed_by: nullableText, corrections_count: { type: 'integer' },
|
|
156
|
+
number: { type: 'integer' }, opened_at: text, closed_at: text,
|
|
157
|
+
till_expected: tenders, expected: tenders, counted: tenders, variance: tenders,
|
|
158
|
+
period_sales_total_minor: minor, period_refunds_total_minor: minor,
|
|
159
|
+
perpetual_sales_total_minor: minor, perpetual_refunds_total_minor: minor,
|
|
160
|
+
unsynced_count: { type: 'integer' }, unsynced_total_minor: minor,
|
|
161
|
+
software_version: text,
|
|
162
|
+
breakdowns: { type: 'object', additionalProperties: true },
|
|
163
|
+
order_ids: { type: 'array', items: text },
|
|
164
|
+
movement_ids: { type: 'array', items: text },
|
|
165
|
+
server_closure_id: { ...nullableText, default: null },
|
|
166
|
+
printed_at: { ...nullableText, default: null },
|
|
167
|
+
print_count: { type: 'integer', default: 0 },
|
|
168
|
+
number_retried: { type: 'boolean', default: false },
|
|
169
|
+
},
|
|
170
|
+
required: ['id', 'session_id', 'register_id', 'number', 'opened_at', 'closed_at', 'till_expected', 'expected',
|
|
171
|
+
'counted', 'variance', 'period_sales_total_minor', 'period_refunds_total_minor', 'perpetual_sales_total_minor',
|
|
172
|
+
'perpetual_refunds_total_minor', 'unsynced_count', 'unsynced_total_minor', 'software_version', 'breakdowns',
|
|
173
|
+
'order_ids', 'movement_ids', 'print_count'],
|
|
174
|
+
indexes: [['register_id'], ['session_id']],
|
|
175
|
+
};
|