mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
refactoring(accountant): accountant.
This commit is contained in:
@@ -1,61 +1,14 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Formik } from 'formik';
|
||||
import { useQuery } from 'react-query';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import { LoadingIndicator } from 'components';
|
||||
import AccountantForm from './AccountantForm';
|
||||
import { AccountantSchema } from './Accountant.schema';
|
||||
|
||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||
import withSettings from 'containers/Settings/withSettings';
|
||||
import withSettingsActions from 'containers/Settings/withSettingsActions';
|
||||
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
import 'style/pages/Preferences/Accounting.scss';
|
||||
|
||||
// Accountant preferences.
|
||||
function AccountantPreferences({
|
||||
changePreferencesPageTitle,
|
||||
|
||||
// #withAccountsActions
|
||||
requestFetchAccounts,
|
||||
}) {
|
||||
const initialValues = {};
|
||||
|
||||
useEffect(() => {
|
||||
changePreferencesPageTitle('Accountant');
|
||||
}, [changePreferencesPageTitle]);
|
||||
|
||||
const fetchAccounts = useQuery('accounts-list', (key) =>
|
||||
requestFetchAccounts(),
|
||||
);
|
||||
import React from 'react';
|
||||
import AccountantFormPage from './AccountantFormPage';
|
||||
import { AccountantFormProvider } from './AccountantFormProvider';
|
||||
|
||||
/**
|
||||
* Accountant preferences.
|
||||
*/
|
||||
export default function AccountantPreferences() {
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT,
|
||||
)}
|
||||
>
|
||||
<div className={classNames(CLASSES.CARD)}>
|
||||
<LoadingIndicator loading={fetchAccounts.isFetching} spinnerSize={28}>
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
validationSchema={AccountantSchema}
|
||||
component={AccountantForm}
|
||||
/>
|
||||
</LoadingIndicator>
|
||||
</div>
|
||||
</div>
|
||||
<AccountantFormProvider>
|
||||
<AccountantFormPage />
|
||||
</AccountantFormProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSettings(({ organizationSettings }) => ({ organizationSettings })),
|
||||
withSettingsActions,
|
||||
withDashboardActions,
|
||||
withAccountsActions,
|
||||
)(AccountantPreferences);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
import { Form, FastField, Field } from 'formik';
|
||||
import {
|
||||
FormGroup,
|
||||
RadioGroup,
|
||||
@@ -10,25 +10,35 @@ import {
|
||||
} from '@blueprintjs/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { AccountsSelectList } from 'components';
|
||||
import {
|
||||
FieldRequiredHint,
|
||||
} from 'components';
|
||||
import { FormattedMessage as T } from 'react-intl';
|
||||
import { compose } from 'utils';
|
||||
import withAccounts from 'containers/Accounts/withAccounts';
|
||||
import { FieldRequiredHint } from 'components';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
// import { } from 'common/accountTypes';
|
||||
import { handleStringChange, saveInvoke } from 'utils';
|
||||
|
||||
function AccountantForm({
|
||||
// #withAccounts
|
||||
accountsList,
|
||||
}) {
|
||||
import { useAccountantFormContext } from './AccountantFormProvider';
|
||||
|
||||
|
||||
|
||||
export default function AccountantForm() {
|
||||
const history = useHistory();
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const handleCloseClick = () => {
|
||||
history.go(-1);
|
||||
};
|
||||
|
||||
const { accounts } = useAccountantFormContext();
|
||||
|
||||
return (
|
||||
<Form>
|
||||
<FormGroup label={<strong>Accounts</strong>}>
|
||||
{/* ----------- accounts ----------- */}
|
||||
<FormGroup
|
||||
label={
|
||||
<strong>
|
||||
<T id={'accounts'} />
|
||||
</strong>
|
||||
}
|
||||
>
|
||||
<Checkbox
|
||||
label={'Make account code required when create a new accounts.'}
|
||||
/>
|
||||
@@ -36,58 +46,93 @@ function AccountantForm({
|
||||
label={'Should account code be unique when create a new account.'}
|
||||
/>
|
||||
</FormGroup>
|
||||
{/* ----------- accounting basis ----------- */}
|
||||
<FastField name={'accounting_basis'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
label={
|
||||
<strong>
|
||||
<T id={'accounting_basis_'} />
|
||||
</strong>
|
||||
}
|
||||
>
|
||||
<RadioGroup inline={true}>
|
||||
<Radio label={formatMessage({ id: 'Cash' })} value="cash" />
|
||||
<Radio label={formatMessage({ id: 'accrual' })} value="accrual" />
|
||||
</RadioGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/* ----------- deposit customer account ----------- */}
|
||||
<FastField name={'deposit_customer_account'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={
|
||||
<strong>
|
||||
<T id={'deposit_customer_account'} />
|
||||
</strong>
|
||||
}
|
||||
helperText={
|
||||
'Select a preferred account to deposit into it after customer make payment.'
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accounts}
|
||||
// onAccountSelected
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
// filterByTypes={['current_asset']}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
<FormGroup
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
label={<strong>Accounting Basis</strong>}>
|
||||
<RadioGroup inline={true}>
|
||||
<Radio label="Cash" value="cash" />
|
||||
<Radio label="Accural" value="accural" />
|
||||
</RadioGroup>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup
|
||||
label={<strong>Deposit customer account</strong>}
|
||||
helperText={
|
||||
'Select a preferred account to deposit into it after customer make payment.'
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accountsList}
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
filterByTypes={['current_asset']}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup
|
||||
label={<strong>Withdrawal customer account</strong>}
|
||||
helperText={
|
||||
'Select a preferred account to deposit into it after customer make payment.'
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accountsList}
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
filterByTypes={['current_asset']}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup
|
||||
label={<strong>Vendor advance deposit</strong>}
|
||||
helperText={
|
||||
'Select a preferred account to deposit into it vendor advanced deposits.'
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accountsList}
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
filterByTypes={['current_asset', 'other_current_asset']}
|
||||
/>
|
||||
</FormGroup>
|
||||
{/* ----------- withdrawal customer account ----------- */}
|
||||
<FastField name={'withdrawal_customer_account'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={
|
||||
<strong>
|
||||
<T id={'withdrawal_customer_account'} />
|
||||
</strong>
|
||||
}
|
||||
helperText={
|
||||
'Select a preferred account to deposit into it after customer make payment.'
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accounts}
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
// filterByTypes={['current_asset']}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ----------- withdrawal customer account ----------- */}
|
||||
<FastField name={'vendor_advance_deposit'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={
|
||||
<strong>
|
||||
<T id={'vendor_advance_deposit'} />
|
||||
</strong>
|
||||
}
|
||||
helperText={
|
||||
'Select a preferred account to deposit into it vendor advanced deposits.'
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accounts}
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
// filterByTypes={['current_asset', 'other_current_asset']}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<div className={'card__footer'}>
|
||||
<Button intent={Intent.PRIMARY} type="submit">
|
||||
<T id={'save'} />
|
||||
@@ -99,7 +144,3 @@ function AccountantForm({
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAccounts(({ accountsList }) => ({ accountsList })),
|
||||
)(AccountantForm);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Formik } from 'formik';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import AccountantForm from './AccountantForm';
|
||||
import { AccountantSchema } from './Accountant.schema';
|
||||
import { useAccountantFormContext } from './AccountantFormProvider';
|
||||
|
||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
import 'style/pages/Preferences/Accounting.scss';
|
||||
|
||||
// Accountant preferences.
|
||||
function AccountantFormPage({ changePreferencesPageTitle }) {
|
||||
|
||||
const { saveSettingMutate } = useAccountantFormContext();
|
||||
|
||||
const initialValues = {};
|
||||
|
||||
useEffect(() => {
|
||||
changePreferencesPageTitle('Accountant');
|
||||
}, [changePreferencesPageTitle]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT,
|
||||
)}
|
||||
>
|
||||
<div className={classNames(CLASSES.CARD)}>
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
validationSchema={AccountantSchema}
|
||||
component={AccountantForm}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDashboardActions)(AccountantFormPage);
|
||||
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
import { LoadingIndicator } from 'components';
|
||||
import { useAccounts, useSaveSettings, useSettings } from 'hooks/query';
|
||||
|
||||
const AccountantFormContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Accountant data provider.
|
||||
*/
|
||||
function AccountantFormProvider({ ...props }) {
|
||||
// Fetches the accounts list.
|
||||
const { isFetching: isAccountsLoading, data: accounts } = useAccounts();
|
||||
|
||||
//Fetches Organization Settings.
|
||||
const { isFetching: isSettingsLoading } = useSettings();
|
||||
|
||||
// Save Organization Settings.
|
||||
const { mutateAsync: saveSettingMutate } = useSaveSettings();
|
||||
|
||||
// Provider state.
|
||||
const provider = {
|
||||
accounts,
|
||||
isAccountsLoading,
|
||||
saveSettingMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
<LoadingIndicator loading={isSettingsLoading || isAccountsLoading}>
|
||||
<AccountantFormContext.Provider value={provider} {...props} />
|
||||
</LoadingIndicator>
|
||||
);
|
||||
}
|
||||
|
||||
const useAccountantFormContext = () => React.useContext(AccountantFormContext);
|
||||
export { AccountantFormProvider, useAccountantFormContext };
|
||||
@@ -9,6 +9,7 @@ export const ERRORS = {
|
||||
export const defaultPaymentMadeEntry = {
|
||||
bill_id: '',
|
||||
payment_amount: '',
|
||||
currency_code:'',
|
||||
id: null,
|
||||
due_amount: null,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const ACCOUNTS = {
|
||||
ACCOUNT: 'ACCOUNT',
|
||||
ACCOUNTS: 'ACCOUNTS',
|
||||
ACCOUNTS_TYPES: 'ACCOUNTS_TYPES'
|
||||
ACCOUNTS_TYPES: 'ACCOUNTS_TYPES',
|
||||
};
|
||||
|
||||
const FINANCIAL_REPORTS = {
|
||||
@@ -18,7 +18,7 @@ const FINANCIAL_REPORTS = {
|
||||
const BILLS = {
|
||||
BILLS: 'BILLS',
|
||||
BILL: 'BILL',
|
||||
BILLS_DUE: 'BILLS_DUE'
|
||||
BILLS_DUE: 'BILLS_DUE',
|
||||
};
|
||||
|
||||
const VENDORS = {
|
||||
@@ -45,7 +45,7 @@ const SALE_ESTIMATES = {
|
||||
const SALE_RECEIPTS = {
|
||||
SALE_RECEIPTS: 'SALE_RECEIPTS',
|
||||
SALE_RECEIPT: 'SALE_RECEIPT',
|
||||
}
|
||||
};
|
||||
|
||||
const INVENTORY_ADJUSTMENTS = {
|
||||
INVENTORY_ADJUSTMENTS: 'INVENTORY_ADJUSTMENTS',
|
||||
@@ -77,7 +77,7 @@ const SALE_INVOICES = {
|
||||
|
||||
const USERS = {
|
||||
USERS: 'USERS',
|
||||
USER: 'USER'
|
||||
USER: 'USER',
|
||||
};
|
||||
|
||||
const SETTING = {
|
||||
@@ -91,7 +91,7 @@ const SETTING = {
|
||||
|
||||
const ORGANIZATIONS = {
|
||||
ORGANIZATIONS: 'ORGANIZATIONS',
|
||||
ORGANIZATION_CURRENT: 'ORGANIZATION_CURRENT'
|
||||
ORGANIZATION_CURRENT: 'ORGANIZATION_CURRENT',
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -111,4 +111,4 @@ export default {
|
||||
...USERS,
|
||||
...SETTING,
|
||||
...ORGANIZATIONS,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1011,4 +1011,8 @@ export default {
|
||||
quick_made_payment: 'Quick Made Payment',
|
||||
the_payment_amount_bigger_than_invoice_due_amount:
|
||||
'The payment amount bigger than invoice due amount.',
|
||||
accounting_basis_: 'Accounting Basis',
|
||||
deposit_customer_account: 'Deposit customer account',
|
||||
withdrawal_customer_account: 'Withdrawal customer account',
|
||||
vendor_advance_deposit: 'Vendor advance deposit',
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import General from 'containers/Preferences/General/General';
|
||||
import Users from 'containers/Preferences/Users/Users';
|
||||
// import Accountant from 'containers/Preferences/Accountant/Accountant';
|
||||
import Accountant from 'containers/Preferences/Accountant/Accountant';
|
||||
import Accounts from 'containers/Preferences/Accounts/Accounts';
|
||||
import Currencies from 'containers/Preferences/Currencies/Currencies'
|
||||
import Currencies from 'containers/Preferences/Currencies/Currencies';
|
||||
|
||||
const BASE_URL = '/preferences';
|
||||
|
||||
@@ -22,9 +22,9 @@ export default [
|
||||
component: Currencies,
|
||||
exact: true,
|
||||
},
|
||||
// {
|
||||
// path: `${BASE_URL}/accountant`,
|
||||
// component: Accountant,
|
||||
// exact: true,
|
||||
// },
|
||||
{
|
||||
path: `${BASE_URL}/accountant`,
|
||||
component: Accountant,
|
||||
exact: true,
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user