apskel-pos-flutter/lib/presentation/report/widgets/transaction_report_widget.dart

196 lines
7.7 KiB
Dart
Raw Normal View History

2025-07-30 22:38:44 +07:00
import 'dart:developer';
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/int_ext.dart';
import 'package:enaklo_pos/core/utils/helper_pdf_service.dart';
2025-08-01 18:27:40 +07:00
import 'package:enaklo_pos/presentation/report/widgets/report_page_title.dart';
2025-07-30 22:38:44 +07:00
import 'package:flutter/material.dart';
import 'package:enaklo_pos/core/utils/permession_handler.dart';
import 'package:enaklo_pos/core/utils/transaction_sales_invoice.dart';
2025-08-03 14:39:15 +07:00
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
2025-07-30 22:38:44 +07:00
import 'package:horizontal_data_table/horizontal_data_table.dart';
class TransactionReportWidget extends StatelessWidget {
final String title;
final String searchDateFormatted;
2025-08-03 14:39:15 +07:00
final List<Order> transactionReport;
2025-07-30 22:38:44 +07:00
final List<Widget>? headerWidgets;
const TransactionReportWidget({
super.key,
required this.transactionReport,
required this.title,
required this.searchDateFormatted,
required this.headerWidgets,
});
@override
Widget build(BuildContext context) {
2025-08-01 18:27:40 +07:00
return Column(
children: [
ReportPageTitle(
title: title,
searchDateFormatted: searchDateFormatted,
onExport: () async {
try {
final status = await PermessionHelper().checkPermission();
if (status) {
final pdfFile = await TransactionSalesInvoice.generate(
transactionReport, searchDateFormatted);
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,
2025-07-30 22:38:44 +07:00
),
2025-08-01 18:27:40 +07:00
);
}
} catch (e) {
log("Error generating PDF: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to generate PDF: $e'),
backgroundColor: Colors.red,
2025-07-30 22:38:44 +07:00
),
2025-08-01 18:27:40 +07:00
);
}
},
),
const SpaceHeight(16.0),
Expanded(
child: Padding(
padding: const EdgeInsets.all(12),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: HorizontalDataTable(
leftHandSideColumnWidth: 50,
rightHandSideColumnWidth: 1020,
isFixedHeader: true,
headerWidgets: headerWidgets,
// isFixedFooter: true,
// footerWidgets: _getTitleWidget(),
leftSideItemBuilder: (context, index) {
return Container(
width: 40,
height: 52,
alignment: Alignment.centerLeft,
child: Center(
child: Text(transactionReport[index].id.toString())),
);
},
rightSideItemBuilder: (context, index) {
return Row(
children: <Widget>[
Container(
width: 120,
height: 52,
padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
alignment: Alignment.centerLeft,
child: Center(
2025-07-30 22:38:44 +07:00
child: Text(
2025-08-03 14:39:15 +07:00
transactionReport[index]
.totalAmount!
.currencyFormatRp,
2025-08-01 18:27:40 +07:00
)),
),
2025-08-03 14:39:15 +07:00
// Container(
// width: 120,
// height: 52,
// padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
// alignment: Alignment.centerLeft,
// child: Center(
// child: Text(
// transactionReport[index].subTotal!.currencyFormatRp,
// )),
// ),
// Container(
// width: 100,
// height: 52,
// padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
// alignment: Alignment.centerLeft,
// child: Center(
// child: Text(
// transactionReport[index].tax!.currencyFormatRp,
// )),
// ),
// Container(
// width: 100,
// height: 52,
// padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
// alignment: Alignment.centerLeft,
// child: Center(
// child: Text(
// int.parse(transactionReport[index]
// .discountAmount!
// .replaceAll('.00', ''))
// .currencyFormatRp,
// ),
// ),
// ),
// Container(
// width: 100,
// height: 52,
// padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
// alignment: Alignment.centerLeft,
// child: Center(
// child: Text(
// transactionReport[index]
// .serviceCharge!
// .currencyFormatRp,
// ),
// ),
// ),
// Container(
// width: 100,
// height: 52,
// padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
// alignment: Alignment.centerLeft,
// child: Center(
// child: Text(
// transactionReport[index].totalItem.toString()),
// ),
// ),
// Container(
// width: 150,
// height: 52,
// padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
// alignment: Alignment.centerLeft,
// child: Center(
// child: Text(transactionReport[index].namaKasir!),
// ),
// ),
// Container(
// width: 230,
// height: 52,
// padding: const EdgeInsets.fromLTRB(5, 0, 0, 0),
// alignment: Alignment.centerLeft,
// child: Center(
// child: Text(transactionReport[index]
// .transactionTime!
// .toFormattedDate()),
// ),
// ),
2025-08-01 18:27:40 +07:00
],
);
},
itemCount: transactionReport.length,
rowSeparatorWidget: const Divider(
color: Colors.black38,
height: 1.0,
thickness: 0.0,
2025-07-30 22:38:44 +07:00
),
2025-08-01 18:27:40 +07:00
leftHandSideColBackgroundColor: AppColors.white,
rightHandSideColBackgroundColor: AppColors.white,
itemExtent: 55,
2025-07-30 22:38:44 +07:00
),
),
),
2025-08-01 18:27:40 +07:00
),
],
2025-07-30 22:38:44 +07:00
);
}
}