From 6323e2ffec78b43a13a8c7848ba22d9e75d78e15 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Wed, 11 Dec 2024 11:44:10 +0200 Subject: [PATCH] fix: line-level discount --- .../src/components/EstimatePaperTemplate.tsx | 15 +++++++++++- .../src/components/InvoicePaperTemplate.tsx | 23 +++++++++++++++---- .../src/components/PaperTemplate.tsx | 7 ++++-- .../src/components/ReceiptPaperTemplate.tsx | 15 ++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/shared/pdf-templates/src/components/EstimatePaperTemplate.tsx b/shared/pdf-templates/src/components/EstimatePaperTemplate.tsx index ac48e7c19..d601e9e56 100644 --- a/shared/pdf-templates/src/components/EstimatePaperTemplate.tsx +++ b/shared/pdf-templates/src/components/EstimatePaperTemplate.tsx @@ -92,6 +92,10 @@ export interface EstimatePaperTemplateProps extends PaperTemplateProps { lineQuantityLabel?: string; lineRateLabel?: string; lineTotalLabel?: string; + + // # Line Discount + lineDiscountLabel?: string; + showLineDiscount?: boolean; } export function EstimatePaperTemplate({ @@ -173,8 +177,11 @@ export function EstimatePaperTemplate({ lineQuantityLabel = 'Qty', lineRateLabel = 'Rate', lineTotalLabel = 'Total', -}: EstimatePaperTemplateProps) { + // # Line Discount + lineDiscountLabel = 'Discount', + showLineDiscount = false, +}: EstimatePaperTemplateProps) { return ( @@ -240,6 +247,12 @@ export function EstimatePaperTemplate({ }, { label: lineQuantityLabel, accessor: 'quantity' }, { label: lineRateLabel, accessor: 'rate', align: 'right' }, + { + label: lineDiscountLabel, + accessor: 'discount', + align: 'right', + visible: showLineDiscount, + }, { label: lineTotalLabel, accessor: 'total', align: 'right' }, ]} data={lines} diff --git a/shared/pdf-templates/src/components/InvoicePaperTemplate.tsx b/shared/pdf-templates/src/components/InvoicePaperTemplate.tsx index 487ae16ef..fd45bbb73 100644 --- a/shared/pdf-templates/src/components/InvoicePaperTemplate.tsx +++ b/shared/pdf-templates/src/components/InvoicePaperTemplate.tsx @@ -17,15 +17,16 @@ import { DefaultPdfTemplateAddressBilledFrom, } from './_constants'; -interface PapaerLine { +interface InvoiceLine { item?: string; description?: string; quantity?: string; rate?: string; total?: string; + discount?: string; } -interface PaperTax { +interface InvoiceTaxLine { label: string; amount: string; } @@ -71,6 +72,10 @@ export interface InvoicePaperTemplateProps extends PaperTemplateProps { lineRateLabel?: string; lineTotalLabel?: string; + // # Line Discount + lineDiscountLabel?: string; + showLineDiscount?: boolean; + // Total showTotal?: boolean; totalLabel?: string; @@ -113,8 +118,8 @@ export interface InvoicePaperTemplateProps extends PaperTemplateProps { showStatement?: boolean; statement?: string; - lines?: Array; - taxes?: Array; + lines?: Array; + taxes?: Array; } export function InvoicePaperTemplate({ @@ -165,6 +170,10 @@ export function InvoicePaperTemplate({ paymentMadeLabel = 'Payment Made', dueAmountLabel = 'Balance Due', + // # Line Discount + lineDiscountLabel = 'Discount', + showLineDiscount = false, + // Totals showTotal = true, total = '$662.75', @@ -277,6 +286,12 @@ export function InvoicePaperTemplate({ align: 'right', }, { label: lineRateLabel, accessor: 'rate', align: 'right' }, + { + label: lineDiscountLabel, + accessor: 'discount', + align: 'right', + visible: showLineDiscount, + }, { label: lineTotalLabel, accessor: 'total', align: 'right' }, ]} data={lines} diff --git a/shared/pdf-templates/src/components/PaperTemplate.tsx b/shared/pdf-templates/src/components/PaperTemplate.tsx index 220e0305a..85f9b134a 100644 --- a/shared/pdf-templates/src/components/PaperTemplate.tsx +++ b/shared/pdf-templates/src/components/PaperTemplate.tsx @@ -90,11 +90,14 @@ interface PaperTemplateTableProps { value?: JSX.Element; align?: 'left' | 'center' | 'right'; thStyle?: React.CSSProperties; + visible?: boolean; }>; data: Array>; } PaperTemplate.Table = ({ columns, data }: PaperTemplateTableProps) => { + const filteredColumns = columns.filter((col) => col.visible !== false); + return ( { > - {columns.map((col, index) => ( + {filteredColumns.map((col, index) => ( {col.label} @@ -151,7 +154,7 @@ PaperTemplate.Table = ({ columns, data }: PaperTemplateTableProps) => { {data.map((_data: any) => ( - {columns.map((column, index) => ( + {filteredColumns.map((column, index) => ( {isFunction(column?.accessor) ? column?.accessor(_data) diff --git a/shared/pdf-templates/src/components/ReceiptPaperTemplate.tsx b/shared/pdf-templates/src/components/ReceiptPaperTemplate.tsx index 04ddb24e3..76f3a38fa 100644 --- a/shared/pdf-templates/src/components/ReceiptPaperTemplate.tsx +++ b/shared/pdf-templates/src/components/ReceiptPaperTemplate.tsx @@ -71,9 +71,14 @@ export interface ReceiptPaperTemplateProps extends PaperTemplateProps { description: string; rate: string; quantity: string; + discount?: string; total: string; }>; + // # Line Discount + lineDiscountLabel?: string; + showLineDiscount?: boolean; + // Receipt Date. receiptDateLabel?: string; showReceiptDate?: boolean; @@ -165,6 +170,10 @@ export function ReceiptPaperTemplate({ lineQuantityLabel = 'Qty', lineRateLabel = 'Rate', lineTotalLabel = 'Total', + + // # Line Discount + lineDiscountLabel = 'Discount', + showLineDiscount = false, }: ReceiptPaperTemplateProps) { return ( @@ -226,6 +235,12 @@ export function ReceiptPaperTemplate({ }, { label: lineQuantityLabel, accessor: 'quantity' }, { label: lineRateLabel, accessor: 'rate', align: 'right' }, + { + label: lineDiscountLabel, + accessor: 'discount', + align: 'right', + visible: showLineDiscount, + }, { label: lineTotalLabel, accessor: 'total', align: 'right' }, ]} data={lines}