Files
kooltab/lib/models/closed_tab.dart
T

56 lines
1.4 KiB
Dart

import 'package:intl/intl.dart';
import 'closed_tab_item.dart';
import 'payment_method.dart';
import '../utils/collection_utils.dart';
class ClosedTab {
final String id;
final String originalTabId;
final String customerName;
final DateTime closedAt;
final PaymentMethod paymentMethod;
final List<ClosedTabItem> items;
const 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.isRemoved ? 0 : item.quantity));
int get totalInCents =>
items.fold(0, (sum, item) => sum + item.lineTotalInCents);
String get formattedTotal =>
NumberFormat.simpleCurrency().format(totalInCents / 100);
String get formattedPaymentMethod => paymentMethod.label;
@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),
);
}