mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { Inject, Service } from 'typedi';
|
|
import { mergePdfTemplateWithDefaultAttributes } from './utils';
|
|
import { GetPdfTemplate } from '@/services/PdfTemplate/GetPdfTemplate';
|
|
import { defaultInvoicePdfTemplateAttributes } from './constants';
|
|
import { GetOrganizationBrandingAttributes } from '@/services/PdfTemplate/GetOrganizationBrandingAttributes';
|
|
|
|
@Service()
|
|
export class SaleInvoicePdfTemplate {
|
|
@Inject()
|
|
private getPdfTemplateService: GetPdfTemplate;
|
|
|
|
@Inject()
|
|
private getOrgBrandingAttributes: GetOrganizationBrandingAttributes;
|
|
|
|
/**
|
|
* Retrieves the invoice pdf template.
|
|
* @param {number} tenantId
|
|
* @param {number} invoiceTemplateId
|
|
* @returns
|
|
*/
|
|
async getInvoicePdfTemplate(tenantId: number, invoiceTemplateId: number) {
|
|
const template = await this.getPdfTemplateService.getPdfTemplate(
|
|
tenantId,
|
|
invoiceTemplateId
|
|
);
|
|
// Retrieves the organization branding attributes.
|
|
const commonOrgBrandingAttrs =
|
|
await this.getOrgBrandingAttributes.getOrganizationBrandingAttributes(
|
|
tenantId
|
|
);
|
|
const organizationBrandingAttrs = {
|
|
...defaultInvoicePdfTemplateAttributes,
|
|
...commonOrgBrandingAttrs,
|
|
};
|
|
const brandingTemplateAttrs = {
|
|
...template.attributes,
|
|
companyLogoUri: template.companyLogoUri,
|
|
};
|
|
const attributes = mergePdfTemplateWithDefaultAttributes(
|
|
brandingTemplateAttrs,
|
|
organizationBrandingAttrs
|
|
);
|
|
return {
|
|
...template,
|
|
attributes,
|
|
};
|
|
}
|
|
}
|