diff --git a/packages/server/src/services/Sales/Invoices/ItemEntryTransformer.ts b/packages/server/src/services/Sales/Invoices/ItemEntryTransformer.ts index dbaea48621..7a99e2e32f 100644 --- a/packages/server/src/services/Sales/Invoices/ItemEntryTransformer.ts +++ b/packages/server/src/services/Sales/Invoices/ItemEntryTransformer.ts @@ -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, }); diff --git a/packages/webapp/src/components/DataTableCells/PercentFieldCell.tsx b/packages/webapp/src/components/DataTableCells/PercentFieldCell.tsx index 9fdbf2e298..8b2bac7099 100644 --- a/packages/webapp/src/components/DataTableCells/PercentFieldCell.tsx +++ b/packages/webapp/src/components/DataTableCells/PercentFieldCell.tsx @@ -32,7 +32,7 @@ const PercentFieldCell = ({ return ( = ({ placeholder, precision, prefix, + suffix, step, decimalSeparator = '.', groupSeparator = ',', @@ -52,6 +53,7 @@ export const CurrencyInput: FC = ({ groupSeparator, turnOffSeparators, prefix, + suffix, }; const cleanValueOptions: Partial = { @@ -62,6 +64,7 @@ export const CurrencyInput: FC = ({ allowNegativeValue, turnOffAbbreviations, prefix, + suffix, }; const _defaultValue = diff --git a/packages/webapp/src/components/Forms/MoneyInputGroup/utils/cleanValue.ts b/packages/webapp/src/components/Forms/MoneyInputGroup/utils/cleanValue.ts index c417562a4c..9aa938bf36 100644 --- a/packages/webapp/src/components/Forms/MoneyInputGroup/utils/cleanValue.ts +++ b/packages/webapp/src/components/Forms/MoneyInputGroup/utils/cleanValue.ts @@ -13,6 +13,7 @@ export type CleanValueOptions = { allowNegativeValue?: boolean; turnOffAbbreviations?: boolean; prefix?: string; + suffix?: string; }; /** @@ -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, diff --git a/packages/webapp/src/components/Forms/MoneyInputGroup/utils/formatValue.ts b/packages/webapp/src/components/Forms/MoneyInputGroup/utils/formatValue.ts index 80d7ecfb42..2f89654c1f 100644 --- a/packages/webapp/src/components/Forms/MoneyInputGroup/utils/formatValue.ts +++ b/packages/webapp/src/components/Forms/MoneyInputGroup/utils/formatValue.ts @@ -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 { @@ -46,6 +51,7 @@ export const formatValue = (props: Props): string => { decimalSeparator = '.', turnOffSeparators = false, prefix, + suffix, } = props; if (_value === '' || _value === undefined) { @@ -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}`; };