pos changes
This commit is contained in:
@@ -303,20 +303,27 @@ class OrderDao {
|
||||
return rows.isEmpty ? null : rows.first;
|
||||
}
|
||||
|
||||
Future<List<Map<String, Object?>>> syncRows({int limit = 200}) => _db.query(
|
||||
Tables.orders,
|
||||
columns: [
|
||||
'id',
|
||||
'invoice_number',
|
||||
'total',
|
||||
'created_at',
|
||||
'sync_status',
|
||||
'synced_at',
|
||||
'sync_attempts',
|
||||
'sync_error',
|
||||
],
|
||||
orderBy: 'created_at DESC',
|
||||
limit: limit,
|
||||
/// Rows for the sync log, with each bill's unit count folded in.
|
||||
///
|
||||
/// The count comes from a correlated sum over [Tables.orderItems] rather
|
||||
/// than a column on the order: quantity can be fractional (loose weight), so
|
||||
/// there is no line count that answers "how many units were on this bill".
|
||||
/// A single aggregate keeps this to one query rather than one per row.
|
||||
Future<List<Map<String, Object?>>> syncRows({int limit = 200}) =>
|
||||
_db.rawQuery(
|
||||
'''
|
||||
SELECT o.id, o.invoice_number, o.total, o.created_at, o.sync_status,
|
||||
o.synced_at, o.sync_attempts, o.sync_error,
|
||||
COALESCE(
|
||||
(SELECT SUM(i.quantity) FROM ${Tables.orderItems} i
|
||||
WHERE i.order_id = o.id),
|
||||
0
|
||||
) AS item_count
|
||||
FROM ${Tables.orders} o
|
||||
ORDER BY o.created_at DESC
|
||||
LIMIT ?
|
||||
''',
|
||||
[limit],
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------- Sync
|
||||
|
||||
Reference in New Issue
Block a user