mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix: pdf template customization
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ export class PaymentReceivedBrandingTemplate {
|
||||
public async getPaymentReceivedPdfTemplate(
|
||||
tenantId: number,
|
||||
paymentTemplateId: number
|
||||
): Promise<PdfTemplate> {
|
||||
) {
|
||||
const template = await this.getPdfTemplateService.getPdfTemplate(
|
||||
tenantId,
|
||||
paymentTemplateId
|
||||
|
||||
@@ -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,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user