Skip to content

Commit

Permalink
Merge pull request #736 from bigcapitalhq/fix-company-logo-mail-receipt
Browse files Browse the repository at this point in the history
fix: company logo does not show up in mail receipt preview
  • Loading branch information
abouolia authored Nov 3, 2024
2 parents ba1d9b3 + 6ba54a9 commit 4879574
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 31 deletions.
15 changes: 14 additions & 1 deletion packages/server/src/models/PdfTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { getUploadedObjectUri } from '@/services/Attachments/utils';
import TenantModel from 'models/TenantModel';

export class PdfTemplate extends TenantModel {
public readonly attributes: Record<string, any>;

/**
* Table name.
*/
Expand Down Expand Up @@ -47,7 +50,17 @@ export class PdfTemplate extends TenantModel {
* Virtual attributes.
*/
static get virtualAttributes() {
return [];
return ['companyLogoUri'];
}

/**
* Retrieves the company logo uri.
* @returns {string}
*/
get companyLogoUri() {
return this.attributes.companyLogoKey
? getUploadedObjectUri(this.attributes.companyLogoKey)
: '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ export class CreditNoteBrandingTemplate {
...defaultCreditNoteBrandingAttributes,
...commonOrgBrandingAttrs,
};

const brandingTemplateAttrs = {
...template.attributes,
companyLogoUri: template.companyLogoUri,
};
const attributes = mergePdfTemplateWithDefaultAttributes(
template.attributes,
brandingTemplateAttrs,
organizationBrandingAttrs
);
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Transformer } from '@/lib/Transformer/Transformer';
import { getTransactionTypeLabel } from '@/utils/transactions-types';
import { getUploadedObjectUri } from '../Attachments/utils';

export class GetPdfTemplateTransformer extends Transformer {
/**
* Includeded attributes.
* Included attributes.
* @returns {string[]}
*/
public includeAttributes = (): string[] => {
Expand Down Expand Up @@ -44,20 +43,10 @@ export class GetPdfTemplateTransformer extends Transformer {

class GetPdfTemplateAttributesTransformer extends Transformer {
/**
* Includeded attributes.
* Included attributes.
* @returns {string[]}
*/
public includeAttributes = (): string[] => {
return ['companyLogoUri'];
return [];
};

/**
* Retrieves the company logo uri.
* @returns {string}
*/
protected companyLogoUri(template) {
return template.companyLogoKey
? getUploadedObjectUri(template.companyLogoKey)
: '';
}
}
1 change: 0 additions & 1 deletion packages/server/src/services/PdfTemplate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface ICreateInvoicePdfTemplateDTO {
showStatement?: boolean;
}


export interface CommonOrganizationBrandingAttributes {
companyName?: string;
primaryColor?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class GetInvoiceMailTemplateAttributesTransformer extends Transformer {
};

public companyLogoUri(): string {
return this.options.brandingTemplate?.attributes?.companyLogoUri;
return this.options.brandingTemplate?.companyLogoUri;
}

public companyName(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class GetSaleInvoiceMailState {
/**
* Retrieves the invoice mail state of the given sale invoice.
* Invoice mail state includes the mail options, branding attributes and the invoice details.
*
* @param {number} tenantId
* @param {number} saleInvoiceId
* @returns {Promise<SaleInvoiceMailState>}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Transformer } from '@/lib/Transformer/Transformer';
import { SaleInvoiceTransformer } from './SaleInvoiceTransformer';
import { ItemEntryTransformer } from './ItemEntryTransformer';

Expand All @@ -11,6 +10,10 @@ export class GetSaleInvoiceMailStateTransformer extends SaleInvoiceTransformer {
return ['*'];
};

/**
* Included attributes.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return [
'invoiceDate',
Expand Down Expand Up @@ -39,14 +42,26 @@ export class GetSaleInvoiceMailStateTransformer extends SaleInvoiceTransformer {
];
};

/**
* 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?.attributes?.companyLogoUri;
return invoice.pdfTemplate?.companyLogoUri;
};

/**
* Retrieves the primary color.
* @returns {string}
*/
protected primaryColor = (invoice) => {
return invoice.pdfTemplate?.attributes?.primaryColor;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ export class SaleEstimatePdfTemplate {
...defaultEstimatePdfBrandingAttributes,
...commonOrgBrandingAttrs,
};
const brandingTemplateAttrs = {
...template.attributes,
companyLogoUri: template.companyLogoUri,
};
const attributes = mergePdfTemplateWithDefaultAttributes(
template.attributes,
brandingTemplateAttrs,
orgainizationBrandingAttrs
);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ export class SaleInvoicePdfTemplate {
...defaultInvoicePdfTemplateAttributes,
...commonOrgBrandingAttrs,
};
const brandingTemplateAttrs = {
...template.attributes,
companyLogoUri: template.companyLogoUri,
};
const attributes = mergePdfTemplateWithDefaultAttributes(
template.attributes,
brandingTemplateAttrs,
organizationBrandingAttrs
);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import { GetInvoicePaymentsService } from './GetInvoicePaymentsService';
import { SaleInvoiceNotifyBySms } from './SaleInvoiceNotifyBySms';
import { SendInvoiceMailReminder } from './SendSaleInvoiceMailReminder';
import { SendSaleInvoiceMail } from './SendSaleInvoiceMail';
import { GetSaleInvoiceMailReminder } from './GetSaleInvoiceMailReminder';
import { GetSaleInvoiceState } from './GetSaleInvoiceState';
import { GetSaleInvoiceBrandTemplate } from './GetSaleInvoiceBrandTemplate';
import { GetSaleInvoiceMailState } from './GetSaleInvoiceMailState';

@Service()
Expand Down Expand Up @@ -366,7 +364,10 @@ export class SaleInvoiceApplication {
* @param {number} saleInvoiceid
* @returns {Promise<SaleInvoiceMailState>}
*/
public getSaleInvoiceMailState(tenantId: number, saleInvoiceid: number) {
public getSaleInvoiceMailState(
tenantId: number,
saleInvoiceid: number
): Promise<SaleInvoiceMailState> {
return this.getSaleInvoiceMailStateService.getInvoiceMailState(
tenantId,
saleInvoiceid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export class PaymentReceivedBrandingTemplate {
...defaultPaymentReceivedPdfTemplateAttributes,
...commonOrgBrandingAttrs,
};
const brandingTemplateAttrs = {
...template.attributes,
companyLogoUri: template.companyLogoUri,
};
const attributes = mergePdfTemplateWithDefaultAttributes(
template.attributes,
brandingTemplateAttrs,
organizationBrandingAttrs
);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export class SaleReceiptBrandingTemplate {
...defaultSaleReceiptBrandingAttributes,
...commonOrgBrandingAttrs,
};
const brandingTemplateAttrs = {
...template.attributes,
companyLogoUri: template.companyLogoUri,
};
const attributes = mergePdfTemplateWithDefaultAttributes(
template.attributes,
brandingTemplateAttrs,
organizationBrandingAttrs
);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function InvoiceMailReceipt({
h="90px"
w="90px"
mx="auto"
borderRadius="3px"
backgroundRepeat="no-repeat"
backgroundPosition="center center"
backgroundSize="contain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function InvoiceMailReceiptPreviewConneceted() {
<Box px={4} pt={8} pb={16}>
<InvoiceMailReceiptPreview
companyName={invoiceMailState?.companyName}
// companyLogoUri={invoiceMailState?.companyLogoUri}
companyLogoUri={invoiceMailState?.companyLogoUri}

primaryColor={invoiceMailState?.primaryColor}
total={invoiceMailState?.totalFormatted}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import React, { createContext, useContext } from 'react';
import { Spinner } from '@blueprintjs/core';
import {
Expand Down
1 change: 1 addition & 0 deletions packages/webapp/src/hooks/query/invoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export function useSendSaleInvoiceMail(
// --------------------------------------
export interface GetSaleInvoiceDefaultOptionsResponse {
companyName: string;
companyLogoUri: string;

dueDate: string;
dueDateFormatted: string;
Expand Down

0 comments on commit 4879574

Please sign in to comment.