feat: inventory report
This commit is contained in:
@@ -0,0 +1,547 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
|
||||
import '../../../common/utils/pdf_service.dart';
|
||||
import '../../../domain/analytic/analytic.dart';
|
||||
import '../../../domain/outlet/outlet.dart';
|
||||
|
||||
class InventoryReport {
|
||||
static final primaryColor = PdfColor.fromHex("36175e");
|
||||
|
||||
static Future<File> previewPdf({
|
||||
required String searchDateFormatted,
|
||||
required InventoryAnalytic inventory,
|
||||
required Outlet outlet,
|
||||
}) async {
|
||||
final pdf = pw.Document();
|
||||
final ByteData dataImage = await rootBundle.load('assets/images/logo.png');
|
||||
final Uint8List bytes = dataImage.buffer.asUint8List();
|
||||
|
||||
final image = pw.MemoryImage(bytes);
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.a4,
|
||||
margin: pw.EdgeInsets.zero,
|
||||
build: (pw.Context context) {
|
||||
return [
|
||||
pw.Container(
|
||||
padding: pw.EdgeInsets.all(20),
|
||||
child: pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Bagian kiri - Logo dan Info Perusahaan
|
||||
pw.Row(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Icon/Logo placeholder (bisa diganti dengan gambar logo)
|
||||
pw.Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: pw.Image(image),
|
||||
),
|
||||
pw.SizedBox(width: 15),
|
||||
pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
pw.Text(
|
||||
'Apskel',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
outlet.name,
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
color: PdfColors.grey700,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 2),
|
||||
pw.Text(
|
||||
outlet.address,
|
||||
style: pw.TextStyle(
|
||||
fontSize: 12,
|
||||
color: PdfColors.grey600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// Bagian kanan - Info Laporan
|
||||
pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.end,
|
||||
children: [
|
||||
pw.Text(
|
||||
'Laporan Transaksi',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.grey800,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 8),
|
||||
pw.Text(
|
||||
searchDateFormatted,
|
||||
style: pw.TextStyle(
|
||||
fontSize: 14,
|
||||
color: PdfColors.grey600,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
'Laporan',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 12,
|
||||
color: PdfColors.grey500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
pw.Container(
|
||||
width: double.infinity,
|
||||
height: 3,
|
||||
color: primaryColor,
|
||||
),
|
||||
|
||||
// Summary
|
||||
pw.Container(
|
||||
padding: pw.EdgeInsets.all(20),
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSectionWidget('1. Ringkasan'),
|
||||
pw.SizedBox(height: 30),
|
||||
pw.Row(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
pw.Expanded(
|
||||
flex: 1,
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSummaryItem(
|
||||
'Total Item',
|
||||
(inventory.summary.totalProducts).toString(),
|
||||
),
|
||||
_buildSummaryItem(
|
||||
'Total Item Masuk',
|
||||
(inventory.products.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.totalIn),
|
||||
)).toString(),
|
||||
),
|
||||
_buildSummaryItem(
|
||||
'Total Item Keluar',
|
||||
(inventory.products.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.totalOut),
|
||||
)).toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
pw.SizedBox(width: 20),
|
||||
pw.Expanded(
|
||||
flex: 1,
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSummaryItem(
|
||||
'Total Ingredient',
|
||||
(inventory.summary.totalIngredients).toString(),
|
||||
),
|
||||
_buildSummaryItem(
|
||||
'Total Ingredient Masuk',
|
||||
(inventory.ingredients.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.totalIn),
|
||||
)).toString(),
|
||||
),
|
||||
_buildSummaryItem(
|
||||
'Total Ingredient Keluar',
|
||||
(inventory.ingredients.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.totalOut),
|
||||
)).toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Summary Item
|
||||
pw.Container(
|
||||
padding: pw.EdgeInsets.all(20),
|
||||
child: pw.Column(
|
||||
children: [
|
||||
pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSectionWidget('2. Item'),
|
||||
pw.SizedBox(height: 30),
|
||||
pw.Container(
|
||||
decoration: pw.BoxDecoration(
|
||||
color: primaryColor, // Purple color
|
||||
borderRadius: pw.BorderRadius.only(
|
||||
topLeft: pw.Radius.circular(8),
|
||||
topRight: pw.Radius.circular(8),
|
||||
),
|
||||
),
|
||||
child: pw.Table(
|
||||
columnWidths: const {
|
||||
0: pw.FlexColumnWidth(2.5), // Produk
|
||||
1: pw.FlexColumnWidth(2), // Kategori
|
||||
2: pw.FlexColumnWidth(1), // Stock
|
||||
3: pw.FlexColumnWidth(2), // Masuk
|
||||
4: pw.FlexColumnWidth(2), // Keluar
|
||||
},
|
||||
children: [
|
||||
pw.TableRow(
|
||||
children: [
|
||||
_buildHeaderCell('Nama'),
|
||||
_buildHeaderCell('Kategori'),
|
||||
_buildHeaderCell('Stock'),
|
||||
_buildHeaderCell('Masuk'),
|
||||
_buildHeaderCell('Keluar'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
pw.Container(
|
||||
decoration: pw.BoxDecoration(color: PdfColors.white),
|
||||
child: pw.Table(
|
||||
columnWidths: {
|
||||
0: pw.FlexColumnWidth(2.5), // Produk
|
||||
1: pw.FlexColumnWidth(2), // Kategori
|
||||
2: pw.FlexColumnWidth(1), // Stock
|
||||
3: pw.FlexColumnWidth(2), // Masuk
|
||||
4: pw.FlexColumnWidth(2), // Keluar
|
||||
},
|
||||
children: inventory.products
|
||||
.map(
|
||||
(item) => _buildProductDataRow(
|
||||
item,
|
||||
inventory.products.indexOf(item) % 2 == 0,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
pw.Container(
|
||||
decoration: pw.BoxDecoration(
|
||||
color: primaryColor, // Purple color
|
||||
borderRadius: pw.BorderRadius.only(
|
||||
bottomLeft: pw.Radius.circular(8),
|
||||
bottomRight: pw.Radius.circular(8),
|
||||
),
|
||||
),
|
||||
child: pw.Table(
|
||||
columnWidths: const {
|
||||
0: pw.FlexColumnWidth(2.5), // Produk
|
||||
1: pw.FlexColumnWidth(2), // Kategori
|
||||
2: pw.FlexColumnWidth(1), // Stock
|
||||
3: pw.FlexColumnWidth(2), // Masuk
|
||||
4: pw.FlexColumnWidth(2), // Keluar
|
||||
},
|
||||
children: [
|
||||
pw.TableRow(
|
||||
children: [
|
||||
_buildTotalCell('TOTAL'),
|
||||
_buildTotalCell(''),
|
||||
_buildTotalCell(
|
||||
(inventory.products.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.quantity),
|
||||
)).toString(),
|
||||
),
|
||||
_buildTotalCell(
|
||||
(inventory.products.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.totalIn),
|
||||
)).toString(),
|
||||
),
|
||||
_buildTotalCell(
|
||||
(inventory.products.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.totalOut),
|
||||
)).toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Summary Ingredient
|
||||
pw.Container(
|
||||
padding: pw.EdgeInsets.all(20),
|
||||
child: pw.Column(
|
||||
children: [
|
||||
pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildSectionWidget('3. Ingredient'),
|
||||
pw.SizedBox(height: 30),
|
||||
pw.Container(
|
||||
decoration: pw.BoxDecoration(
|
||||
color: primaryColor, // Purple color
|
||||
borderRadius: pw.BorderRadius.only(
|
||||
topLeft: pw.Radius.circular(8),
|
||||
topRight: pw.Radius.circular(8),
|
||||
),
|
||||
),
|
||||
child: pw.Table(
|
||||
columnWidths: const {
|
||||
0: pw.FlexColumnWidth(2.5), // Name
|
||||
1: pw.FlexColumnWidth(1), // Stock
|
||||
2: pw.FlexColumnWidth(2), // Masuk
|
||||
3: pw.FlexColumnWidth(2), // Keluar
|
||||
},
|
||||
children: [
|
||||
pw.TableRow(
|
||||
children: [
|
||||
_buildHeaderCell('Nama'),
|
||||
_buildHeaderCell('Stock'),
|
||||
_buildHeaderCell('Masuk'),
|
||||
_buildHeaderCell('Keluar'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
pw.Container(
|
||||
decoration: pw.BoxDecoration(color: PdfColors.white),
|
||||
child: pw.Table(
|
||||
columnWidths: {
|
||||
0: pw.FlexColumnWidth(2.5), // Name
|
||||
1: pw.FlexColumnWidth(1), // Stock
|
||||
2: pw.FlexColumnWidth(2), // Masuk
|
||||
3: pw.FlexColumnWidth(2), // Keluar
|
||||
},
|
||||
children: inventory.ingredients
|
||||
.map(
|
||||
(item) => _buildIngredientsDataRow(
|
||||
item,
|
||||
inventory.ingredients.indexOf(item) % 2 == 0,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
pw.Container(
|
||||
decoration: pw.BoxDecoration(
|
||||
color: primaryColor, // Purple color
|
||||
borderRadius: pw.BorderRadius.only(
|
||||
bottomLeft: pw.Radius.circular(8),
|
||||
bottomRight: pw.Radius.circular(8),
|
||||
),
|
||||
),
|
||||
child: pw.Table(
|
||||
columnWidths: const {
|
||||
0: pw.FlexColumnWidth(2.5), // Name
|
||||
1: pw.FlexColumnWidth(1), // Stock
|
||||
2: pw.FlexColumnWidth(2), // Masuk
|
||||
3: pw.FlexColumnWidth(2), // Keluar
|
||||
},
|
||||
children: [
|
||||
pw.TableRow(
|
||||
children: [
|
||||
_buildTotalCell('TOTAL'),
|
||||
_buildTotalCell(
|
||||
(inventory.ingredients.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.quantity),
|
||||
)).toString(),
|
||||
),
|
||||
_buildTotalCell(
|
||||
(inventory.ingredients.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.totalIn),
|
||||
)).toString(),
|
||||
),
|
||||
_buildTotalCell(
|
||||
(inventory.ingredients.fold<num>(
|
||||
0,
|
||||
(sum, item) => sum + (item.totalOut),
|
||||
)).toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return HelperPdfService.saveDocument(
|
||||
name:
|
||||
'Apskel POS | Inventory Report | ${DateTime.now().millisecondsSinceEpoch}.pdf',
|
||||
pdf: pdf,
|
||||
);
|
||||
}
|
||||
|
||||
static pw.Widget _buildSectionWidget(String title) {
|
||||
return pw.Text(
|
||||
title,
|
||||
style: pw.TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: primaryColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static pw.Widget _buildSummaryItem(
|
||||
String label,
|
||||
String value, {
|
||||
pw.TextStyle? valueStyle,
|
||||
pw.TextStyle? labelStyle,
|
||||
}) {
|
||||
return pw.Container(
|
||||
padding: pw.EdgeInsets.only(bottom: 8),
|
||||
margin: pw.EdgeInsets.only(bottom: 16),
|
||||
decoration: pw.BoxDecoration(
|
||||
border: pw.Border(bottom: pw.BorderSide(color: PdfColors.grey300)),
|
||||
),
|
||||
child: pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text(label, style: labelStyle),
|
||||
pw.Text(
|
||||
value,
|
||||
style: valueStyle ?? pw.TextStyle(fontWeight: pw.FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static pw.Widget _buildHeaderCell(String text) {
|
||||
return pw.Container(
|
||||
padding: pw.EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
||||
child: pw.Text(
|
||||
text,
|
||||
style: pw.TextStyle(
|
||||
color: PdfColors.white,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
textAlign: pw.TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static pw.Widget _buildDataCell(
|
||||
String text, {
|
||||
pw.Alignment alignment = pw.Alignment.center,
|
||||
PdfColor? textColor,
|
||||
}) {
|
||||
return pw.Container(
|
||||
padding: pw.EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
||||
alignment: alignment,
|
||||
child: pw.Text(
|
||||
text,
|
||||
style: pw.TextStyle(
|
||||
fontSize: 12,
|
||||
color: textColor ?? PdfColors.black,
|
||||
fontWeight: pw.FontWeight.normal,
|
||||
),
|
||||
textAlign: alignment == pw.Alignment.centerLeft
|
||||
? pw.TextAlign.left
|
||||
: pw.TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static pw.Widget _buildTotalCell(String text) {
|
||||
return pw.Container(
|
||||
padding: pw.EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
||||
child: pw.Text(
|
||||
text,
|
||||
style: pw.TextStyle(
|
||||
color: PdfColors.white,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 12,
|
||||
),
|
||||
textAlign: pw.TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static pw.TableRow _buildProductDataRow(
|
||||
InventoryProduct product,
|
||||
bool isEven,
|
||||
) {
|
||||
return pw.TableRow(
|
||||
decoration: pw.BoxDecoration(
|
||||
color: product.isZeroStock
|
||||
? PdfColors.red100
|
||||
: product.isLowStock
|
||||
? PdfColors.yellow100
|
||||
: isEven
|
||||
? PdfColors.grey50
|
||||
: PdfColors.white,
|
||||
),
|
||||
children: [
|
||||
_buildDataCell(product.productName, alignment: pw.Alignment.centerLeft),
|
||||
_buildDataCell(
|
||||
product.categoryName,
|
||||
alignment: pw.Alignment.centerLeft,
|
||||
),
|
||||
_buildDataCell(product.quantity.toString()),
|
||||
_buildDataCell(product.totalIn.toString()),
|
||||
_buildDataCell(product.totalOut.toString()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static pw.TableRow _buildIngredientsDataRow(
|
||||
InventoryIngredient item,
|
||||
bool isEven,
|
||||
) {
|
||||
return pw.TableRow(
|
||||
decoration: pw.BoxDecoration(
|
||||
color: item.isZeroStock
|
||||
? PdfColors.red100
|
||||
: item.isLowStock
|
||||
? PdfColors.yellow100
|
||||
: isEven
|
||||
? PdfColors.grey50
|
||||
: PdfColors.white,
|
||||
),
|
||||
children: [
|
||||
_buildDataCell(item.ingredientName, alignment: pw.Alignment.centerLeft),
|
||||
_buildDataCell(item.quantity.toString()),
|
||||
_buildDataCell(item.totalIn.toString()),
|
||||
_buildDataCell(item.totalOut.toString()),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,34 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
|
||||
import '../../../application/report/inventory_report/inventory_report_bloc.dart';
|
||||
import '../../../common/extension/extension.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../common/utils/pdf_service.dart';
|
||||
import '../../../common/utils/permission.dart';
|
||||
import '../../../injection.dart';
|
||||
import '../../components/appbar/appbar.dart';
|
||||
import '../../components/field/date_range_picker_field.dart';
|
||||
import '../../components/report/inventory_report.dart';
|
||||
import '../../components/toast/flushbar.dart';
|
||||
|
||||
@RoutePage()
|
||||
class DownloadReportPage extends StatefulWidget {
|
||||
class DownloadReportPage extends StatefulWidget implements AutoRouteWrapper {
|
||||
const DownloadReportPage({super.key});
|
||||
|
||||
@override
|
||||
State<DownloadReportPage> createState() => _DownloadReportPageState();
|
||||
|
||||
@override
|
||||
Widget wrappedRoute(BuildContext context) => BlocProvider(
|
||||
create: (context) =>
|
||||
getIt<InventoryReportBloc>()..add(InventoryReportEvent.fetchedOutlet()),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
class _DownloadReportPageState extends State<DownloadReportPage>
|
||||
@@ -26,10 +44,10 @@ class _DownloadReportPageState extends State<DownloadReportPage>
|
||||
DateTime? _transactionEndDate;
|
||||
DateTime? _inventoryStartDate;
|
||||
DateTime? _inventoryEndDate;
|
||||
DateTime? _salesStartDate;
|
||||
DateTime? _salesEndDate;
|
||||
DateTime? _customerStartDate;
|
||||
DateTime? _customerEndDate;
|
||||
// DateTime? _salesStartDate;
|
||||
// DateTime? _salesEndDate;
|
||||
// DateTime? _customerStartDate;
|
||||
// DateTime? _customerEndDate;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -76,28 +94,9 @@ class _DownloadReportPageState extends State<DownloadReportPage>
|
||||
DateTime? endDate,
|
||||
) {
|
||||
if (startDate == null || endDate == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Please select both start and end dates'),
|
||||
backgroundColor: AppColor.error,
|
||||
),
|
||||
);
|
||||
AppFlushbar.showError(context, 'Please select both start and end dates');
|
||||
return;
|
||||
}
|
||||
|
||||
// Implement download logic here
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Downloading $reportType from ${_formatDate(startDate)} to ${_formatDate(endDate)}',
|
||||
),
|
||||
backgroundColor: AppColor.success,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
return '${date.day}/${date.month}/${date.year}';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -139,6 +138,7 @@ class _DownloadReportPageState extends State<DownloadReportPage>
|
||||
],
|
||||
startDate: _transactionStartDate,
|
||||
endDate: _transactionEndDate,
|
||||
isLoading: false,
|
||||
onDateRangeChanged: (start, end) {
|
||||
setState(() {
|
||||
_transactionStartDate = start;
|
||||
@@ -156,79 +156,115 @@ class _DownloadReportPageState extends State<DownloadReportPage>
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Inventory Report Card
|
||||
_ReportOptionCard(
|
||||
title: 'Inventory Report',
|
||||
subtitle:
|
||||
'Export inventory and stock data with trends',
|
||||
icon: Icons.inventory_2_outlined,
|
||||
gradient: const [
|
||||
AppColor.secondary,
|
||||
AppColor.secondaryLight,
|
||||
],
|
||||
startDate: _inventoryStartDate,
|
||||
endDate: _inventoryEndDate,
|
||||
onDateRangeChanged: (start, end) {
|
||||
setState(() {
|
||||
_inventoryStartDate = start;
|
||||
_inventoryEndDate = end;
|
||||
});
|
||||
BlocBuilder<InventoryReportBloc, InventoryReportState>(
|
||||
builder: (context, state) {
|
||||
return _ReportOptionCard(
|
||||
title: 'Inventory Report',
|
||||
subtitle:
|
||||
'Export inventory and stock data with trends',
|
||||
icon: Icons.inventory_2_outlined,
|
||||
gradient: const [
|
||||
AppColor.secondary,
|
||||
AppColor.secondaryLight,
|
||||
],
|
||||
startDate: _inventoryStartDate,
|
||||
endDate: _inventoryEndDate,
|
||||
isLoading: state.isFetching,
|
||||
onDateRangeChanged: (start, end) {
|
||||
setState(() {
|
||||
_inventoryStartDate = start;
|
||||
_inventoryEndDate = end;
|
||||
});
|
||||
if (start != null || end != null) {
|
||||
context.read<InventoryReportBloc>().add(
|
||||
InventoryReportEvent.fetchedInventory(
|
||||
start!,
|
||||
end!,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
onDownload: () async {
|
||||
try {
|
||||
final status = await PermessionHelper()
|
||||
.checkPermission();
|
||||
if (status) {
|
||||
final pdfFile =
|
||||
await InventoryReport.previewPdf(
|
||||
searchDateFormatted:
|
||||
"${_inventoryStartDate?.toServerDate} - ${_inventoryEndDate?.toServerDate}",
|
||||
inventory: state.inventoryAnalytic,
|
||||
outlet: state.outlet,
|
||||
);
|
||||
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: 400,
|
||||
);
|
||||
},
|
||||
onDownload: () => _downloadReport(
|
||||
'Inventory Report',
|
||||
_inventoryStartDate,
|
||||
_inventoryEndDate,
|
||||
),
|
||||
delay: 400,
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Sales Report Card
|
||||
_ReportOptionCard(
|
||||
title: 'Sales Report',
|
||||
subtitle: 'Export sales performance and revenue data',
|
||||
icon: Icons.trending_up_outlined,
|
||||
gradient: const [AppColor.info, Color(0xFF64B5F6)],
|
||||
startDate: _salesStartDate,
|
||||
endDate: _salesEndDate,
|
||||
onDateRangeChanged: (start, end) {
|
||||
setState(() {
|
||||
_salesStartDate = start;
|
||||
_salesEndDate = end;
|
||||
});
|
||||
},
|
||||
onDownload: () => _downloadReport(
|
||||
'Sales Report',
|
||||
_salesStartDate,
|
||||
_salesEndDate,
|
||||
),
|
||||
delay: 600,
|
||||
),
|
||||
// _ReportOptionCard(
|
||||
// title: 'Sales Report',
|
||||
// subtitle: 'Export sales performance and revenue data',
|
||||
// icon: Icons.trending_up_outlined,
|
||||
// gradient: const [AppColor.info, Color(0xFF64B5F6)],
|
||||
// startDate: _salesStartDate,
|
||||
// endDate: _salesEndDate,
|
||||
// onDateRangeChanged: (start, end) {
|
||||
// setState(() {
|
||||
// _salesStartDate = start;
|
||||
// _salesEndDate = end;
|
||||
// });
|
||||
// },
|
||||
// onDownload: () => _downloadReport(
|
||||
// 'Sales Report',
|
||||
// _salesStartDate,
|
||||
// _salesEndDate,
|
||||
// ),
|
||||
// delay: 600,
|
||||
// ),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
// const SizedBox(height: 20),
|
||||
|
||||
// Customer Report Card
|
||||
_ReportOptionCard(
|
||||
title: 'Customer Report',
|
||||
subtitle:
|
||||
'Export customer data and behavior analytics',
|
||||
icon: Icons.people_outline,
|
||||
gradient: const [AppColor.warning, Color(0xFFFFB74D)],
|
||||
startDate: _customerStartDate,
|
||||
endDate: _customerEndDate,
|
||||
onDateRangeChanged: (start, end) {
|
||||
setState(() {
|
||||
_customerStartDate = start;
|
||||
_customerEndDate = end;
|
||||
});
|
||||
},
|
||||
onDownload: () => _downloadReport(
|
||||
'Customer Report',
|
||||
_customerStartDate,
|
||||
_customerEndDate,
|
||||
),
|
||||
delay: 800,
|
||||
),
|
||||
// // Customer Report Card
|
||||
// _ReportOptionCard(
|
||||
// title: 'Customer Report',
|
||||
// subtitle:
|
||||
// 'Export customer data and behavior analytics',
|
||||
// icon: Icons.people_outline,
|
||||
// gradient: const [AppColor.warning, Color(0xFFFFB74D)],
|
||||
// startDate: _customerStartDate,
|
||||
// endDate: _customerEndDate,
|
||||
// onDateRangeChanged: (start, end) {
|
||||
// setState(() {
|
||||
// _customerStartDate = start;
|
||||
// _customerEndDate = end;
|
||||
// });
|
||||
// },
|
||||
// onDownload: () => _downloadReport(
|
||||
// 'Customer Report',
|
||||
// _customerStartDate,
|
||||
// _customerEndDate,
|
||||
// ),
|
||||
// delay: 800,
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -253,6 +289,7 @@ class _ReportOptionCard extends StatefulWidget {
|
||||
final DateTime? endDate;
|
||||
final Function(DateTime? startDate, DateTime? endDate) onDateRangeChanged;
|
||||
final VoidCallback onDownload;
|
||||
final bool isLoading;
|
||||
final int delay;
|
||||
|
||||
const _ReportOptionCard({
|
||||
@@ -265,6 +302,7 @@ class _ReportOptionCard extends StatefulWidget {
|
||||
required this.onDateRangeChanged,
|
||||
required this.onDownload,
|
||||
required this.delay,
|
||||
required this.isLoading,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -431,23 +469,41 @@ class _ReportOptionCardState extends State<_ReportOptionCard>
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.download_rounded,
|
||||
color: widget.gradient.first,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Download Report',
|
||||
style: AppStyle.md.copyWith(
|
||||
color: widget.gradient.first,
|
||||
fontWeight: FontWeight.bold,
|
||||
child: widget.isLoading
|
||||
? Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SpinKitCircle(
|
||||
color: widget.gradient.first,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Loading',
|
||||
style: AppStyle.md.copyWith(
|
||||
color: widget.gradient.first,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.download_rounded,
|
||||
color: widget.gradient.first,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Download Report',
|
||||
style: AppStyle.md.copyWith(
|
||||
color: widget.gradient.first,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user