feat: implement discount display in various detail drawers

- Added discount amount and percentage display in Bill, Credit Note, Estimate, Invoice, Receipt, and Vendor Credit detail tables.
- Updated models to include discount-related attributes for better data handling.
- Enhanced user interface to show discount information when applicable, improving clarity in financial documents.
This commit is contained in:
Ahmed Bouhuolia
2024-11-30 16:01:29 +02:00
parent dd1392cdc8
commit 73ab92e693
8 changed files with 91 additions and 13 deletions

View File

@@ -53,6 +53,10 @@ export default class Bill extends mixin(TenantModel, [
'localAllocatedCostAmount', 'localAllocatedCostAmount',
'billableAmount', 'billableAmount',
'amountLocal', 'amountLocal',
'discountAmount',
'discountPercentage',
'subtotal', 'subtotal',
'subtotalLocal', 'subtotalLocal',
'subtotalExludingTax', 'subtotalExludingTax',

View File

@@ -26,14 +26,6 @@ export default class VendorCredit extends mixin(TenantModel, [
static get tableName() { static get tableName() {
return 'vendor_credits'; return 'vendor_credits';
} }
/**
* Virtual attributes.
*/
static get virtualAttributes() {
return ['localAmount'];
}
/** /**
* Vendor credit amount in local currency. * Vendor credit amount in local currency.
* @returns {number} * @returns {number}
@@ -81,7 +73,8 @@ export default class VendorCredit extends mixin(TenantModel, [
* @returns {number} * @returns {number}
*/ */
get total() { get total() {
const discountAmount = this.discountType === DiscountType.Amount const discountAmount =
this.discountType === DiscountType.Amount
? this.discount ? this.discount
: this.subtotal * (this.discount / 100); : this.subtotal * (this.discount / 100);
@@ -182,7 +175,21 @@ export default class VendorCredit extends mixin(TenantModel, [
* Virtual attributes. * Virtual attributes.
*/ */
static get virtualAttributes() { static get virtualAttributes() {
return ['isDraft', 'isPublished', 'isOpen', 'isClosed', 'creditsRemaining']; return [
'isDraft',
'isPublished',
'isOpen',
'isClosed',
'creditsRemaining',
'localAmount',
'discountAmount',
'discountPercentage',
'total',
'totalLocal',
];
} }
/** /**

View File

@@ -31,6 +31,17 @@ export function BillDetailTableFooter() {
textStyle={TotalLineTextStyle.Regular} textStyle={TotalLineTextStyle.Regular}
/> />
))} ))}
{bill.discount_amount > 0 && (
<TotalLine
title={
bill.discount_percentage_formatted
? `Discount [${bill.discount_percentage_formatted}]`
: 'Discount'
}
value={bill.discount_amount_formatted}
textStyle={TotalLineTextStyle.Regular}
/>
)}
<TotalLine <TotalLine
title={<T id={'bill.details.total'} />} title={<T id={'bill.details.total'} />}
value={bill.total_formatted} value={bill.total_formatted}

View File

@@ -22,9 +22,20 @@ export default function CreditNoteDetailTableFooter() {
title={<T id={'credit_note.drawer.label_subtotal'} />} title={<T id={'credit_note.drawer.label_subtotal'} />}
value={creditNote.formatted_subtotal} value={creditNote.formatted_subtotal}
/> />
{creditNote.discount_amount > 0 && (
<TotalLine
title={
creditNote.discount_percentage_formatted
? `Discount [${creditNote.discount_percentage_formatted}]`
: 'Discount'
}
value={creditNote.discount_amount_formatted}
borderStyle={TotalLineBorderStyle.Dark}
/>
)}
<TotalLine <TotalLine
title={<T id={'credit_note.drawer.label_total'} />} title={<T id={'credit_note.drawer.label_total'} />}
value={creditNote.formatted_amount} value={creditNote.total_formatted}
borderStyle={TotalLineBorderStyle.DoubleDark} borderStyle={TotalLineBorderStyle.DoubleDark}
textStyle={TotalLineTextStyle.Bold} textStyle={TotalLineTextStyle.Bold}
/> />

View File

@@ -25,6 +25,17 @@ export default function EstimateDetailTableFooter() {
value={estimate.formatted_subtotal} value={estimate.formatted_subtotal}
borderStyle={TotalLineBorderStyle.SingleDark} borderStyle={TotalLineBorderStyle.SingleDark}
/> />
{estimate.discount_amount > 0 && (
<TotalLine
title={
estimate.discount_percentage_formatted
? `Discount [${invoice.discount_percentage_formatted}]`
: 'Discount'
}
value={estimate.discount_amount_formatted}
textStyle={TotalLineTextStyle.Regular}
/>
)}
<TotalLine <TotalLine
title={<T id={'estimate.details.total'} />} title={<T id={'estimate.details.total'} />}
value={estimate.formatted_amount} value={estimate.formatted_amount}

View File

@@ -26,6 +26,17 @@ export function InvoiceDetailTableFooter() {
value={invoice.subtotal_formatted} value={invoice.subtotal_formatted}
borderStyle={TotalLineBorderStyle.SingleDark} borderStyle={TotalLineBorderStyle.SingleDark}
/> />
{invoice.discount_amount > 0 && (
<TotalLine
title={
invoice.discount_percentage_formatted
? `Discount [${invoice.discount_percentage_formatted}]`
: 'Discount'
}
value={invoice.discount_amount_formatted}
textStyle={TotalLineTextStyle.Regular}
/>
)}
{invoice.taxes.map((taxRate) => ( {invoice.taxes.map((taxRate) => (
<TotalLine <TotalLine
key={taxRate.id} key={taxRate.id}
@@ -34,6 +45,7 @@ export function InvoiceDetailTableFooter() {
textStyle={TotalLineTextStyle.Regular} textStyle={TotalLineTextStyle.Regular}
/> />
))} ))}
<TotalLine <TotalLine
title={<T id={'invoice.details.total'} />} title={<T id={'invoice.details.total'} />}
value={invoice.total_formatted} value={invoice.total_formatted}

View File

@@ -25,6 +25,17 @@ export default function ReceiptDetailTableFooter() {
title={<T id={'receipt.details.subtotal'} />} title={<T id={'receipt.details.subtotal'} />}
value={receipt.formatted_subtotal} value={receipt.formatted_subtotal}
/> />
{receipt.discount_amount > 0 && (
<TotalLine
title={
receipt.discount_percentage_formatted
? `Discount [${invoice.discount_percentage_formatted}]`
: 'Discount'
}
value={receipt.discount_amount_formatted}
textStyle={TotalLineTextStyle.Regular}
/>
)}
<TotalLine <TotalLine
title={<T id={'receipt.details.total'} />} title={<T id={'receipt.details.total'} />}
value={receipt.formatted_amount} value={receipt.formatted_amount}

View File

@@ -25,6 +25,17 @@ export default function VendorCreditDetailDrawerFooter() {
value={vendorCredit.formatted_subtotal} value={vendorCredit.formatted_subtotal}
borderStyle={TotalLineBorderStyle.SingleDark} borderStyle={TotalLineBorderStyle.SingleDark}
/> />
{vendorCredit.discount_amount > 0 && (
<TotalLine
title={
bill.discount_percentage_formatted
? `Discount [${bill.discount_percentage_formatted}]`
: 'Discount'
}
value={vendorCredit.discount_amount_formatted}
textStyle={TotalLineTextStyle.Regular}
/>
)}
<TotalLine <TotalLine
title={<T id={'vendor_credit.drawer.label_total'} />} title={<T id={'vendor_credit.drawer.label_total'} />}
value={vendorCredit.formatted_amount} value={vendorCredit.formatted_amount}