mirror of
https://github.com/Unleash/unleash.git
synced 2025-11-24 20:06:55 +01:00
feat: add taxes to invoices (#10821)
This commit is contained in:
parent
f22144de2a
commit
e9d2b30603
@ -109,13 +109,14 @@ export const BillingInvoice = ({
|
|||||||
invoicePDF,
|
invoicePDF,
|
||||||
invoiceURL,
|
invoiceURL,
|
||||||
totalAmount,
|
totalAmount,
|
||||||
|
subtotal,
|
||||||
|
taxAmount,
|
||||||
|
currency,
|
||||||
mainLines,
|
mainLines,
|
||||||
usageLines,
|
usageLines,
|
||||||
monthText,
|
monthText,
|
||||||
defaultExpanded,
|
defaultExpanded,
|
||||||
}: BillingInvoiceProps) => {
|
}: BillingInvoiceProps) => {
|
||||||
const currency = mainLines?.[0]?.currency || usageLines?.[0]?.currency;
|
|
||||||
|
|
||||||
const formattedTitle = invoiceDate
|
const formattedTitle = invoiceDate
|
||||||
? new Date(invoiceDate).toLocaleDateString(undefined, {
|
? new Date(invoiceDate).toLocaleDateString(undefined, {
|
||||||
month: 'long',
|
month: 'long',
|
||||||
@ -181,7 +182,10 @@ export const BillingInvoice = ({
|
|||||||
</StyledTableRow>
|
</StyledTableRow>
|
||||||
{mainLines.map((line) => (
|
{mainLines.map((line) => (
|
||||||
<StyledTableRow key={line.description}>
|
<StyledTableRow key={line.description}>
|
||||||
<BillingInvoiceMainRow {...line} />
|
<BillingInvoiceMainRow
|
||||||
|
{...line}
|
||||||
|
invoiceCurrency={currency}
|
||||||
|
/>
|
||||||
</StyledTableRow>
|
</StyledTableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
@ -201,7 +205,10 @@ export const BillingInvoice = ({
|
|||||||
</StyledTableRow>
|
</StyledTableRow>
|
||||||
{usageLines.map((line) => (
|
{usageLines.map((line) => (
|
||||||
<StyledTableRow key={line.description}>
|
<StyledTableRow key={line.description}>
|
||||||
<BillingInvoiceUsageRow {...line} />
|
<BillingInvoiceUsageRow
|
||||||
|
{...line}
|
||||||
|
invoiceCurrency={currency}
|
||||||
|
/>
|
||||||
</StyledTableRow>
|
</StyledTableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
@ -210,6 +217,8 @@ export const BillingInvoice = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<BillingInvoiceFooter
|
<BillingInvoiceFooter
|
||||||
|
subTotal={subtotal}
|
||||||
|
taxAmount={taxAmount}
|
||||||
totalAmount={totalAmount}
|
totalAmount={totalAmount}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -29,7 +29,10 @@ const StyledTableFooterCell = styled('div', {
|
|||||||
...(colSpan ? { gridColumn: `span ${colSpan}` } : {}),
|
...(colSpan ? { gridColumn: `span ${colSpan}` } : {}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const TaxRow: FC<{ value?: number }> = ({ value }) => {
|
const TaxRow: FC<{ value?: number; currency?: string }> = ({
|
||||||
|
value,
|
||||||
|
currency,
|
||||||
|
}) => {
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
return (
|
return (
|
||||||
<StyledTableFooterCell colSpan={2}>
|
<StyledTableFooterCell colSpan={2}>
|
||||||
@ -42,7 +45,9 @@ const TaxRow: FC<{ value?: number }> = ({ value }) => {
|
|||||||
<>
|
<>
|
||||||
<StyledTableFooterCell>Tax</StyledTableFooterCell>
|
<StyledTableFooterCell>Tax</StyledTableFooterCell>
|
||||||
<StyledTableFooterCell>
|
<StyledTableFooterCell>
|
||||||
<StyledAmountCell>{formatCurrency(value)}</StyledAmountCell>
|
<StyledAmountCell>
|
||||||
|
{formatCurrency(value, currency)}
|
||||||
|
</StyledAmountCell>
|
||||||
</StyledTableFooterCell>
|
</StyledTableFooterCell>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@ -63,18 +68,16 @@ export const BillingInvoiceFooter = ({
|
|||||||
}: BillingInvoiceFooterProps) => {
|
}: BillingInvoiceFooterProps) => {
|
||||||
return (
|
return (
|
||||||
<StyledTableFooter>
|
<StyledTableFooter>
|
||||||
{subTotal || !taxAmount ? (
|
|
||||||
<StyledTableFooterRow>
|
|
||||||
<StyledTableFooterCell>Sub total</StyledTableFooterCell>
|
|
||||||
<StyledTableFooterCell>
|
|
||||||
<StyledAmountCell>
|
|
||||||
{formatCurrency(subTotal || totalAmount, currency)}
|
|
||||||
</StyledAmountCell>
|
|
||||||
</StyledTableFooterCell>
|
|
||||||
</StyledTableFooterRow>
|
|
||||||
) : null}
|
|
||||||
<StyledTableFooterRow>
|
<StyledTableFooterRow>
|
||||||
<TaxRow value={taxAmount} />
|
<StyledTableFooterCell>Sub total</StyledTableFooterCell>
|
||||||
|
<StyledTableFooterCell>
|
||||||
|
<StyledAmountCell>
|
||||||
|
{formatCurrency(subTotal || 0, currency)}
|
||||||
|
</StyledAmountCell>
|
||||||
|
</StyledTableFooterCell>
|
||||||
|
</StyledTableFooterRow>
|
||||||
|
<StyledTableFooterRow>
|
||||||
|
<TaxRow value={taxAmount} currency={currency} />
|
||||||
</StyledTableFooterRow>
|
</StyledTableFooterRow>
|
||||||
<StyledTableFooterRow last>
|
<StyledTableFooterRow last>
|
||||||
<StyledTableFooterCell>Total</StyledTableFooterCell>
|
<StyledTableFooterCell>Total</StyledTableFooterCell>
|
||||||
|
|||||||
@ -12,6 +12,10 @@ const StyledSubText = styled(Typography)(({ theme }) => ({
|
|||||||
fontSize: theme.typography.caption.fontSize,
|
fontSize: theme.typography.caption.fontSize,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
type BillingInvoiceMainRowProps = DetailedInvoicesLineSchema & {
|
||||||
|
invoiceCurrency?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const BillingInvoiceMainRow = ({
|
export const BillingInvoiceMainRow = ({
|
||||||
quantity,
|
quantity,
|
||||||
description,
|
description,
|
||||||
@ -19,7 +23,8 @@ export const BillingInvoiceMainRow = ({
|
|||||||
totalAmount,
|
totalAmount,
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
}: DetailedInvoicesLineSchema) => {
|
invoiceCurrency,
|
||||||
|
}: BillingInvoiceMainRowProps) => {
|
||||||
const formattedStart = startDate
|
const formattedStart = startDate
|
||||||
? new Date(startDate).toLocaleDateString(undefined, {
|
? new Date(startDate).toLocaleDateString(undefined, {
|
||||||
month: 'short',
|
month: 'short',
|
||||||
@ -45,7 +50,7 @@ export const BillingInvoiceMainRow = ({
|
|||||||
</StyledDescriptionCell>
|
</StyledDescriptionCell>
|
||||||
<div>{quantity ? formatLargeNumbers(quantity) : '–'}</div>
|
<div>{quantity ? formatLargeNumbers(quantity) : '–'}</div>
|
||||||
<StyledAmountCell>
|
<StyledAmountCell>
|
||||||
{formatCurrency(totalAmount || 0, currency)}
|
{formatCurrency(totalAmount || 0, invoiceCurrency)}
|
||||||
</StyledAmountCell>
|
</StyledAmountCell>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -15,6 +15,10 @@ const StyledCellWithIndicator = styled('div')(({ theme }) => ({
|
|||||||
maxHeight: theme.spacing(2.5),
|
maxHeight: theme.spacing(2.5),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
type BillingInvoiceUsageRowProps = DetailedInvoicesLineSchema & {
|
||||||
|
invoiceCurrency?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const BillingInvoiceUsageRow = ({
|
export const BillingInvoiceUsageRow = ({
|
||||||
quantity,
|
quantity,
|
||||||
consumption,
|
consumption,
|
||||||
@ -22,12 +26,15 @@ export const BillingInvoiceUsageRow = ({
|
|||||||
description,
|
description,
|
||||||
currency,
|
currency,
|
||||||
totalAmount,
|
totalAmount,
|
||||||
}: DetailedInvoicesLineSchema) => {
|
invoiceCurrency,
|
||||||
|
}: BillingInvoiceUsageRowProps) => {
|
||||||
const percentage =
|
const percentage =
|
||||||
limit && limit > 0
|
limit && limit > 0
|
||||||
? Math.min(100, Math.round(((consumption || 0) / limit) * 100))
|
? Math.min(100, Math.round(((consumption || 0) / limit) * 100))
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
const hasAmount = totalAmount && totalAmount > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StyledDescriptionCell>{description}</StyledDescriptionCell>
|
<StyledDescriptionCell>{description}</StyledDescriptionCell>
|
||||||
@ -43,10 +50,14 @@ export const BillingInvoiceUsageRow = ({
|
|||||||
: '–'}
|
: '–'}
|
||||||
</div>
|
</div>
|
||||||
</StyledCellWithIndicator>
|
</StyledCellWithIndicator>
|
||||||
<div>{quantity ? formatLargeNumbers(quantity) : '–'}</div>
|
<div>{quantity ? formatLargeNumbers(quantity) : ''}</div>
|
||||||
<StyledAmountCell>
|
{hasAmount ? (
|
||||||
{formatCurrency(totalAmount || 0, currency)}
|
<StyledAmountCell>
|
||||||
</StyledAmountCell>
|
{formatCurrency(totalAmount, invoiceCurrency)}
|
||||||
|
</StyledAmountCell>
|
||||||
|
) : (
|
||||||
|
<div />
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user