mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat: Hook up customer/company address to pdf templates
This commit is contained in:
@@ -150,17 +150,14 @@ block content
|
|||||||
div(class=`${prefix}-terms-item__value`) #{creditNoteDate}
|
div(class=`${prefix}-terms-item__value`) #{creditNoteDate}
|
||||||
|
|
||||||
div(class=`${prefix}-address-section`)
|
div(class=`${prefix}-address-section`)
|
||||||
if showBilledFromAddress
|
if showCompanyAddress
|
||||||
div(class=`${prefix}-address`)
|
div(class=`${prefix}-address-from`)
|
||||||
strong #{companyName}
|
div !{companyAddress}
|
||||||
each address in billedFromAddress
|
|
||||||
div #{address}
|
|
||||||
|
|
||||||
if showBilledToAddress
|
if showCustomerAddress
|
||||||
div(class=`${prefix}-address`)
|
div(class=`${prefix}-address-to`)
|
||||||
strong #{billedToLabel}
|
strong #{billedToLabel}
|
||||||
each address in billedToAddress
|
div !{customerAddress}
|
||||||
div #{address}
|
|
||||||
|
|
||||||
table(class=`${prefix}-table`)
|
table(class=`${prefix}-table`)
|
||||||
thead
|
thead
|
||||||
|
|||||||
@@ -156,17 +156,14 @@ block content
|
|||||||
|
|
||||||
//- Addresses (Group section)
|
//- Addresses (Group section)
|
||||||
div(class=`${prefix}-addresses`)
|
div(class=`${prefix}-addresses`)
|
||||||
if showBilledFromAddress
|
if showCompanyAddress
|
||||||
div(class=`${prefix}-address`)
|
div(class=`${prefix}-address-from`)
|
||||||
strong #{companyName}
|
div !{companyAddress}
|
||||||
each item in billedFromAddress
|
|
||||||
div(class=`${prefix}-address__item`) #{item}
|
|
||||||
|
|
||||||
if showBilledToAddress
|
if showCustomerAddress
|
||||||
div(class=`${prefix}-address`)
|
div(class=`${prefix}-address-to`)
|
||||||
strong #{billedToLabel}
|
strong #{billedToLabel}
|
||||||
each item in billedToAddress
|
div !{customerAddress}
|
||||||
div(class=`${prefix}-address__item`) #{item}
|
|
||||||
|
|
||||||
//- Table section (Line items)
|
//- Table section (Line items)
|
||||||
table(class=`${prefix}-table`)
|
table(class=`${prefix}-table`)
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ block content
|
|||||||
|
|
||||||
if showCustomerAddress
|
if showCustomerAddress
|
||||||
div(class=`${prefix}-address-to`)
|
div(class=`${prefix}-address-to`)
|
||||||
|
strong #{billedToLabel}
|
||||||
div !{customerAddress}
|
div !{customerAddress}
|
||||||
|
|
||||||
//- Invoice table
|
//- Invoice table
|
||||||
|
|||||||
@@ -140,17 +140,14 @@ block content
|
|||||||
div(class=`${prefix}-terms-item__value`) #{paymentReceivedDate}
|
div(class=`${prefix}-terms-item__value`) #{paymentReceivedDate}
|
||||||
|
|
||||||
div(class=`${prefix}-addresses`)
|
div(class=`${prefix}-addresses`)
|
||||||
if showBilledFromAddress
|
if showCompanyAddress
|
||||||
div(class=`${prefix}-address`)
|
div(class=`${prefix}-address-from`)
|
||||||
strong(class=`${prefix}-address__item`) #{companyName}
|
div !{companyAddress}
|
||||||
each addressLine in billedFromAddress
|
|
||||||
div(class=`${prefix}-address__item`) #{addressLine}
|
|
||||||
|
|
||||||
if showBillingToAddress
|
if showCustomerAddress
|
||||||
div(class=`${prefix}-address`)
|
div(class=`${prefix}-address-to`)
|
||||||
strong(class=`${prefix}-address__item`) #{billedToLabel}
|
strong #{billedToLabel}
|
||||||
each addressLine in billedToAddress
|
div !{customerAddress}
|
||||||
div(class=`${prefix}-address__item`) #{addressLine}
|
|
||||||
|
|
||||||
table(class=`${prefix}-table`)
|
table(class=`${prefix}-table`)
|
||||||
thead
|
thead
|
||||||
|
|||||||
@@ -146,17 +146,14 @@ block content
|
|||||||
|
|
||||||
//- Address Section
|
//- Address Section
|
||||||
div(class=`${prefix}-address-section`)
|
div(class=`${prefix}-address-section`)
|
||||||
if showBilledFromAddress
|
if showCompanyAddress
|
||||||
div(class=`${prefix}-address`)
|
div(class=`${prefix}-address-from`)
|
||||||
strong= companyName
|
div !{companyAddress}
|
||||||
each addressLine in billedFromAddress
|
|
||||||
div= addressLine
|
|
||||||
|
|
||||||
if showBilledToAddress
|
if showCustomerAddress
|
||||||
div(class=`${prefix}-address`)
|
div(class=`${prefix}-address-to`)
|
||||||
strong= billedToLabel
|
strong #{billedToLabel}
|
||||||
each addressLine in billedToAddress
|
div !{customerAddress}
|
||||||
div= addressLine
|
|
||||||
|
|
||||||
//- Table Section
|
//- Table Section
|
||||||
table(class=`${prefix}-table`)
|
table(class=`${prefix}-table`)
|
||||||
|
|||||||
@@ -262,16 +262,24 @@ export type ICreditNoteGLCommonEntry = Pick<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
export interface CreditNotePdfTemplateAttributes {
|
export interface CreditNotePdfTemplateAttributes {
|
||||||
|
// # Primary color
|
||||||
primaryColor: string;
|
primaryColor: string;
|
||||||
secondaryColor: string;
|
secondaryColor: string;
|
||||||
|
|
||||||
|
// # Company logo
|
||||||
showCompanyLogo: boolean;
|
showCompanyLogo: boolean;
|
||||||
companyLogo: string;
|
companyLogo: string;
|
||||||
|
|
||||||
|
// # Company name
|
||||||
companyName: string;
|
companyName: string;
|
||||||
|
|
||||||
billedToAddress: string[];
|
// # Customer Address
|
||||||
billedFromAddress: string[];
|
showCustomerAddress: boolean;
|
||||||
showBilledToAddress: boolean;
|
customerAddress: string;
|
||||||
showBilledFromAddress: boolean;
|
|
||||||
|
// # Company address
|
||||||
|
showCompanyAddress: boolean;
|
||||||
|
companyAddress: string;
|
||||||
billedToLabel: string;
|
billedToLabel: string;
|
||||||
|
|
||||||
total: string;
|
total: string;
|
||||||
|
|||||||
@@ -207,10 +207,13 @@ export interface PaymentReceivedPdfTemplateAttributes {
|
|||||||
companyLogo: string;
|
companyLogo: string;
|
||||||
companyName: string;
|
companyName: string;
|
||||||
|
|
||||||
billedToAddress: string[];
|
// Customer Address
|
||||||
billedFromAddress: string[];
|
showCustomerAddress: boolean;
|
||||||
showBilledFromAddress: boolean;
|
customerAddress: string;
|
||||||
showBillingToAddress: boolean;
|
|
||||||
|
// Company address
|
||||||
|
showCompanyAddress: boolean;
|
||||||
|
companyAddress: string;
|
||||||
billedToLabel: string;
|
billedToLabel: string;
|
||||||
|
|
||||||
total: string;
|
total: string;
|
||||||
|
|||||||
@@ -294,8 +294,13 @@ export interface InvoicePdfTemplateAttributes {
|
|||||||
invoiceNumber: string;
|
invoiceNumber: string;
|
||||||
showInvoiceNumber: boolean;
|
showInvoiceNumber: boolean;
|
||||||
|
|
||||||
showBillingToAddress: boolean;
|
// Customer Address
|
||||||
showBilledFromAddress: boolean;
|
showCustomerAddress: boolean;
|
||||||
|
customerAddress: string;
|
||||||
|
|
||||||
|
// Company address
|
||||||
|
showCompanyAddress: boolean;
|
||||||
|
companyAddress: string;
|
||||||
billedToLabel: string;
|
billedToLabel: string;
|
||||||
|
|
||||||
lineItemLabel: string;
|
lineItemLabel: string;
|
||||||
@@ -333,7 +338,4 @@ export interface InvoicePdfTemplateAttributes {
|
|||||||
statementLabel: string;
|
statementLabel: string;
|
||||||
showStatement: boolean;
|
showStatement: boolean;
|
||||||
statement: string;
|
statement: string;
|
||||||
|
|
||||||
billedToAddress: string[];
|
|
||||||
billedFromAddres: string[];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,11 +163,13 @@ export interface ISaleReceiptBrandingTemplateAttributes {
|
|||||||
companyLogo: string;
|
companyLogo: string;
|
||||||
companyName: string;
|
companyName: string;
|
||||||
|
|
||||||
// Address
|
// Customer Address
|
||||||
billedToAddress: string[];
|
showCustomerAddress: boolean;
|
||||||
billedFromAddress: string[];
|
customerAddress: string;
|
||||||
showBilledFromAddress: boolean;
|
|
||||||
showBilledToAddress: boolean;
|
// Company address
|
||||||
|
showCompanyAddress: boolean;
|
||||||
|
companyAddress: string;
|
||||||
billedToLabel: string;
|
billedToLabel: string;
|
||||||
|
|
||||||
// Total
|
// Total
|
||||||
|
|||||||
@@ -1,26 +1,44 @@
|
|||||||
import { Inject } from "typedi";
|
import { Inject } from 'typedi';
|
||||||
import { GetPdfTemplate } from "../PdfTemplate/GetPdfTemplate";
|
import { GetPdfTemplate } from '../PdfTemplate/GetPdfTemplate';
|
||||||
import { defaultCreditNoteBrandingAttributes } from "./constants";
|
import { defaultCreditNoteBrandingAttributes } from './constants';
|
||||||
import { mergePdfTemplateWithDefaultAttributes } from "../Sales/Invoices/utils";
|
import { mergePdfTemplateWithDefaultAttributes } from '../Sales/Invoices/utils';
|
||||||
|
import { GetOrganizationBrandingAttributes } from '../PdfTemplate/GetOrganizationBrandingAttributes';
|
||||||
|
|
||||||
export class CreditNoteBrandingTemplate {
|
export class CreditNoteBrandingTemplate {
|
||||||
@Inject()
|
@Inject()
|
||||||
private getPdfTemplateService: GetPdfTemplate;
|
private getPdfTemplateService: GetPdfTemplate;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private getOrgBrandingAttributes: GetOrganizationBrandingAttributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the credit note branding template.
|
* Retrieves the credit note branding template.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {number} templateId
|
* @param {number} templateId
|
||||||
* @returns {}
|
* @returns {}
|
||||||
*/
|
*/
|
||||||
public async getCreditNoteBrandingTemplate(tenantId: number, templateId: number) {
|
public async getCreditNoteBrandingTemplate(
|
||||||
|
tenantId: number,
|
||||||
|
templateId: number
|
||||||
|
) {
|
||||||
const template = await this.getPdfTemplateService.getPdfTemplate(
|
const template = await this.getPdfTemplateService.getPdfTemplate(
|
||||||
tenantId,
|
tenantId,
|
||||||
templateId
|
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(
|
const attributes = mergePdfTemplateWithDefaultAttributes(
|
||||||
template.attributes,
|
template.attributes,
|
||||||
defaultCreditNoteBrandingAttributes
|
organizationBrandingAttrs
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...template,
|
...template,
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ export default class GetCreditNotePdf {
|
|||||||
tenantId,
|
tenantId,
|
||||||
creditNoteId
|
creditNoteId
|
||||||
);
|
);
|
||||||
console.log(brandingAttributes, 'brandingAttributes');
|
|
||||||
|
|
||||||
const htmlContent = await this.templateInjectable.render(
|
const htmlContent = await this.templateInjectable.render(
|
||||||
tenantId,
|
tenantId,
|
||||||
'modules/credit-note-standard',
|
'modules/credit-note-standard',
|
||||||
|
|||||||
@@ -80,24 +80,13 @@ export const defaultCreditNoteBrandingAttributes = {
|
|||||||
// # Company name
|
// # Company name
|
||||||
companyName: 'Bigcapital Technology, Inc.',
|
companyName: 'Bigcapital Technology, Inc.',
|
||||||
|
|
||||||
// Address
|
// # Customer address
|
||||||
billedToAddress: [
|
showCustomerAddress: true,
|
||||||
'Bigcapital Technology, Inc.',
|
customerAddress: '',
|
||||||
'131 Continental Dr Suite 305 Newark,',
|
|
||||||
'Delaware 19713',
|
// # Company address
|
||||||
'United States',
|
showCompanyAddress: true,
|
||||||
'+1 762-339-5634',
|
companyAddress: '',
|
||||||
'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,
|
|
||||||
billedToLabel: 'Billed To',
|
billedToLabel: 'Billed To',
|
||||||
|
|
||||||
// Total
|
// Total
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { CreditNotePdfTemplateAttributes, ICreditNote } from '@/interfaces';
|
import { CreditNotePdfTemplateAttributes, ICreditNote } from '@/interfaces';
|
||||||
|
import { contactAddressTextFormat } from '@/utils/address-text-format';
|
||||||
|
|
||||||
export const transformCreditNoteToPdfTemplate = (
|
export const transformCreditNoteToPdfTemplate = (
|
||||||
creditNote: ICreditNote
|
creditNote: ICreditNote
|
||||||
@@ -19,5 +20,6 @@ export const transformCreditNoteToPdfTemplate = (
|
|||||||
})),
|
})),
|
||||||
customerNote: creditNote.note,
|
customerNote: creditNote.note,
|
||||||
termsConditions: creditNote.termsConditions,
|
termsConditions: creditNote.termsConditions,
|
||||||
|
customerAddress: contactAddressTextFormat(creditNote.customer),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -231,7 +231,6 @@ export const defaultEstimatePdfBrandingAttributes = {
|
|||||||
expirationDate: 'September 3, 2024',
|
expirationDate: 'September 3, 2024',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
interface EstimatePdfBrandingLineItem {
|
interface EstimatePdfBrandingLineItem {
|
||||||
item: string;
|
item: string;
|
||||||
description: string;
|
description: string;
|
||||||
@@ -247,10 +246,13 @@ export interface EstimatePdfBrandingAttributes {
|
|||||||
companyLogo: string;
|
companyLogo: string;
|
||||||
companyName: string;
|
companyName: string;
|
||||||
|
|
||||||
billedToAddress: string[];
|
// Customer Address
|
||||||
billedFromAddress: string[];
|
showCustomerAddress: boolean;
|
||||||
showBilledFromAddress: boolean;
|
customerAddress: string;
|
||||||
showBilledToAddress: boolean;
|
|
||||||
|
// Company Address
|
||||||
|
showCompanyAddress: boolean;
|
||||||
|
companyAddress: string;
|
||||||
billedToLabel: string;
|
billedToLabel: string;
|
||||||
|
|
||||||
total: string;
|
total: string;
|
||||||
@@ -282,4 +284,4 @@ export interface EstimatePdfBrandingAttributes {
|
|||||||
expirationDateLabel: string;
|
expirationDateLabel: string;
|
||||||
showExpirationDate: boolean;
|
showExpirationDate: boolean;
|
||||||
expirationDate: string;
|
expirationDate: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { contactAddressTextFormat } from '@/utils/address-text-format';
|
||||||
import { EstimatePdfBrandingAttributes } from './constants';
|
import { EstimatePdfBrandingAttributes } from './constants';
|
||||||
|
|
||||||
export const transformEstimateToPdfTemplate = (
|
export const transformEstimateToPdfTemplate = (
|
||||||
@@ -18,5 +19,6 @@ export const transformEstimateToPdfTemplate = (
|
|||||||
subtotal: estimate.formattedSubtotal,
|
subtotal: estimate.formattedSubtotal,
|
||||||
customerNote: estimate.customerNote,
|
customerNote: estimate.customerNote,
|
||||||
termsConditions: estimate.termsConditions,
|
termsConditions: estimate.termsConditions,
|
||||||
|
customerAddress: contactAddressTextFormat(estimate.customer),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export class SaleEstimatePdfTemplate {
|
|||||||
await this.getOrgBrandingAttrs.getOrganizationBrandingAttributes(
|
await this.getOrgBrandingAttrs.getOrganizationBrandingAttributes(
|
||||||
tenantId
|
tenantId
|
||||||
);
|
);
|
||||||
|
// Merge the default branding attributes with organization attrs.
|
||||||
const orgainizationBrandingAttrs = {
|
const orgainizationBrandingAttrs = {
|
||||||
...defaultEstimatePdfBrandingAttributes,
|
...defaultEstimatePdfBrandingAttributes,
|
||||||
...commonOrgBrandingAttrs,
|
...commonOrgBrandingAttrs,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { pickBy } from 'lodash';
|
import { pickBy } from 'lodash';
|
||||||
import { InvoicePdfTemplateAttributes, ISaleInvoice } from '@/interfaces';
|
import { InvoicePdfTemplateAttributes, ISaleInvoice } from '@/interfaces';
|
||||||
|
import { contactAddressTextFormat } from '@/utils/address-text-format';
|
||||||
|
|
||||||
export const mergePdfTemplateWithDefaultAttributes = (
|
export const mergePdfTemplateWithDefaultAttributes = (
|
||||||
brandingTemplate?: Record<string, any>,
|
brandingTemplate?: Record<string, any>,
|
||||||
@@ -42,5 +43,7 @@ export const transformInvoiceToPdfTemplate = (
|
|||||||
label: tax.name,
|
label: tax.name,
|
||||||
amount: tax.taxRateAmountFormatted,
|
amount: tax.taxRateAmountFormatted,
|
||||||
})),
|
})),
|
||||||
|
|
||||||
|
customerAddress: contactAddressTextFormat(invoice.customer),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,12 +3,18 @@ import { Inject, Service } from 'typedi';
|
|||||||
import { mergePdfTemplateWithDefaultAttributes } from '../Invoices/utils';
|
import { mergePdfTemplateWithDefaultAttributes } from '../Invoices/utils';
|
||||||
import { defaultPaymentReceivedPdfTemplateAttributes } from './constants';
|
import { defaultPaymentReceivedPdfTemplateAttributes } from './constants';
|
||||||
import { PdfTemplate } from '@/models/PdfTemplate';
|
import { PdfTemplate } from '@/models/PdfTemplate';
|
||||||
|
import { GetOrganizationBrandingAttributes } from '@/services/PdfTemplate/GetOrganizationBrandingAttributes';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class PaymentReceivedBrandingTemplate {
|
export class PaymentReceivedBrandingTemplate {
|
||||||
@Inject()
|
@Inject()
|
||||||
private getPdfTemplateService: GetPdfTemplate;
|
private getPdfTemplateService: GetPdfTemplate;
|
||||||
|
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private getOrgBrandingAttributes: GetOrganizationBrandingAttributes;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the payment received pdf template.
|
* Retrieves the payment received pdf template.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -23,9 +29,16 @@ export class PaymentReceivedBrandingTemplate {
|
|||||||
tenantId,
|
tenantId,
|
||||||
paymentTemplateId
|
paymentTemplateId
|
||||||
);
|
);
|
||||||
|
// Retrieves the organization branding attributes.
|
||||||
|
const commonOrgBrandingAttrs = this.getOrgBrandingAttributes.getOrganizationBrandingAttributes(tenantId);
|
||||||
|
|
||||||
|
const organizationBrandingAttrs = {
|
||||||
|
...defaultPaymentReceivedPdfTemplateAttributes,
|
||||||
|
...commonOrgBrandingAttrs,
|
||||||
|
};
|
||||||
const attributes = mergePdfTemplateWithDefaultAttributes(
|
const attributes = mergePdfTemplateWithDefaultAttributes(
|
||||||
template.attributes,
|
template.attributes,
|
||||||
defaultPaymentReceivedPdfTemplateAttributes
|
organizationBrandingAttrs
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...template,
|
...template,
|
||||||
|
|||||||
@@ -58,24 +58,13 @@ export const defaultPaymentReceivedPdfTemplateAttributes = {
|
|||||||
// # Company name
|
// # Company name
|
||||||
companyName: 'Bigcapital Technology, Inc.',
|
companyName: 'Bigcapital Technology, Inc.',
|
||||||
|
|
||||||
// Address
|
// # Customer address
|
||||||
billedToAddress: [
|
showCustomerAddress: true,
|
||||||
'Bigcapital Technology, Inc.',
|
customerAddress: '',
|
||||||
'131 Continental Dr Suite 305 Newark,',
|
|
||||||
'Delaware 19713',
|
// # Company address
|
||||||
'United States',
|
showCompanyAddress: true,
|
||||||
'+1 762-339-5634',
|
companyAddress: '',
|
||||||
'ahmed@bigcapital.app',
|
|
||||||
],
|
|
||||||
billedFromAddress: [
|
|
||||||
'131 Continental Dr Suite 305 Newark,',
|
|
||||||
'Delaware 19713',
|
|
||||||
'United States',
|
|
||||||
'+1 762-339-5634',
|
|
||||||
'ahmed@bigcapital.app',
|
|
||||||
],
|
|
||||||
showBilledFromAddress: true,
|
|
||||||
showBillingToAddress: true,
|
|
||||||
billedToLabel: 'Billed To',
|
billedToLabel: 'Billed To',
|
||||||
|
|
||||||
// Total
|
// Total
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
IPaymentReceived,
|
IPaymentReceived,
|
||||||
PaymentReceivedPdfTemplateAttributes,
|
PaymentReceivedPdfTemplateAttributes,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
|
import { contactAddressTextFormat } from '@/utils/address-text-format';
|
||||||
|
|
||||||
export const transformPaymentReceivedToPdfTemplate = (
|
export const transformPaymentReceivedToPdfTemplate = (
|
||||||
payment: IPaymentReceived
|
payment: IPaymentReceived
|
||||||
@@ -17,5 +18,6 @@ export const transformPaymentReceivedToPdfTemplate = (
|
|||||||
invoiceAmount: entry.invoice.totalFormatted,
|
invoiceAmount: entry.invoice.totalFormatted,
|
||||||
paidAmount: entry.paymentAmountFormatted,
|
paidAmount: entry.paymentAmountFormatted,
|
||||||
})),
|
})),
|
||||||
|
customerAddress: contactAddressTextFormat(payment.customer),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ import { GetPdfTemplate } from '@/services/PdfTemplate/GetPdfTemplate';
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { defaultSaleReceiptBrandingAttributes } from './constants';
|
import { defaultSaleReceiptBrandingAttributes } from './constants';
|
||||||
import { mergePdfTemplateWithDefaultAttributes } from '../Invoices/utils';
|
import { mergePdfTemplateWithDefaultAttributes } from '../Invoices/utils';
|
||||||
|
import { GetOrganizationBrandingAttributes } from '@/services/PdfTemplate/GetOrganizationBrandingAttributes';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class SaleReceiptBrandingTemplate {
|
export class SaleReceiptBrandingTemplate {
|
||||||
@Inject()
|
@Inject()
|
||||||
private getPdfTemplateService: GetPdfTemplate;
|
private getPdfTemplateService: GetPdfTemplate;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private getOrgBrandingAttributes: GetOrganizationBrandingAttributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the sale receipt branding template.
|
* Retrieves the sale receipt branding template.
|
||||||
@@ -23,9 +26,20 @@ export class SaleReceiptBrandingTemplate {
|
|||||||
tenantId,
|
tenantId,
|
||||||
templateId
|
templateId
|
||||||
);
|
);
|
||||||
|
// Retrieves the organization branding attributes.
|
||||||
|
const commonOrgBrandingAttrs =
|
||||||
|
await this.getOrgBrandingAttributes.getOrganizationBrandingAttributes(
|
||||||
|
tenantId
|
||||||
|
);
|
||||||
|
|
||||||
|
// Merges the default branding attributes with organization common branding attrs.
|
||||||
|
const organizationBrandingAttrs = {
|
||||||
|
...defaultSaleReceiptBrandingAttributes,
|
||||||
|
...commonOrgBrandingAttrs,
|
||||||
|
};
|
||||||
const attributes = mergePdfTemplateWithDefaultAttributes(
|
const attributes = mergePdfTemplateWithDefaultAttributes(
|
||||||
template.attributes,
|
template.attributes,
|
||||||
defaultSaleReceiptBrandingAttributes
|
organizationBrandingAttrs
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...template,
|
...template,
|
||||||
|
|||||||
@@ -76,26 +76,16 @@ export const defaultSaleReceiptBrandingAttributes = {
|
|||||||
companyLogoUri: '',
|
companyLogoUri: '',
|
||||||
companyLogoKey: '',
|
companyLogoKey: '',
|
||||||
|
|
||||||
// # Address
|
// # Customer address
|
||||||
billedToAddress: [
|
showCustomerAddress: true,
|
||||||
'Bigcapital Technology, Inc.',
|
customerAddress: '',
|
||||||
'131 Continental Dr Suite 305 Newark,',
|
|
||||||
'Delaware 19713',
|
// # Company address
|
||||||
'United States',
|
showCompanyAddress: true,
|
||||||
'+1 762-339-5634',
|
companyAddress: '',
|
||||||
'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,
|
|
||||||
billedToLabel: 'Billed To',
|
billedToLabel: 'Billed To',
|
||||||
|
|
||||||
|
// # Total
|
||||||
total: '$1000.00',
|
total: '$1000.00',
|
||||||
totalLabel: 'Total',
|
totalLabel: 'Total',
|
||||||
showTotal: true,
|
showTotal: true,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { ISaleReceipt, ISaleReceiptBrandingTemplateAttributes } from "@/interfaces";
|
import { ISaleReceipt, ISaleReceiptBrandingTemplateAttributes } from "@/interfaces";
|
||||||
|
import { contactAddressTextFormat } from "@/utils/address-text-format";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -13,8 +14,8 @@ export const transformReceiptToBrandingTemplateAttributes = (saleReceipt: ISaleR
|
|||||||
quantity: entry.quantityFormatted,
|
quantity: entry.quantityFormatted,
|
||||||
total: entry.totalFormatted,
|
total: entry.totalFormatted,
|
||||||
})),
|
})),
|
||||||
|
|
||||||
receiptNumber: saleReceipt.receiptNumber,
|
receiptNumber: saleReceipt.receiptNumber,
|
||||||
receiptDate: saleReceipt.formattedReceiptDate,
|
receiptDate: saleReceipt.formattedReceiptDate,
|
||||||
|
customerAddress: contactAddressTextFormat(saleReceipt.customer),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { addressTextFormat } from '@/utils/address-text-format';
|
import { organizationAddressTextFormat } from '@/utils/address-text-format';
|
||||||
import BaseModel from 'models/Model';
|
import BaseModel from 'models/Model';
|
||||||
import { getUploadedObjectUri } from '../../services/Attachments/utils';
|
import { getUploadedObjectUri } from '../../services/Attachments/utils';
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ export default class TenantMetadata extends BaseModel {
|
|||||||
{POSTAL_CODE},
|
{POSTAL_CODE},
|
||||||
{COUNTRY}
|
{COUNTRY}
|
||||||
`;
|
`;
|
||||||
return addressTextFormat(defaultMessage, {
|
return organizationAddressTextFormat(defaultMessage, {
|
||||||
organizationName: this.name,
|
organizationName: this.name,
|
||||||
address1: this.address?.address1,
|
address1: this.address?.address1,
|
||||||
address2: this.address?.address2,
|
address2: this.address?.address2,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { IContact } from '@/interfaces';
|
||||||
|
|
||||||
interface OrganizationAddressFormatArgs {
|
interface OrganizationAddressFormatArgs {
|
||||||
organizationName?: string;
|
organizationName?: string;
|
||||||
address1?: string;
|
address1?: string;
|
||||||
@@ -17,7 +19,19 @@ const defaultMessage = `
|
|||||||
{COUNTRY}
|
{COUNTRY}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const addressTextFormat = (
|
const formatText = (message: string, replacements: Record<string, string>) => {
|
||||||
|
let formattedMessage = Object.entries(replacements).reduce(
|
||||||
|
(msg, [key, value]) => {
|
||||||
|
return msg.split(`{${key}}`).join(value || '');
|
||||||
|
},
|
||||||
|
message
|
||||||
|
);
|
||||||
|
formattedMessage = formattedMessage.replace(/\n/g, '<br />');
|
||||||
|
|
||||||
|
return formattedMessage.trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const organizationAddressTextFormat = (
|
||||||
message: string,
|
message: string,
|
||||||
args: OrganizationAddressFormatArgs
|
args: OrganizationAddressFormatArgs
|
||||||
) => {
|
) => {
|
||||||
@@ -30,13 +44,53 @@ export const addressTextFormat = (
|
|||||||
POSTAL_CODE: args.postalCode || '',
|
POSTAL_CODE: args.postalCode || '',
|
||||||
COUNTRY: args.country || '',
|
COUNTRY: args.country || '',
|
||||||
};
|
};
|
||||||
let formattedMessage = Object.entries(replacements).reduce(
|
return formatText(message, replacements);
|
||||||
(msg, [key, value]) => {
|
};
|
||||||
return value ? msg.split(`{${key}}`).join(value) : msg;
|
|
||||||
},
|
interface ContactAddressTextFormatArgs {
|
||||||
message
|
displayName?: string;
|
||||||
);
|
state?: string;
|
||||||
formattedMessage = formattedMessage.replace(/\n/g, '<br />');
|
postalCode?: string;
|
||||||
|
email?: string;
|
||||||
return formattedMessage.trim();
|
country?: string;
|
||||||
|
city?: string;
|
||||||
|
address2?: string;
|
||||||
|
address1?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contactFormatMessage = `{CONTACT_NAME}
|
||||||
|
{ADDRESS_1}
|
||||||
|
{ADDRESS_2}
|
||||||
|
{CITY} {STATE}
|
||||||
|
{POSTAL_CODE}
|
||||||
|
{COUNTRY}
|
||||||
|
{EMAIL}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const contactAddressTextFormat = (
|
||||||
|
contact: IContact,
|
||||||
|
message: string = contactFormatMessage
|
||||||
|
) => {
|
||||||
|
const args = {
|
||||||
|
displayName: contact.displayName,
|
||||||
|
address1: contact.billingAddress1,
|
||||||
|
address2: contact.billingAddress2,
|
||||||
|
state: contact.billingAddressState,
|
||||||
|
country: contact.billingAddressCountry,
|
||||||
|
postalCode: contact?.billingAddressPostcode,
|
||||||
|
city: contact?.billingAddressCity,
|
||||||
|
email: contact?.email,
|
||||||
|
} as ContactAddressTextFormatArgs;
|
||||||
|
|
||||||
|
const replacements: Record<string, string> = {
|
||||||
|
CONTACT_NAME: args.displayName || '',
|
||||||
|
ADDRESS_1: args.address1 || '',
|
||||||
|
ADDRESS_2: args.address2 || '',
|
||||||
|
CITY: args.city || '',
|
||||||
|
STATE: args.state || '',
|
||||||
|
POSTAL_CODE: args.postalCode || '',
|
||||||
|
COUNTRY: args.country || '',
|
||||||
|
EMAIL: args?.email || '',
|
||||||
|
};
|
||||||
|
return formatText(message, replacements);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,10 +17,9 @@ United States, <br />
|
|||||||
ahmed@bigcapital.app
|
ahmed@bigcapital.app
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
export const DefaultPdfTemplateAddressBilledFrom = `131 Continental Dr Suite 305 Newark, <br />
|
export const DefaultPdfTemplateAddressBilledFrom = `131 Continental Dr Suite 305 Newark, <br />
|
||||||
Delaware 19713,<br />
|
Delaware 19713,<br />
|
||||||
United States, <br />
|
United States, <br />
|
||||||
+1 762-339-5634, <br />
|
+1 762-339-5634, <br />
|
||||||
ahmed@bigcapital.app
|
ahmed@bigcapital.app
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -71,23 +71,27 @@ export function EstimatePaperTemplate({
|
|||||||
primaryColor,
|
primaryColor,
|
||||||
secondaryColor,
|
secondaryColor,
|
||||||
|
|
||||||
|
// # Company logo
|
||||||
showCompanyLogo = true,
|
showCompanyLogo = true,
|
||||||
companyLogoUri = '',
|
companyLogoUri = '',
|
||||||
|
|
||||||
companyName,
|
companyName,
|
||||||
|
|
||||||
// # Address
|
// # Company address
|
||||||
customerAddress = DefaultPdfTemplateAddressBilledTo,
|
|
||||||
companyAddress = DefaultPdfTemplateAddressBilledFrom,
|
companyAddress = DefaultPdfTemplateAddressBilledFrom,
|
||||||
showCompanyAddress = true,
|
showCompanyAddress = true,
|
||||||
|
|
||||||
|
// # Customer address
|
||||||
|
customerAddress = DefaultPdfTemplateAddressBilledTo,
|
||||||
showCustomerAddress = true,
|
showCustomerAddress = true,
|
||||||
billedToLabel = 'Billed To',
|
billedToLabel = 'Billed To',
|
||||||
|
|
||||||
// #Total
|
// # Total
|
||||||
total = '$1000.00',
|
total = '$1000.00',
|
||||||
totalLabel = 'Total',
|
totalLabel = 'Total',
|
||||||
showTotal = true,
|
showTotal = true,
|
||||||
|
|
||||||
|
// # Subtotal
|
||||||
subtotal = '1000/00',
|
subtotal = '1000/00',
|
||||||
subtotalLabel = 'Subtotal',
|
subtotalLabel = 'Subtotal',
|
||||||
showSubtotal = true,
|
showSubtotal = true,
|
||||||
@@ -111,14 +115,18 @@ export function EstimatePaperTemplate({
|
|||||||
total: '$1000.00',
|
total: '$1000.00',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Estimate number
|
||||||
showEstimateNumber = true,
|
showEstimateNumber = true,
|
||||||
estimateNumberLabel = 'Estimate Number',
|
estimateNumberLabel = 'Estimate Number',
|
||||||
estimateNumebr = '346D3D40-0001',
|
estimateNumebr = '346D3D40-0001',
|
||||||
|
|
||||||
|
// Estimate date
|
||||||
estimateDate = 'September 3, 2024',
|
estimateDate = 'September 3, 2024',
|
||||||
showEstimateDate = true,
|
showEstimateDate = true,
|
||||||
estimateDateLabel = 'Estimate Date',
|
estimateDateLabel = 'Estimate Date',
|
||||||
|
|
||||||
|
// Expiration date
|
||||||
expirationDateLabel = 'Expiration Date',
|
expirationDateLabel = 'Expiration Date',
|
||||||
showExpirationDate = true,
|
showExpirationDate = true,
|
||||||
expirationDate = 'September 3, 2024',
|
expirationDate = 'September 3, 2024',
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ export const initialValues = {
|
|||||||
// Company name
|
// Company name
|
||||||
companyName: 'Bigcapital Technology, Inc.',
|
companyName: 'Bigcapital Technology, Inc.',
|
||||||
|
|
||||||
// Addresses
|
// Customer address
|
||||||
showCustomerAddress: true,
|
showCustomerAddress: true,
|
||||||
|
|
||||||
|
// Company address
|
||||||
showCompanyAddress: true,
|
showCompanyAddress: true,
|
||||||
customerAddress: '',
|
|
||||||
companyAddress: '',
|
companyAddress: '',
|
||||||
billedToLabel: 'Billed To',
|
billedToLabel: 'Billed To',
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,12 @@ export const initialValues = {
|
|||||||
// Company name
|
// Company name
|
||||||
companyName: 'Bigcapital Technology, Inc.',
|
companyName: 'Bigcapital Technology, Inc.',
|
||||||
|
|
||||||
// Addresses
|
// Customer address
|
||||||
showCompanyAddress: true,
|
|
||||||
showCustomerAddress: true,
|
showCustomerAddress: true,
|
||||||
|
|
||||||
|
// Company address
|
||||||
companyAddress: '',
|
companyAddress: '',
|
||||||
customerAddress: '',
|
showCompanyAddress: true,
|
||||||
billedToLabel: 'Billed To',
|
billedToLabel: 'Billed To',
|
||||||
|
|
||||||
// Entries
|
// Entries
|
||||||
|
|||||||
Reference in New Issue
Block a user