stateset-embedded 1.23.5

Embeddable commerce library - the SQLite of commerce operations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
//! Warehouse accessors: warehouses/locations, receiving, fulfillment.

use super::*;

/// Async warehouse operations.
pub struct AsyncWarehouse {
    db: Arc<PostgresDatabase>,
}

impl AsyncWarehouse {
    pub(crate) const fn new(db: Arc<PostgresDatabase>) -> Self {
        Self { db }
    }

    pub async fn create_warehouse(&self, input: CreateWarehouse) -> Result<Warehouse> {
        self.db.warehouse().create_warehouse_async(input).await
    }

    pub async fn get_warehouse(&self, id: i32) -> Result<Option<Warehouse>> {
        self.db.warehouse().get_warehouse_async(id).await
    }

    pub async fn get_warehouse_by_code(&self, code: &str) -> Result<Option<Warehouse>> {
        self.db.warehouse().get_warehouse_by_code_async(code).await
    }

    pub async fn update_warehouse(&self, id: i32, input: UpdateWarehouse) -> Result<Warehouse> {
        self.db.warehouse().update_warehouse_async(id, input).await
    }

    pub async fn list_warehouses(&self, filter: WarehouseFilter) -> Result<Vec<Warehouse>> {
        self.db.warehouse().list_warehouses_async(filter).await
    }

    pub async fn delete_warehouse(&self, id: i32) -> Result<()> {
        self.db.warehouse().delete_warehouse_async(id).await
    }

    pub async fn count_warehouses(&self, filter: WarehouseFilter) -> Result<u64> {
        self.db.warehouse().count_warehouses_async(filter).await
    }

    pub async fn create_zone(&self, input: CreateZone) -> Result<Zone> {
        self.db.warehouse().create_zone_async(input).await
    }

    pub async fn get_zone(&self, id: i32) -> Result<Option<Zone>> {
        self.db.warehouse().get_zone_async(id).await
    }

    pub async fn get_zones(&self, warehouse_id: i32) -> Result<Vec<Zone>> {
        self.db.warehouse().get_zones_async(warehouse_id).await
    }

    pub async fn update_zone(&self, id: i32, input: UpdateZone) -> Result<Zone> {
        self.db.warehouse().update_zone_async(id, input).await
    }

    pub async fn delete_zone(&self, id: i32) -> Result<()> {
        self.db.warehouse().delete_zone_async(id).await
    }

    pub async fn create_location(&self, input: CreateLocation) -> Result<Location> {
        self.db.warehouse().create_location_async(input).await
    }

    pub async fn get_location(&self, id: i32) -> Result<Option<Location>> {
        self.db.warehouse().get_location_async(id).await
    }

    pub async fn get_location_by_code(
        &self,
        warehouse_id: i32,
        code: &str,
    ) -> Result<Option<Location>> {
        self.db.warehouse().get_location_by_code_async(warehouse_id, code).await
    }

    pub async fn update_location(&self, id: i32, input: UpdateLocation) -> Result<Location> {
        self.db.warehouse().update_location_async(id, input).await
    }

    pub async fn list_locations(&self, filter: LocationFilter) -> Result<Vec<Location>> {
        self.db.warehouse().list_locations_async(filter).await
    }

    pub async fn delete_location(&self, id: i32) -> Result<()> {
        self.db.warehouse().delete_location_async(id).await
    }

    pub async fn count_locations(&self, filter: LocationFilter) -> Result<u64> {
        self.db.warehouse().count_locations_async(filter).await
    }

    pub async fn get_locations_for_warehouse(&self, warehouse_id: i32) -> Result<Vec<Location>> {
        self.db.warehouse().get_locations_for_warehouse_async(warehouse_id).await
    }

    pub async fn get_pickable_locations(
        &self,
        warehouse_id: i32,
        sku: &str,
    ) -> Result<Vec<Location>> {
        self.db.warehouse().get_pickable_locations_async(warehouse_id, sku).await
    }

