mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
fix: (*): fix currency code.
This commit is contained in:
@@ -17,13 +17,17 @@ import { AppToaster } from 'components';
|
||||
|
||||
import { ERROR } from 'common/errors';
|
||||
import { useBillFormContext } from './BillFormProvider';
|
||||
import { orderingLinesIndexes, safeSumBy } from 'utils';
|
||||
import { compose, orderingLinesIndexes, safeSumBy } from 'utils';
|
||||
import { defaultBill, transformToEditForm } from './utils';
|
||||
import withSettings from 'containers/Settings/withSettings';
|
||||
|
||||
/**
|
||||
* Bill form.
|
||||
*/
|
||||
export default function BillForm() {
|
||||
function BillForm({
|
||||
// #withSettings
|
||||
baseCurrency,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
const history = useHistory();
|
||||
|
||||
@@ -46,6 +50,7 @@ export default function BillForm() {
|
||||
: {
|
||||
...defaultBill,
|
||||
entries: orderingLinesIndexes(defaultBill.entries),
|
||||
currency_code: baseCurrency,
|
||||
}),
|
||||
}),
|
||||
[bill],
|
||||
@@ -142,3 +147,8 @@ export default function BillForm() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default compose(
|
||||
withSettings(({ organizationSettings }) => ({
|
||||
baseCurrency: organizationSettings?.baseCurrency,
|
||||
})),
|
||||
)(BillForm);
|
||||
|
||||
@@ -11,15 +11,20 @@ export default function BillFormBody({ defaultBill }) {
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||
<FastField name={'entries'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
{({
|
||||
form: { values, setFieldValue },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<ItemsEntriesTable
|
||||
entries={value}
|
||||
onUpdateData={(entries) => {
|
||||
form.setFieldValue('entries', entries);
|
||||
setFieldValue('entries', entries);
|
||||
}}
|
||||
items={items}
|
||||
errors={error}
|
||||
linesNumber={4}
|
||||
currencyCode={values.currency_code}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
@@ -16,6 +16,7 @@ import { useFormikContext } from 'formik';
|
||||
export default function PaymentMadeEntriesTable({
|
||||
onUpdateData,
|
||||
entries,
|
||||
currencyCode,
|
||||
}) {
|
||||
// Payment made inner context.
|
||||
const { isNewEntriesFetching } = usePaymentMadeInnerContext();
|
||||
@@ -24,7 +25,9 @@ export default function PaymentMadeEntriesTable({
|
||||
const columns = usePaymentMadeEntriesTableColumns();
|
||||
|
||||
// Formik context.
|
||||
const { values: { vendor_id } } = useFormikContext();
|
||||
const {
|
||||
values: { vendor_id },
|
||||
} = useFormikContext();
|
||||
|
||||
// Handle update data.
|
||||
const handleUpdateData = useCallback(
|
||||
@@ -54,10 +57,11 @@ export default function PaymentMadeEntriesTable({
|
||||
payload={{
|
||||
errors: [],
|
||||
updateData: handleUpdateData,
|
||||
currencyCode,
|
||||
}}
|
||||
noResults={noResultsMessage}
|
||||
footer={true}
|
||||
/>
|
||||
</CloudLoadingIndicator>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import { defaultPaymentMade, transformToEditForm, ERRORS } from './utils';
|
||||
function PaymentMadeForm({
|
||||
// #withSettings
|
||||
preferredPaymentAccount,
|
||||
baseCurrency,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
const { formatMessage } = useIntl();
|
||||
@@ -54,6 +55,7 @@ function PaymentMadeForm({
|
||||
: {
|
||||
...defaultPaymentMade,
|
||||
payment_account_id: defaultTo(preferredPaymentAccount),
|
||||
currency_code: baseCurrency,
|
||||
entries: orderingLinesIndexes(defaultPaymentMade.entries),
|
||||
}),
|
||||
}),
|
||||
@@ -157,9 +159,10 @@ function PaymentMadeForm({
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSettings(({ billPaymentSettings }) => ({
|
||||
withSettings(({ billPaymentSettings, organizationSettings }) => ({
|
||||
paymentNextNumber: billPaymentSettings?.next_number,
|
||||
paymentNumberPrefix: billPaymentSettings?.number_prefix,
|
||||
preferredPaymentAccount: parseInt(billPaymentSettings?.withdrawalAccount),
|
||||
baseCurrency: organizationSettings?.baseCurrency,
|
||||
})),
|
||||
)(PaymentMadeForm);
|
||||
|
||||
@@ -5,18 +5,23 @@ import { CLASSES } from 'common/classes';
|
||||
import PaymentMadeEntriesTable from './PaymentMadeEntriesTable';
|
||||
|
||||
export default function PaymentMadeFormBody() {
|
||||
return (
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_BODY)}>
|
||||
<FastField name={'entries'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<PaymentMadeEntriesTable
|
||||
{({
|
||||
form: { setFieldValue, values },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<PaymentMadeEntriesTable
|
||||
entries={value}
|
||||
onUpdateData={(newEntries) => {
|
||||
form.setFieldValue('entries', newEntries);
|
||||
setFieldValue('entries', newEntries);
|
||||
}}
|
||||
currencyCode={values.currency_code}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { useIntl } from "react-intl";
|
||||
import { useIntl } from 'react-intl';
|
||||
import moment from 'moment';
|
||||
import { Money } from 'components';
|
||||
import { safeSumBy, formattedAmount } from 'utils';
|
||||
@@ -10,7 +10,7 @@ function BillNumberAccessor(row) {
|
||||
}
|
||||
|
||||
function IndexTableCell({ row: { index } }) {
|
||||
return (<span>{index + 1}</span>);
|
||||
return <span>{index + 1}</span>;
|
||||
}
|
||||
|
||||
function BillDateCell({ value }) {
|
||||
@@ -19,35 +19,34 @@ function BillDateCell({ value }) {
|
||||
/**
|
||||
* Balance footer cell.
|
||||
*/
|
||||
function AmountFooterCell({ rows }) {
|
||||
function AmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||
const total = safeSumBy(rows, 'original.amount');
|
||||
return <span>{ formattedAmount(total, 'USD') }</span>;
|
||||
return <span>{formattedAmount(total, currencyCode)}</span>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Due amount footer cell.
|
||||
*/
|
||||
function DueAmountFooterCell({ rows }) {
|
||||
function DueAmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||
const totalDueAmount = safeSumBy(rows, 'original.due_amount');
|
||||
return <span>{ formattedAmount(totalDueAmount, 'USD') }</span>;
|
||||
return <span>{formattedAmount(totalDueAmount, currencyCode)}</span>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payment amount footer cell.
|
||||
*/
|
||||
function PaymentAmountFooterCell({ rows }) {
|
||||
function PaymentAmountFooterCell({ payload: { currencyCode }, rows }) {
|
||||
const totalPaymentAmount = safeSumBy(rows, 'original.payment_amount');
|
||||
return <span>{ formattedAmount(totalPaymentAmount, 'USD') }</span>;
|
||||
return <span>{formattedAmount(totalPaymentAmount, currencyCode)}</span>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mobey table cell.
|
||||
*/
|
||||
function MoneyTableCell({ value }) {
|
||||
return <Money amount={value} currency={"USD"} />
|
||||
function MoneyTableCell({ row: { original }, value }) {
|
||||
return <Money amount={value} currency={original.currency_code} />;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Payment made entries table columns
|
||||
*/
|
||||
@@ -63,7 +62,7 @@ export function usePaymentMadeEntriesTableColumns() {
|
||||
width: 40,
|
||||
disableResizing: true,
|
||||
disableSortBy: true,
|
||||
className: 'index'
|
||||
className: 'index',
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'Date' }),
|
||||
@@ -106,5 +105,5 @@ export function usePaymentMadeEntriesTableColumns() {
|
||||
},
|
||||
],
|
||||
[formatMessage],
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ export const defaultPaymentMadeEntry = {
|
||||
currency_code:'',
|
||||
id: null,
|
||||
due_amount: null,
|
||||
amount:''
|
||||
};
|
||||
|
||||
// Default initial values of payment made.
|
||||
@@ -46,5 +47,7 @@ export const transformToNewPageEntries = (entries) => {
|
||||
return entries.map((entry) => ({
|
||||
...transformToForm(entry, defaultPaymentMadeEntry),
|
||||
payment_amount: '',
|
||||
currency_code:entry.currency_code,
|
||||
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user