mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix: pdf template customization
This commit is contained in:
@@ -21,7 +21,7 @@ export class PdfTemplatesController extends BaseController {
|
|||||||
this.validationResult,
|
this.validationResult,
|
||||||
this.deletePdfTemplate.bind(this)
|
this.deletePdfTemplate.bind(this)
|
||||||
);
|
);
|
||||||
router.put(
|
router.post(
|
||||||
'/:template_id',
|
'/:template_id',
|
||||||
[
|
[
|
||||||
param('template_id').exists().isInt().toInt(),
|
param('template_id').exists().isInt().toInt(),
|
||||||
@@ -77,7 +77,10 @@ export class PdfTemplatesController extends BaseController {
|
|||||||
resource,
|
resource,
|
||||||
attributes
|
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) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -94,7 +97,10 @@ export class PdfTemplatesController extends BaseController {
|
|||||||
Number(templateId),
|
Number(templateId),
|
||||||
editTemplateDTO
|
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) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -109,7 +115,10 @@ export class PdfTemplatesController extends BaseController {
|
|||||||
tenantId,
|
tenantId,
|
||||||
Number(templateId)
|
Number(templateId)
|
||||||
);
|
);
|
||||||
return res.status(204).send();
|
return res.status(204).send({
|
||||||
|
id: templateId,
|
||||||
|
message: 'The PDF template has been deleted successfully.',
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -158,13 +167,10 @@ export class PdfTemplatesController extends BaseController {
|
|||||||
tenantId,
|
tenantId,
|
||||||
Number(templateId)
|
Number(templateId)
|
||||||
);
|
);
|
||||||
return res
|
return res.status(204).send({
|
||||||
.status(204)
|
id: templateId,
|
||||||
.send({
|
message: 'The given pdf template has been assigned as default template',
|
||||||
id: templateId,
|
});
|
||||||
message:
|
|
||||||
'The given pdf template has been assigned as default template',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export class CreatePdfTemplate {
|
|||||||
tenantId,
|
tenantId,
|
||||||
});
|
});
|
||||||
|
|
||||||
await PdfTemplate.query(trx).insert({
|
const pdfTemplate = await PdfTemplate.query(trx).insert({
|
||||||
templateName,
|
templateName,
|
||||||
resource,
|
resource,
|
||||||
attributes,
|
attributes,
|
||||||
@@ -45,6 +45,7 @@ export class CreatePdfTemplate {
|
|||||||
await this.eventPublisher.emitAsync(events.pdfTemplate.onCreated, {
|
await this.eventPublisher.emitAsync(events.pdfTemplate.onCreated, {
|
||||||
tenantId,
|
tenantId,
|
||||||
});
|
});
|
||||||
|
return pdfTemplate;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { ICreateInvoicePdfTemplateDTO } from './types';
|
import { ICreateInvoicePdfTemplateDTO, IEditPdfTemplateDTO } from './types';
|
||||||
import { CreatePdfTemplate } from './CreatePdfTemplate';
|
import { CreatePdfTemplate } from './CreatePdfTemplate';
|
||||||
import { DeletePdfTemplate } from './DeletePdfTemplate';
|
import { DeletePdfTemplate } from './DeletePdfTemplate';
|
||||||
import { GetPdfTemplate } from './GetPdfTemplate';
|
import { GetPdfTemplate } from './GetPdfTemplate';
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
export enum ERRORS {
|
export enum ERRORS {
|
||||||
CANNOT_DELETE_PREDEFINED_PDF_TEMPLATE = 'CANNOT_DELETE_PREDEFINED_PDF_TEMPLATE',
|
CANNOT_DELETE_PREDEFINED_PDF_TEMPLATE = 'CANNOT_DELETE_PREDEFINED_PDF_TEMPLATE',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IEditPdfTemplateDTO {
|
||||||
|
templateName: string;
|
||||||
|
attributes: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ICreateInvoicePdfTemplateDTO {
|
export interface ICreateInvoicePdfTemplateDTO {
|
||||||
// Colors
|
// Colors
|
||||||
primaryColor?: string;
|
primaryColor?: string;
|
||||||
|
|||||||
@@ -3,5 +3,20 @@ import { EstimatePdfBrandingAttributes } from './constants';
|
|||||||
export const transformEstimateToPdfTemplate = (
|
export const transformEstimateToPdfTemplate = (
|
||||||
estimate
|
estimate
|
||||||
): Partial<EstimatePdfBrandingAttributes> => {
|
): 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,
|
brandingTemplate,
|
||||||
(val, key) => val !== null && Object.keys(defaultAttributes).includes(key)
|
(val, key) => val !== null && Object.keys(defaultAttributes).includes(key)
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...defaultAttributes,
|
...defaultAttributes,
|
||||||
...brandingAttributes,
|
...brandingAttributes,
|
||||||
@@ -39,5 +38,9 @@ export const transformInvoiceToPdfTemplate = (
|
|||||||
quantity: entry.quantityFormatted,
|
quantity: entry.quantityFormatted,
|
||||||
total: entry.totalFormatted,
|
total: entry.totalFormatted,
|
||||||
})),
|
})),
|
||||||
|
taxes: invoice.taxes.map((tax) => ({
|
||||||
|
label: tax.name,
|
||||||
|
amount: tax.taxRateAmountFormatted,
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export class PaymentReceivedBrandingTemplate {
|
|||||||
public async getPaymentReceivedPdfTemplate(
|
public async getPaymentReceivedPdfTemplate(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
paymentTemplateId: number
|
paymentTemplateId: number
|
||||||
): Promise<PdfTemplate> {
|
) {
|
||||||
const template = await this.getPdfTemplateService.getPdfTemplate(
|
const template = await this.getPdfTemplateService.getPdfTemplate(
|
||||||
tenantId,
|
tenantId,
|
||||||
paymentTemplateId
|
paymentTemplateId
|
||||||
|
|||||||
@@ -7,6 +7,15 @@ export const transformPaymentReceivedToPdfTemplate = (
|
|||||||
payment: IPaymentReceived
|
payment: IPaymentReceived
|
||||||
): Partial<PaymentReceivedPdfTemplateAttributes> => {
|
): Partial<PaymentReceivedPdfTemplateAttributes> => {
|
||||||
return {
|
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 = () => {
|
export const transformReceiptToBrandingTemplateAttributes = (saleReceipt: ISaleReceipt): Partial<ISaleReceiptBrandingTemplateAttributes> => {
|
||||||
return {};
|
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'}>
|
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||||
<CreditNoteCustomizeContentFields />
|
<CreditNoteCustomizeContentFields />
|
||||||
</ElementCustomize.FieldsTab>
|
</ElementCustomize.FieldsTab>
|
||||||
|
|
||||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
|
||||||
asdfasdfdsaf #3
|
|
||||||
</ElementCustomize.FieldsTab>
|
|
||||||
</BrandingTemplateForm>
|
</BrandingTemplateForm>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ export function EstimateCustomizeContent() {
|
|||||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||||
<EstimateCustomizeContentFields />
|
<EstimateCustomizeContentFields />
|
||||||
</ElementCustomize.FieldsTab>
|
</ElementCustomize.FieldsTab>
|
||||||
|
|
||||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
|
||||||
asdfasdfdsaf #3
|
|
||||||
</ElementCustomize.FieldsTab>
|
|
||||||
</BrandingTemplateForm>
|
</BrandingTemplateForm>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,6 @@ export function InvoiceCustomizeContent() {
|
|||||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||||
<InvoiceCustomizeContentFields />
|
<InvoiceCustomizeContentFields />
|
||||||
</ElementCustomize.FieldsTab>
|
</ElementCustomize.FieldsTab>
|
||||||
|
|
||||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
|
||||||
asdfasdfdsaf #3
|
|
||||||
</ElementCustomize.FieldsTab>
|
|
||||||
</BrandingTemplateForm>
|
</BrandingTemplateForm>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
compose,
|
compose,
|
||||||
transformToForm,
|
transformToForm,
|
||||||
repeatValue,
|
repeatValue,
|
||||||
formattedAmount,
|
|
||||||
defaultFastFieldShouldUpdate,
|
defaultFastFieldShouldUpdate,
|
||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
import { ERROR } from '@/constants/errors';
|
import { ERROR } from '@/constants/errors';
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ export function PaymentReceivedCustomizeContent() {
|
|||||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||||
<PaymentReceivedCustomizeContentFields />
|
<PaymentReceivedCustomizeContentFields />
|
||||||
</ElementCustomize.FieldsTab>
|
</ElementCustomize.FieldsTab>
|
||||||
|
|
||||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
|
||||||
asdfasdfdsaf #3
|
|
||||||
</ElementCustomize.FieldsTab>
|
|
||||||
</BrandingTemplateForm>
|
</BrandingTemplateForm>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ export function ReceiptCustomizeContent() {
|
|||||||
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
<ElementCustomize.FieldsTab id={'content'} label={'Content'}>
|
||||||
<ReceiptCustomizeFieldsContent />
|
<ReceiptCustomizeFieldsContent />
|
||||||
</ElementCustomize.FieldsTab>
|
</ElementCustomize.FieldsTab>
|
||||||
|
|
||||||
<ElementCustomize.FieldsTab id={'totals'} label={'Totals'}>
|
|
||||||
asdfasdfdsaf #3
|
|
||||||
</ElementCustomize.FieldsTab>
|
|
||||||
</BrandingTemplateForm>
|
</BrandingTemplateForm>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export const useEditPdfTemplate = (
|
|||||||
>(
|
>(
|
||||||
({ templateId, values }) =>
|
({ templateId, values }) =>
|
||||||
apiRequest
|
apiRequest
|
||||||
.put(`/pdf-templates/${templateId}`, transfromToSnakeCase(values))
|
.post(`/pdf-templates/${templateId}`, transfromToSnakeCase(values))
|
||||||
.then((res) => res.data),
|
.then((res) => res.data),
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user