mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 07:40:32 +00:00
feat: payment receive and made form.
This commit is contained in:
@@ -8,6 +8,9 @@ const CLASSES = {
|
|||||||
PAGE_FORM: 'page-form',
|
PAGE_FORM: 'page-form',
|
||||||
PAGE_FORM_HEADER: 'page-form__header',
|
PAGE_FORM_HEADER: 'page-form__header',
|
||||||
PAGE_FORM_HEADER_PRIMARY: 'page-form__primary-section',
|
PAGE_FORM_HEADER_PRIMARY: 'page-form__primary-section',
|
||||||
|
PAGE_FORM_HEADER_FIELDS: 'page-form__header-fields',
|
||||||
|
PAGE_FORM_HEADER_BIG_NUMBERS: 'page-form__big-numbers',
|
||||||
|
|
||||||
PAGE_FORM_FOOTER: 'page-form__footer',
|
PAGE_FORM_FOOTER: 'page-form__footer',
|
||||||
PAGE_FORM_FLOATING_ACTIONS: 'page-form__floating-actions',
|
PAGE_FORM_FLOATING_ACTIONS: 'page-form__floating-actions',
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,12 @@ 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 } from 'lodash';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
import BillFormHeader from './BillFormHeader';
|
import BillFormHeader from './BillFormHeader';
|
||||||
import EstimatesItemsTable from 'containers/Sales/Estimate/EntriesItemsTable';
|
import EstimatesItemsTable from 'containers/Sales/Estimate/EntriesItemsTable';
|
||||||
import BillFloatingActions from './BillFloatingActions';
|
import BillFloatingActions from './BillFloatingActions';
|
||||||
import BillFormFooter from './BillFormFooter';
|
import BillFormFooter from './BillFormFooter';
|
||||||
|
|
||||||
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 withBillActions from './withBillActions';
|
import withBillActions from './withBillActions';
|
||||||
@@ -41,6 +43,7 @@ function BillForm({
|
|||||||
|
|
||||||
//#withDashboard
|
//#withDashboard
|
||||||
changePageTitle,
|
changePageTitle,
|
||||||
|
changePageSubtitle,
|
||||||
|
|
||||||
//#withBillDetail
|
//#withBillDetail
|
||||||
bill,
|
bill,
|
||||||
@@ -235,6 +238,7 @@ function BillForm({
|
|||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
saveBillSubmit({ action: 'update', ...payload });
|
saveBillSubmit({ action: 'update', ...payload });
|
||||||
resetForm();
|
resetForm();
|
||||||
|
changePageSubtitle('');
|
||||||
})
|
})
|
||||||
.catch((errors) => {
|
.catch((errors) => {
|
||||||
handleErrors(errors, { setErrors });
|
handleErrors(errors, { setErrors });
|
||||||
@@ -302,10 +306,22 @@ function BillForm({
|
|||||||
orderingIndex([...formik.values.entries, defaultBill]),
|
orderingIndex([...formik.values.entries, defaultBill]),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBillNumberChanged = useCallback((billNumber) => {
|
||||||
|
changePageSubtitle(billNumber);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Clear page subtitle once unmount bill form page.
|
||||||
|
useEffect(() => () => {
|
||||||
|
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 formik={formik} />
|
<BillFormHeader
|
||||||
|
formik={formik}
|
||||||
|
onBillNumberChanged={handleBillNumberChanged} />
|
||||||
|
|
||||||
<EstimatesItemsTable
|
<EstimatesItemsTable
|
||||||
formik={formik}
|
formik={formik}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import withDialogActions from 'containers/Dialog/withDialogActions';
|
|||||||
|
|
||||||
function BillFormHeader({
|
function BillFormHeader({
|
||||||
formik: { errors, touched, setFieldValue, getFieldProps, values },
|
formik: { errors, touched, setFieldValue, getFieldProps, values },
|
||||||
|
onBillNumberChanged,
|
||||||
|
|
||||||
//#withVendors
|
//#withVendors
|
||||||
vendorItems,
|
vendorItems,
|
||||||
@@ -73,6 +74,10 @@ function BillFormHeader({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBillNumberBlur = (event) => {
|
||||||
|
onBillNumberChanged && onBillNumberChanged(event.currentTarget.value);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||||
<div className={'page-form__primary-section'}>
|
<div className={'page-form__primary-section'}>
|
||||||
@@ -166,6 +171,7 @@ function BillFormHeader({
|
|||||||
intent={errors.bill_number && touched.bill_number && Intent.DANGER}
|
intent={errors.bill_number && touched.bill_number && Intent.DANGER}
|
||||||
minimal={true}
|
minimal={true}
|
||||||
{...getFieldProps('bill_number')}
|
{...getFieldProps('bill_number')}
|
||||||
|
onBlur={handleBillNumberBlur}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import {
|
|||||||
getBillPaginationMetaFactory,
|
getBillPaginationMetaFactory,
|
||||||
getBillTableQueryFactory,
|
getBillTableQueryFactory,
|
||||||
getVendorPayableBillsFactory,
|
getVendorPayableBillsFactory,
|
||||||
getPayableBillsByPaymentMadeFactory,
|
getVendorPayableBillsEntriesFactory,
|
||||||
getPaymentMadeFormPayableBillsFactory
|
|
||||||
} from 'store/Bills/bills.selectors';
|
} from 'store/Bills/bills.selectors';
|
||||||
|
|
||||||
export default (mapState) => {
|
export default (mapState) => {
|
||||||
@@ -14,8 +13,7 @@ export default (mapState) => {
|
|||||||
const getBillsPaginationMeta = getBillPaginationMetaFactory();
|
const getBillsPaginationMeta = getBillPaginationMetaFactory();
|
||||||
const getBillTableQuery = getBillTableQueryFactory();
|
const getBillTableQuery = getBillTableQueryFactory();
|
||||||
const getVendorPayableBills = getVendorPayableBillsFactory();
|
const getVendorPayableBills = getVendorPayableBillsFactory();
|
||||||
const getPayableBillsByPaymentMade = getPayableBillsByPaymentMadeFactory();
|
const getVendorPayableBillsEntries = getVendorPayableBillsEntriesFactory();
|
||||||
const getPaymentMadeFormPayableBills = getPaymentMadeFormPayableBillsFactory();
|
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => {
|
const mapStateToProps = (state, props) => {
|
||||||
const tableQuery = getBillTableQuery(state, props);
|
const tableQuery = getBillTableQuery(state, props);
|
||||||
@@ -29,9 +27,8 @@ export default (mapState) => {
|
|||||||
billsPageination: getBillsPaginationMeta(state, props, tableQuery),
|
billsPageination: getBillsPaginationMeta(state, props, tableQuery),
|
||||||
billsLoading: state.bills.loading,
|
billsLoading: state.bills.loading,
|
||||||
nextBillNumberChanged: state.bills.nextBillNumberChanged,
|
nextBillNumberChanged: state.bills.nextBillNumberChanged,
|
||||||
|
vendorPayableBills: getVendorPayableBills(state, props),
|
||||||
// vendorPayableBills: getVendorPayableBills(state, props),
|
vendorPayableBillsEntries: getVendorPayableBillsEntries(state, props),
|
||||||
paymentMadePayableBills: getPaymentMadeFormPayableBills(state, props),
|
|
||||||
};
|
};
|
||||||
return mapState ? mapState(mapped, state, props) : mapped;
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ function PaymentMade({
|
|||||||
>
|
>
|
||||||
<PaymentMadeForm
|
<PaymentMadeForm
|
||||||
paymentMadeId={paymentMadeId}
|
paymentMadeId={paymentMadeId}
|
||||||
|
mode={paymentMadeId ? 'edit' : 'new'}
|
||||||
/>
|
/>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { FormGroup, TextArea } from '@blueprintjs/core';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
import { Row, Col } from 'components';
|
||||||
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payment made form footer.
|
||||||
|
*/
|
||||||
|
export default function PaymentMadeFooter({
|
||||||
|
getFieldProps
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
|
||||||
|
<Row>
|
||||||
|
<Col md={8}>
|
||||||
|
{/* --------- Statement --------- */}
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'statement'} />}
|
||||||
|
className={'form-group--statement'}
|
||||||
|
>
|
||||||
|
<TextArea
|
||||||
|
growVertically={true}
|
||||||
|
{...getFieldProps('description')}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,30 +1,52 @@
|
|||||||
import React, { useMemo, useState, useCallback } from 'react';
|
import React, { useMemo, useState, useCallback, useEffect } from 'react';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { useFormik } from 'formik';
|
import { useFormik } from 'formik';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { pick, sumBy } from 'lodash';
|
import { pick, sumBy, omit } from 'lodash';
|
||||||
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 { AppToaster } from 'components';
|
||||||
import PaymentMadeHeader from './PaymentMadeFormHeader';
|
import PaymentMadeHeader from './PaymentMadeFormHeader';
|
||||||
import PaymentMadeItemsTable from './PaymentMadeItemsTable';
|
|
||||||
import PaymentMadeFloatingActions from './PaymentMadeFloatingActions';
|
import PaymentMadeFloatingActions from './PaymentMadeFloatingActions';
|
||||||
|
import PaymentMadeItemsTable from './PaymentMadeItemsTable';
|
||||||
|
import PaymentMadeFooter from './PaymentMadeFooter';
|
||||||
|
|
||||||
import withMediaActions from 'containers/Media/withMediaActions';
|
import withMediaActions from 'containers/Media/withMediaActions';
|
||||||
import withPaymentMadeActions from './withPaymentMadeActions';
|
import withPaymentMadeActions from './withPaymentMadeActions';
|
||||||
import withPaymentMadeDetail from './withPaymentMadeDetail';
|
import withPaymentMadeDetail from './withPaymentMadeDetail';
|
||||||
import withPaymentMade from './withPaymentMade';
|
import withPaymentMade from './withPaymentMade';
|
||||||
import { AppToaster } from 'components';
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
|
||||||
import { compose, orderingLinesIndexes } from 'utils';
|
import { compose, orderingLinesIndexes } from 'utils';
|
||||||
import withSettings from 'containers/Settings/withSettings';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
|
|
||||||
const ERRORS = {
|
const ERRORS = {
|
||||||
PAYMENT_NUMBER_NOT_UNIQUE: 'PAYMENT.NUMBER.NOT.UNIQUE',
|
PAYMENT_NUMBER_NOT_UNIQUE: 'PAYMENT.NUMBER.NOT.UNIQUE',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Default payment made entry values.
|
||||||
|
const defaultPaymentMadeEntry = {
|
||||||
|
bill_id: '',
|
||||||
|
payment_amount: '',
|
||||||
|
id: null,
|
||||||
|
due_amount: null,
|
||||||
|
};
|
||||||
|
// Default initial values.
|
||||||
|
const defaultInitialValues = {
|
||||||
|
full_amount: '',
|
||||||
|
vendor_id: '',
|
||||||
|
payment_account_id: '',
|
||||||
|
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
|
reference: '',
|
||||||
|
payment_number: '',
|
||||||
|
description: '',
|
||||||
|
entries: [],
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment made form component.
|
* Payment made form component.
|
||||||
*/
|
*/
|
||||||
@@ -40,6 +62,13 @@ function PaymentMadeForm({
|
|||||||
// #withPaymentMadeDetail
|
// #withPaymentMadeDetail
|
||||||
paymentMade,
|
paymentMade,
|
||||||
|
|
||||||
|
// #withBills
|
||||||
|
paymentMadeEntries,
|
||||||
|
|
||||||
|
// #withDashboardActions
|
||||||
|
changePageSubtitle,
|
||||||
|
|
||||||
|
// #ownProps
|
||||||
paymentMadeId,
|
paymentMadeId,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -50,6 +79,14 @@ function PaymentMadeForm({
|
|||||||
const [clearFormAlert, setClearFormAlert] = useState(false);
|
const [clearFormAlert, setClearFormAlert] = useState(false);
|
||||||
const [fullAmount, setFullAmount] = useState(null);
|
const [fullAmount, setFullAmount] = useState(null);
|
||||||
|
|
||||||
|
const [localPaymentEntries, setLocalPaymentEntries] = useState(paymentMadeEntries);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (localPaymentEntries !== paymentMadeEntries) {
|
||||||
|
setLocalPaymentEntries(paymentMadeEntries);
|
||||||
|
}
|
||||||
|
}, [localPaymentEntries, paymentMadeEntries])
|
||||||
|
|
||||||
// Yup validation schema.
|
// Yup validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
vendor_id: Yup.string()
|
vendor_id: Yup.string()
|
||||||
@@ -62,7 +99,6 @@ function PaymentMadeForm({
|
|||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'payment_account_' })),
|
.label(formatMessage({ id: 'payment_account_' })),
|
||||||
payment_number: Yup.string()
|
payment_number: Yup.string()
|
||||||
.required()
|
|
||||||
.label(formatMessage({ id: 'payment_no_' })),
|
.label(formatMessage({ id: 'payment_no_' })),
|
||||||
reference: Yup.string().min(1).max(255).nullable(),
|
reference: Yup.string().min(1).max(255).nullable(),
|
||||||
description: Yup.string(),
|
description: Yup.string(),
|
||||||
@@ -81,27 +117,6 @@ function PaymentMadeForm({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Default payment made entry values.
|
|
||||||
const defaultPaymentMadeEntry = useMemo(
|
|
||||||
() => ({ bill_id: '', payment_amount: '', id: null }),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Default initial values.
|
|
||||||
const defaultInitialValues = useMemo(
|
|
||||||
() => ({
|
|
||||||
full_amount: '',
|
|
||||||
vendor_id: '',
|
|
||||||
payment_account_id: '',
|
|
||||||
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
||||||
reference: '',
|
|
||||||
payment_number: '',
|
|
||||||
description: '',
|
|
||||||
entries: [],
|
|
||||||
}),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Form initial values.
|
// Form initial values.
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -110,7 +125,7 @@ function PaymentMadeForm({
|
|||||||
...pick(paymentMade, Object.keys(defaultInitialValues)),
|
...pick(paymentMade, Object.keys(defaultInitialValues)),
|
||||||
full_amount: sumBy(paymentMade.entries, 'payment_amount'),
|
full_amount: sumBy(paymentMade.entries, 'payment_amount'),
|
||||||
entries: [
|
entries: [
|
||||||
...paymentMade.entries.map((paymentMadeEntry) => ({
|
...paymentMadeEntries.map((paymentMadeEntry) => ({
|
||||||
...pick(paymentMadeEntry, Object.keys(defaultPaymentMadeEntry)),
|
...pick(paymentMadeEntry, Object.keys(defaultPaymentMadeEntry)),
|
||||||
})),
|
})),
|
||||||
],
|
],
|
||||||
@@ -120,7 +135,7 @@ function PaymentMadeForm({
|
|||||||
entries: orderingLinesIndexes(defaultInitialValues.entries),
|
entries: orderingLinesIndexes(defaultInitialValues.entries),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[paymentMade, defaultInitialValues, defaultPaymentMadeEntry],
|
[paymentMade, paymentMadeEntries],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSubmitForm = (
|
const handleSubmitForm = (
|
||||||
@@ -130,9 +145,11 @@ function PaymentMadeForm({
|
|||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
|
|
||||||
// Filters entries that have no `bill_id` or `payment_amount`.
|
// Filters entries that have no `bill_id` or `payment_amount`.
|
||||||
const entries = values.entries.filter((item) => {
|
const entries = values.entries
|
||||||
return !item.bill_id || item.payment_amount;
|
.filter((item) => !item.bill_id || item.payment_amount)
|
||||||
});
|
.map((entry) => ({
|
||||||
|
...omit(entry, ['due_amount']),
|
||||||
|
}));
|
||||||
// Total payment amount of entries.
|
// Total payment amount of entries.
|
||||||
const totalPaymentAmount = sumBy(entries, 'payment_amount');
|
const totalPaymentAmount = sumBy(entries, 'payment_amount');
|
||||||
|
|
||||||
@@ -159,6 +176,7 @@ function PaymentMadeForm({
|
|||||||
});
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
resetForm();
|
resetForm();
|
||||||
|
changePageSubtitle('');
|
||||||
};
|
};
|
||||||
|
|
||||||
const onError = (errors) => {
|
const onError = (errors) => {
|
||||||
@@ -213,10 +231,26 @@ function PaymentMadeForm({
|
|||||||
setAmountChangeAlert(false);
|
setAmountChangeAlert(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const transformPaymentEntries = (entries) => {
|
||||||
|
return entries.map((entry) => ({
|
||||||
|
...pick(entry, Object.keys(defaultPaymentMadeEntry)),
|
||||||
|
}));
|
||||||
|
};
|
||||||
// Handle update data.
|
// Handle update data.
|
||||||
const handleUpdataData = useCallback(
|
const handleUpdataData = useCallback(
|
||||||
(entries) => {
|
(entries) => {
|
||||||
setFieldValue('entries', entries);
|
setFieldValue('entries', transformPaymentEntries(entries));
|
||||||
|
},
|
||||||
|
[setFieldValue],
|
||||||
|
);
|
||||||
|
|
||||||
|
const resetEntriesPaymentAmount = (entries) => {
|
||||||
|
return entries.map((entry) => ({ ...entry, payment_amount: 0 }));
|
||||||
|
}
|
||||||
|
// Handle fetch success of vendor bills entries.
|
||||||
|
const handleFetchEntriesSuccess = useCallback(
|
||||||
|
(entries) => {
|
||||||
|
setFieldValue('entries', transformPaymentEntries(entries));
|
||||||
},
|
},
|
||||||
[setFieldValue],
|
[setFieldValue],
|
||||||
);
|
);
|
||||||
@@ -236,26 +270,22 @@ function PaymentMadeForm({
|
|||||||
}, [setClearLinesAlert]);
|
}, [setClearLinesAlert]);
|
||||||
|
|
||||||
const handleConfirmClearLines = useCallback(() => {
|
const handleConfirmClearLines = useCallback(() => {
|
||||||
setFieldValue(
|
setLocalPaymentEntries(resetEntriesPaymentAmount(localPaymentEntries));
|
||||||
'entries',
|
setFieldValue('entries', resetEntriesPaymentAmount(values.entries));
|
||||||
values.entries.map((entry) => ({
|
|
||||||
...entry,
|
|
||||||
payment_amount: 0,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
setClearLinesAlert(false);
|
setClearLinesAlert(false);
|
||||||
}, [setFieldValue, setClearLinesAlert, values.entries]);
|
}, [setFieldValue, localPaymentEntries, values.entries]);
|
||||||
|
|
||||||
// Handle clear button click.
|
// Handle clear button click.
|
||||||
const handleClearBtnClick = useCallback(() => {
|
const handleClearBtnClick = useCallback(() => {
|
||||||
setClearFormAlert(true);
|
setClearFormAlert(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
//
|
// Handle cancel button clear
|
||||||
const handleCancelClearFormAlert = () => {
|
const handleCancelClearFormAlert = () => {
|
||||||
setClearFormAlert(false);
|
setClearFormAlert(false);
|
||||||
};
|
};
|
||||||
|
// Handle confirm button click of clear form alert.
|
||||||
const handleConfirmCancelClearFormAlert = () => {
|
const handleConfirmCancelClearFormAlert = () => {
|
||||||
setValues({
|
setValues({
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
@@ -268,6 +298,24 @@ function PaymentMadeForm({
|
|||||||
});
|
});
|
||||||
setClearFormAlert(false);
|
setClearFormAlert(false);
|
||||||
};
|
};
|
||||||
|
// Payable full amount.
|
||||||
|
const payableFullAmount = useMemo(() => sumBy(values.entries, 'due_amount'), [
|
||||||
|
values.entries,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const handlePaymentNoChanged = (paymentNumber) => {
|
||||||
|
changePageSubtitle(paymentNumber);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clear page subtitle before once page leave.
|
||||||
|
useEffect(() => () => {
|
||||||
|
changePageSubtitle('')
|
||||||
|
}, [changePageSubtitle]);
|
||||||
|
|
||||||
|
const fullAmountPaid = useMemo(
|
||||||
|
() => sumBy(values.entries, 'payment_amount'),
|
||||||
|
[values.entries],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -282,50 +330,65 @@ function PaymentMadeForm({
|
|||||||
setFieldValue={setFieldValue}
|
setFieldValue={setFieldValue}
|
||||||
getFieldProps={getFieldProps}
|
getFieldProps={getFieldProps}
|
||||||
values={values}
|
values={values}
|
||||||
|
payableFullAmount={payableFullAmount}
|
||||||
onFullAmountChanged={handleFullAmountChange}
|
onFullAmountChanged={handleFullAmountChange}
|
||||||
|
onPaymentNumberChanged={handlePaymentNoChanged}
|
||||||
|
amountPaid={fullAmountPaid}
|
||||||
/>
|
/>
|
||||||
<PaymentMadeItemsTable
|
<PaymentMadeItemsTable
|
||||||
fullAmount={fullAmount}
|
fullAmount={fullAmount}
|
||||||
paymentEntries={values.entries}
|
paymentEntries={localPaymentEntries}
|
||||||
vendorId={values.vendor_id}
|
vendorId={values.vendor_id}
|
||||||
paymentMadeId={paymentMadeId}
|
paymentMadeId={paymentMadeId}
|
||||||
onUpdateData={handleUpdataData}
|
onUpdateData={handleUpdataData}
|
||||||
onClickClearAllLines={handleClearAllLines}
|
onClickClearAllLines={handleClearAllLines}
|
||||||
errors={errors?.entries}
|
errors={errors?.entries}
|
||||||
|
onFetchEntriesSuccess={handleFetchEntriesSuccess}
|
||||||
|
vendorPayableBillsEntrie={[]}
|
||||||
/>
|
/>
|
||||||
<Alert
|
<Alert
|
||||||
cancelButtonText={<T id={'cancel'} />}
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
confirmButtonText={<T id={'ok'} />}
|
confirmButtonText={<T id={'ok'} />}
|
||||||
intent={Intent.WARNING}
|
intent={Intent.DANGER}
|
||||||
isOpen={amountChangeAlert}
|
isOpen={amountChangeAlert}
|
||||||
onCancel={handleCancelAmountChangeAlert}
|
onCancel={handleCancelAmountChangeAlert}
|
||||||
onConfirm={handleConfirmAmountChangeAlert}
|
onConfirm={handleConfirmAmountChangeAlert}
|
||||||
>
|
>
|
||||||
<p>Are you sure to discard full amount?</p>
|
<p>
|
||||||
|
Changing full amount will change all credit and payment were
|
||||||
|
applied, Is this okay?
|
||||||
|
</p>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
<Alert
|
<Alert
|
||||||
cancelButtonText={<T id={'cancel'} />}
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
confirmButtonText={<T id={'ok'} />}
|
confirmButtonText={<T id={'ok'} />}
|
||||||
intent={Intent.WARNING}
|
intent={Intent.DANGER}
|
||||||
isOpen={clearLinesAlert}
|
isOpen={clearLinesAlert}
|
||||||
onCancel={handleCancelClearLines}
|
onCancel={handleCancelClearLines}
|
||||||
onConfirm={handleConfirmClearLines}
|
onConfirm={handleConfirmClearLines}
|
||||||
>
|
>
|
||||||
<p>Are you sure to discard full amount?</p>
|
<p>
|
||||||
|
Clearing the table lines will delete all credits and payments were
|
||||||
|
applied. Is this okay?
|
||||||
|
</p>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
<Alert
|
<Alert
|
||||||
cancelButtonText={<T id={'cancel'} />}
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
confirmButtonText={<T id={'ok'} />}
|
confirmButtonText={<T id={'ok'} />}
|
||||||
intent={Intent.WARNING}
|
intent={Intent.DANGER}
|
||||||
isOpen={clearFormAlert}
|
isOpen={clearFormAlert}
|
||||||
onCancel={handleCancelClearFormAlert}
|
onCancel={handleCancelClearFormAlert}
|
||||||
onConfirm={handleConfirmCancelClearFormAlert}
|
onConfirm={handleConfirmCancelClearFormAlert}
|
||||||
>
|
>
|
||||||
<p>Are you sure to clear form data.</p>
|
<p>Are you sure you want to clear this transaction?</p>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
|
<PaymentMadeFooter
|
||||||
|
getFieldProps={getFieldProps}
|
||||||
|
/>
|
||||||
|
|
||||||
<PaymentMadeFloatingActions
|
<PaymentMadeFloatingActions
|
||||||
isSubmitting={isSubmitting}
|
isSubmitting={isSubmitting}
|
||||||
onCancelClick={handleCancelClick}
|
onCancelClick={handleCancelClick}
|
||||||
@@ -347,11 +410,15 @@ export default compose(
|
|||||||
withPaymentMadeActions,
|
withPaymentMadeActions,
|
||||||
withMediaActions,
|
withMediaActions,
|
||||||
withPaymentMadeDetail(),
|
withPaymentMadeDetail(),
|
||||||
withPaymentMade(({ nextPaymentNumberChanged }) => ({
|
withPaymentMade(
|
||||||
|
({ nextPaymentNumberChanged, paymentMadeEntries }, state, props) => ({
|
||||||
nextPaymentNumberChanged,
|
nextPaymentNumberChanged,
|
||||||
})),
|
paymentMadeEntries,
|
||||||
|
}),
|
||||||
|
),
|
||||||
withSettings(({ billPaymentSettings }) => ({
|
withSettings(({ billPaymentSettings }) => ({
|
||||||
paymentNextNumber: billPaymentSettings?.next_number,
|
paymentNextNumber: billPaymentSettings?.next_number,
|
||||||
paymentNumberPrefix: billPaymentSettings?.number_prefix,
|
paymentNumberPrefix: billPaymentSettings?.number_prefix,
|
||||||
})),
|
})),
|
||||||
|
withDashboardActions,
|
||||||
)(PaymentMadeForm);
|
)(PaymentMadeForm);
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import {
|
|||||||
Hint,
|
Hint,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
|
|
||||||
import withBills from '../Bill/withBills';
|
|
||||||
import withVender from 'containers/Vendors/withVendors';
|
import withVender from 'containers/Vendors/withVendors';
|
||||||
import withAccounts from 'containers/Accounts/withAccounts';
|
import withAccounts from 'containers/Accounts/withAccounts';
|
||||||
|
|
||||||
@@ -32,7 +31,9 @@ import withAccounts from 'containers/Accounts/withAccounts';
|
|||||||
*/
|
*/
|
||||||
function PaymentMadeFormHeader({
|
function PaymentMadeFormHeader({
|
||||||
paymentMadeId,
|
paymentMadeId,
|
||||||
vendorId,
|
payableFullAmount,
|
||||||
|
onPaymentNumberChanged,
|
||||||
|
amountPaid = 0,
|
||||||
|
|
||||||
// #useFormik
|
// #useFormik
|
||||||
errors,
|
errors,
|
||||||
@@ -49,17 +50,9 @@ function PaymentMadeFormHeader({
|
|||||||
|
|
||||||
//#withAccouts
|
//#withAccouts
|
||||||
accountsList,
|
accountsList,
|
||||||
|
|
||||||
// #withBills
|
|
||||||
paymentMadePayableBills,
|
|
||||||
}) {
|
}) {
|
||||||
const isNewMode = !paymentMadeId;
|
const isNewMode = !paymentMadeId;
|
||||||
|
|
||||||
const payableFullAmount = useMemo(
|
|
||||||
() => sumBy(paymentMadePayableBills, 'due_amount'),
|
|
||||||
[paymentMadePayableBills],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDateChange = useCallback(
|
const handleDateChange = useCallback(
|
||||||
(date_filed) => (date) => {
|
(date_filed) => (date) => {
|
||||||
const formatted = moment(date).format('YYYY-MM-DD');
|
const formatted = moment(date).format('YYYY-MM-DD');
|
||||||
@@ -119,9 +112,14 @@ function PaymentMadeFormHeader({
|
|||||||
triggerFullAmountChanged(payableFullAmount);
|
triggerFullAmountChanged(payableFullAmount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePaymentNumberBlur = (event) => {
|
||||||
|
onPaymentNumberChanged && onPaymentNumberChanged(event.currentTarget.value)
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_PRIMARY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_PRIMARY)}>
|
||||||
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
{/* ------------ Vendor name ------------ */}
|
{/* ------------ Vendor name ------------ */}
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'vendor_name'} />}
|
label={<T id={'vendor_name'} />}
|
||||||
@@ -215,6 +213,7 @@ function PaymentMadeFormHeader({
|
|||||||
}
|
}
|
||||||
minimal={true}
|
minimal={true}
|
||||||
{...getFieldProps('payment_number')}
|
{...getFieldProps('payment_number')}
|
||||||
|
onBlur={handlePaymentNumberBlur}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
@@ -264,6 +263,16 @@ function PaymentMadeFormHeader({
|
|||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_BIG_NUMBERS)}>
|
||||||
|
<div class="big-amount">
|
||||||
|
<span class="big-amount__label">Amount Received</span>
|
||||||
|
<h1 class="big-amount__number">
|
||||||
|
<Money amount={amountPaid} currency={'USD'} />
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -276,7 +285,4 @@ export default compose(
|
|||||||
withAccounts(({ accountsList }) => ({
|
withAccounts(({ accountsList }) => ({
|
||||||
accountsList,
|
accountsList,
|
||||||
})),
|
})),
|
||||||
withBills(({ paymentMadePayableBills }) => ({
|
|
||||||
paymentMadePayableBills,
|
|
||||||
})),
|
|
||||||
)(PaymentMadeFormHeader);
|
)(PaymentMadeFormHeader);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect, useMemo, useCallback } from 'react';
|
import React, { useState, useEffect, useMemo, useCallback } from 'react';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import { omit } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import { CloudLoadingIndicator } from 'components'
|
import { CloudLoadingIndicator } from 'components';
|
||||||
import PaymentMadeItemsTableEditor from './PaymentMadeItemsTableEditor';
|
import PaymentMadeItemsTableEditor from './PaymentMadeItemsTableEditor';
|
||||||
|
|
||||||
import withPaymentMadeActions from './withPaymentMadeActions';
|
import withPaymentMadeActions from './withPaymentMadeActions';
|
||||||
@@ -22,48 +22,51 @@ function PaymentMadeItemsTable({
|
|||||||
paymentEntries = [], // { bill_id: number, payment_amount: number, id?: number }
|
paymentEntries = [], // { bill_id: number, payment_amount: number, id?: number }
|
||||||
onClickClearAllLines,
|
onClickClearAllLines,
|
||||||
errors,
|
errors,
|
||||||
|
onFetchEntriesSuccess,
|
||||||
|
|
||||||
// #withBillActions
|
// #withBillActions
|
||||||
requestFetchDueBills,
|
requestFetchDueBills,
|
||||||
|
|
||||||
// #withBills
|
// #withBills
|
||||||
paymentMadePayableBills,
|
vendorPayableBillsEntries,
|
||||||
|
|
||||||
// #withPaymentMadeDetail
|
|
||||||
paymentMade,
|
|
||||||
}) {
|
}) {
|
||||||
const [tableData, setTableData] = useState([]);
|
|
||||||
const [localAmount, setLocalAmount] = useState(fullAmount);
|
|
||||||
|
|
||||||
const isNewMode = !paymentMadeId;
|
const isNewMode = !paymentMadeId;
|
||||||
|
|
||||||
const triggerUpdateData = useCallback((entries) => {
|
// Detarmines takes vendor payable bills entries in create mode
|
||||||
const _data = entries.map((entry) => ({
|
// or payment made entries in edit mode.
|
||||||
bill_id: entry?.bill?.id,
|
const computedTableEntries = useMemo(
|
||||||
...omit(entry, ['bill']),
|
() =>
|
||||||
}))
|
!isEmpty(paymentEntries)
|
||||||
onUpdateData && onUpdateData(_data);
|
? paymentEntries
|
||||||
}, [onUpdateData]);
|
: (vendorPayableBillsEntries || []),
|
||||||
|
[vendorPayableBillsEntries, paymentEntries],
|
||||||
// Merges payment entries with payable bills.
|
);
|
||||||
const computedTableData = useMemo(() => {
|
const [tableData, setTableData] = useState(computedTableEntries);
|
||||||
const entriesTable = new Map(
|
const [localEntries, setLocalEntries] = useState(computedTableEntries);
|
||||||
paymentEntries.map((e) => [e.bill_id, e]),
|
|
||||||
|
const [localAmount, setLocalAmount] = useState(fullAmount);
|
||||||
|
|
||||||
|
// Triggers `onUpdateData` event that passes changed entries.
|
||||||
|
const triggerUpdateData = useCallback(
|
||||||
|
(entries) => {
|
||||||
|
onUpdateData && onUpdateData(entries);
|
||||||
|
},
|
||||||
|
[onUpdateData],
|
||||||
|
);
|
||||||
|
|
||||||
|
const triggerOnFetchBillsSuccess = useCallback(
|
||||||
|
(bills) => {
|
||||||
|
onFetchEntriesSuccess && onFetchEntriesSuccess(bills);
|
||||||
|
},
|
||||||
|
[onFetchEntriesSuccess],
|
||||||
);
|
);
|
||||||
return paymentMadePayableBills.map((bill) => {
|
|
||||||
const entry = entriesTable.get(bill.id);
|
|
||||||
return {
|
|
||||||
bill,
|
|
||||||
id: null,
|
|
||||||
payment_number: 0,
|
|
||||||
...(entry || {}),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [paymentEntries, paymentMadePayableBills]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTableData(computedTableData);
|
if (computedTableEntries !== localEntries) {
|
||||||
}, [computedTableData]);
|
setTableData(computedTableEntries);
|
||||||
|
setLocalEntries(computedTableEntries);
|
||||||
|
}
|
||||||
|
}, [computedTableEntries, localEntries]);
|
||||||
|
|
||||||
// Handle mapping `fullAmount` prop to `localAmount` state.
|
// Handle mapping `fullAmount` prop to `localAmount` state.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -98,14 +101,34 @@ function PaymentMadeItemsTable({
|
|||||||
{ enabled: isNewMode && vendorId },
|
{ enabled: isNewMode && vendorId },
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle update data.
|
useEffect(() => {
|
||||||
const handleUpdateData = (rows) => {
|
const enabled = isNewMode && vendorId;
|
||||||
triggerUpdateData(rows);
|
|
||||||
};
|
|
||||||
|
|
||||||
const noResultsMessage = (vendorId) ?
|
if (!fetchVendorDueBills.isFetching && enabled) {
|
||||||
'There is no payable bills for this vendor that can be applied for this payment' :
|
triggerOnFetchBillsSuccess(computedTableEntries);
|
||||||
'Please select a vendor to display all open bills for it.';
|
}
|
||||||
|
}, [
|
||||||
|
vendorId,
|
||||||
|
isNewMode,
|
||||||
|
fetchVendorDueBills.isFetching,
|
||||||
|
computedTableEntries,
|
||||||
|
triggerOnFetchBillsSuccess,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Handle update data.
|
||||||
|
const handleUpdateData = useCallback(
|
||||||
|
(rows) => {
|
||||||
|
setTableData(rows);
|
||||||
|
triggerUpdateData(rows);
|
||||||
|
},
|
||||||
|
[setTableData, triggerUpdateData],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Detarmines the right no results message before selecting vendor and aftering
|
||||||
|
// selecting vendor id.
|
||||||
|
const noResultsMessage = vendorId
|
||||||
|
? 'There is no payable bills for this vendor that can be applied for this payment'
|
||||||
|
: 'Please select a vendor to display all open bills for it.';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CloudLoadingIndicator isLoading={fetchVendorDueBills.isFetching}>
|
<CloudLoadingIndicator isLoading={fetchVendorDueBills.isFetching}>
|
||||||
@@ -123,7 +146,8 @@ function PaymentMadeItemsTable({
|
|||||||
export default compose(
|
export default compose(
|
||||||
withPaymentMadeActions,
|
withPaymentMadeActions,
|
||||||
withBillActions,
|
withBillActions,
|
||||||
withBills(({ paymentMadePayableBills }) => ({
|
withBills(({ paymentMadePayableBills, vendorPayableBillsEntries }) => ({
|
||||||
paymentMadePayableBills,
|
paymentMadePayableBills,
|
||||||
|
vendorPayableBillsEntries,
|
||||||
})),
|
})),
|
||||||
)(PaymentMadeItemsTable);
|
)(PaymentMadeItemsTable);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default function PaymentMadeItemsTableEditor({
|
|||||||
noResultsMessage
|
noResultsMessage
|
||||||
}) {
|
}) {
|
||||||
const transformedData = useMemo(() => {
|
const transformedData = useMemo(() => {
|
||||||
const rows = data;
|
const rows = [ ...data ];
|
||||||
const totalRow = {
|
const totalRow = {
|
||||||
due_amount: sumBy(data, 'due_amount'),
|
due_amount: sumBy(data, 'due_amount'),
|
||||||
payment_amount: sumBy(data, 'payment_amount'),
|
payment_amount: sumBy(data, 'payment_amount'),
|
||||||
@@ -74,27 +74,27 @@ export default function PaymentMadeItemsTableEditor({
|
|||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'Date' }),
|
Header: formatMessage({ id: 'Date' }),
|
||||||
id: 'bill_date',
|
id: 'bill_date',
|
||||||
accessor: (r) => moment(r.bill?.bill_date).format('YYYY MMM DD'),
|
accessor: (r) => moment(r.bill_date).format('YYYY MMM DD'),
|
||||||
Cell: CellRenderer(EmptyDiv, 'bill_date'),
|
Cell: CellRenderer(EmptyDiv, 'bill_date'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'bill_number' }),
|
Header: formatMessage({ id: 'bill_number' }),
|
||||||
accessor: (row) => `#${row.bill?.bill_number}`,
|
accessor: (row) => `#${row?.bill_number}`,
|
||||||
Cell: CellRenderer(EmptyDiv, 'bill_number'),
|
Cell: CellRenderer(EmptyDiv, 'bill_number'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
className: 'bill_number',
|
className: 'bill_number',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'bill_amount' }),
|
Header: formatMessage({ id: 'bill_amount' }),
|
||||||
accessor: r => r.bill?.amount,
|
accessor: 'amount',
|
||||||
Cell: CellRenderer(DivFieldCell, 'amount'),
|
Cell: CellRenderer(DivFieldCell, 'amount'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
className: '',
|
className: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'amount_due' }),
|
Header: formatMessage({ id: 'amount_due' }),
|
||||||
accessor: r => r.bill?.due_amount,
|
accessor: 'due_amount',
|
||||||
Cell: TotalCellRederer(DivFieldCell, 'due_amount'),
|
Cell: TotalCellRederer(DivFieldCell, 'due_amount'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
className: '',
|
className: '',
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import {
|
|||||||
getPaymentMadeCurrentPageFactory,
|
getPaymentMadeCurrentPageFactory,
|
||||||
getPaymentMadePaginationMetaFactory,
|
getPaymentMadePaginationMetaFactory,
|
||||||
getPaymentMadeTableQuery,
|
getPaymentMadeTableQuery,
|
||||||
|
getPaymentMadeEntriesFactory
|
||||||
} from 'store/PaymentMades/paymentMade.selector';
|
} from 'store/PaymentMades/paymentMade.selector';
|
||||||
|
|
||||||
export default (mapState) => {
|
export default (mapState) => {
|
||||||
const getPyamentMadesItems = getPaymentMadeCurrentPageFactory();
|
const getPyamentMadesItems = getPaymentMadeCurrentPageFactory();
|
||||||
const getPyamentMadesPaginationMeta = getPaymentMadePaginationMetaFactory();
|
const getPyamentMadesPaginationMeta = getPaymentMadePaginationMetaFactory();
|
||||||
|
const getPaymentMadeEntries = getPaymentMadeEntriesFactory();
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => {
|
const mapStateToProps = (state, props) => {
|
||||||
const query = getPaymentMadeTableQuery(state, props);
|
const query = getPaymentMadeTableQuery(state, props);
|
||||||
const mapped = {
|
const mapped = {
|
||||||
@@ -23,8 +26,8 @@ export default (mapState) => {
|
|||||||
query,
|
query,
|
||||||
),
|
),
|
||||||
paymentMadesLoading: state.paymentMades.loading,
|
paymentMadesLoading: state.paymentMades.loading,
|
||||||
nextPaymentNumberChanged:
|
nextPaymentNumberChanged: state.paymentMades.nextPaymentNumberChanged,
|
||||||
state.paymentMades.nextPaymentNumberChanged,
|
paymentMadeEntries: getPaymentMadeEntries(state, props),
|
||||||
};
|
};
|
||||||
return mapState ? mapState(mapped, state, props) : mapped;
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ function InvoiceForm({
|
|||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'due_date_' })),
|
.label(formatMessage({ id: 'due_date_' })),
|
||||||
invoice_no: Yup.string()
|
invoice_no: Yup.string()
|
||||||
.required()
|
|
||||||
.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(),
|
||||||
|
|||||||
@@ -170,7 +170,6 @@ function InvoiceFormHeader({
|
|||||||
label={<T id={'invoice_no'} />}
|
label={<T id={'invoice_no'} />}
|
||||||
inline={true}
|
inline={true}
|
||||||
className={classNames('form-group--invoice-no', CLASSES.FILL)}
|
className={classNames('form-group--invoice-no', CLASSES.FILL)}
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
intent={errors.invoice_no && touched.invoice_no && Intent.DANGER}
|
intent={errors.invoice_no && touched.invoice_no && Intent.DANGER}
|
||||||
helperText={
|
helperText={
|
||||||
<ErrorMessage name="invoice_no" {...{ errors, touched }} />
|
<ErrorMessage name="invoice_no" {...{ errors, touched }} />
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ import {
|
|||||||
getInvoiceCurrentPageFactory,
|
getInvoiceCurrentPageFactory,
|
||||||
getInvoicePaginationMetaFactory,
|
getInvoicePaginationMetaFactory,
|
||||||
getInvoiceTableQueryFactory,
|
getInvoiceTableQueryFactory,
|
||||||
getCustomerReceivableInvoicesFactory,
|
getCustomerReceivableInvoicesEntriesFactory
|
||||||
getPaymentReceivableInvoicesFactory,
|
|
||||||
getPaymentReceiveReceivableInvoicesFactory
|
|
||||||
} from 'store/Invoice/invoices.selector';
|
} from 'store/Invoice/invoices.selector';
|
||||||
|
|
||||||
export default (mapState) => {
|
export default (mapState) => {
|
||||||
@@ -15,10 +13,7 @@ export default (mapState) => {
|
|||||||
const getInvoicesPaginationMeta = getInvoicePaginationMetaFactory();
|
const getInvoicesPaginationMeta = getInvoicePaginationMetaFactory();
|
||||||
const getInvoiceTableQuery = getInvoiceTableQueryFactory();
|
const getInvoiceTableQuery = getInvoiceTableQueryFactory();
|
||||||
|
|
||||||
// const getPaymentReceivableInvoices = getPaymentReceivableInvoicesFactory();
|
const getCustomerReceivableInvoicesEntries = getCustomerReceivableInvoicesEntriesFactory();
|
||||||
// const getCustomerReceivableInvoices = getCustomerReceivableInvoicesFactory();
|
|
||||||
|
|
||||||
const getPaymentReceiveReceivableInvoices = getPaymentReceiveReceivableInvoicesFactory();
|
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => {
|
const mapStateToProps = (state, props) => {
|
||||||
const query = getInvoiceTableQuery(state, props);
|
const query = getInvoiceTableQuery(state, props);
|
||||||
@@ -30,8 +25,7 @@ export default (mapState) => {
|
|||||||
invoicesTableQuery: query,
|
invoicesTableQuery: query,
|
||||||
invoicesPageination: getInvoicesPaginationMeta(state, props, query),
|
invoicesPageination: getInvoicesPaginationMeta(state, props, query),
|
||||||
invoicesLoading: state.salesInvoices.loading,
|
invoicesLoading: state.salesInvoices.loading,
|
||||||
|
customerInvoiceEntries: getCustomerReceivableInvoicesEntries(state, props),
|
||||||
paymentReceiveReceivableInvoices: getPaymentReceiveReceivableInvoices(state, props),
|
|
||||||
};
|
};
|
||||||
return mapState ? mapState(mapped, state, props) : mapped;
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import * as Yup from 'yup';
|
|||||||
import { useFormik } from 'formik';
|
import { useFormik } from 'formik';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { pick, sumBy } from 'lodash';
|
import { pick, sumBy, omit } from 'lodash';
|
||||||
import { Intent, Alert } from '@blueprintjs/core';
|
import { Intent, Alert } from '@blueprintjs/core';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ import { CLASSES } from 'common/classes';
|
|||||||
import PaymentReceiveHeader from './PaymentReceiveFormHeader';
|
import PaymentReceiveHeader from './PaymentReceiveFormHeader';
|
||||||
import PaymentReceiveItemsTable from './PaymentReceiveItemsTable';
|
import PaymentReceiveItemsTable from './PaymentReceiveItemsTable';
|
||||||
import PaymentReceiveFloatingActions from './PaymentReceiveFloatingActions';
|
import PaymentReceiveFloatingActions from './PaymentReceiveFloatingActions';
|
||||||
|
import PaymentReceiveFormFooter from './PaymentReceiveFormFooter';
|
||||||
|
|
||||||
import withMediaActions from 'containers/Media/withMediaActions';
|
import withMediaActions from 'containers/Media/withMediaActions';
|
||||||
import withPaymentReceivesActions from './withPaymentReceivesActions';
|
import withPaymentReceivesActions from './withPaymentReceivesActions';
|
||||||
@@ -26,23 +27,54 @@ import { AppToaster } from 'components';
|
|||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
// Default payment receive entry.
|
||||||
|
const defaultPaymentReceiveEntry = {
|
||||||
|
id: null,
|
||||||
|
payment_amount: null,
|
||||||
|
invoice_id: null,
|
||||||
|
due_amount: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Form initial values.
|
||||||
|
const defaultInitialValues = {
|
||||||
|
customer_id: '',
|
||||||
|
deposit_account_id: '',
|
||||||
|
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
|
reference_no: '',
|
||||||
|
payment_receive_no: '',
|
||||||
|
description: '',
|
||||||
|
full_amount: '',
|
||||||
|
entries: [],
|
||||||
|
};
|
||||||
|
|
||||||
function PaymentReceiveForm({
|
function PaymentReceiveForm({
|
||||||
// #ownProps
|
// #ownProps
|
||||||
paymentReceiveId,
|
paymentReceiveId,
|
||||||
|
mode, //edit, new
|
||||||
|
|
||||||
//#WithPaymentReceiveActions
|
//#WithPaymentReceiveActions
|
||||||
requestSubmitPaymentReceive,
|
requestSubmitPaymentReceive,
|
||||||
requestEditPaymentReceive,
|
requestEditPaymentReceive,
|
||||||
|
|
||||||
// #withPaymentReceive
|
// #withPaymentReceiveDetail
|
||||||
paymentReceive,
|
paymentReceive,
|
||||||
|
paymentReceiveEntries,
|
||||||
}) {
|
}) {
|
||||||
const [amountChangeAlert, setAmountChangeAlert] = useState(false);
|
const [amountChangeAlert, setAmountChangeAlert] = useState(false);
|
||||||
const [clearLinesAlert, setClearLinesAlert] = useState(false);
|
const [clearLinesAlert, setClearLinesAlert] = useState(false);
|
||||||
const [fullAmount, setFullAmount] = useState(null);
|
const [fullAmount, setFullAmount] = useState(null);
|
||||||
|
const [clearFormAlert, setClearFormAlert] = useState(false);
|
||||||
|
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
const [localPaymentEntries, setLocalPaymentEntries] = useState(paymentReceiveEntries);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (localPaymentEntries !== paymentReceiveEntries) {
|
||||||
|
setLocalPaymentEntries(paymentReceiveEntries);
|
||||||
|
}
|
||||||
|
}, [localPaymentEntries, paymentReceiveEntries]);
|
||||||
|
|
||||||
// Form validation schema.
|
// Form validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
customer_id: Yup.string()
|
customer_id: Yup.string()
|
||||||
@@ -55,9 +87,9 @@ function PaymentReceiveForm({
|
|||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'deposit_account_' })),
|
.label(formatMessage({ id: 'deposit_account_' })),
|
||||||
full_amount: Yup.number().nullable(),
|
full_amount: Yup.number().nullable(),
|
||||||
payment_receive_no: Yup.number()
|
payment_receive_no: Yup.number().label(
|
||||||
.required()
|
formatMessage({ id: 'payment_receive_no_' }),
|
||||||
.label(formatMessage({ id: 'payment_receive_no_' })),
|
),
|
||||||
reference_no: Yup.string().min(1).max(255).nullable(),
|
reference_no: Yup.string().min(1).max(255).nullable(),
|
||||||
description: Yup.string().nullable(),
|
description: Yup.string().nullable(),
|
||||||
entries: Yup.array().of(
|
entries: Yup.array().of(
|
||||||
@@ -74,36 +106,6 @@ function PaymentReceiveForm({
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
// Default payment receive.
|
|
||||||
const defaultPaymentReceive = useMemo(
|
|
||||||
() => ({
|
|
||||||
invoice_id: '',
|
|
||||||
invoice_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
||||||
invoice_no: '',
|
|
||||||
balance: '',
|
|
||||||
due_amount: '',
|
|
||||||
payment_amount: '',
|
|
||||||
}),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
const defaultPaymentReceiveEntry = {
|
|
||||||
id: null,
|
|
||||||
payment_amount: null,
|
|
||||||
invoice_id: null,
|
|
||||||
};
|
|
||||||
// Form initial values.
|
|
||||||
const defaultInitialValues = useMemo(
|
|
||||||
() => ({
|
|
||||||
customer_id: '',
|
|
||||||
deposit_account_id: '',
|
|
||||||
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
|
||||||
reference_no: '',
|
|
||||||
payment_receive_no: '',
|
|
||||||
description: '',
|
|
||||||
entries: [],
|
|
||||||
}),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Form initial values.
|
// Form initial values.
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
@@ -112,8 +114,11 @@ function PaymentReceiveForm({
|
|||||||
? {
|
? {
|
||||||
...pick(paymentReceive, Object.keys(defaultInitialValues)),
|
...pick(paymentReceive, Object.keys(defaultInitialValues)),
|
||||||
entries: [
|
entries: [
|
||||||
...paymentReceive.entries.map((paymentReceive) => ({
|
...paymentReceiveEntries.map((paymentReceiveEntry) => ({
|
||||||
...pick(paymentReceive, Object.keys(defaultPaymentReceive)),
|
...pick(
|
||||||
|
paymentReceiveEntry,
|
||||||
|
Object.keys(defaultPaymentReceiveEntry),
|
||||||
|
),
|
||||||
})),
|
})),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@@ -121,7 +126,7 @@ function PaymentReceiveForm({
|
|||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[paymentReceive, defaultInitialValues, defaultPaymentReceive],
|
[paymentReceive, paymentReceiveEntries],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle form submit.
|
// Handle form submit.
|
||||||
@@ -135,7 +140,7 @@ function PaymentReceiveForm({
|
|||||||
const entries = values.entries
|
const entries = values.entries
|
||||||
.filter((entry) => entry.invoice_id && entry.payment_amount)
|
.filter((entry) => entry.invoice_id && entry.payment_amount)
|
||||||
.map((entry) => ({
|
.map((entry) => ({
|
||||||
...pick(entry, Object.keys(defaultPaymentReceiveEntry)),
|
...omit(entry, ['due_amount']),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Calculates the total payment amount of entries.
|
// Calculates the total payment amount of entries.
|
||||||
@@ -148,6 +153,7 @@ function PaymentReceiveForm({
|
|||||||
intent: Intent.WARNING,
|
intent: Intent.WARNING,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
setSubmitting(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const form = { ...values, entries };
|
const form = { ...values, entries };
|
||||||
@@ -196,6 +202,7 @@ function PaymentReceiveForm({
|
|||||||
handleSubmit,
|
handleSubmit,
|
||||||
isSubmitting,
|
isSubmitting,
|
||||||
touched,
|
touched,
|
||||||
|
resetForm,
|
||||||
} = useFormik({
|
} = useFormik({
|
||||||
enableReinitialize: true,
|
enableReinitialize: true,
|
||||||
validationSchema,
|
validationSchema,
|
||||||
@@ -205,14 +212,29 @@ function PaymentReceiveForm({
|
|||||||
onSubmit: handleSubmitForm,
|
onSubmit: handleSubmitForm,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const transformDataTableToEntries = (dataTable) => {
|
||||||
|
return dataTable.map((data) => ({
|
||||||
|
...pick(data, Object.keys(defaultPaymentReceiveEntry)),
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
// Handle update data.
|
// Handle update data.
|
||||||
const handleUpdataData = useCallback(
|
const handleUpdataData = useCallback(
|
||||||
(entries) => {
|
(entries) => {
|
||||||
setFieldValue('entries', entries);
|
setFieldValue('entries', transformDataTableToEntries(entries));
|
||||||
},
|
},
|
||||||
[setFieldValue],
|
[setFieldValue],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Handle fetch success of customer invoices entries.
|
||||||
|
const handleFetchEntriesSuccess = useCallback(
|
||||||
|
(entries) => {
|
||||||
|
setFieldValue('entries', transformDataTableToEntries(entries));
|
||||||
|
},
|
||||||
|
[setFieldValue],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handles full amount change.
|
||||||
const handleFullAmountChange = useCallback(
|
const handleFullAmountChange = useCallback(
|
||||||
(value) => {
|
(value) => {
|
||||||
if (value !== fullAmount) {
|
if (value !== fullAmount) {
|
||||||
@@ -241,22 +263,51 @@ function PaymentReceiveForm({
|
|||||||
setFullAmount(amountChangeAlert);
|
setFullAmount(amountChangeAlert);
|
||||||
setAmountChangeAlert(false);
|
setAmountChangeAlert(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Reset entries payment amount.
|
||||||
|
const resetEntriesPaymentAmount = (entries) => {
|
||||||
|
return entries.map((entry) => ({ ...entry, payment_amount: 0 }));
|
||||||
|
};
|
||||||
// Handle confirm clear all lines.
|
// Handle confirm clear all lines.
|
||||||
const handleConfirmClearLines = useCallback(() => {
|
const handleConfirmClearLines = useCallback(() => {
|
||||||
setFieldValue(
|
setLocalPaymentEntries(resetEntriesPaymentAmount(localPaymentEntries));
|
||||||
'entries',
|
setFieldValue('entries', resetEntriesPaymentAmount(values.entries));
|
||||||
values.entries.map((entry) => ({
|
|
||||||
...entry,
|
|
||||||
payment_amount: 0,
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
setClearLinesAlert(false);
|
setClearLinesAlert(false);
|
||||||
}, [setFieldValue, setClearLinesAlert, values.entries]);
|
}, [setFieldValue, setClearLinesAlert, values.entries, localPaymentEntries]);
|
||||||
|
|
||||||
|
// Handle footer clear button click.
|
||||||
|
const handleClearBtnClick = () => {
|
||||||
|
setClearFormAlert(true);
|
||||||
|
};
|
||||||
|
// Handle cancel button click of clear form alert.
|
||||||
|
const handleCancelClearFormAlert = () => {
|
||||||
|
setClearFormAlert(false);
|
||||||
|
};
|
||||||
|
// Handle confirm button click of clear form alert.
|
||||||
|
const handleConfirmCancelClearFormAlert = () => {
|
||||||
|
resetForm();
|
||||||
|
setClearFormAlert(false);
|
||||||
|
setFullAmount(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculates the total receivable amount from due amount.
|
||||||
|
const receivableFullAmount = useMemo(
|
||||||
|
() => sumBy(values.entries, 'due_amount'),
|
||||||
|
[values.entries],
|
||||||
|
);
|
||||||
|
|
||||||
|
const fullAmountReceived = useMemo(
|
||||||
|
() => sumBy(values.entries, 'payment_amount'),
|
||||||
|
[values.entries],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(
|
<div
|
||||||
CLASSES.PAGE_FORM, CLASSES.PAGE_FORM_PAYMENT_RECEIVE
|
className={classNames(
|
||||||
)}>
|
CLASSES.PAGE_FORM,
|
||||||
|
CLASSES.PAGE_FORM_PAYMENT_RECEIVE,
|
||||||
|
)}
|
||||||
|
>
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<PaymentReceiveHeader
|
<PaymentReceiveHeader
|
||||||
errors={errors}
|
errors={errors}
|
||||||
@@ -267,15 +318,18 @@ function PaymentReceiveForm({
|
|||||||
paymentReceiveId={paymentReceiveId}
|
paymentReceiveId={paymentReceiveId}
|
||||||
customerId={values.customer_id}
|
customerId={values.customer_id}
|
||||||
onFullAmountChanged={handleFullAmountChange}
|
onFullAmountChanged={handleFullAmountChange}
|
||||||
|
receivableFullAmount={receivableFullAmount}
|
||||||
|
amountReceived={fullAmountReceived}
|
||||||
/>
|
/>
|
||||||
<PaymentReceiveItemsTable
|
<PaymentReceiveItemsTable
|
||||||
paymentReceiveId={paymentReceiveId}
|
paymentReceiveId={paymentReceiveId}
|
||||||
customerId={values.customer_id}
|
customerId={values.customer_id}
|
||||||
fullAmount={fullAmount}
|
fullAmount={fullAmount}
|
||||||
onUpdateData={handleUpdataData}
|
onUpdateData={handleUpdataData}
|
||||||
paymentEntries={values.entries}
|
paymentReceiveEntries={localPaymentEntries}
|
||||||
errors={errors?.entries}
|
errors={errors?.entries}
|
||||||
onClickClearAllLines={handleClearAllLines}
|
onClickClearAllLines={handleClearAllLines}
|
||||||
|
onFetchEntriesSuccess={handleFetchEntriesSuccess}
|
||||||
/>
|
/>
|
||||||
<Alert
|
<Alert
|
||||||
cancelButtonText={<T id={'cancel'} />}
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
@@ -285,8 +339,12 @@ function PaymentReceiveForm({
|
|||||||
onCancel={handleCancelAmountChangeAlert}
|
onCancel={handleCancelAmountChangeAlert}
|
||||||
onConfirm={handleConfirmAmountChangeAlert}
|
onConfirm={handleConfirmAmountChangeAlert}
|
||||||
>
|
>
|
||||||
<p>Are you sure to discard full amount?</p>
|
<p>
|
||||||
|
Changing full amount will change all credits and payment were
|
||||||
|
applied, Is this okay?
|
||||||
|
</p>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
<Alert
|
<Alert
|
||||||
cancelButtonText={<T id={'cancel'} />}
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
confirmButtonText={<T id={'ok'} />}
|
confirmButtonText={<T id={'ok'} />}
|
||||||
@@ -295,12 +353,31 @@ function PaymentReceiveForm({
|
|||||||
onCancel={handleCancelClearLines}
|
onCancel={handleCancelClearLines}
|
||||||
onConfirm={handleConfirmClearLines}
|
onConfirm={handleConfirmClearLines}
|
||||||
>
|
>
|
||||||
<p>Are you sure to discard full amount?</p>
|
<p>
|
||||||
|
Clearing the table lines will delete all credits and payment were
|
||||||
|
applied, Is this okay?
|
||||||
|
</p>
|
||||||
</Alert>
|
</Alert>
|
||||||
|
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'ok'} />}
|
||||||
|
intent={Intent.WARNING}
|
||||||
|
isOpen={clearFormAlert}
|
||||||
|
onCancel={handleCancelClearFormAlert}
|
||||||
|
onConfirm={handleConfirmCancelClearFormAlert}
|
||||||
|
>
|
||||||
|
<p>Are you sure you want to clear this transaction?</p>
|
||||||
|
</Alert>
|
||||||
|
|
||||||
|
<PaymentReceiveFormFooter
|
||||||
|
getFieldProps={getFieldProps}
|
||||||
|
/>
|
||||||
|
|
||||||
<PaymentReceiveFloatingActions
|
<PaymentReceiveFloatingActions
|
||||||
isSubmitting={isSubmitting}
|
isSubmitting={isSubmitting}
|
||||||
paymentReceiveId={paymentReceiveId}
|
paymentReceiveId={paymentReceiveId}
|
||||||
|
onClearClick={handleClearBtnClick}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@@ -313,7 +390,8 @@ export default compose(
|
|||||||
// withPaymentReceives(({ paymentReceivesItems }) => ({
|
// withPaymentReceives(({ paymentReceivesItems }) => ({
|
||||||
// paymentReceivesItems,
|
// paymentReceivesItems,
|
||||||
// })),
|
// })),
|
||||||
withPaymentReceiveDetail(({ paymentReceive }) => ({
|
withPaymentReceiveDetail(({ paymentReceive, paymentReceiveEntries }) => ({
|
||||||
paymentReceive,
|
paymentReceive,
|
||||||
|
paymentReceiveEntries,
|
||||||
})),
|
})),
|
||||||
)(PaymentReceiveForm);
|
)(PaymentReceiveForm);
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { FormGroup, TextArea } from '@blueprintjs/core';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
import { Row, Col } from 'components';
|
||||||
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payment receive form footer.
|
||||||
|
*/
|
||||||
|
export default function PaymentReceiveFormFooter({
|
||||||
|
getFieldProps,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={classNames(CLASSES.PAGE_FORM_FOOTER)}>
|
||||||
|
<Row>
|
||||||
|
<Col md={8}>
|
||||||
|
{/* --------- Statement --------- */}
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'statement'} />}
|
||||||
|
className={'form-group--statement'}
|
||||||
|
>
|
||||||
|
<TextArea
|
||||||
|
growVertically={true}
|
||||||
|
{...getFieldProps('description')}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo, useCallback, useState } from 'react';
|
import React, { useMemo, useCallback } from 'react';
|
||||||
import {
|
import {
|
||||||
FormGroup,
|
FormGroup,
|
||||||
InputGroup,
|
InputGroup,
|
||||||
@@ -10,10 +10,9 @@ import {
|
|||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { sumBy } from 'lodash';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { CLASSES } from 'common/classes'
|
import { CLASSES } from 'common/classes';
|
||||||
import { momentFormatter, compose, tansformDateValue } from 'utils';
|
import { momentFormatter, compose, tansformDateValue } from 'utils';
|
||||||
import {
|
import {
|
||||||
AccountsSelectList,
|
AccountsSelectList,
|
||||||
@@ -24,7 +23,6 @@ import {
|
|||||||
Money,
|
Money,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
|
|
||||||
import withInvoices from 'containers/Sales/Invoice/withInvoices';
|
|
||||||
import withCustomers from 'containers/Customers/withCustomers';
|
import withCustomers from 'containers/Customers/withCustomers';
|
||||||
import withAccounts from 'containers/Accounts/withAccounts';
|
import withAccounts from 'containers/Accounts/withAccounts';
|
||||||
|
|
||||||
@@ -37,7 +35,8 @@ function PaymentReceiveFormHeader({
|
|||||||
values,
|
values,
|
||||||
onFullAmountChanged,
|
onFullAmountChanged,
|
||||||
paymentReceiveId,
|
paymentReceiveId,
|
||||||
customerId,
|
receivableFullAmount,
|
||||||
|
amountReceived,
|
||||||
|
|
||||||
//#withCustomers
|
//#withCustomers
|
||||||
customers,
|
customers,
|
||||||
@@ -48,11 +47,6 @@ function PaymentReceiveFormHeader({
|
|||||||
// #withInvoices
|
// #withInvoices
|
||||||
receivableInvoices,
|
receivableInvoices,
|
||||||
}) {
|
}) {
|
||||||
// Compute the total receivable amount.
|
|
||||||
const receivableFullAmount = useMemo(
|
|
||||||
() => sumBy(receivableInvoices, 'due_amount'),
|
|
||||||
[receivableInvoices],
|
|
||||||
);
|
|
||||||
const handleDateChange = useCallback(
|
const handleDateChange = useCallback(
|
||||||
(date_filed) => (date) => {
|
(date_filed) => (date) => {
|
||||||
const formatted = moment(date).format('YYYY-MM-DD');
|
const formatted = moment(date).format('YYYY-MM-DD');
|
||||||
@@ -118,6 +112,7 @@ function PaymentReceiveFormHeader({
|
|||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_PRIMARY)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_PRIMARY)}>
|
||||||
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
{/* ------------- Customer name ------------- */}
|
{/* ------------- Customer name ------------- */}
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'customer_name'} />}
|
label={<T id={'customer_name'} />}
|
||||||
@@ -149,7 +144,9 @@ function PaymentReceiveFormHeader({
|
|||||||
inline={true}
|
inline={true}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
className={classNames('form-group--select-list', CLASSES.FILL)}
|
className={classNames('form-group--select-list', CLASSES.FILL)}
|
||||||
intent={errors.payment_date && touched.payment_date && Intent.DANGER}
|
intent={
|
||||||
|
errors.payment_date && touched.payment_date && Intent.DANGER
|
||||||
|
}
|
||||||
helperText={
|
helperText={
|
||||||
<ErrorMessage name="payment_date" {...{ errors, touched }} />
|
<ErrorMessage name="payment_date" {...{ errors, touched }} />
|
||||||
}
|
}
|
||||||
@@ -167,9 +164,7 @@ function PaymentReceiveFormHeader({
|
|||||||
label={<T id={'full_amount'} />}
|
label={<T id={'full_amount'} />}
|
||||||
inline={true}
|
inline={true}
|
||||||
className={('form-group--full-amount', CLASSES.FILL)}
|
className={('form-group--full-amount', CLASSES.FILL)}
|
||||||
intent={
|
intent={errors.full_amount && touched.full_amount && Intent.DANGER}
|
||||||
errors.full_amount && touched.full_amount && Intent.DANGER
|
|
||||||
}
|
|
||||||
labelInfo={<Hint />}
|
labelInfo={<Hint />}
|
||||||
helperText={
|
helperText={
|
||||||
<ErrorMessage name="full_amount" {...{ errors, touched }} />
|
<ErrorMessage name="full_amount" {...{ errors, touched }} />
|
||||||
@@ -185,8 +180,13 @@ function PaymentReceiveFormHeader({
|
|||||||
onBlur={handleFullAmountBlur}
|
onBlur={handleFullAmountBlur}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<a onClick={handleReceiveFullAmountClick} href="#" className={'receive-full-amount'}>
|
<a
|
||||||
Receive full amount (<Money amount={receivableFullAmount} currency={'USD'} />)
|
onClick={handleReceiveFullAmountClick}
|
||||||
|
href="#"
|
||||||
|
className={'receive-full-amount'}
|
||||||
|
>
|
||||||
|
Receive full amount (
|
||||||
|
<Money amount={receivableFullAmount} currency={'USD'} />)
|
||||||
</a>
|
</a>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
@@ -202,7 +202,10 @@ function PaymentReceiveFormHeader({
|
|||||||
Intent.DANGER
|
Intent.DANGER
|
||||||
}
|
}
|
||||||
helperText={
|
helperText={
|
||||||
<ErrorMessage name="payment_receive_no" {...{ errors, touched }} />
|
<ErrorMessage
|
||||||
|
name="payment_receive_no"
|
||||||
|
{...{ errors, touched }}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<InputGroup
|
<InputGroup
|
||||||
@@ -252,16 +255,32 @@ function PaymentReceiveFormHeader({
|
|||||||
label={<T id={'reference'} />}
|
label={<T id={'reference'} />}
|
||||||
inline={true}
|
inline={true}
|
||||||
className={classNames('form-group--reference', CLASSES.FILL)}
|
className={classNames('form-group--reference', CLASSES.FILL)}
|
||||||
intent={errors.reference_no && touched.reference_no && Intent.DANGER}
|
intent={
|
||||||
helperText={<ErrorMessage name="reference" {...{ errors, touched }} />}
|
errors.reference_no && touched.reference_no && Intent.DANGER
|
||||||
|
}
|
||||||
|
helperText={
|
||||||
|
<ErrorMessage name="reference" {...{ errors, touched }} />
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<InputGroup
|
<InputGroup
|
||||||
intent={errors.reference_no && touched.reference_no && Intent.DANGER}
|
intent={
|
||||||
|
errors.reference_no && touched.reference_no && Intent.DANGER
|
||||||
|
}
|
||||||
minimal={true}
|
minimal={true}
|
||||||
{...getFieldProps('reference_no')}
|
{...getFieldProps('reference_no')}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_BIG_NUMBERS)}>
|
||||||
|
<div class="big-amount">
|
||||||
|
<span class="big-amount__label">Amount Received</span>
|
||||||
|
<h1 class="big-amount__number">
|
||||||
|
<Money amount={amountReceived} currency={'USD'} />
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -273,7 +292,4 @@ export default compose(
|
|||||||
withAccounts(({ accountsList }) => ({
|
withAccounts(({ accountsList }) => ({
|
||||||
accountsList,
|
accountsList,
|
||||||
})),
|
})),
|
||||||
withInvoices(({ paymentReceiveReceivableInvoices }) => ({
|
|
||||||
receivableInvoices: paymentReceiveReceivableInvoices,
|
|
||||||
})),
|
|
||||||
)(PaymentReceiveFormHeader);
|
)(PaymentReceiveFormHeader);
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ import { useParams } from 'react-router-dom';
|
|||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
|
|
||||||
import { DashboardInsider } from 'components'
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
// import PaymentReceiveForm from './PaymentReceiveForm';
|
import PaymentReceiveForm from './PaymentReceiveForm';
|
||||||
import withDashboardActions from "containers/Dashboard/withDashboardActions";
|
import withDashboardActions from "containers/Dashboard/withDashboardActions";
|
||||||
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
||||||
import withSettingsActions from 'containers/Settings/withSettingsActions';
|
import withSettingsActions from 'containers/Settings/withSettingsActions';
|
||||||
import withPaymentReceivesActions from './withPaymentReceivesActions';
|
import withPaymentReceivesActions from './withPaymentReceivesActions';
|
||||||
|
import withCustomersActions from 'containers/Customers/withCustomersActions';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ function PaymentReceiveFormPage({
|
|||||||
requestFetchOptions,
|
requestFetchOptions,
|
||||||
|
|
||||||
// #withPaymentReceivesActions
|
// #withPaymentReceivesActions
|
||||||
requestFetchPaymentReceive
|
requestFetchPaymentReceive,
|
||||||
|
|
||||||
// #withCustomersActions
|
// #withCustomersActions
|
||||||
requestFetchCustomers
|
requestFetchCustomers
|
||||||
@@ -37,6 +38,8 @@ function PaymentReceiveFormPage({
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log(paymentReceiveId, 'X');
|
||||||
|
|
||||||
if (paymentReceiveId) {
|
if (paymentReceiveId) {
|
||||||
changePageTitle(formatMessage({ id: 'edit_payment_receive' }));
|
changePageTitle(formatMessage({ id: 'edit_payment_receive' }));
|
||||||
} else {
|
} else {
|
||||||
@@ -72,9 +75,9 @@ function PaymentReceiveFormPage({
|
|||||||
fetchSettings.isFetching ||
|
fetchSettings.isFetching ||
|
||||||
fetchCustomers.isFetching
|
fetchCustomers.isFetching
|
||||||
}>
|
}>
|
||||||
{/* <PaymentReceiveForm
|
<PaymentReceiveForm
|
||||||
paymentReceiveId={paymentReceiveId}
|
paymentReceiveId={paymentReceiveId}
|
||||||
/> */}
|
/>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import React, { useState, useMemo, useEffect, useCallback } from 'react';
|
import React, { useState, useMemo, useEffect, useCallback } from 'react';
|
||||||
import { Button, Intent, Position, Tooltip } from '@blueprintjs/core';
|
import { CloudLoadingIndicator } from 'components';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
|
||||||
import { Icon, CloudLoadingIndicator } from 'components';
|
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import { omit } from 'lodash';
|
import { omit } from 'lodash';
|
||||||
|
|
||||||
import { compose, formattedAmount } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
import withInvoices from '../Invoice/withInvoices';
|
import withInvoices from '../Invoice/withInvoices';
|
||||||
import PaymentReceiveItemsTableEditor from './PaymentReceiveItemsTableEditor';
|
import PaymentReceiveItemsTableEditor from './PaymentReceiveItemsTableEditor';
|
||||||
@@ -18,55 +16,45 @@ function PaymentReceiveItemsTable({
|
|||||||
customerId,
|
customerId,
|
||||||
fullAmount,
|
fullAmount,
|
||||||
onUpdateData,
|
onUpdateData,
|
||||||
paymentEntries = [],// { invoice_id: number, payment_amount: number, id?: number }
|
paymentReceiveEntries = [],
|
||||||
errors,
|
errors,
|
||||||
onClickClearAllLines,
|
onClickClearAllLines,
|
||||||
|
onFetchEntriesSuccess,
|
||||||
|
|
||||||
// #withInvoices
|
// #withInvoices
|
||||||
paymentReceiveReceivableInvoices,
|
customerInvoiceEntries,
|
||||||
|
|
||||||
// #withPaymentReceive
|
|
||||||
receivableInvoices,
|
|
||||||
|
|
||||||
// #withPaymentReceiveActions
|
// #withPaymentReceiveActions
|
||||||
requestFetchDueInvoices
|
requestFetchDueInvoices
|
||||||
}) {
|
}) {
|
||||||
const isNewMode = !paymentReceiveId;
|
const isNewMode = !paymentReceiveId;
|
||||||
|
|
||||||
const [tableData, setTableData] = useState([]);
|
// Detarmines takes payment receive invoices entries from customer receivable
|
||||||
const [localAmount, setLocalAmount] = useState(fullAmount);
|
// invoices or associated payment receive invoices.
|
||||||
|
const computedTableData = useMemo(() => [
|
||||||
const computedTableData = useMemo(() => {
|
...(!isNewMode ? (paymentReceiveEntries || []) : []),
|
||||||
const entriesTable = new Map(
|
...(isNewMode ? (customerInvoiceEntries || []) : []),
|
||||||
paymentEntries.map((e) => [e.invoice_id, e]),
|
], [
|
||||||
);
|
isNewMode,
|
||||||
return receivableInvoices.map((invoice) => {
|
paymentReceiveEntries,
|
||||||
const entry = entriesTable.get(invoice.id);
|
customerInvoiceEntries,
|
||||||
|
|
||||||
return {
|
|
||||||
invoice,
|
|
||||||
id: null,
|
|
||||||
payment_amount: 0,
|
|
||||||
...(entry || {}),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}, [
|
|
||||||
receivableInvoices,
|
|
||||||
paymentEntries,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const [tableData, setTableData] = useState(computedTableData);
|
||||||
|
const [localEntries, setLocalEntries] = useState(computedTableData);
|
||||||
|
|
||||||
|
const [localAmount, setLocalAmount] = useState(fullAmount);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (computedTableData !== localEntries) {
|
||||||
setTableData(computedTableData);
|
setTableData(computedTableData);
|
||||||
}, [computedTableData]);
|
setLocalEntries(computedTableData);
|
||||||
|
}
|
||||||
|
}, [computedTableData, localEntries]);
|
||||||
|
|
||||||
// Triggers `onUpdateData` prop event.
|
// Triggers `onUpdateData` prop event.
|
||||||
const triggerUpdateData = useCallback((entries) => {
|
const triggerUpdateData = useCallback((entries) => {
|
||||||
const _data = entries.map((entry) => ({
|
onUpdateData && onUpdateData(entries);
|
||||||
invoice_id: entry?.invoice?.id,
|
|
||||||
...omit(entry, ['invoice']),
|
|
||||||
due_amount: entry?.invoice?.due_amount,
|
|
||||||
}))
|
|
||||||
onUpdateData && onUpdateData(_data);
|
|
||||||
}, [onUpdateData]);
|
}, [onUpdateData]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -74,7 +62,7 @@ function PaymentReceiveItemsTable({
|
|||||||
let _fullAmount = fullAmount;
|
let _fullAmount = fullAmount;
|
||||||
|
|
||||||
const newTableData = tableData.map((data) => {
|
const newTableData = tableData.map((data) => {
|
||||||
const amount = Math.min(data?.invoice?.due_amount, _fullAmount);
|
const amount = Math.min(data?.due_amount, _fullAmount);
|
||||||
_fullAmount -= Math.max(amount, 0);
|
_fullAmount -= Math.max(amount, 0);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -93,6 +81,7 @@ function PaymentReceiveItemsTable({
|
|||||||
triggerUpdateData,
|
triggerUpdateData,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Fetches customer receivable invoices.
|
||||||
const fetchCustomerDueInvoices = useQuery(
|
const fetchCustomerDueInvoices = useQuery(
|
||||||
['customer-due-invoices', customerId],
|
['customer-due-invoices', customerId],
|
||||||
(key, _customerId) => requestFetchDueInvoices(_customerId),
|
(key, _customerId) => requestFetchDueInvoices(_customerId),
|
||||||
@@ -103,13 +92,29 @@ function PaymentReceiveItemsTable({
|
|||||||
'There is no receivable invoices for this customer that can be applied for this payment' :
|
'There is no receivable invoices for this customer that can be applied for this payment' :
|
||||||
'Please select a customer to display all open invoices for it.';
|
'Please select a customer to display all open invoices for it.';
|
||||||
|
|
||||||
|
const triggerOnFetchInvoicesSuccess = useCallback((bills) => {
|
||||||
|
onFetchEntriesSuccess && onFetchEntriesSuccess(bills);
|
||||||
|
}, [onFetchEntriesSuccess])
|
||||||
|
|
||||||
// Handle update data.
|
// Handle update data.
|
||||||
const handleUpdateData = useCallback((rows) => {
|
const handleUpdateData = useCallback((rows) => {
|
||||||
triggerUpdateData(rows);
|
triggerUpdateData(rows);
|
||||||
}, []);
|
setTableData(rows);
|
||||||
|
}, [triggerUpdateData]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const enabled = isNewMode && customerId;
|
||||||
|
|
||||||
console.log(tableData, 'XX');
|
if (!fetchCustomerDueInvoices.isFetching && enabled) {
|
||||||
|
triggerOnFetchInvoicesSuccess(computedTableData);
|
||||||
|
}
|
||||||
|
}, [
|
||||||
|
isNewMode,
|
||||||
|
customerId,
|
||||||
|
fetchCustomerDueInvoices.isFetching,
|
||||||
|
computedTableData,
|
||||||
|
triggerOnFetchInvoicesSuccess,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CloudLoadingIndicator isLoading={fetchCustomerDueInvoices.isFetching}>
|
<CloudLoadingIndicator isLoading={fetchCustomerDueInvoices.isFetching}>
|
||||||
@@ -125,8 +130,8 @@ function PaymentReceiveItemsTable({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withInvoices(({ paymentReceiveReceivableInvoices }) => ({
|
withInvoices(({ customerInvoiceEntries }) => ({
|
||||||
receivableInvoices: paymentReceiveReceivableInvoices,
|
customerInvoiceEntries,
|
||||||
})),
|
})),
|
||||||
withInvoiceActions,
|
withInvoiceActions,
|
||||||
)(PaymentReceiveItemsTable);
|
)(PaymentReceiveItemsTable);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export default function PaymentReceiveItemsTableEditor ({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'Date' }),
|
Header: formatMessage({ id: 'Date' }),
|
||||||
id: 'invoice.invoice_date',
|
id: 'invoice_date',
|
||||||
accessor: (r) => moment(r.invoice_date).format('YYYY MMM DD'),
|
accessor: (r) => moment(r.invoice_date).format('YYYY MMM DD'),
|
||||||
Cell: CellRenderer(EmptyDiv, 'invoice_date'),
|
Cell: CellRenderer(EmptyDiv, 'invoice_date'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
@@ -79,14 +79,17 @@ export default function PaymentReceiveItemsTableEditor ({
|
|||||||
|
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'invocie_number' }),
|
Header: formatMessage({ id: 'invocie_number' }),
|
||||||
accessor: (row) => `#${row?.invoice?.invoice_no}`,
|
accessor: (row) => {
|
||||||
|
const invNumber = row?.invoice_no || row?.id;
|
||||||
|
return `#INV-${invNumber}`;
|
||||||
|
},
|
||||||
Cell: CellRenderer(EmptyDiv, 'invoice_no'),
|
Cell: CellRenderer(EmptyDiv, 'invoice_no'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
className: '',
|
className: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'invoice_amount' }),
|
Header: formatMessage({ id: 'invoice_amount' }),
|
||||||
accessor: 'invoice.balance',
|
accessor: 'balance',
|
||||||
Cell: CellRenderer(DivFieldCell, 'balance'),
|
Cell: CellRenderer(DivFieldCell, 'balance'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 100,
|
width: 100,
|
||||||
@@ -94,7 +97,7 @@ export default function PaymentReceiveItemsTableEditor ({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: formatMessage({ id: 'amount_due' }),
|
Header: formatMessage({ id: 'amount_due' }),
|
||||||
accessor: 'invoice.due_amount',
|
accessor: 'due_amount',
|
||||||
Cell: TotalCellRederer(DivFieldCell, 'due_amount'),
|
Cell: TotalCellRederer(DivFieldCell, 'due_amount'),
|
||||||
disableSortBy: true,
|
disableSortBy: true,
|
||||||
width: 150,
|
width: 150,
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
import React, { useCallback, useState, useEffect, useMemo } from 'react';
|
|
||||||
import { useParams, useHistory } from 'react-router-dom';
|
|
||||||
import { useQuery } from 'react-query';
|
|
||||||
|
|
||||||
import PaymentReceiveForm from './PaymentReceiveForm';
|
|
||||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
|
||||||
|
|
||||||
import withCustomersActions from 'containers/Customers/withCustomersActions';
|
|
||||||
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
|
||||||
import withItemsActions from 'containers/Items/withItemsActions';
|
|
||||||
import withPaymentReceivesActions from './withPaymentReceivesActions';
|
|
||||||
import withInvoiceActions from '../Invoice/withInvoiceActions';
|
|
||||||
import withInvoices from '../Invoice/withInvoices';
|
|
||||||
|
|
||||||
import { compose } from 'utils';
|
|
||||||
|
|
||||||
function PaymentReceives({
|
|
||||||
//#withwithAccountsActions
|
|
||||||
requestFetchAccounts,
|
|
||||||
|
|
||||||
//#withCustomersActions
|
|
||||||
requestFetchCustomers,
|
|
||||||
|
|
||||||
//#withItemsActions
|
|
||||||
requestFetchItems,
|
|
||||||
|
|
||||||
//#withPaymentReceivesActions
|
|
||||||
requestFetchPaymentReceive,
|
|
||||||
|
|
||||||
//#withInvoicesActions
|
|
||||||
requestFetchDueInvoices,
|
|
||||||
}) {
|
|
||||||
const history = useHistory();
|
|
||||||
const { id } = useParams();
|
|
||||||
const [customerId, setCustomerId] = useState(null);
|
|
||||||
const [payload, setPayload] = useState(false);
|
|
||||||
|
|
||||||
// Handle fetch accounts data
|
|
||||||
const fetchAccounts = useQuery('accounts-list', (key) =>
|
|
||||||
requestFetchAccounts(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handle fetch Items data table or list
|
|
||||||
const fetchItems = useQuery('items-list', () => requestFetchItems({}));
|
|
||||||
|
|
||||||
// Handle fetch customers data table or list
|
|
||||||
const fetchCustomers = useQuery('customers-list', () =>
|
|
||||||
requestFetchCustomers({}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const fetchPaymentReceive = useQuery(
|
|
||||||
['payment-receive', id],
|
|
||||||
(key, _id) => requestFetchPaymentReceive(_id),
|
|
||||||
{ enabled: !!id },
|
|
||||||
);
|
|
||||||
|
|
||||||
const fetchDueInvoices = useQuery(
|
|
||||||
['due-invoies', customerId],
|
|
||||||
(key, query) => requestFetchDueInvoices(query),
|
|
||||||
{ enabled: !!customerId },
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleFormSubmit = useCallback(
|
|
||||||
(payload) => {
|
|
||||||
payload.redirect && history.push('/payment-receives');
|
|
||||||
},
|
|
||||||
[history],
|
|
||||||
);
|
|
||||||
const handleCancel = useCallback(() => {
|
|
||||||
history.goBack();
|
|
||||||
}, [history]);
|
|
||||||
|
|
||||||
const handleCustomerChange = (customerId) => {
|
|
||||||
setCustomerId(customerId);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DashboardInsider
|
|
||||||
loading={
|
|
||||||
fetchCustomers.isFetching ||
|
|
||||||
fetchItems.isFetching ||
|
|
||||||
fetchAccounts.isFetching ||
|
|
||||||
fetchPaymentReceive.isFetching
|
|
||||||
}
|
|
||||||
name={'payment-receive'}
|
|
||||||
>
|
|
||||||
<PaymentReceiveForm
|
|
||||||
onFormSubmit={handleFormSubmit}
|
|
||||||
paymentReceiveId={id}
|
|
||||||
onCancelForm={handleCancel}
|
|
||||||
onCustomerChange={handleCustomerChange}
|
|
||||||
/>
|
|
||||||
</DashboardInsider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withCustomersActions,
|
|
||||||
withItemsActions,
|
|
||||||
withAccountsActions,
|
|
||||||
withPaymentReceivesActions,
|
|
||||||
withInvoiceActions,
|
|
||||||
)(PaymentReceives);
|
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {
|
import {
|
||||||
getPaymentReceiveByIdFactory,
|
getPaymentReceiveByIdFactory,
|
||||||
getPaymentReceiveInvoices,
|
getPaymentReceiveEntriesFactory,
|
||||||
} from 'store/PaymentReceive/paymentReceive.selector';
|
} from 'store/PaymentReceive/paymentReceive.selector';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const getPaymentReceiveById = getPaymentReceiveByIdFactory();
|
const getPaymentReceiveById = getPaymentReceiveByIdFactory();
|
||||||
|
const getPaymentReceiveEntries = getPaymentReceiveEntriesFactory();
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
paymentReceive: getPaymentReceiveById(state, props),
|
paymentReceive: getPaymentReceiveById(state, props),
|
||||||
paymentReceiveInvoices: getPaymentReceiveInvoices(state, props),
|
paymentReceiveEntries: getPaymentReceiveEntries(state, props),
|
||||||
});
|
});
|
||||||
return connect(mapStateToProps);
|
return connect(mapStateToProps);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -787,5 +787,6 @@ export default {
|
|||||||
invoice_number_is_not_unqiue: 'Invoice number is not unqiue',
|
invoice_number_is_not_unqiue: 'Invoice number is not unqiue',
|
||||||
sale_receipt_number_not_unique: 'Receipt number is not unique',
|
sale_receipt_number_not_unique: 'Receipt number is not unique',
|
||||||
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!',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -280,14 +280,14 @@ export default [
|
|||||||
{
|
{
|
||||||
path: `/payment-receive/:id/edit`,
|
path: `/payment-receive/:id/edit`,
|
||||||
component: LazyLoader({
|
component: LazyLoader({
|
||||||
loader: () => import('containers/Sales/PaymentReceive/PaymentReceives'),
|
loader: () => import('containers/Sales/PaymentReceive/PaymentReceiveFormPage'),
|
||||||
}),
|
}),
|
||||||
breadcrumb: 'Edit',
|
breadcrumb: 'Edit',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: `/payment-receive/new`,
|
path: `/payment-receive/new`,
|
||||||
component: LazyLoader({
|
component: LazyLoader({
|
||||||
loader: () => import('containers/Sales/PaymentReceive/PaymentReceives'),
|
loader: () => import('containers/Sales/PaymentReceive/PaymentReceiveFormPage'),
|
||||||
}),
|
}),
|
||||||
breadcrumb: 'New Payment Receive',
|
breadcrumb: 'New Payment Receive',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const initialState = {
|
|||||||
byVendorId: [],
|
byVendorId: [],
|
||||||
byBillPayamentId: [],
|
byBillPayamentId: [],
|
||||||
},
|
},
|
||||||
|
byBillPayamentId: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultBill = {
|
const defaultBill = {
|
||||||
@@ -133,6 +134,13 @@ const reducer = createReducer(initialState, {
|
|||||||
_data.push(bill.id);
|
_data.push(bill.id);
|
||||||
});
|
});
|
||||||
state.payable.byBillPayamentId[billPaymentId] = _data;
|
state.payable.byBillPayamentId[billPaymentId] = _data;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.BILLS_BY_PAYMENT_ID]: (state, action) => {
|
||||||
|
const { bills, billPaymentId } = action.payload;
|
||||||
|
const billsIds = bills.map((bill) => bill.id);
|
||||||
|
|
||||||
|
state.byBillPayamentId[billPaymentId] = billsIds;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,21 @@
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||||
|
|
||||||
|
// Retreive bills table query.
|
||||||
const billTableQuery = (state) => state.bills.tableQuery;
|
const billTableQuery = (state) => state.bills.tableQuery;
|
||||||
|
|
||||||
const billPageSelector = (state, props, query) => {
|
const billPageSelector = (state, props, query) => {
|
||||||
const viewId = state.bills.currentViewId;
|
const viewId = state.bills.currentViewId;
|
||||||
return state.bills.views?.[viewId]?.pages?.[query.page];
|
return state.bills.views?.[viewId]?.pages?.[query.page];
|
||||||
};
|
};
|
||||||
|
// Retreive bills items.
|
||||||
const billItemsSelector = (state) => state.bills.items;
|
const billItemsSelector = (state) => state.bills.items;
|
||||||
|
|
||||||
/**
|
// Retrieve bill details.
|
||||||
* Retrieve bill details.
|
|
||||||
* @return {IBill}
|
|
||||||
*/
|
|
||||||
const billByIdSelector = (state, props) => state.bills.items[props.billId];
|
const billByIdSelector = (state, props) => state.bills.items[props.billId];
|
||||||
|
|
||||||
/**
|
// Retrieve vendor due bills ids.
|
||||||
* Retrieve vendor due bills ids.
|
|
||||||
* @return {number[]}
|
|
||||||
*/
|
|
||||||
const billsPayableVendorSelector = (state, props) => state.bills.payable.byVendorId[props.vendorId];
|
const billsPayableVendorSelector = (state, props) => state.bills.payable.byVendorId[props.vendorId];
|
||||||
const billsPayableByPaymentMadeSelector = (state, props) => {
|
|
||||||
return state.bills.payable.byBillPayamentId[props.paymentMadeId];
|
|
||||||
}
|
|
||||||
|
|
||||||
const billPaginationSelector = (state, props) => {
|
const billPaginationSelector = (state, props) => {
|
||||||
const viewId = state.bills.currentViewId;
|
const viewId = state.bills.currentViewId;
|
||||||
@@ -60,12 +53,17 @@ export const getBillByIdFactory = () =>
|
|||||||
return bill;
|
return bill;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve bills datatable pagination meta.
|
||||||
|
*/
|
||||||
export const getBillPaginationMetaFactory = () =>
|
export const getBillPaginationMetaFactory = () =>
|
||||||
createSelector(billPaginationSelector, (billPage) => {
|
createSelector(billPaginationSelector, (billPage) => {
|
||||||
return billPage?.paginationMeta || {};
|
return billPage?.paginationMeta || {};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve vendor payable bills.
|
||||||
|
*/
|
||||||
export const getVendorPayableBillsFactory = () =>
|
export const getVendorPayableBillsFactory = () =>
|
||||||
createSelector(
|
createSelector(
|
||||||
billItemsSelector,
|
billItemsSelector,
|
||||||
@@ -77,28 +75,24 @@ export const getVendorPayableBillsFactory = () =>
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
export const getPayableBillsByPaymentMadeFactory = () =>
|
* Retrieve vendor payable bills entries.
|
||||||
createSelector(
|
*/
|
||||||
billItemsSelector,
|
export const getVendorPayableBillsEntriesFactory = () =>
|
||||||
billsPayableByPaymentMadeSelector,
|
|
||||||
(billsItems, payableBillsIds) => {
|
|
||||||
return Array.isArray(payableBillsIds)
|
|
||||||
? pickItemsFromIds(billsItems, payableBillsIds) || []
|
|
||||||
: [];
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getPaymentMadeFormPayableBillsFactory = () =>
|
|
||||||
createSelector(
|
createSelector(
|
||||||
billItemsSelector,
|
billItemsSelector,
|
||||||
billsPayableVendorSelector,
|
billsPayableVendorSelector,
|
||||||
billsPayableByPaymentMadeSelector,
|
(billsItems, payableBillsIds) => {
|
||||||
(billsItems, vendorBillsIds, paymentMadeBillsIds) => {
|
const bills = Array.isArray(payableBillsIds)
|
||||||
const billsIds = [
|
? pickItemsFromIds(billsItems, payableBillsIds) || []
|
||||||
...(vendorBillsIds || []),
|
: [];
|
||||||
...(paymentMadeBillsIds || [])
|
|
||||||
];
|
return bills.map((bill) => ({
|
||||||
return pickItemsFromIds(billsItems, billsIds);
|
...bill,
|
||||||
},
|
bill_id: bill.id,
|
||||||
|
total_payment_amount: bill.payment_amount,
|
||||||
|
id: null,
|
||||||
|
payment_amount: null,
|
||||||
|
}));
|
||||||
|
}
|
||||||
);
|
);
|
||||||
@@ -10,7 +10,7 @@ export default {
|
|||||||
BILLS_PAGE_SET: 'BILLS_PAGE_SET',
|
BILLS_PAGE_SET: 'BILLS_PAGE_SET',
|
||||||
BILLS_ITEMS_SET: 'BILLS_ITEMS_SET',
|
BILLS_ITEMS_SET: 'BILLS_ITEMS_SET',
|
||||||
BILL_NUMBER_CHANGED: 'BILL_NUMBER_CHANGED',
|
BILL_NUMBER_CHANGED: 'BILL_NUMBER_CHANGED',
|
||||||
|
|
||||||
BILLS_PAYABLE_BY_PAYMENT_ID: 'BILLS_PAYABLE_BY_PAYMENT_ID',
|
BILLS_PAYABLE_BY_PAYMENT_ID: 'BILLS_PAYABLE_BY_PAYMENT_ID',
|
||||||
BILLS_PAYABLE_BY_VENDOR_ID: 'BILLS_PAYABLE_BY_VENDOR_ID',
|
BILLS_PAYABLE_BY_VENDOR_ID: 'BILLS_PAYABLE_BY_VENDOR_ID',
|
||||||
|
BILLS_BY_PAYMENT_ID: 'BILLS_BY_PAYMENT_ID',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ export const fetchInvoicesTable = ({ query } = {}) => {
|
|||||||
customViewId: response.data.customViewId || -1,
|
customViewId: response.data.customViewId || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICES_ITEMS_SET,
|
type: t.INVOICES_ITEMS_SET,
|
||||||
payload: {
|
payload: {
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ const initialState = {
|
|||||||
receivable: {
|
receivable: {
|
||||||
byCustomerId: [],
|
byCustomerId: [],
|
||||||
byPaymentReceiveId: [],
|
byPaymentReceiveId: [],
|
||||||
}
|
},
|
||||||
|
byPaymentReceiveId: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultInvoice = {
|
const defaultInvoice = {
|
||||||
@@ -115,6 +116,13 @@ const reducer = createReducer(initialState, {
|
|||||||
|
|
||||||
state.receivable.byCustomerId[customerId] = saleInvoiceIds
|
state.receivable.byCustomerId[customerId] = saleInvoiceIds
|
||||||
},
|
},
|
||||||
|
|
||||||
|
[t.INVOICES_BY_PAYMENT_ID]: (state, action) => {
|
||||||
|
const { paymentReceiveId, saleInvoices } = action.payload;
|
||||||
|
const saleInvoiceIds = saleInvoices.map((saleInvoice) => saleInvoice.id);
|
||||||
|
|
||||||
|
state.byPaymentReceiveId[paymentReceiveId] = saleInvoiceIds;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default createTableQueryReducers('sales_invoices', reducer);
|
export default createTableQueryReducers('sales_invoices', reducer);
|
||||||
|
|||||||
@@ -19,12 +19,8 @@ const invoicesPageSelector = (state, props, query) => {
|
|||||||
const viewId = state.salesInvoices.currentViewId;
|
const viewId = state.salesInvoices.currentViewId;
|
||||||
return state.salesInvoices.views?.[viewId]?.pages?.[query.page];
|
return state.salesInvoices.views?.[viewId]?.pages?.[query.page];
|
||||||
};
|
};
|
||||||
|
|
||||||
const invoicesItemsSelector = (state) => state.salesInvoices.items;
|
const invoicesItemsSelector = (state) => state.salesInvoices.items;
|
||||||
|
|
||||||
const invoicesReceiableCustomerSelector = (state, props) => state.salesInvoices.receivable.byCustomerId[props.customerId];
|
const invoicesReceiableCustomerSelector = (state, props) => state.salesInvoices.receivable.byCustomerId[props.customerId];
|
||||||
const paymentReceivableInvoicesSelector = (state, props) => state.salesInvoices.receivable.byPaymentReceiveId[props.paymentReceiveId];
|
|
||||||
|
|
||||||
|
|
||||||
export const getInvoiceTableQueryFactory = () =>
|
export const getInvoiceTableQueryFactory = () =>
|
||||||
createSelector(
|
createSelector(
|
||||||
@@ -59,39 +55,22 @@ export const getInvoicePaginationMetaFactory = () =>
|
|||||||
return invoicePage?.paginationMeta || {};
|
return invoicePage?.paginationMeta || {};
|
||||||
});
|
});
|
||||||
|
|
||||||
// export const getCustomerReceivableInvoicesFactory = () =>
|
export const getCustomerReceivableInvoicesEntriesFactory = () =>
|
||||||
// createSelector(
|
|
||||||
// invoicesItemsSelector,
|
|
||||||
// invoicesReceiableCustomerSelector,
|
|
||||||
// (invoicesItems, invoicesIds) => {
|
|
||||||
// return Array.isArray(invoicesIds)
|
|
||||||
// ? (pickItemsFromIds(invoicesItems, invoicesIds) || [])
|
|
||||||
// : [];
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
|
|
||||||
// export const getPaymentReceivableInvoicesFactory = () =>
|
|
||||||
// createSelector(
|
|
||||||
// invoicesItemsSelector,
|
|
||||||
// paymentReceivableInvoicesSelector,
|
|
||||||
// (invoicesItems, invoicesIds) => {
|
|
||||||
// return Array.isArray(invoicesIds)
|
|
||||||
// ? (pickItemsFromIds(invoicesItems, invoicesIds) || [])
|
|
||||||
// : [];
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
|
||||||
export const getPaymentReceiveReceivableInvoicesFactory = () =>
|
|
||||||
createSelector(
|
createSelector(
|
||||||
invoicesItemsSelector,
|
invoicesItemsSelector,
|
||||||
invoicesReceiableCustomerSelector,
|
invoicesReceiableCustomerSelector,
|
||||||
paymentReceivableInvoicesSelector,
|
(invoicesItems, customerInvoicesIds) => {
|
||||||
(invoicesItems, customerInvoicesIds, paymentInvoicesIds) => {
|
|
||||||
const invoicesIds = [
|
const invoicesIds = [
|
||||||
...(customerInvoicesIds || []),
|
...(customerInvoicesIds || []),
|
||||||
...(paymentInvoicesIds || []),
|
|
||||||
];
|
];
|
||||||
return pickItemsFromIds(invoicesItems, invoicesIds);
|
const invoices = pickItemsFromIds(invoicesItems, invoicesIds);
|
||||||
|
|
||||||
|
return invoices.map((invoice) => ({
|
||||||
|
...invoice,
|
||||||
|
invoice_id: invoice.id,
|
||||||
|
total_payment_amount: invoice.payment_amount,
|
||||||
|
id: null,
|
||||||
|
payment_amount: 0,
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
);
|
)
|
||||||
@@ -13,5 +13,6 @@ export default {
|
|||||||
RELOAD_INVOICES: 'RELOAD_INVOICES',
|
RELOAD_INVOICES: 'RELOAD_INVOICES',
|
||||||
|
|
||||||
INVOICES_RECEIVABLE_BY_PAYMENT_ID: 'INVOICES_RECEIVABLE_BY_PAYMENT_ID',
|
INVOICES_RECEIVABLE_BY_PAYMENT_ID: 'INVOICES_RECEIVABLE_BY_PAYMENT_ID',
|
||||||
INVOICES_RECEIVABLE_BY_CUSTOMER_ID: 'INVOICES_RECEIVABLE_BY_CUSTOMER_ID'
|
INVOICES_RECEIVABLE_BY_CUSTOMER_ID: 'INVOICES_RECEIVABLE_BY_CUSTOMER_ID',
|
||||||
|
INVOICES_BY_PAYMENT_ID: 'INVOICES_BY_PAYMENT_ID'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -109,17 +109,30 @@ export const fetchPaymentMade = ({ id }) => {
|
|||||||
paymentMade: response.data.bill_payment,
|
paymentMade: response.data.bill_payment,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
dispatch({
|
||||||
|
type: t.BILLS_ITEMS_SET,
|
||||||
|
payload: {
|
||||||
|
bills: response.data.payable_bills,
|
||||||
|
},
|
||||||
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.BILLS_PAYABLE_BY_PAYMENT_ID,
|
type: t.BILLS_PAYABLE_BY_PAYMENT_ID,
|
||||||
payload: {
|
payload: {
|
||||||
billPaymentId: id,
|
billPaymentId: response.data.bill_payment.id,
|
||||||
bills: response.data.bill_payment.payable_bills,
|
bills: response.data.payable_bills,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.BILLS_ITEMS_SET,
|
type: t.BILLS_ITEMS_SET,
|
||||||
payload: {
|
payload: {
|
||||||
bills: response.data.bill_payment.payable_bills,
|
bills: response.data.payment_bills,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: t.BILLS_BY_PAYMENT_ID,
|
||||||
|
payload: {
|
||||||
|
billPaymentId: response.data.bill_payment.id,
|
||||||
|
bills: response.data.payment_bills,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
resovle(response);
|
resovle(response);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||||
|
import { transformToObject } from 'utils';
|
||||||
|
|
||||||
|
|
||||||
const paymentMadeTableQuery = (state) => state.paymentMades.tableQuery;
|
const paymentMadeTableQuery = (state) => state.paymentMades.tableQuery;
|
||||||
|
|
||||||
@@ -10,21 +9,19 @@ const paymentMadesPageSelector = (state, props, query) => {
|
|||||||
return state.paymentMades.views?.[viewId]?.pages?.[query.page];
|
return state.paymentMades.views?.[viewId]?.pages?.[query.page];
|
||||||
};
|
};
|
||||||
|
|
||||||
const paymentMadesItemsSelector = (state) => {
|
const paymentMadesItemsSelector = (state) => state.paymentMades.items;
|
||||||
return state.paymentMades.items;
|
|
||||||
};
|
|
||||||
|
|
||||||
const PaymentMadePaginationSelector = (state, props) => {
|
const PaymentMadePaginationSelector = (state, props) => {
|
||||||
const viewId = state.paymentMades.currentViewId;
|
const viewId = state.paymentMades.currentViewId;
|
||||||
return state.paymentMades.views?.[viewId];
|
return state.paymentMades.views?.[viewId];
|
||||||
};
|
};
|
||||||
|
|
||||||
const paymentMadesIds = (state, props) => {
|
const paymentMadeById = (state, props) => state.paymentMades.items[props.paymentMadeId];
|
||||||
return state.paymentMades.items[props.paymentMadeId];
|
|
||||||
};
|
|
||||||
|
|
||||||
const paymentMadeEntries = (state, props) => props.paymentMadeEntries;
|
const paymentMadeEntries = (state, props) => props.paymentMadeEntries;
|
||||||
const billsItemsSelector = (state, props) => state.bills.items;
|
const billsItemsSelector = (state, props) => state.bills.items;
|
||||||
|
const billsPayableByPaymentMadeSelector = (state, props) => state.bills.payable.byBillPayamentId[props.paymentMadeId];
|
||||||
|
const paymentMadeBillsSelector = (state, props) => state.bills.byBillPayamentId[props.paymentMadeId];
|
||||||
|
|
||||||
export const getPaymentMadeCurrentPageFactory = () =>
|
export const getPaymentMadeCurrentPageFactory = () =>
|
||||||
createSelector(
|
createSelector(
|
||||||
@@ -54,7 +51,7 @@ export const getPaymentMadePaginationMetaFactory = () =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const getPaymentMadeByIdFactory = () =>
|
export const getPaymentMadeByIdFactory = () =>
|
||||||
createSelector(paymentMadesIds, (payment_Made) => {
|
createSelector(paymentMadeById, (payment_Made) => {
|
||||||
return payment_Made;
|
return payment_Made;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -68,4 +65,37 @@ export const getPaymentMadeEntriesDataFactory = () =>
|
|||||||
...entry, ...(billsItems[entry.bill_id] || {}),
|
...entry, ...(billsItems[entry.bill_id] || {}),
|
||||||
})) : [];
|
})) : [];
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
|
|
||||||
|
export const getPaymentMadeEntriesFactory = () =>
|
||||||
|
createSelector(
|
||||||
|
billsItemsSelector,
|
||||||
|
billsPayableByPaymentMadeSelector,
|
||||||
|
paymentMadeBillsSelector,
|
||||||
|
paymentMadeById,
|
||||||
|
(
|
||||||
|
billsItems,
|
||||||
|
paymentPayableBillsIds,
|
||||||
|
paymentMadeBillsIds,
|
||||||
|
paymentMade,
|
||||||
|
) => {
|
||||||
|
const billsIds = [
|
||||||
|
...(paymentPayableBillsIds || []),
|
||||||
|
...(paymentMadeBillsIds || []),
|
||||||
|
];
|
||||||
|
const bills = pickItemsFromIds(billsItems, billsIds);
|
||||||
|
const billEntries = transformToObject((paymentMade?.entries || []), 'bill_id');
|
||||||
|
|
||||||
|
return bills.map((bill) => {
|
||||||
|
const paymentMadeEntry = (billEntries?.[bill.id] || {});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...bill,
|
||||||
|
bill_id: bill.id,
|
||||||
|
total_payment_amount: bill.payment_amount,
|
||||||
|
id: paymentMadeEntry?.id,
|
||||||
|
payment_amount: paymentMadeEntry?.payment_amount,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
@@ -56,20 +56,33 @@ export const fetchPaymentReceive = ({ id }) => {
|
|||||||
type: t.PAYMENT_RECEIVE_SET,
|
type: t.PAYMENT_RECEIVE_SET,
|
||||||
payload: {
|
payload: {
|
||||||
id,
|
id,
|
||||||
paymentReceive: response.data.paymentReceive,
|
paymentReceive: response.data.payment_receive,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICES_ITEMS_SET,
|
type: t.INVOICES_ITEMS_SET,
|
||||||
payload: {
|
payload: {
|
||||||
sales_invoices: response.data.sale_invoice.receivable_invoices,
|
sales_invoices: response.data.receivable_invoices,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: t.INVOICES_ITEMS_SET,
|
||||||
|
payload: {
|
||||||
|
sales_invoices: response.data.payment_invoices,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICES_RECEIVABLE_BY_PAYMENT_ID,
|
type: t.INVOICES_RECEIVABLE_BY_PAYMENT_ID,
|
||||||
payload: {
|
payload: {
|
||||||
paymentReceiveid: response.data.id,
|
paymentReceiveId: response.data.payment_receive.id,
|
||||||
saleInvoices: response.data.sale_invoice.receivable_invoices,
|
saleInvoices: response.data.receivable_invoices,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: t.INVOICES_BY_PAYMENT_ID,
|
||||||
|
payload: {
|
||||||
|
paymentReceiveId: response.data.payment_receive.id,
|
||||||
|
saleInvoices: response.data.payment_invoices,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
resovle(response);
|
resovle(response);
|
||||||
|
|||||||
@@ -1,14 +1,32 @@
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||||
|
import { transformToObject } from 'utils';
|
||||||
|
|
||||||
const paymentReceivesPageSelector = (state, props, query) => {
|
const paymentReceivesPageSelector = (state, props, query) => {
|
||||||
const viewId = state.paymentReceives.currentViewId;
|
const viewId = state.paymentReceives.currentViewId;
|
||||||
return state.paymentReceives.views?.[viewId]?.pages?.[query.page];
|
return state.paymentReceives.views?.[viewId]?.pages?.[query.page];
|
||||||
};
|
};
|
||||||
|
|
||||||
const paymentReceivesItemsSelector = (state) => {
|
const paymentReceivesItemsSelector = (state) => state.paymentReceives.items;
|
||||||
return state.paymentReceives.items;
|
const paymentReceiveTableQuery = (state) => state.paymentReceives.tableQuery;
|
||||||
|
|
||||||
|
const PaymentReceivePaginationSelector = (state, props) => {
|
||||||
|
const viewId = state.paymentReceives.currentViewId;
|
||||||
|
return state.paymentReceives.views?.[viewId];
|
||||||
};
|
};
|
||||||
|
const invoicesItemsSelector = (state) => state.salesInvoices.items;
|
||||||
|
|
||||||
|
const payemntReceiveById = (state, props) =>
|
||||||
|
state.paymentReceives.items[props.paymentReceiveId];
|
||||||
|
|
||||||
|
const invoicesReceivableByPaymentReceiveSelector = (state, props) =>
|
||||||
|
state.salesInvoices.receivable.byPaymentReceiveId[props.paymentReceiveId];
|
||||||
|
|
||||||
|
const paymentReceiveInvoicesSelector = (state, props) =>
|
||||||
|
state.salesInvoices.byPaymentReceiveId[props.paymentReceiveId];
|
||||||
|
|
||||||
|
const paymentReceiveByIdSelector = (state, props) =>
|
||||||
|
state.paymentReceives.items[props.paymentReceiveId];
|
||||||
|
|
||||||
export const getPaymentReceiveCurrentPageFactory = () =>
|
export const getPaymentReceiveCurrentPageFactory = () =>
|
||||||
createSelector(
|
createSelector(
|
||||||
@@ -21,8 +39,6 @@ export const getPaymentReceiveCurrentPageFactory = () =>
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const paymentReceiveTableQuery = (state) => state.paymentReceives.tableQuery;
|
|
||||||
|
|
||||||
export const getPaymentReceiveTableQuery = createSelector(
|
export const getPaymentReceiveTableQuery = createSelector(
|
||||||
paginationLocationQuery,
|
paginationLocationQuery,
|
||||||
paymentReceiveTableQuery,
|
paymentReceiveTableQuery,
|
||||||
@@ -34,48 +50,19 @@ export const getPaymentReceiveTableQuery = createSelector(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const PaymentReceivePaginationSelector = (state, props) => {
|
|
||||||
const viewId = state.paymentReceives.currentViewId;
|
|
||||||
return state.paymentReceives.views?.[viewId];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getPaymentReceivePaginationMetaFactory = () =>
|
export const getPaymentReceivePaginationMetaFactory = () =>
|
||||||
createSelector(PaymentReceivePaginationSelector, (Page) => {
|
createSelector(PaymentReceivePaginationSelector, (Page) => {
|
||||||
return Page?.paginationMeta || {};
|
return Page?.paginationMeta || {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const invoicesItems = (state) => {
|
|
||||||
return state.salesInvoices.items;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const payemntReceiveById = (state, props) => {
|
|
||||||
return state.paymentReceives.items[props.paymentReceiveId];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getPaymentReceiveByIdFactory = () =>
|
export const getPaymentReceiveByIdFactory = () =>
|
||||||
createSelector(payemntReceiveById, (payment_receive) => {
|
createSelector(payemntReceiveById, (payment_receive) => {
|
||||||
return payment_receive;
|
return payment_receive;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const paymentReceiveInvoicesIdss = (state, props) => {
|
|
||||||
return state.paymentReceives.items[props.paymentReceiveInvoices]
|
|
||||||
};
|
|
||||||
|
|
||||||
// const invoicesItems = (state) => {
|
|
||||||
// return state.sales_invoices.items;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// export const = createSelector(
|
|
||||||
// paymentReceiveInvoicesIds,
|
|
||||||
// invoicesItems,
|
|
||||||
// (ids, items) => {},
|
|
||||||
// );
|
|
||||||
|
|
||||||
export const getPaymentReceiveInvoices = createSelector(
|
export const getPaymentReceiveInvoices = createSelector(
|
||||||
payemntReceiveById,
|
payemntReceiveById,
|
||||||
invoicesItems,
|
invoicesItemsSelector,
|
||||||
(paymentRecieve, items) => {
|
(paymentRecieve, items) => {
|
||||||
return typeof paymentRecieve === 'object'
|
return typeof paymentRecieve === 'object'
|
||||||
? pickItemsFromIds(
|
? pickItemsFromIds(
|
||||||
@@ -85,3 +72,42 @@ export const getPaymentReceiveInvoices = createSelector(
|
|||||||
: [];
|
: [];
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve payment receive invoices entries.
|
||||||
|
*/
|
||||||
|
export const getPaymentReceiveEntriesFactory = () =>
|
||||||
|
createSelector(
|
||||||
|
invoicesItemsSelector,
|
||||||
|
invoicesReceivableByPaymentReceiveSelector,
|
||||||
|
paymentReceiveInvoicesSelector,
|
||||||
|
paymentReceiveByIdSelector,
|
||||||
|
(
|
||||||
|
invoicesItems,
|
||||||
|
paymentReceivableInvoicesIds,
|
||||||
|
paymentReceiveInvoicesIds,
|
||||||
|
paymentReceive,
|
||||||
|
) => {
|
||||||
|
const invoicesIds = [
|
||||||
|
...(paymentReceivableInvoicesIds || []),
|
||||||
|
...(paymentReceiveInvoicesIds || []),
|
||||||
|
];
|
||||||
|
const invoices = pickItemsFromIds(invoicesItems, invoicesIds);
|
||||||
|
const invoicesEntries = transformToObject(
|
||||||
|
paymentReceive?.entries || [],
|
||||||
|
'invoice_id',
|
||||||
|
);
|
||||||
|
|
||||||
|
return invoices.map((invoice) => {
|
||||||
|
const paymentReceiveEntry = invoicesEntries?.[invoice.id] || {};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...invoice,
|
||||||
|
invoice_id: invoice.id,
|
||||||
|
total_payment_amount: invoice.payment_amount,
|
||||||
|
id: paymentReceiveEntry?.id,
|
||||||
|
payment_amount: paymentReceiveEntry?.payment_amount,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|||||||
@@ -217,6 +217,10 @@ body.authentication {
|
|||||||
margin: -20px;
|
margin: -20px;
|
||||||
padding-bottom: 6px;
|
padding-bottom: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__header-fields{
|
||||||
|
width: 85%;
|
||||||
|
}
|
||||||
&__footer{
|
&__footer{
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
margin: 15px 0 0 0;
|
margin: 15px 0 0 0;
|
||||||
@@ -430,3 +434,33 @@ body.authentication {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.big-amount{
|
||||||
|
|
||||||
|
&__label{
|
||||||
|
color: #5d6f90;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
&__number{
|
||||||
|
margin: 0;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-weight: 400;
|
||||||
|
margin-top: 6px;
|
||||||
|
color: #343463;
|
||||||
|
line-height: 1;
|
||||||
|
font-size: 34px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.bp3-alert{
|
||||||
|
.bp3-alert-footer{
|
||||||
|
.bp3-button{
|
||||||
|
min-width: 70px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,9 +26,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#{$self}__primary-section{
|
#{$self}__primary-section{
|
||||||
|
display: flex;
|
||||||
padding-bottom: 2px;
|
padding-bottom: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#{$self}__big-numbers{
|
||||||
|
margin-left: auto;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.datatable-editor{
|
.datatable-editor{
|
||||||
|
|
||||||
.table .tbody{
|
.table .tbody{
|
||||||
@@ -56,6 +62,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#{$self}__footer{
|
#{$self}__footer{
|
||||||
|
.form-group--statement{
|
||||||
|
max-width: 500px;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
textarea{
|
||||||
|
width: 100%;
|
||||||
|
min-height: 70px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,9 +26,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#{$self}__primary-section{
|
#{$self}__primary-section{
|
||||||
|
display: flex;
|
||||||
padding-bottom: 2px;
|
padding-bottom: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#{$self}__big-numbers{
|
||||||
|
margin-left: auto;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.datatable-editor{
|
.datatable-editor{
|
||||||
|
|
||||||
.table .tbody{
|
.table .tbody{
|
||||||
@@ -56,6 +62,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#{$self}__footer{
|
#{$self}__footer{
|
||||||
|
.form-group--statement{
|
||||||
|
max-width: 500px;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
textarea{
|
||||||
|
width: 100%;
|
||||||
|
min-height: 70px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,3 +262,15 @@ export const flatToNestedArray = (
|
|||||||
export const orderingLinesIndexes = (lines, attribute = 'index') => {
|
export const orderingLinesIndexes = (lines, attribute = 'index') => {
|
||||||
return lines.map((line, index) => ({ ...line, [attribute]: index + 1 }));
|
return lines.map((line, index) => ({ ...line, [attribute]: index + 1 }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const transformToObject = (arr, key) => {
|
||||||
|
return arr.reduce(function(acc, cur, i) {
|
||||||
|
acc[key ? cur[key] : i] = cur;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const itemsStartWith = (items, char) => {
|
||||||
|
return items.filter((item) => item.indexOf(char) === 0);
|
||||||
|
};
|
||||||
@@ -6,6 +6,7 @@ export interface ISaleInvoice {
|
|||||||
paymentAmount: number,
|
paymentAmount: number,
|
||||||
invoiceDate: Date,
|
invoiceDate: Date,
|
||||||
dueDate: Date,
|
dueDate: Date,
|
||||||
|
dueAmount: number,
|
||||||
entries: IItemEntry[],
|
entries: IItemEntry[],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -172,13 +172,23 @@ export default class BillPaymentsService {
|
|||||||
* @param {NextFunction} next
|
* @param {NextFunction} next
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
private async validateBillsDueAmount(tenantId: number, billPaymentEntries: IBillPaymentEntryDTO[]) {
|
private async validateBillsDueAmount(
|
||||||
|
tenantId: number,
|
||||||
|
billPaymentEntries: IBillPaymentEntryDTO[],
|
||||||
|
oldPaymentEntries: IBillPaymentEntry[] = []
|
||||||
|
) {
|
||||||
const { Bill } = this.tenancy.models(tenantId);
|
const { Bill } = this.tenancy.models(tenantId);
|
||||||
const billsIds = billPaymentEntries.map((entry: IBillPaymentEntryDTO) => entry.billId);
|
const billsIds = billPaymentEntries.map((entry: IBillPaymentEntryDTO) => entry.billId);
|
||||||
|
|
||||||
const storedBills = await Bill.query().whereIn('id', billsIds);
|
const storedBills = await Bill.query().whereIn('id', billsIds);
|
||||||
const storedBillsMap = new Map(
|
const storedBillsMap = new Map(
|
||||||
storedBills.map((bill: any) => [bill.id, bill]),
|
storedBills
|
||||||
|
.map((bill) => {
|
||||||
|
const oldEntries = oldPaymentEntries.filter(entry => entry.billId === bill.id);
|
||||||
|
const oldPaymentAmount = sumBy(oldEntries, 'paymentAmount') || 0;
|
||||||
|
|
||||||
|
return [bill.id, { ...bill, dueAmount: bill.dueAmount + oldPaymentAmount }];
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
interface invalidPaymentAmountError{
|
interface invalidPaymentAmountError{
|
||||||
index: number,
|
index: number,
|
||||||
@@ -328,7 +338,7 @@ export default class BillPaymentsService {
|
|||||||
await this.validateBillsExistance(tenantId, billPaymentObj.entries, billPaymentDTO.vendorId);
|
await this.validateBillsExistance(tenantId, billPaymentObj.entries, billPaymentDTO.vendorId);
|
||||||
|
|
||||||
// Validates the bills due payment amount.
|
// Validates the bills due payment amount.
|
||||||
await this.validateBillsDueAmount(tenantId, billPaymentObj.entries);
|
await this.validateBillsDueAmount(tenantId, billPaymentObj.entries, oldBillPayment.entries);
|
||||||
|
|
||||||
// Validate the payment number uniquiness.
|
// Validate the payment number uniquiness.
|
||||||
if (billPaymentObj.paymentNumber) {
|
if (billPaymentObj.paymentNumber) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
IPaginationMeta,
|
IPaginationMeta,
|
||||||
IPaymentReceive,
|
IPaymentReceive,
|
||||||
IPaymentReceiveDTO,
|
IPaymentReceiveDTO,
|
||||||
|
IPaymentReceiveEntry,
|
||||||
IPaymentReceiveEntryDTO,
|
IPaymentReceiveEntryDTO,
|
||||||
IPaymentReceivesFilter,
|
IPaymentReceivesFilter,
|
||||||
ISaleInvoice
|
ISaleInvoice
|
||||||
@@ -158,14 +159,24 @@ export default class PaymentReceiveService {
|
|||||||
* @param {Response} res -
|
* @param {Response} res -
|
||||||
* @param {Function} next -
|
* @param {Function} next -
|
||||||
*/
|
*/
|
||||||
async validateInvoicesPaymentsAmount(tenantId: number, paymentReceiveEntries: IPaymentReceiveEntryDTO[]) {
|
async validateInvoicesPaymentsAmount(
|
||||||
|
tenantId: number,
|
||||||
|
paymentReceiveEntries: IPaymentReceiveEntryDTO[],
|
||||||
|
oldPaymentEntries: IPaymentReceiveEntry[] = [],
|
||||||
|
) {
|
||||||
const { SaleInvoice } = this.tenancy.models(tenantId);
|
const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||||
const invoicesIds = paymentReceiveEntries.map((e: IPaymentReceiveEntryDTO) => e.invoiceId);
|
const invoicesIds = paymentReceiveEntries.map((e: IPaymentReceiveEntryDTO) => e.invoiceId);
|
||||||
|
|
||||||
const storedInvoices = await SaleInvoice.query().whereIn('id', invoicesIds);
|
const storedInvoices = await SaleInvoice.query().whereIn('id', invoicesIds);
|
||||||
|
|
||||||
const storedInvoicesMap = new Map(
|
const storedInvoicesMap = new Map(
|
||||||
storedInvoices.map((invoice: ISaleInvoice) => [invoice.id, invoice])
|
storedInvoices
|
||||||
|
.map((invoice: ISaleInvoice) => {
|
||||||
|
const oldEntries = oldPaymentEntries.filter(entry => entry.invoiceId);
|
||||||
|
const oldPaymentAmount = sumBy(oldEntries, 'paymentAmount') || 0,
|
||||||
|
|
||||||
|
return [invoice.id, { ...invoice, dueAmount: invoice.dueAmount + oldPaymentAmount }];
|
||||||
|
})
|
||||||
);
|
);
|
||||||
const hasWrongPaymentAmount: any[] = [];
|
const hasWrongPaymentAmount: any[] = [];
|
||||||
|
|
||||||
@@ -301,7 +312,7 @@ export default class PaymentReceiveService {
|
|||||||
await this.validateInvoicesIDsExistance(tenantId, paymentReceiveDTO.customerId, paymentReceiveDTO.entries);
|
await this.validateInvoicesIDsExistance(tenantId, paymentReceiveDTO.customerId, paymentReceiveDTO.entries);
|
||||||
|
|
||||||
// Validate invoice payment amount.
|
// Validate invoice payment amount.
|
||||||
await this.validateInvoicesPaymentsAmount(tenantId, paymentReceiveDTO.entries);
|
await this.validateInvoicesPaymentsAmount(tenantId, paymentReceiveDTO.entries, oldPaymentReceive.entries);
|
||||||
|
|
||||||
// Update the payment receive transaction.
|
// Update the payment receive transaction.
|
||||||
const paymentReceive = await PaymentReceive.query()
|
const paymentReceive = await PaymentReceive.query()
|
||||||
|
|||||||
Reference in New Issue
Block a user