mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Hook up customer/company address to pdf templates
This commit is contained in:
@@ -1,26 +1,44 @@
|
||||
import { Inject } from "typedi";
|
||||
import { GetPdfTemplate } from "../PdfTemplate/GetPdfTemplate";
|
||||
import { defaultCreditNoteBrandingAttributes } from "./constants";
|
||||
import { mergePdfTemplateWithDefaultAttributes } from "../Sales/Invoices/utils";
|
||||
import { Inject } from 'typedi';
|
||||
import { GetPdfTemplate } from '../PdfTemplate/GetPdfTemplate';
|
||||
import { defaultCreditNoteBrandingAttributes } from './constants';
|
||||
import { mergePdfTemplateWithDefaultAttributes } from '../Sales/Invoices/utils';
|
||||
import { GetOrganizationBrandingAttributes } from '../PdfTemplate/GetOrganizationBrandingAttributes';
|
||||
|
||||
export class CreditNoteBrandingTemplate {
|
||||
@Inject()
|
||||
private getPdfTemplateService: GetPdfTemplate;
|
||||
|
||||
@Inject()
|
||||
private getOrgBrandingAttributes: GetOrganizationBrandingAttributes;
|
||||
|
||||
/**
|
||||
* Retrieves the credit note branding template.
|
||||
* @param {number} tenantId
|
||||
* @param {number} templateId
|
||||
* @param {number} tenantId
|
||||
* @param {number} templateId
|
||||
* @returns {}
|
||||
*/
|
||||
public async getCreditNoteBrandingTemplate(tenantId: number, templateId: number) {
|
||||
public async getCreditNoteBrandingTemplate(
|
||||
tenantId: number,
|
||||
templateId: number
|
||||
) {
|
||||
const template = await this.getPdfTemplateService.getPdfTemplate(
|
||||
tenantId,
|
||||
templateId
|
||||
);
|
||||
// Retrieves the organization branding attributes.
|
||||
const commonOrgBrandingAttrs =
|
||||
await this.getOrgBrandingAttributes.getOrganizationBrandingAttributes(
|
||||
tenantId
|
||||
);
|
||||
// Merges the default branding attributes with common organization branding attrs.
|
||||
const organizationBrandingAttrs = {
|
||||
...defaultCreditNoteBrandingAttributes,
|
||||
...commonOrgBrandingAttrs,
|
||||
};
|
||||
|
||||
const attributes = mergePdfTemplateWithDefaultAttributes(
|
||||
template.attributes,
|
||||
defaultCreditNoteBrandingAttributes
|
||||
organizationBrandingAttrs
|
||||
);
|
||||
return {
|
||||
...template,
|
||||
|
||||
@@ -34,8 +34,6 @@ export default class GetCreditNotePdf {
|
||||
tenantId,
|
||||
creditNoteId
|
||||
);
|
||||
console.log(brandingAttributes, 'brandingAttributes');
|
||||
|
||||
const htmlContent = await this.templateInjectable.render(
|
||||
tenantId,
|
||||
'modules/credit-note-standard',
|
||||
|
||||
@@ -80,24 +80,13 @@ export const defaultCreditNoteBrandingAttributes = {
|
||||
// # Company name
|
||||
companyName: 'Bigcapital Technology, Inc.',
|
||||
|
||||
// Address
|
||||
billedToAddress: [
|
||||
'Bigcapital Technology, Inc.',
|
||||
'131 Continental Dr Suite 305 Newark,',
|
||||
'Delaware 19713',
|
||||
'United States',
|
||||
'+1 762-339-5634',
|
||||
'ahmed@bigcapital.app',
|
||||
],
|
||||
billedFromAddress: [
|
||||
'131 Continental Dr Suite 305 Newark,',
|
||||
'Delaware 19713',
|
||||
'United States',
|
||||
'+1 762-339-5634',
|
||||
'ahmed@bigcapital.app',
|
||||
],
|
||||
showBilledToAddress: true,
|
||||
showBilledFromAddress: true,
|
||||
// # Customer address
|
||||
showCustomerAddress: true,
|
||||
customerAddress: '',
|
||||
|
||||
// # Company address
|
||||
showCompanyAddress: true,
|
||||
companyAddress: '',
|
||||
billedToLabel: 'Billed To',
|
||||
|
||||
// Total
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { CreditNotePdfTemplateAttributes, ICreditNote } from '@/interfaces';
|
||||
import { contactAddressTextFormat } from '@/utils/address-text-format';
|
||||
|
||||
export const transformCreditNoteToPdfTemplate = (
|
||||
creditNote: ICreditNote
|
||||
@@ -19,5 +20,6 @@ export const transformCreditNoteToPdfTemplate = (
|
||||
})),
|
||||
customerNote: creditNote.note,
|
||||
termsConditions: creditNote.termsConditions,
|
||||
customerAddress: contactAddressTextFormat(creditNote.customer),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user