mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
Fix :Conditions within Entries items
This commit is contained in:
@@ -11,7 +11,7 @@ import moment from 'moment';
|
|||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { pick } from 'lodash';
|
import { pick, sumBy } from 'lodash';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
import BillFormHeader from './BillFormHeader';
|
import BillFormHeader from './BillFormHeader';
|
||||||
@@ -215,11 +215,25 @@ function BillForm({
|
|||||||
...initialValues,
|
...initialValues,
|
||||||
},
|
},
|
||||||
onSubmit: (values, { setSubmitting, setErrors, resetForm }) => {
|
onSubmit: (values, { setSubmitting, setErrors, resetForm }) => {
|
||||||
setSubmitting(true);
|
const entries = values.entries.filter(
|
||||||
|
(item) => item.item_id && item.quantity,
|
||||||
|
);
|
||||||
|
const totalQuantity = sumBy(entries, (entry) => parseInt(entry.quantity));
|
||||||
|
|
||||||
|
if (totalQuantity === 0) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'quantity_cannot_be_zero_or_empty',
|
||||||
|
}),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
setSubmitting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
entries: values.entries.filter((item) => item.item_id && item.quantity),
|
entries,
|
||||||
};
|
};
|
||||||
const requestForm = { ...form };
|
const requestForm = { ...form };
|
||||||
if (bill && bill.id) {
|
if (bill && bill.id) {
|
||||||
@@ -311,16 +325,20 @@ function BillForm({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Clear page subtitle once unmount bill form page.
|
// Clear page subtitle once unmount bill form page.
|
||||||
useEffect(() => () => {
|
useEffect(
|
||||||
changePageSubtitle('');
|
() => () => {
|
||||||
}, [changePageSubtitle]);
|
changePageSubtitle('');
|
||||||
|
},
|
||||||
|
[changePageSubtitle],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM, CLASSES.PAGE_FORM_BILL)}>
|
<div className={classNames(CLASSES.PAGE_FORM, CLASSES.PAGE_FORM_BILL)}>
|
||||||
<form onSubmit={formik.handleSubmit}>
|
<form onSubmit={formik.handleSubmit}>
|
||||||
<BillFormHeader
|
<BillFormHeader
|
||||||
formik={formik}
|
formik={formik}
|
||||||
onBillNumberChanged={handleBillNumberChanged} />
|
onBillNumberChanged={handleBillNumberChanged}
|
||||||
|
/>
|
||||||
|
|
||||||
<EstimatesItemsTable
|
<EstimatesItemsTable
|
||||||
formik={formik}
|
formik={formik}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { useFormik } from 'formik';
|
|||||||
import moment from 'moment';
|
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, sumBy } from 'lodash';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
@@ -230,6 +230,19 @@ const EstimateForm = ({
|
|||||||
const entries = values.entries.filter(
|
const entries = values.entries.filter(
|
||||||
(item) => item.item_id && item.quantity,
|
(item) => item.item_id && item.quantity,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const totalQuantity = sumBy(entries, (entry) => parseInt(entry.quantity));
|
||||||
|
|
||||||
|
if (totalQuantity === 0) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'quantity_cannot_be_zero_or_empty',
|
||||||
|
}),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
setSubmitting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
entries,
|
entries,
|
||||||
@@ -277,7 +290,6 @@ const EstimateForm = ({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
formik.setFieldValue('estimate_number', estimateNumber);
|
formik.setFieldValue('estimate_number', estimateNumber);
|
||||||
}, [estimateNumber]);
|
}, [estimateNumber]);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { useFormik } from 'formik';
|
|||||||
import moment from 'moment';
|
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, sumBy } from 'lodash';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
@@ -97,8 +97,7 @@ function InvoiceForm({
|
|||||||
due_date: Yup.date()
|
due_date: Yup.date()
|
||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'due_date_' })),
|
.label(formatMessage({ id: 'due_date_' })),
|
||||||
invoice_no: Yup.string()
|
invoice_no: Yup.string().label(formatMessage({ id: 'invoice_no_' })),
|
||||||
.label(formatMessage({ id: 'invoice_no_' })),
|
|
||||||
reference_no: Yup.string().min(1).max(255),
|
reference_no: Yup.string().min(1).max(255),
|
||||||
status: Yup.string().required(),
|
status: Yup.string().required(),
|
||||||
invoice_message: Yup.string()
|
invoice_message: Yup.string()
|
||||||
@@ -127,7 +126,7 @@ function InvoiceForm({
|
|||||||
is: (quantity, rate) => quantity || rate,
|
is: (quantity, rate) => quantity || rate,
|
||||||
then: Yup.number().required(),
|
then: Yup.number().required(),
|
||||||
}),
|
}),
|
||||||
discount: Yup.number().nullable().min(0).max(100),
|
discount: Yup.number().nullable().min(0).max(100),
|
||||||
description: Yup.string().nullable(),
|
description: Yup.string().nullable(),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -232,6 +231,18 @@ function InvoiceForm({
|
|||||||
const entries = values.entries.filter(
|
const entries = values.entries.filter(
|
||||||
(item) => item.item_id && item.quantity,
|
(item) => item.item_id && item.quantity,
|
||||||
);
|
);
|
||||||
|
const totalQuantity = sumBy(entries, (entry) => parseInt(entry.quantity));
|
||||||
|
|
||||||
|
if (totalQuantity === 0) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'quantity_cannot_be_zero_or_empty',
|
||||||
|
}),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
setSubmitting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
entries,
|
entries,
|
||||||
@@ -279,6 +290,7 @@ function InvoiceForm({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
formik.setFieldValue('invoice_no', invoiceNumber);
|
formik.setFieldValue('invoice_no', invoiceNumber);
|
||||||
}, [invoiceNumber]);
|
}, [invoiceNumber]);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { useFormik } from 'formik';
|
|||||||
import moment from 'moment';
|
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,sumBy } from 'lodash';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
@@ -229,6 +229,19 @@ function ReceiptForm({
|
|||||||
const entries = values.entries.filter(
|
const entries = values.entries.filter(
|
||||||
(item) => item.item_id && item.quantity,
|
(item) => item.item_id && item.quantity,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const totalQuantity = sumBy(entries, (entry) => parseInt(entry.quantity));
|
||||||
|
|
||||||
|
if (totalQuantity === 0) {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'quantity_cannot_be_zero_or_empty',
|
||||||
|
}),
|
||||||
|
intent: Intent.DANGER,
|
||||||
|
});
|
||||||
|
setSubmitting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
entries,
|
entries,
|
||||||
|
|||||||
@@ -789,4 +789,6 @@ export default {
|
|||||||
sale_invoice_number_is_exists: 'Sale invoice number is exists',
|
sale_invoice_number_is_exists: 'Sale invoice number is exists',
|
||||||
bill_number_exists:'Bill number exists',
|
bill_number_exists:'Bill number exists',
|
||||||
ok: 'Ok!',
|
ok: 'Ok!',
|
||||||
|
quantity_cannot_be_zero_or_empty: 'Quantity cannot be zero or empty.',
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user