    pub async fn get_receivable_locations(&self, warehouse_id: i32) -> Result<Vec<Location>> {
        self.db.warehouse().get_receivable_locations_async(warehouse_id).await
    }

    pub async fn get_location_inventory(&self, location_id: i32) -> Result<Vec<LocationInventory>> {
        self.db.warehouse().get_location_inventory_async(location_id).await
    }

    pub async fn get_inventory_for_sku(
        &self,
        warehouse_id: i32,
        sku: &str,
    ) -> Result<Vec<LocationInventory>> {
        self.db.warehouse().get_inventory_for_sku_async(warehouse_id, sku).await
    }

    pub async fn adjust_inventory(
        &self,
        input: AdjustLocationInventory,
    ) -> Result<LocationInventory> {
        self.db.warehouse().adjust_inventory_async(input).await
    }

    pub async fn move_inventory(&self, input: MoveInventory) -> Result<LocationMovement> {
        self.db.warehouse().move_inventory_async(input).await
    }

    pub async fn list_location_inventory(
        &self,
        filter: LocationInventoryFilter,
    ) -> Result<Vec<LocationInventory>> {
        self.db.warehouse().list_location_inventory_async(filter).await
    }

    pub async fn get_movements(&self, filter: MovementFilter) -> Result<Vec<LocationMovement>> {
        self.db.warehouse().get_movements_async(filter).await
    }

    pub async fn count_movements(&self, filter: MovementFilter) -> Result<u64> {
        self.db.warehouse().count_movements_async(filter).await
    }

    pub async fn create_locations_batch(
        &self,
        inputs: Vec<CreateLocation>,
    ) -> Result<BatchResult<Location>> {
        self.db.warehouse().create_locations_batch_async(inputs).await
    }

    pub async fn get_locations_batch(&self, ids: Vec<i32>) -> Result<Vec<Location>> {
        self.db.warehouse().get_locations_batch_async(ids).await
    }

    /// Create a cycle count (draft) with its expected lines.
    pub async fn create_cycle_count(&self, input: CreateCycleCount) -> Result<CycleCount> {
        self.db.warehouse().create_cycle_count_async(input).await
    }

    /// Get a cycle count (with lines) by ID.
    pub async fn get_cycle_count(&self, id: Uuid) -> Result<Option<CycleCount>> {
        self.db.warehouse().get_cycle_count_async(id).await
    }

    /// List cycle counts matching the filter.
    pub async fn list_cycle_counts(&self, filter: CycleCountFilter) -> Result<Vec<CycleCount>> {
        self.db.warehouse().list_cycle_counts_async(filter).await
    }

    /// Start a draft cycle count (`draft` → `in_progress`).
    pub async fn start_cycle_count(&self, id: Uuid) -> Result<CycleCount> {
        self.db.warehouse().start_cycle_count_async(id).await
    }

    /// Record physical counts against an in-progress cycle count.
    pub async fn record_cycle_counts(
        &self,
        id: Uuid,
        counts: Vec<RecordCycleCountLine>,
    ) -> Result<CycleCount> {
        self.db.warehouse().record_cycle_counts_async(id, counts).await
    }

    /// Complete an in-progress cycle count, applying variance adjustments
    /// to `location_inventory`.
    pub async fn complete_cycle_count(&self, id: Uuid) -> Result<CycleCount> {
        self.db.warehouse().complete_cycle_count_async(id).await
    }

    /// Cancel a draft or in-progress cycle count. No adjustments are applied.
    pub async fn cancel_cycle_count(&self, id: Uuid) -> Result<CycleCount> {
        self.db.warehouse().cancel_cycle_count_async(id).await
    }
}

// ============================================================================
// Async Receiving
// ============================================================================

/// Async receiving operations.
pub struct AsyncReceiving {
    db: Arc<PostgresDatabase>,
}

impl AsyncReceiving {
    pub(crate) const fn new(db: Arc<PostgresDatabase>) -> Self {
        Self { db }
    }

    pub async fn create_receipt(&self, input: CreateReceipt) -> Result<Receipt> {
        self.db.receiving().create_receipt_async(input).await
    }

