first commit
This commit is contained in:
209
lib/pdf_report/transactions/all_transaction_report_pdf.dart
Normal file
209
lib/pdf_report/transactions/all_transaction_report_pdf.dart
Normal file
@@ -0,0 +1,209 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:mobile_pos/Screens/all_transaction/all_transaction.dart';
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../Screens/all_transaction/model/transaction_model.dart' as tmodel;
|
||||
import '../../model/business_info_model.dart';
|
||||
|
||||
Future<void> generateAllTransactionReportPdf(
|
||||
BuildContext context,
|
||||
tmodel.TransactionModel data,
|
||||
BusinessInformationModel? business,
|
||||
DateTime? fromDate,
|
||||
DateTime? toDate,
|
||||
) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
'All Transaction Report',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < (data.data?.length ?? 0); i++) {
|
||||
final _transaction = [...?data.data][i];
|
||||
tableData.add([
|
||||
"${i + 1}",
|
||||
_transaction.date == null
|
||||
? "N/A"
|
||||
: intl.DateFormat('dd MMM, yyyy').format(DateTime.parse(_transaction.date!)),
|
||||
_transaction.invoiceNo ?? "N/A",
|
||||
_transaction.platform?.toTitleCase() ?? "N/A",
|
||||
formatPointNumber(_transaction.amount ?? 0, addComma: DateTime.now().minute.isEven),
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: [
|
||||
"SL.",
|
||||
"Date",
|
||||
"Reference",
|
||||
"Type",
|
||||
"Amount",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(2),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(4),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(4),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
6: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
// Totals row (styled to match)
|
||||
pw.Table.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(4),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(4),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(4),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
6: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
'Total',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
formatPointNumber(data.totalAmount ?? 0),
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-customer-ledger.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Sales Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
181
lib/pdf_report/transactions/balance_sheet_report_pdf.dart
Normal file
181
lib/pdf_report/transactions/balance_sheet_report_pdf.dart
Normal file
@@ -0,0 +1,181 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
|
||||
import '../../model/balance_sheet_model.dart' as model;
|
||||
import '../../model/business_info_model.dart';
|
||||
|
||||
Future<void> generateBalanceSheetReportPdf(BuildContext context, model.BalanceSheetModel data,
|
||||
BusinessInformationModel? business, DateTime? fromDate, DateTime? toDate) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
final interFont = await PdfGoogleFonts.notoSansRegular();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
'Balance Sheet',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
fromDate != null
|
||||
? 'Duration: ${DateFormat('dd-MM-yyyy').format(fromDate)} to ${DateFormat('dd-MM-yyyy').format(toDate!)}'
|
||||
: '',
|
||||
style: pw.TextStyle(
|
||||
font: interFont,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < (data.data?.length ?? 0); i++) {
|
||||
final _asset = data.data?[i];
|
||||
tableData.add([
|
||||
// Asset
|
||||
_asset?.name ?? '',
|
||||
formatPointNumber(_asset?.amount ?? 0, addComma: true),
|
||||
]);
|
||||
}
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: ["Assets", "Amout"],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(5),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.centerLeft,
|
||||
1: pw.Alignment.centerRight,
|
||||
},
|
||||
),
|
||||
|
||||
// Totals row (styled to match)
|
||||
pw.Table.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(5),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.centerLeft,
|
||||
1: pw.Alignment.centerRight,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
"Total",
|
||||
formatPointNumber(data.totalAsset ?? 0, addComma: true),
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-loss-profit-report.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Loss Profit Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
227
lib/pdf_report/transactions/cashflow_report_pdf.dart
Normal file
227
lib/pdf_report/transactions/cashflow_report_pdf.dart
Normal file
@@ -0,0 +1,227 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:mobile_pos/Screens/Report/Screens/cashflow_screen.dart';
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../model/business_info_model.dart';
|
||||
import '../../model/cashflow_model.dart' as cf;
|
||||
|
||||
Future<void> generateCashflowReportPdf(BuildContext context, cf.CashflowModel data, BusinessInformationModel? business,
|
||||
DateTime? fromDate, DateTime? toDate) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
num initialRunningCash = data.initialRunningCash ?? 0;
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
'Cash Flow',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < (data.data?.length ?? 0); i++) {
|
||||
final _transaction = [...?data.data][i];
|
||||
final _runningCash = _transaction.type == 'credit'
|
||||
? initialRunningCash + (_transaction.amount ?? 0)
|
||||
: initialRunningCash - (_transaction.amount ?? 0);
|
||||
|
||||
tableData.add(
|
||||
[
|
||||
"${i + 1}",
|
||||
_transaction.date == null ? "N/A" : intl.DateFormat("dd MMM, yyyy").format(_transaction.date!),
|
||||
_transaction.invoiceNo ?? "N/A",
|
||||
_transaction.partyName ?? "N/A",
|
||||
_transaction.type?.toTitleCase() ?? "N/A",
|
||||
_transaction.type == "credit" ? formatPointNumber(_transaction.amount ?? 0) : "0",
|
||||
_transaction.type == "debit" ? formatPointNumber(_transaction.amount ?? 0) : "0",
|
||||
formatPointNumber(initialRunningCash = _runningCash),
|
||||
_transaction.paymentType ?? _transaction.transactionType?.split('_')[0].toTitleCase() ?? "N/A",
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: [
|
||||
"SL.",
|
||||
"Date",
|
||||
"Invoice",
|
||||
"Name",
|
||||
"Type",
|
||||
"Cash In",
|
||||
"Cash Out",
|
||||
"Running Cash",
|
||||
"Payment",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(2),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(4),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(3),
|
||||
6: const pw.FlexColumnWidth(3),
|
||||
7: const pw.FlexColumnWidth(3),
|
||||
8: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
7: pw.Alignment.center,
|
||||
8: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
// Totals row (styled to match)
|
||||
pw.Table.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(4),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(4),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(3),
|
||||
6: const pw.FlexColumnWidth(3),
|
||||
7: const pw.FlexColumnWidth(3),
|
||||
8: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
7: pw.Alignment.center,
|
||||
8: pw.Alignment.center,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
'Total',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
formatPointNumber(data.cashIn ?? 0),
|
||||
formatPointNumber(data.cashOut ?? 0),
|
||||
formatPointNumber(initialRunningCash),
|
||||
'',
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-customer-ledger.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Sales Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
212
lib/pdf_report/transactions/daybook_report_pdf.dart
Normal file
212
lib/pdf_report/transactions/daybook_report_pdf.dart
Normal file
@@ -0,0 +1,212 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../Screens/all_transaction/model/transaction_model.dart' as tmodel;
|
||||
import '../../model/business_info_model.dart';
|
||||
|
||||
Future<void> generateDayBookReportPdf(BuildContext context, tmodel.TransactionModel data,
|
||||
BusinessInformationModel? business, DateTime? fromDate, DateTime? toDate) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
num getMoneyIn(tmodel.TransactionModelData t) {
|
||||
return t.type == 'credit' ? (t.amount ?? 0) : 0;
|
||||
}
|
||||
|
||||
num getMoneyOut(tmodel.TransactionModelData t) {
|
||||
return t.type == 'debit' ? (t.amount ?? 0) : 0;
|
||||
}
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
'Day Book Report',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < (data.data?.length ?? 0); i++) {
|
||||
final _transaction = [...?data.data][i];
|
||||
tableData.add([
|
||||
_transaction.referenceId?.toString() ?? "",
|
||||
_transaction.party?.name ?? "",
|
||||
_transaction.date ?? "",
|
||||
_transaction.type ?? "",
|
||||
formatPointNumber(_transaction.totalAmount ?? 0, addComma: true),
|
||||
formatPointNumber(getMoneyIn(_transaction), addComma: true),
|
||||
formatPointNumber(getMoneyOut(_transaction), addComma: true),
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: [
|
||||
"Reference",
|
||||
"Name",
|
||||
"Date",
|
||||
"Type",
|
||||
"Total",
|
||||
"Money In",
|
||||
"Money Out",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(4),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(4),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(4),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
6: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
// Totals row (styled to match)
|
||||
pw.Table.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(4),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(4),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(4),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
6: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
'Total',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
formatPointNumber(data.totalAmount ?? 0),
|
||||
formatPointNumber(data.moneyIn ?? 0),
|
||||
formatPointNumber(data.moneyOut ?? 0),
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-customer-ledger.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Sales Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../model/business_info_model.dart';
|
||||
import '../../model/product_history_model.dart' as phlm;
|
||||
|
||||
Future<void> generateProductWisePurchaseHistoryDetailsReportPdf(
|
||||
BuildContext context,
|
||||
phlm.ProductHistoryDetailsModel data,
|
||||
BusinessInformationModel? business,
|
||||
DateTime? fromDate,
|
||||
DateTime? toDate,
|
||||
) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
data.productName ?? "N/A",
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
fromDate != null
|
||||
? 'Duration: ${intl.DateFormat('dd-MM-yyyy').format(fromDate)} to ${intl.DateFormat('dd-MM-yyyy').format(toDate!)}'
|
||||
: '',
|
||||
style: pw.TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final _transactions = [...?data.items];
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < (data.items?.length ?? 0); i++) {
|
||||
final _transaction = _transactions[i];
|
||||
tableData.add(
|
||||
[
|
||||
"${i + 1}",
|
||||
_transaction.invoiceNo ?? "N/A",
|
||||
_transaction.transactionDate != null
|
||||
? intl.DateFormat('dd-MM-yyyy').format(_transaction.transactionDate!)
|
||||
: "N/A",
|
||||
_transaction.type ?? "N/A",
|
||||
formatPointNumber(_transaction.quantities ?? 0),
|
||||
formatPointNumber(_transaction.purchasePrice ?? 0, addComma: true),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.TableHelper.fromTextArray(
|
||||
headers: [
|
||||
"SL",
|
||||
"Invoice",
|
||||
"Date",
|
||||
"Type",
|
||||
"Qty",
|
||||
"Cost Price",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.5),
|
||||
1: const pw.FlexColumnWidth(3),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(4),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
// Totals row (styled to match)
|
||||
pw.TableHelper.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.5),
|
||||
1: const pw.FlexColumnWidth(3),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(4),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
'',
|
||||
'Total',
|
||||
'',
|
||||
'',
|
||||
formatPointNumber(data.totalQuantities ?? 0),
|
||||
formatPointNumber(data.totalPurchasePrice ?? 0, addComma: true),
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-customer-ledger.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Sales Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../model/business_info_model.dart';
|
||||
import '../../model/product_history_model.dart' as phlm;
|
||||
|
||||
Future<void> generateProductWisePurchaseHistoryReportPdf(
|
||||
BuildContext context,
|
||||
phlm.ProductHistoryListModel data,
|
||||
BusinessInformationModel? business,
|
||||
DateTime? fromDate,
|
||||
DateTime? toDate,
|
||||
) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
'Product Purchase History',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
fromDate != null
|
||||
? 'Duration: ${intl.DateFormat('dd-MM-yyyy').format(fromDate)} to ${intl.DateFormat('dd-MM-yyyy').format(toDate!)}'
|
||||
: '',
|
||||
style: pw.TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final _transactions = [...?data.items];
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < (data.items?.length ?? 0); i++) {
|
||||
final _transaction = _transactions[i];
|
||||
tableData.add(
|
||||
[
|
||||
"${i + 1}",
|
||||
_transaction.name ?? "N/A",
|
||||
formatPointNumber(_transaction.purchasePrice ?? 0, addComma: true),
|
||||
formatPointNumber(_transaction.purchaseQuantity ?? 0),
|
||||
formatPointNumber(_transaction.saleQuantity ?? 0),
|
||||
formatPointNumber(_transaction.remainingQuantity ?? 0),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: [
|
||||
"SL",
|
||||
"Name",
|
||||
"Cost Price",
|
||||
"Purchase Qty",
|
||||
"Sold Qty",
|
||||
"Remaining Qty",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.5),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(4),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
// Totals row (styled to match)
|
||||
pw.Table.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.5),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(4),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
'',
|
||||
'Total',
|
||||
formatPointNumber(data.totalSalePrice, addComma: true),
|
||||
formatPointNumber(data.totalPurchaseQuantity ?? 0),
|
||||
formatPointNumber(data.totalSaleQuantity ?? 0),
|
||||
formatPointNumber(data.totalRemainingQuantity),
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-customer-ledger.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Sales Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../model/business_info_model.dart';
|
||||
import '../../model/product_history_model.dart' as phlm;
|
||||
|
||||
Future<void> generateProductWiseSaleHistoryDetailsReportPdf(
|
||||
BuildContext context,
|
||||
phlm.ProductHistoryDetailsModel data,
|
||||
BusinessInformationModel? business,
|
||||
DateTime? fromDate,
|
||||
DateTime? toDate,
|
||||
) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
data.productName ?? "N/A",
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
fromDate != null
|
||||
? 'Duration: ${intl.DateFormat('dd-MM-yyyy').format(fromDate)} to ${intl.DateFormat('dd-MM-yyyy').format(toDate!)}'
|
||||
: '',
|
||||
style: pw.TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final _transactions = [...?data.items];
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < (data.items?.length ?? 0); i++) {
|
||||
final _transaction = _transactions[i];
|
||||
tableData.add(
|
||||
[
|
||||
"${i + 1}",
|
||||
_transaction.invoiceNo ?? "N/A",
|
||||
_transaction.transactionDate != null
|
||||
? intl.DateFormat('dd-MM-yyyy').format(_transaction.transactionDate!)
|
||||
: "N/A",
|
||||
formatPointNumber(_transaction.quantities ?? 0),
|
||||
formatPointNumber(_transaction.purchasePrice ?? 0, addComma: true),
|
||||
formatPointNumber(_transaction.salePrice ?? 0, addComma: true),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: [
|
||||
"SL",
|
||||
"Invoice",
|
||||
"Date",
|
||||
"Qty",
|
||||
"Cost Price",
|
||||
"Sales Price",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.5),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
// Totals row (styled to match)
|
||||
pw.Table.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.5),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
'',
|
||||
'Total',
|
||||
'',
|
||||
formatPointNumber(data.totalQuantities ?? 0),
|
||||
formatPointNumber(data.totalPurchasePrice ?? 0, addComma: true),
|
||||
formatPointNumber(data.totalSalePrice ?? 0, addComma: true),
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-customer-ledger.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Sales Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../model/business_info_model.dart';
|
||||
import '../../model/product_history_model.dart' as phlm;
|
||||
|
||||
Future<void> generateProductWiseSaleHistoryReportPdf(
|
||||
BuildContext context,
|
||||
phlm.ProductHistoryListModel data,
|
||||
BusinessInformationModel? business,
|
||||
DateTime? fromDate,
|
||||
DateTime? toDate,
|
||||
) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
'Product Sale History',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
fromDate != null
|
||||
? 'Duration: ${intl.DateFormat('dd-MM-yyyy').format(fromDate)} to ${intl.DateFormat('dd-MM-yyyy').format(toDate!)}'
|
||||
: '',
|
||||
style: pw.TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final _transactions = [...?data.items];
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < (data.items?.length ?? 0); i++) {
|
||||
final _transaction = _transactions[i];
|
||||
tableData.add(
|
||||
[
|
||||
"${i + 1}",
|
||||
_transaction.name ?? "N/A",
|
||||
formatPointNumber(_transaction.salePrice ?? 0, addComma: true),
|
||||
formatPointNumber(_transaction.purchaseQuantity ?? 0),
|
||||
formatPointNumber(_transaction.saleQuantity ?? 0),
|
||||
formatPointNumber(_transaction.remainingQuantity ?? 0),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: [
|
||||
"SL",
|
||||
"Name",
|
||||
"Sales Price",
|
||||
"Purchase Qty",
|
||||
"Sold Qty",
|
||||
"Remaining Qty",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.5),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
// Totals row (styled to match)
|
||||
pw.Table.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.5),
|
||||
1: const pw.FlexColumnWidth(5),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
'',
|
||||
'Total',
|
||||
formatPointNumber(data.totalSalePrice, addComma: true),
|
||||
formatPointNumber(data.totalPurchaseQuantity ?? 0),
|
||||
formatPointNumber(data.totalSaleQuantity ?? 0),
|
||||
formatPointNumber(data.totalRemainingQuantity),
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-customer-ledger.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Sales Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
171
lib/pdf_report/transactions/subscription_report_pdf.dart
Normal file
171
lib/pdf_report/transactions/subscription_report_pdf.dart
Normal file
@@ -0,0 +1,171 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
|
||||
import '../../model/subscription_report_model.dart' as model;
|
||||
import '../../model/business_info_model.dart';
|
||||
|
||||
Future<void> generateSubscriptionReportPdf(BuildContext context, List<model.SubscriptionReportModel> data,
|
||||
BusinessInformationModel? business, DateTime? fromDate, DateTime? toDate) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
final interFont = await PdfGoogleFonts.notoSansRegular();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
'Subscription Reports',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
fromDate != null
|
||||
? 'Duration: ${DateFormat('dd-MM-yyyy').format(fromDate)} to ${DateFormat('dd-MM-yyyy').format(toDate!)}'
|
||||
: '',
|
||||
style: pw.TextStyle(
|
||||
font: interFont,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
final _subscription = data[i];
|
||||
tableData.add([
|
||||
"${i + 1}",
|
||||
_subscription.startDate == null ? "N/A" : DateFormat('dd MMM yyyy').format(_subscription.startDate!),
|
||||
_subscription.name ?? "N/A",
|
||||
_subscription.startDate == null ? "N/A" : DateFormat('dd MMM yyyy').format(_subscription.startDate!),
|
||||
_subscription.startDate == null ? "N/A" : DateFormat('dd MMM yyyy').format(_subscription.startDate!),
|
||||
_subscription.paymentBy ?? "N/A",
|
||||
_subscription.isPaid ? "Paid" : "Unpaid",
|
||||
]);
|
||||
}
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: [
|
||||
"SL",
|
||||
"Date",
|
||||
"Package",
|
||||
"Started",
|
||||
"End",
|
||||
"Payment By",
|
||||
"Status",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(2),
|
||||
1: const pw.FlexColumnWidth(4),
|
||||
2: const pw.FlexColumnWidth(4),
|
||||
3: const pw.FlexColumnWidth(4),
|
||||
4: const pw.FlexColumnWidth(4),
|
||||
5: const pw.FlexColumnWidth(4),
|
||||
6: const pw.FlexColumnWidth(4),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-loss-profit-report.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Loss Profit Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
232
lib/pdf_report/transactions/tax_report_pdf.dart
Normal file
232
lib/pdf_report/transactions/tax_report_pdf.dart
Normal file
@@ -0,0 +1,232 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:printing/printing.dart';
|
||||
import '../../model/business_info_model.dart';
|
||||
import '../../model/tax_report_model.dart' as trm;
|
||||
|
||||
Future<void> generateTaxReportPdf(
|
||||
BuildContext context,
|
||||
trm.TaxReportModel data,
|
||||
BusinessInformationModel? business,
|
||||
DateTime? fromDate,
|
||||
DateTime? toDate, {
|
||||
bool isPurchase = false,
|
||||
}) async {
|
||||
final pw.Document pdf = pw.Document();
|
||||
|
||||
// Show loading indicator
|
||||
EasyLoading.show(status: 'Generating PDF');
|
||||
|
||||
final _transactions = [...?(isPurchase ? data.purchases : data.sales)];
|
||||
final _overview = isPurchase ? data.overviews?.firstOrNull : data.overviews?.lastOrNull;
|
||||
|
||||
try {
|
||||
pdf.addPage(
|
||||
pw.MultiPage(
|
||||
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||||
margin: pw.EdgeInsets.symmetric(horizontal: 16),
|
||||
//----------------pdf header--------------
|
||||
header: (pw.Context context) {
|
||||
return pw.Center(
|
||||
child: pw.Column(
|
||||
crossAxisAlignment: pw.CrossAxisAlignment.center,
|
||||
children: [
|
||||
pw.Text(
|
||||
business?.data?.companyName.toString() ?? '',
|
||||
style: pw.TextStyle(
|
||||
// font: interFont,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
pw.Text(
|
||||
// 'বিক্রয় প্রতিবেদন',
|
||||
'Tax Report (${isPurchase ? 'Purchase' : 'Sales'})',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
// font: ttf,
|
||||
),
|
||||
),
|
||||
pw.SizedBox(height: 4),
|
||||
pw.Text(
|
||||
fromDate != null
|
||||
? 'Duration: ${intl.DateFormat('dd-MM-yyyy').format(fromDate)} to ${intl.DateFormat('dd-MM-yyyy').format(toDate!)}'
|
||||
: '',
|
||||
style: pw.TextStyle(
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
//-----------------pdf footer-------------
|
||||
footer: (pw.Context context) {
|
||||
return pw.Row(
|
||||
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
pw.Text('${business?.data?.developByLevel ?? ''} ${business?.data?.developBy ?? ''}'),
|
||||
pw.Text('Page-${context.pageNumber}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
build: (pw.Context context) {
|
||||
final List<List<String>> tableData = [];
|
||||
|
||||
for (int i = 0; i < _transactions.length; i++) {
|
||||
final _transaction = _transactions[i];
|
||||
tableData.add([
|
||||
"${i + 1}",
|
||||
_transaction.invoiceNumber ?? "N/A",
|
||||
_transaction.transactionDate == null
|
||||
? "N/A"
|
||||
: intl.DateFormat("dd MMM, yyyy").format(_transaction.transactionDate!),
|
||||
_transaction.partyName ?? "N/A",
|
||||
_transaction.amount.toString(),
|
||||
_transaction.discountAmount.toString(),
|
||||
_transaction.vatName ?? "",
|
||||
_transaction.vatAmount.toString(),
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
pw.SizedBox(height: 16),
|
||||
|
||||
// Main Table
|
||||
pw.Table.fromTextArray(
|
||||
headers: [
|
||||
"SL",
|
||||
"Invoice",
|
||||
"Date",
|
||||
"Name",
|
||||
"Amount",
|
||||
"Discount",
|
||||
"Vat",
|
||||
"Vat Value",
|
||||
],
|
||||
data: tableData,
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
border: pw.TableBorder.all(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
rowDecoration: const pw.BoxDecoration(
|
||||
color: PdfColors.white,
|
||||
),
|
||||
oddRowDecoration: pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffF7F7F7),
|
||||
),
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(1.75),
|
||||
1: const pw.FlexColumnWidth(2),
|
||||
2: const pw.FlexColumnWidth(3),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(3),
|
||||
6: const pw.FlexColumnWidth(3),
|
||||
7: const pw.FlexColumnWidth(2),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
7: pw.Alignment.center,
|
||||
},
|
||||
),
|
||||
// Totals row (styled to match)
|
||||
pw.Table.fromTextArray(
|
||||
border: const pw.TableBorder(
|
||||
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||||
),
|
||||
columnWidths: <int, pw.TableColumnWidth>{
|
||||
0: const pw.FlexColumnWidth(3),
|
||||
1: const pw.FlexColumnWidth(2),
|
||||
2: const pw.FlexColumnWidth(2),
|
||||
3: const pw.FlexColumnWidth(3),
|
||||
4: const pw.FlexColumnWidth(3),
|
||||
5: const pw.FlexColumnWidth(3),
|
||||
6: const pw.FlexColumnWidth(3),
|
||||
7: const pw.FlexColumnWidth(2),
|
||||
},
|
||||
cellAlignments: {
|
||||
0: pw.Alignment.center,
|
||||
1: pw.Alignment.center,
|
||||
2: pw.Alignment.center,
|
||||
3: pw.Alignment.center,
|
||||
4: pw.Alignment.center,
|
||||
5: pw.Alignment.center,
|
||||
6: pw.Alignment.center,
|
||||
7: pw.Alignment.center,
|
||||
},
|
||||
data: [
|
||||
[
|
||||
"Total",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
formatPointNumber(_overview?.totalAmount ?? 0, addComma: true),
|
||||
formatPointNumber(_overview?.totalDiscount ?? 0, addComma: true),
|
||||
"",
|
||||
formatPointNumber(_overview?.totalDiscount ?? 0, addComma: true),
|
||||
]
|
||||
],
|
||||
headerDecoration: const pw.BoxDecoration(
|
||||
color: PdfColor.fromInt(0xffC52127),
|
||||
),
|
||||
headerStyle: pw.TextStyle(
|
||||
fontWeight: pw.FontWeight.bold,
|
||||
color: PdfColors.white,
|
||||
),
|
||||
cellAlignment: pw.Alignment.center,
|
||||
cellPadding: const pw.EdgeInsets.all(8),
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
final byteData = await pdf.save();
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$appsName-customer-ledger.pdf');
|
||||
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
|
||||
EasyLoading.showSuccess('Generate Complete');
|
||||
//print pdf
|
||||
if (context.mounted) {
|
||||
await Printing.layoutPdf(
|
||||
name: 'Sales Report',
|
||||
usePrinterSettings: true,
|
||||
dynamicLayout: true,
|
||||
forceCustomPrintPaper: true,
|
||||
onLayout: (PdfPageFormat format) async => pdf.save(),
|
||||
);
|
||||
}
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) => PDFViewerPage(path: file.path),
|
||||
// ),
|
||||
// );
|
||||
} catch (e) {
|
||||
EasyLoading.showError('Error: $e');
|
||||
print('Error during PDF generation: $e');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user