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