mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// @ts-nocheck
|
||||
import * as Yup from 'yup';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
accounting_basis: Yup.string().required(),
|
||||
account_code_required: Yup.boolean().nullable(),
|
||||
account_code_unique: Yup.boolean().nullable(),
|
||||
withdrawal_account: Yup.number().nullable(),
|
||||
preferred_deposit_account: Yup.number().nullable(),
|
||||
preferred_advance_deposit: Yup.number().nullable(),
|
||||
});
|
||||
|
||||
export const AccountantSchema = Schema;
|
||||
@@ -0,0 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import AccountantFormPage from './AccountantFormPage';
|
||||
import { AccountantFormProvider } from './AccountantFormProvider';
|
||||
|
||||
/**
|
||||
* Accountant preferences.
|
||||
*/
|
||||
export default function AccountantPreferences() {
|
||||
return (
|
||||
<AccountantFormProvider>
|
||||
<AccountantFormPage />
|
||||
</AccountantFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Form, FastField, useFormikContext } from 'formik';
|
||||
import {
|
||||
FormGroup,
|
||||
RadioGroup,
|
||||
Radio,
|
||||
Checkbox,
|
||||
Button,
|
||||
Intent,
|
||||
} from '@blueprintjs/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import {
|
||||
FormattedMessage as T,
|
||||
AccountsSelectList,
|
||||
FieldRequiredHint,
|
||||
CardFooterActions,
|
||||
} from '@/components';
|
||||
import { handleStringChange, inputIntent } from '@/utils';
|
||||
import { ACCOUNT_TYPE } from '@/constants/accountTypes';
|
||||
|
||||
import { useAccountantFormContext } from './AccountantFormProvider';
|
||||
|
||||
/**
|
||||
* Accountant form.
|
||||
*/
|
||||
export default function AccountantForm() {
|
||||
const history = useHistory();
|
||||
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
const handleCloseClick = () => {
|
||||
history.go(-1);
|
||||
};
|
||||
|
||||
const { accounts } = useAccountantFormContext();
|
||||
|
||||
return (
|
||||
<Form>
|
||||
{/* ----------- Accounts ----------- */}
|
||||
<FormGroup
|
||||
label={
|
||||
<strong>
|
||||
<T id={'accounts'} />
|
||||
</strong>
|
||||
}
|
||||
className={'accounts-checkbox'}
|
||||
>
|
||||
{/*------------ account code required -----------*/}
|
||||
<FastField name={'account_code_required'} type={'checkbox'}>
|
||||
{({ field }) => (
|
||||
<FormGroup inline={true}>
|
||||
<Checkbox
|
||||
inline={true}
|
||||
label={
|
||||
<T
|
||||
id={'make_account_code_required_when_create_a_new_accounts'}
|
||||
/>
|
||||
}
|
||||
name={'account_code_required'}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/*------------ account code unique -----------*/}
|
||||
<FastField name={'account_code_unique'} type={'checkbox'}>
|
||||
{({ field }) => (
|
||||
<FormGroup inline={true}>
|
||||
<Checkbox
|
||||
inline={true}
|
||||
label={
|
||||
<T
|
||||
id={
|
||||
'should_account_code_be_unique_when_create_a_new_account'
|
||||
}
|
||||
/>
|
||||
}
|
||||
name={'account_code_unique'}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</FormGroup>
|
||||
{/* ----------- Accounting basis ----------- */}
|
||||
<FastField name={'accounting_basis'}>
|
||||
{({
|
||||
form: { setFieldValue },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
label={
|
||||
<strong>
|
||||
<T id={'accounting_basis_'} />
|
||||
</strong>
|
||||
}
|
||||
>
|
||||
<RadioGroup
|
||||
inline={true}
|
||||
selectedValue={value}
|
||||
onChange={handleStringChange((_value) => {
|
||||
setFieldValue('accounting_basis', _value);
|
||||
})}
|
||||
>
|
||||
<Radio label={intl.get('cash')} value="cash" />
|
||||
<Radio label={intl.get('accrual')} value="accrual" />
|
||||
</RadioGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ----------- Deposit customer account ----------- */}
|
||||
<FastField name={'preferred_deposit_account'}>
|
||||
{({
|
||||
form: { values, setFieldValue },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
label={
|
||||
<strong>
|
||||
<T id={'deposit_customer_account'} />
|
||||
</strong>
|
||||
}
|
||||
helperText={
|
||||
<T
|
||||
id={
|
||||
'select_a_preferred_account_to_deposit_into_it_after_customer_make_payment'
|
||||
}
|
||||
/>
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accounts}
|
||||
onAccountSelected={({ id }) => {
|
||||
setFieldValue('preferred_deposit_account', id);
|
||||
}}
|
||||
selectedAccountId={value}
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
filterByTypes={[
|
||||
ACCOUNT_TYPE.CASH,
|
||||
ACCOUNT_TYPE.BANK,
|
||||
ACCOUNT_TYPE.OTHER_CURRENT_ASSET,
|
||||
]}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ----------- Withdrawal vendor account ----------- */}
|
||||
<FastField name={'withdrawal_account'}>
|
||||
{({
|
||||
form: { values, setFieldValue },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
label={
|
||||
<strong>
|
||||
<T id={'withdrawal_vendor_account'} />
|
||||
</strong>
|
||||
}
|
||||
helperText={
|
||||
<T
|
||||
id={
|
||||
'select_a_preferred_account_to_deposit_into_it_after_customer_make_payment'
|
||||
}
|
||||
/>
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accounts}
|
||||
onAccountSelected={({ id }) => {
|
||||
setFieldValue('withdrawal_account', id);
|
||||
}}
|
||||
selectedAccountId={value}
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
filterByTypes={[
|
||||
ACCOUNT_TYPE.CASH,
|
||||
ACCOUNT_TYPE.BANK,
|
||||
ACCOUNT_TYPE.OTHER_CURRENT_ASSET,
|
||||
]}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/* ----------- Withdrawal customer account ----------- */}
|
||||
<FastField name={'preferred_advance_deposit'}>
|
||||
{({
|
||||
form: { values, setFieldValue },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
label={
|
||||
<strong>
|
||||
<T id={'customer_advance_deposit'} />
|
||||
</strong>
|
||||
}
|
||||
helperText={
|
||||
<T
|
||||
id={
|
||||
'select_a_preferred_account_to_deposit_into_it_vendor_advanced_deposits'
|
||||
}
|
||||
/>
|
||||
}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
>
|
||||
<AccountsSelectList
|
||||
accounts={accounts}
|
||||
onAccountSelected={({ id }) => {
|
||||
setFieldValue('preferred_advance_deposit', id);
|
||||
}}
|
||||
selectedAccountId={value}
|
||||
defaultSelectText={<T id={'select_payment_account'} />}
|
||||
// filterByParentTypes={[ACCOUNT_PARENT_TYPE.CURRENT_ASSET]}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
<CardFooterActions>
|
||||
<Button intent={Intent.PRIMARY} loading={isSubmitting} type="submit">
|
||||
<T id={'save'} />
|
||||
</Button>
|
||||
<Button disabled={isSubmitting} onClick={handleCloseClick}>
|
||||
<T id={'close'} />
|
||||
</Button>
|
||||
</CardFooterActions>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// @ts-nocheck
|
||||
import React, { useEffect } from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Formik } from 'formik';
|
||||
import { pick } from 'lodash';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
|
||||
import { AppToaster } from '@/components';
|
||||
|
||||
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
|
||||
import AccountantForm from './AccountantForm';
|
||||
import { AccountantSchema } from './Accountant.schema';
|
||||
import { useAccountantFormContext } from './AccountantFormProvider';
|
||||
import { transformToOptions } from './utils';
|
||||
import { compose, transformGeneralSettings } from '@/utils';
|
||||
|
||||
import '@/style/pages/Preferences/Accounting.scss';
|
||||
|
||||
// Accountant preferences.
|
||||
function AccountantFormPage({
|
||||
//# withDashboardActions
|
||||
changePreferencesPageTitle,
|
||||
|
||||
// #withSettings
|
||||
organizationSettings,
|
||||
paymentReceiveSettings,
|
||||
accountsSettings,
|
||||
billPaymentSettings,
|
||||
}) {
|
||||
const { saveSettingMutate } = useAccountantFormContext();
|
||||
|
||||
const accountantSettings = {
|
||||
...billPaymentSettings,
|
||||
...accountsSettings,
|
||||
...pick(organizationSettings, ['accountingBasis']),
|
||||
...pick(paymentReceiveSettings, ['preferredDepositAccount', 'preferredAdvanceDeposit']),
|
||||
};
|
||||
|
||||
const initialValues = {
|
||||
...transformGeneralSettings(accountantSettings),
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
changePreferencesPageTitle(intl.get('accountant'));
|
||||
}, [changePreferencesPageTitle]);
|
||||
|
||||
const handleFormSubmit = (values, { setSubmitting }) => {
|
||||
const options = transformToOptions(values);
|
||||
|
||||
setSubmitting(true);
|
||||
const onSuccess = () => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_accountant_preferences_has_been_saved'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
const onError = (errors) => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
saveSettingMutate({ options }).then(onSuccess).catch(onError);
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
validationSchema={AccountantSchema}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={AccountantForm}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSettings(
|
||||
({
|
||||
organizationSettings,
|
||||
paymentReceiveSettings,
|
||||
accountsSettings,
|
||||
billPaymentSettings,
|
||||
}) => ({
|
||||
organizationSettings,
|
||||
paymentReceiveSettings,
|
||||
accountsSettings,
|
||||
billPaymentSettings,
|
||||
}),
|
||||
),
|
||||
withDashboardActions,
|
||||
)(AccountantFormPage);
|
||||
@@ -0,0 +1,59 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { Card } from '@/components';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import { useAccounts, useSaveSettings, useSettings } from '@/hooks/query';
|
||||
import PreferencesPageLoader from '../PreferencesPageLoader';
|
||||
|
||||
const AccountantFormContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Accountant data provider.
|
||||
*/
|
||||
function AccountantFormProvider({ ...props }) {
|
||||
// Fetches the accounts list.
|
||||
const { isLoading: isAccountsLoading, data: accounts } = useAccounts();
|
||||
|
||||
//Fetches Organization Settings.
|
||||
const { isLoading: isSettingsLoading } = useSettings();
|
||||
|
||||
// Save Organization Settings.
|
||||
const { mutateAsync: saveSettingMutate } = useSaveSettings();
|
||||
|
||||
// Provider state.
|
||||
const provider = {
|
||||
accounts,
|
||||
isAccountsLoading,
|
||||
saveSettingMutate,
|
||||
};
|
||||
|
||||
const isLoading = isSettingsLoading || isAccountsLoading;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT,
|
||||
)}
|
||||
>
|
||||
<AccountantFormCard>
|
||||
{isLoading ? (
|
||||
<PreferencesPageLoader />
|
||||
) : (
|
||||
<AccountantFormContext.Provider value={provider} {...props} />
|
||||
)}
|
||||
</AccountantFormCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const useAccountantFormContext = () => React.useContext(AccountantFormContext);
|
||||
|
||||
export { AccountantFormProvider, useAccountantFormContext };
|
||||
|
||||
const AccountantFormCard = styled(Card)`
|
||||
padding: 25px;
|
||||
`;
|
||||
@@ -0,0 +1,38 @@
|
||||
// @ts-nocheck
|
||||
export const transformToOptions = (option) => {
|
||||
return [
|
||||
{
|
||||
key: 'accounting_basis',
|
||||
value: option.accounting_basis,
|
||||
group: 'organization',
|
||||
},
|
||||
{
|
||||
key: 'withdrawal_account',
|
||||
value: option.withdrawal_account,
|
||||
group: 'bill_payments',
|
||||
},
|
||||
{
|
||||
key: 'preferred_deposit_account',
|
||||
value: option.preferred_deposit_account,
|
||||
group: 'payment_receives',
|
||||
},
|
||||
{
|
||||
key: 'preferred_advance_deposit',
|
||||
value: option.preferred_advance_deposit,
|
||||
group: 'payment_receives',
|
||||
},
|
||||
{
|
||||
key: 'account_code_required',
|
||||
value: option.account_code_required,
|
||||
group: 'accounts',
|
||||
},
|
||||
{
|
||||
|
||||
key: 'account_code_unique',
|
||||
value: option.account_code_unique,
|
||||
group: 'accounts',
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user