@tomei/finance 0.4.7 → 0.4.8
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/package.json
CHANGED
package/src/document/document.ts
CHANGED
|
@@ -298,7 +298,9 @@ export default class Document extends AccountSystemEntity {
|
|
|
298
298
|
*
|
|
299
299
|
* @returns {Express.Multer.File} - PDF File
|
|
300
300
|
*/
|
|
301
|
-
public static async DEFAULT_INVOICE_TEMPLATE_PDF(
|
|
301
|
+
public static async DEFAULT_INVOICE_TEMPLATE_PDF(
|
|
302
|
+
customer: FinanceCustomerBase,
|
|
303
|
+
): Promise<Express.Multer.File> {
|
|
302
304
|
/* prepping HTML conversion by getting its URL and String */
|
|
303
305
|
|
|
304
306
|
/* todo: needs to generate HTML first before converting to PDF */
|
|
@@ -322,25 +324,35 @@ export default class Document extends AccountSystemEntity {
|
|
|
322
324
|
|
|
323
325
|
const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
|
|
324
326
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
327
|
+
await page.setContent(htmlString);
|
|
328
|
+
await page.addStyleTag({ path: cssLocation });
|
|
329
|
+
|
|
330
|
+
// Replace the <img> tag with the new image
|
|
331
|
+
const divHandle = await page.$('.tm_logo');
|
|
332
|
+
await divHandle.evaluate((div, imgTag) => {
|
|
333
|
+
div.innerHTML = imgTag;
|
|
334
|
+
}, imgTag);
|
|
335
|
+
|
|
336
|
+
// Get the current date and invoice number from customer
|
|
337
|
+
const currentDate = new Date().toLocaleDateString();
|
|
338
|
+
const invoiceNo = 'EZC-2202-2020';
|
|
339
|
+
|
|
340
|
+
// Update the invoice number and date in the HTML content
|
|
341
|
+
const invoiceContent = `
|
|
342
|
+
<div class="tm_invoice_seperator tm_gray_bg"></div>
|
|
343
|
+
<div class="tm_invoice_info_list">
|
|
344
|
+
<p class="tm_invoice_number tm_m0">
|
|
345
|
+
Invoice No: <b class="tm_primary_color">#${invoiceNo}</b>
|
|
346
|
+
</p>
|
|
347
|
+
<p class="tm_invoice_date tm_m0">
|
|
348
|
+
Date: <b class="tm_primary_color">${currentDate}</b>
|
|
349
|
+
</p>
|
|
350
|
+
</div>
|
|
351
|
+
`;
|
|
352
|
+
const invoiceHandle = await page.$('.tm_invoice_info');
|
|
353
|
+
await invoiceHandle.evaluate((invoice, invoiceContent) => {
|
|
354
|
+
invoice.innerHTML = invoiceContent;
|
|
355
|
+
}, invoiceContent);
|
|
344
356
|
|
|
345
357
|
const pdfBuffer = await page.pdf({
|
|
346
358
|
format: 'a4',
|
|
@@ -448,12 +460,6 @@ export default class Document extends AccountSystemEntity {
|
|
|
448
460
|
this.mediaCommonService,
|
|
449
461
|
);
|
|
450
462
|
|
|
451
|
-
/* todo: needs to manipulate HTML DOM before uploading to media*/
|
|
452
|
-
console.log(
|
|
453
|
-
customer || 'no customer provided',
|
|
454
|
-
'<< customer dari generate invoice',
|
|
455
|
-
);
|
|
456
|
-
|
|
457
463
|
/* insert FileStream on htmlPayload */
|
|
458
464
|
const htmlPayload: InternalMediaDto = {
|
|
459
465
|
ObjectId: this.DocNo,
|
|
@@ -480,7 +486,7 @@ export default class Document extends AccountSystemEntity {
|
|
|
480
486
|
ObjectType: this.DocType,
|
|
481
487
|
Type: MediaType.Document,
|
|
482
488
|
FileName: `${this.DocType}-${this.DocNo}`,
|
|
483
|
-
FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_PDF(),
|
|
489
|
+
FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_PDF(customer),
|
|
484
490
|
FileExtension: 'pdf',
|
|
485
491
|
Title: `${this.DocType}-${this.DocNo}.pdf`,
|
|
486
492
|
Description: `PDF ${this.DocType}`,
|
|
@@ -489,7 +495,7 @@ export default class Document extends AccountSystemEntity {
|
|
|
489
495
|
|
|
490
496
|
/* create PDF media from the converted HTML */
|
|
491
497
|
const PDFInvoiceMedia = await media.postInternal(
|
|
492
|
-
await Document.DEFAULT_INVOICE_TEMPLATE_PDF(),
|
|
498
|
+
await Document.DEFAULT_INVOICE_TEMPLATE_PDF(customer),
|
|
493
499
|
pdfPayload,
|
|
494
500
|
userId ?? 'System',
|
|
495
501
|
);
|