added product import and billing integration
This commit is contained in:
@@ -85,6 +85,46 @@ class OrderDao {
|
||||
});
|
||||
}
|
||||
|
||||
/// Reverses [commitSale]: deletes the order and its lines, adds the stock
|
||||
/// back, and restores an attached customer's row exactly as passed in
|
||||
/// (the caller supplies the pre-sale row — reconstructing it from deltas
|
||||
/// here would get `last_visit_at` wrong).
|
||||
Future<void> voidSale({
|
||||
required String orderId,
|
||||
required Map<String, double> stockMovements,
|
||||
Map<String, Object?>? customerRow,
|
||||
}) async {
|
||||
await _db.transaction((txn) async {
|
||||
await txn
|
||||
.delete(Tables.orderItems, where: 'order_id = ?', whereArgs: [orderId]);
|
||||
await txn.delete(Tables.orders, where: 'id = ?', whereArgs: [orderId]);
|
||||
|
||||
final batch = txn.batch();
|
||||
final now = DateTime.now().millisecondsSinceEpoch;
|
||||
stockMovements.forEach((id, qty) {
|
||||
batch.rawUpdate(
|
||||
'UPDATE ${Tables.products} SET stock = stock + ?, updated_at = ? '
|
||||
'WHERE id = ?',
|
||||
[qty, now, id],
|
||||
);
|
||||
});
|
||||
if (customerRow != null) {
|
||||
batch.update(
|
||||
Tables.customers,
|
||||
{
|
||||
'loyalty_points': customerRow['loyalty_points'],
|
||||
'lifetime_spend': customerRow['lifetime_spend'],
|
||||
'visit_count': customerRow['visit_count'],
|
||||
'last_visit_at': customerRow['last_visit_at'],
|
||||
},
|
||||
where: 'id = ?',
|
||||
whereArgs: [customerRow['id']],
|
||||
);
|
||||
}
|
||||
await batch.commit(noResult: true);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _insertOrder(DatabaseExecutor txn, SaleTransaction t) async {
|
||||
final cart = t.cart;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user