@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.
@@ -150,7 +150,7 @@
150
150
  <td
151
151
  class="tm_width_3 tm_primary_color tm_border_none tm_bold"
152
152
  >
153
- Subtoal
153
+ Subtotal
154
154
  </td>
155
155
  <td
156
156
  class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_bold"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/finance",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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(): Promise<Express.Multer.File> {
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
- if (htmlString) {
326
- await page.setContent(htmlString);
327
- await page.addStyleTag({ path: cssLocation });
328
- const divHandle = await page.$('.tm_logo');
329
- await divHandle.evaluate((div, imgTag) => {
330
- div.innerHTML = imgTag;
331
- }, imgTag);
332
- } else if (templateLocation) {
333
- await page.goto(templateLocation, {
334
- waitUntil: 'networkidle2',
335
- });
336
- await page.addStyleTag({ path: cssLocation });
337
- const divHandle = await page.$('.tm_logo');
338
- await divHandle.evaluate((div, imgTag) => {
339
- div.innerHTML = imgTag;
340
- }, imgTag);
341
- } else {
342
- await browser.close();
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
  );