fix: pdf template customization

This commit is contained in:
Ahmed Bouhuolia
2024-09-17 18:19:28 +02:00
parent bb0d91a9cb
commit 5f40d50852
16 changed files with 74 additions and 41 deletions

View File

@@ -36,7 +36,7 @@ export class CreatePdfTemplate {
tenantId,
});
await PdfTemplate.query(trx).insert({
const pdfTemplate = await PdfTemplate.query(trx).insert({
templateName,
resource,
attributes,
@@ -45,6 +45,7 @@ export class CreatePdfTemplate {
await this.eventPublisher.emitAsync(events.pdfTemplate.onCreated, {
tenantId,
});
return pdfTemplate;
});
}
}

View File

@@ -1,5 +1,5 @@
import { Inject, Service } from 'typedi';
import { ICreateInvoicePdfTemplateDTO } from './types';
import { ICreateInvoicePdfTemplateDTO, IEditPdfTemplateDTO } from './types';
import { CreatePdfTemplate } from './CreatePdfTemplate';
import { DeletePdfTemplate } from './DeletePdfTemplate';
import { GetPdfTemplate } from './GetPdfTemplate';

View File

@@ -1,6 +1,12 @@
export enum ERRORS {
CANNOT_DELETE_PREDEFINED_PDF_TEMPLATE = 'CANNOT_DELETE_PREDEFINED_PDF_TEMPLATE',
}
export interface IEditPdfTemplateDTO {
templateName: string;
attributes: Record<string, any>;
}
export interface ICreateInvoicePdfTemplateDTO {
// Colors
primaryColor?: string;

View File

@@ -3,5 +3,20 @@ import { EstimatePdfBrandingAttributes } from './constants';
export const transformEstimateToPdfTemplate = (
estimate
): Partial<EstimatePdfBrandingAttributes> => {
return {};
return {
expirationDate: estimate.formattedExpirationDate,
estimateNumebr: estimate.estimateNumber,
estimateDate: estimate.formattedEstimateDate,
lines: estimate.entries.map((entry) => ({
item: entry.item.name,
description: entry.description,
rate: entry.rateFormatted,
quantity: entry.quantityFormatted,
total: entry.totalFormatted,
})),
total: estimate.formattedSubtotal,
subtotal: estimate.formattedSubtotal,
customerNote: estimate.customerNote,
termsConditions: estimate.termsConditions,
};
};

View File

@@ -9,7 +9,6 @@ export const mergePdfTemplateWithDefaultAttributes = (
brandingTemplate,
(val, key) => val !== null && Object.keys(defaultAttributes).includes(key)
);
return {
...defaultAttributes,
...brandingAttributes,
@@ -39,5 +38,9 @@ export const transformInvoiceToPdfTemplate = (
quantity: entry.quantityFormatted,
total: entry.totalFormatted,
})),
taxes: invoice.taxes.map((tax) => ({
label: tax.name,
amount: tax.taxRateAmountFormatted,
})),
};
};

View File

@@ -18,7 +18,7 @@ export class PaymentReceivedBrandingTemplate {
public async getPaymentReceivedPdfTemplate(
tenantId: number,
paymentTemplateId: number
): Promise<PdfTemplate> {
) {
const template = await this.getPdfTemplateService.getPdfTemplate(
tenantId,
paymentTemplateId

View File

@@ -7,6 +7,15 @@ export const transformPaymentReceivedToPdfTemplate = (
payment: IPaymentReceived
): Partial<PaymentReceivedPdfTemplateAttributes> => {
return {
// ...payment
total: payment.formattedAmount,
subtotal: payment.subtotalFormatted,
paymentReceivedNumebr: payment.paymentReceiveNo,
paymentReceivedDate: payment.formattedPaymentDate,
customerName: payment.customer.displayName,
lines: payment.entries.map((entry) => ({
invoiceNumber: entry.invoice.invoiceNo,
invoiceAmount: entry.invoice.totalFormatted,
paidAmount: entry.paymentAmountFormatted,
})),
};
};

View File

@@ -1,6 +1,20 @@
import { ISaleReceipt, ISaleReceiptBrandingTemplateAttributes } from "@/interfaces";
export const transformReceiptToBrandingTemplateAttributes = () => {
return {};
export const transformReceiptToBrandingTemplateAttributes = (saleReceipt: ISaleReceipt): Partial<ISaleReceiptBrandingTemplateAttributes> => {
return {
total: saleReceipt.formattedAmount,
subtotal: saleReceipt.formattedSubtotal,
lines: saleReceipt.entries?.map((entry) => ({
item: entry.item.name,
description: entry.description,
rate: entry.rateFormatted,
quantity: entry.quantityFormatted,
total: entry.totalFormatted,
})),
receiptNumber: saleReceipt.receiptNumber,
receiptDate: saleReceipt.formattedReceiptDate,
};
}