feat: transaction report
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
|
||||
import '../../../application/report/inventory_report/inventory_report_bloc.dart';
|
||||
import '../../../application/report/transaction_report/transaction_report_bloc.dart';
|
||||
import '../../../common/extension/extension.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../common/utils/pdf_service.dart';
|
||||
@@ -14,6 +15,7 @@ import '../../../injection.dart';
|
||||
import '../../components/appbar/appbar.dart';
|
||||
import '../../components/field/date_range_picker_field.dart';
|
||||
import '../../components/report/inventory_report.dart';
|
||||
import '../../components/report/transaction_report.dart';
|
||||
import '../../components/toast/flushbar.dart';
|
||||
|
||||
@RoutePage()
|
||||
@@ -24,9 +26,19 @@ class DownloadReportPage extends StatefulWidget implements AutoRouteWrapper {
|
||||
State<DownloadReportPage> createState() => _DownloadReportPageState();
|
||||
|
||||
@override
|
||||
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
||||
create: (context) =>
|
||||
getIt<InventoryReportBloc>()..add(InventoryReportEvent.fetchedOutlet()),
|
||||
Widget wrappedRoute(BuildContext context) => MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) =>
|
||||
getIt<InventoryReportBloc>()
|
||||
..add(InventoryReportEvent.fetchedOutlet()),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) =>
|
||||
getIt<TransactionReportBloc>()
|
||||
..add(TransactionReportEvent.fetchedOutlet()),
|
||||
),
|
||||
],
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
@@ -88,17 +100,6 @@ class _DownloadReportPageState extends State<DownloadReportPage>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _downloadReport(
|
||||
String reportType,
|
||||
DateTime? startDate,
|
||||
DateTime? endDate,
|
||||
) {
|
||||
if (startDate == null || endDate == null) {
|
||||
AppFlushbar.showError(context, 'Please select both start and end dates');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -127,30 +128,75 @@ class _DownloadReportPageState extends State<DownloadReportPage>
|
||||
child: Column(
|
||||
children: [
|
||||
// Transaction Report Card
|
||||
_ReportOptionCard(
|
||||
title: 'Transaction Report',
|
||||
subtitle:
|
||||
'Export all transaction data with detailed analytics',
|
||||
icon: Icons.receipt_long_outlined,
|
||||
gradient: const [
|
||||
AppColor.primary,
|
||||
AppColor.primaryLight,
|
||||
],
|
||||
startDate: _transactionStartDate,
|
||||
endDate: _transactionEndDate,
|
||||
isLoading: false,
|
||||
onDateRangeChanged: (start, end) {
|
||||
setState(() {
|
||||
_transactionStartDate = start;
|
||||
_transactionEndDate = end;
|
||||
});
|
||||
BlocBuilder<
|
||||
TransactionReportBloc,
|
||||
TransactionReportState
|
||||
>(
|
||||
builder: (context, state) {
|
||||
return _ReportOptionCard(
|
||||
title: 'Transaction Report',
|
||||
subtitle:
|
||||
'Export all transaction data with detailed analytics',
|
||||
icon: Icons.receipt_long_outlined,
|
||||
gradient: const [
|
||||
AppColor.primary,
|
||||
AppColor.primaryLight,
|
||||
],
|
||||
startDate: _transactionStartDate,
|
||||
endDate: _transactionEndDate,
|
||||
isLoading: state.isFetching,
|
||||
onDateRangeChanged: (start, end) {
|
||||
setState(() {
|
||||
_transactionStartDate = start;
|
||||
_transactionEndDate = end;
|
||||
});
|
||||
if (start != null || end != null) {
|
||||
context.read<TransactionReportBloc>().add(
|
||||
TransactionReportEvent.fetchedTransaction(
|
||||
start!,
|
||||
end!,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
onDownload: () async {
|
||||
try {
|
||||
final status = await PermessionHelper()
|
||||
.checkPermission();
|
||||
if (status) {
|
||||
final pdfFile =
|
||||
await TransactionReport.previewPdf(
|
||||
searchDateFormatted:
|
||||
"${_transactionStartDate?.toServerDate} - ${_transactionEndDate?.toServerDate}",
|
||||
outlet: state.outlet,
|
||||
categoryAnalyticData:
|
||||
state.categoryAnalytic,
|
||||
profitLossData:
|
||||
state.profitLossAnalytic,
|
||||
paymentMethodAnalyticData:
|
||||
state.paymentMethodAnalytic,
|
||||
productAnalyticData:
|
||||
state.productAnalytic,
|
||||
);
|
||||
log("pdfFile: $pdfFile");
|
||||
await HelperPdfService.openFile(pdfFile);
|
||||
} else {
|
||||
AppFlushbar.showError(
|
||||
context,
|
||||
'Storage permission is required to save PDF',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
log("Error generating PDF: $e");
|
||||
AppFlushbar.showError(
|
||||
context,
|
||||
'Failed to generate PDF: $e',
|
||||
);
|
||||
}
|
||||
},
|
||||
delay: 200,
|
||||
);
|
||||
},
|
||||
onDownload: () => _downloadReport(
|
||||
'Transaction Report',
|
||||
_transactionStartDate,
|
||||
_transactionEndDate,
|
||||
),
|
||||
delay: 200,
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
Reference in New Issue
Block a user