    pub async fn get_receipt(&self, id: Uuid) -> Result<Option<Receipt>> {
        self.db.receiving().get_receipt_async(id).await
    }

    pub async fn get_receipt_by_number(&self, number: &str) -> Result<Option<Receipt>> {
        self.db.receiving().get_receipt_by_number_async(number).await
    }

    pub async fn update_receipt(&self, id: Uuid, input: UpdateReceipt) -> Result<Receipt> {
        self.db.receiving().update_receipt_async(id, input).await
    }

    pub async fn list_receipts(&self, filter: ReceiptFilter) -> Result<Vec<Receipt>> {
        self.db.receiving().list_receipts_async(filter).await
    }

    pub async fn delete_receipt(&self, id: Uuid) -> Result<()> {
        self.db.receiving().delete_receipt_async(id).await
    }

    pub async fn start_receiving(&self, id: Uuid) -> Result<Receipt> {
        self.db.receiving().start_receiving_async(id).await
    }

    pub async fn receive_items(&self, input: ReceiveItems) -> Result<Receipt> {
        self.db.receiving().receive_items_async(input).await
    }

    pub async fn complete_receiving(&self, id: Uuid) -> Result<Receipt> {
        self.db.receiving().complete_receiving_async(id).await
    }

    pub async fn cancel_receipt(&self, id: Uuid) -> Result<Receipt> {
        self.db.receiving().cancel_receipt_async(id).await
    }

    pub async fn get_receipt_items(&self, receipt_id: Uuid) -> Result<Vec<ReceiptItem>> {
        self.db.receiving().get_receipt_items_async(receipt_id).await
    }

    pub async fn count_receipts(&self, filter: ReceiptFilter) -> Result<u64> {
        self.db.receiving().count_receipts_async(filter).await
    }

    pub async fn create_put_away(&self, input: CreatePutAway) -> Result<PutAway> {
        self.db.receiving().create_put_away_async(input).await
    }

    pub async fn get_put_away(&self, id: Uuid) -> Result<Option<PutAway>> {
        self.db.receiving().get_put_away_async(id).await
    }

    pub async fn list_put_aways(&self, filter: PutAwayFilter) -> Result<Vec<PutAway>> {
        self.db.receiving().list_put_aways_async(filter).await
    }

    pub async fn assign_put_away(&self, id: Uuid, assigned_to: &str) -> Result<PutAway> {
        self.db.receiving().assign_put_away_async(id, assigned_to).await
    }

    pub async fn start_put_away(&self, id: Uuid) -> Result<PutAway> {
        self.db.receiving().start_put_away_async(id).await
    }

    pub async fn complete_put_away(&self, input: CompletePutAway) -> Result<PutAway> {
        self.db.receiving().complete_put_away_async(input).await
    }

    pub async fn cancel_put_away(&self, id: Uuid) -> Result<PutAway> {
        self.db.receiving().cancel_put_away_async(id).await
    }

    pub async fn get_pending_put_aways(&self, receipt_id: Uuid) -> Result<Vec<PutAway>> {
        self.db.receiving().get_pending_put_aways_async(receipt_id).await
    }

    pub async fn count_put_aways(&self, filter: PutAwayFilter) -> Result<u64> {
        self.db.receiving().count_put_aways_async(filter).await
    }

    pub async fn create_receipt_from_po(&self, po_id: Uuid, warehouse_id: i32) -> Result<Receipt> {
        self.db.receiving().create_receipt_from_po_async(po_id, warehouse_id).await
    }

    pub async fn create_receipts_batch(
        &self,
        inputs: Vec<CreateReceipt>,
    ) -> Result<BatchResult<Receipt>> {
        self.db.receiving().create_receipts_batch_async(inputs).await
    }

    pub async fn get_receipts_batch(&self, ids: Vec<Uuid>) -> Result<Vec<Receipt>> {
        self.db.receiving().get_receipts_batch_async(ids).await
    }
}

// ============================================================================
// Async Fulfillment
// ============================================================================

/// Async fulfillment operations.
pub struct AsyncFulfillment {
    db: Arc<PostgresDatabase>,
}

