mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: item-level discount
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IItemEntry } from '@/interfaces';
|
||||
import { DiscountType, IItemEntry } from '@/interfaces';
|
||||
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||
import { formatNumber } from '@/utils';
|
||||
|
||||
@@ -8,7 +8,13 @@ export class ItemEntryTransformer extends Transformer {
|
||||
* @returns {Array}
|
||||
*/
|
||||
public includeAttributes = (): string[] => {
|
||||
return ['quantityFormatted', 'rateFormatted', 'totalFormatted'];
|
||||
return [
|
||||
'quantityFormatted',
|
||||
'rateFormatted',
|
||||
'totalFormatted',
|
||||
'discountFormatted',
|
||||
'discountAmountFormatted',
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -43,4 +49,34 @@ export class ItemEntryTransformer extends Transformer {
|
||||
money: false,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the formatted discount of item entry.
|
||||
* @param {IItemEntry} entry
|
||||
* @returns {string}
|
||||
*/
|
||||
protected discountFormatted = (entry: IItemEntry): string => {
|
||||
if (!entry.discount) {
|
||||
return '';
|
||||
}
|
||||
return entry.discountType === DiscountType.Percentage
|
||||
? `${entry.discount}%`
|
||||
: formatNumber(entry.discount, {
|
||||
currencyCode: this.context.currencyCode,
|
||||
money: false,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the formatted discount amount of item entry.
|
||||
* @param {IItemEntry} entry
|
||||
* @returns {string}
|
||||
*/
|
||||
protected discountAmountFormatted = (entry: IItemEntry): string => {
|
||||
return formatNumber(entry.discountAmount, {
|
||||
currencyCode: this.context.currencyCode,
|
||||
money: false,
|
||||
excerptZero: true,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user