49 lines
1.4 KiB
Dart
49 lines
1.4 KiB
Dart
import 'receipt_group.dart';
|
|
|
|
/// Satu tugas kirim ke Firefly III: satu struk sebagai satu transaksi split.
|
|
///
|
|
/// [groups] berisi semua grup berisi item; [tipAmount] diisi bila kembalian
|
|
/// dijadikan tip. Seluruh pecahan dikirim dalam satu panggilan API.
|
|
class SubmissionTask {
|
|
final String taskId;
|
|
final List<ReceiptGroup> groups;
|
|
final double? tipAmount;
|
|
final String? tipSourceAccountId;
|
|
final String? tipSourceAccountName;
|
|
final String destinationAccountId;
|
|
final String destinationAccountName;
|
|
final DateTime transactionDate;
|
|
final List<String>? tags;
|
|
final String? customerName;
|
|
final String? invoiceNumber;
|
|
|
|
SubmissionTask({
|
|
required this.taskId,
|
|
required this.groups,
|
|
this.tipAmount,
|
|
this.tipSourceAccountId,
|
|
this.tipSourceAccountName,
|
|
required this.destinationAccountId,
|
|
required this.destinationAccountName,
|
|
required this.transactionDate,
|
|
this.tags,
|
|
this.customerName,
|
|
this.invoiceNumber,
|
|
});
|
|
|
|
bool get hasTip =>
|
|
tipSourceAccountId != null && tipAmount != null && tipAmount! > 0;
|
|
|
|
double get itemsTotal => groups.fold(0.0, (sum, group) => sum + group.total);
|
|
|
|
double get amount => itemsTotal + (hasTip ? tipAmount! : 0.0);
|
|
|
|
int get splitCount => groups.length + (hasTip ? 1 : 0);
|
|
|
|
String get label {
|
|
final name = customerName?.trim() ?? '';
|
|
if (name.isNotEmpty) return name;
|
|
return groups.length > 1 ? 'Struk (${groups.length} grup)' : 'Struk';
|
|
}
|
|
}
|