impl AsyncFulfillment {
    pub(crate) const fn new(db: Arc<PostgresDatabase>) -> Self {
        Self { db }
    }

    pub async fn create_wave(&self, input: CreateWave) -> Result<Wave> {
        self.db.fulfillment().create_wave_async(input).await
    }

    pub async fn get_wave(&self, id: Uuid) -> Result<Option<Wave>> {
        self.db.fulfillment().get_wave_async(id).await
    }

    pub async fn get_wave_by_number(&self, number: &str) -> Result<Option<Wave>> {
        self.db.fulfillment().get_wave_by_number_async(number).await
    }

    pub async fn list_waves(&self, filter: WaveFilter) -> Result<Vec<Wave>> {
        self.db.fulfillment().list_waves_async(filter).await
    }

    pub async fn release_wave(&self, id: Uuid) -> Result<Wave> {
        self.db.fulfillment().release_wave_async(id).await
    }

    pub async fn complete_wave(&self, id: Uuid) -> Result<Wave> {
        self.db.fulfillment().complete_wave_async(id).await
    }

    pub async fn cancel_wave(&self, id: Uuid) -> Result<Wave> {
        self.db.fulfillment().cancel_wave_async(id).await
    }

    pub async fn get_wave_orders(&self, wave_id: Uuid) -> Result<Vec<Uuid>> {
        self.db.fulfillment().get_wave_orders_async(wave_id).await
    }

    pub async fn count_waves(&self, filter: WaveFilter) -> Result<u64> {
        self.db.fulfillment().count_waves_async(filter).await
    }

    pub async fn create_pick(&self, input: CreatePickTask) -> Result<PickTask> {
        self.db.fulfillment().create_pick_async(input).await
    }

    pub async fn get_pick(&self, id: Uuid) -> Result<Option<PickTask>> {
        self.db.fulfillment().get_pick_async(id).await
    }

    pub async fn list_picks(&self, filter: PickTaskFilter) -> Result<Vec<PickTask>> {
        self.db.fulfillment().list_picks_async(filter).await
    }

    pub async fn assign_pick(&self, id: Uuid, assigned_to: &str) -> Result<PickTask> {
        self.db.fulfillment().assign_pick_async(id, assigned_to).await
    }

    pub async fn start_pick(&self, id: Uuid) -> Result<PickTask> {
        self.db.fulfillment().start_pick_async(id).await
    }

    pub async fn complete_pick(&self, input: CompletePick) -> Result<PickTask> {
        self.db.fulfillment().complete_pick_async(input).await
    }

    pub async fn report_short(
        &self,
        id: Uuid,
        short_qty: Decimal,
        reason: &str,
    ) -> Result<PickTask> {
        self.db.fulfillment().report_short_async(id, short_qty, reason).await
    }

    pub async fn cancel_pick(&self, id: Uuid) -> Result<PickTask> {
        self.db.fulfillment().cancel_pick_async(id).await
    }

    pub async fn get_picks_for_order(&self, order_id: Uuid) -> Result<Vec<PickTask>> {
        self.db.fulfillment().get_picks_for_order_async(order_id).await
    }

    pub async fn get_picks_for_wave(&self, wave_id: Uuid) -> Result<Vec<PickTask>> {
        self.db.fulfillment().get_picks_for_wave_async(wave_id).await
    }

    pub async fn count_picks(&self, filter: PickTaskFilter) -> Result<u64> {
        self.db.fulfillment().count_picks_async(filter).await
    }

    pub async fn create_pack(&self, input: CreatePackTask) -> Result<PackTask> {
        self.db.fulfillment().create_pack_async(input).await
    }

    pub async fn get_pack(&self, id: Uuid) -> Result<Option<PackTask>> {
        self.db.fulfillment().get_pack_async(id).await
    }

    pub async fn list_packs(&self, filter: PackTaskFilter) -> Result<Vec<PackTask>> {
        self.db.fulfillment().list_packs_async(filter).await
    }

