From 776b69475c5191622bf967b141687c0885d57862 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 29 Sep 2024 19:31:00 +0200 Subject: [PATCH] feat: PDF templates company/customer address --- .../src/services/Sales/Estimates/constants.ts | 21 +++--------- .../Sales/Invoices/SaleEstimatePdfTemplate.ts | 16 ++++++++- .../CreditNotePaperTemplate.tsx | 29 ++++++++-------- .../CreditNoteCustomize/constants.ts | 7 ++-- .../EstimatePaperTemplate.tsx | 25 +++++++------- .../Estimates/EstimateCustomize/constants.ts | 7 ++-- .../PaymentReceivedPaperTemplate.tsx | 33 +++++++++++-------- .../PaymentReceivedCustomize/constants.ts | 6 ++-- .../ReceiptCustomize/ReceiptPaperTemplate.tsx | 30 +++++++++-------- .../Receipts/ReceiptCustomize/constants.ts | 6 ++-- 10 files changed, 101 insertions(+), 79 deletions(-) diff --git a/packages/server/src/services/Sales/Estimates/constants.ts b/packages/server/src/services/Sales/Estimates/constants.ts index e4783e0f9..57ab68632 100644 --- a/packages/server/src/services/Sales/Estimates/constants.ts +++ b/packages/server/src/services/Sales/Estimates/constants.ts @@ -185,23 +185,10 @@ export const defaultEstimatePdfBrandingAttributes = { companyName: '', - 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', - ], - showBilledFromAddress: true, - showBilledToAddress: true, + customerAddress: '', + companyAddress: '', + showCustomerAddress: true, + showCompanyAddress: true, billedToLabel: 'Billed To', total: '$1000.00', diff --git a/packages/server/src/services/Sales/Invoices/SaleEstimatePdfTemplate.ts b/packages/server/src/services/Sales/Invoices/SaleEstimatePdfTemplate.ts index de324ea90..e0b955591 100644 --- a/packages/server/src/services/Sales/Invoices/SaleEstimatePdfTemplate.ts +++ b/packages/server/src/services/Sales/Invoices/SaleEstimatePdfTemplate.ts @@ -2,12 +2,16 @@ import { Inject, Service } from 'typedi'; import { mergePdfTemplateWithDefaultAttributes } from './utils'; import { GetPdfTemplate } from '@/services/PdfTemplate/GetPdfTemplate'; import { defaultEstimatePdfBrandingAttributes } from '../Estimates/constants'; +import { GetOrganizationBrandingAttributes } from '@/services/PdfTemplate/GetOrganizationBrandingAttributes'; @Service() export class SaleEstimatePdfTemplate { @Inject() private getPdfTemplateService: GetPdfTemplate; + @Inject() + private getOrgBrandingAttrs: GetOrganizationBrandingAttributes; + /** * Retrieves the estimate pdf template. * @param {number} tenantId @@ -19,9 +23,19 @@ export class SaleEstimatePdfTemplate { tenantId, estimateTemplateId ); + // Retreives the organization branding attributes. + const commonOrgBrandingAttrs = + await this.getOrgBrandingAttrs.getOrganizationBrandingAttributes( + tenantId + ); + + const orgainizationBrandingAttrs = { + ...defaultEstimatePdfBrandingAttributes, + ...commonOrgBrandingAttrs, + }; const attributes = mergePdfTemplateWithDefaultAttributes( template.attributes, - defaultEstimatePdfBrandingAttributes + orgainizationBrandingAttrs ); return { ...template, diff --git a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/CreditNotePaperTemplate.tsx b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/CreditNotePaperTemplate.tsx index 0362a6ae3..f19a1fd54 100644 --- a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/CreditNotePaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/CreditNotePaperTemplate.tsx @@ -14,10 +14,12 @@ import { export interface CreditNotePaperTemplateProps extends PaperTemplateProps { // Address - billedToAddress?: string; - billedFromAddress?: string; - showBilledToAddress?: boolean; - showBilledFromAddress?: boolean; + showCustomerAddress?: boolean; + customerAddress?: string; + + showCompanyAddress?: boolean; + companyAddress?: string; + billedToLabel?: string; // Total @@ -72,11 +74,12 @@ export function CreditNotePaperTemplate({ companyName = 'Bigcapital Technology, Inc.', // Address - billedToAddress = DefaultPdfTemplateAddressBilledTo, - billedFromAddress = DefaultPdfTemplateAddressBilledFrom, + showCustomerAddress = true, + customerAddress = DefaultPdfTemplateAddressBilledTo, + + showCompanyAddress = true, + companyAddress = DefaultPdfTemplateAddressBilledFrom, - showBilledFromAddress = true, - showBilledToAddress = true, billedToLabel = 'Billed To', // Total @@ -141,16 +144,16 @@ export function CreditNotePaperTemplate({ - {showBilledFromAddress && ( + {showCompanyAddress && ( - {companyName} - + )} - {showBilledToAddress && ( + + {showCustomerAddress && ( {billedToLabel} - + )} diff --git a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/constants.ts b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/constants.ts index 67d421193..c426247d7 100644 --- a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/constants.ts +++ b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteCustomize/constants.ts @@ -11,9 +11,10 @@ export const initialValues = { companyLogoUri: '', // Address - showBilledToAddress: true, - showBilledFromAddress: true, - billedToLabel: 'Bill To', + showCustomerAddress: true, + showCompanyAddress: true, + companyAddress: '', + billedToLabel: 'Billed To', // Entries itemNameLabel: 'Item', diff --git a/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/EstimatePaperTemplate.tsx b/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/EstimatePaperTemplate.tsx index 0426b9a30..5dddf78a4 100644 --- a/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/EstimatePaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/EstimatePaperTemplate.tsx @@ -32,11 +32,11 @@ export interface EstimatePaperTemplateProps extends PaperTemplateProps { companyName?: string; // Address - showBilledToAddress?: boolean; - billedToAddress?: string; + showCustomerAddress?: boolean; + customerAddress?: string; - showBilledFromAddress?: boolean; - billedFromAddress?: string; + showCompanyAddress?: boolean; + companyAddress?: string; billedToLabel?: string; // Totals @@ -77,10 +77,10 @@ export function EstimatePaperTemplate({ companyName, // # Address - billedToAddress = DefaultPdfTemplateAddressBilledTo, - billedFromAddress = DefaultPdfTemplateAddressBilledFrom, - showBilledFromAddress = true, - showBilledToAddress = true, + customerAddress = DefaultPdfTemplateAddressBilledTo, + companyAddress = DefaultPdfTemplateAddressBilledFrom, + showCompanyAddress = true, + showCustomerAddress = true, billedToLabel = 'Billed To', // #Total @@ -151,16 +151,15 @@ export function EstimatePaperTemplate({ - {showBilledFromAddress && ( + {showCompanyAddress && ( - {companyName} - + )} - {showBilledToAddress && ( + {showCustomerAddress && ( {billedToLabel} - + )} diff --git a/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/constants.ts b/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/constants.ts index 8f5046849..4bcb5b7a9 100644 --- a/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/constants.ts +++ b/packages/webapp/src/containers/Sales/Estimates/EstimateCustomize/constants.ts @@ -24,8 +24,10 @@ export const initialValues = { companyName: 'Bigcapital Technology, Inc.', // Addresses - showBilledFromAddress: true, - showBilledToAddress: true, + showCustomerAddress: true, + showCompanyAddress: true, + customerAddress: '', + companyAddress: '', billedToLabel: 'Billed To', // Entries @@ -45,6 +47,7 @@ export const initialValues = { showCustomerNote: true, customerNoteLabel: 'Customer Note', + // Terms & Conditions showTermsConditions: true, termsConditionsLabel: 'Terms & Conditions', }; diff --git a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/PaymentReceivedPaperTemplate.tsx b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/PaymentReceivedPaperTemplate.tsx index 496afddd1..3ef62ed7f 100644 --- a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/PaymentReceivedPaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/PaymentReceivedPaperTemplate.tsx @@ -10,11 +10,14 @@ import { } from '@/constants/PdfTemplates'; export interface PaymentReceivedPaperTemplateProps extends PaperTemplateProps { - billedToAddress?: string; - showBilledToAddress?: boolean; + // Customer address + showCustomerAddress?: boolean; + customerAddress?: string; + + // Company address + showCompanyAddress?: boolean; + companyAddress?: string; - billedFromAddress?: string; - showBilledFromAddress?: boolean; billedToLabel?: string; // Total. @@ -56,10 +59,14 @@ export function PaymentReceivedPaperTemplate({ // # Company name companyName = 'Bigcapital Technology, Inc.', - billedToAddress = DefaultPdfTemplateAddressBilledTo, - billedFromAddress = DefaultPdfTemplateAddressBilledFrom, - showBilledFromAddress, - showBilledToAddress, + // # Customer address + showCustomerAddress = true, + customerAddress = DefaultPdfTemplateAddressBilledTo, + + // # Company address + showCompanyAddress = true, + companyAddress = DefaultPdfTemplateAddressBilledFrom, + billedToLabel = 'Billed To', total = '$1000.00', @@ -109,16 +116,16 @@ export function PaymentReceivedPaperTemplate({ - {showBilledFromAddress && ( + {showCompanyAddress && ( - {companyName} - + )} - {showBilledToAddress && ( + + {showCustomerAddress && ( {billedToLabel} - + )} diff --git a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/constants.ts b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/constants.ts index e9aef8a0e..46181004c 100644 --- a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/constants.ts +++ b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedCustomize/constants.ts @@ -21,8 +21,10 @@ export const initialValues = { companyName: 'Bigcapital Technology, Inc.', // Addresses - showBilledFromAddress: true, - showBillingToAddress: true, + showCustomerAddress: true, + showCompanyAddress: true, + customerAddress: '', + companyAddress: '', billedToLabel: 'Billed To', // Entries diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptPaperTemplate.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptPaperTemplate.tsx index 00faba13b..30bb31c1e 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptPaperTemplate.tsx +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/ReceiptPaperTemplate.tsx @@ -14,10 +14,12 @@ import { export interface ReceiptPaperTemplateProps extends PaperTemplateProps { // Addresses - billedToAddress?: string; - billedFromAddress?: string; - showBilledFromAddress?: boolean; - showBilledToAddress?: boolean; + showCustomerAddress?: boolean; + customerAddress?: string; + + showCompanyAddress?: boolean; + companyAddress?: string; + billedToLabel?: string; // Total @@ -73,10 +75,12 @@ export function ReceiptPaperTemplate({ companyName = 'Bigcapital Technology, Inc.', // # Address - billedToAddress = DefaultPdfTemplateAddressBilledTo, - billedFromAddress = DefaultPdfTemplateAddressBilledFrom, - showBilledFromAddress = true, - showBilledToAddress = true, + showCustomerAddress = true, + customerAddress = DefaultPdfTemplateAddressBilledTo, + + showCompanyAddress = true, + companyAddress = DefaultPdfTemplateAddressBilledFrom, + billedToLabel = 'Billed To', total = '$1000.00', @@ -135,16 +139,16 @@ export function ReceiptPaperTemplate({ - {showBilledFromAddress && ( + {showCompanyAddress && ( - {companyName} - + )} - {showBilledToAddress && ( + + {showCustomerAddress && ( {billedToLabel} - + )} diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/constants.ts b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/constants.ts index 6f67d5a48..8f571d260 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/constants.ts +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptCustomize/constants.ts @@ -22,8 +22,10 @@ export const initialValues = { companyName: 'Bigcapital Technology, Inc.', // Addresses - showBilledFromAddress: true, - showBilledToAddress: true, + showCompanyAddress: true, + showCustomerAddress: true, + companyAddress: '', + customerAddress: '', billedToLabel: 'Billed To', // Entries