mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Pdf templates customer/company addresses
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Service } from 'typedi';
|
||||
import { TenantMetadata } from '@/system/models';
|
||||
import { CommonOrganizationBrandingAttributes } from './types';
|
||||
|
||||
@Service()
|
||||
export class GetOrganizationBrandingAttributes {
|
||||
/**
|
||||
* Retrieves the given organization branding attributes initial state.
|
||||
* @param {number} tenantId
|
||||
* @returns {Promise<CommonOrganizationBrandingAttributes>}
|
||||
*/
|
||||
async getOrganizationBrandingAttributes(
|
||||
tenantId: number
|
||||
): Promise<CommonOrganizationBrandingAttributes> {
|
||||
const tenantMetadata = await TenantMetadata.query().findOne({ tenantId });
|
||||
|
||||
const companyName = tenantMetadata?.name;
|
||||
const primaryColor = tenantMetadata?.primaryColor;
|
||||
const companyLogoKey = tenantMetadata?.logoKey;
|
||||
const companyLogoUri = tenantMetadata?.logoUri;
|
||||
const companyAddress = tenantMetadata?.addressTextFormatted;
|
||||
|
||||
return {
|
||||
companyName,
|
||||
companyAddress,
|
||||
companyLogoUri,
|
||||
companyLogoKey,
|
||||
primaryColor,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { GetOrganizationBrandingAttributes } from './GetOrganizationBrandingAttributes';
|
||||
|
||||
@Service()
|
||||
export class GetPdfTemplateBrandingState {
|
||||
@Inject()
|
||||
private getOrgBrandingAttributes: GetOrganizationBrandingAttributes;
|
||||
|
||||
getBrandingState(tenantId: number) {
|
||||
const brandingAttributes =
|
||||
this.getOrgBrandingAttributes.getOrganizationBrandingAttributes(tenantId);
|
||||
|
||||
return brandingAttributes;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||
import { getTransactionTypeLabel } from '@/utils/transactions-types';
|
||||
import { getUploadedObjectUri } from '../Attachments/utils';
|
||||
|
||||
export class GetPdfTemplateTransformer extends Transformer {
|
||||
/**
|
||||
@@ -56,7 +57,7 @@ class GetPdfTemplateAttributesTransformer extends Transformer {
|
||||
*/
|
||||
protected companyLogoUri(template) {
|
||||
return template.companyLogoKey
|
||||
? `https://bigcapital.sfo3.digitaloceanspaces.com/${template.companyLogoKey}`
|
||||
? getUploadedObjectUri(template.companyLogoKey)
|
||||
: '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { GetPdfTemplate } from './GetPdfTemplate';
|
||||
import { GetPdfTemplates } from './GetPdfTemplates';
|
||||
import { EditPdfTemplate } from './EditPdfTemplate';
|
||||
import { AssignPdfTemplateDefault } from './AssignPdfTemplateDefault';
|
||||
import { GetPdfTemplateBrandingState } from './GetPdfTemplateBrandingState';
|
||||
|
||||
@Service()
|
||||
export class PdfTemplateApplication {
|
||||
@@ -27,6 +28,9 @@ export class PdfTemplateApplication {
|
||||
@Inject()
|
||||
private assignPdfTemplateDefaultService: AssignPdfTemplateDefault;
|
||||
|
||||
@Inject()
|
||||
private getPdfTemplateBrandingStateService: GetPdfTemplateBrandingState;
|
||||
|
||||
/**
|
||||
* Creates a new PDF template.
|
||||
* @param {number} tenantId -
|
||||
@@ -120,4 +124,12 @@ export class PdfTemplateApplication {
|
||||
templateId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} tenantId
|
||||
*/
|
||||
public async getPdfTemplateBrandingState(tenantId: number) {
|
||||
return this.getPdfTemplateBrandingStateService.getBrandingState(tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,3 +65,12 @@ export interface ICreateInvoicePdfTemplateDTO {
|
||||
statementLabel?: string;
|
||||
showStatement?: boolean;
|
||||
}
|
||||
|
||||
|
||||
export interface CommonOrganizationBrandingAttributes {
|
||||
companyName?: string;
|
||||
primaryColor?: string;
|
||||
companyLogoKey?: string;
|
||||
companyLogoUri?: string;
|
||||
companyAddress?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user