Files
kooltab/lib/models/bar_tab.dart
T

65 lines
1.5 KiB
Dart

import 'tab_item.dart';
class BarTab {
final String id;
final String customerName;
final String status;
final DateTime openedAt;
final DateTime? closedAt;
final List<TabItem> items;
const BarTab({
required this.id,
required this.customerName,
required this.status,
required this.openedAt,
required this.items,
this.closedAt,
});
int get totalInCents {
return items.fold<int>(0, (total, item) => total + item.lineTotalInCents);
}
int get itemCount {
return items.fold<int>(0, (total, item) => total + item.quantity);
}
String get formattedTotal {
return '€${(totalInCents / 100).toStringAsFixed(2)}';
}
bool get isOpen => status == 'open';
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is BarTab &&
id == other.id &&
customerName == other.customerName &&
status == other.status &&
openedAt == other.openedAt &&
closedAt == other.closedAt &&
_listEquals(items, other.items);
@override
int get hashCode => Object.hash(
id,
customerName,
status,
openedAt,
closedAt,
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;
}