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

format numbers as currency according to the language rules #52

Merged
merged 2 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
format numbers as currency according to the language rules
  • Loading branch information
madisvain committed Mar 8, 2020
commit 9380cbaefc2a2d95606038d450eb29da601c5cf1
3 changes: 2 additions & 1 deletion src/components/forms/fields.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Checkbox, DatePicker, Form, Input, Radio, Select } from 'antd';
import { Checkbox, DatePicker, Form, Input, InputNumber, Radio, Select } from 'antd';
import { withProps } from 'recompose';
import { isString } from 'lodash';
import moment from 'moment';
Expand Down Expand Up @@ -65,6 +65,7 @@ const makeField = Component => ({
};

export const AInput = makeField(Input);
export const AInputNumber = makeField(InputNumber);
export const APasswordInput = makeField(Input.Password);
export const ACheckbox = makeField(Checkbox);
export const ADatePicker = withProps({ picker: true })(makeField(DatePicker));
Expand Down
64 changes: 53 additions & 11 deletions src/pages/invoices/$id/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component } from 'react';
import { compose } from 'redux';
import { connect } from 'dva';
import { Spin } from 'antd';
import { Trans } from '@lingui/macro';
import { Trans, NumberFormat } from '@lingui/macro';
import { get, has, head } from 'lodash';

import getSymbolFromCurrency from 'currency-symbol-map';
Expand Down Expand Up @@ -224,8 +224,14 @@ class Invoice extends Component {
<Trans>Subtotal</Trans>
</td>
<td className="text-right">
{invoice.subTotal}
{getSymbolFromCurrency(invoice.currency)}
<NumberFormat
value={invoice.subTotal}
format={{
style: 'currency',
currency: invoice.currency,
minimumFractionDigits: get(organization, 'minimum_fraction_digits', 2),
}}
/>
</td>
</tr>
<tr>
Expand All @@ -234,8 +240,14 @@ class Invoice extends Component {
Tax
</td>
<td className="text-right border-top-0">
{invoice.taxTotal}
{getSymbolFromCurrency(invoice.currency)}
<NumberFormat
value={invoice.taxTotal}
format={{
style: 'currency',
currency: invoice.currency,
minimumFractionDigits: get(organization, 'minimum_fraction_digits', 2),
}}
/>
</td>
</tr>
<tr>
Expand All @@ -247,8 +259,18 @@ class Invoice extends Component {
</td>
<td className="text-right">
<strong>
{invoice.total}
{getSymbolFromCurrency(invoice.currency)}
<NumberFormat
value={invoice.total}
format={{
style: 'currency',
currency: invoice.currency,
minimumFractionDigits: get(
organization,
'minimum_fraction_digits',
2
),
}}
/>
</strong>
</td>
</tr>
Expand All @@ -260,12 +282,32 @@ class Invoice extends Component {
<td>{lineItem.description}</td>
<td className="min-width">{lineItem.quantity}</td>
<td className="min-width spaced text-right">
{lineItem.unitPrice}
{getSymbolFromCurrency(invoice.currency)}
<NumberFormat
value={lineItem.unitPrice}
format={{
style: 'currency',
currency: invoice.currency,
minimumFractionDigits: get(
organization,
'minimum_fraction_digits',
2
),
}}
/>
</td>
<td className="min-width spaced text-right">
{lineItem.subtotal}
{getSymbolFromCurrency(invoice.currency)}
<NumberFormat
value={lineItem.subtotal}
format={{
style: 'currency',
currency: invoice.currency,
minimumFractionDigits: get(
organization,
'minimum_fraction_digits',
2
),
}}
/>
</td>
</tr>
))}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/settings/invoice/_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { get, map } from 'lodash';

import currencyToSymbolMap from 'currency-symbol-map/map';

import { AInput, ASelect, ATextarea } from '../../../components/forms/fields';
import { AInput, AInputNumber, ASelect, ATextarea } from '../../../components/forms/fields';

class Settings extends Component {
componentDidMount() {
Expand Down Expand Up @@ -68,6 +68,13 @@ class Settings extends Component {
</Select.Option>
))}
</Field>
<Field
name="minimum_fraction_digits"
min={0}
max={10}
component={AInputNumber}
label={<Trans>Decimal places</Trans>}
/>
<Field name="due_days" component={AInput} label={<Trans>Due days</Trans>} />
<Field
name="overdue_charge"
Expand Down