84 lines
2.8 KiB
Dart
84 lines
2.8 KiB
Dart
|
|
// lib/models/saved_report.dart
|
||
|
|
|
||
|
|
import 'package:cashumit/models/report_transaction.dart';
|
||
|
|
import 'package:cashumit/models/report_signature_config.dart';
|
||
|
|
|
||
|
|
class SavedReport {
|
||
|
|
final String id;
|
||
|
|
String title;
|
||
|
|
final String accountId;
|
||
|
|
final String accountName;
|
||
|
|
final DateTime startDate;
|
||
|
|
final DateTime endDate;
|
||
|
|
final DateTime createdAt;
|
||
|
|
DateTime updatedAt;
|
||
|
|
List<ReportTransaction> transactions;
|
||
|
|
ReportSignatureConfig? signatureConfig;
|
||
|
|
|
||
|
|
SavedReport({
|
||
|
|
required this.id,
|
||
|
|
required this.title,
|
||
|
|
required this.accountId,
|
||
|
|
required this.accountName,
|
||
|
|
required this.startDate,
|
||
|
|
required this.endDate,
|
||
|
|
required this.createdAt,
|
||
|
|
required this.updatedAt,
|
||
|
|
required this.transactions,
|
||
|
|
this.signatureConfig,
|
||
|
|
});
|
||
|
|
|
||
|
|
double get totalPemasukan => transactions
|
||
|
|
.where((t) => t.isPemasukan)
|
||
|
|
.fold(0.0, (sum, t) => sum + t.amount);
|
||
|
|
|
||
|
|
double get totalPengeluaran => transactions
|
||
|
|
.where((t) => t.isPengeluaran)
|
||
|
|
.fold(0.0, (sum, t) => sum + t.amount);
|
||
|
|
|
||
|
|
double get saldoBersih => totalPemasukan - totalPengeluaran;
|
||
|
|
|
||
|
|
int get completedAttachmentCount =>
|
||
|
|
transactions.where((t) => t.isPengeluaran && t.isComplete).length;
|
||
|
|
|
||
|
|
int get totalPengeluaranCount =>
|
||
|
|
transactions.where((t) => t.isPengeluaran).length;
|
||
|
|
|
||
|
|
int get incompleteAttachmentCount =>
|
||
|
|
transactions.where((t) => t.isPengeluaran && !t.isComplete).length;
|
||
|
|
|
||
|
|
factory SavedReport.fromJson(Map<String, dynamic> json) {
|
||
|
|
return SavedReport(
|
||
|
|
id: json['id']?.toString() ?? '',
|
||
|
|
title: json['title']?.toString() ?? 'Laporan Keuangan',
|
||
|
|
accountId: json['accountId']?.toString() ?? '',
|
||
|
|
accountName: json['accountName']?.toString() ?? '-',
|
||
|
|
startDate: DateTime.tryParse(json['startDate']?.toString() ?? '') ?? DateTime.now(),
|
||
|
|
endDate: DateTime.tryParse(json['endDate']?.toString() ?? '') ?? DateTime.now(),
|
||
|
|
createdAt: DateTime.tryParse(json['createdAt']?.toString() ?? '') ?? DateTime.now(),
|
||
|
|
updatedAt: DateTime.tryParse(json['updatedAt']?.toString() ?? '') ?? DateTime.now(),
|
||
|
|
transactions: (json['transactions'] as List<dynamic>? ?? [])
|
||
|
|
.map((item) => ReportTransaction.fromJson(item as Map<String, dynamic>))
|
||
|
|
.toList(),
|
||
|
|
signatureConfig: json['signatureConfig'] != null
|
||
|
|
? ReportSignatureConfig.fromJson(json['signatureConfig'] as Map<String, dynamic>)
|
||
|
|
: null,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, dynamic> toJson() {
|
||
|
|
return {
|
||
|
|
'id': id,
|
||
|
|
'title': title,
|
||
|
|
'accountId': accountId,
|
||
|
|
'accountName': accountName,
|
||
|
|
'startDate': startDate.toIso8601String(),
|
||
|
|
'endDate': endDate.toIso8601String(),
|
||
|
|
'createdAt': createdAt.toIso8601String(),
|
||
|
|
'updatedAt': updatedAt.toIso8601String(),
|
||
|
|
'transactions': transactions.map((t) => t.toJson()).toList(),
|
||
|
|
'signatureConfig': signatureConfig?.toJson(),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|