Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Fix: Correctly display the discount percentage on Invoice Creation and discount fix on items #620

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class ItemEntryTransformer extends Transformer {
* @returns {string}
*/
protected totalFormatted = (entry: IItemEntry): string => {
return formatNumber(entry.total, {
const discountedTotal = entry.total - ((entry.total * entry.discount) / 100);
return formatNumber(discountedTotal, {
currencyCode: this.context.currencyCode,
money: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const PercentFieldCell = ({
return (
<FormGroup intent={error ? Intent.DANGER : null}>
<MoneyInputGroup
prefix={'%'}
suffix={'%'}
value={value}
onChange={handleChange}
onBlurValue={handleBlurChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export type CurrencyInputProps = Overwrite<
*/
prefix?: string;

/**
* Include a suffix eg. %
*/
suffix?: string;

/**
* Incremental value change on arrow down and arrow up key press
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const CurrencyInput: FC<CurrencyInputProps> = ({
placeholder,
precision,
prefix,
suffix,
step,
decimalSeparator = '.',
groupSeparator = ',',
Expand All @@ -52,6 +53,7 @@ export const CurrencyInput: FC<CurrencyInputProps> = ({
groupSeparator,
turnOffSeparators,
prefix,
suffix,
};

const cleanValueOptions: Partial<CleanValueOptions> = {
Expand All @@ -62,6 +64,7 @@ export const CurrencyInput: FC<CurrencyInputProps> = ({
allowNegativeValue,
turnOffAbbreviations,
prefix,
suffix,
};

const _defaultValue =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type CleanValueOptions = {
allowNegativeValue?: boolean;
turnOffAbbreviations?: boolean;
prefix?: string;
suffix?: string;
};

/**
Expand All @@ -27,12 +28,14 @@ export const cleanValue = ({
allowNegativeValue = true,
turnOffAbbreviations = false,
prefix = '',
suffix = '',
}: CleanValueOptions): string => {
const abbreviations = turnOffAbbreviations ? [] : ['k', 'm', 'b'];
const isNegative = value.includes('-');

const [prefixWithValue, preValue] = RegExp(`(\\d+)-?${escapeRegExp(prefix)}`).exec(value) || [];
const withoutPrefix = prefix ? value.replace(prefixWithValue, '').concat(preValue) : value;
// Remove suffix from value
const withoutSeparators = removeSeparators(withoutPrefix, groupSeparator);
const withoutInvalidChars = removeInvalidChars(withoutSeparators, [
groupSeparator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ type Props = {
* Prefix
*/
prefix?: string;

/**
* Suffix
*/
suffix?: string;
};

/**
* Format value with decimal separator, group separator and prefix
* Format value with decimal separator, group separator, prefix, and suffix
*/
export const formatValue = (props: Props): string => {
const {
Expand All @@ -46,6 +51,7 @@ export const formatValue = (props: Props): string => {
decimalSeparator = '.',
turnOffSeparators = false,
prefix,
suffix,
} = props;

if (_value === '' || _value === undefined) {
Expand Down Expand Up @@ -75,5 +81,7 @@ export const formatValue = (props: Props): string => {
? `${decimalSeparator}`
: '';

return `${includeNegative}${includePrefix}${formattedInt}${includeDecimals}`;
const includeSuffix = suffix ? suffix : '';

return `${includeNegative}${includePrefix}${formattedInt}${includeDecimals}${includeSuffix}`;
};
Loading