taxtank-core 2.0.13 → 2.0.15

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.
@@ -4715,10 +4715,13 @@ class ServiceSubscription extends ServiceSubscription$1 {
4715
4715
  if (!this.promoCode) {
4716
4716
  return 0;
4717
4717
  }
4718
- const discountApplicable = this.items
4719
- .map(item => item.price)
4720
- .filter(price => this.promoCode.getProductsIds().includes(price.product.id))
4721
- .reduce((sum, price) => sum + price.amount, 0) || this.initialPrice;
4718
+ let discountApplicable = this.initialPrice;
4719
+ if (this.promoCode.products.length) {
4720
+ discountApplicable = this.items
4721
+ .map(item => item.price)
4722
+ .filter(price => this.promoCode.getProductsIds().includes(price.product.id))
4723
+ .reduce((sum, price) => sum + price.amount, 0);
4724
+ }
4722
4725
  if (this.promoCode.amountOff) {
4723
4726
  return Math.min(discountApplicable, this.promoCode.amountOff);
4724
4727
  }
@@ -20220,7 +20223,7 @@ class ExportFormatterService {
20220
20223
  return rows.map((row) => row.map((column) => {
20221
20224
  switch (column.type) {
20222
20225
  case ExportCellTypeEnum.DATE:
20223
- return this.datePipe.transform(column.value, 'dd/MM/YYYY').toString();
20226
+ return this.datePipe.transform(column.value, 'dd/MM/yyyy').toString();
20224
20227
  case ExportCellTypeEnum.CURRENCY:
20225
20228
  return this.currencyPipe.transform(column.value).toString();
20226
20229
  case ExportCellTypeEnum.PERCENT:
@@ -20416,11 +20419,8 @@ class PdfFromTableService {
20416
20419
  /**
20417
20420
  * Set basic options for PDF table
20418
20421
  */
20419
- setTableOptions(pdf, tableCaption = '') {
20422
+ setTableOptions(pdf) {
20420
20423
  const lastTableCoords = pdf['lastAutoTable'].finalY || FILE_SETTINGS.contentCoords.top;
20421
- // get caption height based on caption content height
20422
- const captionHeight = pdf.getTextDimensions(pdf.splitTextToSize(tableCaption, pdf.internal.pageSize.width)).h;
20423
- pdf.text(tableCaption, FILE_SETTINGS.contentCoords.left, lastTableCoords + FILE_SETTINGS.contentCoords.top);
20424
20424
  return {
20425
20425
  headStyles: {
20426
20426
  fillColor: FILE_SETTINGS.text.colorPrimary,
@@ -20429,7 +20429,7 @@ class PdfFromTableService {
20429
20429
  fillColor: FILE_SETTINGS.text.colorWhite,
20430
20430
  textColor: FILE_SETTINGS.text.colorBlack
20431
20431
  },
20432
- startY: lastTableCoords + captionHeight + FILE_SETTINGS.titleCoords.top,
20432
+ startY: lastTableCoords,
20433
20433
  didParseCell: (data) => {
20434
20434
  // Align last column content to right
20435
20435
  if (data.table.columns.length > 1 && (data.column.index === data.table.columns.length - 1)) {
@@ -20458,6 +20458,32 @@ class PdfFromTableService {
20458
20458
  .text(description, FILE_SETTINGS.text.positionDescriptionX, FILE_SETTINGS.text.positionDescriptionY)
20459
20459
  .setTextColor(FILE_SETTINGS.text.colorPrimary);
20460
20460
  }
20461
+ /**
20462
+ * Renders a caption before a table.
20463
+ * - Implemented via autoTable (not plain text) so that:
20464
+ * • line wrapping and text height are calculated automatically,
20465
+ * • the vertical position (finalY) updates consistently,
20466
+ * • page breaks keep caption and table together.
20467
+ * - If `pageBreak` is true, caption (and table) start on a new page.
20468
+ */
20469
+ addCaption(pdf, text, pageBreak) {
20470
+ const lastTableCoords = pdf['lastAutoTable'].finalY || FILE_SETTINGS.contentCoords.top;
20471
+ pdf.autoTable({
20472
+ body: [[text]],
20473
+ theme: 'plain',
20474
+ margin: {
20475
+ bottom: 0,
20476
+ left: FILE_SETTINGS.titleCoords.left,
20477
+ },
20478
+ styles: {
20479
+ minCellHeight: 4,
20480
+ fontSize: 12,
20481
+ fontStyle: 'bold',
20482
+ },
20483
+ pageBreak: pageBreak ? 'always' : 'auto',
20484
+ startY: lastTableCoords + FILE_SETTINGS.titleCoords.top / 2,
20485
+ });
20486
+ }
20461
20487
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: PdfFromTableService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
20462
20488
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: PdfFromTableService, providedIn: 'root' }); }
20463
20489
  }
@@ -20489,13 +20515,17 @@ class PdfFromDataTableService extends PdfFromTableService {
20489
20515
  this.setDocumentLogo(pdf);
20490
20516
  this.setDocumentSubtitle(pdf, fileSettings.subtitle);
20491
20517
  this.setDocumentDescription(pdf, fileSettings.description);
20518
+ let pageBreak;
20492
20519
  dataTables.forEach((dataTable) => {
20520
+ this.addCaption(pdf, dataTable.caption || '', pageBreak);
20493
20521
  pdf.autoTable({
20494
20522
  head: [dataTable.header],
20495
20523
  body: this.formatter.format(dataTable.body),
20496
20524
  foot: this.formatter.format(dataTable.footer),
20497
- ...this.setTableOptions(pdf, dataTable.caption)
20525
+ ...this.setTableOptions(pdf)
20498
20526
  });
20527
+ // pageBreak affects the next caption, so we set it at loop end.
20528
+ pageBreak = dataTable.pageBreak;
20499
20529
  });
20500
20530
  return pdf;
20501
20531
  }
@@ -20524,19 +20554,18 @@ class PdfFromHtmlTableService extends PdfFromTableService {
20524
20554
  const pdf = new JsPdf(fileSettings.orientation);
20525
20555
  this.setDocumentTitle(pdf, fileSettings.title);
20526
20556
  this.setDocumentLogo(pdf);
20557
+ let pageBreak;
20527
20558
  tables.forEach((table) => {
20528
20559
  table.querySelectorAll('tbody .mat-mdc-row')
20529
20560
  .forEach(row => row.classList.contains('expandable-row') ? row.remove() : '');
20530
- // Add table caption if not provided
20531
- if (!table.caption) {
20532
- table.createCaption();
20533
- table.caption.innerText = '';
20534
- }
20561
+ this.addCaption(pdf, table.caption?.innerText || '', pageBreak);
20535
20562
  pdf.autoTable({
20536
20563
  html: table,
20537
20564
  ...customOptions,
20538
- ...this.setTableOptions(pdf, table.caption.innerText)
20565
+ ...this.setTableOptions(pdf),
20539
20566
  });
20567
+ // pageBreak affects the next caption, so we set it at loop end.
20568
+ pageBreak = table.hasAttribute('pageBreak');
20540
20569
  });
20541
20570
  return pdf;
20542
20571
  }