mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
refactor: mail templates
This commit is contained in:
@@ -171,6 +171,9 @@ export class SaleInvoicesController {
|
||||
'Content-Length': pdfContent.length,
|
||||
});
|
||||
res.send(pdfContent);
|
||||
} else if (acceptHeader.includes(AcceptType.ApplicationTextHtml)) {
|
||||
const htmlContent = await this.saleInvoiceApplication.saleInvoiceHtml(id);
|
||||
return { htmlContent };
|
||||
} else {
|
||||
return this.saleInvoiceApplication.getSaleInvoice(id);
|
||||
}
|
||||
@@ -270,7 +273,7 @@ export class SaleInvoicesController {
|
||||
return this.saleInvoiceApplication.saleInvoiceHtml(id);
|
||||
}
|
||||
|
||||
@Get(':id/mail-state')
|
||||
@Get(':id/mail')
|
||||
@ApiOperation({ summary: 'Retrieves the sale invoice mail state.' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
|
||||
@@ -39,7 +39,7 @@ export class GetInvoicePaymentMail {
|
||||
|
||||
/**
|
||||
* Retrieves the mail template html content.
|
||||
* @param {number} invoiceId - Invoice id.
|
||||
* @param {number} invoiceId - Sale invoice id.
|
||||
*/
|
||||
public async getMailTemplate(
|
||||
invoiceId: number,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Transformer } from "@/modules/Transformer/Transformer";
|
||||
import { Transformer } from '@/modules/Transformer/Transformer';
|
||||
|
||||
export class GetInvoicePaymentMailAttributesTransformer extends Transformer {
|
||||
/**
|
||||
@@ -26,6 +26,15 @@ export class GetInvoicePaymentMailAttributesTransformer extends Transformer {
|
||||
'total',
|
||||
'totalLabel',
|
||||
|
||||
'subtotal',
|
||||
'subtotalLabel',
|
||||
|
||||
'discount',
|
||||
'discountLabel',
|
||||
|
||||
'adjustment',
|
||||
'adjustmentLabel',
|
||||
|
||||
'dueAmount',
|
||||
'dueAmountLabel',
|
||||
|
||||
@@ -76,6 +85,30 @@ export class GetInvoicePaymentMailAttributesTransformer extends Transformer {
|
||||
return 'Invoice # {invoiceNumber}';
|
||||
}
|
||||
|
||||
public subtotal(): string {
|
||||
return this.options.invoice?.subtotalFormatted;
|
||||
}
|
||||
|
||||
public subtotalLabel(): string {
|
||||
return 'Subtotal';
|
||||
}
|
||||
|
||||
public discount(): string {
|
||||
return this.options.invoice?.discountAmountFormatted;
|
||||
}
|
||||
|
||||
public discountLabel(): string {
|
||||
return 'Discount';
|
||||
}
|
||||
|
||||
public adjustment(): string {
|
||||
return this.options.invoice?.adjustmentFormatted;
|
||||
}
|
||||
|
||||
public adjustmentLabel(): string {
|
||||
return 'Adjustment';
|
||||
}
|
||||
|
||||
public total(): string {
|
||||
return this.options.invoice?.totalFormatted;
|
||||
}
|
||||
@@ -103,7 +136,7 @@ export class GetInvoicePaymentMailAttributesTransformer extends Transformer {
|
||||
public items(): Array<any> {
|
||||
return this.item(
|
||||
this.options.invoice?.entries,
|
||||
new GetInvoiceMailTemplateItemAttrsTransformer()
|
||||
new GetInvoiceMailTemplateItemAttrsTransformer(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,15 @@ export class GetSaleInvoiceMailStateTransformer extends SaleInvoiceTransformer {
|
||||
'subtotal',
|
||||
'subtotalFormatted',
|
||||
|
||||
'discountAmount',
|
||||
'discountAmountFormatted',
|
||||
'discountPercentage',
|
||||
'discountPercentageFormatted',
|
||||
'discountLabel',
|
||||
|
||||
'adjustment',
|
||||
'adjustmentFormatted',
|
||||
|
||||
'invoiceNo',
|
||||
|
||||
'entries',
|
||||
@@ -76,6 +85,17 @@ export class GetSaleInvoiceMailStateTransformer extends SaleInvoiceTransformer {
|
||||
return invoice.pdfTemplate?.attributes?.primaryColor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the discount label of the estimate.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected discountLabel(invoice) {
|
||||
return invoice.discountType === 'percentage'
|
||||
? `Discount [${invoice.discountPercentageFormatted}]`
|
||||
: 'Discount';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param invoice
|
||||
@@ -87,7 +107,7 @@ export class GetSaleInvoiceMailStateTransformer extends SaleInvoiceTransformer {
|
||||
new GetSaleInvoiceMailStateEntryTransformer(),
|
||||
{
|
||||
currencyCode: invoice.currencyCode,
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { SaleInvoice } from '../models/SaleInvoice';
|
||||
import { ItemEntryTransformer } from '../../TransactionItemEntry/ItemEntry.transformer';
|
||||
import { AttachmentTransformer } from '../../Attachments/Attachment.transformer';
|
||||
import { SaleInvoiceTaxEntryTransformer } from './SaleInvoiceTaxEntry.transformer';
|
||||
import { DiscountType } from '@/common/types/Discount';
|
||||
|
||||
export class SaleInvoiceTransformer extends Transformer {
|
||||
/**
|
||||
@@ -25,6 +26,9 @@ export class SaleInvoiceTransformer extends Transformer {
|
||||
'taxAmountWithheldLocalFormatted',
|
||||
'totalFormatted',
|
||||
'totalLocalFormatted',
|
||||
'discountAmountFormatted',
|
||||
'discountPercentageFormatted',
|
||||
'adjustmentFormatted',
|
||||
'taxes',
|
||||
'entries',
|
||||
'attachments',
|
||||
@@ -180,6 +184,39 @@ export class SaleInvoiceTransformer extends Transformer {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves formatted discount amount.
|
||||
* @param invoice
|
||||
* @returns {string}
|
||||
*/
|
||||
protected discountAmountFormatted = (invoice: SaleInvoice): string => {
|
||||
return this.formatNumber(invoice.discountAmount, {
|
||||
currencyCode: invoice.currencyCode,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves formatted discount percentage.
|
||||
* @param invoice
|
||||
* @returns {string}
|
||||
*/
|
||||
protected discountPercentageFormatted = (invoice: SaleInvoice): string => {
|
||||
return invoice.discountType === DiscountType.Percentage
|
||||
? `${invoice.discount}%`
|
||||
: '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves formatted adjustment amount.
|
||||
* @param invoice
|
||||
* @returns {string}
|
||||
*/
|
||||
protected adjustmentFormatted = (invoice: SaleInvoice): string => {
|
||||
return this.formatMoney(invoice.adjustment, {
|
||||
currencyCode: invoice.currencyCode,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the taxes lines of sale invoice.
|
||||
* @param {ISaleInvoice} invoice
|
||||
|
||||
@@ -47,7 +47,6 @@ export class SaleInvoicePdf {
|
||||
*/
|
||||
public async getSaleInvoicePdf(invoiceId: number): Promise<[Buffer, string]> {
|
||||
const filename = await this.getInvoicePdfFilename(invoiceId);
|
||||
|
||||
const htmlContent = await this.getSaleInvoiceHtml(invoiceId);
|
||||
|
||||
// Converts the given html content to pdf document.
|
||||
|
||||
@@ -44,7 +44,10 @@ export const transformInvoiceToPdfTemplate = (
|
||||
label: tax.name,
|
||||
amount: tax.taxRateAmountFormatted,
|
||||
})),
|
||||
|
||||
discount: invoice.discountAmountFormatted,
|
||||
discountLabel: invoice.discountPercentageFormatted
|
||||
? `Discount [${invoice.discountPercentageFormatted}]`
|
||||
: 'Discount',
|
||||
customerAddress: contactAddressTextFormat(invoice.customer),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user