mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -225,7 +225,7 @@ function MakeJournalEntriesForm({
|
|||||||
},
|
},
|
||||||
[setSubmitPayload],
|
[setSubmitPayload],
|
||||||
);
|
);
|
||||||
console.log(submitPayload, 'RR');
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames(
|
className={classNames(
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ function ExpensesDataTable({
|
|||||||
{
|
{
|
||||||
id: 'total_amount',
|
id: 'total_amount',
|
||||||
Header: formatMessage({ id: 'full_amount' }),
|
Header: formatMessage({ id: 'full_amount' }),
|
||||||
accessor: (r) => <Money amount={r.total_amount} currency={'USD'} />,
|
accessor: (r) => <Money amount={r.total_amount} currency={r.currency_code} />,
|
||||||
className: 'total_amount',
|
className: 'total_amount',
|
||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
@@ -209,7 +209,7 @@ function ExpensesDataTable({
|
|||||||
id: 'publish',
|
id: 'publish',
|
||||||
Header: formatMessage({ id: 'publish' }),
|
Header: formatMessage({ id: 'publish' }),
|
||||||
accessor: (r) => {
|
accessor: (r) => {
|
||||||
return !!r.is_published ? (
|
return r.is_published ? (
|
||||||
<Tag minimal={true}>
|
<Tag minimal={true}>
|
||||||
<T id={'published'} />
|
<T id={'published'} />
|
||||||
</Tag>
|
</Tag>
|
||||||
|
|||||||
@@ -23,13 +23,11 @@ export default function ExpenseFloatingFooter({
|
|||||||
isSubmitting,
|
isSubmitting,
|
||||||
onSubmitClick,
|
onSubmitClick,
|
||||||
onCancelClick,
|
onCancelClick,
|
||||||
onDraftClick,
|
|
||||||
onClearClick,
|
|
||||||
onSubmitForm,
|
|
||||||
onResetForm,
|
|
||||||
expense,
|
expense,
|
||||||
expensePublished,
|
expensePublished,
|
||||||
}) {
|
}) {
|
||||||
|
const { submitForm, resetForm } = useFormikContext();
|
||||||
|
|
||||||
const handleSubmitPublishBtnClick = (event) => {
|
const handleSubmitPublishBtnClick = (event) => {
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: true,
|
redirect: true,
|
||||||
@@ -38,7 +36,7 @@ export default function ExpenseFloatingFooter({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitPublishAndNewBtnClick = (event) => {
|
const handleSubmitPublishAndNewBtnClick = (event) => {
|
||||||
onSubmitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: true,
|
publish: true,
|
||||||
@@ -47,7 +45,7 @@ export default function ExpenseFloatingFooter({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitPublishContinueEditingBtnClick = (event) => {
|
const handleSubmitPublishContinueEditingBtnClick = (event) => {
|
||||||
onSubmitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: true,
|
publish: true,
|
||||||
@@ -62,7 +60,7 @@ export default function ExpenseFloatingFooter({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitDraftAndNewBtnClick = (event) => {
|
const handleSubmitDraftAndNewBtnClick = (event) => {
|
||||||
onSubmitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: false,
|
publish: false,
|
||||||
@@ -71,7 +69,7 @@ export default function ExpenseFloatingFooter({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitDraftContinueEditingBtnClick = (event) => {
|
const handleSubmitDraftContinueEditingBtnClick = (event) => {
|
||||||
onSubmitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: false,
|
publish: false,
|
||||||
@@ -84,9 +82,8 @@ export default function ExpenseFloatingFooter({
|
|||||||
|
|
||||||
const handleClearBtnClick = (event) => {
|
const handleClearBtnClick = (event) => {
|
||||||
// saveInvoke(onClearClick, event);
|
// saveInvoke(onClearClick, event);
|
||||||
onResetForm();
|
resetForm();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
||||||
{/* ----------- Save And Publish ----------- */}
|
{/* ----------- Save And Publish ----------- */}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import React, {
|
import React, { useMemo, useEffect,useState,useCallback } from 'react';
|
||||||
useMemo,
|
|
||||||
useEffect,
|
|
||||||
} from 'react';
|
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { defaultTo, pick } from 'lodash';
|
import { defaultTo, pick } from 'lodash';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
import ExpenseFormHeader from './ExpenseFormHeader';
|
import ExpenseFormHeader from './ExpenseFormHeader';
|
||||||
@@ -28,9 +26,7 @@ import {
|
|||||||
CreateExpenseFormSchema,
|
CreateExpenseFormSchema,
|
||||||
EditExpenseFormSchema,
|
EditExpenseFormSchema,
|
||||||
} from './ExpenseForm.schema';
|
} from './ExpenseForm.schema';
|
||||||
import {
|
import { transformErrors } from './utils';
|
||||||
transformErrors,
|
|
||||||
} from './utils';
|
|
||||||
import { compose, repeatValue, orderingLinesIndexes } from 'utils';
|
import { compose, repeatValue, orderingLinesIndexes } from 'utils';
|
||||||
|
|
||||||
const MIN_LINES_NUMBER = 4;
|
const MIN_LINES_NUMBER = 4;
|
||||||
@@ -49,6 +45,7 @@ const defaultInitialValues = {
|
|||||||
description: '',
|
description: '',
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
currency_code: '',
|
currency_code: '',
|
||||||
|
is_published:'',
|
||||||
categories: [...repeatValue(defaultCategory, MIN_LINES_NUMBER)],
|
categories: [...repeatValue(defaultCategory, MIN_LINES_NUMBER)],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,7 +79,9 @@ function ExpenseForm({
|
|||||||
onCancelForm,
|
onCancelForm,
|
||||||
}) {
|
}) {
|
||||||
const isNewMode = !expenseId;
|
const isNewMode = !expenseId;
|
||||||
|
const [submitPayload, setSubmitPayload] = useState({});
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const validationSchema = isNewMode
|
const validationSchema = isNewMode
|
||||||
? CreateExpenseFormSchema
|
? CreateExpenseFormSchema
|
||||||
@@ -101,8 +100,6 @@ function ExpenseForm({
|
|||||||
...(expense
|
...(expense
|
||||||
? {
|
? {
|
||||||
...pick(expense, Object.keys(defaultInitialValues)),
|
...pick(expense, Object.keys(defaultInitialValues)),
|
||||||
currency_code: baseCurrency,
|
|
||||||
payment_account_id: defaultTo(preferredPaymentAccount, ''),
|
|
||||||
categories: [
|
categories: [
|
||||||
...expense.categories.map((category) => ({
|
...expense.categories.map((category) => ({
|
||||||
...pick(category, Object.keys(defaultCategory)),
|
...pick(category, Object.keys(defaultCategory)),
|
||||||
@@ -115,9 +112,9 @@ function ExpenseForm({
|
|||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
categories: orderingLinesIndexes(
|
currency_code: baseCurrency,
|
||||||
defaultInitialValues.categories,
|
payment_account_id: defaultTo(preferredPaymentAccount, ''),
|
||||||
),
|
categories: orderingLinesIndexes(defaultInitialValues.categories),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[expense, baseCurrency, preferredPaymentAccount],
|
[expense, baseCurrency, preferredPaymentAccount],
|
||||||
@@ -146,22 +143,30 @@ function ExpenseForm({
|
|||||||
|
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
publish: 1,
|
is_published: submitPayload.publish,
|
||||||
categories,
|
categories,
|
||||||
};
|
};
|
||||||
// Handle request success.
|
// Handle request success.
|
||||||
const handleSuccess = (response) => {
|
const handleSuccess = (response) => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage(
|
message: formatMessage(
|
||||||
{ id: isNewMode ?
|
{
|
||||||
'the_expense_has_been_successfully_created' :
|
id: isNewMode
|
||||||
'the_expense_has_been_successfully_edited' },
|
? 'the_expense_has_been_successfully_created'
|
||||||
|
: 'the_expense_has_been_successfully_edited',
|
||||||
|
},
|
||||||
{ number: values.payment_account_id },
|
{ number: values.payment_account_id },
|
||||||
),
|
),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
|
||||||
|
if (submitPayload.redirect) {
|
||||||
|
history.push('/expenses');
|
||||||
|
}
|
||||||
|
if (submitPayload.resetForm) {
|
||||||
resetForm();
|
resetForm();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle request error
|
// Handle request error
|
||||||
@@ -172,16 +177,30 @@ function ExpenseForm({
|
|||||||
if (isNewMode) {
|
if (isNewMode) {
|
||||||
requestSubmitExpense(form).then(handleSuccess).catch(handleError);
|
requestSubmitExpense(form).then(handleSuccess).catch(handleError);
|
||||||
} else {
|
} else {
|
||||||
requestEditExpense(expense.id, form).then(handleSuccess).catch(handleError);
|
requestEditExpense(expense.id, form)
|
||||||
|
.then(handleSuccess)
|
||||||
|
.catch(handleError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const handleCancelClick = useCallback(() => {
|
||||||
|
history.goBack();
|
||||||
|
}, [history]);
|
||||||
|
|
||||||
|
const handleSubmitClick = useCallback(
|
||||||
|
(event, payload) => {
|
||||||
|
setSubmitPayload({ ...payload });
|
||||||
|
},
|
||||||
|
[setSubmitPayload],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(
|
<div
|
||||||
|
className={classNames(
|
||||||
CLASSES.PAGE_FORM,
|
CLASSES.PAGE_FORM,
|
||||||
CLASSES.PAGE_FORM_STRIP_STYLE,
|
CLASSES.PAGE_FORM_STRIP_STYLE,
|
||||||
CLASSES.PAGE_FORM_EXPENSE
|
CLASSES.PAGE_FORM_EXPENSE,
|
||||||
)}>
|
)}
|
||||||
|
>
|
||||||
<Formik
|
<Formik
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
@@ -192,7 +211,13 @@ function ExpenseForm({
|
|||||||
<ExpenseFormHeader />
|
<ExpenseFormHeader />
|
||||||
<ExpenseFormBody />
|
<ExpenseFormBody />
|
||||||
<ExpenseFormFooter />
|
<ExpenseFormFooter />
|
||||||
<ExpenseFloatingFooter />
|
<ExpenseFloatingFooter
|
||||||
|
isSubmitting={isSubmitting}
|
||||||
|
expense={expenseId}
|
||||||
|
expensePublished={values.is_published}
|
||||||
|
onCancelClick={handleCancelClick}
|
||||||
|
onSubmitClick={handleSubmitClick}
|
||||||
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
@@ -208,6 +233,9 @@ export default compose(
|
|||||||
withExpenseDetail(),
|
withExpenseDetail(),
|
||||||
withSettings(({ organizationSettings, expenseSettings }) => ({
|
withSettings(({ organizationSettings, expenseSettings }) => ({
|
||||||
baseCurrency: organizationSettings?.baseCurrency,
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
preferredPaymentAccount: parseInt(expenseSettings?.preferredPaymentAccount, 10),
|
preferredPaymentAccount: parseInt(
|
||||||
|
expenseSettings?.preferredPaymentAccount,
|
||||||
|
10,
|
||||||
|
),
|
||||||
})),
|
})),
|
||||||
)(ExpenseForm);
|
)(ExpenseForm);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const Schema = Yup.object().shape({
|
|||||||
payment_date: Yup.date()
|
payment_date: Yup.date()
|
||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'payment_date_' })),
|
.label(formatMessage({ id: 'payment_date_' })),
|
||||||
reference_no: Yup.string().min(1).max(DATATYPES_LENGTH.STRING),
|
reference_no: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
|
||||||
currency_code: Yup.string()
|
currency_code: Yup.string()
|
||||||
.nullable()
|
.nullable()
|
||||||
.max(3)
|
.max(3)
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { FastField } from 'formik';
|
import { FastField } from 'formik';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ExpenseFormEntries from './ExpenseFormEntries';
|
import ExpenseFormEntries from './ExpenseFormEntries';
|
||||||
|
import { orderingLinesIndexes, repeatValue } from 'utils';
|
||||||
|
|
||||||
export default function ExpenseFormEntriesField({
|
export default function ExpenseFormEntriesField({
|
||||||
|
defaultRow,
|
||||||
|
linesNumber = 4,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<FastField name={'categories'}>
|
<FastField name={'categories'}>
|
||||||
@@ -12,10 +14,19 @@ export default function ExpenseFormEntriesField({
|
|||||||
entries={value}
|
entries={value}
|
||||||
error={error}
|
error={error}
|
||||||
onChange={(entries) => {
|
onChange={(entries) => {
|
||||||
form.setFieldValue('categories', entries)
|
form.setFieldValue('categories', entries);
|
||||||
|
}}
|
||||||
|
onClickAddNewRow={() => {
|
||||||
|
form.setFieldValue('categories', [...value, defaultRow]);
|
||||||
|
}}
|
||||||
|
onClickClearAllLines={() => {
|
||||||
|
form.setFieldValue(
|
||||||
|
'categories',
|
||||||
|
orderingLinesIndexes([...repeatValue(defaultRow, linesNumber)])
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ export default function ExpenseFormHeader() {
|
|||||||
<PageFormBigNumber
|
<PageFormBigNumber
|
||||||
label={'Expense Amount'}
|
label={'Expense Amount'}
|
||||||
amount={totalExpenseAmount}
|
amount={totalExpenseAmount}
|
||||||
currencyCode={'LYD'}
|
currencyCode={values?.currency_code}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import {
|
|||||||
} from './ItemForm.schema';
|
} from './ItemForm.schema';
|
||||||
|
|
||||||
const defaultInitialValues = {
|
const defaultInitialValues = {
|
||||||
active: true,
|
active: 1,
|
||||||
name: '',
|
name: '',
|
||||||
type: 'service',
|
type: 'service',
|
||||||
code: '',
|
code: '',
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export const transformItemFormData = (item, defaultValue) => {
|
|||||||
...item,
|
...item,
|
||||||
sellable: !!defaultTo(item?.sellable, defaultValue.sellable),
|
sellable: !!defaultTo(item?.sellable, defaultValue.sellable),
|
||||||
purchasable: !!defaultTo(item?.purchasable, defaultValue.purchasable),
|
purchasable: !!defaultTo(item?.purchasable, defaultValue.purchasable),
|
||||||
|
active: !!defaultTo(item?.active, defaultValue.active),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import classNames from 'classnames';
|
|||||||
import { FastField } from 'formik';
|
import { FastField } from 'formik';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Item form floating actions.
|
* Item form floating actions.
|
||||||
*/
|
*/
|
||||||
@@ -56,13 +55,13 @@ export default function ItemFormFloatingActions({
|
|||||||
|
|
||||||
{/*----------- Active ----------*/}
|
{/*----------- Active ----------*/}
|
||||||
<FastField name={'active'} type={'checkbox'}>
|
<FastField name={'active'} type={'checkbox'}>
|
||||||
{({ form, field, field: { value } }) => (
|
{({ field }) => (
|
||||||
<FormGroup inline={true} className={'form-group--active'}>
|
<FormGroup inline={true} className={'form-group--active'}>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
inline={true}
|
inline={true}
|
||||||
label={<T id={'active'} />}
|
label={<T id={'active'} />}
|
||||||
checked={value}
|
name={'active'}
|
||||||
onChange={() => form.setFieldValue('active', !value)}
|
{...field}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user