@tomei/finance 0.14.0-dev.0 → 0.14.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document/document.d.ts +2 -2
- package/dist/document/document.d.ts.map +1 -1
- package/dist/document/document.js +268 -201
- package/dist/document/document.js.map +1 -1
- package/dist/finance-company/finance-company.d.ts +13 -1
- package/dist/finance-company/finance-company.d.ts.map +1 -1
- package/dist/finance-company/finance-company.js +130 -114
- package/dist/finance-company/finance-company.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/receipt-template/default/assets/css/style.css +2630 -0
- package/receipt-template/default/assets/css/style.css.map +13 -0
- package/receipt-template/default/assets/css/style.min.css +1 -0
- package/receipt-template/default/assets/img/arrow_bg.svg +12 -0
- package/receipt-template/default/assets/img/coffy_shop_img.svg +19 -0
- package/receipt-template/default/assets/img/ezcash-logo.png +0 -0
- package/receipt-template/default/assets/img/header_bg.jpeg +0 -0
- package/receipt-template/default/assets/img/header_bg_2.jpeg +0 -0
- package/receipt-template/default/assets/img/logo.svg +4 -0
- package/receipt-template/default/assets/img/logo_accent.svg +4 -0
- package/receipt-template/default/assets/img/logo_white.svg +4 -0
- package/receipt-template/default/assets/img/qbar.png +0 -0
- package/receipt-template/default/assets/img/shape_1.svg +1 -0
- package/receipt-template/default/assets/img/shape_2.svg +1 -0
- package/receipt-template/default/assets/img/sign.svg +12 -0
- package/receipt-template/default/assets/img/tomei-logo.png +0 -0
- package/receipt-template/default/assets/img/tomei-logo.svg +9 -0
- package/receipt-template/default/assets/js/html2canvas.min.js +10379 -0
- package/receipt-template/default/assets/js/jquery.min.js +2 -0
- package/receipt-template/default/assets/js/jspdf.min.js +1 -0
- package/receipt-template/default/assets/js/main.js +48 -0
- package/receipt-template/default/assets/sass/common/_color_variable.scss +12 -0
- package/receipt-template/default/assets/sass/common/_invoice.scss +1802 -0
- package/receipt-template/default/assets/sass/common/_normalize.scss +350 -0
- package/receipt-template/default/assets/sass/common/_typography.scss +178 -0
- package/receipt-template/default/assets/sass/style.scss +12 -0
- package/receipt-template/default/index.html +291 -0
|
@@ -67,14 +67,14 @@ export default class Document extends AccountSystemEntity {
|
|
|
67
67
|
static settleByCreditNote(loginUser: LoginUserBase, dbTransaction: any, DocNo: string, AmountToReduce: number): Promise<Document>;
|
|
68
68
|
static DEFAULT_INVOICE_TEMPLATE_HTML(): Promise<Express.Multer.File>;
|
|
69
69
|
DEFAULT_INVOICE_TEMPLATE_PDF(customer: FinanceCustomerBase, date?: Date): Promise<Express.Multer.File>;
|
|
70
|
-
DEFAULT_RECEIPT_TEMPLATE_PDF(customer: FinanceCustomerBase, date?: Date): Promise<Express.Multer.File>;
|
|
70
|
+
DEFAULT_RECEIPT_TEMPLATE_PDF(customer: FinanceCustomerBase, date?: Date, templateType?: string, customData?: any): Promise<Express.Multer.File>;
|
|
71
71
|
get DocumentFileInHTML(): Promise<MediasModel>;
|
|
72
72
|
get DocumentFileInPDF(): Promise<MediasModel>;
|
|
73
73
|
generateInvoice(userId?: string, customer?: FinanceCustomerBase, dbTransaction?: any, date?: Date): Promise<{
|
|
74
74
|
HTMLMedia: MediasModel;
|
|
75
75
|
PDFMedia: MediasModel;
|
|
76
76
|
}>;
|
|
77
|
-
generateReceipt(userId?: string, customer?: FinanceCustomerBase, transaction?: any, date?: Date): Promise<{
|
|
77
|
+
generateReceipt(userId?: string, customer?: FinanceCustomerBase, transaction?: any, date?: Date, templateType?: string, customData?: any): Promise<{
|
|
78
78
|
HTMLMedia: MediasModel;
|
|
79
79
|
PDFMedia: MediasModel;
|
|
80
80
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/document/document.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,aAAa,IA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CAAC,EAAE,GAAG,EACjB,IAAI,CAAC,EAAE,IAAI,EACX,YAAY,CAAC,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,GAAG,GACf,OAAO,CAAC;QACT,SAAS,EAAE,WAAW,CAAC;QACvB,QAAQ,EAAE,WAAW,CAAC;KACvB,CAAC;IA0EI,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,mBAAmB;IAUlE,eAAe,CAAC,YAAY,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAsBnE,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;WAqB/C,OAAO,CACzB,SAAS,EAAE,aAAa,EACxB,aAAa,EAAE,GAAG,EAClB,IAAI,CAAC,EAAE,MAAM,EACb,GAAG,CAAC,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,gBAAgB,EACzB,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC1B,gBAAgB,CAAC,EAAE,cAAc,GAChC,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;CAwKrD"}
|
|
@@ -575,182 +575,239 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
575
575
|
};
|
|
576
576
|
return pdfStream;
|
|
577
577
|
}
|
|
578
|
-
async DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date = new Date()) {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
578
|
+
async DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date = new Date(), templateType = 'default', customData) {
|
|
579
|
+
let browser = null;
|
|
580
|
+
try {
|
|
581
|
+
const baseTemplatePath = './receipt-template';
|
|
582
|
+
const templateFolder = templateType || 'default';
|
|
583
|
+
const templateLocation = path.resolve(`${baseTemplatePath}/${templateFolder}/index.html`);
|
|
584
|
+
const cssLocation = path.resolve(`${baseTemplatePath}/${templateFolder}/assets/css/style.css`);
|
|
585
|
+
if (!fs.existsSync(templateLocation)) {
|
|
586
|
+
throw new Error(`Template file not found: ${templateLocation}`);
|
|
587
|
+
}
|
|
588
|
+
if (!fs.existsSync(cssLocation)) {
|
|
589
|
+
throw new Error(`CSS file not found: ${cssLocation}`);
|
|
590
|
+
}
|
|
591
|
+
const readFileContent = util.promisify(fs.readFile);
|
|
592
|
+
const [htmlString] = await Promise.all([
|
|
593
|
+
readFileContent(templateLocation, 'utf8'),
|
|
594
|
+
]);
|
|
595
|
+
browser = await puppeteer.launch({
|
|
596
|
+
headless: true,
|
|
597
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
598
|
+
});
|
|
599
|
+
const page = await browser.newPage();
|
|
600
|
+
await page.setContent(htmlString);
|
|
601
|
+
await page.addStyleTag({ path: cssLocation });
|
|
602
|
+
if (templateType === 'default') {
|
|
603
|
+
const imagePath = path.resolve('./invoice-template/assets/img/ezcash-logo.svg');
|
|
604
|
+
const imageBuffer = await readFileContent(imagePath);
|
|
605
|
+
const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
|
|
606
|
+
const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
|
|
607
|
+
const divHandle = await page.$('.tm_logo');
|
|
608
|
+
if (divHandle) {
|
|
609
|
+
await divHandle.evaluate((div, imgTag) => {
|
|
610
|
+
div.innerHTML = imgTag;
|
|
611
|
+
}, imgTag);
|
|
612
|
+
}
|
|
613
|
+
const currentDate = date.toLocaleDateString('en-GB');
|
|
614
|
+
const receiptNo = this.DocNo;
|
|
615
|
+
const receiptTitle = `
|
|
616
|
+
<div class="tm_primary_color tm_f50 tm_text_uppercase">
|
|
617
|
+
Receipt
|
|
618
|
+
</div>
|
|
619
|
+
`;
|
|
620
|
+
const receiptTitleHandle = await page.$('.tm_invoice_title');
|
|
621
|
+
if (receiptTitleHandle) {
|
|
622
|
+
await receiptTitleHandle.evaluate((receipt, receiptTitle) => {
|
|
623
|
+
receipt.innerHTML = receiptTitle;
|
|
624
|
+
}, receiptTitle);
|
|
625
|
+
}
|
|
626
|
+
const receiptTitleInfo = `
|
|
627
|
+
<div class="tm_invoice_seperator tm_gray_bg"></div>
|
|
628
|
+
<div class="tm_invoice_info_list">
|
|
629
|
+
<p class="tm_invoice_number tm_m0">
|
|
630
|
+
Receipt No: <b class="tm_primary_color">${receiptNo}</b>
|
|
631
|
+
</p>
|
|
632
|
+
<p class="tm_invoice_date tm_m0">
|
|
633
|
+
Date: <b class="tm_primary_color">${currentDate}</b>
|
|
634
|
+
</p>
|
|
605
635
|
</div>
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
636
|
+
`;
|
|
637
|
+
const receiptTitleInfoHandle = await page.$('.tm_invoice_info');
|
|
638
|
+
if (receiptTitleInfoHandle) {
|
|
639
|
+
await receiptTitleInfoHandle.evaluate((receipt, receiptTitleInfo) => {
|
|
640
|
+
receipt.innerHTML = receiptTitleInfo;
|
|
641
|
+
}, receiptTitleInfo);
|
|
642
|
+
}
|
|
643
|
+
const customerAddress = customer?.DefaultAddress;
|
|
644
|
+
const receiptCustomerContent = `
|
|
645
|
+
<p class="tm_mb2">
|
|
646
|
+
<b class="tm_primary_color">Issued To:</b>
|
|
616
647
|
</p>
|
|
617
|
-
<p
|
|
618
|
-
|
|
648
|
+
<p>
|
|
649
|
+
${customer?.FullName || 'N/A'} <br />
|
|
650
|
+
${customerAddress?.AddressLine1 || ''}, ${customerAddress?.City || ''} <br />
|
|
651
|
+
${customerAddress?.Country || ''} <br />
|
|
652
|
+
${customer?.Email || ''}
|
|
619
653
|
</p>
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
654
|
+
`;
|
|
655
|
+
const receiptCustomerHandle = await page.$('.tm_customer_detail');
|
|
656
|
+
if (receiptCustomerHandle) {
|
|
657
|
+
await receiptCustomerHandle.evaluate((receipt, receiptCustomerContent) => {
|
|
658
|
+
receipt.innerHTML = receiptCustomerContent;
|
|
659
|
+
}, receiptCustomerContent);
|
|
660
|
+
}
|
|
661
|
+
const receiptPayToContent = ``;
|
|
662
|
+
const receiptPayToHandle = await page.$('.tm_payto_detail');
|
|
663
|
+
if (receiptPayToHandle) {
|
|
664
|
+
await receiptPayToHandle.evaluate((receipt, receiptPayToContent) => {
|
|
665
|
+
receipt.innerHTML = receiptPayToContent;
|
|
666
|
+
}, receiptPayToContent);
|
|
667
|
+
}
|
|
668
|
+
const receiptPaymentInfoContent = ``;
|
|
669
|
+
const receiptPaymentInfoHandle = await page.$('.tm_payment_info');
|
|
670
|
+
if (receiptPaymentInfoHandle) {
|
|
671
|
+
await receiptPaymentInfoHandle.evaluate((receipt, receiptPaymentInfoContent) => {
|
|
672
|
+
receipt.innerHTML = receiptPaymentInfoContent;
|
|
673
|
+
}, receiptPaymentInfoContent);
|
|
674
|
+
}
|
|
675
|
+
const receiptSubtotal = +this.Amount;
|
|
676
|
+
const receiptTax = 0;
|
|
677
|
+
const receiptRightFooterContent = `
|
|
678
|
+
<table>
|
|
679
|
+
<tbody>
|
|
680
|
+
<tr>
|
|
681
|
+
<td
|
|
682
|
+
class="tm_width_3 tm_primary_color tm_border_none tm_bold"
|
|
683
|
+
>
|
|
684
|
+
Subtotal
|
|
685
|
+
</td>
|
|
686
|
+
<td
|
|
687
|
+
class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_bold"
|
|
688
|
+
>
|
|
689
|
+
${this.Currency} ${receiptSubtotal}
|
|
690
|
+
</td>
|
|
691
|
+
</tr>
|
|
692
|
+
<tr>
|
|
693
|
+
<td
|
|
694
|
+
class="tm_width_3 tm_primary_color tm_border_none tm_pt0"
|
|
695
|
+
>
|
|
696
|
+
Tax <span class="tm_ternary_color">(0%)</span>
|
|
697
|
+
</td>
|
|
698
|
+
<td
|
|
699
|
+
class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_pt0"
|
|
700
|
+
>
|
|
701
|
+
${this.Currency} ${receiptTax}
|
|
702
|
+
</td>
|
|
703
|
+
</tr>
|
|
704
|
+
<tr class="tm_border_top tm_border_bottom">
|
|
705
|
+
<td
|
|
706
|
+
class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_primary_color"
|
|
707
|
+
>
|
|
708
|
+
Grand Total
|
|
709
|
+
</td>
|
|
710
|
+
<td
|
|
711
|
+
class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_primary_color tm_text_right"
|
|
712
|
+
>
|
|
713
|
+
${this.Currency} ${receiptSubtotal + receiptTax}
|
|
714
|
+
</td>
|
|
715
|
+
</tr>
|
|
716
|
+
</tbody>
|
|
717
|
+
</table>
|
|
718
|
+
`;
|
|
719
|
+
const receiptRightFooterHandle = await page.$('.tm_item_total_section');
|
|
720
|
+
if (receiptRightFooterHandle) {
|
|
721
|
+
await receiptRightFooterHandle.evaluate((receipt, receiptRightFooterContent) => {
|
|
722
|
+
receipt.innerHTML = receiptRightFooterContent;
|
|
723
|
+
}, receiptRightFooterContent);
|
|
724
|
+
}
|
|
725
|
+
const receiptDocumentItems = await this.DocumentItems;
|
|
726
|
+
let receiptItemContent = ``;
|
|
727
|
+
receiptDocumentItems.forEach((documentItem, i) => {
|
|
728
|
+
receiptItemContent += `
|
|
668
729
|
<tr>
|
|
669
|
-
<td
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
Tax <span class="tm_ternary_color">(0%)</span>
|
|
673
|
-
</td>
|
|
674
|
-
<td
|
|
675
|
-
class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_pt0"
|
|
676
|
-
>
|
|
677
|
-
${this.Currency} ${receiptTax}
|
|
678
|
-
</td>
|
|
679
|
-
</tr>
|
|
680
|
-
<tr class="tm_border_top tm_border_bottom">
|
|
681
|
-
<td
|
|
682
|
-
class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_primary_color"
|
|
683
|
-
>
|
|
684
|
-
Grand Total
|
|
685
|
-
</td>
|
|
686
|
-
<td
|
|
687
|
-
class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_primary_color tm_text_right"
|
|
688
|
-
>
|
|
689
|
-
${this.Currency} ${receiptSubtotal + receiptTax}
|
|
730
|
+
<td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
|
|
731
|
+
<td class="tm_width_4">
|
|
732
|
+
${documentItem.Description}
|
|
690
733
|
</td>
|
|
734
|
+
<td class="tm_width_2">${documentItem.Currency} ${documentItem.UnitPrice}</td>
|
|
735
|
+
<td class="tm_width_1">${documentItem.Quantity}</td>
|
|
736
|
+
<td class="tm_width_2 tm_text_right">${documentItem.Currency} ${+documentItem.UnitPrice * +documentItem.Quantity}</td>
|
|
691
737
|
</tr>
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
738
|
+
`;
|
|
739
|
+
});
|
|
740
|
+
const receiptDocumentItemHandle = await page.$('.tm_items_content');
|
|
741
|
+
if (receiptDocumentItemHandle) {
|
|
742
|
+
await receiptDocumentItemHandle.evaluate((receipt, receiptItemContent) => {
|
|
743
|
+
receipt.innerHTML = receiptItemContent;
|
|
744
|
+
}, receiptItemContent);
|
|
745
|
+
}
|
|
746
|
+
const receiptFooterContent = `
|
|
747
|
+
<p class="tm_mb5 tm_text_center tm_f11">
|
|
748
|
+
<i>
|
|
749
|
+
Thank you for your payment. This is computer generated receipt
|
|
750
|
+
- no signature is required.
|
|
751
|
+
</i>
|
|
752
|
+
</p>
|
|
753
|
+
`;
|
|
754
|
+
const receiptFooterHandle = await page.$('.tm_footer_section');
|
|
755
|
+
if (receiptFooterHandle) {
|
|
756
|
+
await receiptFooterHandle.evaluate((receipt, receiptFooterContent) => {
|
|
757
|
+
receipt.innerHTML = receiptFooterContent;
|
|
758
|
+
}, receiptFooterContent);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
if (customData) {
|
|
763
|
+
let updatedHtml = await page.content();
|
|
764
|
+
const placeholderPattern = /\{\{([^}]+)\}\}/g;
|
|
765
|
+
updatedHtml = updatedHtml.replace(placeholderPattern, (match, key) => {
|
|
766
|
+
return customData[key] !== undefined ? customData[key] : match;
|
|
767
|
+
});
|
|
768
|
+
await page.setContent(updatedHtml);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
const pdfBuffer = await page.pdf({
|
|
772
|
+
format: 'a4',
|
|
773
|
+
printBackground: true,
|
|
774
|
+
margin: {
|
|
775
|
+
left: '0px',
|
|
776
|
+
top: '0px',
|
|
777
|
+
right: '0px',
|
|
778
|
+
bottom: '0px',
|
|
779
|
+
},
|
|
780
|
+
});
|
|
781
|
+
const pdfBufferAsBuffer = Buffer.from(pdfBuffer);
|
|
782
|
+
const pdfStream = {
|
|
783
|
+
buffer: pdfBufferAsBuffer,
|
|
784
|
+
fieldname: 'FileStream',
|
|
785
|
+
originalname: 'sample-receipt.pdf',
|
|
786
|
+
mimetype: 'application/pdf',
|
|
787
|
+
size: pdfBuffer.length,
|
|
788
|
+
encoding: '8bit',
|
|
789
|
+
filename: 'sample-receipt.pdf',
|
|
790
|
+
destination: '',
|
|
791
|
+
path: '',
|
|
792
|
+
stream: null,
|
|
793
|
+
};
|
|
794
|
+
return pdfStream;
|
|
795
|
+
}
|
|
796
|
+
catch (error) {
|
|
797
|
+
console.error('Error in DEFAULT_RECEIPT_TEMPLATE_PDF:', error);
|
|
798
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
799
|
+
throw new Error(`Receipt generation failed: ${errorMessage}`);
|
|
800
|
+
}
|
|
801
|
+
finally {
|
|
802
|
+
if (browser) {
|
|
803
|
+
try {
|
|
804
|
+
await browser.close();
|
|
805
|
+
}
|
|
806
|
+
catch (closeError) {
|
|
807
|
+
console.error('Error closing browser:', closeError);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
754
811
|
}
|
|
755
812
|
get DocumentFileInHTML() {
|
|
756
813
|
return (async () => {
|
|
@@ -796,37 +853,47 @@ class Document extends account_system_entity_1.AccountSystemEntity {
|
|
|
796
853
|
PDFMedia: PDFInvoiceMedia,
|
|
797
854
|
};
|
|
798
855
|
}
|
|
799
|
-
async generateReceipt(userId, customer, transaction, date) {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
856
|
+
async generateReceipt(userId, customer, transaction, date, templateType, customData) {
|
|
857
|
+
try {
|
|
858
|
+
if (!customer) {
|
|
859
|
+
throw new Error('Customer data is required for receipt generation');
|
|
860
|
+
}
|
|
861
|
+
const media = new media_1.Medias(this.mediaCommonService);
|
|
862
|
+
const user = new login_user_1.LoginUser(userId ?? 'System', null, null);
|
|
863
|
+
const htmlPayload = {
|
|
864
|
+
ObjectId: this.DocNo,
|
|
865
|
+
ObjectType: 'Document',
|
|
866
|
+
Type: media_1.MediaType.Document,
|
|
867
|
+
FileName: `${this.DocType}-${this.DocNo}`,
|
|
868
|
+
FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
|
|
869
|
+
FileExtension: 'html',
|
|
870
|
+
Title: `${this.DocType}-${this.DocNo}.html`,
|
|
871
|
+
Description: `HTML ${this.DocType}`,
|
|
872
|
+
IsEncryptedYN: 'N',
|
|
873
|
+
};
|
|
874
|
+
const HTMLInvoiceMedia = await media.postInternal(await Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, user, transaction);
|
|
875
|
+
const pdfPayload = {
|
|
876
|
+
ObjectId: this.DocNo,
|
|
877
|
+
ObjectType: 'Document',
|
|
878
|
+
Type: media_1.MediaType.Document,
|
|
879
|
+
FileName: `${this.DocType}-${this.DocNo}`,
|
|
880
|
+
FileStream: await this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date, templateType, customData),
|
|
881
|
+
FileExtension: 'pdf',
|
|
882
|
+
Title: `${this.DocType}-${this.DocNo}.pdf`,
|
|
883
|
+
Description: `PDF ${this.DocType}`,
|
|
884
|
+
IsEncryptedYN: 'N',
|
|
885
|
+
};
|
|
886
|
+
const PDFInvoiceMedia = await media.postInternal(await this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date, templateType, customData), pdfPayload, user, transaction);
|
|
887
|
+
return {
|
|
888
|
+
HTMLMedia: HTMLInvoiceMedia,
|
|
889
|
+
PDFMedia: PDFInvoiceMedia,
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
catch (error) {
|
|
893
|
+
console.error('Error in generateReceipt:', error);
|
|
894
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
895
|
+
throw new Error(`Receipt generation failed: ${errorMessage}`);
|
|
896
|
+
}
|
|
830
897
|
}
|
|
831
898
|
async generateCreditNote(userId, customer) {
|
|
832
899
|
console.log(userId, customer, '<< generateCreditNote');
|