mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
refactor: mail templates
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
import { ItemEntryTransformer } from '@/modules/TransactionItemEntry/ItemEntry.transformer';
|
||||
import { SaleEstimateTransfromer } from './SaleEstimate.transformer';
|
||||
|
||||
export class GetSaleEstimateMailStateTransformer extends SaleEstimateTransfromer {
|
||||
public excludeAttributes = (): string[] => {
|
||||
return ['*'];
|
||||
};
|
||||
|
||||
public includeAttributes = (): string[] => {
|
||||
return [
|
||||
'estimateDate',
|
||||
'estimateDateFormatted',
|
||||
|
||||
'expirationDate',
|
||||
'expirationDateFormatted',
|
||||
|
||||
'total',
|
||||
'totalFormatted',
|
||||
|
||||
'subtotal',
|
||||
'subtotalFormatted',
|
||||
|
||||
'estimateNumber',
|
||||
'entries',
|
||||
|
||||
'companyName',
|
||||
'companyLogoUri',
|
||||
|
||||
'primaryColor',
|
||||
'customerName',
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the customer name of the invoice.
|
||||
* @returns {string}
|
||||
*/
|
||||
protected customerName = (invoice) => {
|
||||
return invoice.customer.displayName;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the company name.
|
||||
* @returns {string}
|
||||
*/
|
||||
protected companyName = () => {
|
||||
return this.context.organization.name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the company logo uri.
|
||||
* @returns {string | null}
|
||||
*/
|
||||
protected companyLogoUri = (invoice) => {
|
||||
return invoice.pdfTemplate?.companyLogoUri || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the primary color.
|
||||
* @returns {string}
|
||||
*/
|
||||
protected primaryColor = (invoice) => {
|
||||
return invoice.pdfTemplate?.attributes?.primaryColor || null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the estimate number.
|
||||
*/
|
||||
protected estimateDateFormatted = (estimate) => {
|
||||
return this.formattedEstimateDate(estimate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the expiration date of the estimate.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected expirationDateFormatted = (estimate) => {
|
||||
return this.formattedExpirationDate(estimate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the total amount of the estimate.
|
||||
* @param estimate
|
||||
* @returns
|
||||
*/
|
||||
protected total(estimate) {
|
||||
return estimate.amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the subtotal amount of the estimate.
|
||||
* @param estimate
|
||||
* @returns {number}
|
||||
*/
|
||||
protected subtotal(estimate) {
|
||||
return estimate.amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the formatted total of the estimate.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected totalFormatted(estimate) {
|
||||
return this.formatMoney(estimate.amount, {
|
||||
currencyCode: estimate.currencyCode,
|
||||
money: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the formatted subtotal of the estimate.
|
||||
* @param estimate
|
||||
* @returns {string}
|
||||
*/
|
||||
protected subtotalFormatted = (estimate) => {
|
||||
return this.formatNumber(estimate.amount, { money: false });
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the estimate entries.
|
||||
* @param invoice
|
||||
* @returns {Array}
|
||||
*/
|
||||
protected entries = (invoice) => {
|
||||
return this.item(
|
||||
invoice.entries,
|
||||
new GetSaleEstimateMailStateEntryTransformer(),
|
||||
{
|
||||
currencyCode: invoice.currencyCode,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Merges the mail options with the invoice object.
|
||||
*/
|
||||
public transform = (object: any) => {
|
||||
return {
|
||||
...this.options.mailOptions,
|
||||
...object,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
class GetSaleEstimateMailStateEntryTransformer extends ItemEntryTransformer {
|
||||
public excludeAttributes = (): string[] => {
|
||||
return ['*'];
|
||||
};
|
||||
|
||||
/**
|
||||
* Item name.
|
||||
* @param entry
|
||||
* @returns
|
||||
*/
|
||||
public name = (entry) => {
|
||||
return entry.item.name;
|
||||
};
|
||||
|
||||
public includeAttributes = (): string[] => {
|
||||
return [
|
||||
'name',
|
||||
'quantity',
|
||||
'unitPrice',
|
||||
'unitPriceFormatted',
|
||||
'total',
|
||||
'totalFormatted',
|
||||
];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user