mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
fix: pdf template customization
This commit is contained in:
@@ -21,7 +21,7 @@ export class PdfTemplatesController extends BaseController {
|
||||
this.validationResult,
|
||||
this.deletePdfTemplate.bind(this)
|
||||
);
|
||||
router.put(
|
||||
router.post(
|
||||
'/:template_id',
|
||||
[
|
||||
param('template_id').exists().isInt().toInt(),
|
||||
@@ -77,7 +77,10 @@ export class PdfTemplatesController extends BaseController {
|
||||
resource,
|
||||
attributes
|
||||
);
|
||||
return res.status(201).send(result);
|
||||
return res.status(201).send({
|
||||
id: result.id,
|
||||
message: 'The PDF template has been created successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -94,7 +97,10 @@ export class PdfTemplatesController extends BaseController {
|
||||
Number(templateId),
|
||||
editTemplateDTO
|
||||
);
|
||||
return res.status(200).send(result);
|
||||
return res.status(200).send({
|
||||
id: result.id,
|
||||
message: 'The PDF template has been updated successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -109,7 +115,10 @@ export class PdfTemplatesController extends BaseController {
|
||||
tenantId,
|
||||
Number(templateId)
|
||||
);
|
||||
return res.status(204).send();
|
||||
return res.status(204).send({
|
||||
id: templateId,
|
||||
message: 'The PDF template has been deleted successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
@@ -158,13 +167,10 @@ export class PdfTemplatesController extends BaseController {
|
||||
tenantId,
|
||||
Number(templateId)
|
||||
);
|
||||
return res
|
||||
.status(204)
|
||||
.send({
|
||||
id: templateId,
|
||||
message:
|
||||
'The given pdf template has been assigned as default template',
|
||||
});
|
||||
return res.status(204).send({
|
||||
id: templateId,
|
||||
message: 'The given pdf template has been assigned as default template',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -37,10 +37,6 @@ export function CreditNoteCustomizeContent() {
|
||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||
<CreditNoteCustomizeContentFields />
|
||||
</ElementCustomize.FieldsTab>
|
||||
|
||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
||||
asdfasdfdsaf #3
|
||||
</ElementCustomize.FieldsTab>
|
||||
</BrandingTemplateForm>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,10 +36,6 @@ export function EstimateCustomizeContent() {
|
||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||
<EstimateCustomizeContentFields />
|
||||
</ElementCustomize.FieldsTab>
|
||||
|
||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
||||
asdfasdfdsaf #3
|
||||
</ElementCustomize.FieldsTab>
|
||||
</BrandingTemplateForm>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,10 +43,6 @@ export function InvoiceCustomizeContent() {
|
||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||
<InvoiceCustomizeContentFields />
|
||||
</ElementCustomize.FieldsTab>
|
||||
|
||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
||||
asdfasdfdsaf #3
|
||||
</ElementCustomize.FieldsTab>
|
||||
</BrandingTemplateForm>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
compose,
|
||||
transformToForm,
|
||||
repeatValue,
|
||||
formattedAmount,
|
||||
defaultFastFieldShouldUpdate,
|
||||
} from '@/utils';
|
||||
import { ERROR } from '@/constants/errors';
|
||||
|
||||
@@ -37,10 +37,6 @@ export function PaymentReceivedCustomizeContent() {
|
||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||
<PaymentReceivedCustomizeContentFields />
|
||||
</ElementCustomize.FieldsTab>
|
||||
|
||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
||||
asdfasdfdsaf #3
|
||||
</ElementCustomize.FieldsTab>
|
||||
</BrandingTemplateForm>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,10 +36,6 @@ export function ReceiptCustomizeContent() {
|
||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||
<ReceiptCustomizeFieldsContent />
|
||||
</ElementCustomize.FieldsTab>
|
||||
|
||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
||||
asdfasdfdsaf #3
|
||||
</ElementCustomize.FieldsTab>
|
||||
</BrandingTemplateForm>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ export const useEditPdfTemplate = (
|
||||
>(
|
||||
({ templateId, values }) =>
|
||||
apiRequest
|
||||
.put(`/pdf-templates/${templateId}`, transfromToSnakeCase(values))
|
||||
.post(`/pdf-templates/${templateId}`, transfromToSnakeCase(values))
|
||||
.then((res) => res.data),
|
||||
{
|
||||
onSuccess: () => {
|
||||
|
||||
Reference in New Issue
Block a user