feat: report transaction
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
||||
import 'package:enaklo_pos/core/utils/helper_pdf_service.dart';
|
||||
import 'package:enaklo_pos/core/utils/permession_handler.dart';
|
||||
import 'package:enaklo_pos/core/utils/transaction_report.dart';
|
||||
import 'package:enaklo_pos/presentation/report/blocs/profit_loss/profit_loss_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/report/blocs/report/report_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/report/widgets/dashboard_analytic_widget.dart';
|
||||
import 'package:enaklo_pos/presentation/report/widgets/profit_loss_widget.dart';
|
||||
import 'package:enaklo_pos/presentation/sales/pages/sales_page.dart';
|
||||
@@ -44,6 +48,9 @@ class _ReportPageState extends State<ReportPage> {
|
||||
context.read<SummaryBloc>().add(
|
||||
SummaryEvent.getSummary(fromDate, toDate),
|
||||
);
|
||||
context.read<ReportBloc>().add(
|
||||
ReportEvent.get(startDate: fromDate, endDate: toDate),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -64,12 +71,14 @@ class _ReportPageState extends State<ReportPage> {
|
||||
initialDate: fromDate,
|
||||
onDateSelected: (selectedDate) {
|
||||
fromDate = selectedDate;
|
||||
|
||||
context.read<ReportBloc>().add(
|
||||
ReportEvent.get(startDate: fromDate, endDate: toDate),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SpaceWidth(24.0),
|
||||
const SpaceWidth(12.0),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: CustomDatePicker(
|
||||
@@ -77,6 +86,9 @@ class _ReportPageState extends State<ReportPage> {
|
||||
initialDate: toDate,
|
||||
onDateSelected: (selectedDate) {
|
||||
toDate = selectedDate;
|
||||
context.read<ReportBloc>().add(
|
||||
ReportEvent.get(startDate: fromDate, endDate: toDate),
|
||||
);
|
||||
setState(() {});
|
||||
// context.read<TransactionReportBloc>().add(
|
||||
// TransactionReportEvent.getReport(
|
||||
@@ -97,6 +109,72 @@ class _ReportPageState extends State<ReportPage> {
|
||||
},
|
||||
),
|
||||
),
|
||||
const SpaceWidth(12.0),
|
||||
BlocBuilder<ReportBloc, ReportState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => SizedBox.shrink(),
|
||||
loading: () => SizedBox(
|
||||
height: 24,
|
||||
width: 24,
|
||||
child: const CircularProgressIndicator(),
|
||||
),
|
||||
loaded: (outlet, categoryAnalyticData, profitLossData,
|
||||
paymentMethodAnalyticData, productAnalyticData) =>
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
try {
|
||||
final status =
|
||||
await PermessionHelper().checkPermission();
|
||||
if (status) {
|
||||
final pdfFile = await TransactionReport.previewPdf(
|
||||
outlet: outlet,
|
||||
searchDateFormatted: searchDateFormatted,
|
||||
categoryAnalyticData: categoryAnalyticData,
|
||||
profitLossData: profitLossData,
|
||||
paymentMethodAnalyticData:
|
||||
paymentMethodAnalyticData,
|
||||
productAnalyticData: productAnalyticData,
|
||||
);
|
||||
log("pdfFile: $pdfFile");
|
||||
await HelperPdfService.openFile(pdfFile);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Storage permission is required to save PDF'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
log("Error generating PDF: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to generate PDF: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12.0, vertical: 8.0),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(6.0),
|
||||
border: Border.all(
|
||||
color: AppColors.stroke,
|
||||
)),
|
||||
child: Icon(
|
||||
Icons.download,
|
||||
color: AppColors.primary,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
|
||||
Reference in New Issue
Block a user