From 9d1cb8791f6b74a1a325afe641f4b289e54de933 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sun, 15 Nov 2020 19:03:26 +0200 Subject: [PATCH] fix :default currency in make journal form. --- .../Accounting/MakeJournalEntriesForm.js | 5 ++- .../Accounting/MakeJournalEntriesHeader.js | 45 +++++++++++++++++-- .../Accounting/MakeJournalEntriesPage.js | 15 +++++-- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/client/src/containers/Accounting/MakeJournalEntriesForm.js b/client/src/containers/Accounting/MakeJournalEntriesForm.js index aa8f86fe8..dec6f8304 100644 --- a/client/src/containers/Accounting/MakeJournalEntriesForm.js +++ b/client/src/containers/Accounting/MakeJournalEntriesForm.js @@ -126,6 +126,7 @@ function MakeJournalEntriesForm({ date: Yup.date() .required() .label(formatMessage({ id: 'date' })), + currency_code: Yup.string(), reference: Yup.string().min(1).max(255), description: Yup.string().min(1).max(1024), entries: Yup.array().of( @@ -172,6 +173,7 @@ function MakeJournalEntriesForm({ date: moment(new Date()).format('YYYY-MM-DD'), description: '', reference: '', + currency_code: '', entries: [...repeatValue(defaultEntry, 4)], }), [defaultEntry, journalNumber], @@ -442,11 +444,12 @@ function MakeJournalEntriesForm({ }, [changePageSubtitle], ); - + console.log(values, 'Val'); return (
{ const formatted = moment(date).format('YYYY-MM-DD'); @@ -57,6 +68,19 @@ function MakeJournalEntriesHeader({ saveInvoke(onJournalNumberChanged, event.currentTarget.value); }; + const onItemsSelect = useCallback( + (filedName) => { + return (filed) => { + setSelectedItems({ + ...selectedItems, + [filedName]: filed, + }); + setFieldValue(filedName, filed.currency_code); + }; + }, + [setFieldValue, selectedItems], + ); + return (
@@ -197,7 +221,12 @@ function MakeJournalEntriesHeader({ CLASSES.FILL, )} > - + @@ -205,4 +234,12 @@ function MakeJournalEntriesHeader({ ); } -export default compose(withDialogActions)(MakeJournalEntriesHeader); +export default compose( + withDialogActions, + withSettings(({ organizationSettings }) => ({ + baseCurrency: organizationSettings?.baseCurrency, + })), + withCurrencies(({ currenciesList }) => ({ + currenciesList, + })), +)(MakeJournalEntriesHeader); diff --git a/client/src/containers/Accounting/MakeJournalEntriesPage.js b/client/src/containers/Accounting/MakeJournalEntriesPage.js index 5faeb3317..387d0d301 100644 --- a/client/src/containers/Accounting/MakeJournalEntriesPage.js +++ b/client/src/containers/Accounting/MakeJournalEntriesPage.js @@ -8,6 +8,7 @@ import DashboardInsider from 'components/Dashboard/DashboardInsider'; import withCustomersActions from 'containers/Customers/withCustomersActions'; import withAccountsActions from 'containers/Accounts/withAccountsActions'; import withManualJournalsActions from 'containers/Accounting/withManualJournalsActions'; +import withCurrenciesActions from 'containers/Currencies/withCurrenciesActions'; import withSettingsActions from 'containers/Settings/withSettingsActions'; import { compose } from 'utils'; @@ -22,6 +23,9 @@ function MakeJournalEntriesPage({ // #withManualJournalActions requestFetchManualJournal, + // #wihtCurrenciesActions + requestFetchCurrencies, + // #withSettingsActions requestFetchOptions, }) { @@ -36,11 +40,12 @@ function MakeJournalEntriesPage({ requestFetchCustomers(), ); - const fetchSettings = useQuery( - ['settings'], - () => requestFetchOptions({}), + const fetchCurrencies = useQuery('currencies', () => + requestFetchCurrencies(), ); + const fetchSettings = useQuery(['settings'], () => requestFetchOptions({})); + const fetchJournal = useQuery( ['manual-journal', id], (key, journalId) => requestFetchManualJournal(journalId), @@ -63,6 +68,7 @@ function MakeJournalEntriesPage({ loading={ fetchJournal.isFetching || fetchAccounts.isFetching || + fetchCurrencies.isFetching || fetchCustomers.isFetching } name={'make-journal-page'} @@ -80,5 +86,6 @@ export default compose( withAccountsActions, withCustomersActions, withManualJournalsActions, - withSettingsActions + withCurrenciesActions, + withSettingsActions, )(MakeJournalEntriesPage);