1009 lines
47 KiB
Dart
1009 lines
47 KiB
Dart
|
|
import 'dart:async';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:flutter/services.dart';
|
||
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
|
|
import 'package:intl/intl.dart';
|
||
|
|
import 'package:mobile_pos/Const/api_config.dart';
|
||
|
|
import 'package:mobile_pos/PDF%20Invoice/universal_image_widget.dart';
|
||
|
|
import 'package:mobile_pos/constant.dart';
|
||
|
|
import 'package:mobile_pos/generated/l10n.dart' as l;
|
||
|
|
import 'package:nb_utils/nb_utils.dart';
|
||
|
|
import 'package:pdf/pdf.dart';
|
||
|
|
import 'package:pdf/widgets.dart' as pw;
|
||
|
|
import 'package:printing/printing.dart';
|
||
|
|
|
||
|
|
import '../Screens/Due Calculation/Model/due_collection_model.dart';
|
||
|
|
import '../model/business_info_model.dart';
|
||
|
|
import 'pdf_common_functions.dart';
|
||
|
|
|
||
|
|
class DueInvoicePDF {
|
||
|
|
static Future<void> generateDueDocument(
|
||
|
|
DueCollection transactions,
|
||
|
|
BusinessInformationModel personalInformation,
|
||
|
|
BuildContext context, {
|
||
|
|
bool? isShare,
|
||
|
|
bool? download,
|
||
|
|
bool? showPreview,
|
||
|
|
}) async {
|
||
|
|
final pw.Document doc = pw.Document();
|
||
|
|
final _lang = l.S.of(context);
|
||
|
|
// Load the image as bytes
|
||
|
|
EasyLoading.show(status: _lang.generatingPdf);
|
||
|
|
|
||
|
|
final String imageUrl =
|
||
|
|
'${APIConfig.domain}${(personalInformation.data?.showA4InvoiceLogo == 1) ? personalInformation.data?.a4InvoiceLogo : ''}';
|
||
|
|
dynamic imageData = await PDFCommonFunctions().getNetworkImage(imageUrl);
|
||
|
|
imageData ??= (personalInformation.data?.showA4InvoiceLogo == 1)
|
||
|
|
? await PDFCommonFunctions().loadAssetImage('images/logo.png')
|
||
|
|
: null;
|
||
|
|
final englishFont = pw.Font.ttf(await rootBundle.load('fonts/NotoSans/NotoSans-Regular.ttf'));
|
||
|
|
final englishBold = pw.Font.ttf(await rootBundle.load('fonts/NotoSans/NotoSans-Medium.ttf'));
|
||
|
|
final banglaFont = pw.Font.ttf(await rootBundle.load('assets/fonts/siyam_rupali_ansi.ttf'));
|
||
|
|
final arabicFont = pw.Font.ttf(await rootBundle.load('assets/fonts/Amiri-Regular.ttf'));
|
||
|
|
final hindiFont = pw.Font.ttf(await rootBundle.load('assets/fonts/Hind-Regular.ttf'));
|
||
|
|
final frenchFont = pw.Font.ttf(await rootBundle.load('assets/fonts/GFSDidot-Regular.ttf'));
|
||
|
|
|
||
|
|
// Helper function
|
||
|
|
pw.Font getFont({bool bold = false}) {
|
||
|
|
switch (selectedLanguage) {
|
||
|
|
case 'en':
|
||
|
|
return bold ? englishBold : englishFont;
|
||
|
|
case 'bn':
|
||
|
|
// Bold not available, fallback to regular
|
||
|
|
return banglaFont;
|
||
|
|
case 'ar':
|
||
|
|
return arabicFont;
|
||
|
|
case 'hi':
|
||
|
|
return hindiFont;
|
||
|
|
case 'fr':
|
||
|
|
return frenchFont;
|
||
|
|
default:
|
||
|
|
return bold ? englishBold : englishFont;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
getFontWithLangMatching(String data) {
|
||
|
|
String detectedLanguage = detectLanguageEnhanced(data);
|
||
|
|
if (detectedLanguage == 'en') {
|
||
|
|
return englishFont;
|
||
|
|
} else if (detectedLanguage == 'bn') {
|
||
|
|
return banglaFont;
|
||
|
|
} else if (detectedLanguage == 'ar') {
|
||
|
|
return arabicFont;
|
||
|
|
} else if (detectedLanguage == 'hi') {
|
||
|
|
return hindiFont;
|
||
|
|
} else if (detectedLanguage == 'fr') {
|
||
|
|
return frenchFont;
|
||
|
|
} else {
|
||
|
|
return englishFont;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
final bankTransactions =
|
||
|
|
transactions.transactions?.where((t) => t.transactionType == 'bank_payment').toList() ?? [];
|
||
|
|
|
||
|
|
final latestBankTransaction = bankTransactions.isNotEmpty ? bankTransactions.last : null;
|
||
|
|
|
||
|
|
final showWarranty = personalInformation.data?.showWarranty == 1 &&
|
||
|
|
(personalInformation.data?.warrantyVoidLabel != null || personalInformation.data?.warrantyVoid != null);
|
||
|
|
|
||
|
|
doc.addPage(
|
||
|
|
pw.MultiPage(
|
||
|
|
pageFormat: PdfPageFormat.letter.copyWith(marginBottom: 1.5 * PdfPageFormat.cm),
|
||
|
|
margin: pw.EdgeInsets.zero,
|
||
|
|
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||
|
|
header: (pw.Context context) {
|
||
|
|
return pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(20.0),
|
||
|
|
child: pw.Column(
|
||
|
|
children: [
|
||
|
|
pw.Row(
|
||
|
|
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||
|
|
children: [
|
||
|
|
pw.Container(
|
||
|
|
height: 54.12,
|
||
|
|
width: 200,
|
||
|
|
child: universalImage(
|
||
|
|
imageData,
|
||
|
|
w: 200,
|
||
|
|
h: 54.12,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Column(
|
||
|
|
crossAxisAlignment: pw.CrossAxisAlignment.end,
|
||
|
|
children: [
|
||
|
|
if (personalInformation.data?.meta?.showAddress == 1)
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 200,
|
||
|
|
child: pw.Text(
|
||
|
|
'${_lang.address}: ${personalInformation.data?.address ?? ''}',
|
||
|
|
textAlign: pw.TextAlign.end,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
if (personalInformation.data?.meta?.showPhoneNumber == 1)
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 200,
|
||
|
|
child: pw.Text(
|
||
|
|
'${_lang.mobile}: ${personalInformation.data?.phoneNumber ?? ''}',
|
||
|
|
textAlign: pw.TextAlign.end,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
if (personalInformation.data?.meta?.showEmail == 1)
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 200,
|
||
|
|
child: pw.Text(
|
||
|
|
'${_lang.emailText}: ${personalInformation.data?.invoiceEmail ?? ''}',
|
||
|
|
textAlign: pw.TextAlign.end,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
//vat Name
|
||
|
|
if (personalInformation.data?.meta?.showVat == 1)
|
||
|
|
if (personalInformation.data?.vatNo != null && personalInformation.data?.meta?.showVat == 1)
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 200,
|
||
|
|
child: pw.Text(
|
||
|
|
'${personalInformation.data?.vatName ?? _lang.vatNumber}: ${personalInformation.data?.vatNo ?? ''}',
|
||
|
|
textAlign: pw.TextAlign.end,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 16.0),
|
||
|
|
pw.Center(
|
||
|
|
child: pw.Container(
|
||
|
|
padding: pw.EdgeInsets.symmetric(horizontal: 19, vertical: 10),
|
||
|
|
decoration: pw.BoxDecoration(
|
||
|
|
borderRadius: pw.BorderRadius.circular(20),
|
||
|
|
border: pw.Border.all(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
child: pw.Text(
|
||
|
|
_lang.INVOICE,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
fontSize: 18,
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(bold: true),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 20),
|
||
|
|
pw.Row(
|
||
|
|
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||
|
|
children: [
|
||
|
|
pw.Column(
|
||
|
|
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||
|
|
children: [
|
||
|
|
//customer name
|
||
|
|
if (personalInformation.data?.meta?.showCompanyName == 1)
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 60.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.customer,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 10.0,
|
||
|
|
child: pw.Text(
|
||
|
|
':',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 100.0,
|
||
|
|
child: getLocalizedPdfTextWithLanguage(
|
||
|
|
transactions.party?.name ?? '',
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFontWithLangMatching(transactions.party?.name ?? ''),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
//Address
|
||
|
|
if (personalInformation.data?.meta?.showAddress == 1)
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 60.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.address,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 10.0,
|
||
|
|
child: pw.Text(
|
||
|
|
':',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 150.0,
|
||
|
|
child: getLocalizedPdfTextWithLanguage(
|
||
|
|
transactions.party?.address ?? 'N/a',
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFontWithLangMatching(transactions.party?.address ?? ''),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
//mobile
|
||
|
|
if (personalInformation.data?.meta?.showPhoneNumber == 1)
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 60.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.mobile,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 10.0,
|
||
|
|
child: pw.Text(
|
||
|
|
':',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 100.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
transactions.party?.phone ?? (transactions.party?.phone ?? _lang.guest),
|
||
|
|
pw.TextStyle(font: getFont(), fontFallback: [englishFont]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
//Remarks
|
||
|
|
if (personalInformation.data?.showNote == 1)
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 60.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.remark,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 10.0,
|
||
|
|
child: pw.Text(
|
||
|
|
':',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 100.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
personalInformation.data?.invoiceNote ?? 'N/A',
|
||
|
|
pw.TextStyle(font: getFont(), fontFallback: [englishFont]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.Column(
|
||
|
|
children: [
|
||
|
|
//Invoice Number
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 100.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.invoiceNumber,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 10.0,
|
||
|
|
child: pw.Text(
|
||
|
|
':',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 75.0,
|
||
|
|
child: pw.Text(
|
||
|
|
'#${transactions.invoiceNumber}',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
//date
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 100.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.date,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 10.0,
|
||
|
|
child: pw.Text(
|
||
|
|
':',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 75.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
DateFormat('d MMM, yyyy').format(DateTime.parse(transactions.paymentDate ?? '')),
|
||
|
|
// DateTimeFormat.format(DateTime.parse(transactions.saleDate ?? ''), format: 'D, M j'),
|
||
|
|
pw.TextStyle(font: getFont(), fontFallback: [englishFont]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
//Time
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 100.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.time,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 10.0,
|
||
|
|
child: pw.Text(
|
||
|
|
':',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 75.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
DateFormat('hh:mm a').format(DateTime.parse(transactions.paymentDate!)),
|
||
|
|
pw.TextStyle(font: getFont(), fontFallback: [englishFont]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
//Sales by
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 100.0,
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.collectedBy,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 10.0,
|
||
|
|
child: pw.Text(
|
||
|
|
':',
|
||
|
|
style: pw.Theme.of(context).defaultTextStyle.copyWith(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 75.0,
|
||
|
|
child: getLocalizedPdfTextWithLanguage(
|
||
|
|
transactions.user?.role == "shop-owner" ? _lang.admin : transactions.user?.name ?? '',
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFontWithLangMatching(
|
||
|
|
transactions.user?.role == "shop-owner"
|
||
|
|
? _lang.admin
|
||
|
|
: transactions.user?.name ?? '',
|
||
|
|
),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
footer: (pw.Context context) {
|
||
|
|
return pw.Column(
|
||
|
|
children: [
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(10.0),
|
||
|
|
child: pw.Column(children: [
|
||
|
|
pw.Row(
|
||
|
|
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||
|
|
children: [
|
||
|
|
pw.Container(
|
||
|
|
alignment: pw.Alignment.centerRight,
|
||
|
|
margin: const pw.EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
|
||
|
|
padding: const pw.EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
|
||
|
|
child: pw.Column(
|
||
|
|
children: [
|
||
|
|
pw.Container(
|
||
|
|
width: 120.0,
|
||
|
|
height: 2.0,
|
||
|
|
color: PdfColors.black,
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 4.0),
|
||
|
|
getLocalizedPdfText(
|
||
|
|
_lang.customerSignature,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Container(
|
||
|
|
alignment: pw.Alignment.centerRight,
|
||
|
|
margin: const pw.EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
|
||
|
|
padding: const pw.EdgeInsets.only(bottom: 3.0 * PdfPageFormat.mm),
|
||
|
|
child: pw.Column(
|
||
|
|
children: [
|
||
|
|
pw.Container(
|
||
|
|
width: 120.0,
|
||
|
|
height: 2.0,
|
||
|
|
color: PdfColors.black,
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 4.0),
|
||
|
|
getLocalizedPdfText(
|
||
|
|
_lang.authorizedSignature,
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 8.5),
|
||
|
|
if (showWarranty)
|
||
|
|
pw.Container(
|
||
|
|
width: double.infinity,
|
||
|
|
padding: const pw.EdgeInsets.all(4),
|
||
|
|
decoration: pw.BoxDecoration(
|
||
|
|
border: pw.Border.all(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
child: pw.RichText(
|
||
|
|
text: pw.TextSpan(
|
||
|
|
children: [
|
||
|
|
if (personalInformation.data?.warrantyVoidLabel != null)
|
||
|
|
pw.TextSpan(
|
||
|
|
text: '${personalInformation.data!.warrantyVoidLabel!}- ',
|
||
|
|
style: pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
if (personalInformation.data?.warrantyVoid != null)
|
||
|
|
pw.TextSpan(
|
||
|
|
text: personalInformation.data!.warrantyVoid!,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
]),
|
||
|
|
),
|
||
|
|
// if (!personalInformation.data!.gratitudeMessage.isEmptyOrNull)
|
||
|
|
// pw.Container(
|
||
|
|
// width: double.infinity,
|
||
|
|
// padding: const pw.EdgeInsets.only(bottom: 8.0),
|
||
|
|
// child: pw.Center(
|
||
|
|
// child: pw.Text(
|
||
|
|
// personalInformation.data!.gratitudeMessage ?? '',
|
||
|
|
// )),
|
||
|
|
// ),
|
||
|
|
pw.SizedBox(height: 8.5),
|
||
|
|
pw.Padding(
|
||
|
|
padding: pw.EdgeInsets.symmetric(horizontal: 10),
|
||
|
|
child: pw.Center(
|
||
|
|
child: pw.Text(
|
||
|
|
'${personalInformation.data?.developByLevel ?? ''} ${personalInformation.data?.developBy ?? ''}',
|
||
|
|
style: pw.TextStyle(fontWeight: pw.FontWeight.bold),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
},
|
||
|
|
build: (pw.Context context) => <pw.Widget>[
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.only(left: 20.0, right: 20.0, bottom: 20.0),
|
||
|
|
child: pw.Column(
|
||
|
|
children: [
|
||
|
|
pw.Table(
|
||
|
|
columnWidths: <int, pw.TableColumnWidth>{
|
||
|
|
0: const pw.FlexColumnWidth(1),
|
||
|
|
1: const pw.FlexColumnWidth(3),
|
||
|
|
2: const pw.FlexColumnWidth(3),
|
||
|
|
3: const pw.FlexColumnWidth(3),
|
||
|
|
},
|
||
|
|
border: pw.TableBorder(
|
||
|
|
horizontalInside: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||
|
|
verticalInside: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||
|
|
left: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||
|
|
right: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||
|
|
top: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||
|
|
bottom: pw.BorderSide(color: PdfColor.fromInt(0xffD9D9D9)),
|
||
|
|
),
|
||
|
|
children: [
|
||
|
|
// pw.TableRow(
|
||
|
|
// children: [
|
||
|
|
// pw.Container(
|
||
|
|
// decoration: const pw.BoxDecoration(
|
||
|
|
// color: PdfColor.fromInt(0xffC52127),
|
||
|
|
// ), // Red background
|
||
|
|
// padding: const pw.EdgeInsets.all(8.0),
|
||
|
|
// child: getLocalizedPdfText(
|
||
|
|
// _lang.sl,
|
||
|
|
// pw.TextStyle(color: PdfColors.white, fontWeight: pw.FontWeight.bold, font: getFont(), fontFallback: [englishFont]),
|
||
|
|
// textAlignment: pw.TextAlign.left,
|
||
|
|
// ),
|
||
|
|
// ),
|
||
|
|
// pw.Container(
|
||
|
|
// color: const PdfColor.fromInt(0xffC52127), // Red background
|
||
|
|
// padding: const pw.EdgeInsets.all(8.0),
|
||
|
|
// child: getLocalizedPdfText(
|
||
|
|
// _lang.totalDue,
|
||
|
|
// pw.TextStyle(color: PdfColors.white, fontWeight: pw.FontWeight.bold, font: getFont(), fontFallback: [englishFont]),
|
||
|
|
// textAlignment: pw.TextAlign.left,
|
||
|
|
// ),
|
||
|
|
// ),
|
||
|
|
// pw.Container(
|
||
|
|
// color: const PdfColor.fromInt(0xff000000), // Black background
|
||
|
|
// padding: const pw.EdgeInsets.all(8.0),
|
||
|
|
// child: getLocalizedPdfText(
|
||
|
|
// _lang.paymentsAmount,
|
||
|
|
// pw.TextStyle(color: PdfColors.white, fontWeight: pw.FontWeight.bold, font: getFont(), fontFallback: [englishFont]),
|
||
|
|
// textAlignment: pw.TextAlign.left,
|
||
|
|
// ),
|
||
|
|
// ),
|
||
|
|
// pw.Container(
|
||
|
|
// color: const PdfColor.fromInt(0xff000000), // Black background
|
||
|
|
// padding: const pw.EdgeInsets.all(8.0),
|
||
|
|
// child: getLocalizedPdfText(
|
||
|
|
// _lang.remainingDue,
|
||
|
|
// pw.TextStyle(color: PdfColors.white, fontWeight: pw.FontWeight.bold, font: getFont(), fontFallback: [englishFont]),
|
||
|
|
// textAlignment: pw.TextAlign.left,
|
||
|
|
// ),
|
||
|
|
// ),
|
||
|
|
// ],
|
||
|
|
// ),
|
||
|
|
pw.TableRow(
|
||
|
|
children: [
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(8),
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.sl,
|
||
|
|
pw.TextStyle(
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
textAlignment: pw.TextAlign.center,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(8),
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.totalDue,
|
||
|
|
pw.TextStyle(
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
),
|
||
|
|
textAlignment: pw.TextAlign.left,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(8),
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.paymentsAmount,
|
||
|
|
pw.TextStyle(
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
),
|
||
|
|
textAlignment: pw.TextAlign.center,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(8),
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
_lang.remainingDue,
|
||
|
|
pw.TextStyle(
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
),
|
||
|
|
textAlignment: pw.TextAlign.right,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.TableRow(
|
||
|
|
children: [
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(8.0),
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
'1',
|
||
|
|
textAlignment: pw.TextAlign.left,
|
||
|
|
pw.TextStyle(font: getFont(), fontFallback: [englishFont]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(8.0),
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
"${transactions.totalDue}",
|
||
|
|
textAlignment: pw.TextAlign.center,
|
||
|
|
pw.TextStyle(font: getFont(), fontFallback: [englishFont]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(8.0),
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
(transactions.totalDue!.toDouble() - transactions.dueAmountAfterPay!.toDouble())
|
||
|
|
.toStringAsFixed(2),
|
||
|
|
textAlignment: pw.TextAlign.center,
|
||
|
|
pw.TextStyle(font: getFont(), fontFallback: [englishFont]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.all(8.0),
|
||
|
|
child: getLocalizedPdfText(
|
||
|
|
"${transactions.dueAmountAfterPay?.toStringAsFixed(2)}",
|
||
|
|
textAlignment: pw.TextAlign.right,
|
||
|
|
pw.TextStyle(font: getFont(), fontFallback: [englishFont]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.Row(
|
||
|
|
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
|
||
|
|
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||
|
|
children: [
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Column(
|
||
|
|
crossAxisAlignment: pw.CrossAxisAlignment.start,
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(height: 22),
|
||
|
|
// Amount in words
|
||
|
|
pw.SizedBox(
|
||
|
|
width: 350,
|
||
|
|
child: pw.Text(
|
||
|
|
PDFCommonFunctions().numberToWords(transactions.totalDue ?? 0),
|
||
|
|
style: pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
),
|
||
|
|
maxLines: 3,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 18),
|
||
|
|
// Paid via
|
||
|
|
pw.Wrap(
|
||
|
|
spacing: 6,
|
||
|
|
runSpacing: 4,
|
||
|
|
children: [
|
||
|
|
pw.Text('${_lang.paidVia} :'),
|
||
|
|
...?transactions.transactions?.asMap().entries.map((entry) {
|
||
|
|
final index = entry.key;
|
||
|
|
final item = entry.value;
|
||
|
|
|
||
|
|
String label;
|
||
|
|
switch (item.transactionType) {
|
||
|
|
case 'cash_payment':
|
||
|
|
label = 'Cash';
|
||
|
|
break;
|
||
|
|
case 'cheque_payment':
|
||
|
|
label = 'Cheque';
|
||
|
|
break;
|
||
|
|
case 'wallet_payment':
|
||
|
|
label = 'Wallet';
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
label = item.paymentType?.name ?? 'n/a';
|
||
|
|
}
|
||
|
|
|
||
|
|
final isLast = index == transactions.transactions!.length - 1;
|
||
|
|
final text = isLast ? label : '$label,';
|
||
|
|
|
||
|
|
return pw.Text(
|
||
|
|
text,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 12),
|
||
|
|
if ((!personalInformation.data!.invoiceNote.isEmptyOrNull ||
|
||
|
|
!personalInformation.data!.invoiceNoteLevel.isEmptyOrNull) &&
|
||
|
|
personalInformation.data!.showNote == 1)
|
||
|
|
pw.RichText(
|
||
|
|
text: pw.TextSpan(
|
||
|
|
text: '${personalInformation.data?.invoiceNoteLevel ?? ''}: ',
|
||
|
|
style: pw.TextStyle(
|
||
|
|
font: getFont(bold: true),
|
||
|
|
),
|
||
|
|
children: [
|
||
|
|
pw.TextSpan(
|
||
|
|
text: personalInformation.data?.invoiceNote ?? '',
|
||
|
|
style: pw.TextStyle(
|
||
|
|
font: getFont(bold: true),
|
||
|
|
))
|
||
|
|
])),
|
||
|
|
|
||
|
|
pw.SizedBox(height: 12),
|
||
|
|
|
||
|
|
// Bank details - FIXED: Check if transactions list is not empty
|
||
|
|
if (latestBankTransaction != null)
|
||
|
|
pw.Container(
|
||
|
|
width: 256,
|
||
|
|
height: 120,
|
||
|
|
decoration: pw.BoxDecoration(
|
||
|
|
border: pw.Border.all(color: PdfColors.black),
|
||
|
|
),
|
||
|
|
child: pw.Column(
|
||
|
|
children: [
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||
|
|
child: pw.Text(
|
||
|
|
_lang.bankDetails,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontSize: 12,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Divider(color: PdfColors.black, height: 1),
|
||
|
|
pw.Padding(
|
||
|
|
padding: const pw.EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||
|
|
child: pw.Column(
|
||
|
|
children: [
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Text(
|
||
|
|
_lang.name,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
font: getFont(),
|
||
|
|
fontSize: 12,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Text(': ${latestBankTransaction.paymentType?.name ?? ''}'),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 4),
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Text(
|
||
|
|
_lang.accountNumber,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
font: getFont(),
|
||
|
|
fontSize: 12,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Text(
|
||
|
|
': ${latestBankTransaction.paymentType?.paymentTypeMeta?.accountNumber ?? ''}',
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 4),
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Text(
|
||
|
|
_lang.ifscCode,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
font: getFont(),
|
||
|
|
fontSize: 12,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Text(
|
||
|
|
': ${latestBankTransaction.paymentType?.paymentTypeMeta?.ifscCode ?? ''}',
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 4),
|
||
|
|
pw.Row(
|
||
|
|
children: [
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Text(
|
||
|
|
_lang.holderName,
|
||
|
|
style: pw.TextStyle(
|
||
|
|
font: getFont(),
|
||
|
|
fontSize: 12,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.Expanded(
|
||
|
|
child: pw.Text(
|
||
|
|
': ${latestBankTransaction.paymentType?.paymentTypeMeta?.holderName ?? ''}',
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
|
||
|
|
// Right column - Amount calculation (ALWAYS shows)
|
||
|
|
pw.Column(
|
||
|
|
crossAxisAlignment: pw.CrossAxisAlignment.end,
|
||
|
|
children: [
|
||
|
|
pw.SizedBox(height: 10.0),
|
||
|
|
getLocalizedPdfText(
|
||
|
|
"${_lang.payableAmount}: ${transactions.totalDue?.toStringAsFixed(2) ?? 0}",
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 5.0),
|
||
|
|
getLocalizedPdfText(
|
||
|
|
"${_lang.receivedAmount} : ${(transactions.totalDue!.toDouble() - transactions.dueAmountAfterPay!.toDouble()).toStringAsFixed(2)}",
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 5.0),
|
||
|
|
getLocalizedPdfText(
|
||
|
|
"${_lang.dueAmount} : ${transactions.dueAmountAfterPay?.toStringAsFixed(2) ?? 0}",
|
||
|
|
pw.TextStyle(
|
||
|
|
color: PdfColors.black,
|
||
|
|
fontWeight: pw.FontWeight.bold,
|
||
|
|
font: getFont(bold: true),
|
||
|
|
fontFallback: [englishFont],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 5.0),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
pw.SizedBox(height: 20.0),
|
||
|
|
if (personalInformation.data?.showGratitudeMsg == 1)
|
||
|
|
if (!personalInformation.data!.gratitudeMessage.isEmptyOrNull)
|
||
|
|
pw.Container(
|
||
|
|
width: double.infinity,
|
||
|
|
padding: const pw.EdgeInsets.only(bottom: 8.0),
|
||
|
|
child: pw.Center(
|
||
|
|
child: pw.Text(
|
||
|
|
personalInformation.data!.gratitudeMessage ?? '',
|
||
|
|
)),
|
||
|
|
),
|
||
|
|
pw.Padding(padding: const pw.EdgeInsets.all(10)),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
|
||
|
|
EasyLoading.showSuccess(_lang.pdfGenerateSuccessfully);
|
||
|
|
|
||
|
|
if (showPreview == true) {
|
||
|
|
await Printing.layoutPdf(
|
||
|
|
name: personalInformation.data?.companyName ?? '',
|
||
|
|
usePrinterSettings: true,
|
||
|
|
dynamicLayout: true,
|
||
|
|
forceCustomPrintPaper: true,
|
||
|
|
onLayout: (PdfPageFormat format) async => doc.save(),
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
await PDFCommonFunctions.savePdfAndShowPdf(
|
||
|
|
context: context,
|
||
|
|
shopName: personalInformation.data?.companyName ?? '',
|
||
|
|
invoice: transactions.invoiceNumber ?? '',
|
||
|
|
doc: doc,
|
||
|
|
isShare: isShare,
|
||
|
|
download: download,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|