feat: report page
This commit is contained in:
@@ -5,12 +5,12 @@ import 'package:enaklo_pos/core/constants/colors.dart';
|
||||
import 'package:enaklo_pos/core/extensions/date_time_ext.dart';
|
||||
import 'package:enaklo_pos/core/extensions/int_ext.dart';
|
||||
import 'package:enaklo_pos/core/utils/helper_pdf_service.dart';
|
||||
import 'package:enaklo_pos/presentation/report/widgets/report_page_title.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:enaklo_pos/core/utils/permession_handler.dart';
|
||||
import 'package:enaklo_pos/core/utils/transaction_sales_invoice.dart';
|
||||
import 'package:enaklo_pos/data/models/response/order_remote_datasource.dart';
|
||||
import 'package:horizontal_data_table/horizontal_data_table.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class TransactionReportWidget extends StatelessWidget {
|
||||
final String title;
|
||||
@@ -27,208 +27,168 @@ class TransactionReportWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
color: const Color.fromARGB(255, 255, 255, 255),
|
||||
child: Column(
|
||||
children: [
|
||||
const SpaceHeight(24.0),
|
||||
Center(
|
||||
child: Text(
|
||||
title,
|
||||
style:
|
||||
const TextStyle(fontWeight: FontWeight.w800, fontSize: 16.0),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 8.0,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
searchDateFormatted,
|
||||
style: const TextStyle(fontSize: 16.0),
|
||||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
log("Error generating PDF: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to generate PDF: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () 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,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
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(
|
||||
child: Text(
|
||||
transactionReport[index].total!.currencyFormatRp,
|
||||
)),
|
||||
),
|
||||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
log("Error generating PDF: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to generate PDF: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Row(
|
||||
children: [
|
||||
Text(
|
||||
"PDF",
|
||||
style: TextStyle(
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.download_outlined,
|
||||
color: AppColors.primary,
|
||||
)
|
||||
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()),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: transactionReport.length,
|
||||
rowSeparatorWidget: const Divider(
|
||||
color: Colors.black38,
|
||||
height: 1.0,
|
||||
thickness: 0.0,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
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(
|
||||
child: Text(
|
||||
transactionReport[index].total!.currencyFormatRp,
|
||||
)),
|
||||
),
|
||||
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()),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
itemCount: transactionReport.length,
|
||||
rowSeparatorWidget: const Divider(
|
||||
color: Colors.black38,
|
||||
height: 1.0,
|
||||
thickness: 0.0,
|
||||
),
|
||||
leftHandSideColBackgroundColor: AppColors.white,
|
||||
rightHandSideColBackgroundColor: AppColors.white,
|
||||
leftHandSideColBackgroundColor: AppColors.white,
|
||||
rightHandSideColBackgroundColor: AppColors.white,
|
||||
|
||||
itemExtent: 55,
|
||||
),
|
||||
itemExtent: 55,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user