feat: add more detailed history and group per day

This commit is contained in:
2026-08-07 05:07:41 +02:00
parent 1dd7e69aa8
commit 799c1c4045
23 changed files with 2506 additions and 346 deletions
+63 -30
View File
@@ -49,19 +49,27 @@ class DefaultExportService implements ExportService {
final itemRows = await itemsQuery.get();
result.add(_ClosedTabExport(
id: tabRow.id,
originalTabId: tabRow.originalTabId,
customerName: tabRow.customerName,
closedAt: tabRow.closedAt.toIso8601String(),
paymentMethod: tabRow.paymentMethod,
items: itemRows.map((row) => _ClosedTabItemExport(
productId: row.productId,
productName: row.productName,
quantity: row.quantity,
unitPriceInCents: row.unitPriceInCents,
)).toList(),
));
result.add(
_ClosedTabExport(
id: tabRow.id,
originalTabId: tabRow.originalTabId,
customerName: tabRow.customerName,
closedAt: tabRow.closedAt.toIso8601String(),
paymentMethod: tabRow.paymentMethod,
items: itemRows
.map(
(row) => _ClosedTabItemExport(
productId: row.productId,
productName: row.productName,
quantity: row.quantity,
unitPriceInCents: row.unitPriceInCents,
purchasedAt: row.purchasedAt?.toIso8601String(),
removedAt: row.removedAt?.toIso8601String(),
),
)
.toList(),
),
);
}
return result;
@@ -71,22 +79,39 @@ class DefaultExportService implements ExportService {
return {
'exportedAt': DateTime.now().toIso8601String(),
'appVersion': '1.0.7',
'closedTabs': tabs.map((tab) => {
'id': tab.id,
'originalTabId': tab.originalTabId,
'customerName': tab.customerName,
'closedAt': tab.closedAt,
'paymentMethod': tab.paymentMethod,
'items': tab.items.map((item) => {
'productId': item.productId,
'productName': item.productName,
'quantity': item.quantity,
'unitPriceInCents': item.unitPriceInCents,
'lineTotalInCents': item.quantity * item.unitPriceInCents,
}).toList(),
'itemCount': tab.items.fold(0, (sum, item) => sum + item.quantity),
'totalInCents': tab.items.fold(0, (sum, item) => sum + item.quantity * item.unitPriceInCents),
}).toList(),
'closedTabs': tabs
.map(
(tab) => {
'id': tab.id,
'originalTabId': tab.originalTabId,
'customerName': tab.customerName,
'closedAt': tab.closedAt,
'paymentMethod': tab.paymentMethod,
'items': tab.items
.map(
(item) => {
'productId': item.productId,
'productName': item.productName,
'quantity': item.quantity,
'unitPriceInCents': item.unitPriceInCents,
'purchasedAt': item.purchasedAt,
'removedAt': item.removedAt,
'isRemoved': item.isRemoved,
'lineTotalInCents': item.lineTotalInCents,
},
)
.toList(),
'itemCount': tab.items.fold(
0,
(sum, item) => sum + (item.isRemoved ? 0 : item.quantity),
),
'totalInCents': tab.items.fold(
0,
(sum, item) => sum + item.lineTotalInCents,
),
},
)
.toList(),
};
}
}
@@ -96,13 +121,21 @@ class _ClosedTabItemExport {
final String productName;
final int quantity;
final int unitPriceInCents;
final String? purchasedAt;
final String? removedAt;
_ClosedTabItemExport({
required this.productId,
required this.productName,
required this.quantity,
required this.unitPriceInCents,
required this.purchasedAt,
required this.removedAt,
});
bool get isRemoved => removedAt != null;
int get lineTotalInCents => isRemoved ? 0 : quantity * unitPriceInCents;
}
class _ClosedTabExport {
@@ -121,4 +154,4 @@ class _ClosedTabExport {
required this.paymentMethod,
required this.items,
});
}
}