    pub async fn assign_pack(&self, id: Uuid, assigned_to: &str) -> Result<PackTask> {
        self.db.fulfillment().assign_pack_async(id, assigned_to).await
    }

    pub async fn start_pack(&self, id: Uuid) -> Result<PackTask> {
        self.db.fulfillment().start_pack_async(id).await
    }

    pub async fn complete_pack(&self, id: Uuid) -> Result<PackTask> {
        self.db.fulfillment().complete_pack_async(id).await
    }

    pub async fn add_carton(&self, input: AddCarton) -> Result<Carton> {
        self.db.fulfillment().add_carton_async(input).await
    }

    pub async fn add_carton_item(&self, input: AddCartonItem) -> Result<CartonItem> {
        self.db.fulfillment().add_carton_item_async(input).await
    }

    pub async fn get_cartons(&self, pack_task_id: Uuid) -> Result<Vec<Carton>> {
        self.db.fulfillment().get_cartons_async(pack_task_id).await
    }

    pub async fn get_carton_items(&self, carton_id: Uuid) -> Result<Vec<CartonItem>> {
        self.db.fulfillment().get_carton_items_async(carton_id).await
    }

    pub async fn mark_label_printed(&self, carton_id: Uuid) -> Result<Carton> {
        self.db.fulfillment().mark_label_printed_async(carton_id).await
    }

    pub async fn cancel_pack(&self, id: Uuid) -> Result<PackTask> {
        self.db.fulfillment().cancel_pack_async(id).await
    }

    pub async fn count_packs(&self, filter: PackTaskFilter) -> Result<u64> {
        self.db.fulfillment().count_packs_async(filter).await
    }

    pub async fn create_ship(&self, input: CreateShipTask) -> Result<ShipTask> {
        self.db.fulfillment().create_ship_async(input).await
    }

    pub async fn get_ship(&self, id: Uuid) -> Result<Option<ShipTask>> {
        self.db.fulfillment().get_ship_async(id).await
    }

    pub async fn list_ships(&self, filter: ShipTaskFilter) -> Result<Vec<ShipTask>> {
        self.db.fulfillment().list_ships_async(filter).await
    }

    pub async fn assign_ship(&self, id: Uuid, assigned_to: &str) -> Result<ShipTask> {
        self.db.fulfillment().assign_ship_async(id, assigned_to).await
    }

    pub async fn print_label(&self, id: Uuid, label_url: &str) -> Result<ShipTask> {
        self.db.fulfillment().print_label_async(id, label_url).await
    }

    pub async fn complete_ship(&self, input: CompleteShip) -> Result<ShipTask> {
        self.db.fulfillment().complete_ship_async(input).await
    }

    pub async fn cancel_ship(&self, id: Uuid) -> Result<ShipTask> {
        self.db.fulfillment().cancel_ship_async(id).await
    }

    pub async fn count_ships(&self, filter: ShipTaskFilter) -> Result<u64> {
        self.db.fulfillment().count_ships_async(filter).await
    }

    pub async fn create_picks_for_order(
        &self,
        order_id: Uuid,
        warehouse_id: i32,
    ) -> Result<Vec<PickTask>> {
        self.db.fulfillment().create_picks_for_order_async(order_id, warehouse_id).await
    }

    pub async fn is_order_ready_to_pack(&self, order_id: Uuid) -> Result<bool> {
        self.db.fulfillment().is_order_ready_to_pack_async(order_id).await
    }

    pub async fn is_order_ready_to_ship(&self, order_id: Uuid) -> Result<bool> {
        self.db.fulfillment().is_order_ready_to_ship_async(order_id).await
    }

    pub async fn create_waves_batch(&self, inputs: Vec<CreateWave>) -> Result<BatchResult<Wave>> {
        self.db.fulfillment().create_waves_batch_async(inputs).await
    }

    pub async fn get_picks_batch(&self, ids: Vec<Uuid>) -> Result<Vec<PickTask>> {
        self.db.fulfillment().get_picks_batch_async(ids).await
    }
}

// ============================================================================
// Async Accounts Payable
// ============================================================================