From 459bf4cd55e09987a9b0fc5cad0b369fb0b46c82 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 24 Nov 2024 15:40:12 +0200 Subject: [PATCH] feat: mail receipt preview --- ...timateMailTemplateAttributesTransformer.ts | 148 +++++++++++++++++- .../GetPaymentReceivedMailStateTransformer.ts | 24 ++- ...entReceivedMailTemplateAttrsTransformer.ts | 82 +++++++++- ...eceiptMailTemplateAttributesTransformer.ts | 143 ++++++++++++++++- .../PaymentReceivedMailPreviewReceipt.tsx | 5 +- 5 files changed, 393 insertions(+), 9 deletions(-) diff --git a/packages/server/src/services/Sales/Estimates/GetEstimateMailTemplateAttributesTransformer.ts b/packages/server/src/services/Sales/Estimates/GetEstimateMailTemplateAttributesTransformer.ts index e1fb9b164..a643ee58d 100644 --- a/packages/server/src/services/Sales/Estimates/GetEstimateMailTemplateAttributesTransformer.ts +++ b/packages/server/src/services/Sales/Estimates/GetEstimateMailTemplateAttributesTransformer.ts @@ -1,3 +1,149 @@ import { Transformer } from '@/lib/Transformer/Transformer'; -export class GetEstimateMailTemplateAttributesTransformer extends Transformer {} +export class GetEstimateMailTemplateAttributesTransformer extends Transformer { + public includeAttributes = (): string[] => { + return [ + 'companyLogoUri', + 'companyName', + + 'estimateAmount', + + 'primaryColor', + + 'estimateAmount', + 'estimateMessage', + + 'dueDate', + 'dueDateLabel', + + 'estimateNumber', + 'estimateNumberLabel', + + 'total', + 'totalLabel', + + 'dueAmount', + 'dueAmountLabel', + + 'viewEstimateButtonLabel', + 'viewEstimateButtonUrl', + + 'items', + ]; + }; + + /** + * Exclude all attributes. + * @returns {string[]} + */ + public excludeAttributes = (): string[] => { + return ['*']; + }; + + /** + * Company logo uri. + * @returns {string} + */ + public companyLogoUri(): string { + return this.options.brandingTemplate?.companyLogoUri; + } + + /** + * Company name. + * @returns {string} + */ + public companyName(): string { + return this.context.organization.name; + } + + /** + * Primary color + * @returns {string} + */ + public primaryColor(): string { + return this.options?.brandingTemplate?.attributes?.primaryColor; + } + + /** + * Estimate number. + * @returns {string} + */ + public estimateNumber(): string { + return this.options.estimate.number; + } + + /** + * Estimate number label. + * @returns {string} + */ + public estimateNumberLabel(): string { + return 'Estimate Number'; + } + + /** + * Expiration date. + * @returns {string} + */ + public expirationDate(): string { + return this.options.estimate.expirationDate; + } + + /** + * Expiration date label. + * @returns {string} + */ + public expirationDateLabel(): string { + return 'Expiration Date'; + } + + /** + * Estimate total. + */ + public total(): string { + return this.options.estimate.totalFormatted; + } + + /** + * Estimate total label. + * @returns {string} + */ + public totalLabel(): string { + return 'Total'; + } + + /** + * Estimate mail items attributes. + */ + public items(): any[] { + return this.item( + this.options.estimate.entries, + new GetEstimateMailTemplateEntryAttributesTransformer() + ); + } +} + +class GetEstimateMailTemplateEntryAttributesTransformer extends Transformer { + public includeAttributes = (): string[] => { + return ['label', 'quantity', 'rate', 'total']; + }; + + public excludeAttributes = (): string[] => { + return ['*']; + }; + + public label(entry): string { + return entry?.item?.name; + } + + public quantity(entry): string { + return entry?.quantity; + } + + public rate(entry): string { + return entry?.rateFormatted; + } + + public total(entry): string { + return entry?.totalFormatted; + } +} diff --git a/packages/server/src/services/Sales/PaymentReceived/GetPaymentReceivedMailStateTransformer.ts b/packages/server/src/services/Sales/PaymentReceived/GetPaymentReceivedMailStateTransformer.ts index f3a922f85..8a57467e3 100644 --- a/packages/server/src/services/Sales/PaymentReceived/GetPaymentReceivedMailStateTransformer.ts +++ b/packages/server/src/services/Sales/PaymentReceived/GetPaymentReceivedMailStateTransformer.ts @@ -106,7 +106,7 @@ export class GetPaymentReceivedMailStateTransformer extends PaymentReceiveTransf * @returns {string} */ protected totalFormatted = (payment) => { - return this.formatMoney(payment.total); + return this.formatMoney(payment.amount); }; /** @@ -125,7 +125,7 @@ export class GetPaymentReceivedMailStateTransformer extends PaymentReceiveTransf * @returns {string} */ protected subtotalFormatted = (payment) => { - return this.formatMoney(payment.total); + return this.formatMoney(payment.amount); }; /** @@ -163,7 +163,7 @@ export class GetPaymentReceivedEntryMailState extends PaymentReceivedEntryTransf * @returns {Array} */ public includeAttributes = (): string[] => { - return ['paymentAmountFormatted']; + return ['paidAmount', 'invoiceNumber']; }; /** @@ -173,4 +173,22 @@ export class GetPaymentReceivedEntryMailState extends PaymentReceivedEntryTransf public excludeAttributes = (): string[] => { return ['*']; }; + + /** + * + * @param entry + * @returns {string} + */ + public paidAmount = (entry) => { + return this.paymentAmountFormatted(entry); + }; + + /** + * + * @param entry + * @returns {string} + */ + public invoiceNumber = (entry) => { + return entry.invoice.invoiceNo; + }; } diff --git a/packages/server/src/services/Sales/PaymentReceived/GetPaymentReceivedMailTemplateAttrsTransformer.ts b/packages/server/src/services/Sales/PaymentReceived/GetPaymentReceivedMailTemplateAttrsTransformer.ts index 10d9059c8..94002cbbd 100644 --- a/packages/server/src/services/Sales/PaymentReceived/GetPaymentReceivedMailTemplateAttrsTransformer.ts +++ b/packages/server/src/services/Sales/PaymentReceived/GetPaymentReceivedMailTemplateAttrsTransformer.ts @@ -1,3 +1,83 @@ import { Transformer } from '@/lib/Transformer/Transformer'; -export class GetPaymentReceivedMailTemplateAttrsTransformer extends Transformer {} +export class GetPaymentReceivedMailTemplateAttrsTransformer extends Transformer { + /** + * Included attributes. + * @returns {Array} + */ + public includeAttributes = (): string[] => { + return [ + 'companyLogoUri', + 'companyName', + 'primaryColor', + 'total', + 'totalLabel', + 'paymentNumberLabel', + 'paymentNumber', + ]; + }; + + /** + * Exclude all attributes. + * @returns {string[]} + */ + public excludeAttributes = (): string[] => { + return ['*']; + }; + + /** + * Company logo uri. + * @returns {string} + */ + public companyLogoUri(): string { + return this.options.brandingTemplate?.companyLogoUri; + } + + /** + * Company name. + * @returns {string} + */ + public companyName(): string { + return this.context.organization.name; + } + + /** + * Primary color + * @returns {string} + */ + public primaryColor(): string { + return this.options?.brandingTemplate?.attributes?.primaryColor; + } + + /** + * Total. + * @returns {string} + */ + public total(): string { + return this.options.paymentReceived.formattedAmount; + } + + /** + * Total label. + * @returns {string} + */ + public totalLabel(): string { + return 'Total'; + } + + /** + * Payment number label. + * @returns + */ + public paymentNumberLabel(): string { + return 'Payment # {paymentNumber}'; + } + + /** + * Payment number. + * @returns {string} + */ + public paymentNumber(): string { + return this.options.paymentReceived.paymentReceiveNumber; + } +} diff --git a/packages/server/src/services/Sales/Receipts/GetSaleReceiptMailTemplateAttributesTransformer.ts b/packages/server/src/services/Sales/Receipts/GetSaleReceiptMailTemplateAttributesTransformer.ts index 1c2ed9e6f..2764c6c85 100644 --- a/packages/server/src/services/Sales/Receipts/GetSaleReceiptMailTemplateAttributesTransformer.ts +++ b/packages/server/src/services/Sales/Receipts/GetSaleReceiptMailTemplateAttributesTransformer.ts @@ -1,3 +1,144 @@ import { Transformer } from '@/lib/Transformer/Transformer'; -export class GetSaleReceiptMailTemplateAttributesTransformer extends Transformer {} +export class GetSaleReceiptMailTemplateAttributesTransformer extends Transformer { + public includeAttributes = (): string[] => { + return [ + 'companyLogoUri', + 'companyName', + + 'primaryColor', + + 'receiptAmount', + 'receiptMessage', + + 'date', + 'dateLabel', + + 'receiptNumber', + 'receiptNumberLabel', + + 'total', + 'totalLabel', + + 'paidAmount', + 'paidAmountLabel', + + 'items', + ]; + }; + + /** + * Exclude all attributes. + * @returns {string[]} + */ + public excludeAttributes = (): string[] => { + return ['*']; + }; + + /** + * Company logo uri. + * @returns {string} + */ + public companyLogoUri(): string { + return this.options.brandingTemplate?.companyLogoUri; + } + + /** + * Company name. + * @returns {string} + */ + public companyName(): string { + return this.context.organization.name; + } + + /** + * Primary color + * @returns {string} + */ + public primaryColor(): string { + return this.options?.brandingTemplate?.attributes?.primaryColor; + } + + /** + * Receipt number. + * @returns {string} + */ + public receiptNumber(): string { + return this.options.receipt.number; + } + + /** + * Receipt number label. + * @returns {string} + */ + public receiptNumberLabel(): string { + return 'Receipt Number'; + } + + /** + * Date. + * @returns {string} + */ + public date(): string { + return this.options.receipt.date; + } + + /** + * Date label. + * @returns {string} + */ + public dateLabel(): string { + return 'Date'; + } + + /** + * Receipt total. + */ + public total(): string { + return this.options.receipt.totalFormatted; + } + + /** + * Receipt total label. + * @returns {string} + */ + public totalLabel(): string { + return 'Total'; + } + + /** + * Receipt mail items attributes. + */ + public items(): any[] { + return this.item( + this.options.receipt.entries, + new GetSaleReceiptMailTemplateEntryAttributesTransformer() + ); + } +} + +class GetSaleReceiptMailTemplateEntryAttributesTransformer extends Transformer { + public includeAttributes = (): string[] => { + return ['label', 'quantity', 'rate', 'total']; + }; + + public excludeAttributes = (): string[] => { + return ['*']; + }; + + public label(entry): string { + return entry?.item?.name; + } + + public quantity(entry): string { + return entry?.quantity; + } + + public rate(entry): string { + return entry?.rateFormatted; + } + + public total(entry): string { + return entry?.totalFormatted; + } +} diff --git a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailPreviewReceipt.tsx b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailPreviewReceipt.tsx index 31c67222d..df16b75dd 100644 --- a/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailPreviewReceipt.tsx +++ b/packages/webapp/src/containers/Sales/PaymentsReceived/PaymentReceivedMailDrawer/PaymentReceivedMailPreviewReceipt.tsx @@ -45,9 +45,8 @@ const withPaymentReceivedMailReceiptPreviewProps = < const items = useMemo( () => paymentReceivedMailState?.entries?.map((entry: any) => ({ - quantity: entry.quantity, - total: entry.totalFormatted, - label: entry.name, + total: entry.paidAmount, + label: entry.invoiceNumber, })), [paymentReceivedMailState?.entries], );