Files
kooltab/lib/models/closed_tab.dart
T
2026-07-29 21:25:56 +02:00

68 lines
1.7 KiB
Dart

import 'package:intl/intl.dart';
import 'closed_tab_item.dart';
class ClosedTab {
final String id;
final String originalTabId;
final String customerName;
final DateTime closedAt;
final String paymentMethod;
final List<ClosedTabItem> items;
ClosedTab({
required this.id,
required this.originalTabId,
required this.customerName,
required this.closedAt,
required this.paymentMethod,
required this.items,
});
int get itemCount => items.fold(0, (sum, item) => sum + item.quantity);
int get totalInCents =>
items.fold(0, (sum, item) => sum + item.quantity * item.unitPriceInCents);
String get formattedTotal =>
NumberFormat.simpleCurrency().format(totalInCents / 100);
String get formattedPaymentMethod {
return switch (paymentMethod) {
'cash' => 'Cash',
'payconiq' => 'Payconiq',
_ => 'Cash',
};
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ClosedTab &&
id == other.id &&
originalTabId == other.originalTabId &&
customerName == other.customerName &&
closedAt == other.closedAt &&
paymentMethod == other.paymentMethod &&
_listEquals(items, other.items);
@override
int get hashCode => Object.hash(
id,
originalTabId,
customerName,
closedAt,
paymentMethod,
Object.hashAll(items),
);
}
bool _listEquals<T>(List<T>? a, List<T>? b) {
if (identical(a, b)) return true;
if (a == null || b == null) return a == b;
if (a.length != b.length) return false;
for (int i = 0; i < a.length; i++) {
if (a[i] != b[i]) return false;
}
return true;
}