diff --git a/packages/server/src/models/PdfTemplate.ts b/packages/server/src/models/PdfTemplate.ts index 5cf27f358..ccf5f48d2 100644 --- a/packages/server/src/models/PdfTemplate.ts +++ b/packages/server/src/models/PdfTemplate.ts @@ -1,6 +1,9 @@ +import { getUploadedObjectUri } from '@/services/Attachments/utils'; import TenantModel from 'models/TenantModel'; export class PdfTemplate extends TenantModel { + public readonly attributes: Record; + /** * Table name. */ @@ -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) + : ''; } /** diff --git a/packages/server/src/services/CreditNotes/CreditNoteBrandingTemplate.ts b/packages/server/src/services/CreditNotes/CreditNoteBrandingTemplate.ts index 872f16ef4..ef0150747 100644 --- a/packages/server/src/services/CreditNotes/CreditNoteBrandingTemplate.ts +++ b/packages/server/src/services/CreditNotes/CreditNoteBrandingTemplate.ts @@ -35,9 +35,12 @@ export class CreditNoteBrandingTemplate { ...defaultCreditNoteBrandingAttributes, ...commonOrgBrandingAttrs, }; - + const brandingTemplateAttrs = { + ...template.attributes, + companyLogoUri: template.companyLogoUri, + }; const attributes = mergePdfTemplateWithDefaultAttributes( - template.attributes, + brandingTemplateAttrs, organizationBrandingAttrs ); return { diff --git a/packages/server/src/services/PdfTemplate/GetPdfTemplateTransformer.ts b/packages/server/src/services/PdfTemplate/GetPdfTemplateTransformer.ts index fddc28c59..5d7470018 100644 --- a/packages/server/src/services/PdfTemplate/GetPdfTemplateTransformer.ts +++ b/packages/server/src/services/PdfTemplate/GetPdfTemplateTransformer.ts @@ -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[] => { @@ -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) - : ''; - } } diff --git a/packages/server/src/services/PdfTemplate/types.ts b/packages/server/src/services/PdfTemplate/types.ts index 6fad632ab..de1029afa 100644 --- a/packages/server/src/services/PdfTemplate/types.ts +++ b/packages/server/src/services/PdfTemplate/types.ts @@ -66,7 +66,6 @@ export interface ICreateInvoicePdfTemplateDTO { showStatement?: boolean; } - export interface CommonOrganizationBrandingAttributes { companyName?: string; primaryColor?: string; diff --git a/packages/server/src/services/Sales/Invoices/GetInvoicePaymentMailAttributesTransformer.ts b/packages/server/src/services/Sales/Invoices/GetInvoicePaymentMailAttributesTransformer.ts index 976b5053f..1ac116064 100644 --- a/packages/server/src/services/Sales/Invoices/GetInvoicePaymentMailAttributesTransformer.ts +++ b/packages/server/src/services/Sales/Invoices/GetInvoicePaymentMailAttributesTransformer.ts @@ -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 { diff --git a/packages/server/src/services/Sales/Invoices/GetSaleInvoiceMailState.ts b/packages/server/src/services/Sales/Invoices/GetSaleInvoiceMailState.ts index c32fa2430..6f00dd08d 100644 --- a/packages/server/src/services/Sales/Invoices/GetSaleInvoiceMailState.ts +++ b/packages/server/src/services/Sales/Invoices/GetSaleInvoiceMailState.ts @@ -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} diff --git a/packages/server/src/services/Sales/Invoices/GetSaleInvoiceMailStateTransformer.ts b/packages/server/src/services/Sales/Invoices/GetSaleInvoiceMailStateTransformer.ts index 75d3d1f62..e1676d845 100644 --- a/packages/server/src/services/Sales/Invoices/GetSaleInvoiceMailStateTransformer.ts +++ b/packages/server/src/services/Sales/Invoices/GetSaleInvoiceMailStateTransformer.ts @@ -1,4 +1,3 @@ -import { Transformer } from '@/lib/Transformer/Transformer'; import { SaleInvoiceTransformer } from './SaleInvoiceTransformer'; import { ItemEntryTransformer } from './ItemEntryTransformer'; @@ -11,6 +10,10 @@ export class GetSaleInvoiceMailStateTransformer extends SaleInvoiceTransformer { return ['*']; }; + /** + * Included attributes. + * @returns {Array} + */ public includeAttributes = (): string[] => { return [ 'invoiceDate', @@ -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; }; diff --git a/packages/server/src/services/Sales/Invoices/SaleEstimatePdfTemplate.ts b/packages/server/src/services/Sales/Invoices/SaleEstimatePdfTemplate.ts index 54048619a..544468b49 100644 --- a/packages/server/src/services/Sales/Invoices/SaleEstimatePdfTemplate.ts +++ b/packages/server/src/services/Sales/Invoices/SaleEstimatePdfTemplate.ts @@ -33,8 +33,12 @@ export class SaleEstimatePdfTemplate { ...defaultEstimatePdfBrandingAttributes, ...commonOrgBrandingAttrs, }; + const brandingTemplateAttrs = { + ...template.attributes, + companyLogoUri: template.companyLogoUri, + }; const attributes = mergePdfTemplateWithDefaultAttributes( - template.attributes, + brandingTemplateAttrs, orgainizationBrandingAttrs ); return { diff --git a/packages/server/src/services/Sales/Invoices/SaleInvoicePdfTemplate.ts b/packages/server/src/services/Sales/Invoices/SaleInvoicePdfTemplate.ts index ca1f8c142..e7cffd69f 100644 --- a/packages/server/src/services/Sales/Invoices/SaleInvoicePdfTemplate.ts +++ b/packages/server/src/services/Sales/Invoices/SaleInvoicePdfTemplate.ts @@ -32,8 +32,12 @@ export class SaleInvoicePdfTemplate { ...defaultInvoicePdfTemplateAttributes, ...commonOrgBrandingAttrs, }; + const brandingTemplateAttrs = { + ...template.attributes, + companyLogoUri: template.companyLogoUri, + }; const attributes = mergePdfTemplateWithDefaultAttributes( - template.attributes, + brandingTemplateAttrs, organizationBrandingAttrs ); return { diff --git a/packages/server/src/services/Sales/Invoices/SaleInvoicesApplication.ts b/packages/server/src/services/Sales/Invoices/SaleInvoicesApplication.ts index e04ce4439..5490bec44 100644 --- a/packages/server/src/services/Sales/Invoices/SaleInvoicesApplication.ts +++ b/packages/server/src/services/Sales/Invoices/SaleInvoicesApplication.ts @@ -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() @@ -366,7 +364,10 @@ export class SaleInvoiceApplication { * @param {number} saleInvoiceid * @returns {Promise} */ - public getSaleInvoiceMailState(tenantId: number, saleInvoiceid: number) { + public getSaleInvoiceMailState( + tenantId: number, + saleInvoiceid: number + ): Promise { return this.getSaleInvoiceMailStateService.getInvoiceMailState( tenantId, saleInvoiceid diff --git a/packages/server/src/services/Sales/PaymentReceived/PaymentReceivedBrandingTemplate.ts b/packages/server/src/services/Sales/PaymentReceived/PaymentReceivedBrandingTemplate.ts index 5e7c89fb7..d7a88bf6b 100644 --- a/packages/server/src/services/Sales/PaymentReceived/PaymentReceivedBrandingTemplate.ts +++ b/packages/server/src/services/Sales/PaymentReceived/PaymentReceivedBrandingTemplate.ts @@ -37,8 +37,12 @@ export class PaymentReceivedBrandingTemplate { ...defaultPaymentReceivedPdfTemplateAttributes, ...commonOrgBrandingAttrs, }; + const brandingTemplateAttrs = { + ...template.attributes, + companyLogoUri: template.companyLogoUri, + }; const attributes = mergePdfTemplateWithDefaultAttributes( - template.attributes, + brandingTemplateAttrs, organizationBrandingAttrs ); return { diff --git a/packages/server/src/services/Sales/Receipts/SaleReceiptBrandingTemplate.ts b/packages/server/src/services/Sales/Receipts/SaleReceiptBrandingTemplate.ts index 1cef714b9..12689d7cd 100644 --- a/packages/server/src/services/Sales/Receipts/SaleReceiptBrandingTemplate.ts +++ b/packages/server/src/services/Sales/Receipts/SaleReceiptBrandingTemplate.ts @@ -37,8 +37,12 @@ export class SaleReceiptBrandingTemplate { ...defaultSaleReceiptBrandingAttributes, ...commonOrgBrandingAttrs, }; + const brandingTemplateAttrs = { + ...template.attributes, + companyLogoUri: template.companyLogoUri, + }; const attributes = mergePdfTemplateWithDefaultAttributes( - template.attributes, + brandingTemplateAttrs, organizationBrandingAttrs ); return { diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/InvoiceMailReceipt.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/InvoiceMailReceipt.tsx index 02801698a..7669a1fc9 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/InvoiceMailReceipt.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceCustomize/InvoiceMailReceipt.tsx @@ -93,6 +93,7 @@ export function InvoiceMailReceipt({ h="90px" w="90px" mx="auto" + borderRadius="3px" backgroundRepeat="no-repeat" backgroundPosition="center center" backgroundSize="contain" diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx index b93d26696..fe593a4ca 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceSendMailDrawer/InvoiceMailReceiptPreviewConnected..tsx @@ -25,7 +25,7 @@ export function InvoiceMailReceiptPreviewConneceted() {