fix: line-level discount

This commit is contained in:
Ahmed Bouhuolia
2024-12-11 11:44:10 +02:00
parent 7af2e7ccbc
commit 6323e2ffec
4 changed files with 53 additions and 7 deletions

View File

@@ -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 (
<PaperTemplate primaryColor={primaryColor} secondaryColor={secondaryColor}>
<Stack spacing={24}>
@@ -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}

View File

@@ -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<PapaerLine>;
taxes?: Array<PaperTax>;
lines?: Array<InvoiceLine>;
taxes?: Array<InvoiceTaxLine>;
}
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}

View File

@@ -90,11 +90,14 @@ interface PaperTemplateTableProps {
value?: JSX.Element;
align?: 'left' | 'center' | 'right';
thStyle?: React.CSSProperties;
visible?: boolean;
}>;
data: Array<Record<string, any>>;
}
PaperTemplate.Table = ({ columns, data }: PaperTemplateTableProps) => {
const filteredColumns = columns.filter((col) => col.visible !== false);
return (
<table
className={css`
@@ -140,7 +143,7 @@ PaperTemplate.Table = ({ columns, data }: PaperTemplateTableProps) => {
>
<thead>
<tr>
{columns.map((col, index) => (
{filteredColumns.map((col, index) => (
<x.th key={index} textAlign={col.align} style={col.thStyle}>
{col.label}
</x.th>
@@ -151,7 +154,7 @@ PaperTemplate.Table = ({ columns, data }: PaperTemplateTableProps) => {
<tbody>
{data.map((_data: any) => (
<tr>
{columns.map((column, index) => (
{filteredColumns.map((column, index) => (
<x.td textAlign={column.align} key={index}>
{isFunction(column?.accessor)
? column?.accessor(_data)

View File

@@ -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 (
<PaperTemplate primaryColor={primaryColor} secondaryColor={secondaryColor}>
@@ -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}