mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -26,7 +26,6 @@ import {
|
|||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withCurrencies from 'containers/Currencies/withCurrencies';
|
import withCurrencies from 'containers/Currencies/withCurrencies';
|
||||||
import withSettings from 'containers/Settings/withSettings';
|
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
@@ -41,9 +40,6 @@ function MakeJournalEntriesHeader({
|
|||||||
manualJournal,
|
manualJournal,
|
||||||
onJournalNumberChanged,
|
onJournalNumberChanged,
|
||||||
|
|
||||||
// #withSettings
|
|
||||||
baseCurrency,
|
|
||||||
|
|
||||||
// #withCurrencies
|
// #withCurrencies
|
||||||
currenciesList,
|
currenciesList,
|
||||||
|
|
||||||
@@ -225,7 +221,7 @@ function MakeJournalEntriesHeader({
|
|||||||
currenciesList={currenciesList}
|
currenciesList={currenciesList}
|
||||||
selectedCurrencyCode={values.currency_code}
|
selectedCurrencyCode={values.currency_code}
|
||||||
onCurrencySelected={onItemsSelect('currency_code')}
|
onCurrencySelected={onItemsSelect('currency_code')}
|
||||||
defaultSelectText={baseCurrency}
|
defaultSelectText={values.currency_code}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -236,9 +232,6 @@ function MakeJournalEntriesHeader({
|
|||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
withSettings(({ organizationSettings }) => ({
|
|
||||||
baseCurrency: organizationSettings?.baseCurrency,
|
|
||||||
})),
|
|
||||||
withCurrencies(({ currenciesList }) => ({
|
withCurrencies(({ currenciesList }) => ({
|
||||||
currenciesList,
|
currenciesList,
|
||||||
})),
|
})),
|
||||||
|
|||||||
69
client/src/containers/Expenses/ExpenseFloatingActions.js
Normal file
69
client/src/containers/Expenses/ExpenseFloatingActions.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Intent, Button } from '@blueprintjs/core';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
import { CLASSES } from 'common/classes';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { saveInvoke } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expense form floating actions.
|
||||||
|
*/
|
||||||
|
export default function ExpenseFloatingFooter({
|
||||||
|
isSubmitting,
|
||||||
|
onSubmitClick,
|
||||||
|
onCancelClick,
|
||||||
|
onDraftClick,
|
||||||
|
onSubmitAndNewClick,
|
||||||
|
expense,
|
||||||
|
}) {
|
||||||
|
const handleSubmitBtnClick = (event) => {
|
||||||
|
saveInvoke(onSubmitClick, event);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancelBtnClick = (event) => {
|
||||||
|
saveInvoke(onCancelClick, event);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmitAndDraftBtnClick = (event) => {
|
||||||
|
saveInvoke(onDraftClick, event);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmitAndNewBtnClick = (event) => {
|
||||||
|
saveInvoke(onSubmitAndNewClick, event);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
||||||
|
<Button
|
||||||
|
disabled={isSubmitting}
|
||||||
|
intent={Intent.PRIMARY}
|
||||||
|
type="submit"
|
||||||
|
onClick={handleSubmitBtnClick}
|
||||||
|
>
|
||||||
|
{expense && expense.id ? <T id={'edit'} /> : <T id={'save'} />}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className={'ml1'}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
onClick={handleSubmitAndNewBtnClick}
|
||||||
|
type="submit"
|
||||||
|
>
|
||||||
|
<T id={'save_new'} />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className={'ml1'}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
onClick={handleSubmitAndDraftBtnClick}
|
||||||
|
>
|
||||||
|
<T id={'save_as_draft'} />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button className={'ml1'} onClick={handleCancelBtnClick}>
|
||||||
|
<T id={'close'} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Intent, Button } from '@blueprintjs/core';
|
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
|
||||||
|
|
||||||
export default function ExpenseFloatingFooter({
|
|
||||||
formik: { isSubmitting },
|
|
||||||
onSubmitClick,
|
|
||||||
onCancelClick,
|
|
||||||
|
|
||||||
expense,
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className={'form__floating-footer'}>
|
|
||||||
<Button
|
|
||||||
disabled={isSubmitting}
|
|
||||||
intent={Intent.PRIMARY}
|
|
||||||
type="submit"
|
|
||||||
onClick={() => {
|
|
||||||
onSubmitClick({ publish: true, redirect: true });
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{expense && expense.id ? <T id={'edit'} /> : <T id={'save'} />}
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
disabled={isSubmitting}
|
|
||||||
intent={Intent.PRIMARY}
|
|
||||||
className={'ml1'}
|
|
||||||
name={'save_and_new'}
|
|
||||||
onClick={() => {
|
|
||||||
onSubmitClick({ publish: true, redirect: false });
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<T id={'save_new'} />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
className={'ml1'}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
onClick={() => {
|
|
||||||
onSubmitClick({ publish: false, redirect: false });
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<T id={'save_as_draft'} />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
className={'ml1'}
|
|
||||||
onClick={() => {
|
|
||||||
onCancelClick && onCancelClick();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<T id={'close'} />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -11,28 +11,33 @@ import moment from 'moment';
|
|||||||
import { Intent, FormGroup, TextArea } from '@blueprintjs/core';
|
import { Intent, FormGroup, TextArea } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import ExpenseFormHeader from './ExpenseFormHeader';
|
import ExpenseFormHeader from './ExpenseFormHeader';
|
||||||
import ExpenseTable from './ExpenseTable';
|
import ExpenseTable from './ExpenseTable';
|
||||||
import ExpenseFloatingFooter from './ExpenseFooter';
|
import ExpenseFloatingFooter from './ExpenseFloatingActions';
|
||||||
|
|
||||||
import withExpensesActions from 'containers/Expenses/withExpensesActions';
|
import withExpensesActions from 'containers/Expenses/withExpensesActions';
|
||||||
import withExpenseDetail from 'containers/Expenses/withExpenseDetail';
|
import withExpenseDetail from 'containers/Expenses/withExpenseDetail';
|
||||||
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
import withMediaActions from 'containers/Media/withMediaActions';
|
import withMediaActions from 'containers/Media/withMediaActions';
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
|
||||||
import AppToaster from 'components/AppToaster';
|
import AppToaster from 'components/AppToaster';
|
||||||
import Dragzone from 'components/Dragzone';
|
import Dragzone from 'components/Dragzone';
|
||||||
|
|
||||||
import useMedia from 'hooks/useMedia';
|
import useMedia from 'hooks/useMedia';
|
||||||
import { compose, repeatValue } from 'utils';
|
import { compose, repeatValue, transformToForm } from 'utils';
|
||||||
|
|
||||||
const MIN_LINES_NUMBER = 4;
|
const MIN_LINES_NUMBER = 4;
|
||||||
const ERROR = {
|
const ERROR = {
|
||||||
EXPENSE_ALREADY_PUBLISHED: 'EXPENSE.ALREADY.PUBLISHED',
|
EXPENSE_ALREADY_PUBLISHED: 'EXPENSE.ALREADY.PUBLISHED',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expense form.
|
||||||
|
*/
|
||||||
function ExpenseForm({
|
function ExpenseForm({
|
||||||
// #withMedia
|
// #withMedia
|
||||||
requestSubmitMedia,
|
requestSubmitMedia,
|
||||||
@@ -49,13 +54,20 @@ function ExpenseForm({
|
|||||||
//#withExpenseDetail
|
//#withExpenseDetail
|
||||||
expense,
|
expense,
|
||||||
|
|
||||||
|
// #withSettings
|
||||||
|
baseCurrency,
|
||||||
|
preferredPaymentAccount,
|
||||||
|
|
||||||
// #own Props
|
// #own Props
|
||||||
expenseId,
|
expenseId,
|
||||||
onFormSubmit,
|
onFormSubmit,
|
||||||
onCancelForm,
|
onCancelForm,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
const [payload, setPayload] = useState({});
|
const [payload, setPayload] = useState({});
|
||||||
|
|
||||||
|
const history = useHistory();
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setFiles,
|
setFiles,
|
||||||
saveMedia,
|
saveMedia,
|
||||||
@@ -67,23 +79,6 @@ function ExpenseForm({
|
|||||||
deleteCallback: requestDeleteMedia,
|
deleteCallback: requestDeleteMedia,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleDropFiles = useCallback((_files) => {
|
|
||||||
setFiles(_files.filter((file) => file.uploaded === false));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const savedMediaIds = useRef([]);
|
|
||||||
const clearSavedMediaIds = () => {
|
|
||||||
savedMediaIds.current = [];
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (expense && expense.id) {
|
|
||||||
changePageTitle(formatMessage({ id: 'edit_expense' }));
|
|
||||||
} else {
|
|
||||||
changePageTitle(formatMessage({ id: 'new_expense' }));
|
|
||||||
}
|
|
||||||
}, [changePageTitle, expense, formatMessage]);
|
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
beneficiary: Yup.string().label(formatMessage({ id: 'beneficiary' })),
|
beneficiary: Yup.string().label(formatMessage({ id: 'beneficiary' })),
|
||||||
payment_account_id: Yup.number()
|
payment_account_id: Yup.number()
|
||||||
@@ -117,11 +112,27 @@ function ExpenseForm({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleDropFiles = useCallback((_files) => {
|
||||||
|
setFiles(_files.filter((file) => file.uploaded === false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const savedMediaIds = useRef([]);
|
||||||
|
const clearSavedMediaIds = () => {
|
||||||
|
savedMediaIds.current = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (expense && expense.id) {
|
||||||
|
changePageTitle(formatMessage({ id: 'edit_expense' }));
|
||||||
|
} else {
|
||||||
|
changePageTitle(formatMessage({ id: 'new_expense' }));
|
||||||
|
}
|
||||||
|
}, [changePageTitle, expense, formatMessage]);
|
||||||
|
|
||||||
const saveInvokeSubmit = useCallback(
|
const saveInvokeSubmit = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
onFormSubmit && onFormSubmit(payload);
|
onFormSubmit && onFormSubmit(payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
[onFormSubmit],
|
[onFormSubmit],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -137,12 +148,12 @@ function ExpenseForm({
|
|||||||
|
|
||||||
const defaultInitialValues = useMemo(
|
const defaultInitialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
payment_account_id: '',
|
payment_account_id: parseInt(preferredPaymentAccount),
|
||||||
beneficiary: '',
|
beneficiary: '',
|
||||||
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
description: '',
|
description: '',
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
currency_code: '',
|
currency_code: baseCurrency,
|
||||||
categories: [...repeatValue(defaultCategory, MIN_LINES_NUMBER)],
|
categories: [...repeatValue(defaultCategory, MIN_LINES_NUMBER)],
|
||||||
}),
|
}),
|
||||||
[defaultCategory],
|
[defaultCategory],
|
||||||
@@ -205,7 +216,15 @@ function ExpenseForm({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const formik = useFormik({
|
const {
|
||||||
|
values,
|
||||||
|
errors,
|
||||||
|
touched,
|
||||||
|
isSubmitting,
|
||||||
|
setFieldValue,
|
||||||
|
handleSubmit,
|
||||||
|
getFieldProps,
|
||||||
|
} = useFormik({
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
validationSchema,
|
validationSchema,
|
||||||
initialValues: {
|
initialValues: {
|
||||||
@@ -294,20 +313,20 @@ function ExpenseForm({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmitClick = useCallback(
|
const handleSubmitClick = useCallback(() => {
|
||||||
(payload) => {
|
setPayload({ publish: true, redirect: true });
|
||||||
setPayload(payload);
|
}, [setPayload]);
|
||||||
formik.submitForm();
|
|
||||||
},
|
|
||||||
[setPayload, formik],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleCancelClick = useCallback(
|
const handleCancelClick = useCallback(() => {
|
||||||
(payload) => {
|
history.goBack();
|
||||||
onCancelForm && onCancelForm(payload);
|
}, []);
|
||||||
},
|
|
||||||
[onCancelForm],
|
const handleSubmitAndNewClick = useCallback(() => {
|
||||||
);
|
setPayload({ publish: true, redirect: false });
|
||||||
|
});
|
||||||
|
const handleSubmitAndDraftClick = useCallback(() => {
|
||||||
|
setPayload({ publish: false, redirect: false });
|
||||||
|
});
|
||||||
|
|
||||||
const handleDeleteFile = useCallback(
|
const handleDeleteFile = useCallback(
|
||||||
(_deletedFiles) => {
|
(_deletedFiles) => {
|
||||||
@@ -322,14 +341,14 @@ function ExpenseForm({
|
|||||||
|
|
||||||
// Handle click on add a new line/row.
|
// Handle click on add a new line/row.
|
||||||
const handleClickAddNewRow = () => {
|
const handleClickAddNewRow = () => {
|
||||||
formik.setFieldValue(
|
setFieldValue(
|
||||||
'categories',
|
'categories',
|
||||||
orderingCategoriesIndex([...formik.values.categories, defaultCategory]),
|
orderingCategoriesIndex([...values.categories, defaultCategory]),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClearAllLines = () => {
|
const handleClearAllLines = () => {
|
||||||
formik.setFieldValue(
|
setFieldValue(
|
||||||
'categories',
|
'categories',
|
||||||
orderingCategoriesIndex([
|
orderingCategoriesIndex([
|
||||||
...repeatValue(defaultCategory, MIN_LINES_NUMBER),
|
...repeatValue(defaultCategory, MIN_LINES_NUMBER),
|
||||||
@@ -337,21 +356,23 @@ function ExpenseForm({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const categories = formik.values.categories.filter(
|
|
||||||
(category) =>
|
|
||||||
category.amount && category.index && category.expense_account_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'expense-form'}>
|
<div className={'expense-form'}>
|
||||||
<form onSubmit={formik.handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<ExpenseFormHeader formik={formik} />
|
<ExpenseFormHeader
|
||||||
|
errors={errors}
|
||||||
|
touched={touched}
|
||||||
|
values={values}
|
||||||
|
setFieldValue={setFieldValue}
|
||||||
|
getFieldProps={getFieldProps}
|
||||||
|
/>
|
||||||
|
|
||||||
<ExpenseTable
|
<ExpenseTable
|
||||||
categories={formik.values.categories}
|
categories={values.categories}
|
||||||
onClickAddNewRow={handleClickAddNewRow}
|
onClickAddNewRow={handleClickAddNewRow}
|
||||||
onClickClearAllLines={handleClearAllLines}
|
onClickClearAllLines={handleClearAllLines}
|
||||||
formik={formik}
|
errors={errors}
|
||||||
|
setFieldValue={setFieldValue}
|
||||||
defaultRow={defaultCategory}
|
defaultRow={defaultCategory}
|
||||||
/>
|
/>
|
||||||
<div class="expense-form-footer">
|
<div class="expense-form-footer">
|
||||||
@@ -359,10 +380,7 @@ function ExpenseForm({
|
|||||||
label={<T id={'description'} />}
|
label={<T id={'description'} />}
|
||||||
className={'form-group--description'}
|
className={'form-group--description'}
|
||||||
>
|
>
|
||||||
<TextArea
|
<TextArea growVertically={true} {...getFieldProps('description')} />
|
||||||
growVertically={true}
|
|
||||||
{...formik.getFieldProps('description')}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
<Dragzone
|
<Dragzone
|
||||||
@@ -372,13 +390,16 @@ function ExpenseForm({
|
|||||||
hint={'Attachments: Maxiumum size: 20MB'}
|
hint={'Attachments: Maxiumum size: 20MB'}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
<ExpenseFloatingFooter
|
<ExpenseFloatingFooter
|
||||||
formik={formik}
|
isSubmitting={isSubmitting}
|
||||||
onSubmitClick={handleSubmitClick}
|
onSubmitClick={handleSubmitClick}
|
||||||
expense={expense}
|
|
||||||
onCancelClick={handleCancelClick}
|
onCancelClick={handleCancelClick}
|
||||||
|
onDraftClick={handleSubmitAndDraftClick}
|
||||||
|
onSubmitAndNewClick={handleSubmitAndNewClick}
|
||||||
|
expense={expense}
|
||||||
/>
|
/>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -389,4 +410,8 @@ export default compose(
|
|||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withMediaActions,
|
withMediaActions,
|
||||||
withExpenseDetail(),
|
withExpenseDetail(),
|
||||||
|
withSettings(({ organizationSettings, expenseSettings }) => ({
|
||||||
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
|
preferredPaymentAccount: expenseSettings?.preferredPaymentAccount,
|
||||||
|
})),
|
||||||
)(ExpenseForm);
|
)(ExpenseForm);
|
||||||
|
|||||||
@@ -26,10 +26,21 @@ import withAccounts from 'containers/Accounts/withAccounts';
|
|||||||
import withCustomers from 'containers/Customers/withCustomers';
|
import withCustomers from 'containers/Customers/withCustomers';
|
||||||
|
|
||||||
function ExpenseFormHeader({
|
function ExpenseFormHeader({
|
||||||
formik: { errors, touched, setFieldValue, getFieldProps, values },
|
// #ownProps
|
||||||
|
errors,
|
||||||
|
touched,
|
||||||
|
setFieldValue,
|
||||||
|
getFieldProps,
|
||||||
|
values,
|
||||||
|
|
||||||
|
//withCurrencies
|
||||||
currenciesList,
|
currenciesList,
|
||||||
|
|
||||||
|
// #withAccounts
|
||||||
accountsList,
|
accountsList,
|
||||||
accountsTypes,
|
accountsTypes,
|
||||||
|
|
||||||
|
// #withCustomers
|
||||||
customers,
|
customers,
|
||||||
}) {
|
}) {
|
||||||
const [selectedItems, setSelectedItems] = useState({});
|
const [selectedItems, setSelectedItems] = useState({});
|
||||||
@@ -171,6 +182,7 @@ function ExpenseFormHeader({
|
|||||||
currenciesList={currenciesList}
|
currenciesList={currenciesList}
|
||||||
selectedCurrencyCode={values.currency_code}
|
selectedCurrencyCode={values.currency_code}
|
||||||
onCurrencySelected={onItemsSelect('currency_code')}
|
onCurrencySelected={onItemsSelect('currency_code')}
|
||||||
|
defaultSelectText={values.currency_code}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -94,7 +94,8 @@ function ExpenseTable({
|
|||||||
onClickClearAllLines,
|
onClickClearAllLines,
|
||||||
defaultRow,
|
defaultRow,
|
||||||
categories,
|
categories,
|
||||||
formik: { errors, setFieldValue, resetForm },
|
errors,
|
||||||
|
setFieldValue,
|
||||||
}) {
|
}) {
|
||||||
const [rows, setRows] = useState([]);
|
const [rows, setRows] = useState([]);
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import withMediaActions from 'containers/Media/withMediaActions';
|
|||||||
import useMedia from 'hooks/useMedia';
|
import useMedia from 'hooks/useMedia';
|
||||||
import withItemDetail from 'containers/Items/withItemDetail';
|
import withItemDetail from 'containers/Items/withItemDetail';
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
|
||||||
import { compose, transformToForm } from 'utils';
|
import { compose, transformToForm } from 'utils';
|
||||||
|
|
||||||
@@ -54,6 +55,11 @@ function ItemForm({
|
|||||||
changePageTitle,
|
changePageTitle,
|
||||||
changePageSubtitle,
|
changePageSubtitle,
|
||||||
|
|
||||||
|
// #withSettings
|
||||||
|
preferredCostAccount,
|
||||||
|
preferredSellAccount,
|
||||||
|
preferredInventoryAccount,
|
||||||
|
|
||||||
// #withMediaActions
|
// #withMediaActions
|
||||||
requestSubmitMedia,
|
requestSubmitMedia,
|
||||||
requestDeleteMedia,
|
requestDeleteMedia,
|
||||||
@@ -89,13 +95,15 @@ function ItemForm({
|
|||||||
sku: Yup.string().trim(),
|
sku: Yup.string().trim(),
|
||||||
cost_price: Yup.number().when(['purchasable'], {
|
cost_price: Yup.number().when(['purchasable'], {
|
||||||
is: true,
|
is: true,
|
||||||
then: Yup.number().required()
|
then: Yup.number()
|
||||||
|
.required()
|
||||||
.label(formatMessage({ id: 'cost_price_' })),
|
.label(formatMessage({ id: 'cost_price_' })),
|
||||||
otherwise: Yup.number().nullable(true),
|
otherwise: Yup.number().nullable(true),
|
||||||
}),
|
}),
|
||||||
sell_price: Yup.number().when(['sellable'], {
|
sell_price: Yup.number().when(['sellable'], {
|
||||||
is: true,
|
is: true,
|
||||||
then: Yup.number().required()
|
then: Yup.number()
|
||||||
|
.required()
|
||||||
.label(formatMessage({ id: 'sell_price_' })),
|
.label(formatMessage({ id: 'sell_price_' })),
|
||||||
otherwise: Yup.number().nullable(true),
|
otherwise: Yup.number().nullable(true),
|
||||||
}),
|
}),
|
||||||
@@ -132,7 +140,9 @@ function ItemForm({
|
|||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
|
cost_account_id: parseInt(preferredCostAccount),
|
||||||
|
sell_account_id: parseInt(preferredSellAccount),
|
||||||
|
inventory_account_id: parseInt(preferredInventoryAccount),
|
||||||
/**
|
/**
|
||||||
* We only care about the fields in the form. Previously unfilled optional
|
* We only care about the fields in the form. Previously unfilled optional
|
||||||
* values such as `notes` come back from the API as null, so remove those
|
* values such as `notes` come back from the API as null, so remove those
|
||||||
@@ -283,4 +293,9 @@ export default compose(
|
|||||||
withItemDetail,
|
withItemDetail,
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withMediaActions,
|
withMediaActions,
|
||||||
|
withSettings(({ itemsSettings }) => ({
|
||||||
|
preferredCostAccount: itemsSettings.preferredCostAccount,
|
||||||
|
preferredSellAccount: itemsSettings.preferredSellAccount,
|
||||||
|
preferredInventoryAccount: itemsSettings.preferredInventoryAccount,
|
||||||
|
})),
|
||||||
)(ItemForm);
|
)(ItemForm);
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ function ReceiptForm({
|
|||||||
// #withSettings
|
// #withSettings
|
||||||
receiptNextNumber,
|
receiptNextNumber,
|
||||||
receiptNumberPrefix,
|
receiptNumberPrefix,
|
||||||
|
preferredDepositAccount,
|
||||||
|
|
||||||
//#own Props
|
//#own Props
|
||||||
receiptId,
|
receiptId,
|
||||||
@@ -88,7 +89,7 @@ function ReceiptForm({
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const [submitPayload, setSubmitPayload ] = useState({});
|
const [submitPayload, setSubmitPayload] = useState({});
|
||||||
const isNewMode = !receiptId;
|
const isNewMode = !receiptId;
|
||||||
|
|
||||||
const receiptNumber = receiptNumberPrefix
|
const receiptNumber = receiptNumberPrefix
|
||||||
@@ -130,6 +131,7 @@ function ReceiptForm({
|
|||||||
: {
|
: {
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
receipt_number: receiptNumber,
|
receipt_number: receiptNumber,
|
||||||
|
deposit_account_id: parseInt(preferredDepositAccount),
|
||||||
entries: orderingLinesIndexes(defaultInitialValues.entries),
|
entries: orderingLinesIndexes(defaultInitialValues.entries),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -264,5 +266,6 @@ export default compose(
|
|||||||
withSettings(({ receiptSettings }) => ({
|
withSettings(({ receiptSettings }) => ({
|
||||||
receiptNextNumber: receiptSettings?.nextNumber,
|
receiptNextNumber: receiptSettings?.nextNumber,
|
||||||
receiptNumberPrefix: receiptSettings?.numberPrefix,
|
receiptNumberPrefix: receiptSettings?.numberPrefix,
|
||||||
|
preferredDepositAccount: receiptSettings?.preferredDepositAccount,
|
||||||
})),
|
})),
|
||||||
)(ReceiptForm);
|
)(ReceiptForm);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const Schema = Yup.object().shape({
|
|||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'receipt_date_' })),
|
.label(formatMessage({ id: 'receipt_date_' })),
|
||||||
receipt_number: Yup.string()
|
receipt_number: Yup.string()
|
||||||
|
.nullable()
|
||||||
.label(formatMessage({ id: 'receipt_no_' })),
|
.label(formatMessage({ id: 'receipt_no_' })),
|
||||||
deposit_account_id: Yup.number()
|
deposit_account_id: Yup.number()
|
||||||
.required()
|
.required()
|
||||||
@@ -48,7 +49,4 @@ const Schema = Yup.object().shape({
|
|||||||
const CreateReceiptFormSchema = Schema;
|
const CreateReceiptFormSchema = Schema;
|
||||||
const EditReceiptFormSchema = Schema;
|
const EditReceiptFormSchema = Schema;
|
||||||
|
|
||||||
export {
|
export { CreateReceiptFormSchema, EditReceiptFormSchema };
|
||||||
CreateReceiptFormSchema,
|
|
||||||
EditReceiptFormSchema
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ export default (mapState) => {
|
|||||||
estimatesSettings: state.settings.data.salesEstimates,
|
estimatesSettings: state.settings.data.salesEstimates,
|
||||||
receiptSettings: state.settings.data.salesReceipts,
|
receiptSettings: state.settings.data.salesReceipts,
|
||||||
invoiceSettings: state.settings.data.salesInvoices,
|
invoiceSettings: state.settings.data.salesInvoices,
|
||||||
|
itemsSettings: state.settings.data.items,
|
||||||
|
expenseSettings: state.settings.data.expenses,
|
||||||
};
|
};
|
||||||
return mapState ? mapState(mapped, state, props) : mapped;
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -92,6 +92,10 @@ export default {
|
|||||||
key: "number_prefix",
|
key: "number_prefix",
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: "preferred_deposit_account",
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
sales_invoices: [
|
sales_invoices: [
|
||||||
{
|
{
|
||||||
@@ -105,12 +109,32 @@ export default {
|
|||||||
],
|
],
|
||||||
payment_receives: [
|
payment_receives: [
|
||||||
{
|
{
|
||||||
key: 'next_number',
|
key: "next_number",
|
||||||
type: 'number',
|
type: "number",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'number_prefix',
|
key: "number_prefix",
|
||||||
type: 'string',
|
type: "string",
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
key: "preferred_sell_account",
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "preferred_cost_account",
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "preferred_inventory_account",
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
expenses: [
|
||||||
|
{
|
||||||
|
key: "preferred_payment_account",
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user