mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
WIP/ Feature : Estimate & Receipt & Bill & Invoice
This commit is contained in:
@@ -1,39 +1,71 @@
|
|||||||
import React, { useCallback, useMemo, useEffect, useState } from 'react';
|
import React, { useCallback, useMemo, useEffect, useState } from 'react';
|
||||||
import { MenuItem, Button } from '@blueprintjs/core';
|
import { MenuItem } from '@blueprintjs/core';
|
||||||
import ListSelect from 'components/ListSelect';
|
import ListSelect from 'components/ListSelect';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
|
||||||
function EstimateListField({
|
function EstimateListField({
|
||||||
products,
|
products,
|
||||||
|
initialProductId,
|
||||||
selectedProductId,
|
selectedProductId,
|
||||||
onProductSelected,
|
|
||||||
defautlSelectText = <T id={'select_product'} />,
|
defautlSelectText = <T id={'select_product'} />,
|
||||||
|
onProductSelected,
|
||||||
}) {
|
}) {
|
||||||
|
const initialProduct = useMemo(
|
||||||
|
() => products.find((a) => a.id === initialProductId),
|
||||||
|
[initialProductId],
|
||||||
|
);
|
||||||
|
|
||||||
|
const [selectedProduct, setSelectedProduct] = useState(
|
||||||
|
initialProduct || null,
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof selectedProductId !== 'undefined') {
|
||||||
|
const product = selectedProductId
|
||||||
|
? products.find((a) => a.id === selectedProductId)
|
||||||
|
: null;
|
||||||
|
setSelectedProduct(product);
|
||||||
|
}
|
||||||
|
}, [selectedProductId, products, setSelectedProduct]);
|
||||||
|
|
||||||
const onProductSelect = useCallback(
|
const onProductSelect = useCallback(
|
||||||
(product) => {
|
(product) => {
|
||||||
|
setSelectedProduct({ ...product });
|
||||||
onProductSelected && onProductSelected(product);
|
onProductSelected && onProductSelected(product);
|
||||||
},
|
},
|
||||||
[onProductSelected],
|
[onProductSelected],
|
||||||
);
|
);
|
||||||
|
|
||||||
const productRenderer = useCallback(
|
const productRenderer = useCallback(
|
||||||
(item, { handleClick, modifiers, query }) => (
|
(item, { handleClick }) => (
|
||||||
<MenuItem text={item.name} key={item.id} onClick={handleClick} />
|
<MenuItem key={item.id} text={item.name} onClick={handleClick} />
|
||||||
),
|
),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const filterProduct = useCallback((query, product, _index, exactMatch) => {
|
||||||
|
const normalizedTitle = product.name.toLowerCase();
|
||||||
|
const normalizedQuery = query.toLowerCase();
|
||||||
|
|
||||||
|
if (exactMatch) {
|
||||||
|
return normalizedTitle === normalizedQuery;
|
||||||
|
} else {
|
||||||
|
return normalizedTitle.indexOf(normalizedQuery) >= 0;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListSelect
|
<ListSelect
|
||||||
items={products}
|
items={products}
|
||||||
noResults={<MenuItem disabled={true} text="No results." />}
|
noResults={<MenuItem disabled={true} text="No results." />}
|
||||||
itemRenderer={productRenderer}
|
itemRenderer={productRenderer}
|
||||||
|
itemPredicate={filterProduct}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
onItemSelect={onProductSelect}
|
onItemSelect={onProductSelect}
|
||||||
selectedItem={`${selectedProductId}`}
|
selectedItem={`${selectedProductId}`}
|
||||||
selectedItemProp={'id'}
|
selectedItemProp={'id'}
|
||||||
labelProp={'name'}
|
labelProp={'name'}
|
||||||
defaultText={defautlSelectText}
|
defaultText={selectedProduct ? selectedProduct.name : defautlSelectText}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,21 +42,35 @@ export default [
|
|||||||
text: <T id={'estimates'} />,
|
text: <T id={'estimates'} />,
|
||||||
href: '/estimates/new',
|
href: '/estimates/new',
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// text: <T id={'estimate_list'} />,
|
||||||
|
// href: '/estimates',
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
text: <T id={'invocies'} />,
|
text: <T id={'invocies'} />,
|
||||||
href: '/invoices/new',
|
href: '/invoices/new',
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// text: <T id={'invoices_list'} />,
|
||||||
|
// href: '/invoices',
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
text: <T id={'payment_receives'} />,
|
text: <T id={'payment_receives'} />,
|
||||||
href: '/payment-receive/new',
|
href: '/payment-receive/new',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
divider: true,
|
divider: true,
|
||||||
|
text: <T id={'invoices_list'} />,
|
||||||
|
href: '/invoices',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: <T id={'receipts'} />,
|
text: <T id={'receipts'} />,
|
||||||
href: '/receipts/new',
|
href: '/receipts/new',
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// text: <T id={'receipt_list'} />,
|
||||||
|
// href: '/receipts',
|
||||||
|
// },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -64,8 +78,12 @@ export default [
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
text: <T id={'bills'} />,
|
text: <T id={'bills'} />,
|
||||||
href: '/bill/new',
|
href: '/bills/new',
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// text: <T id={'bill_list'} />,
|
||||||
|
// href: '/bills',
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
text: <T id={'payment_mades'} />,
|
text: <T id={'payment_mades'} />,
|
||||||
},
|
},
|
||||||
|
|||||||
148
client/src/containers/Purchases/Bill/BillActionsBar.js
Normal file
148
client/src/containers/Purchases/Bill/BillActionsBar.js
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
import React, { useCallback, useState, useMemo } from 'react';
|
||||||
|
import Icon from 'components/Icon';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Classes,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
Popover,
|
||||||
|
NavbarDivider,
|
||||||
|
NavbarGroup,
|
||||||
|
PopoverInteractionKind,
|
||||||
|
Position,
|
||||||
|
Intent,
|
||||||
|
} from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { useRouteMatch, useHistory } from 'react-router-dom';
|
||||||
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import FilterDropdown from 'components/FilterDropdown';
|
||||||
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
|
|
||||||
|
import { If, DashboardActionViewsList } from 'components';
|
||||||
|
|
||||||
|
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
||||||
|
import withBillActions from './withBillActions';
|
||||||
|
import withBills from './withBills';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function BillActionsBar({
|
||||||
|
// #withResourceDetail
|
||||||
|
resourceFields,
|
||||||
|
|
||||||
|
//#withBills
|
||||||
|
billsViews,
|
||||||
|
|
||||||
|
//#withBillActions
|
||||||
|
addBillsTableQueries,
|
||||||
|
|
||||||
|
// #own Porps
|
||||||
|
onFilterChanged,
|
||||||
|
selectedRows = [],
|
||||||
|
}) {
|
||||||
|
const history = useHistory();
|
||||||
|
const { path } = useRouteMatch();
|
||||||
|
const [filterCount, setFilterCount] = useState(0);
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
const handleClickNewBill = useCallback(() => {
|
||||||
|
history.push('/bills/new');
|
||||||
|
}, [history]);
|
||||||
|
|
||||||
|
// const FilterDropdown = FilterDropdown({
|
||||||
|
// initialCondition: {
|
||||||
|
// fieldKey: '',
|
||||||
|
// compatator: '',
|
||||||
|
// value: '',
|
||||||
|
// },
|
||||||
|
// fields: resourceFields,
|
||||||
|
// onFilterChange: (filterConditions) => {
|
||||||
|
// addBillsTableQueries({
|
||||||
|
// filter_roles: filterConditions || '',
|
||||||
|
// });
|
||||||
|
// onFilterChanged && onFilterChanged(filterConditions);
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
||||||
|
selectedRows,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardActionsBar>
|
||||||
|
<NavbarGroup>
|
||||||
|
<DashboardActionViewsList resourceName={'bills'} views={[]} />
|
||||||
|
<NavbarDivider />
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'plus'} />}
|
||||||
|
text={<T id={'new_bill'} />}
|
||||||
|
onClick={handleClickNewBill}
|
||||||
|
/>
|
||||||
|
<Popover
|
||||||
|
minimal={true}
|
||||||
|
content={[]}
|
||||||
|
interactionKind={PopoverInteractionKind.CLICK}
|
||||||
|
position={Position.BOTTOM_LEFT}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
className={classNames(Classes.MINIMAL)}
|
||||||
|
text={
|
||||||
|
filterCount <= 0 ? (
|
||||||
|
<T id={'filter'} />
|
||||||
|
) : (
|
||||||
|
`${filterCount} ${formatMessage({ id: 'filters_applied' })}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
icon={<Icon icon={'filter-16'} iconSize={16} />}
|
||||||
|
/>
|
||||||
|
</Popover>
|
||||||
|
<If condition={hasSelectedRows}>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'trash-16'} iconSize={16} />}
|
||||||
|
text={<T id={'delete'} />}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
// onClick={handleBulkDelete}
|
||||||
|
/>
|
||||||
|
</If>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'print-16'} iconSize={'16'} />}
|
||||||
|
text={<T id={'print'} />}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'file-import-16'} />}
|
||||||
|
text={<T id={'import'} />}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'file-export-16'} iconSize={'16'} />}
|
||||||
|
text={<T id={'export'} />}
|
||||||
|
/>
|
||||||
|
</NavbarGroup>
|
||||||
|
</DashboardActionsBar>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, props) => ({
|
||||||
|
resourceName: 'bills',
|
||||||
|
});
|
||||||
|
const withBillActionsBar = connect(mapStateToProps);
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withBillActionsBar,
|
||||||
|
withResourceDetail(({ resourceFields }) => ({
|
||||||
|
resourceFields,
|
||||||
|
})),
|
||||||
|
|
||||||
|
// withBills(({billsViews})=>({
|
||||||
|
// billsViews
|
||||||
|
// })),
|
||||||
|
|
||||||
|
withBillActions,
|
||||||
|
)(BillActionsBar);
|
||||||
334
client/src/containers/Purchases/Bill/BillForm.js
Normal file
334
client/src/containers/Purchases/Bill/BillForm.js
Normal file
@@ -0,0 +1,334 @@
|
|||||||
|
import React, {
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
} from 'react';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
import { useFormik } from 'formik';
|
||||||
|
import moment from 'moment';
|
||||||
|
import { Intent, FormGroup, TextArea } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
import { pick, omit } from 'lodash';
|
||||||
|
|
||||||
|
import BillFormHeader from './BillFormHeader';
|
||||||
|
import EstimatesItemsTable from 'containers/Sales/Estimate/EntriesItemsTable';
|
||||||
|
import BillFormFooter from './BillFormFooter';
|
||||||
|
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withMediaActions from 'containers/Media/withMediaActions';
|
||||||
|
import withBillActions from './withBillActions';
|
||||||
|
import withBillDetail from './withBillDetail';
|
||||||
|
|
||||||
|
import { AppToaster } from 'components';
|
||||||
|
import Dragzone from 'components/Dragzone';
|
||||||
|
import useMedia from 'hooks/useMedia';
|
||||||
|
|
||||||
|
import { compose, repeatValue } from 'utils';
|
||||||
|
|
||||||
|
const MIN_LINES_NUMBER = 4;
|
||||||
|
|
||||||
|
function BillForm({
|
||||||
|
//#WithMedia
|
||||||
|
requestSubmitMedia,
|
||||||
|
requestDeleteMedia,
|
||||||
|
|
||||||
|
//#withBillActions
|
||||||
|
requestSubmitBill,
|
||||||
|
requestEditBill,
|
||||||
|
|
||||||
|
//#withDashboard
|
||||||
|
changePageTitle,
|
||||||
|
changePageSubtitle,
|
||||||
|
|
||||||
|
//#withBillDetail
|
||||||
|
bill,
|
||||||
|
|
||||||
|
//#Own Props
|
||||||
|
billId,
|
||||||
|
onFormSubmit,
|
||||||
|
onCancelForm,
|
||||||
|
}) {
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
const [payload, setPayload] = useState({});
|
||||||
|
|
||||||
|
const {
|
||||||
|
setFiles,
|
||||||
|
saveMedia,
|
||||||
|
deletedFiles,
|
||||||
|
setDeletedFiles,
|
||||||
|
deleteMedia,
|
||||||
|
} = useMedia({
|
||||||
|
saveCallback: requestSubmitMedia,
|
||||||
|
deleteCallback: requestDeleteMedia,
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleDropFiles = useCallback((_files) => {
|
||||||
|
setFiles(_files.filter((file) => file.uploaded === false));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const savedMediaIds = useRef([]);
|
||||||
|
const clearSavedMediaIds = () => {
|
||||||
|
savedMediaIds.current = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (bill && bill.id) {
|
||||||
|
changePageTitle(formatMessage({ id: 'edit_bill' }));
|
||||||
|
} else {
|
||||||
|
changePageTitle(formatMessage({ id: 'new_bill' }));
|
||||||
|
}
|
||||||
|
}, [changePageTitle, bill, formatMessage]);
|
||||||
|
|
||||||
|
const validationSchema = Yup.object().shape({
|
||||||
|
vendor_id: Yup.number()
|
||||||
|
.required()
|
||||||
|
.label(formatMessage({ id: 'vendor_name_' })),
|
||||||
|
bill_date: Yup.date()
|
||||||
|
.required()
|
||||||
|
.label(formatMessage({ id: 'bill_date_' })),
|
||||||
|
due_date: Yup.date()
|
||||||
|
.required()
|
||||||
|
.label(formatMessage({ id: 'due_date_' })),
|
||||||
|
bill_number: Yup.number()
|
||||||
|
.required()
|
||||||
|
.label(formatMessage({ id: 'bill_number_' })),
|
||||||
|
reference_no: Yup.string().min(1).max(255),
|
||||||
|
status: Yup.string().required().nullable(),
|
||||||
|
note: Yup.string()
|
||||||
|
.trim()
|
||||||
|
.min(1)
|
||||||
|
.max(1024)
|
||||||
|
.label(formatMessage({ id: 'note' })),
|
||||||
|
|
||||||
|
entries: Yup.array().of(
|
||||||
|
Yup.object().shape({
|
||||||
|
quantity: Yup.number().nullable(),
|
||||||
|
rate: Yup.number().nullable(),
|
||||||
|
item_id: Yup.number()
|
||||||
|
.nullable()
|
||||||
|
.when(['quantity', 'rate'], {
|
||||||
|
is: (quantity, rate) => quantity || rate,
|
||||||
|
then: Yup.number().required(),
|
||||||
|
}),
|
||||||
|
total: Yup.number().nullable(),
|
||||||
|
discount: Yup.number().nullable(),
|
||||||
|
description: Yup.string().nullable(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
const saveBillSubmit = useCallback(
|
||||||
|
(payload) => {
|
||||||
|
onFormSubmit && onFormSubmit(payload);
|
||||||
|
},
|
||||||
|
[onFormSubmit],
|
||||||
|
);
|
||||||
|
|
||||||
|
const defaultBill = useMemo(() => ({
|
||||||
|
index: 0,
|
||||||
|
item_id: null,
|
||||||
|
rate: null,
|
||||||
|
discount: 0,
|
||||||
|
quantity: null,
|
||||||
|
description: '',
|
||||||
|
}));
|
||||||
|
|
||||||
|
const defaultInitialValues = useMemo(
|
||||||
|
() => ({
|
||||||
|
vendor_id: '',
|
||||||
|
bill_number: '',
|
||||||
|
bill_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
|
due_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
|
status: 'Bill',
|
||||||
|
reference_no: '',
|
||||||
|
note: '',
|
||||||
|
entries: [...repeatValue(defaultBill, MIN_LINES_NUMBER)],
|
||||||
|
}),
|
||||||
|
[defaultBill],
|
||||||
|
);
|
||||||
|
|
||||||
|
const orderingIndex = (_bill) => {
|
||||||
|
return _bill.map((item, index) => ({
|
||||||
|
...item,
|
||||||
|
index: index + 1,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialValues = useMemo(
|
||||||
|
() => ({
|
||||||
|
...(bill
|
||||||
|
? {
|
||||||
|
...pick(bill, Object.keys(defaultInitialValues)),
|
||||||
|
entries: [
|
||||||
|
...bill.entries.map((bill) => ({
|
||||||
|
...pick(bill, Object.keys(defaultBill)),
|
||||||
|
})),
|
||||||
|
...repeatValue(
|
||||||
|
defaultBill,
|
||||||
|
Math.max(MIN_LINES_NUMBER - bill.entries.length, 0),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
...defaultInitialValues,
|
||||||
|
entries: orderingIndex(defaultInitialValues.entries),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
[bill, defaultInitialValues, defaultBill],
|
||||||
|
);
|
||||||
|
|
||||||
|
// const initialValues = useMemo(
|
||||||
|
// () => ({
|
||||||
|
// ...defaultInitialValues,
|
||||||
|
// entries: orderingIndex(defaultInitialValues.entries),
|
||||||
|
// }),
|
||||||
|
// [defaultInitialValues],
|
||||||
|
// );
|
||||||
|
|
||||||
|
const initialAttachmentFiles = useMemo(() => {
|
||||||
|
return bill && bill.media
|
||||||
|
? bill.media.map((attach) => ({
|
||||||
|
preview: attach.attachment_file,
|
||||||
|
uploaded: true,
|
||||||
|
metadata: { ...attach },
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
}, [bill]);
|
||||||
|
|
||||||
|
const formik = useFormik({
|
||||||
|
enableReinitialize: true,
|
||||||
|
validationSchema,
|
||||||
|
initialValues: {
|
||||||
|
...initialValues,
|
||||||
|
},
|
||||||
|
onSubmit: async (values, { setSubmitting, setErrors, resetForm }) => {
|
||||||
|
setSubmitting(true);
|
||||||
|
|
||||||
|
const entries = values.entries.filter(
|
||||||
|
(item) => item.item_id && item.quantity,
|
||||||
|
);
|
||||||
|
const form = {
|
||||||
|
...values,
|
||||||
|
entries,
|
||||||
|
};
|
||||||
|
|
||||||
|
const requestForm = { ...form };
|
||||||
|
if (bill && bill.id) {
|
||||||
|
requestEditBill(bill.id, requestForm)
|
||||||
|
.then((response) => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'the_bill_has_been_successfully_edited',
|
||||||
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
setSubmitting(false);
|
||||||
|
saveBillSubmit({ action: 'update', ...payload });
|
||||||
|
resetForm();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
setSubmitting(false);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
requestSubmitBill(requestForm)
|
||||||
|
.then((response) => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage(
|
||||||
|
{ id: 'the_bill_has_been_successfully_created' },
|
||||||
|
{ number: values.bill_number },
|
||||||
|
),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
setSubmitting(false);
|
||||||
|
resetForm();
|
||||||
|
saveBillSubmit({ action: 'new', ...payload });
|
||||||
|
})
|
||||||
|
.catch((errors) => {
|
||||||
|
setSubmitting(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmitClick = useCallback(
|
||||||
|
(payload) => {
|
||||||
|
setPayload(payload);
|
||||||
|
formik.submitForm();
|
||||||
|
},
|
||||||
|
[setPayload, formik],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleCancelClick = useCallback(
|
||||||
|
(payload) => {
|
||||||
|
onCancelForm && onCancelForm(payload);
|
||||||
|
},
|
||||||
|
[onCancelForm],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleDeleteFile = useCallback(
|
||||||
|
(_deletedFiles) => {
|
||||||
|
_deletedFiles.forEach((deletedFile) => {
|
||||||
|
if (deletedFile.uploaded && deletedFile.metadata.id) {
|
||||||
|
setDeletedFiles([...deletedFiles, deletedFile.metadata.id]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[setDeletedFiles, deletedFiles],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onClickCleanAllLines = () => {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'entries',
|
||||||
|
orderingIndex([...repeatValue(defaultBill, MIN_LINES_NUMBER)]),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onClickAddNewRow = () => {
|
||||||
|
formik.setFieldValue(
|
||||||
|
'entries',
|
||||||
|
orderingIndex([...formik.values.entries, defaultBill]),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(formik.errors, 'Errors');
|
||||||
|
console.log(formik.values, 'values');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={'bill-form'}>
|
||||||
|
<form onSubmit={formik.handleSubmit}>
|
||||||
|
<BillFormHeader formik={formik} />
|
||||||
|
<EstimatesItemsTable
|
||||||
|
formik={formik}
|
||||||
|
entries={formik.values.entries}
|
||||||
|
onClickAddNewRow={onClickAddNewRow}
|
||||||
|
onClickClearAllLines={onClickCleanAllLines}
|
||||||
|
/>
|
||||||
|
<FormGroup label={<T id={'note'} />} className={'form-group--'}>
|
||||||
|
<TextArea growVertically={true} {...formik.getFieldProps('note')} />
|
||||||
|
</FormGroup>
|
||||||
|
<Dragzone
|
||||||
|
initialFiles={initialAttachmentFiles}
|
||||||
|
onDrop={handleDropFiles}
|
||||||
|
onDeleteFile={handleDeleteFile}
|
||||||
|
hint={'Attachments: Maxiumum size: 20MB'}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
<BillFormFooter
|
||||||
|
formik={formik}
|
||||||
|
onSubmitClick={handleSubmitClick}
|
||||||
|
bill={bill}
|
||||||
|
onCancelClick={handleCancelClick}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withBillActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withMediaActions,
|
||||||
|
withBillDetail(),
|
||||||
|
)(BillForm);
|
||||||
52
client/src/containers/Purchases/Bill/BillFormFooter.js
Normal file
52
client/src/containers/Purchases/Bill/BillFormFooter.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Intent, Button } from '@blueprintjs/core';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
|
||||||
|
export default function BillFormFooter({
|
||||||
|
formik: { isSubmitting },
|
||||||
|
onSubmitClick,
|
||||||
|
onCancelClick,
|
||||||
|
bill,
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
disabled={isSubmitting}
|
||||||
|
intent={Intent.PRIMARY}
|
||||||
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onSubmitClick({ redirect: true });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{bill && bill.id ? <T id={'edit'} /> : <T id={'save_send'} />}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
disabled={isSubmitting}
|
||||||
|
intent={Intent.PRIMARY}
|
||||||
|
className={'ml1'}
|
||||||
|
name={'save'}
|
||||||
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onSubmitClick({ redirect: false });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<T id={'save'} />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button className={'ml1'} disabled={isSubmitting}>
|
||||||
|
<T id={'clear'} />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className={'ml1'}
|
||||||
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onCancelClick && onCancelClick();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<T id={'close'} />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
190
client/src/containers/Purchases/Bill/BillFormHeader.js
Normal file
190
client/src/containers/Purchases/Bill/BillFormHeader.js
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
import React, { useMemo, useCallback, useState } from 'react';
|
||||||
|
import {
|
||||||
|
FormGroup,
|
||||||
|
InputGroup,
|
||||||
|
Intent,
|
||||||
|
Position,
|
||||||
|
MenuItem,
|
||||||
|
Classes,
|
||||||
|
} from '@blueprintjs/core';
|
||||||
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
import { Row, Col } from 'react-grid-system';
|
||||||
|
import moment from 'moment';
|
||||||
|
import { momentFormatter, compose, tansformDateValue } from 'utils';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import {
|
||||||
|
AccountsSelectList,
|
||||||
|
ListSelect,
|
||||||
|
ErrorMessage,
|
||||||
|
FieldRequiredHint,
|
||||||
|
Hint,
|
||||||
|
} from 'components';
|
||||||
|
|
||||||
|
// import withCustomers from 'containers/Customers/withCustomers';
|
||||||
|
import withVendors from 'containers/Vendors/withVendors';
|
||||||
|
import withAccounts from 'containers/Accounts/withAccounts';
|
||||||
|
|
||||||
|
function BillFormHeader({
|
||||||
|
formik: { errors, touched, setFieldValue, getFieldProps, values },
|
||||||
|
|
||||||
|
//#withVendors
|
||||||
|
vendorsCurrentPage,
|
||||||
|
vendorItems,
|
||||||
|
//#withAccouts
|
||||||
|
accountsList,
|
||||||
|
}) {
|
||||||
|
const handleDateChange = useCallback(
|
||||||
|
(date_filed) => (date) => {
|
||||||
|
const formatted = moment(date).format('YYYY-MM-DD');
|
||||||
|
setFieldValue(date_filed, formatted);
|
||||||
|
},
|
||||||
|
[setFieldValue],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onChangeSelected = useCallback(
|
||||||
|
(filedName) => {
|
||||||
|
return (item) => {
|
||||||
|
setFieldValue(filedName, item.id);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
[setFieldValue],
|
||||||
|
);
|
||||||
|
|
||||||
|
const vendorNameRenderer = useCallback(
|
||||||
|
(accept, { handleClick }) => (
|
||||||
|
<MenuItem
|
||||||
|
key={accept.id}
|
||||||
|
text={accept.display_name}
|
||||||
|
onClick={handleClick}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Filter vendor name
|
||||||
|
const filterVendorAccount = (query, vendor, _index, exactMatch) => {
|
||||||
|
const normalizedTitle = vendor.display_name.toLowerCase();
|
||||||
|
const normalizedQuery = query.toLowerCase();
|
||||||
|
if (exactMatch) {
|
||||||
|
return normalizedTitle === normalizedQuery;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
`${vendor.display_name} ${normalizedTitle}`.indexOf(normalizedQuery) >=
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(vendorsCurrentPage, 'vendorsCurrentPage');
|
||||||
|
console.log(vendorItems, 'vendorItems');
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
{/* vendor account name */}
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'vendor_name'} />}
|
||||||
|
inline={true}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
intent={errors.vendor_id && touched.vendor_id && Intent.DANGER}
|
||||||
|
helperText={
|
||||||
|
<ErrorMessage name={'vendor_id'} {...{ errors, touched }} />
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<ListSelect
|
||||||
|
items={vendorsCurrentPage}
|
||||||
|
noResults={<MenuItem disabled={true} text="No results." />}
|
||||||
|
itemRenderer={vendorNameRenderer}
|
||||||
|
itemPredicate={filterVendorAccount}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
onItemSelect={onChangeSelected('vendor_id')}
|
||||||
|
selectedItem={values.vendor_id}
|
||||||
|
selectedItemProp={'id'}
|
||||||
|
defaultText={<T id={'select_vendor_account'} />}
|
||||||
|
labelProp={'display_name'}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
<Row>
|
||||||
|
<Col>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'bill_date'} />}
|
||||||
|
inline={true}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
intent={errors.bill_date && touched.bill_date && Intent.DANGER}
|
||||||
|
helperText={
|
||||||
|
<ErrorMessage name="bill_date" {...{ errors, touched }} />
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<DateInput
|
||||||
|
{...momentFormatter('YYYY/MM/DD')}
|
||||||
|
value={tansformDateValue(values.bill_date)}
|
||||||
|
onChange={handleDateChange('bill_date')}
|
||||||
|
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
<Col>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'due_date'} />}
|
||||||
|
inline={true}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
intent={errors.due_date && touched.due_date && Intent.DANGER}
|
||||||
|
helperText={
|
||||||
|
<ErrorMessage name="due_date" {...{ errors, touched }} />
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<DateInput
|
||||||
|
{...momentFormatter('YYYY/MM/DD')}
|
||||||
|
value={tansformDateValue(values.due_date)}
|
||||||
|
onChange={handleDateChange('due_date')}
|
||||||
|
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
{/* bill number */}
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'bill_number'} />}
|
||||||
|
inline={true}
|
||||||
|
className={('form-group--estimate', Classes.FILL)}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
intent={errors.bill_number && touched.bill_number && Intent.DANGER}
|
||||||
|
helperText={
|
||||||
|
<ErrorMessage name="bill_number" {...{ errors, touched }} />
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<InputGroup
|
||||||
|
intent={errors.bill_number && touched.bill_number && Intent.DANGER}
|
||||||
|
minimal={true}
|
||||||
|
{...getFieldProps('bill_number')}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</div>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'reference'} />}
|
||||||
|
inline={true}
|
||||||
|
className={classNames('form-group--reference', Classes.FILL)}
|
||||||
|
intent={errors.reference_no && touched.reference_no && Intent.DANGER}
|
||||||
|
helperText={<ErrorMessage name="reference" {...{ errors, touched }} />}
|
||||||
|
>
|
||||||
|
<InputGroup
|
||||||
|
intent={errors.reference_no && touched.reference_no && Intent.DANGER}
|
||||||
|
minimal={true}
|
||||||
|
{...getFieldProps('reference_no')}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withVendors(({ vendorsCurrentPage, vendorItems }) => ({
|
||||||
|
vendorsCurrentPage,
|
||||||
|
vendorItems,
|
||||||
|
})),
|
||||||
|
withAccounts(({ accountsList }) => ({
|
||||||
|
accountsList,
|
||||||
|
})),
|
||||||
|
)(BillFormHeader);
|
||||||
178
client/src/containers/Purchases/Bill/BillList.js
Normal file
178
client/src/containers/Purchases/Bill/BillList.js
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
import React, { useEffect, useCallback, useMemo, useState } from 'react';
|
||||||
|
import { Route, Switch, useHistory } from 'react-router-dom';
|
||||||
|
import { useQuery, queryCache } from 'react-query';
|
||||||
|
import { Alert, Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import AppToaster from 'components/AppToaster';
|
||||||
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||||
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
|
import BillsDataTable from './BillsDataTable';
|
||||||
|
import BillActionsBar from './BillActionsBar';
|
||||||
|
import BillViewTabs from './BillViewTabs';
|
||||||
|
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withResourceActions from 'containers/Resources/withResourcesActions';
|
||||||
|
|
||||||
|
import withBills from './withBills';
|
||||||
|
import withBillActions from './withBillActions';
|
||||||
|
import withViewsActions from 'containers/Views/withViewsActions';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function BillList({
|
||||||
|
// #withDashboardActions
|
||||||
|
changePageTitle,
|
||||||
|
|
||||||
|
// #withViewsActions
|
||||||
|
requestFetchResourceViews,
|
||||||
|
requestFetchResourceFields,
|
||||||
|
|
||||||
|
//#withBills
|
||||||
|
billsTableQuery,
|
||||||
|
|
||||||
|
//#withBillActions
|
||||||
|
requestFetchBillsTable,
|
||||||
|
requestDeleteBill,
|
||||||
|
addBillsTableQueries,
|
||||||
|
}) {
|
||||||
|
const history = useHistory();
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
const [deleteBill, setDeleteBill] = useState(false);
|
||||||
|
const [selectedRows, setSelectedRows] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
changePageTitle(formatMessage({ id: 'bill_list' }));
|
||||||
|
}, [changePageTitle, formatMessage]);
|
||||||
|
|
||||||
|
const fetchResourceViews = useQuery(
|
||||||
|
['resource-views', 'bills'],
|
||||||
|
(key, resourceName) => requestFetchResourceViews(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchResourceFields = useQuery(
|
||||||
|
['resource-fields', 'bills'],
|
||||||
|
(key, resourceName) => requestFetchResourceFields(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchBills = useQuery(['bills-table', billsTableQuery], () =>
|
||||||
|
requestFetchBillsTable(),
|
||||||
|
);
|
||||||
|
|
||||||
|
//handle dalete Bill
|
||||||
|
const handleDeleteBill = useCallback(
|
||||||
|
(bill) => {
|
||||||
|
setDeleteBill(bill);
|
||||||
|
},
|
||||||
|
[setDeleteBill],
|
||||||
|
);
|
||||||
|
|
||||||
|
// handle cancel Bill
|
||||||
|
const handleCancelBillDelete = useCallback(() => {
|
||||||
|
setDeleteBill(false);
|
||||||
|
}, [setDeleteBill]);
|
||||||
|
|
||||||
|
// handleConfirm delete invoice
|
||||||
|
const handleConfirmBillDelete = useCallback(() => {
|
||||||
|
requestDeleteBill(deleteBill.id).then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'the_bill_has_been_successfully_deleted',
|
||||||
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
setDeleteBill(false);
|
||||||
|
});
|
||||||
|
}, [deleteBill, requestDeleteBill, formatMessage]);
|
||||||
|
|
||||||
|
const handleEditBill = useCallback((bill) => {
|
||||||
|
history.push(`/bills/${bill.id}/edit`);
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleFetchData = useCallback(
|
||||||
|
({ pageIndex, pageSize, sortBy }) => {
|
||||||
|
const page = pageIndex + 1;
|
||||||
|
|
||||||
|
addBillsTableQueries({
|
||||||
|
...(sortBy.length > 0
|
||||||
|
? {
|
||||||
|
column_sort_by: sortBy[0].id,
|
||||||
|
sort_order: sortBy[0].desc ? 'desc' : 'asc',
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
page_size: pageSize,
|
||||||
|
page,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[addBillsTableQueries],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle selected rows change.
|
||||||
|
const handleSelectedRowsChange = useCallback(
|
||||||
|
(_invoices) => {
|
||||||
|
setSelectedRows(_invoices);
|
||||||
|
},
|
||||||
|
[setSelectedRows],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle filter change to re-fetch data-table.
|
||||||
|
const handleFilterChanged = useCallback(
|
||||||
|
(filterConditions) => {
|
||||||
|
addBillsTableQueries({
|
||||||
|
filter_roles: filterConditions || '',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[fetchBills],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardInsider
|
||||||
|
loading={fetchResourceViews.isFetching || fetchResourceFields.isFetching}
|
||||||
|
name={'bills'}
|
||||||
|
>
|
||||||
|
<BillActionsBar
|
||||||
|
// onBulkDelete={}
|
||||||
|
selectedRows={selectedRows}
|
||||||
|
onFilterChanged={handleFilterChanged}
|
||||||
|
/>
|
||||||
|
<DashboardPageContent>
|
||||||
|
<Switch>
|
||||||
|
<Route exact={true}>
|
||||||
|
<BillViewTabs />
|
||||||
|
<BillsDataTable
|
||||||
|
loading={fetchBills.isFetching}
|
||||||
|
onDeleteBill={handleDeleteBill}
|
||||||
|
onFetchData={handleFetchData}
|
||||||
|
onEditBill={handleEditBill}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
/>
|
||||||
|
</Route>
|
||||||
|
</Switch>
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'delete'} />}
|
||||||
|
icon={'trash'}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
isOpen={deleteBill}
|
||||||
|
onCancel={handleCancelBillDelete}
|
||||||
|
onConfirm={handleConfirmBillDelete}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<T id={'once_delete_this_bill_you_will_able_to_restore_it'} />
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
</DashboardPageContent>
|
||||||
|
</DashboardInsider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withResourceActions,
|
||||||
|
withBillActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withViewsActions,
|
||||||
|
withBills(({ billsTableQuery }) => ({
|
||||||
|
billsTableQuery,
|
||||||
|
})),
|
||||||
|
)(BillList);
|
||||||
110
client/src/containers/Purchases/Bill/BillViewTabs.js
Normal file
110
client/src/containers/Purchases/Bill/BillViewTabs.js
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
import { useHistory } from 'react-router';
|
||||||
|
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||||
|
import { useParams, withRouter } from 'react-router-dom';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { pick, debounce } from 'lodash';
|
||||||
|
|
||||||
|
import { DashboardViewsTabs } from 'components';
|
||||||
|
import { useUpdateEffect } from 'hooks';
|
||||||
|
|
||||||
|
import withBills from './withBills';
|
||||||
|
import withBillActions from './withBillActions';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withViewDetails from 'containers/Views/withViewDetails';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function BillViewTabs({
|
||||||
|
//#withBills
|
||||||
|
billsViews,
|
||||||
|
|
||||||
|
// #withViewDetails
|
||||||
|
viewItem,
|
||||||
|
|
||||||
|
//#withBillActions
|
||||||
|
changeBillView,
|
||||||
|
addBillsTableQueries,
|
||||||
|
|
||||||
|
// #withDashboardActions
|
||||||
|
setTopbarEditView,
|
||||||
|
changePageSubtitle,
|
||||||
|
|
||||||
|
// #ownProps
|
||||||
|
customViewChanged,
|
||||||
|
onViewChanged,
|
||||||
|
}) {
|
||||||
|
const history = useHistory();
|
||||||
|
const { custom_view_id: customViewId = null } = useParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
changeBillView(customViewId || -1);
|
||||||
|
setTopbarEditView(customViewId);
|
||||||
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
|
|
||||||
|
addBillsTableQueries({
|
||||||
|
custom_view_id: customViewId,
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
setTopbarEditView(null);
|
||||||
|
changePageSubtitle('');
|
||||||
|
changeBillView(null);
|
||||||
|
};
|
||||||
|
}, [customViewId, addBillsTableQueries, changeBillView]);
|
||||||
|
|
||||||
|
useUpdateEffect(() => {
|
||||||
|
onViewChanged && onViewChanged(customViewId);
|
||||||
|
}, [customViewId]);
|
||||||
|
|
||||||
|
const debounceChangeHistory = useRef(
|
||||||
|
debounce((toUrl) => {
|
||||||
|
history.push(toUrl);
|
||||||
|
}, 250),
|
||||||
|
);
|
||||||
|
// Handle click a new view tab.
|
||||||
|
const handleClickNewView = () => {
|
||||||
|
setTopbarEditView(null);
|
||||||
|
history.push('/custom_views/invoices/new');
|
||||||
|
};
|
||||||
|
const handleTabsChange = (viewId) => {
|
||||||
|
const toPath = viewId ? `${viewId}/custom_view` : '';
|
||||||
|
debounceChangeHistory.current(`/bills/${toPath}`);
|
||||||
|
setTopbarEditView(viewId);
|
||||||
|
};
|
||||||
|
const tabs = billsViews.map((view) => ({
|
||||||
|
...pick(view, ['name', 'id']),
|
||||||
|
}));
|
||||||
|
|
||||||
|
console.log(billsViews, 'billsViews');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Navbar className={'navbar--dashboard-views'}>
|
||||||
|
<NavbarGroup align={Alignment.LEFT}>
|
||||||
|
<DashboardViewsTabs
|
||||||
|
initialViewId={customViewId}
|
||||||
|
baseUrl={'/bills'}
|
||||||
|
tabs={tabs}
|
||||||
|
onNewViewTabClick={handleClickNewView}
|
||||||
|
onChange={handleTabsChange}
|
||||||
|
/>
|
||||||
|
</NavbarGroup>
|
||||||
|
</Navbar>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
|
viewId: ownProps.match.params.custom_view_id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const withBillsViewTabs = connect(mapStateToProps);
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withRouter,
|
||||||
|
withBillsViewTabs,
|
||||||
|
withBillActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withViewDetails(),
|
||||||
|
withBills(({ billsViews }) => ({
|
||||||
|
billsViews,
|
||||||
|
})),
|
||||||
|
)(BillViewTabs);
|
||||||
85
client/src/containers/Purchases/Bill/Bills.js
Normal file
85
client/src/containers/Purchases/Bill/Bills.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import { useParams, useHistory } from 'react-router-dom';
|
||||||
|
import { useQuery } from 'react-query';
|
||||||
|
|
||||||
|
import BillForm from './BillForm';
|
||||||
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
|
import withVendorActions from 'containers/Vendors/withVendorActions';
|
||||||
|
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
||||||
|
import withItemsActions from 'containers/Items/withItemsActions';
|
||||||
|
import withBillActions from './withBillActions';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function Bills({
|
||||||
|
//#withwithAccountsActions
|
||||||
|
requestFetchAccounts,
|
||||||
|
|
||||||
|
//#withVendorActions
|
||||||
|
requestFetchVendorsTable,
|
||||||
|
|
||||||
|
//#withItemsActions
|
||||||
|
requestFetchItems,
|
||||||
|
|
||||||
|
//# withBilleActions
|
||||||
|
requestFetchBill,
|
||||||
|
}) {
|
||||||
|
const history = useHistory();
|
||||||
|
const { id } = useParams();
|
||||||
|
|
||||||
|
// Handle fetch accounts
|
||||||
|
const fetchAccounts = useQuery('accounts-list', (key) =>
|
||||||
|
requestFetchAccounts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle fetch customers data table
|
||||||
|
const fetchVendors = useQuery('vendors-list', () =>
|
||||||
|
requestFetchVendorsTable({}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle fetch Items data table or list
|
||||||
|
const fetchItems = useQuery('items-list', () => requestFetchItems({}));
|
||||||
|
|
||||||
|
const handleFormSubmit = useCallback(
|
||||||
|
(payload) => {
|
||||||
|
payload.redirect && history.push('/bills');
|
||||||
|
},
|
||||||
|
[history],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleCancel = useCallback(() => {
|
||||||
|
history.goBack();
|
||||||
|
}, [history]);
|
||||||
|
|
||||||
|
const fetchBill = useQuery(
|
||||||
|
['bill', id],
|
||||||
|
(key, _id) => requestFetchBill(_id),
|
||||||
|
{ enabled: !!id },
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardInsider
|
||||||
|
loading={
|
||||||
|
fetchVendors.isFetching ||
|
||||||
|
fetchItems.isFetching ||
|
||||||
|
fetchAccounts.isFetching ||
|
||||||
|
fetchBill.isFetching
|
||||||
|
}
|
||||||
|
name={'bill-form'}
|
||||||
|
>
|
||||||
|
<BillForm
|
||||||
|
onFormSubmit={handleFormSubmit}
|
||||||
|
billId={id}
|
||||||
|
onCancelForm={handleCancel}
|
||||||
|
/>
|
||||||
|
</DashboardInsider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withBillActions,
|
||||||
|
withVendorActions,
|
||||||
|
withItemsActions,
|
||||||
|
withAccountsActions,
|
||||||
|
)(Bills);
|
||||||
243
client/src/containers/Purchases/Bill/BillsDataTable.js
Normal file
243
client/src/containers/Purchases/Bill/BillsDataTable.js
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
import React, { useEffect, useCallback, useState, useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
Intent,
|
||||||
|
Button,
|
||||||
|
Classes,
|
||||||
|
Popover,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
MenuDivider,
|
||||||
|
Position,
|
||||||
|
} from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
|
import { withRouter } from 'react-router';
|
||||||
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
import Icon from 'components/Icon';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
import { useUpdateEffect } from 'hooks';
|
||||||
|
|
||||||
|
import LoadingIndicator from 'components/LoadingIndicator';
|
||||||
|
import DataTable from 'components/DataTable';
|
||||||
|
|
||||||
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withViewDetails from 'containers/Views/withViewDetails';
|
||||||
|
|
||||||
|
import withBills from './withBills';
|
||||||
|
import withBillActions from './withBillActions';
|
||||||
|
import withCurrentView from 'containers/Views/withCurrentView';
|
||||||
|
|
||||||
|
function BillsDataTable({
|
||||||
|
//#withBills
|
||||||
|
billsCurrentPage,
|
||||||
|
billsLoading,
|
||||||
|
billsPageination,
|
||||||
|
|
||||||
|
// #withDashboardActions
|
||||||
|
changeCurrentView,
|
||||||
|
changePageSubtitle,
|
||||||
|
setTopbarEditView,
|
||||||
|
|
||||||
|
// #withView
|
||||||
|
viewMeta,
|
||||||
|
|
||||||
|
//#OwnProps
|
||||||
|
loading,
|
||||||
|
onFetchData,
|
||||||
|
onEditBill,
|
||||||
|
onDeleteBill,
|
||||||
|
onSelectedRowsChange,
|
||||||
|
}) {
|
||||||
|
const [initialMount, setInitialMount] = useState(false);
|
||||||
|
const { custom_view_id: customViewId } = useParams();
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setInitialMount(false);
|
||||||
|
}, [customViewId]);
|
||||||
|
|
||||||
|
useUpdateEffect(() => {
|
||||||
|
if (!billsLoading) {
|
||||||
|
setInitialMount(true);
|
||||||
|
}
|
||||||
|
}, [billsLoading, setInitialMount]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (customViewId) {
|
||||||
|
changeCurrentView(customViewId);
|
||||||
|
setTopbarEditView(customViewId);
|
||||||
|
}
|
||||||
|
changePageSubtitle(customViewId && viewMeta ? viewMeta.name : '');
|
||||||
|
}, [
|
||||||
|
customViewId,
|
||||||
|
changeCurrentView,
|
||||||
|
changePageSubtitle,
|
||||||
|
setTopbarEditView,
|
||||||
|
viewMeta,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const handleEditBill = useCallback(
|
||||||
|
(_bill) => () => {
|
||||||
|
onEditBill && onEditBill(_bill);
|
||||||
|
},
|
||||||
|
[onEditBill],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleDeleteBill = useCallback(
|
||||||
|
(_bill) => () => {
|
||||||
|
onDeleteBill && onDeleteBill(_bill);
|
||||||
|
},
|
||||||
|
[onDeleteBill],
|
||||||
|
);
|
||||||
|
|
||||||
|
const actionMenuList = useCallback(
|
||||||
|
(bill) => (
|
||||||
|
<Menu>
|
||||||
|
<MenuItem text={formatMessage({ id: 'view_details' })} />
|
||||||
|
<MenuDivider />
|
||||||
|
<MenuItem
|
||||||
|
text={formatMessage({ id: 'edit_bill' })}
|
||||||
|
onClick={handleEditBill(bill)}
|
||||||
|
/>
|
||||||
|
<MenuItem
|
||||||
|
text={formatMessage({ id: 'delete_bill' })}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
onClick={handleDeleteBill(bill)}
|
||||||
|
/>
|
||||||
|
</Menu>
|
||||||
|
),
|
||||||
|
[handleDeleteBill, handleEditBill, formatMessage],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onRowContextMenu = useCallback(
|
||||||
|
(cell) => {
|
||||||
|
return actionMenuList(cell.row.original);
|
||||||
|
},
|
||||||
|
[actionMenuList],
|
||||||
|
);
|
||||||
|
|
||||||
|
const columns = useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
id: 'bill_date',
|
||||||
|
Header: formatMessage({ id: 'bill_date' }),
|
||||||
|
accessor: (r) => moment(r.bill_date).format('YYYY MMM DD'),
|
||||||
|
width: 140,
|
||||||
|
className: 'bill_date',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'vendor_id',
|
||||||
|
Header: formatMessage({ id: 'vendor_name' }),
|
||||||
|
accessor: (row) => row.vendor_id,
|
||||||
|
width: 140,
|
||||||
|
className: 'vendor_id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'bill_number',
|
||||||
|
Header: formatMessage({ id: 'bill_number' }),
|
||||||
|
accessor: (row) => `#${row.bill_number}`,
|
||||||
|
width: 140,
|
||||||
|
className: 'bill_number',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: 'due_date',
|
||||||
|
Header: formatMessage({ id: 'due_date' }),
|
||||||
|
accessor: (r) => moment(r.due_date).format('YYYY MMM DD'),
|
||||||
|
width: 140,
|
||||||
|
className: 'due_date',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'amount',
|
||||||
|
Header: formatMessage({ id: 'amount' }),
|
||||||
|
accessor: 'amount',
|
||||||
|
width: 140,
|
||||||
|
className: 'amount',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'reference_no',
|
||||||
|
Header: formatMessage({ id: 'reference_no' }),
|
||||||
|
accessor: 'reference_no',
|
||||||
|
width: 140,
|
||||||
|
className: 'reference_no',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'status',
|
||||||
|
Header: formatMessage({ id: 'status' }),
|
||||||
|
accessor: 'status',
|
||||||
|
width: 140,
|
||||||
|
className: 'status',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'actions',
|
||||||
|
Header: '',
|
||||||
|
Cell: ({ cell }) => (
|
||||||
|
<Popover
|
||||||
|
content={actionMenuList(cell.row.original)}
|
||||||
|
position={Position.RIGHT_BOTTOM}
|
||||||
|
>
|
||||||
|
<Button icon={<Icon icon="more-h-16" iconSize={16} />} />
|
||||||
|
</Popover>
|
||||||
|
),
|
||||||
|
className: 'actions',
|
||||||
|
width: 50,
|
||||||
|
disableResizing: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[actionMenuList, formatMessage],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleDataTableFetchData = useCallback(
|
||||||
|
(...args) => {
|
||||||
|
onFetchData && onFetchData(...args);
|
||||||
|
},
|
||||||
|
[onFetchData],
|
||||||
|
);
|
||||||
|
const handleSelectedRowsChange = useCallback(
|
||||||
|
(selectedRows) => {
|
||||||
|
onSelectedRowsChange &&
|
||||||
|
onSelectedRowsChange(selectedRows.map((s) => s.original));
|
||||||
|
},
|
||||||
|
[onSelectedRowsChange],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<LoadingIndicator loading={loading} mount={false}>
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={billsCurrentPage}
|
||||||
|
onFetchData={handleDataTableFetchData}
|
||||||
|
manualSortBy={true}
|
||||||
|
selectionColumn={true}
|
||||||
|
noInitialFetch={true}
|
||||||
|
sticky={true}
|
||||||
|
loading={billsLoading && !initialMount}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
rowContextMenu={onRowContextMenu}
|
||||||
|
pagination={true}
|
||||||
|
pagesCount={billsPageination.pagesCount}
|
||||||
|
initialPageSize={billsPageination.pageSize}
|
||||||
|
initialPageIndex={billsPageination.page - 1}
|
||||||
|
/>
|
||||||
|
</LoadingIndicator>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withRouter,
|
||||||
|
withCurrentView,
|
||||||
|
withDialogActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withBillActions,
|
||||||
|
withBills(({ billsCurrentPage, billsLoading, billsPageination }) => ({
|
||||||
|
billsCurrentPage,
|
||||||
|
billsLoading,
|
||||||
|
billsPageination,
|
||||||
|
})),
|
||||||
|
withViewDetails(),
|
||||||
|
)(BillsDataTable);
|
||||||
32
client/src/containers/Purchases/Bill/withBillActions.js
Normal file
32
client/src/containers/Purchases/Bill/withBillActions.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import {
|
||||||
|
submitBill,
|
||||||
|
deleteBill,
|
||||||
|
editBill,
|
||||||
|
fetchBillsTable,
|
||||||
|
fetchBill,
|
||||||
|
} from 'store/Bills/bills.actions';
|
||||||
|
import t from 'store/types';
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
|
requestSubmitBill: (form) => dispatch(submitBill({ form })),
|
||||||
|
requestFetchBill: (id) => dispatch(fetchBill({ id })),
|
||||||
|
requestEditBill: (id, form) => dispatch(editBill( id, form )),
|
||||||
|
requestDeleteBill: (id) => dispatch(deleteBill({ id })),
|
||||||
|
requestFetchBillsTable: (query = {}) =>
|
||||||
|
dispatch(fetchBillsTable({ query: { ...query } })),
|
||||||
|
|
||||||
|
changeBillView: (id) =>
|
||||||
|
dispatch({
|
||||||
|
type: t.BILLS_SET_CURRENT_VIEW,
|
||||||
|
currentViewId: parseInt(id, 10),
|
||||||
|
}),
|
||||||
|
|
||||||
|
addBillsTableQueries: (queries) =>
|
||||||
|
dispatch({
|
||||||
|
type: t.BILLS_TABLE_QUERIES_ADD,
|
||||||
|
queries,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(null, mapDispatchToProps);
|
||||||
11
client/src/containers/Purchases/Bill/withBillDetail.js
Normal file
11
client/src/containers/Purchases/Bill/withBillDetail.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { getBillByIdFactory } from 'store/Bills/bills.selectors';
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const getBillById = getBillByIdFactory();
|
||||||
|
|
||||||
|
const mapStateToProps = (state, props) => ({
|
||||||
|
bill: getBillById(state, props),
|
||||||
|
});
|
||||||
|
return connect(mapStateToProps);
|
||||||
|
};
|
||||||
25
client/src/containers/Purchases/Bill/withBills.js
Normal file
25
client/src/containers/Purchases/Bill/withBills.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { getResourceViews } from 'store/customViews/customViews.selectors';
|
||||||
|
import {
|
||||||
|
getBillCurrentPageFactory,
|
||||||
|
getBillPaginationMetaFactory,
|
||||||
|
getBillTableQuery,
|
||||||
|
} from 'store/Bills/bills.selectors';
|
||||||
|
|
||||||
|
export default (mapState) => {
|
||||||
|
const getBillsItems = getBillCurrentPageFactory();
|
||||||
|
const getBillsPaginationMeta = getBillPaginationMetaFactory();
|
||||||
|
const mapStateToProps = (state, props) => {
|
||||||
|
const query = getBillTableQuery(state, props);
|
||||||
|
const mapped = {
|
||||||
|
billsCurrentPage: getBillsItems(state, props, query),
|
||||||
|
billsViews: getResourceViews(state, props, 'bills'),
|
||||||
|
billsItems: state.bills.items,
|
||||||
|
billsTableQuery: query,
|
||||||
|
billsPageination: getBillsPaginationMeta(state, props, query),
|
||||||
|
billsLoading: state.bills.loading,
|
||||||
|
};
|
||||||
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
|
};
|
||||||
|
return connect(mapStateToProps);
|
||||||
|
};
|
||||||
@@ -4,7 +4,7 @@ import { FormattedMessage as T, useIntl } from 'react-intl';
|
|||||||
import DataTable from 'components/DataTable';
|
import DataTable from 'components/DataTable';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
|
|
||||||
import { compose, formattedAmount, transformUpdatedRows } from 'utils';
|
import { compose, formattedAmount } from 'utils';
|
||||||
import {
|
import {
|
||||||
InputGroupCell,
|
InputGroupCell,
|
||||||
MoneyFieldCell,
|
MoneyFieldCell,
|
||||||
@@ -176,7 +176,7 @@ function EstimateTable({
|
|||||||
setFieldValue(
|
setFieldValue(
|
||||||
'entries',
|
'entries',
|
||||||
newRow.map((row) => ({
|
newRow.map((row) => ({
|
||||||
...omit(row),
|
...omit(row, ['total']),
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo, useCallback } from 'react';
|
import React, { useMemo, useCallback, useState } from 'react';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -14,9 +14,9 @@ import {
|
|||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useRouteMatch, useHistory } from 'react-router-dom';
|
import { useRouteMatch, useHistory } from 'react-router-dom';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import { If } from 'components';
|
import { If, DashboardActionViewsList } from 'components';
|
||||||
import FilterDropdown from 'components/FilterDropdown';
|
import FilterDropdown from 'components/FilterDropdown';
|
||||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
|
|
||||||
@@ -41,37 +41,60 @@ function EstimateActionsBar({
|
|||||||
|
|
||||||
// #own Porps
|
// #own Porps
|
||||||
onFilterChanged,
|
onFilterChanged,
|
||||||
selectedRows,
|
selectedRows = [],
|
||||||
}) {
|
}) {
|
||||||
const { path } = useRouteMatch();
|
const { path } = useRouteMatch();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const [filterCount, setFilterCount] = useState(0);
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
const onClickNewEstimate = useCallback(() => {
|
const onClickNewEstimate = useCallback(() => {
|
||||||
// history.push('/estimates/new');
|
history.push('/estimates/new');
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
const filterDropdown = FilterDropdown({
|
// const filterDropdown = FilterDropdown({
|
||||||
initialCondition: {
|
// fields: resourceFields,
|
||||||
fieldKey: '',
|
// initialCondition: {
|
||||||
compatator: '',
|
// fieldKey: 'estimate_number',
|
||||||
value: '',
|
// compatator: 'contains',
|
||||||
},
|
// value: '',
|
||||||
fields: resourceFields,
|
// },
|
||||||
onFilterChange: (filterConditions) => {
|
// onFilterChange: (filterConditions) => {
|
||||||
addEstimatesTableQueries({
|
// setFilterCount(filterConditions.length || 0);
|
||||||
filter_roles: filterConditions || '',
|
// addEstimatesTableQueries({
|
||||||
});
|
// filter_roles: filterConditions || '',
|
||||||
onFilterChanged && onFilterChange(filterConditions);
|
// });
|
||||||
},
|
// onFilterChanged && onFilterChanged(filterConditions);
|
||||||
});
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
||||||
selectedRows,
|
selectedRows,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const viewsMenuItems = estimateViews.map((view) => {
|
||||||
|
return (
|
||||||
|
<MenuItem href={`${path}/${view.id}/custom_view`} text={view.name} />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
|
<Popover
|
||||||
|
content={<Menu>{viewsMenuItems}</Menu>}
|
||||||
|
minimal={true}
|
||||||
|
interactionKind={PopoverInteractionKind.HOVER}
|
||||||
|
position={Position.BOTTOM_LEFT}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
className={classNames(Classes.MINIMAL, 'button--table-views')}
|
||||||
|
icon={<Icon icon="table-16" iconSize={16} />}
|
||||||
|
text={<T id={'table_views'} />}
|
||||||
|
rightIcon={'caret-down'}
|
||||||
|
/>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
@@ -81,13 +104,19 @@ function EstimateActionsBar({
|
|||||||
/>
|
/>
|
||||||
<Popover
|
<Popover
|
||||||
minimal={true}
|
minimal={true}
|
||||||
content={filterDropdown}
|
// content={filterDropdown}
|
||||||
interactionKind={PopoverInteractionKind.CLICK}
|
interactionKind={PopoverInteractionKind.CLICK}
|
||||||
position={Position.BOTTOM_LEFT}
|
position={Position.BOTTOM_LEFT}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
className={classNames(Classes.MINIMAL, 'button--filter')}
|
className={classNames(Classes.MINIMAL, 'button--filter')}
|
||||||
text={'Filter'}
|
text={
|
||||||
|
filterCount <= 0 ? (
|
||||||
|
<T id={'filter'} />
|
||||||
|
) : (
|
||||||
|
`${filterCount} ${formatMessage({ id: 'filters_applied' })}`
|
||||||
|
)
|
||||||
|
}
|
||||||
icon={<Icon icon={'filter-16'} iconSize={16} />}
|
icon={<Icon icon={'filter-16'} iconSize={16} />}
|
||||||
/>
|
/>
|
||||||
</Popover>
|
</Popover>
|
||||||
@@ -122,7 +151,7 @@ function EstimateActionsBar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
resourceName: 'estimates',
|
resourceName: 'sales_estimates',
|
||||||
});
|
});
|
||||||
|
|
||||||
const withEstimateActionsBar = connect(mapStateToProps);
|
const withEstimateActionsBar = connect(mapStateToProps);
|
||||||
@@ -130,11 +159,11 @@ const withEstimateActionsBar = connect(mapStateToProps);
|
|||||||
export default compose(
|
export default compose(
|
||||||
withEstimateActionsBar,
|
withEstimateActionsBar,
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
|
withEstimates(({ estimateViews }) => ({
|
||||||
|
estimateViews,
|
||||||
|
})),
|
||||||
withResourceDetail(({ resourceFields }) => ({
|
withResourceDetail(({ resourceFields }) => ({
|
||||||
resourceFields,
|
resourceFields,
|
||||||
})),
|
})),
|
||||||
// withEstimate(({ estimateViews }) => ({
|
|
||||||
// estimateViews,
|
|
||||||
// })),
|
|
||||||
withEstimateActions,
|
withEstimateActions,
|
||||||
)(EstimateActionsBar);
|
)(EstimateActionsBar);
|
||||||
|
|||||||
@@ -11,20 +11,22 @@ import { useFormik } from 'formik';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Intent, FormGroup, TextArea, Button } from '@blueprintjs/core';
|
import { Intent, FormGroup, TextArea, Button } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { pick, omitBy, omit } from 'lodash';
|
import { pick, omit } from 'lodash';
|
||||||
|
import { queryCache } from 'react-query';
|
||||||
|
|
||||||
import EstimateFormHeader from './EstimateFormHeader';
|
import EstimateFormHeader from './EstimateFormHeader';
|
||||||
import EstimatesItemsTable from './EntriesItemsTable';
|
import EstimatesItemsTable from './EntriesItemsTable';
|
||||||
import EstimateFormFooter from './EstimateFormFooter';
|
import EstimateFormFooter from './EstimateFormFooter';
|
||||||
|
|
||||||
import withEstimateActions from './withEstimateActions';
|
import withEstimateActions from './withEstimateActions';
|
||||||
|
import withEstimateDetail from './withEstimateDetail';
|
||||||
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 AppToaster from 'components/AppToaster';
|
import AppToaster from 'components/AppToaster';
|
||||||
import Dragzone from 'components/Dragzone';
|
import Dragzone from 'components/Dragzone';
|
||||||
|
|
||||||
import useMedia from 'hooks/useMedia';
|
import useMedia from 'hooks/useMedia';
|
||||||
|
|
||||||
import { compose, repeatValue } from 'utils';
|
import { compose, repeatValue } from 'utils';
|
||||||
|
|
||||||
const MIN_LINES_NUMBER = 4;
|
const MIN_LINES_NUMBER = 4;
|
||||||
@@ -51,7 +53,7 @@ const EstimateForm = ({
|
|||||||
onCancelForm,
|
onCancelForm,
|
||||||
}) => {
|
}) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const [payload, setPaload] = useState({});
|
const [payload, setPayload] = useState({});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setFiles,
|
setFiles,
|
||||||
@@ -93,6 +95,7 @@ const EstimateForm = ({
|
|||||||
.label(formatMessage({ id: 'expiration_date_' })),
|
.label(formatMessage({ id: 'expiration_date_' })),
|
||||||
estimate_number: Yup.number()
|
estimate_number: Yup.number()
|
||||||
.required()
|
.required()
|
||||||
|
.nullable()
|
||||||
.label(formatMessage({ id: 'estimate_number_' })),
|
.label(formatMessage({ id: 'estimate_number_' })),
|
||||||
reference: Yup.string().min(1).max(255),
|
reference: Yup.string().min(1).max(255),
|
||||||
note: Yup.string()
|
note: Yup.string()
|
||||||
@@ -134,7 +137,7 @@ const EstimateForm = ({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
const saveInvokeSubmit = useCallback(
|
const saveEstimateSubmit = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
onFormSubmit && onFormSubmit(payload);
|
onFormSubmit && onFormSubmit(payload);
|
||||||
},
|
},
|
||||||
@@ -146,7 +149,7 @@ const EstimateForm = ({
|
|||||||
index: 0,
|
index: 0,
|
||||||
item_id: null,
|
item_id: null,
|
||||||
rate: null,
|
rate: null,
|
||||||
discount: null,
|
discount: 0,
|
||||||
quantity: null,
|
quantity: null,
|
||||||
description: '',
|
description: '',
|
||||||
}),
|
}),
|
||||||
@@ -155,10 +158,10 @@ const EstimateForm = ({
|
|||||||
|
|
||||||
const defaultInitialValues = useMemo(
|
const defaultInitialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
customer_id: null,
|
customer_id: '',
|
||||||
estimate_date: moment(new Date()).format('YYYY-MM-DD'),
|
estimate_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
expiration_date: moment(new Date()).format('YYYY-MM-DD'),
|
expiration_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
estimate_number: null,
|
estimate_number: '',
|
||||||
reference: '',
|
reference: '',
|
||||||
note: '',
|
note: '',
|
||||||
terms_conditions: '',
|
terms_conditions: '',
|
||||||
@@ -173,15 +176,38 @@ const EstimateForm = ({
|
|||||||
index: index + 1,
|
index: index + 1,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
// debugger;
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
...defaultInitialValues,
|
...(estimate
|
||||||
entries: orderingProductsIndex(defaultInitialValues.entries),
|
? {
|
||||||
|
...pick(estimate, Object.keys(defaultInitialValues)),
|
||||||
|
entries: [
|
||||||
|
...estimate.entries.map((estimate) => ({
|
||||||
|
...pick(estimate, Object.keys(defaultEstimate)),
|
||||||
|
})),
|
||||||
|
...repeatValue(
|
||||||
|
defaultEstimate,
|
||||||
|
Math.max(MIN_LINES_NUMBER - estimate.entries.length, 0),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
...defaultInitialValues,
|
||||||
|
entries: orderingProductsIndex(defaultInitialValues.entries),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
[defaultEstimate, defaultInitialValues, estimate],
|
[estimate, defaultInitialValues, defaultEstimate],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// const initialValues = useMemo(
|
||||||
|
// () => ({
|
||||||
|
// ...defaultInitialValues,
|
||||||
|
// entries: orderingProductsIndex(defaultInitialValues.entries),
|
||||||
|
// }),
|
||||||
|
// [defaultEstimate, defaultInitialValues, estimate],
|
||||||
|
// );
|
||||||
|
|
||||||
const initialAttachmentFiles = useMemo(() => {
|
const initialAttachmentFiles = useMemo(() => {
|
||||||
return estimate && estimate.media
|
return estimate && estimate.media
|
||||||
? estimate.media.map((attach) => ({
|
? estimate.media.map((attach) => ({
|
||||||
@@ -199,56 +225,58 @@ const EstimateForm = ({
|
|||||||
...initialValues,
|
...initialValues,
|
||||||
},
|
},
|
||||||
onSubmit: async (values, { setSubmitting, setErrors, resetForm }) => {
|
onSubmit: async (values, { setSubmitting, setErrors, resetForm }) => {
|
||||||
const entries = values.entries.map((item) => omit(item, ['total']));
|
const entries = values.entries.filter(
|
||||||
|
(item) => item.item_id && item.quantity,
|
||||||
|
);
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
entries,
|
entries,
|
||||||
};
|
};
|
||||||
const saveEstimate = (mediaIds) =>
|
const requestForm = { ...form };
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
const requestForm = { ...form, media_ids: mediaIds };
|
|
||||||
|
|
||||||
requestSubmitEstimate(requestForm)
|
if (estimate && estimate.id) {
|
||||||
.then((response) => {
|
requestEditEstimate(estimate.id, requestForm).then((response) => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage(
|
message: formatMessage({
|
||||||
{
|
id: 'the_estimate_has_been_successfully_edited',
|
||||||
id: 'the_estimate_has_been_successfully_created',
|
}),
|
||||||
},
|
intent: Intent.SUCCESS,
|
||||||
{
|
});
|
||||||
number: values.estimate_number,
|
setSubmitting(false);
|
||||||
},
|
saveEstimateSubmit({ action: 'update', ...payload });
|
||||||
),
|
resetForm();
|
||||||
intent: Intent.SUCCESS,
|
});
|
||||||
});
|
} else {
|
||||||
setSubmitting(false);
|
requestSubmitEstimate(requestForm)
|
||||||
resetForm();
|
.then((response) => {
|
||||||
saveInvokeSubmit({ action: 'new', ...payload });
|
AppToaster.show({
|
||||||
clearSavedMediaIds();
|
message: formatMessage(
|
||||||
})
|
{
|
||||||
.catch((errors) => {
|
id: 'the_estimate_has_been_successfully_created',
|
||||||
setSubmitting(false);
|
},
|
||||||
|
{
|
||||||
|
number: values.estimate_number,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
});
|
setSubmitting(false);
|
||||||
Promise.all([saveMedia(), deleteMedia()])
|
resetForm();
|
||||||
.then(([savedMediaResponses]) => {
|
saveEstimateSubmit({ action: 'new', ...payload });
|
||||||
const mediaIds = savedMediaResponses.map((res) => res.data.media.id);
|
})
|
||||||
savedMediaIds.current = mediaIds;
|
.catch((errors) => {
|
||||||
return savedMediaResponses;
|
setSubmitting(false);
|
||||||
})
|
});
|
||||||
.then(() => {
|
}
|
||||||
return saveEstimate(saveEstimate.current);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmitClick = useCallback(
|
const handleSubmitClick = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
setPaload(payload);
|
setPayload(payload);
|
||||||
formik.submitForm();
|
formik.submitForm();
|
||||||
},
|
},
|
||||||
[setPaload, formik],
|
[setPayload, formik],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCancelClick = useCallback(
|
const handleCancelClick = useCallback(
|
||||||
@@ -285,6 +313,9 @@ const EstimateForm = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<form onSubmit={formik.handleSubmit}>
|
<form onSubmit={formik.handleSubmit}>
|
||||||
@@ -294,6 +325,7 @@ const EstimateForm = ({
|
|||||||
onClickAddNewRow={handleClickAddNewRow}
|
onClickAddNewRow={handleClickAddNewRow}
|
||||||
onClickClearAllLines={handleClearAllLines}
|
onClickClearAllLines={handleClearAllLines}
|
||||||
formik={formik}
|
formik={formik}
|
||||||
|
// defaultRow={defaultEstimate}
|
||||||
/>
|
/>
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'customer_note'} />}
|
label={<T id={'customer_note'} />}
|
||||||
@@ -316,13 +348,14 @@ const EstimateForm = ({
|
|||||||
onDeleteFile={handleDeleteFile}
|
onDeleteFile={handleDeleteFile}
|
||||||
hint={'Attachments: Maxiumum size: 20MB'}
|
hint={'Attachments: Maxiumum size: 20MB'}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<EstimateFormFooter
|
|
||||||
formik={formik}
|
|
||||||
onSubmitClick={handleSubmitClick}
|
|
||||||
onCancelClick={handleCancelClick}
|
|
||||||
/>
|
|
||||||
</form>
|
</form>
|
||||||
|
<EstimateFormFooter
|
||||||
|
formik={formik}
|
||||||
|
onSubmitClick={handleSubmitClick}
|
||||||
|
estimate={estimate}
|
||||||
|
onCancelClick={handleCancelClick}
|
||||||
|
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -331,4 +364,5 @@ export default compose(
|
|||||||
withEstimateActions,
|
withEstimateActions,
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withMediaActions,
|
withMediaActions,
|
||||||
|
withEstimateDetail(),
|
||||||
)(EstimateForm);
|
)(EstimateForm);
|
||||||
|
|||||||
@@ -1,16 +1,26 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Intent, Button } from '@blueprintjs/core';
|
import { Intent, Button } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
import { queryCache } from 'react-query';
|
||||||
|
|
||||||
export default function EstimateFormFooter({
|
export default function EstimateFormFooter({
|
||||||
formik: { isSubmitting },
|
formik: { isSubmitting, resetForm },
|
||||||
onSubmitClick,
|
onSubmitClick,
|
||||||
onCancelClick,
|
onCancelClick,
|
||||||
|
onClearClick,
|
||||||
|
estimate,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className={'estimate-form__floating-footer'}>
|
<div className={'estimate-form__floating-footer'}>
|
||||||
<Button disabled={isSubmitting} intent={Intent.PRIMARY} type="submit">
|
<Button
|
||||||
<T id={'save_send'} />
|
disabled={isSubmitting}
|
||||||
|
intent={Intent.PRIMARY}
|
||||||
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onSubmitClick({ redirect: true });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{estimate && estimate.id ? <T id={'edit'} /> : <T id={'save_send'} />}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -19,11 +29,20 @@ export default function EstimateFormFooter({
|
|||||||
className={'ml1'}
|
className={'ml1'}
|
||||||
name={'save'}
|
name={'save'}
|
||||||
type="submit"
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onSubmitClick({ redirect: false });
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<T id={'save'} />
|
<T id={'save'} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button className={'ml1'} disabled={isSubmitting}>
|
<Button
|
||||||
|
className={'ml1'}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
// onClick={() => {
|
||||||
|
// onClearClick && onClearClick();
|
||||||
|
// }}
|
||||||
|
>
|
||||||
<T id={'clear'} />
|
<T id={'clear'} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useCallback, useMemo } from 'react';
|
import React, { useEffect, useCallback, useMemo, useState } from 'react';
|
||||||
import { Route, Switch, useHistory } from 'react-router-dom';
|
import { Route, Switch, useHistory } from 'react-router-dom';
|
||||||
import { useQuery, queryCache } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import { Alert, Intent } from '@blueprintjs/core';
|
import { Alert, Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
import AppToaster from 'components/AppToaster';
|
import AppToaster from 'components/AppToaster';
|
||||||
@@ -8,10 +8,15 @@ import { FormattedMessage as T, useIntl } from 'react-intl';
|
|||||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import EstimatesDataTable from './EstimatesDataTable';
|
||||||
import withEstimateActions from './withEstimateActions';
|
|
||||||
|
|
||||||
import EstimateActionsBar from './EstimateActionsBar';
|
import EstimateActionsBar from './EstimateActionsBar';
|
||||||
|
import EstimateViewTabs from './EstimateViewTabs';
|
||||||
|
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withResourceActions from 'containers/Resources/withResourcesActions';
|
||||||
|
import withEstimates from './withEstimates';
|
||||||
|
import withEstimateActions from './withEstimateActions';
|
||||||
|
import withViewsActions from 'containers/Views/withViewsActions';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
@@ -20,8 +25,12 @@ function EstimateList({
|
|||||||
changePageTitle,
|
changePageTitle,
|
||||||
|
|
||||||
// #withViewsActions
|
// #withViewsActions
|
||||||
|
requestFetchResourceViews,
|
||||||
|
requestFetchResourceFields,
|
||||||
|
|
||||||
// #withEstimate
|
// #withEstimate
|
||||||
|
estimateTableQuery,
|
||||||
|
estimateViews,
|
||||||
|
|
||||||
//#withEistimateActions
|
//#withEistimateActions
|
||||||
requestFetchEstimatesTable,
|
requestFetchEstimatesTable,
|
||||||
@@ -33,7 +42,17 @@ function EstimateList({
|
|||||||
const [deleteEstimate, setDeleteEstimate] = useState(false);
|
const [deleteEstimate, setDeleteEstimate] = useState(false);
|
||||||
const [selectedRows, setSelectedRows] = useState([]);
|
const [selectedRows, setSelectedRows] = useState([]);
|
||||||
|
|
||||||
const fetchEstimate = useQuery(['estimate-table'], () =>
|
const fetchResourceViews = useQuery(
|
||||||
|
['resource-views', 'sales_estimates'],
|
||||||
|
(key, resourceName) => requestFetchResourceViews(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchResourceFields = useQuery(
|
||||||
|
['resource-fields', 'sales_estimates'],
|
||||||
|
(key, resourceName) => requestFetchResourceFields(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchEstimate = useQuery(['estimates-table', estimateTableQuery], () =>
|
||||||
requestFetchEstimatesTable(),
|
requestFetchEstimatesTable(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -42,7 +61,6 @@ function EstimateList({
|
|||||||
}, [changePageTitle, formatMessage]);
|
}, [changePageTitle, formatMessage]);
|
||||||
|
|
||||||
// handle delete estimate click
|
// handle delete estimate click
|
||||||
|
|
||||||
const handleDeleteEstimate = useCallback(
|
const handleDeleteEstimate = useCallback(
|
||||||
(estimate) => {
|
(estimate) => {
|
||||||
setDeleteEstimate(estimate);
|
setDeleteEstimate(estimate);
|
||||||
@@ -57,7 +75,7 @@ function EstimateList({
|
|||||||
|
|
||||||
// handle confirm delete estimate
|
// handle confirm delete estimate
|
||||||
const handleConfirmEstimateDelete = useCallback(() => {
|
const handleConfirmEstimateDelete = useCallback(() => {
|
||||||
requestDeleteEstimate(deleteEstimate.id).then((response) => {
|
requestDeleteEstimate(deleteEstimate.id).then(() => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'the_estimate_has_been_successfully_deleted',
|
id: 'the_estimate_has_been_successfully_deleted',
|
||||||
@@ -68,12 +86,25 @@ function EstimateList({
|
|||||||
});
|
});
|
||||||
}, [deleteEstimate, requestDeleteEstimate, formatMessage]);
|
}, [deleteEstimate, requestDeleteEstimate, formatMessage]);
|
||||||
|
|
||||||
|
// // Handle filter change to re-fetch data-table.
|
||||||
|
// const handleFilterChanged = useCallback(
|
||||||
|
// (filterConditions) => {
|
||||||
|
// addEstimatesTableQueries({
|
||||||
|
// filter_roles: filterConditions || '',
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
// [fetchEstimate],
|
||||||
|
// );
|
||||||
|
|
||||||
|
// Handle filter change to re-fetch data-table.
|
||||||
|
const handleFilterChanged = useCallback(() => {}, [fetchEstimate]);
|
||||||
|
|
||||||
// Calculates the selected rows
|
// Calculates the selected rows
|
||||||
const selectedRowsCount = useMemo(() => Object.values(selectedRows).length, [
|
const selectedRowsCount = useMemo(() => Object.values(selectedRows).length, [
|
||||||
selectedRows,
|
selectedRows,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const handleEidtEstimate = useCallback(
|
const handleEditEstimate = useCallback(
|
||||||
(estimate) => {
|
(estimate) => {
|
||||||
history.push(`/estimates/${estimate.id}/edit`);
|
history.push(`/estimates/${estimate.id}/edit`);
|
||||||
},
|
},
|
||||||
@@ -97,24 +128,63 @@ function EstimateList({
|
|||||||
[addEstimatesTableQueries],
|
[addEstimatesTableQueries],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSelectedRowsChange = useCallback((estimate) => {
|
const handleSelectedRowsChange = useCallback(
|
||||||
selectedRows(estimate);
|
(estimate) => {
|
||||||
});
|
setSelectedRows(estimate);
|
||||||
|
},
|
||||||
|
[setSelectedRows],
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<DashboardInsider name={'estimates'}>
|
<DashboardInsider
|
||||||
|
loading={fetchResourceViews.isFetching || fetchResourceFields.isFetching}
|
||||||
|
name={'sales_estimates'}
|
||||||
|
>
|
||||||
<EstimateActionsBar
|
<EstimateActionsBar
|
||||||
// onBulkDelete={}
|
// onBulkDelete={}
|
||||||
selectedRows={selectedRows}
|
selectedRows={selectedRows}
|
||||||
// onFilterChanged={}
|
onFilterChanged={handleFilterChanged}
|
||||||
/>
|
/>
|
||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route></Route>
|
<Route
|
||||||
|
exact={true}
|
||||||
|
path={['/estimates/:custom_view_id/custom_view', '/estimates']}
|
||||||
|
>
|
||||||
|
<EstimateViewTabs />
|
||||||
|
<EstimatesDataTable
|
||||||
|
loading={fetchEstimate.isFetching}
|
||||||
|
onDeleteEstimate={handleDeleteEstimate}
|
||||||
|
onFetchData={handleFetchData}
|
||||||
|
onEditEstimate={handleEditEstimate}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
/>
|
||||||
|
</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'delete'} />}
|
||||||
|
icon={'trash'}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
isOpen={deleteEstimate}
|
||||||
|
onCancel={handleCancelEstimateDelete}
|
||||||
|
onConfirm={handleConfirmEstimateDelete}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<T id={'once_delete_this_estimate_you_will_able_to_restore_it'} />
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
</DashboardPageContent>
|
</DashboardPageContent>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default EstimateList;
|
export default compose(
|
||||||
|
withResourceActions,
|
||||||
|
withEstimateActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withViewsActions,
|
||||||
|
withEstimates(({ estimateTableQuery, estimateViews }) => ({
|
||||||
|
estimateTableQuery,
|
||||||
|
estimateViews,
|
||||||
|
})),
|
||||||
|
)(EstimateList);
|
||||||
|
|||||||
110
client/src/containers/Sales/Estimate/EstimateViewTabs.js
Normal file
110
client/src/containers/Sales/Estimate/EstimateViewTabs.js
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
import { useHistory } from 'react-router';
|
||||||
|
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||||
|
import { useParams, withRouter } from 'react-router-dom';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { pick, debounce } from 'lodash';
|
||||||
|
|
||||||
|
import { DashboardViewsTabs } from 'components';
|
||||||
|
import { useUpdateEffect } from 'hooks';
|
||||||
|
|
||||||
|
import withEstimates from './withEstimates';
|
||||||
|
import withEstimateActions from './withEstimateActions';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withViewDetails from 'containers/Views/withViewDetails';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function EstimateViewTabs({
|
||||||
|
// #withExpenses
|
||||||
|
estimateViews,
|
||||||
|
|
||||||
|
// #withViewDetails
|
||||||
|
viewItem,
|
||||||
|
|
||||||
|
//#withEstimatesActions
|
||||||
|
addEstimatesTableQueries,
|
||||||
|
changeEstimateView,
|
||||||
|
|
||||||
|
// #withDashboardActions
|
||||||
|
setTopbarEditView,
|
||||||
|
changePageSubtitle,
|
||||||
|
// props
|
||||||
|
customViewChanged,
|
||||||
|
onViewChanged,
|
||||||
|
}) {
|
||||||
|
const history = useHistory();
|
||||||
|
const { custom_view_id: customViewId = null } = useParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
changeEstimateView(customViewId || -1);
|
||||||
|
setTopbarEditView(customViewId);
|
||||||
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
|
|
||||||
|
addEstimatesTableQueries({
|
||||||
|
custom_view_id: customViewId,
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
setTopbarEditView(null);
|
||||||
|
changePageSubtitle('');
|
||||||
|
changeEstimateView(null);
|
||||||
|
};
|
||||||
|
}, [customViewId, addEstimatesTableQueries, changeEstimateView]);
|
||||||
|
|
||||||
|
useUpdateEffect(() => {
|
||||||
|
onViewChanged && onViewChanged(customViewId);
|
||||||
|
}, [customViewId]);
|
||||||
|
|
||||||
|
const debounceChangeHistory = useRef(
|
||||||
|
debounce((toUrl) => {
|
||||||
|
history.push(toUrl);
|
||||||
|
}, 250),
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTabsChange = (viewId) => {
|
||||||
|
const toPath = viewId ? `${viewId}/custom_view` : '';
|
||||||
|
debounceChangeHistory.current(`/estimates/${toPath}`);
|
||||||
|
setTopbarEditView(viewId);
|
||||||
|
};
|
||||||
|
const tabs = estimateViews.map((view) => ({
|
||||||
|
...pick(view, ['name', 'id']),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Handle click a new view tab.
|
||||||
|
const handleClickNewView = () => {
|
||||||
|
setTopbarEditView(null);
|
||||||
|
history.push('/custom_views/estimates/new');
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(estimateViews, 'estimateViews');
|
||||||
|
return (
|
||||||
|
<Navbar className={'navbar--dashboard-views'}>
|
||||||
|
<NavbarGroup align={Alignment.LEFT}>
|
||||||
|
<DashboardViewsTabs
|
||||||
|
initialViewId={customViewId}
|
||||||
|
baseUrl={'/estimates'}
|
||||||
|
tabs={tabs}
|
||||||
|
onNewViewTabClick={handleClickNewView}
|
||||||
|
onChange={handleTabsChange}
|
||||||
|
/>
|
||||||
|
</NavbarGroup>
|
||||||
|
</Navbar>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
|
viewId: ownProps.match.params.custom_view_id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const withEstimatesViewTabs = connect(mapStateToProps);
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withRouter,
|
||||||
|
withEstimatesViewTabs,
|
||||||
|
withEstimateActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withViewDetails(),
|
||||||
|
withEstimates(({ estimateViews }) => ({
|
||||||
|
estimateViews,
|
||||||
|
})),
|
||||||
|
)(EstimateViewTabs);
|
||||||
@@ -11,31 +11,50 @@ import withEstimateActions from './withEstimateActions';
|
|||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
function Estimates({ requestFetchCustomers, requestFetchItems }) {
|
function Estimates({
|
||||||
|
requestFetchCustomers,
|
||||||
|
requestFetchItems,
|
||||||
|
requsetFetchEstimate,
|
||||||
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
|
const fetchEstimate = useQuery(
|
||||||
|
['estimate', id],
|
||||||
|
(key, _id) => requsetFetchEstimate(_id),
|
||||||
|
{ enabled: !!id },
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle fetch Items data table or list
|
||||||
|
const fetchItems = useQuery('items-list', () => requestFetchItems({}));
|
||||||
|
|
||||||
// Handle fetch customers data table or list
|
// Handle fetch customers data table or list
|
||||||
const fetchCustomers = useQuery('customers-table', () =>
|
const fetchCustomers = useQuery('customers-table', () =>
|
||||||
requestFetchCustomers({}),
|
requestFetchCustomers({}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle fetch Items data table or list
|
const handleFormSubmit = useCallback(
|
||||||
const fetchItems = useQuery('items-table', () => requestFetchItems({}));
|
(payload) => {
|
||||||
|
payload.redirect && history.push('/estimates');
|
||||||
const handleFormSubmit = useCallback((payload) => {}, [history]);
|
},
|
||||||
|
[history],
|
||||||
|
);
|
||||||
const handleCancel = useCallback(() => {
|
const handleCancel = useCallback(() => {
|
||||||
history.goBack();
|
history.goBack();
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardInsider
|
<DashboardInsider
|
||||||
loading={fetchCustomers.isFetching || fetchItems.isFetching}
|
loading={
|
||||||
|
fetchCustomers.isFetching ||
|
||||||
|
fetchItems.isFetching ||
|
||||||
|
fetchEstimate.isFetching
|
||||||
|
}
|
||||||
|
name={'estimate-form'}
|
||||||
>
|
>
|
||||||
<EstimateForm
|
<EstimateForm
|
||||||
onFormSubmit={handleFormSubmit}
|
onFormSubmit={handleFormSubmit}
|
||||||
// estimateId={id}
|
estimateId={id}
|
||||||
onCancelForm={handleCancel}
|
onCancelForm={handleCancel}
|
||||||
/>
|
/>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
|
|||||||
@@ -2,36 +2,37 @@ import React, { useEffect, useCallback, useState, useMemo } from 'react';
|
|||||||
import {
|
import {
|
||||||
Intent,
|
Intent,
|
||||||
Button,
|
Button,
|
||||||
Classes,
|
|
||||||
Popover,
|
Popover,
|
||||||
Tooltip,
|
|
||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
MenuDivider,
|
MenuDivider,
|
||||||
Position,
|
Position,
|
||||||
Tag,
|
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { withRouter } from 'react-router';
|
import { withRouter } from 'react-router';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import Icon from 'components/Icon';
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
import { useUpdateEffect } from 'hooks';
|
import { useUpdateEffect } from 'hooks';
|
||||||
|
|
||||||
import LoadingIndicator from 'components/LoadingIndicator';
|
import LoadingIndicator from 'components/LoadingIndicator';
|
||||||
import { If } from 'components';
|
import { DataTable, Money, Icon } from 'components';
|
||||||
import DataTable from 'components/DataTable';
|
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
import withViewDetails from 'containers/Views/withViewDetails';
|
import withViewDetails from 'containers/Views/withViewDetails';
|
||||||
|
|
||||||
import withEstimates from './withEstimates';
|
import withEstimates from './withEstimates';
|
||||||
import withEstimateActions from './withEstimateActions';
|
import withEstimateActions from './withEstimateActions';
|
||||||
|
import withCurrentView from 'containers/Views/withCurrentView';
|
||||||
|
|
||||||
function EstimatesDataTable({
|
function EstimatesDataTable({
|
||||||
//#withEitimates
|
//#withEitimates
|
||||||
|
estimatesCurrentPage,
|
||||||
|
estimatesLoading,
|
||||||
|
estimatesPageination,
|
||||||
|
estimateItems,
|
||||||
|
|
||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changeCurrentView,
|
changeCurrentView,
|
||||||
@@ -56,11 +57,11 @@ function EstimatesDataTable({
|
|||||||
setInitialMount(false);
|
setInitialMount(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// useUpdateEffect(() => {
|
useUpdateEffect(() => {
|
||||||
// if (!estimateLoading) {
|
if (!estimatesLoading) {
|
||||||
// setInitialMount(true);
|
setInitialMount(true);
|
||||||
// }
|
}
|
||||||
// }, []);
|
}, [estimatesLoading, setInitialMount]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (customViewId) {
|
if (customViewId) {
|
||||||
@@ -77,66 +78,90 @@ function EstimatesDataTable({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const handleEditEstimate = useCallback(
|
const handleEditEstimate = useCallback(
|
||||||
(estimate) => {
|
(estimate) => () => {
|
||||||
onEditEstimate && onEditEstimate(estimate);
|
onEditEstimate && onEditEstimate(estimate);
|
||||||
},
|
},
|
||||||
[onEditEstimate],
|
[onEditEstimate],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDeleteEstimate = useCallback(() => {
|
const handleDeleteEstimate = useCallback(
|
||||||
onDeleteEstimate && onDeleteEstimate();
|
(estimate) => () => {
|
||||||
}, [onDeleteEstimate]);
|
onDeleteEstimate && onDeleteEstimate(estimate);
|
||||||
|
},
|
||||||
|
[onDeleteEstimate],
|
||||||
|
);
|
||||||
|
|
||||||
const actionMenuList = useCallback(
|
const actionMenuList = useCallback(
|
||||||
() => (
|
(estimate) => (
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuItem text={formatMessage({ id: 'view_details' })} />
|
<MenuItem text={formatMessage({ id: 'view_details' })} />
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={formatMessage({ id: 'edit_estimate' })}
|
text={formatMessage({ id: 'edit_estimate' })}
|
||||||
// onClick={handleEditEstimate(estimate)}
|
onClick={handleEditEstimate(estimate)}
|
||||||
/>
|
/>
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={formatMessage({ id: 'delete_estimate' })}
|
text={formatMessage({ id: 'delete_estimate' })}
|
||||||
intent={Intent.DANGER}
|
intent={Intent.DANGER}
|
||||||
// onClick={handleDeleteEstimate(estimate)}
|
onClick={handleDeleteEstimate(estimate)}
|
||||||
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
/>
|
/>
|
||||||
</Menu>
|
</Menu>
|
||||||
),
|
),
|
||||||
[handleDeleteEstimate, handleEditEstimate, formatMessage],
|
[handleDeleteEstimate, handleEditEstimate, formatMessage],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onRowContextMenu = useCallback(
|
||||||
|
(cell) => {
|
||||||
|
return actionMenuList(cell.row.original);
|
||||||
|
},
|
||||||
|
[actionMenuList],
|
||||||
|
);
|
||||||
|
|
||||||
const columns = useMemo(
|
const columns = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'estimate_date',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'estimate_date' }),
|
||||||
accessor: '',
|
accessor: (r) => moment(r.estimate_date).format('YYYY MMM DD'),
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'estimate_date',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'customer_id',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'customer_name' }),
|
||||||
accessor: '',
|
accessor: (row) => row.customer_id,
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'customer_id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'expiration_date',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'expiration_date' }),
|
||||||
accessor: '',
|
accessor: (r) => moment(r.expiration_date).format('YYYY MMM DD'),
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'expiration_date',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'estimate_number',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'estimate_number' }),
|
||||||
accessor: '',
|
accessor: (row) => `#${row.estimate_number}`,
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'estimate_number',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'amount',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'amount' }),
|
||||||
accessor: '',
|
accessor: (r) => <Money amount={r.amount} currency={'USD'} />,
|
||||||
className: '',
|
|
||||||
|
width: 140,
|
||||||
|
className: 'amount',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'reference',
|
||||||
|
Header: formatMessage({ id: 'reference_no' }),
|
||||||
|
accessor: 'reference',
|
||||||
|
width: 140,
|
||||||
|
className: 'reference',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
@@ -156,10 +181,18 @@ function EstimatesDataTable({
|
|||||||
],
|
],
|
||||||
[actionMenuList, formatMessage],
|
[actionMenuList, formatMessage],
|
||||||
);
|
);
|
||||||
|
const selectionColumn = useMemo(
|
||||||
|
() => ({
|
||||||
|
minWidth: 40,
|
||||||
|
width: 40,
|
||||||
|
maxWidth: 40,
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
const handleDataTableFetchData = useCallback(
|
const handleDataTableFetchData = useCallback(
|
||||||
(...arguments) => {
|
(...args) => {
|
||||||
onFetchData && onFetchData(...arguments);
|
onFetchData && onFetchData(...args);
|
||||||
},
|
},
|
||||||
[onFetchData],
|
[onFetchData],
|
||||||
);
|
);
|
||||||
@@ -171,15 +204,27 @@ function EstimatesDataTable({
|
|||||||
},
|
},
|
||||||
[onSelectedRowsChange],
|
[onSelectedRowsChange],
|
||||||
);
|
);
|
||||||
|
console.log(estimatesCurrentPage, 'estimatesCurrentPage');
|
||||||
|
console.log(estimateItems, 'estimateItems');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<LoadingIndicator loading={loading} mount={false}>
|
<LoadingIndicator loading={loading} mount={false}>
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={[]}
|
data={estimatesCurrentPage}
|
||||||
onFetchData={handleDataTableFetchData}
|
onFetchData={handleDataTableFetchData}
|
||||||
manualSortBy={true}
|
manualSortBy={true}
|
||||||
|
selectionColumn={true}
|
||||||
|
noInitialFetch={true}
|
||||||
|
sticky={true}
|
||||||
|
loading={estimatesLoading && !initialMount}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
rowContextMenu={onRowContextMenu}
|
||||||
|
pagination={true}
|
||||||
|
pagesCount={estimatesPageination.pagesCount}
|
||||||
|
initialPageSize={estimatesPageination.pageSize}
|
||||||
|
initialPageIndex={estimatesPageination.page - 1}
|
||||||
/>
|
/>
|
||||||
</LoadingIndicator>
|
</LoadingIndicator>
|
||||||
</div>
|
</div>
|
||||||
@@ -188,9 +233,22 @@ function EstimatesDataTable({
|
|||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withRouter,
|
withRouter,
|
||||||
|
withCurrentView,
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withEstimateActions,
|
withEstimateActions,
|
||||||
// withEstimates(({}) => ({})),
|
withEstimates(
|
||||||
|
({
|
||||||
|
estimatesCurrentPage,
|
||||||
|
estimatesLoading,
|
||||||
|
estimatesPageination,
|
||||||
|
estimateItems,
|
||||||
|
}) => ({
|
||||||
|
estimatesCurrentPage,
|
||||||
|
estimatesLoading,
|
||||||
|
estimatesPageination,
|
||||||
|
estimateItems,
|
||||||
|
}),
|
||||||
|
),
|
||||||
withViewDetails(),
|
withViewDetails(),
|
||||||
)(EstimatesDataTable);
|
)(EstimatesDataTable);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import t from 'store/types';
|
|||||||
const mapDipatchToProps = (dispatch) => ({
|
const mapDipatchToProps = (dispatch) => ({
|
||||||
requestSubmitEstimate: (form) => dispatch(submitEstimate({ form })),
|
requestSubmitEstimate: (form) => dispatch(submitEstimate({ form })),
|
||||||
requsetFetchEstimate: (id) => dispatch(fetchEstimate({ id })),
|
requsetFetchEstimate: (id) => dispatch(fetchEstimate({ id })),
|
||||||
requestEditEstimate: (id, form) => dispatch(editEstimate({ id, form })),
|
requestEditEstimate: (id, form) => dispatch(editEstimate(id, form)),
|
||||||
requestFetchEstimatesTable: (query = {}) =>
|
requestFetchEstimatesTable: (query = {}) =>
|
||||||
dispatch(fetchEstimatesTable({ query: { ...query } })),
|
dispatch(fetchEstimatesTable({ query: { ...query } })),
|
||||||
requestDeleteEstimate: (id) => dispatch(deleteEstimate({ id })),
|
requestDeleteEstimate: (id) => dispatch(deleteEstimate({ id })),
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { getResourceViews } from 'store/customViews/customViews.selectors';
|
import { getResourceViews } from 'store/customViews/customViews.selectors';
|
||||||
import {
|
import {
|
||||||
getEstimateCurrentPage,
|
getEstimateCurrentPageFactory,
|
||||||
getEstimatesTableQuery,
|
getEstimatesTableQuery,
|
||||||
getEstimatesPaginationMetaFactory,
|
getEstimatesPaginationMetaFactory,
|
||||||
} from 'store/Estimate/estimates.selectors';
|
} from 'store/Estimate/estimates.selectors';
|
||||||
|
|
||||||
function withEstimates(mapSate) {
|
export default (mapState) => {
|
||||||
|
const getEstimatesItems = getEstimateCurrentPageFactory();
|
||||||
|
const getEstimatesPaginationMeta = getEstimatesPaginationMetaFactory();
|
||||||
const mapStateToProps = (state, props) => {
|
const mapStateToProps = (state, props) => {
|
||||||
const query = getEstimatesTableQuery(state, props);
|
const query = getEstimatesTableQuery(state, props);
|
||||||
const mapped = {
|
const mapped = {
|
||||||
estimateViews: getResourceViews(state, props, 'estimates'),
|
estimatesCurrentPage: getEstimatesItems(state, props, query),
|
||||||
estimateItems: state.estiamte.items,
|
estimateViews: getResourceViews(state, props, 'sales_estimates'),
|
||||||
|
estimateItems: state.sales_estimates.items,
|
||||||
estimateTableQuery: query,
|
estimateTableQuery: query,
|
||||||
estimatesLoading: state.estiamte.loading,
|
estimatesPageination: getEstimatesPaginationMeta(state, props, query),
|
||||||
|
estimatesLoading: state.sales_estimates.loading,
|
||||||
};
|
};
|
||||||
return mapSate ? mapSate(mapped, state, props) : mapped;
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
};
|
};
|
||||||
|
|
||||||
return connect(mapStateToProps);
|
return connect(mapStateToProps);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default withEstimates;
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo, useCallback } from 'react';
|
import React, { useCallback, useState, useMemo } from 'react';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -15,49 +15,59 @@ import {
|
|||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useRouteMatch, useHistory } from 'react-router-dom';
|
import { useRouteMatch, useHistory } from 'react-router-dom';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import { If } from 'components';
|
import { connect } from 'react-redux';
|
||||||
import FilterDropdown from 'components/FilterDropdown';
|
import FilterDropdown from 'components/FilterDropdown';
|
||||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
|
|
||||||
|
import { If, DashboardActionViewsList } from 'components';
|
||||||
|
|
||||||
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withInvoiceActions from './withInvoices';
|
|
||||||
|
import withInvoiceActions from './withInvoiceActions';
|
||||||
|
import withInvoices from './withInvoices';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
function InvoiceActionsBar({
|
function InvoiceActionsBar({
|
||||||
// #withResourceDetail
|
// #withResourceDetail
|
||||||
resourceFields,
|
resourceFields,
|
||||||
|
|
||||||
//#withInvoice
|
//#withInvoice
|
||||||
InvoiceViews,
|
invoicesViews,
|
||||||
|
|
||||||
// #withInvoiceActions
|
// #withInvoiceActions
|
||||||
addInvoiceTableQueries,
|
addInvoiceTableQueries,
|
||||||
|
|
||||||
// #own Porps
|
// #own Porps
|
||||||
onFilterChanged,
|
onFilterChanged,
|
||||||
selectedRows,
|
selectedRows = [],
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { path } = useRouteMatch();
|
||||||
|
const [filterCount, setFilterCount] = useState(0);
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
const FilterDropdown = FilterDropdown({
|
const handleClickNewInvoice = useCallback(() => {
|
||||||
initialCondition: {
|
history.push('/invoices/new');
|
||||||
fieldKey: '',
|
}, [history]);
|
||||||
compatator: '',
|
|
||||||
value: '',
|
// const filterDropdown = FilterDropdown({
|
||||||
},
|
// initialCondition: {
|
||||||
fields: resourceFields,
|
// fieldKey: 'reference_no',
|
||||||
onFilterChange: (filterConditions) => {
|
// compatator: 'contains',
|
||||||
addInvoiceTableQueries({
|
// value: '',
|
||||||
filter_roles: filterConditions || '',
|
// },
|
||||||
});
|
// fields: resourceFields,
|
||||||
onFilterChanged && onFilterChanged(filterConditions);
|
// onFilterChange: (filterConditions) => {
|
||||||
},
|
// addInvoiceTableQueries({
|
||||||
});
|
// filter_roles: filterConditions || '',
|
||||||
|
// });
|
||||||
|
// onFilterChanged && onFilterChanged(filterConditions);
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
||||||
selectedRows,
|
selectedRows,
|
||||||
@@ -66,22 +76,32 @@ function InvoiceActionsBar({
|
|||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
|
<DashboardActionViewsList
|
||||||
|
resourceName={'sales_invoices'}
|
||||||
|
views={invoicesViews}
|
||||||
|
/>
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon={'plus'} />}
|
icon={<Icon icon={'plus'} />}
|
||||||
text={<T id={'new_invoice'} />}
|
text={<T id={'new_invoice'} />}
|
||||||
onClick={onClickNewInvoice}
|
onClick={handleClickNewInvoice}
|
||||||
/>
|
/>
|
||||||
<Popover
|
<Popover
|
||||||
minimal={true}
|
minimal={true}
|
||||||
content={FilterDropdown}
|
// content={filterDropdown}
|
||||||
interactionKind={PopoverInteractionKind.CLICK}
|
interactionKind={PopoverInteractionKind.CLICK}
|
||||||
position={Position.BOTTOM_LEFT}
|
position={Position.BOTTOM_LEFT}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
className={classNames(Classes.MINIMAL)}
|
className={classNames(Classes.MINIMAL)}
|
||||||
text={'Filter'}
|
text={
|
||||||
|
filterCount <= 0 ? (
|
||||||
|
<T id={'filter'} />
|
||||||
|
) : (
|
||||||
|
`${filterCount} ${formatMessage({ id: 'filters_applied' })}`
|
||||||
|
)
|
||||||
|
}
|
||||||
icon={<Icon icon={'filter-16'} iconSize={16} />}
|
icon={<Icon icon={'filter-16'} iconSize={16} />}
|
||||||
/>
|
/>
|
||||||
</Popover>
|
</Popover>
|
||||||
@@ -115,19 +135,17 @@ function InvoiceActionsBar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
resourceName: 'invoice',
|
resourceName: 'sales_invoices',
|
||||||
});
|
});
|
||||||
|
|
||||||
const withInvoiceActionsBar = connect(mapStateToProps);
|
const withInvoiceActionsBar = connect(mapStateToProps);
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withInvoiceActionsBar,
|
withInvoiceActionsBar,
|
||||||
withDialogActions,
|
|
||||||
withResourceDetail(({ resourceFields }) => ({
|
withResourceDetail(({ resourceFields }) => ({
|
||||||
resourceFields,
|
resourceFields,
|
||||||
})),
|
})),
|
||||||
// withInvoices(({ invoiceViews }) => ({
|
withInvoices(({ invoicesViews }) => ({
|
||||||
// invoiceViews,
|
invoicesViews,
|
||||||
// })),
|
})),
|
||||||
withInvoiceActions,
|
withInvoiceActions,
|
||||||
)(InvoiceActionsBar);
|
)(InvoiceActionsBar);
|
||||||
|
|||||||
@@ -10,15 +10,16 @@ import { useFormik } from 'formik';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Intent, FormGroup, TextArea, Button } from '@blueprintjs/core';
|
import { Intent, FormGroup, TextArea, Button } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { pick, omit } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
import InvoiceFormHeader from './InvoiceFormHeader';
|
import InvoiceFormHeader from './InvoiceFormHeader';
|
||||||
import EstimatesItemsTable from 'containers/Sales/Estimate/EntriesItemsTable';
|
import EstimatesItemsTable from 'containers/Sales/Estimate/EntriesItemsTable';
|
||||||
import InvoiceFormFooter from './InvoiceFormFooter';
|
import InvoiceFormFooter from './InvoiceFormFooter';
|
||||||
|
|
||||||
|
import withInvoiceActions from './withInvoiceActions';
|
||||||
|
import withInvoiceDetail from './withInvoiceDetail';
|
||||||
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 withInvoiceActions from './withInvoiceActions';
|
|
||||||
|
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
import Dragzone from 'components/Dragzone';
|
import Dragzone from 'components/Dragzone';
|
||||||
@@ -35,6 +36,7 @@ function InvoiceForm({
|
|||||||
|
|
||||||
//#WithInvoiceActions
|
//#WithInvoiceActions
|
||||||
requestSubmitInvoice,
|
requestSubmitInvoice,
|
||||||
|
requestEditInvoice,
|
||||||
|
|
||||||
//#withDashboard
|
//#withDashboard
|
||||||
changePageTitle,
|
changePageTitle,
|
||||||
@@ -44,12 +46,12 @@ function InvoiceForm({
|
|||||||
invoice,
|
invoice,
|
||||||
|
|
||||||
//#own Props
|
//#own Props
|
||||||
InvoiceId,
|
invoiceId,
|
||||||
onFormSubmit,
|
onFormSubmit,
|
||||||
onCancelForm,
|
onCancelForm,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const [payload, setPaload] = useState({});
|
const [payload, setPayload] = useState({});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setFiles,
|
setFiles,
|
||||||
@@ -70,7 +72,6 @@ function InvoiceForm({
|
|||||||
const clearSavedMediaIds = () => {
|
const clearSavedMediaIds = () => {
|
||||||
savedMediaIds.current = [];
|
savedMediaIds.current = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (invoice && invoice.id) {
|
if (invoice && invoice.id) {
|
||||||
changePageTitle(formatMessage({ id: 'edit_invoice' }));
|
changePageTitle(formatMessage({ id: 'edit_invoice' }));
|
||||||
@@ -115,7 +116,6 @@ function InvoiceForm({
|
|||||||
is: (quantity, rate) => quantity || rate,
|
is: (quantity, rate) => quantity || rate,
|
||||||
then: Yup.number().required(),
|
then: Yup.number().required(),
|
||||||
}),
|
}),
|
||||||
total: Yup.number().nullable(),
|
|
||||||
discount: Yup.number().nullable(),
|
discount: Yup.number().nullable(),
|
||||||
description: Yup.string().nullable(),
|
description: Yup.string().nullable(),
|
||||||
}),
|
}),
|
||||||
@@ -134,18 +134,19 @@ function InvoiceForm({
|
|||||||
index: 0,
|
index: 0,
|
||||||
item_id: null,
|
item_id: null,
|
||||||
rate: null,
|
rate: null,
|
||||||
discount: null,
|
discount: 0,
|
||||||
quantity: null,
|
quantity: null,
|
||||||
description: '',
|
description: '',
|
||||||
}),
|
}),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const defaultInitialValues = useMemo(
|
const defaultInitialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
customer_id: '',
|
customer_id: '',
|
||||||
invoice_date: moment(new Date()).format('YYYY-MM-DD'),
|
invoice_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
due_date: moment(new Date()).format('YYYY-MM-DD'),
|
due_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
status: 'status',
|
status: 'SEND',
|
||||||
invoice_no: '',
|
invoice_no: '',
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
invoice_message: '',
|
invoice_message: '',
|
||||||
@@ -161,15 +162,38 @@ function InvoiceForm({
|
|||||||
index: index + 1,
|
index: index + 1,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
// debugger;
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
...defaultInitialValues,
|
...(invoice
|
||||||
entries: orderingIndex(defaultInitialValues.entries),
|
? {
|
||||||
|
...pick(invoice, Object.keys(defaultInitialValues)),
|
||||||
|
entries: [
|
||||||
|
...invoice.entries.map((invoice) => ({
|
||||||
|
...pick(invoice, Object.keys(defaultInvoice)),
|
||||||
|
})),
|
||||||
|
...repeatValue(
|
||||||
|
defaultInvoice,
|
||||||
|
Math.max(MIN_LINES_NUMBER - invoice.entries.length, 0),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
...defaultInitialValues,
|
||||||
|
entries: orderingIndex(defaultInitialValues.entries),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
[defaultInvoice, defaultInitialValues, invoice],
|
[invoice, defaultInitialValues, defaultInvoice],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// const initialValues = useMemo(
|
||||||
|
// () => ({
|
||||||
|
// ...defaultInitialValues,
|
||||||
|
// entries: orderingIndex(defaultInitialValues.entries),
|
||||||
|
// }),
|
||||||
|
// [defaultInvoice, defaultInitialValues, invoice],
|
||||||
|
// );
|
||||||
|
|
||||||
const initialAttachmentFiles = useMemo(() => {
|
const initialAttachmentFiles = useMemo(() => {
|
||||||
return invoice && invoice.media
|
return invoice && invoice.media
|
||||||
? invoice.media.map((attach) => ({
|
? invoice.media.map((attach) => ({
|
||||||
@@ -188,52 +212,58 @@ function InvoiceForm({
|
|||||||
},
|
},
|
||||||
onSubmit: async (values, { setSubmitting, setErrors, resetForm }) => {
|
onSubmit: async (values, { setSubmitting, setErrors, resetForm }) => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
const entries = values.entries.map((item) => omit(item, ['total']));
|
|
||||||
|
|
||||||
|
const entries = values.entries.filter(
|
||||||
|
(item) => item.item_id && item.quantity,
|
||||||
|
);
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
entries,
|
entries,
|
||||||
};
|
};
|
||||||
const saveInvoice = (mediaIds) =>
|
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
const requestForm = { ...form, media_ids: mediaIds };
|
|
||||||
|
|
||||||
requestSubmitInvoice(requestForm)
|
const requestForm = { ...form };
|
||||||
.then((response) => {
|
if (invoice && invoice.id) {
|
||||||
AppToaster.show({
|
requestEditInvoice(invoice.id, requestForm)
|
||||||
message: formatMessage(
|
.then((response) => {
|
||||||
{ id: 'the_invocie_has_been_successfully_created' },
|
AppToaster.show({
|
||||||
{ number: values.invoice_no },
|
message: formatMessage({
|
||||||
),
|
id: 'the_invoice_has_been_successfully_edited',
|
||||||
intent: Intent.SUCCESS,
|
}),
|
||||||
});
|
intent: Intent.SUCCESS,
|
||||||
setSubmitting(false);
|
|
||||||
resetForm();
|
|
||||||
saveInvokeSubmit({ action: 'new', ...payload });
|
|
||||||
clearSavedMediaIds();
|
|
||||||
})
|
|
||||||
.catch((errors) => {
|
|
||||||
setSubmitting(false);
|
|
||||||
});
|
});
|
||||||
});
|
setSubmitting(false);
|
||||||
|
saveInvokeSubmit({ action: 'update', ...payload });
|
||||||
Promise.all([saveMedia(), deleteMedia()])
|
resetForm();
|
||||||
.then(([savedMediaResponses]) => {
|
})
|
||||||
const mediaIds = savedMediaResponses.map((res) => res.data.media.id);
|
.catch((error) => {
|
||||||
savedMediaIds.current = mediaIds;
|
setSubmitting(false);
|
||||||
return savedMediaResponses;
|
});
|
||||||
})
|
} else {
|
||||||
.then(() => {
|
requestSubmitInvoice(requestForm)
|
||||||
return saveInvoice(savedMediaIds.current);
|
.then((response) => {
|
||||||
});
|
AppToaster.show({
|
||||||
|
message: formatMessage(
|
||||||
|
{ id: 'the_invocie_has_been_successfully_created' },
|
||||||
|
{ number: values.invoice_no },
|
||||||
|
),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
setSubmitting(false);
|
||||||
|
saveInvokeSubmit({ action: 'new', ...payload });
|
||||||
|
resetForm();
|
||||||
|
})
|
||||||
|
.catch((errors) => {
|
||||||
|
setSubmitting(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const handleSubmitClick = useCallback(
|
const handleSubmitClick = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
setPaload(payload);
|
setPayload(payload);
|
||||||
formik.submitForm();
|
formik.submitForm();
|
||||||
},
|
},
|
||||||
[setPaload, formik],
|
[setPayload, formik],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCancelClick = useCallback(
|
const handleCancelClick = useCallback(
|
||||||
@@ -243,7 +273,6 @@ function InvoiceForm({
|
|||||||
[onCancelForm],
|
[onCancelForm],
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(formik.errors, 'Errors');
|
|
||||||
const handleDeleteFile = useCallback(
|
const handleDeleteFile = useCallback(
|
||||||
(_deletedFiles) => {
|
(_deletedFiles) => {
|
||||||
_deletedFiles.forEach((deletedFile) => {
|
_deletedFiles.forEach((deletedFile) => {
|
||||||
@@ -303,13 +332,13 @@ function InvoiceForm({
|
|||||||
onDeleteFile={handleDeleteFile}
|
onDeleteFile={handleDeleteFile}
|
||||||
hint={'Attachments: Maxiumum size: 20MB'}
|
hint={'Attachments: Maxiumum size: 20MB'}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<InvoiceFormFooter
|
|
||||||
formik={formik}
|
|
||||||
onSubmitClick={handleSubmitClick}
|
|
||||||
onCancelClick={handleCancelClick}
|
|
||||||
/>
|
|
||||||
</form>
|
</form>
|
||||||
|
<InvoiceFormFooter
|
||||||
|
formik={formik}
|
||||||
|
onSubmitClick={handleSubmitClick}
|
||||||
|
invoice={invoice}
|
||||||
|
onCancelClick={handleCancelClick}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -318,4 +347,5 @@ export default compose(
|
|||||||
withInvoiceActions,
|
withInvoiceActions,
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withMediaActions,
|
withMediaActions,
|
||||||
|
withInvoiceDetail(),
|
||||||
)(InvoiceForm);
|
)(InvoiceForm);
|
||||||
|
|||||||
@@ -6,11 +6,19 @@ export default function EstimateFormFooter({
|
|||||||
formik: { isSubmitting },
|
formik: { isSubmitting },
|
||||||
onSubmitClick,
|
onSubmitClick,
|
||||||
onCancelClick,
|
onCancelClick,
|
||||||
|
invoice,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className={'estimate-form__floating-footer'}>
|
<div className={'estimate-form__floating-footer'}>
|
||||||
<Button disabled={isSubmitting} intent={Intent.PRIMARY} type="submit">
|
<Button
|
||||||
<T id={'save_send'} />
|
disabled={isSubmitting}
|
||||||
|
intent={Intent.PRIMARY}
|
||||||
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onSubmitClick({ redirect: true });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{invoice && invoice.id ? <T id={'edit'} /> : <T id={'save_send'} />}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -19,6 +27,9 @@ export default function EstimateFormFooter({
|
|||||||
className={'ml1'}
|
className={'ml1'}
|
||||||
name={'save'}
|
name={'save'}
|
||||||
type="submit"
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onSubmitClick({ redirect: false });
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<T id={'save'} />
|
<T id={'save'} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -8,23 +8,34 @@ import { FormattedMessage as T, useIntl } from 'react-intl';
|
|||||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import InvoicesDataTable from './InvoicesDataTable';
|
||||||
// import withInvoiceActions from './withInvoiceActions'
|
import InvoiceActionsBar from './InvoiceActionsBar';
|
||||||
|
import InvoiceViewTabs from './InvoiceViewTabs';
|
||||||
|
|
||||||
// import InvoiceActionsBar from './InvoiceActionsBar';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withResourceActions from 'containers/Resources/withResourcesActions';
|
||||||
|
import withInvoices from './withInvoices';
|
||||||
|
import withInvoiceActions from './withInvoiceActions';
|
||||||
|
import withViewsActions from 'containers/Views/withViewsActions';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
import InvoiceActionsBar from './InvoiceActionsBar';
|
|
||||||
|
|
||||||
function InvoiceList({
|
function InvoiceList({
|
||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changePageTitle,
|
changePageTitle,
|
||||||
|
|
||||||
// #withViewsActions
|
// #withViewsActions
|
||||||
|
requestFetchResourceViews,
|
||||||
|
requestFetchResourceFields,
|
||||||
|
|
||||||
//#withInvoice
|
//#withInvoice
|
||||||
|
invoicesTableQuery,
|
||||||
|
invoicesViews,
|
||||||
|
|
||||||
//#withInvoiceActions
|
//#withInvoiceActions
|
||||||
|
requestFetchInvoiceTable,
|
||||||
|
requestDeleteInvoice,
|
||||||
|
addInvoiceTableQueries,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
@@ -35,6 +46,19 @@ function InvoiceList({
|
|||||||
changePageTitle(formatMessage({ id: 'invoice_list' }));
|
changePageTitle(formatMessage({ id: 'invoice_list' }));
|
||||||
}, [changePageTitle, formatMessage]);
|
}, [changePageTitle, formatMessage]);
|
||||||
|
|
||||||
|
const fetchResourceViews = useQuery(
|
||||||
|
['resource-views', 'sales_invoices'],
|
||||||
|
(key, resourceName) => requestFetchResourceViews(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchResourceFields = useQuery(
|
||||||
|
['resource-fields', 'sales_invoices'],
|
||||||
|
(key, resourceName) => requestFetchResourceFields(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchInvoices = useQuery(['invoices-table', invoicesTableQuery], () =>
|
||||||
|
requestFetchInvoiceTable(),
|
||||||
|
);
|
||||||
//handle dalete Invoice
|
//handle dalete Invoice
|
||||||
const handleDeleteInvoice = useCallback(
|
const handleDeleteInvoice = useCallback(
|
||||||
(invoice) => {
|
(invoice) => {
|
||||||
@@ -59,15 +83,16 @@ function InvoiceList({
|
|||||||
});
|
});
|
||||||
setDeleteInvoice(false);
|
setDeleteInvoice(false);
|
||||||
});
|
});
|
||||||
}, [setDeleteInvoice, requestDeleteInvoice]);
|
}, [deleteInvoice, requestDeleteInvoice, formatMessage]);
|
||||||
|
|
||||||
const handleEditInvoice = useCallback((invoice) => {
|
const handleEditInvoice = useCallback((invoice) => {
|
||||||
history.push(`/invoices/${invoice.id}/edit`);
|
history.push(`/invoices/${invoice.id}/edit`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const fetchInvoice = useQuery(['invoice-table'], () =>
|
// Calculates the selected rows count.
|
||||||
requsetFetchInvoiceTable(),
|
const selectedRowsCount = useMemo(() => Object.values(selectedRows).length, [
|
||||||
);
|
selectedRows,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleFetchData = useCallback(
|
const handleFetchData = useCallback(
|
||||||
({ pageIndex, pageSize, sortBy }) => {
|
({ pageIndex, pageSize, sortBy }) => {
|
||||||
@@ -86,24 +111,67 @@ function InvoiceList({
|
|||||||
},
|
},
|
||||||
[addInvoiceTableQueries],
|
[addInvoiceTableQueries],
|
||||||
);
|
);
|
||||||
const handleSelectedRowsChange = useCallback((_invoice) => {
|
|
||||||
selectedRows(_invoice);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// Handle filter change to re-fetch data-table.
|
||||||
|
const handleFilterChanged = useCallback(() => {}, [fetchInvoices]);
|
||||||
|
|
||||||
|
// Handle selected rows change.
|
||||||
|
const handleSelectedRowsChange = useCallback(
|
||||||
|
(_invoices) => {
|
||||||
|
setSelectedRows(_invoices);
|
||||||
|
},
|
||||||
|
[setSelectedRows],
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<DashboardInsider name={'invoices'}>
|
<DashboardInsider
|
||||||
|
loading={fetchResourceViews.isFetching || fetchResourceFields.isFetching}
|
||||||
|
name={'sales_invoices'}
|
||||||
|
>
|
||||||
<InvoiceActionsBar
|
<InvoiceActionsBar
|
||||||
// onBulkDelete={}
|
// onBulkDelete={}
|
||||||
selectedRows={selectedRows}
|
selectedRows={selectedRows}
|
||||||
// onFilterChanged={}
|
onFilterChanged={handleFilterChanged}
|
||||||
/>
|
/>
|
||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route></Route>
|
<Route
|
||||||
|
exact={true}
|
||||||
|
path={['/invoices/:custom_view_id/custom_view', '/invoices']}
|
||||||
|
>
|
||||||
|
<InvoiceViewTabs />
|
||||||
|
<InvoicesDataTable
|
||||||
|
loading={fetchInvoices.isFetching}
|
||||||
|
onDeleteInvoice={handleDeleteInvoice}
|
||||||
|
onFetchData={handleFetchData}
|
||||||
|
onEditInvoice={handleEditInvoice}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
/>
|
||||||
|
</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'delete'} />}
|
||||||
|
icon={'trash'}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
isOpen={deleteInvoice}
|
||||||
|
onCancel={handleCancelInvoiceDelete}
|
||||||
|
onConfirm={handleConfirmInvoiceDelete}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<T id={'once_delete_this_invoice_you_will_able_to_restore_it'} />
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
</DashboardPageContent>
|
</DashboardPageContent>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default InvoiceList;
|
export default compose(
|
||||||
|
withResourceActions,
|
||||||
|
withInvoiceActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withViewsActions,
|
||||||
|
withInvoices(({ invoicesTableQuery }) => ({
|
||||||
|
invoicesTableQuery,
|
||||||
|
})),
|
||||||
|
)(InvoiceList);
|
||||||
|
|||||||
113
client/src/containers/Sales/Invoice/InvoiceViewTabs.js
Normal file
113
client/src/containers/Sales/Invoice/InvoiceViewTabs.js
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
import { useHistory } from 'react-router';
|
||||||
|
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||||
|
import { useParams, withRouter } from 'react-router-dom';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { pick, debounce } from 'lodash';
|
||||||
|
|
||||||
|
import { DashboardViewsTabs } from 'components';
|
||||||
|
import { useUpdateEffect } from 'hooks';
|
||||||
|
|
||||||
|
import withInvoices from './withInvoices';
|
||||||
|
import withInvoiceActions from './withInvoiceActions';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withViewDetails from 'containers/Views/withViewDetails';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function InvoiceViewTabs({
|
||||||
|
//#withInvoices
|
||||||
|
invoicesViews,
|
||||||
|
|
||||||
|
// #withViewDetails
|
||||||
|
viewItem,
|
||||||
|
|
||||||
|
//#withInvoiceActions
|
||||||
|
changeInvoiceView,
|
||||||
|
addInvoiceTableQueries,
|
||||||
|
|
||||||
|
// #withDashboardActions
|
||||||
|
setTopbarEditView,
|
||||||
|
changePageSubtitle,
|
||||||
|
|
||||||
|
// #ownProps
|
||||||
|
customViewChanged,
|
||||||
|
onViewChanged,
|
||||||
|
}) {
|
||||||
|
const history = useHistory();
|
||||||
|
const { custom_view_id: customViewId = null } = useParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
changeInvoiceView(customViewId || -1);
|
||||||
|
setTopbarEditView(customViewId);
|
||||||
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
|
|
||||||
|
addInvoiceTableQueries({
|
||||||
|
custom_view_id: customViewId,
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
setTopbarEditView(null);
|
||||||
|
changePageSubtitle('');
|
||||||
|
changeInvoiceView(null);
|
||||||
|
};
|
||||||
|
}, [customViewId, addInvoiceTableQueries, changeInvoiceView]);
|
||||||
|
|
||||||
|
useUpdateEffect(() => {
|
||||||
|
onViewChanged && onViewChanged(customViewId);
|
||||||
|
}, [customViewId]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const debounceChangeHistory = useRef(
|
||||||
|
debounce((toUrl) => {
|
||||||
|
history.push(toUrl);
|
||||||
|
}, 250),
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTabsChange = (viewId) => {
|
||||||
|
const toPath = viewId ? `${viewId}/custom_view` : '';
|
||||||
|
debounceChangeHistory.current(`/invoices/${toPath}`);
|
||||||
|
setTopbarEditView(viewId);
|
||||||
|
};
|
||||||
|
const tabs = invoicesViews.map((view) => ({
|
||||||
|
...pick(view, ['name', 'id']),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Handle click a new view tab.
|
||||||
|
const handleClickNewView = () => {
|
||||||
|
setTopbarEditView(null);
|
||||||
|
history.push('/custom_views/invoices/new');
|
||||||
|
};
|
||||||
|
console.log(invoicesViews, 'invoicesViews');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Navbar className={'navbar--dashboard-views'}>
|
||||||
|
<NavbarGroup align={Alignment.LEFT}>
|
||||||
|
<DashboardViewsTabs
|
||||||
|
initialViewId={customViewId}
|
||||||
|
baseUrl={'/invoices'}
|
||||||
|
tabs={tabs}
|
||||||
|
onNewViewTabClick={handleClickNewView}
|
||||||
|
onChange={handleTabsChange}
|
||||||
|
/>
|
||||||
|
</NavbarGroup>
|
||||||
|
</Navbar>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
|
viewId: ownProps.match.params.custom_view_id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const withInvoicesViewTabs = connect(mapStateToProps);
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withRouter,
|
||||||
|
withInvoicesViewTabs,
|
||||||
|
withInvoiceActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withViewDetails(),
|
||||||
|
withInvoices(({ invoicesViews }) => ({
|
||||||
|
invoicesViews,
|
||||||
|
})),
|
||||||
|
)(InvoiceViewTabs);
|
||||||
@@ -11,31 +11,50 @@ import withInvoiceActions from './withInvoiceActions';
|
|||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
function Invoices({ requestFetchCustomers, requestFetchItems }) {
|
function Invoices({
|
||||||
|
requestFetchCustomers,
|
||||||
|
requestFetchItems,
|
||||||
|
requsetFetchInvoice,
|
||||||
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
// Handle fetch Items data table or list
|
// Handle fetch Items data table or list
|
||||||
const fetchItems = useQuery('items-table', () => requestFetchItems({}));
|
const fetchItems = useQuery('items-table', () => requestFetchItems({}));
|
||||||
|
|
||||||
const handleFormSubmit = useCallback((payload) => {}, [history]);
|
const handleFormSubmit = useCallback(
|
||||||
|
(payload) => {
|
||||||
|
payload.redirect && history.push('/invoices');
|
||||||
|
},
|
||||||
|
[history],
|
||||||
|
);
|
||||||
// Handle fetch customers data table or list
|
// Handle fetch customers data table or list
|
||||||
const fetchCustomers = useQuery('customers-table', () =>
|
const fetchCustomers = useQuery('customers-table', () =>
|
||||||
requestFetchCustomers({}),
|
requestFetchCustomers({}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const fetchInvoice = useQuery(
|
||||||
|
['invoice', id],
|
||||||
|
(key, _id) => requsetFetchInvoice(_id),
|
||||||
|
{ enabled: !!id },
|
||||||
|
);
|
||||||
|
|
||||||
const handleCancel = useCallback(() => {
|
const handleCancel = useCallback(() => {
|
||||||
history.goBack();
|
history.goBack();
|
||||||
}, [history]);
|
}, [history]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardInsider
|
<DashboardInsider
|
||||||
loading={fetchCustomers.isFetching || fetchItems.isFetching}
|
loading={
|
||||||
|
fetchCustomers.isFetching ||
|
||||||
|
fetchItems.isFetching ||
|
||||||
|
fetchInvoice.isFetching
|
||||||
|
}
|
||||||
|
name={'invoice-form'}
|
||||||
>
|
>
|
||||||
<InvoiceForm
|
<InvoiceForm
|
||||||
onFormSubmit={handleFormSubmit}
|
onFormSubmit={handleFormSubmit}
|
||||||
// InvoiceId={id}
|
invoiceId={id}
|
||||||
onCancelForm={handleCancel}
|
onCancelForm={handleCancel}
|
||||||
/>
|
/>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
|
|||||||
@@ -4,35 +4,36 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Classes,
|
Classes,
|
||||||
Popover,
|
Popover,
|
||||||
Tooltip,
|
|
||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
MenuDivider,
|
MenuDivider,
|
||||||
Position,
|
Position,
|
||||||
Tag,
|
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { withRouter } from 'react-router';
|
import { withRouter } from 'react-router';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import Icon from 'components/Icon';
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
import { useUpdateEffect } from 'hooks';
|
import { useUpdateEffect } from 'hooks';
|
||||||
|
|
||||||
import LoadingIndicator from 'components/LoadingIndicator';
|
import LoadingIndicator from 'components/LoadingIndicator';
|
||||||
import { If } from 'components';
|
import { DataTable, Money, Icon } from 'components';
|
||||||
import DataTable from 'components/DataTable';
|
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
import withViewDetails from 'containers/Views/withViewDetails';
|
import withViewDetails from 'containers/Views/withViewDetails';
|
||||||
|
|
||||||
import witInvoice from './withInvoice';
|
import withInvoices from './withInvoices';
|
||||||
import withInvoiceActions from './withInvoiceActions';
|
import withInvoiceActions from './withInvoiceActions';
|
||||||
|
import withCurrentView from 'containers/Views/withCurrentView';
|
||||||
|
|
||||||
function InvoicesDataTable({
|
function InvoicesDataTable({
|
||||||
//#withInvoices
|
//#withInvoices
|
||||||
|
invoicesCurrentPage,
|
||||||
|
invoicesLoading,
|
||||||
|
invoicesPageination,
|
||||||
|
invoicesItems,
|
||||||
|
|
||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changeCurrentView,
|
changeCurrentView,
|
||||||
@@ -45,8 +46,8 @@ function InvoicesDataTable({
|
|||||||
//#OwnProps
|
//#OwnProps
|
||||||
loading,
|
loading,
|
||||||
onFetchData,
|
onFetchData,
|
||||||
onEditEstimate,
|
onEditInvoice,
|
||||||
onDeleteEstimate,
|
onDeleteInvoice,
|
||||||
onSelectedRowsChange,
|
onSelectedRowsChange,
|
||||||
}) {
|
}) {
|
||||||
const [initialMount, setInitialMount] = useState(false);
|
const [initialMount, setInitialMount] = useState(false);
|
||||||
@@ -55,79 +56,120 @@ function InvoicesDataTable({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInitialMount(false);
|
setInitialMount(false);
|
||||||
}, []);
|
}, [customViewId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useUpdateEffect(() => {
|
||||||
if (customViewId) {
|
if (!invoicesLoading) {
|
||||||
changeCurrentView(customViewId);
|
setInitialMount(true);
|
||||||
setTopbarEditView(customViewId);
|
|
||||||
}
|
}
|
||||||
changePageSubtitle(customViewId && viewMeta ? viewMeta.name : '');
|
}, [invoicesLoading, setInitialMount]);
|
||||||
}, [
|
|
||||||
customViewId,
|
// useEffect(() => {
|
||||||
changeCurrentView,
|
// if (customViewId) {
|
||||||
changePageSubtitle,
|
// changeCurrentView(customViewId);
|
||||||
setTopbarEditView,
|
// setTopbarEditView(customViewId);
|
||||||
viewMeta,
|
// }
|
||||||
]);
|
// changePageSubtitle(customViewId && viewMeta ? viewMeta.name : '');
|
||||||
|
// }, [
|
||||||
|
// customViewId,
|
||||||
|
// changeCurrentView,
|
||||||
|
// changePageSubtitle,
|
||||||
|
// setTopbarEditView,
|
||||||
|
// viewMeta,
|
||||||
|
// ]);
|
||||||
|
|
||||||
const handleEditInvoice = useCallback(
|
const handleEditInvoice = useCallback(
|
||||||
(_invoice) => {
|
(_invoice) => () => {
|
||||||
onEditInvoice && onEditInvoice(_invoice);
|
onEditInvoice && onEditInvoice(_invoice);
|
||||||
},
|
},
|
||||||
[onEditInvoice],
|
[onEditInvoice],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDeleteInvoice = useCallback(() => {
|
const handleDeleteInvoice = useCallback(
|
||||||
onDeleteInvoice && onDeleteInvoice();
|
(_invoice) => () => {
|
||||||
}, [onDeleteInvoice]);
|
onDeleteInvoice && onDeleteInvoice(_invoice);
|
||||||
|
},
|
||||||
|
[onDeleteInvoice],
|
||||||
|
);
|
||||||
|
|
||||||
const actionsMenuList = useCallback(
|
const actionMenuList = useCallback(
|
||||||
(invoice) => {
|
(invoice) => (
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuItem text={formatMessage({ id: 'view_details' })} />
|
<MenuItem text={formatMessage({ id: 'view_details' })} />
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
|
|
||||||
<MenuItem
|
<MenuItem
|
||||||
text={formatMessage({ id: 'edit_invoice' })}
|
text={formatMessage({ id: 'edit_invoice' })}
|
||||||
// onClick={handleEditInvoice(invoice)}
|
onClick={handleEditInvoice(invoice)}
|
||||||
/>
|
/>
|
||||||
</Menu>;
|
<MenuItem
|
||||||
},
|
text={formatMessage({ id: 'delete_invoice' })}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
onClick={handleDeleteInvoice(invoice)}
|
||||||
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
|
/>
|
||||||
|
</Menu>
|
||||||
|
),
|
||||||
[handleDeleteInvoice, handleEditInvoice, formatMessage],
|
[handleDeleteInvoice, handleEditInvoice, formatMessage],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onRowContextMenu = useCallback(
|
||||||
|
(cell) => {
|
||||||
|
return actionMenuList(cell.row.original);
|
||||||
|
},
|
||||||
|
[actionMenuList],
|
||||||
|
);
|
||||||
|
|
||||||
const columns = useMemo(
|
const columns = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'invoice_date',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'invoice_date' }),
|
||||||
accessor: '',
|
accessor: (r) => moment(r.invoice_date).format('YYYY MMM DD'),
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'invoice_date',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'customer_id',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'customer_name' }),
|
||||||
accessor: '',
|
accessor: (row) => row.customer_id,
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'customer_id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'invoice_no',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'invoice_no__' }),
|
||||||
accessor: '',
|
accessor: (row) => `#${row.invoice_no}`,
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'invoice_no',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: 'due_date',
|
||||||
|
Header: formatMessage({ id: 'due_date' }),
|
||||||
|
accessor: (r) => moment(r.due_date).format('YYYY MMM DD'),
|
||||||
|
width: 140,
|
||||||
|
className: 'due_date',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'balance',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'balance' }),
|
||||||
accessor: '',
|
accessor: (r) => <Money amount={r.balance} currency={'USD'} />,
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'balance',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '',
|
id: 'reference_no',
|
||||||
Header: formatMessage({ id: '' }),
|
Header: formatMessage({ id: 'reference_no' }),
|
||||||
accessor: '',
|
accessor: 'reference_no',
|
||||||
className: '',
|
width: 140,
|
||||||
|
className: 'reference_no',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'status',
|
||||||
|
Header: formatMessage({ id: 'status' }),
|
||||||
|
accessor: 'status',
|
||||||
|
width: 140,
|
||||||
|
className: 'status',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
@@ -149,12 +191,11 @@ function InvoicesDataTable({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const handleDataTableFetchData = useCallback(
|
const handleDataTableFetchData = useCallback(
|
||||||
(...arguments) => {
|
(...args) => {
|
||||||
onFetchData && onFetchData(...arguments);
|
onFetchData && onFetchData(...args);
|
||||||
},
|
},
|
||||||
[onFetchData],
|
[onFetchData],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSelectedRowsChange = useCallback(
|
const handleSelectedRowsChange = useCallback(
|
||||||
(selectedRows) => {
|
(selectedRows) => {
|
||||||
onSelectedRowsChange &&
|
onSelectedRowsChange &&
|
||||||
@@ -163,14 +204,33 @@ function InvoicesDataTable({
|
|||||||
[onSelectedRowsChange],
|
[onSelectedRowsChange],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const selectionColumn = useMemo(
|
||||||
|
() => ({
|
||||||
|
minWidth: 40,
|
||||||
|
width: 40,
|
||||||
|
maxWidth: 40,
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<LoadingIndicator>
|
<LoadingIndicator loading={loading} mount={false}>
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={[]}
|
data={invoicesCurrentPage}
|
||||||
onFetchData={handleDataTableFetchData}
|
onFetchData={handleDataTableFetchData}
|
||||||
manualSortBy={true}
|
manualSortBy={true}
|
||||||
|
selectionColumn={true}
|
||||||
|
noInitialFetch={true}
|
||||||
|
sticky={true}
|
||||||
|
loading={invoicesLoading && !initialMount}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
rowContextMenu={onRowContextMenu}
|
||||||
|
pagination={true}
|
||||||
|
pagesCount={invoicesPageination.pagesCount}
|
||||||
|
initialPageSize={invoicesPageination.pageSize}
|
||||||
|
initialPageIndex={invoicesPageination.page - 1}
|
||||||
/>
|
/>
|
||||||
</LoadingIndicator>
|
</LoadingIndicator>
|
||||||
</div>
|
</div>
|
||||||
@@ -179,11 +239,16 @@ function InvoicesDataTable({
|
|||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withRouter,
|
withRouter,
|
||||||
|
withCurrentView,
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withInvoiceActions,
|
withInvoiceActions,
|
||||||
// withInvoices(({})=>({
|
withInvoices(
|
||||||
|
({ invoicesCurrentPage, invoicesLoading, invoicesPageination }) => ({
|
||||||
// }))
|
invoicesCurrentPage,
|
||||||
|
invoicesLoading,
|
||||||
|
invoicesPageination,
|
||||||
|
}),
|
||||||
|
),
|
||||||
withViewDetails(),
|
withViewDetails(),
|
||||||
)(InvoicesDataTable);
|
)(InvoicesDataTable);
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ import t from 'store/types';
|
|||||||
const mapDipatchToProps = (dispatch) => ({
|
const mapDipatchToProps = (dispatch) => ({
|
||||||
requestSubmitInvoice: (form) => dispatch(submitInvoice({ form })),
|
requestSubmitInvoice: (form) => dispatch(submitInvoice({ form })),
|
||||||
requsetFetchInvoice: (id) => dispatch(fetchInvoice({ id })),
|
requsetFetchInvoice: (id) => dispatch(fetchInvoice({ id })),
|
||||||
requestEditInvoice: (id, form) => dispatch(editInvoice({ id, form })),
|
requestEditInvoice: (id, form) => dispatch(editInvoice( id, form )),
|
||||||
requestFetchInvoiceTable: (query = {}) =>
|
requestFetchInvoiceTable: (query = {}) =>
|
||||||
dispatch(fetchInvoicesTable({ query: { ...query } })),
|
dispatch(fetchInvoicesTable({ query: { ...query } })),
|
||||||
requestDeleteInvoice: (id) => dispatch(deleteInvoice({ id })),
|
requestDeleteInvoice: (id) => dispatch(deleteInvoice({ id })),
|
||||||
|
|
||||||
changeInvoiceView: (id) =>
|
changeInvoiceView: (id) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICES_SET_CURREMT_VIEW,
|
type: t.INVOICES_SET_CURRENT_VIEW,
|
||||||
currentViewId: parseInt(id, 10),
|
currentViewId: parseInt(id, 10),
|
||||||
}),
|
}),
|
||||||
addInvoiceTableQueries: (_queries) =>
|
addInvoiceTableQueries: (_queries) =>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { getInvoiceById } from 'store/Invoice/invoices.selector';
|
import { getInvoiecsByIdFactory } from 'store/Invoice/invoices.selector';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const getInvoiceById = getInvoiceById();
|
const getInvoiceById = getInvoiecsByIdFactory();
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
invoice: getInvoiceById(state, props),
|
invoice: getInvoiceById(state, props),
|
||||||
|
|||||||
25
client/src/containers/Sales/Invoice/withInvoices.js
Normal file
25
client/src/containers/Sales/Invoice/withInvoices.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { getResourceViews } from 'store/customViews/customViews.selectors';
|
||||||
|
import {
|
||||||
|
getInvoiceCurrentPageFactory,
|
||||||
|
getInvoicePaginationMetaFactory,
|
||||||
|
getInvoiceTableQuery,
|
||||||
|
} from 'store/Invoice/invoices.selector';
|
||||||
|
|
||||||
|
export default (mapState) => {
|
||||||
|
const getInvoicesItems = getInvoiceCurrentPageFactory();
|
||||||
|
const getInvoicesPaginationMeta = getInvoicePaginationMetaFactory();
|
||||||
|
const mapStateToProps = (state, props) => {
|
||||||
|
const query = getInvoiceTableQuery(state, props);
|
||||||
|
const mapped = {
|
||||||
|
invoicesCurrentPage: getInvoicesItems(state, props, query),
|
||||||
|
invoicesViews: getResourceViews(state, props, 'sales_invoices'),
|
||||||
|
invoicesItems: state.sales_invoices.items,
|
||||||
|
invoicesTableQuery: query,
|
||||||
|
invoicesPageination: getInvoicesPaginationMeta(state, props, query),
|
||||||
|
invoicesLoading: state.sales_invoices.loading,
|
||||||
|
};
|
||||||
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
|
};
|
||||||
|
return connect(mapStateToProps);
|
||||||
|
};
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
import React, { useCallback, useState, useMemo } from 'react';
|
||||||
|
import Icon from 'components/Icon';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Classes,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
Popover,
|
||||||
|
NavbarDivider,
|
||||||
|
NavbarGroup,
|
||||||
|
PopoverInteractionKind,
|
||||||
|
Position,
|
||||||
|
Intent,
|
||||||
|
} from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { useRouteMatch, useHistory } from 'react-router-dom';
|
||||||
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { If, DashboardActionViewsList } from 'components';
|
||||||
|
import FilterDropdown from 'components/FilterDropdown';
|
||||||
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
|
|
||||||
|
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
||||||
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
import withReceiptActions from './withReceipActions';
|
||||||
|
import withReceipts from './withReceipts';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function ReceiptActionsBar({
|
||||||
|
// #withResourceDetail
|
||||||
|
resourceFields,
|
||||||
|
|
||||||
|
//#withReceipts
|
||||||
|
receiptview,
|
||||||
|
//#withReceiptActions
|
||||||
|
addReceiptsTableQueries,
|
||||||
|
|
||||||
|
//#OWn Props
|
||||||
|
onFilterChanged,
|
||||||
|
selectedRows = [],
|
||||||
|
}) {
|
||||||
|
const { path } = useRouteMatch();
|
||||||
|
const history = useHistory();
|
||||||
|
const [filterCount, setFilterCount] = useState(0);
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
const onClickNewReceipt = useCallback(() => {
|
||||||
|
history.push('/receipts/new');
|
||||||
|
}, [history]);
|
||||||
|
|
||||||
|
// const filterDropdown = FilterDropdown({
|
||||||
|
// initialCondition: {
|
||||||
|
// fieldKey: '',
|
||||||
|
// compatator: '',
|
||||||
|
// value: '',
|
||||||
|
// },
|
||||||
|
// fields: resourceFields,
|
||||||
|
// onFilterChange: (filterConditions) => {
|
||||||
|
// addReceiptsTableQueries({
|
||||||
|
// filter_roles: filterConditions || '',
|
||||||
|
// });
|
||||||
|
// onFilterChanged && onFilterChange(filterConditions);
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
||||||
|
selectedRows,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardActionsBar>
|
||||||
|
<NavbarGroup>
|
||||||
|
<DashboardActionViewsList
|
||||||
|
resourceName={'sales_receipts'}
|
||||||
|
views={receiptview}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<NavbarDivider />
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'plus'} />}
|
||||||
|
text={<T id={'new_receipt'} />}
|
||||||
|
onClick={onClickNewReceipt}
|
||||||
|
/>
|
||||||
|
<Popover
|
||||||
|
minimal={true}
|
||||||
|
// content={filterDropdown}
|
||||||
|
interactionKind={PopoverInteractionKind.CLICK}
|
||||||
|
position={Position.BOTTOM_LEFT}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
className={classNames(Classes.MINIMAL, 'button--filter')}
|
||||||
|
text={
|
||||||
|
filterCount <= 0 ? (
|
||||||
|
<T id={'filter'} />
|
||||||
|
) : (
|
||||||
|
`${filterCount} ${formatMessage({ id: 'filters_applied' })}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
icon={<Icon icon={'filter-16'} iconSize={16} />}
|
||||||
|
/>
|
||||||
|
</Popover>
|
||||||
|
<If condition={hasSelectedRows}>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'trash-16'} iconSize={16} />}
|
||||||
|
text={<T id={'delete'} />}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
/>
|
||||||
|
</If>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'print-16'} iconSize={'16'} />}
|
||||||
|
text={<T id={'print'} />}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'file-import-16'} />}
|
||||||
|
text={<T id={'import'} />}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
icon={<Icon icon={'file-export-16'} iconSize={'16'} />}
|
||||||
|
text={<T id={'export'} />}
|
||||||
|
/>
|
||||||
|
</NavbarGroup>
|
||||||
|
</DashboardActionsBar>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const mapStateToProps = (state, props) => ({
|
||||||
|
resourceName: 'sales_receipts',
|
||||||
|
});
|
||||||
|
|
||||||
|
const withReceiptActionsBar = connect(mapStateToProps);
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withReceiptActionsBar,
|
||||||
|
withResourceDetail(({ resourceFields }) => ({
|
||||||
|
resourceFields,
|
||||||
|
})),
|
||||||
|
withReceipts(({ receiptview }) => ({
|
||||||
|
receiptview,
|
||||||
|
})),
|
||||||
|
withReceiptActions,
|
||||||
|
)(ReceiptActionsBar);
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import React, {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} 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, FormGroup, TextArea } from '@blueprintjs/core';
|
import { Intent, FormGroup, TextArea } from '@blueprintjs/core';
|
||||||
|
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
@@ -17,9 +17,10 @@ import ReceiptFromHeader from './ReceiptFormHeader';
|
|||||||
import EstimatesItemsTable from 'containers/Sales/Estimate/EntriesItemsTable';
|
import EstimatesItemsTable from 'containers/Sales/Estimate/EntriesItemsTable';
|
||||||
import ReceiptFormFooter from './ReceiptFormFooter';
|
import ReceiptFormFooter from './ReceiptFormFooter';
|
||||||
|
|
||||||
|
import withReceipActions from './withReceipActions';
|
||||||
|
import withReceiptDetail from './withReceiptDetail';
|
||||||
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 withReceipActions from './withReceipActions';
|
|
||||||
|
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
import Dragzone from 'components/Dragzone';
|
import Dragzone from 'components/Dragzone';
|
||||||
@@ -36,21 +37,22 @@ function ReceiptForm({
|
|||||||
|
|
||||||
//#withReceiptActions
|
//#withReceiptActions
|
||||||
requestSubmitReceipt,
|
requestSubmitReceipt,
|
||||||
|
requestEditReceipt,
|
||||||
|
|
||||||
|
//#withReceiptDetail
|
||||||
|
receipt,
|
||||||
|
|
||||||
//#withDashboard
|
//#withDashboard
|
||||||
changePageTitle,
|
changePageTitle,
|
||||||
changePageSubtitle,
|
changePageSubtitle,
|
||||||
|
|
||||||
//#withReceiptDetail
|
|
||||||
receipt,
|
|
||||||
|
|
||||||
//#own Props
|
//#own Props
|
||||||
receiptId,
|
receiptId,
|
||||||
onFormSubmit,
|
onFormSubmit,
|
||||||
onCancelForm,
|
onCancelForm,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const [payload, setPaload] = useState({});
|
const [payload, setPayload] = useState({});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setFiles,
|
setFiles,
|
||||||
@@ -87,9 +89,9 @@ function ReceiptForm({
|
|||||||
receipt_date: Yup.date()
|
receipt_date: Yup.date()
|
||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'receipt_date_' })),
|
.label(formatMessage({ id: 'receipt_date_' })),
|
||||||
receipt_no: Yup.number()
|
// receipt_no: Yup.number()
|
||||||
.required()
|
// .required()
|
||||||
.label(formatMessage({ id: 'receipt_no_' })),
|
// .label(formatMessage({ id: 'receipt_no_' })),
|
||||||
deposit_account_id: Yup.number()
|
deposit_account_id: Yup.number()
|
||||||
.required()
|
.required()
|
||||||
.label(formatMessage({ id: 'deposit_account_' })),
|
.label(formatMessage({ id: 'deposit_account_' })),
|
||||||
@@ -99,7 +101,7 @@ function ReceiptForm({
|
|||||||
.min(1)
|
.min(1)
|
||||||
.max(1024)
|
.max(1024)
|
||||||
.label(formatMessage({ id: 'receipt_message_' })),
|
.label(formatMessage({ id: 'receipt_message_' })),
|
||||||
send_to_email: Yup.string().email(),
|
email_send_to: Yup.string().email().nullable(),
|
||||||
statement: Yup.string()
|
statement: Yup.string()
|
||||||
.trim()
|
.trim()
|
||||||
.min(1)
|
.min(1)
|
||||||
@@ -121,7 +123,7 @@ function ReceiptForm({
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
const saveReceiptSubmit = useCallback(
|
const saveInvokeSubmit = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
onFormSubmit && onFormSubmit(payload);
|
onFormSubmit && onFormSubmit(payload);
|
||||||
},
|
},
|
||||||
@@ -133,7 +135,7 @@ function ReceiptForm({
|
|||||||
index: 0,
|
index: 0,
|
||||||
item_id: null,
|
item_id: null,
|
||||||
rate: null,
|
rate: null,
|
||||||
discount: null,
|
discount: 0,
|
||||||
quantity: null,
|
quantity: null,
|
||||||
description: '',
|
description: '',
|
||||||
}),
|
}),
|
||||||
@@ -145,7 +147,7 @@ function ReceiptForm({
|
|||||||
customer_id: '',
|
customer_id: '',
|
||||||
deposit_account_id: '',
|
deposit_account_id: '',
|
||||||
receipt_date: moment(new Date()).format('YYYY-MM-DD'),
|
receipt_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
send_to_email: '',
|
email_send_to: '',
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
receipt_message: '',
|
receipt_message: '',
|
||||||
statement: '',
|
statement: '',
|
||||||
@@ -163,10 +165,25 @@ function ReceiptForm({
|
|||||||
|
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
...defaultInitialValues,
|
...(receipt
|
||||||
entries: orderingIndex(defaultInitialValues.entries),
|
? {
|
||||||
|
...pick(receipt, Object.keys(defaultInitialValues)),
|
||||||
|
entries: [
|
||||||
|
...receipt.entries.map((receipt) => ({
|
||||||
|
...pick(receipt, Object.keys(defaultReceipt)),
|
||||||
|
})),
|
||||||
|
...repeatValue(
|
||||||
|
defaultReceipt,
|
||||||
|
Math.max(MIN_LINES_NUMBER - receipt.entries.length, 0),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
...defaultInitialValues,
|
||||||
|
entries: orderingIndex(defaultInitialValues.entries),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
[defaultReceipt, defaultInitialValues, receipt],
|
[receipt, defaultInitialValues, defaultReceipt],
|
||||||
);
|
);
|
||||||
|
|
||||||
const initialAttachmentFiles = useMemo(() => {
|
const initialAttachmentFiles = useMemo(() => {
|
||||||
@@ -186,49 +203,45 @@ function ReceiptForm({
|
|||||||
...initialValues,
|
...initialValues,
|
||||||
},
|
},
|
||||||
onSubmit: async (values, { setErrors, setSubmitting, resetForm }) => {
|
onSubmit: async (values, { setErrors, setSubmitting, resetForm }) => {
|
||||||
const entries = values.entries.map(
|
const entries = values.entries.filter(
|
||||||
({ item_id, quantity, rate, description }) => ({
|
(item) => item.item_id && item.quantity,
|
||||||
item_id,
|
|
||||||
quantity,
|
|
||||||
rate,
|
|
||||||
description,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
entries,
|
entries,
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveReceipt = (mediaIds) =>
|
const requestForm = { ...form };
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
const requestForm = { ...form, media_ids: mediaIds };
|
|
||||||
|
|
||||||
requestSubmitReceipt(requestForm)
|
if (receipt && receipt.id) {
|
||||||
.then((resposne) => {
|
requestEditReceipt(receipt.id && requestForm).then(() => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage({
|
message: formatMessage({
|
||||||
id: 'the_receipt_has_been_successfully_created',
|
id: 'the_receipt_has_been_successfully_edited',
|
||||||
}),
|
}),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
resetForm();
|
saveInvokeSubmit({ action: 'update', ...payload });
|
||||||
saveReceiptSubmit({ action: 'new', ...payload });
|
resetForm();
|
||||||
clearSavedMediaIds();
|
});
|
||||||
})
|
} else {
|
||||||
.catch((errors) => {
|
requestSubmitReceipt(requestForm)
|
||||||
setSubmitting(false);
|
.then((response) => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'the_receipt_has_been_successfully_created',
|
||||||
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
});
|
setSubmitting(false);
|
||||||
Promise.all([saveMedia(), deleteMedia()])
|
saveInvokeSubmit({ action: 'new', ...payload });
|
||||||
.then(([savedMediaResponses]) => {
|
resetForm();
|
||||||
const mediaIds = savedMediaResponses.map((res) => res.data.media.id);
|
})
|
||||||
savedMediaIds.current = mediaIds;
|
.catch((errors) => {
|
||||||
return savedMediaResponses;
|
setSubmitting(false);
|
||||||
})
|
});
|
||||||
.then(() => {
|
}
|
||||||
return saveReceipt(saveReceipt.current);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -245,10 +258,10 @@ function ReceiptForm({
|
|||||||
|
|
||||||
const handleSubmitClick = useCallback(
|
const handleSubmitClick = useCallback(
|
||||||
(payload) => {
|
(payload) => {
|
||||||
setPaload(payload);
|
setPayload(payload);
|
||||||
formik.submitForm();
|
formik.submitForm();
|
||||||
},
|
},
|
||||||
[setPaload, formik],
|
[setPayload, formik],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleCancelClick = useCallback(
|
const handleCancelClick = useCallback(
|
||||||
@@ -308,12 +321,13 @@ function ReceiptForm({
|
|||||||
onDeleteFile={handleDeleteFile}
|
onDeleteFile={handleDeleteFile}
|
||||||
hint={'Attachments: Maxiumum size: 20MB'}
|
hint={'Attachments: Maxiumum size: 20MB'}
|
||||||
/>
|
/>
|
||||||
<ReceiptFormFooter
|
|
||||||
formik={formik}
|
|
||||||
onSubmit={handleSubmitClick}
|
|
||||||
onCancelForm={handleCancelClick}
|
|
||||||
/>
|
|
||||||
</form>
|
</form>
|
||||||
|
<ReceiptFormFooter
|
||||||
|
formik={formik}
|
||||||
|
onSubmitClick={handleSubmitClick}
|
||||||
|
receipt={receipt}
|
||||||
|
onCancelForm={handleCancelClick}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -322,4 +336,5 @@ export default compose(
|
|||||||
withReceipActions,
|
withReceipActions,
|
||||||
withDashboardActions,
|
withDashboardActions,
|
||||||
withMediaActions,
|
withMediaActions,
|
||||||
|
withReceiptDetail(),
|
||||||
)(ReceiptForm);
|
)(ReceiptForm);
|
||||||
|
|||||||
@@ -6,11 +6,19 @@ export default function ReceiptFormFooter({
|
|||||||
formik: { isSubmitting },
|
formik: { isSubmitting },
|
||||||
onSubmitClick,
|
onSubmitClick,
|
||||||
onCancelClick,
|
onCancelClick,
|
||||||
|
receipt,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className={'estimate-form__floating-footer'}>
|
<div className={'estimate-form__floating-footer'}>
|
||||||
<Button disabled={isSubmitting} intent={Intent.PRIMARY} type="submit">
|
<Button
|
||||||
<T id={'save_send'} />
|
disabled={isSubmitting}
|
||||||
|
intent={Intent.PRIMARY}
|
||||||
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onSubmitClick({ redirect: true });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{receipt && receipt.id ? <T id={'edit'} /> : <T id={'save_send'} />}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -19,6 +27,9 @@ export default function ReceiptFormFooter({
|
|||||||
className={'ml1'}
|
className={'ml1'}
|
||||||
name={'save'}
|
name={'save'}
|
||||||
type="submit"
|
type="submit"
|
||||||
|
onClick={() => {
|
||||||
|
onSubmitClick({ redirect: false });
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<T id={'save'} />
|
<T id={'save'} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ function ReceiptFormHeader({
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
</div>
|
</div>
|
||||||
{/* receipt_no */}
|
{/* receipt_no */}
|
||||||
<FormGroup
|
{/* <FormGroup
|
||||||
label={<T id={'receipt'} />}
|
label={<T id={'receipt'} />}
|
||||||
inline={true}
|
inline={true}
|
||||||
className={('form-group--receipt_no', Classes.FILL)}
|
className={('form-group--receipt_no', Classes.FILL)}
|
||||||
@@ -170,7 +170,7 @@ function ReceiptFormHeader({
|
|||||||
minimal={true}
|
minimal={true}
|
||||||
{...getFieldProps('receipt_no')}
|
{...getFieldProps('receipt_no')}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup> */}
|
||||||
|
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'reference'} />}
|
label={<T id={'reference'} />}
|
||||||
@@ -189,12 +189,12 @@ function ReceiptFormHeader({
|
|||||||
label={<T id={'send_to_email'} />}
|
label={<T id={'send_to_email'} />}
|
||||||
inline={true}
|
inline={true}
|
||||||
className={classNames('form-group--send_to_email', Classes.FILL)}
|
className={classNames('form-group--send_to_email', Classes.FILL)}
|
||||||
intent={errors.send_to_email && touched.send_to_email && Intent.DANGER}
|
intent={errors.email_send_to && touched.email_send_to && Intent.DANGER}
|
||||||
helperText={<ErrorMessage name="reference" {...{ errors, touched }} />}
|
helperText={<ErrorMessage name="reference" {...{ errors, touched }} />}
|
||||||
>
|
>
|
||||||
<InputGroup
|
<InputGroup
|
||||||
intent={
|
intent={
|
||||||
errors.send_to_email && touched.send_to_email && Intent.DANGER
|
errors.email_send_to && touched.email_send_to && Intent.DANGER
|
||||||
}
|
}
|
||||||
minimal={true}
|
minimal={true}
|
||||||
{...getFieldProps('send_to_email')}
|
{...getFieldProps('send_to_email')}
|
||||||
|
|||||||
191
client/src/containers/Sales/Receipt/ReceiptList.js
Normal file
191
client/src/containers/Sales/Receipt/ReceiptList.js
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
import React, { useEffect, useCallback, useMemo, useState } from 'react';
|
||||||
|
import { Route, Switch, useHistory } from 'react-router-dom';
|
||||||
|
import { useQuery, queryCache } from 'react-query';
|
||||||
|
import { Alert, Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import AppToaster from 'components/AppToaster';
|
||||||
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||||
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
|
||||||
|
import ReceiptsDataTable from './ReceiptsDataTable';
|
||||||
|
import ReceiptActionsBar from './ReceiptActionsBar';
|
||||||
|
import ReceiptViewTabs from './ReceiptViewTabs';
|
||||||
|
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withResourceActions from 'containers/Resources/withResourcesActions';
|
||||||
|
import withReceipts from './withReceipts';
|
||||||
|
import withReceipActions from './withReceipActions';
|
||||||
|
import withViewsActions from 'containers/Views/withViewsActions';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function ReceiptList({
|
||||||
|
// #withDashboardActions
|
||||||
|
changePageTitle,
|
||||||
|
|
||||||
|
// #withViewsActions
|
||||||
|
requestFetchResourceViews,
|
||||||
|
requestFetchResourceFields,
|
||||||
|
|
||||||
|
//#withReceipts
|
||||||
|
receiptTableQuery,
|
||||||
|
receiptview,
|
||||||
|
|
||||||
|
//#withReceiptActions
|
||||||
|
requestFetchReceiptsTable,
|
||||||
|
requestDeleteReceipt,
|
||||||
|
addReceiptsTableQueries,
|
||||||
|
}) {
|
||||||
|
const history = useHistory();
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
const [deleteReceipt, setDeleteReceipt] = useState(false);
|
||||||
|
const [selectedRows, setSelectedRows] = useState([]);
|
||||||
|
|
||||||
|
const fetchReceipts = useQuery(['receipts-table', receiptTableQuery], () =>
|
||||||
|
requestFetchReceiptsTable(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchResourceViews = useQuery(
|
||||||
|
['resource-views', 'sales_receipts'],
|
||||||
|
(key, resourceName) => requestFetchResourceViews(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
|
const fetchResourceFields = useQuery(
|
||||||
|
['resource-fields', 'sales_receipts'],
|
||||||
|
(key, resourceName) => requestFetchResourceFields(resourceName),
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
changePageTitle(formatMessage({ id: 'receipt_list' }));
|
||||||
|
}, [changePageTitle, formatMessage]);
|
||||||
|
|
||||||
|
// handle delete receipt click
|
||||||
|
const handleDeleteReceipt = useCallback(
|
||||||
|
(_receipt) => {
|
||||||
|
setDeleteReceipt(_receipt);
|
||||||
|
},
|
||||||
|
[setDeleteReceipt],
|
||||||
|
);
|
||||||
|
|
||||||
|
// handle cancel receipt
|
||||||
|
const handleCancelReceiptDelete = useCallback(() => {
|
||||||
|
setDeleteReceipt(false);
|
||||||
|
}, [setDeleteReceipt]);
|
||||||
|
|
||||||
|
// handle confirm delete receipt
|
||||||
|
const handleConfirmReceiptDelete = useCallback(() => {
|
||||||
|
requestDeleteReceipt(deleteReceipt.id).then(() => {
|
||||||
|
AppToaster.show({
|
||||||
|
message: formatMessage({
|
||||||
|
id: 'the_receipt_has_been_successfully_deleted',
|
||||||
|
}),
|
||||||
|
intent: Intent.SUCCESS,
|
||||||
|
});
|
||||||
|
setDeleteReceipt(false);
|
||||||
|
});
|
||||||
|
}, [deleteReceipt, requestDeleteReceipt, formatMessage]);
|
||||||
|
|
||||||
|
// Handle filter change to re-fetch data-table.
|
||||||
|
// const handleFilterChanged = useCallback(
|
||||||
|
// (filterConditions) => {
|
||||||
|
// addReceiptsTableQueries({
|
||||||
|
// filter_roles: filterConditions || '',
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
// [fetchReceipt],
|
||||||
|
// );
|
||||||
|
|
||||||
|
// Handle filter change to re-fetch data-table.
|
||||||
|
const handleFilterChanged = useCallback(() => {}, [fetchReceipts]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Calculates the selected rows
|
||||||
|
const selectedRowsCount = useMemo(() => Object.values(selectedRows).length, [
|
||||||
|
selectedRows,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const handleEditReceipt = useCallback(
|
||||||
|
(receipt) => {
|
||||||
|
history.push(`/receipts/${receipt.id}/edit`);
|
||||||
|
},
|
||||||
|
[history],
|
||||||
|
);
|
||||||
|
const handleFetchData = useCallback(
|
||||||
|
({ pageIndex, pageSize, sortBy }) => {
|
||||||
|
const page = pageIndex + 1;
|
||||||
|
|
||||||
|
addReceiptsTableQueries({
|
||||||
|
...(sortBy.length > 0
|
||||||
|
? {
|
||||||
|
column_sort_by: sortBy[0].id,
|
||||||
|
sort_order: sortBy[0].desc ? 'desc' : 'asc',
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
page_size: pageSize,
|
||||||
|
page,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[addReceiptsTableQueries],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleSelectedRowsChange = useCallback(
|
||||||
|
(estimate) => {
|
||||||
|
setSelectedRows(estimate);
|
||||||
|
},
|
||||||
|
[setSelectedRows],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardInsider
|
||||||
|
name={'sales_receipts'}
|
||||||
|
loading={fetchResourceViews.isFetching || fetchResourceFields.isFetching}
|
||||||
|
>
|
||||||
|
<DashboardPageContent>
|
||||||
|
<ReceiptActionsBar
|
||||||
|
selectedRows={selectedRows}
|
||||||
|
onFilterChanged={handleFilterChanged}
|
||||||
|
/>
|
||||||
|
<Switch>
|
||||||
|
<Route
|
||||||
|
exact={true}
|
||||||
|
path={['/receipts/:custom_view_id/custom_view', '/receipts']}
|
||||||
|
>
|
||||||
|
<ReceiptViewTabs />
|
||||||
|
<ReceiptsDataTable
|
||||||
|
loading={fetchReceipts.isLoading}
|
||||||
|
onDeleteReceipt={handleDeleteReceipt}
|
||||||
|
onFetchData={handleFetchData}
|
||||||
|
onEditReceipt={handleEditReceipt}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
/>
|
||||||
|
</Route>
|
||||||
|
</Switch>
|
||||||
|
<Alert
|
||||||
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
confirmButtonText={<T id={'delete'} />}
|
||||||
|
icon={'trash'}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
isOpen={deleteReceipt}
|
||||||
|
onCancel={handleCancelReceiptDelete}
|
||||||
|
onConfirm={handleConfirmReceiptDelete}
|
||||||
|
>
|
||||||
|
<p>
|
||||||
|
<T id={'once_delete_this_receipt_you_will_able_to_restore_it'} />
|
||||||
|
</p>
|
||||||
|
</Alert>
|
||||||
|
</DashboardPageContent>
|
||||||
|
</DashboardInsider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withResourceActions,
|
||||||
|
withReceipActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withViewsActions,
|
||||||
|
withReceipts(({ receiptTableQuery }) => ({
|
||||||
|
receiptTableQuery,
|
||||||
|
})),
|
||||||
|
)(ReceiptList);
|
||||||
109
client/src/containers/Sales/Receipt/ReceiptViewTabs.js
Normal file
109
client/src/containers/Sales/Receipt/ReceiptViewTabs.js
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
import { useHistory } from 'react-router';
|
||||||
|
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||||
|
import { useParams, withRouter } from 'react-router-dom';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { pick, debounce } from 'lodash';
|
||||||
|
|
||||||
|
import { DashboardViewsTabs } from 'components';
|
||||||
|
import { useUpdateEffect } from 'hooks';
|
||||||
|
|
||||||
|
import withReceipts from './withReceipts';
|
||||||
|
import withReceiptActions from './withReceipActions';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withViewDetails from 'containers/Views/withViewDetails';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
function ReceiptViewTabs({
|
||||||
|
//#withReceipts
|
||||||
|
receiptview,
|
||||||
|
// #withViewDetails
|
||||||
|
viewItem,
|
||||||
|
|
||||||
|
//#withReceiptActions
|
||||||
|
changeReceiptView,
|
||||||
|
addReceiptsTableQueries,
|
||||||
|
|
||||||
|
// #withDashboardActions
|
||||||
|
setTopbarEditView,
|
||||||
|
changePageSubtitle,
|
||||||
|
|
||||||
|
//# own Props
|
||||||
|
customViewChanged,
|
||||||
|
onViewChanged,
|
||||||
|
}) {
|
||||||
|
const history = useHistory();
|
||||||
|
const { custom_view_id: customViewId = null } = useParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
changeReceiptView(customViewId || -1);
|
||||||
|
setTopbarEditView(customViewId);
|
||||||
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
|
|
||||||
|
addReceiptsTableQueries({
|
||||||
|
custom_view_id: customViewId,
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
setTopbarEditView(null);
|
||||||
|
changePageSubtitle('');
|
||||||
|
changeReceiptView(null);
|
||||||
|
};
|
||||||
|
}, [customViewId, addReceiptsTableQueries, changeReceiptView]);
|
||||||
|
|
||||||
|
useUpdateEffect(() => {
|
||||||
|
onViewChanged && onViewChanged(customViewId);
|
||||||
|
}, [customViewId]);
|
||||||
|
|
||||||
|
const debounceChangeHistory = useRef(
|
||||||
|
debounce((toUrl) => {
|
||||||
|
history.push(toUrl);
|
||||||
|
}, 250),
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTabsChange = (viewId) => {
|
||||||
|
const toPath = viewId ? `${viewId}/custom_view` : '';
|
||||||
|
debounceChangeHistory.current(`/receipts/${toPath}`);
|
||||||
|
setTopbarEditView(viewId);
|
||||||
|
};
|
||||||
|
const tabs = receiptview.map((view) => ({
|
||||||
|
...pick(view, ['name', 'id']),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Handle click a new view tab.
|
||||||
|
const handleClickNewView = () => {
|
||||||
|
setTopbarEditView(null);
|
||||||
|
history.push('/custom_views/receipts/new');
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(receiptview, 'receiptview');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Navbar className={'navbar--dashboard-views'}>
|
||||||
|
<NavbarGroup align={Alignment.LEFT}>
|
||||||
|
<DashboardViewsTabs
|
||||||
|
initialViewId={customViewId}
|
||||||
|
baseUrl={'/receipts'}
|
||||||
|
tabs={tabs}
|
||||||
|
onNewViewTabClick={handleClickNewView}
|
||||||
|
onChange={handleTabsChange}
|
||||||
|
/>
|
||||||
|
</NavbarGroup>
|
||||||
|
</Navbar>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
|
viewId: ownProps.match.params.custom_view_id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const withReceiptsViewTabs = connect(mapStateToProps);
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withRouter,
|
||||||
|
withReceiptsViewTabs,
|
||||||
|
withReceiptActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withViewDetails(),
|
||||||
|
withReceipts(({ receiptview }) => ({ receiptview })),
|
||||||
|
)(ReceiptViewTabs);
|
||||||
@@ -8,6 +8,7 @@ import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
|||||||
import withCustomersActions from 'containers/Customers/withCustomersActions';
|
import withCustomersActions from 'containers/Customers/withCustomersActions';
|
||||||
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
import withAccountsActions from 'containers/Accounts/withAccountsActions';
|
||||||
import withItemsActions from 'containers/Items/withItemsActions';
|
import withItemsActions from 'containers/Items/withItemsActions';
|
||||||
|
import withReceipActions from './withReceipActions';
|
||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
@@ -20,10 +21,18 @@ function Receipts({
|
|||||||
|
|
||||||
//#withItemsActions
|
//#withItemsActions
|
||||||
requestFetchItems,
|
requestFetchItems,
|
||||||
|
|
||||||
|
//#withReceiptsActions
|
||||||
|
requsetFetchInvoice,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
|
const fetchReceipt = useQuery(
|
||||||
|
['receipt', id],
|
||||||
|
(key, _id) => requsetFetchInvoice(_id),
|
||||||
|
{ enabled: !!id },
|
||||||
|
);
|
||||||
const fetchAccounts = useQuery('accounts-list', (key) =>
|
const fetchAccounts = useQuery('accounts-list', (key) =>
|
||||||
requestFetchAccounts(),
|
requestFetchAccounts(),
|
||||||
);
|
);
|
||||||
@@ -35,7 +44,12 @@ function Receipts({
|
|||||||
// Handle fetch Items data table or list
|
// Handle fetch Items data table or list
|
||||||
const fetchItems = useQuery('items-table', () => requestFetchItems({}));
|
const fetchItems = useQuery('items-table', () => requestFetchItems({}));
|
||||||
|
|
||||||
const handleFormSubmit = useCallback((payload) => {}, [history]);
|
const handleFormSubmit = useCallback(
|
||||||
|
(payload) => {
|
||||||
|
payload.redirect && history.push('/receipts');
|
||||||
|
},
|
||||||
|
[history],
|
||||||
|
);
|
||||||
|
|
||||||
const handleCancel = useCallback(() => {
|
const handleCancel = useCallback(() => {
|
||||||
history.goBack();
|
history.goBack();
|
||||||
@@ -46,12 +60,14 @@ function Receipts({
|
|||||||
loading={
|
loading={
|
||||||
fetchCustomers.isFetching ||
|
fetchCustomers.isFetching ||
|
||||||
fetchItems.isFetching ||
|
fetchItems.isFetching ||
|
||||||
fetchAccounts.isFetching
|
fetchAccounts.isFetching||
|
||||||
|
fetchReceipt.isFetching
|
||||||
}
|
}
|
||||||
|
name={'receipt-form'}
|
||||||
>
|
>
|
||||||
<ReceiptFrom
|
<ReceiptFrom
|
||||||
onFormSubmit={handleFormSubmit}
|
onFormSubmit={handleFormSubmit}
|
||||||
// ReceiptId={id}
|
receiptId={id}
|
||||||
onCancelForm={handleCancel}
|
onCancelForm={handleCancel}
|
||||||
/>
|
/>
|
||||||
</DashboardInsider>
|
</DashboardInsider>
|
||||||
@@ -59,6 +75,7 @@ function Receipts({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
|
withReceipActions,
|
||||||
withCustomersActions,
|
withCustomersActions,
|
||||||
withItemsActions,
|
withItemsActions,
|
||||||
withAccountsActions,
|
withAccountsActions,
|
||||||
|
|||||||
247
client/src/containers/Sales/Receipt/ReceiptsDataTable.js
Normal file
247
client/src/containers/Sales/Receipt/ReceiptsDataTable.js
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
import React, { useEffect, useCallback, useState, useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
Intent,
|
||||||
|
Button,
|
||||||
|
Popover,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
MenuDivider,
|
||||||
|
Position,
|
||||||
|
} from '@blueprintjs/core';
|
||||||
|
import { useParams } from 'react-router-dom';
|
||||||
|
import { withRouter } from 'react-router';
|
||||||
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
import { useUpdateEffect } from 'hooks';
|
||||||
|
|
||||||
|
import LoadingIndicator from 'components/LoadingIndicator';
|
||||||
|
import { DataTable, Money, Icon } from 'components';
|
||||||
|
|
||||||
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withViewDetails from 'containers/Views/withViewDetails';
|
||||||
|
|
||||||
|
import withReceipts from './withReceipts';
|
||||||
|
import withReceipActions from './withReceipActions';
|
||||||
|
import withCurrentView from 'containers/Views/withCurrentView';
|
||||||
|
|
||||||
|
function ReceiptsDataTable({
|
||||||
|
//#withReceipts
|
||||||
|
receiptsCurrentPage,
|
||||||
|
receiptsLoading,
|
||||||
|
receiptsPagination,
|
||||||
|
receiptItems,
|
||||||
|
// #withDashboardActions
|
||||||
|
changeCurrentView,
|
||||||
|
changePageSubtitle,
|
||||||
|
setTopbarEditView,
|
||||||
|
|
||||||
|
// #withView
|
||||||
|
viewMeta,
|
||||||
|
|
||||||
|
// #Own Props
|
||||||
|
|
||||||
|
loading,
|
||||||
|
onFetchData,
|
||||||
|
onEditReceipt,
|
||||||
|
onDeleteReceipt,
|
||||||
|
onSelectedRowsChange,
|
||||||
|
}) {
|
||||||
|
const [initialMount, setInitialMount] = useState(false);
|
||||||
|
const { custom_view_id: customViewId } = useParams();
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
useUpdateEffect(() => {
|
||||||
|
if (!receiptsLoading) {
|
||||||
|
setInitialMount(true);
|
||||||
|
}
|
||||||
|
}, [receiptsLoading, setInitialMount]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setInitialMount(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (customViewId) {
|
||||||
|
changeCurrentView(customViewId);
|
||||||
|
setTopbarEditView(customViewId);
|
||||||
|
}
|
||||||
|
changePageSubtitle(customViewId && viewMeta ? viewMeta.name : '');
|
||||||
|
}, [
|
||||||
|
customViewId,
|
||||||
|
changeCurrentView,
|
||||||
|
changePageSubtitle,
|
||||||
|
setTopbarEditView,
|
||||||
|
viewMeta,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const handleEditReceipt = useCallback(
|
||||||
|
(receipt) => () => {
|
||||||
|
onEditReceipt && onEditReceipt(receipt);
|
||||||
|
},
|
||||||
|
[onEditReceipt],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleDeleteReceipt = useCallback(
|
||||||
|
(receipt) => () => {
|
||||||
|
onDeleteReceipt && onDeleteReceipt(receipt);
|
||||||
|
},
|
||||||
|
[onDeleteReceipt],
|
||||||
|
);
|
||||||
|
|
||||||
|
const actionMenuList = useCallback(
|
||||||
|
(estimate) => (
|
||||||
|
<Menu>
|
||||||
|
<MenuItem text={formatMessage({ id: 'view_details' })} />
|
||||||
|
<MenuDivider />
|
||||||
|
<MenuItem
|
||||||
|
text={formatMessage({ id: 'edit_receipt' })}
|
||||||
|
onClick={handleEditReceipt(estimate)}
|
||||||
|
/>
|
||||||
|
<MenuItem
|
||||||
|
text={formatMessage({ id: 'delete_receipt' })}
|
||||||
|
intent={Intent.DANGER}
|
||||||
|
onClick={handleDeleteReceipt(estimate)}
|
||||||
|
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||||
|
/>
|
||||||
|
</Menu>
|
||||||
|
),
|
||||||
|
[handleDeleteReceipt, handleEditReceipt, formatMessage],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onRowContextMenu = useCallback(
|
||||||
|
(cell) => {
|
||||||
|
return actionMenuList(cell.row.original);
|
||||||
|
},
|
||||||
|
[actionMenuList],
|
||||||
|
);
|
||||||
|
|
||||||
|
const columns = useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
id: 'receipt_date',
|
||||||
|
Header: formatMessage({ id: 'receipt_date' }),
|
||||||
|
accessor: (r) => moment(r.receipt_date).format('YYYY MMM DD'),
|
||||||
|
width: 140,
|
||||||
|
className: 'receipt_date',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'customer_id',
|
||||||
|
Header: formatMessage({ id: 'customer_name' }),
|
||||||
|
accessor: (row) => row.customer_id,
|
||||||
|
width: 140,
|
||||||
|
className: 'customer_id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'deposit_account_id',
|
||||||
|
Header: formatMessage({ id: 'deposit_account' }),
|
||||||
|
accessor: 'deposit_account.name',
|
||||||
|
width: 140,
|
||||||
|
className: 'deposit_account',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'email_send_to',
|
||||||
|
Header: formatMessage({ id: 'email' }),
|
||||||
|
accessor: 'email_send_to',
|
||||||
|
width: 140,
|
||||||
|
className: 'email_send_to',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'amount',
|
||||||
|
Header: formatMessage({ id: 'amount' }),
|
||||||
|
accessor: (r) => <Money amount={r.amount} currency={'USD'} />,
|
||||||
|
|
||||||
|
width: 140,
|
||||||
|
className: 'amount',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'reference_no',
|
||||||
|
Header: formatMessage({ id: 'reference_no' }),
|
||||||
|
accessor: 'reference_no',
|
||||||
|
width: 140,
|
||||||
|
className: 'reference_no',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'actions',
|
||||||
|
Header: '',
|
||||||
|
Cell: ({ cell }) => (
|
||||||
|
<Popover
|
||||||
|
content={actionMenuList(cell.row.original)}
|
||||||
|
position={Position.RIGHT_BOTTOM}
|
||||||
|
>
|
||||||
|
<Button icon={<Icon icon="more-h-16" iconSize={16} />} />
|
||||||
|
</Popover>
|
||||||
|
),
|
||||||
|
className: 'actions',
|
||||||
|
width: 50,
|
||||||
|
disableResizing: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[actionMenuList, formatMessage],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleDataTableFetchData = useCallback(
|
||||||
|
(...args) => {
|
||||||
|
onFetchData && onFetchData(...args);
|
||||||
|
},
|
||||||
|
[onFetchData],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleSelectedRowsChange = useCallback(
|
||||||
|
(selectedRows) => {
|
||||||
|
onSelectedRowsChange &&
|
||||||
|
onSelectedRowsChange(selectedRows.map((s) => s.original));
|
||||||
|
},
|
||||||
|
[onSelectedRowsChange],
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(receiptsCurrentPage, 'receiptCurrnetPage');
|
||||||
|
console.log(receiptItems, 'receiptItems');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<LoadingIndicator loading={loading} mount={false}>
|
||||||
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
data={receiptsCurrentPage}
|
||||||
|
loading={receiptsLoading && !initialMount}
|
||||||
|
onFetchData={handleDataTableFetchData}
|
||||||
|
manualSortBy={true}
|
||||||
|
selectionColumn={true}
|
||||||
|
noInitialFetch={true}
|
||||||
|
sticky={true}
|
||||||
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
rowContextMenu={onRowContextMenu}
|
||||||
|
pagination={true}
|
||||||
|
pagesCount={receiptsPagination.pagesCount}
|
||||||
|
initialPageSize={receiptsPagination.pageSize}
|
||||||
|
initialPageIndex={receiptsPagination.page - 1}
|
||||||
|
/>
|
||||||
|
</LoadingIndicator>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withRouter,
|
||||||
|
withCurrentView,
|
||||||
|
withDialogActions,
|
||||||
|
withDashboardActions,
|
||||||
|
withReceipActions,
|
||||||
|
withReceipts(
|
||||||
|
({
|
||||||
|
receiptsCurrentPage,
|
||||||
|
receiptsLoading,
|
||||||
|
receiptsPagination,
|
||||||
|
receiptItems,
|
||||||
|
}) => ({
|
||||||
|
receiptsCurrentPage,
|
||||||
|
receiptsLoading,
|
||||||
|
receiptsPagination,
|
||||||
|
receiptItems,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
withViewDetails(),
|
||||||
|
)(ReceiptsDataTable);
|
||||||
@@ -11,7 +11,7 @@ import t from 'store/types';
|
|||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
requestSubmitReceipt: (form) => dispatch(submitReceipt({ form })),
|
requestSubmitReceipt: (form) => dispatch(submitReceipt({ form })),
|
||||||
requestFetchReceipt: (id) => dispatch(fetchReceipt({ id })),
|
requestFetchReceipt: (id) => dispatch(fetchReceipt({ id })),
|
||||||
requestEditTeceipt: (id, form) => dispatch(editReceipt({ id, form })),
|
requestEditReceipt: (id, form) => dispatch(editReceipt( id, form )),
|
||||||
requestDeleteReceipt: (id) => dispatch(deleteReceipt({ id })),
|
requestDeleteReceipt: (id) => dispatch(deleteReceipt({ id })),
|
||||||
requestFetchReceiptsTable: (query = {}) =>
|
requestFetchReceiptsTable: (query = {}) =>
|
||||||
dispatch(fetchReceiptsTable({ query: { ...query } })),
|
dispatch(fetchReceiptsTable({ query: { ...query } })),
|
||||||
@@ -19,7 +19,7 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
|
|
||||||
changeReceiptView: (id) =>
|
changeReceiptView: (id) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.RECEIPT_SET_CURRENT_VIEW,
|
type: t.RECEIPTS_SET_CURRENT_VIEW,
|
||||||
currentViewId: parseInt(id, 10),
|
currentViewId: parseInt(id, 10),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
11
client/src/containers/Sales/Receipt/withReceiptDetail.js
Normal file
11
client/src/containers/Sales/Receipt/withReceiptDetail.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { getReceiptByIdFactory } from 'store/receipt/receipt.selector';
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const getReceiptById = getReceiptByIdFactory();
|
||||||
|
|
||||||
|
const mapStateToProps = (state, props) => ({
|
||||||
|
receipt: getReceiptById(state, props),
|
||||||
|
});
|
||||||
|
return connect(mapStateToProps);
|
||||||
|
};
|
||||||
27
client/src/containers/Sales/Receipt/withReceipts.js
Normal file
27
client/src/containers/Sales/Receipt/withReceipts.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { getResourceViews } from 'store/customViews/customViews.selectors';
|
||||||
|
import {
|
||||||
|
getReceiptCurrentPageFactory,
|
||||||
|
getReceiptsTableQuery,
|
||||||
|
getReceiptsPaginationMetaFactory,
|
||||||
|
} from 'store/receipt/receipt.selector';
|
||||||
|
|
||||||
|
export default (mapState) => {
|
||||||
|
const getReceiptsItems = getReceiptCurrentPageFactory();
|
||||||
|
const getReceiptPaginationMeta = getReceiptsPaginationMetaFactory();
|
||||||
|
|
||||||
|
const mapStateToProps = (state, props) => {
|
||||||
|
const query = getReceiptsTableQuery(state, props);
|
||||||
|
const mapped = {
|
||||||
|
receiptsCurrentPage: getReceiptsItems(state, props, query),
|
||||||
|
receiptview:getResourceViews(state, props, 'sales_receipts'),
|
||||||
|
receiptItems: state.sales_receipts.items,
|
||||||
|
receiptTableQuery: query,
|
||||||
|
receiptsPagination: getReceiptPaginationMeta(state, props, query),
|
||||||
|
receiptsLoading: state.sales_receipts.loading,
|
||||||
|
};
|
||||||
|
|
||||||
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
|
};
|
||||||
|
return connect(mapStateToProps);
|
||||||
|
};
|
||||||
32
client/src/containers/Vendors/withVendorActions.js
Normal file
32
client/src/containers/Vendors/withVendorActions.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import {
|
||||||
|
submitVendor,
|
||||||
|
editVendor,
|
||||||
|
deleteVendor,
|
||||||
|
fetchVendorsTable,
|
||||||
|
} from 'store/vendors/vendors.actions';
|
||||||
|
import t from 'store/types';
|
||||||
|
|
||||||
|
|
||||||
|
const mapDipatchToProps = (dispatch) => ({
|
||||||
|
requestSubmitVendor: (form) => dispatch(submitVendor({ form })),
|
||||||
|
requestEditVendor: (id, form) => dispatch(editVendor(id, form)),
|
||||||
|
requestFetchVendorsTable: (query = {}) =>
|
||||||
|
dispatch(fetchVendorsTable({ query: { ...query } })),
|
||||||
|
requestDeleteEstimate: (id) => dispatch(deleteVendor({ id })),
|
||||||
|
|
||||||
|
changeVendorView: (id) =>
|
||||||
|
dispatch({
|
||||||
|
type: t.VENDORS_SET_CURRENT_VIEW,
|
||||||
|
currentViewId: parseInt(id, 10),
|
||||||
|
}),
|
||||||
|
|
||||||
|
addVendorsTableQueries: (queries) =>
|
||||||
|
dispatch({
|
||||||
|
type: t.VENDORS_TABLE_QUERIES_ADD,
|
||||||
|
queries,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(null, mapDipatchToProps);
|
||||||
|
|
||||||
27
client/src/containers/Vendors/withVendors.js
Normal file
27
client/src/containers/Vendors/withVendors.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { getResourceViews } from 'store/customViews/customViews.selectors';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getVendorCurrentPageFactory,
|
||||||
|
getVendorsTableQuery,
|
||||||
|
getVendorsPaginationMetaFactory,
|
||||||
|
} from 'store/vendors/vendors.selectors';
|
||||||
|
|
||||||
|
export default (mapState) => {
|
||||||
|
const getVendorsItems = getVendorCurrentPageFactory();
|
||||||
|
const getVendorsPaginationMeta = getVendorsPaginationMetaFactory();
|
||||||
|
const mapStateToProps = (state, props) => {
|
||||||
|
const query = getVendorsTableQuery(state, props);
|
||||||
|
|
||||||
|
const mapped = {
|
||||||
|
vendorsCurrentPage: getVendorsItems(state, props, query),
|
||||||
|
vendorViews: getResourceViews(state, props, 'vendors'),
|
||||||
|
vendorItems: state.vendors.items,
|
||||||
|
vendorTableQuery: query,
|
||||||
|
vendorsPageination: getVendorsPaginationMeta(state, props, query),
|
||||||
|
vendorsLoading: state.vendors.loading,
|
||||||
|
};
|
||||||
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
|
};
|
||||||
|
return connect(mapStateToProps);
|
||||||
|
};
|
||||||
@@ -458,6 +458,7 @@ export default {
|
|||||||
display_name_: 'Display name',
|
display_name_: 'Display name',
|
||||||
new_customer: 'New Customer',
|
new_customer: 'New Customer',
|
||||||
customer_type: 'Customer Type',
|
customer_type: 'Customer Type',
|
||||||
|
customer_account: 'Customer Account',
|
||||||
business: 'Business',
|
business: 'Business',
|
||||||
individual: 'Individual',
|
individual: 'Individual',
|
||||||
display_name: 'Display Name',
|
display_name: 'Display Name',
|
||||||
@@ -584,6 +585,7 @@ export default {
|
|||||||
quantity: 'Quantity',
|
quantity: 'Quantity',
|
||||||
rate: 'Rate',
|
rate: 'Rate',
|
||||||
estimate_list: 'Estimate List',
|
estimate_list: 'Estimate List',
|
||||||
|
estimate_number: 'Estimate Number',
|
||||||
|
|
||||||
product_and_service: 'Product/Service',
|
product_and_service: 'Product/Service',
|
||||||
the_estimate_has_been_successfully_edited:
|
the_estimate_has_been_successfully_edited:
|
||||||
@@ -592,15 +594,21 @@ export default {
|
|||||||
'The estimate #{number} has been successfully created.',
|
'The estimate #{number} has been successfully created.',
|
||||||
the_estimate_has_been_successfully_deleted:
|
the_estimate_has_been_successfully_deleted:
|
||||||
'The estimate has been successfully deleted.',
|
'The estimate has been successfully deleted.',
|
||||||
|
|
||||||
|
once_delete_this_estimate_you_will_able_to_restore_it: `Once you delete this estimate, you won\'t be able to restore it later. Are you sure you want to delete this estimate?`,
|
||||||
|
|
||||||
cannot_be_zero_or_empty: 'cannot be zero or empty.',
|
cannot_be_zero_or_empty: 'cannot be zero or empty.',
|
||||||
invocies: 'Invoices',
|
invocies: 'Invoices',
|
||||||
|
invoices_list: 'Invoices List',
|
||||||
invoice_date: 'Invoice Date',
|
invoice_date: 'Invoice Date',
|
||||||
due_date: 'Due Date',
|
due_date: 'Due Date',
|
||||||
invoice_date_: 'Invoice date',
|
invoice_date_: 'Invoice date',
|
||||||
invoice_no: 'Invoice #',
|
invoice_no: 'Invoice #',
|
||||||
|
invoice_no__: 'Invoice No',
|
||||||
invoice_no_: 'Invoice number',
|
invoice_no_: 'Invoice number',
|
||||||
due_date_: 'Due date',
|
due_date_: 'Due date',
|
||||||
invoice_message: 'Invoice Message',
|
invoice_message: 'Invoice Message',
|
||||||
|
reference_no: 'Reference No',
|
||||||
|
|
||||||
edit_invoice: 'Edit Invoice',
|
edit_invoice: 'Edit Invoice',
|
||||||
delete_invoice: 'Delete Invoice',
|
delete_invoice: 'Delete Invoice',
|
||||||
@@ -613,6 +621,10 @@ export default {
|
|||||||
'The invoice #{number} has been successfully created.',
|
'The invoice #{number} has been successfully created.',
|
||||||
the_invocie_has_been_successfully_deleted:
|
the_invocie_has_been_successfully_deleted:
|
||||||
'The invoice has been successfully deleted.',
|
'The invoice has been successfully deleted.',
|
||||||
|
|
||||||
|
once_delete_this_invoice_you_will_able_to_restore_it: `Once you delete this invoice, you won\'t be able to restore it later. Are you sure you want to delete this invoice?`,
|
||||||
|
|
||||||
|
receipt_list: 'Receipt List',
|
||||||
receipts: 'Receipts',
|
receipts: 'Receipts',
|
||||||
receipt: 'Receipt #',
|
receipt: 'Receipt #',
|
||||||
receipt_date_: 'Receipt date',
|
receipt_date_: 'Receipt date',
|
||||||
@@ -621,12 +633,16 @@ export default {
|
|||||||
receipt_message_: 'Receipt message',
|
receipt_message_: 'Receipt message',
|
||||||
receipt_no_: 'receipt number',
|
receipt_no_: 'receipt number',
|
||||||
edit_receipt: 'Edit Receipt',
|
edit_receipt: 'Edit Receipt',
|
||||||
|
delete_receipt: 'Delete Receipt',
|
||||||
new_receipt: 'New Receipt',
|
new_receipt: 'New Receipt',
|
||||||
receipt_message: 'Receipt Message',
|
receipt_message: 'Receipt Message',
|
||||||
statement: 'Statement',
|
statement: 'Statement',
|
||||||
deposit_account: 'Deposit Account',
|
deposit_account: 'Deposit Account',
|
||||||
send_to_email: 'Send to email',
|
send_to_email: 'Send to email',
|
||||||
select_deposit_account: 'Select Deposit Account',
|
select_deposit_account: 'Select Deposit Account',
|
||||||
|
|
||||||
|
once_delete_this_receipt_you_will_able_to_restore_it: `Once you delete this receipt, you won\'t be able to restore it later. Are you sure you want to delete this receipt?`,
|
||||||
|
|
||||||
the_receipt_has_been_successfully_created:
|
the_receipt_has_been_successfully_created:
|
||||||
'The recepit has been successfully created.',
|
'The recepit has been successfully created.',
|
||||||
the_receipt_has_been_successfully_edited:
|
the_receipt_has_been_successfully_edited:
|
||||||
@@ -634,6 +650,7 @@ export default {
|
|||||||
the_receipt_has_been_successfully_deleted:
|
the_receipt_has_been_successfully_deleted:
|
||||||
'The receipt has been successfully deleted.',
|
'The receipt has been successfully deleted.',
|
||||||
|
|
||||||
|
bill_list: 'Bill List',
|
||||||
bills: 'Bills',
|
bills: 'Bills',
|
||||||
accept: 'Accept',
|
accept: 'Accept',
|
||||||
vendor_name: 'Vendor Name',
|
vendor_name: 'Vendor Name',
|
||||||
@@ -647,10 +664,19 @@ export default {
|
|||||||
bill_date_: 'Bill date',
|
bill_date_: 'Bill date',
|
||||||
bill_number_: 'Bill number',
|
bill_number_: 'Bill number',
|
||||||
vendor_name_: 'Vendor name',
|
vendor_name_: 'Vendor name',
|
||||||
|
delete_bill: 'Delete Bill',
|
||||||
|
|
||||||
|
the_bill_has_been_successfully_edited:
|
||||||
|
'The bill #{number} has been successfully edited.',
|
||||||
|
|
||||||
the_bill_has_been_successfully_created:
|
the_bill_has_been_successfully_created:
|
||||||
'The bill has been successfully created.',
|
'The bill has been successfully created.',
|
||||||
|
|
||||||
|
the_bill_has_been_successfully_deleted:
|
||||||
|
'The bill has been successfully deleted.',
|
||||||
|
|
||||||
|
once_delete_this_bill_you_will_able_to_restore_it: `Once you delete this bill, you won\'t be able to restore it later. Are you sure you want to delete this bill?`,
|
||||||
|
|
||||||
edit_payment_receive: 'Edit Payment Receive',
|
edit_payment_receive: 'Edit Payment Receive',
|
||||||
new_payment_receive: 'New Payment Receive',
|
new_payment_receive: 'New Payment Receive',
|
||||||
payment_receives: 'Payment Receives',
|
payment_receives: 'Payment Receives',
|
||||||
@@ -659,7 +685,7 @@ export default {
|
|||||||
the_payment_receive_has_been_successfully_created:
|
the_payment_receive_has_been_successfully_created:
|
||||||
'The payment receive has been successfully created.',
|
'The payment receive has been successfully created.',
|
||||||
|
|
||||||
select_invoice:'Select Invoice',
|
select_invoice: 'Select Invoice',
|
||||||
|
|
||||||
payment_mades: 'Payment Mades',
|
payment_mades: 'Payment Mades',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -220,13 +220,13 @@ export default [
|
|||||||
}),
|
}),
|
||||||
breadcrumb: 'New Estimates',
|
breadcrumb: 'New Estimates',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: `/estimates`,
|
path: `/estimates`,
|
||||||
// component: LazyLoader({
|
component: LazyLoader({
|
||||||
// loader: () => import('containers/Sales/EstimatesList'),
|
loader: () => import('containers/Sales/Estimate/EstimateList'),
|
||||||
// }),
|
}),
|
||||||
// breadcrumb: 'Estimates',
|
breadcrumb: 'Estimates List',
|
||||||
// },
|
},
|
||||||
|
|
||||||
//Invoices
|
//Invoices
|
||||||
|
|
||||||
@@ -245,13 +245,13 @@ export default [
|
|||||||
}),
|
}),
|
||||||
breadcrumb: 'New Invoice',
|
breadcrumb: 'New Invoice',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path:`/invoices`,
|
path: `/invoices`,
|
||||||
// component:LazyLoader({
|
component: LazyLoader({
|
||||||
// loader:()=>import('containers/Sales/Invoice/Invoices')
|
loader: () => import('containers/Sales/Invoice/InvoiceList'),
|
||||||
// }),
|
}),
|
||||||
// breadcrumb: 'New Invoice',
|
breadcrumb: 'Invoices List',
|
||||||
// },
|
},
|
||||||
|
|
||||||
//Receipts
|
//Receipts
|
||||||
{
|
{
|
||||||
@@ -268,14 +268,13 @@ export default [
|
|||||||
}),
|
}),
|
||||||
breadcrumb: 'New Receipt',
|
breadcrumb: 'New Receipt',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: `/receipts`,
|
path: `/receipts`,
|
||||||
// component: LazyLoader({
|
component: LazyLoader({
|
||||||
// loader: () => import('containers/Sales/Receipt/Receipts'),
|
loader: () => import('containers/Sales/Receipt/ReceiptList'),
|
||||||
// }),
|
}),
|
||||||
// breadcrumb: 'New Receipt',
|
breadcrumb: 'Receipt List',
|
||||||
// }
|
},
|
||||||
|
|
||||||
|
|
||||||
// Payment Receives
|
// Payment Receives
|
||||||
|
|
||||||
@@ -285,7 +284,6 @@ export default [
|
|||||||
loader: () => import('containers/Sales/PaymentReceive/PaymentReceives'),
|
loader: () => import('containers/Sales/PaymentReceive/PaymentReceives'),
|
||||||
}),
|
}),
|
||||||
breadcrumb: 'Edit',
|
breadcrumb: 'Edit',
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: `/payment-receive/new`,
|
path: `/payment-receive/new`,
|
||||||
@@ -293,24 +291,35 @@ export default [
|
|||||||
loader: () => import('containers/Sales/PaymentReceive/PaymentReceives'),
|
loader: () => import('containers/Sales/PaymentReceive/PaymentReceives'),
|
||||||
}),
|
}),
|
||||||
breadcrumb: 'New Payment Receive',
|
breadcrumb: 'New Payment Receive',
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Bills
|
//Bills
|
||||||
{
|
{
|
||||||
path: `/bill/:id/edit`,
|
path: `/bills/:id/edit`,
|
||||||
component: LazyLoader({
|
component: LazyLoader({
|
||||||
loader: () => import('containers/Purchases/Bills'),
|
loader: () => import('containers/Purchases/Bill/Bills'),
|
||||||
}),
|
}),
|
||||||
breadcrumb: 'Edit',
|
breadcrumb: 'Edit',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: `/bill/new`,
|
path: `/bills/new`,
|
||||||
component: LazyLoader({
|
component: LazyLoader({
|
||||||
loader: () => import('containers/Purchases/Bills'),
|
loader: () => import('containers/Purchases/Bill/Bills'),
|
||||||
}),
|
}),
|
||||||
breadcrumb: 'New Bill',
|
breadcrumb: 'New Bill',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: `/bills`,
|
||||||
|
component: LazyLoader({
|
||||||
|
loader: () => import('containers/Purchases/Bill/BillList'),
|
||||||
|
}),
|
||||||
|
breadcrumb: 'Bill List',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: `/receipts`,
|
||||||
|
component: LazyLoader({
|
||||||
|
loader: () => import('containers/Sales/Receipt/ReceiptList'),
|
||||||
|
}),
|
||||||
|
breadcrumb: 'Receipt List',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import t from 'store/types';
|
|||||||
export const fetchBillsTable = ({ query = {} }) => {
|
export const fetchBillsTable = ({ query = {} }) => {
|
||||||
return (dispatch, getState) =>
|
return (dispatch, getState) =>
|
||||||
new Promise((resolve, rejcet) => {
|
new Promise((resolve, rejcet) => {
|
||||||
const pageQuery = getState().bill.tableQuery;
|
const pageQuery = getState().bills.tableQuery;
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.BILLS_TABLE_LOADING,
|
type: t.BILLS_TABLE_LOADING,
|
||||||
@@ -12,7 +12,7 @@ export const fetchBillsTable = ({ query = {} }) => {
|
|||||||
loading: true,
|
loading: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
ApiService.get('bills', {
|
ApiService.get('purchases/bills', {
|
||||||
params: { ...pageQuery, ...query },
|
params: { ...pageQuery, ...query },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
@@ -54,9 +54,9 @@ export const fetchBillsTable = ({ query = {} }) => {
|
|||||||
export const deleteBill = ({ id }) => {
|
export const deleteBill = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resovle, reject) => {
|
new Promise((resovle, reject) => {
|
||||||
ApiService.delete(`bills/${id}`)
|
ApiService.delete(`purchases/bills/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({ type: t.BILL_DELETE });
|
dispatch({ type: t.BILL_DELETE, payload: { id } });
|
||||||
resovle(response);
|
resovle(response);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -71,7 +71,7 @@ export const submitBill = ({ form }) => {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
});
|
});
|
||||||
ApiService.post('bills', form)
|
ApiService.post('purchases/bills', form)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
@@ -92,7 +92,7 @@ export const submitBill = ({ form }) => {
|
|||||||
export const fetchBill = ({ id }) => {
|
export const fetchBill = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resovle, reject) => {
|
new Promise((resovle, reject) => {
|
||||||
ApiService.get(`bills/${id}`)
|
ApiService.get(`purchases/bills/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.BILL_SET,
|
type: t.BILL_SET,
|
||||||
@@ -117,7 +117,7 @@ export const editBill = (id, form) => {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
});
|
});
|
||||||
ApiService.post(`bills/${id}`, form)
|
ApiService.post(`purchases/bills/${id}`, form)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
import { createReducer } from '@reduxjs/toolkit';
|
||||||
|
import { createTableQueryReducers } from 'store/queryReducers';
|
||||||
|
|
||||||
|
import t from 'store/types';
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
items: {},
|
||||||
|
views: {},
|
||||||
|
loading: false,
|
||||||
|
currentViewId: -1,
|
||||||
|
tableQuery: {
|
||||||
|
page_size: 5,
|
||||||
|
page: 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultBill = {
|
||||||
|
entries: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const reducer = createReducer(initialState, {
|
||||||
|
[t.BILL_SET]: (state, action) => {
|
||||||
|
const { id, bill } = action.payload;
|
||||||
|
const _bill = state.items[id] || {};
|
||||||
|
|
||||||
|
state.items[id] = { ...defaultBill, ..._bill, ...bill };
|
||||||
|
},
|
||||||
|
[t.BILLS_TABLE_LOADING]: (state, action) => {
|
||||||
|
const { loading } = action.payload;
|
||||||
|
state.loading = loading;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.BILLS_SET_CURRENT_VIEW]: (state, action) => {
|
||||||
|
state.currentViewId = action.currentViewId;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.BILLS_ITEMS_SET]: (state, action) => {
|
||||||
|
const { bills } = action.payload;
|
||||||
|
const _bills = {};
|
||||||
|
bills.forEach((bill) => {
|
||||||
|
_bills[bill.id] = {
|
||||||
|
...defaultBill,
|
||||||
|
...bill,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
state.items = {
|
||||||
|
...state.items,
|
||||||
|
..._bills,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.BILL_DELETE]: (state, action) => {
|
||||||
|
const { id } = action.payload;
|
||||||
|
|
||||||
|
if (typeof state.items[id] !== 'undefined') {
|
||||||
|
delete state.items[id];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.BILLS_PAGE_SET]: (state, action) => {
|
||||||
|
const { customViewId, bills, pagination } = action.payload;
|
||||||
|
|
||||||
|
const viewId = customViewId || -1;
|
||||||
|
const view = state.views[viewId] || {};
|
||||||
|
|
||||||
|
state.views[viewId] = {
|
||||||
|
...view,
|
||||||
|
pages: {
|
||||||
|
...(state.views?.[viewId]?.pages || {}),
|
||||||
|
[pagination.page]: {
|
||||||
|
ids: bills.map((i) => i.id),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.BILLS_PAGINATION_SET]: (state, action) => {
|
||||||
|
const { pagination, customViewId } = action.payload;
|
||||||
|
|
||||||
|
const mapped = {
|
||||||
|
pageSize: parseInt(pagination.pageSize, 10),
|
||||||
|
page: parseInt(pagination.page, 10),
|
||||||
|
total: parseInt(pagination.total, 10),
|
||||||
|
};
|
||||||
|
const paginationMeta = {
|
||||||
|
...mapped,
|
||||||
|
pagesCount: Math.ceil(mapped.total / mapped.pageSize),
|
||||||
|
pageIndex: Math.max(mapped.page - 1, 0),
|
||||||
|
};
|
||||||
|
state.views = {
|
||||||
|
...state.views,
|
||||||
|
[customViewId]: {
|
||||||
|
...(state.views?.[customViewId] || {}),
|
||||||
|
paginationMeta,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default createTableQueryReducers('bills', reducer);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,52 @@
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||||
|
|
||||||
const billByIdSelector = (state, props) => state.bills.items[props.billId];
|
const billTableQuery = (state) => {
|
||||||
|
return state.bills.tableQuery;
|
||||||
|
};
|
||||||
|
|
||||||
export const getBillById = () =>
|
export const getBillTableQuery = createSelector(
|
||||||
createSelector(billByIdSelector, (_bill) => _bill);
|
paginationLocationQuery,
|
||||||
|
billTableQuery,
|
||||||
|
(locationQuery, tableQuery) => {
|
||||||
|
return {
|
||||||
|
...locationQuery,
|
||||||
|
...tableQuery,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const billPageSelector = (state, props, query) => {
|
||||||
|
const viewId = state.bills.currentViewId;
|
||||||
|
return state.bills.views?.[viewId]?.pages?.[query.page];
|
||||||
|
};
|
||||||
|
|
||||||
|
const billItemsSelector = (state) => {
|
||||||
|
return state.bills.items;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBillCurrentPageFactory = () =>
|
||||||
|
createSelector(billPageSelector, billItemsSelector, (billPage, billItems) => {
|
||||||
|
return typeof billPage === 'object'
|
||||||
|
? pickItemsFromIds(billItems, billPage.ids) || []
|
||||||
|
: [];
|
||||||
|
});
|
||||||
|
|
||||||
|
const billByIdSelector = (state, props) => {
|
||||||
|
return state.bills.items[props.billId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBillByIdFactory = () =>
|
||||||
|
createSelector(billByIdSelector, (bill) => {
|
||||||
|
return bill;
|
||||||
|
});
|
||||||
|
|
||||||
|
const billPaginationSelector = (state, props) => {
|
||||||
|
const viewId = state.bills.currentViewId;
|
||||||
|
return state.bills.views?.[viewId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getBillPaginationMetaFactory = () =>
|
||||||
|
createSelector(billPaginationSelector, (billPage) => {
|
||||||
|
return billPage?.paginationMeta || {};
|
||||||
|
});
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const submitEstimate = ({ form }) => {
|
|||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
});
|
});
|
||||||
ApiService.post('sales/estimates', form)
|
ApiService.post('sales/estimates', form)
|
||||||
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
@@ -32,7 +33,7 @@ export const editEstimate = (id, form) => {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
});
|
});
|
||||||
ApiService.post(`estimates/${id}`, form)
|
ApiService.post(`sales/estimates/${id}`, form)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
@@ -54,9 +55,12 @@ export const editEstimate = (id, form) => {
|
|||||||
export const deleteEstimate = ({ id }) => {
|
export const deleteEstimate = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resovle, reject) => {
|
new Promise((resovle, reject) => {
|
||||||
ApiService.delete(`estimates/${id}`)
|
ApiService.delete(`sales/estimates/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({ type: t.ESTIMATE_DELETE });
|
dispatch({
|
||||||
|
type: t.ESTIMATE_DELETE,
|
||||||
|
payload: { id },
|
||||||
|
});
|
||||||
resovle(response);
|
resovle(response);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -68,8 +72,9 @@ export const deleteEstimate = ({ id }) => {
|
|||||||
export const fetchEstimate = ({ id }) => {
|
export const fetchEstimate = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resovle, reject) => {
|
new Promise((resovle, reject) => {
|
||||||
ApiService.get(`estimate/${id}`)
|
ApiService.get(`sales/estimates/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ESTIMATE_SET,
|
type: t.ESTIMATE_SET,
|
||||||
payload: {
|
payload: {
|
||||||
@@ -90,36 +95,36 @@ export const fetchEstimate = ({ id }) => {
|
|||||||
export const fetchEstimatesTable = ({ query = {} }) => {
|
export const fetchEstimatesTable = ({ query = {} }) => {
|
||||||
return (dispatch, getState) =>
|
return (dispatch, getState) =>
|
||||||
new Promise((resolve, rejcet) => {
|
new Promise((resolve, rejcet) => {
|
||||||
const pageQuery = getState().estimates.tableQuery;
|
const pageQuery = getState().sales_estimates.tableQuery;
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ESTIMATES_TABLE_LOADING,
|
type: t.ESTIMATES_TABLE_LOADING,
|
||||||
payload: {
|
payload: {
|
||||||
loading: true,
|
loading: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
ApiService.get('estimates', {
|
ApiService.get('sales/estimates', {
|
||||||
params: { ...pageQuery, ...query },
|
params: { ...pageQuery, ...query },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
// debugger;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ESTIMATES_PAGE_SET,
|
type: t.ESTIMATES_PAGE_SET,
|
||||||
payload: {
|
payload: {
|
||||||
estimates: response.data.estimates.results,
|
sales_estimates: response.data.sales_estimates.results,
|
||||||
pagination: response.data.estimates.pagination,
|
pagination: response.data.sales_estimates.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId: response.data.customViewId || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ESTIMATES_ITEMS_SET,
|
type: t.ESTIMATES_ITEMS_SET,
|
||||||
payload: {
|
payload: {
|
||||||
estimates: response.data.estimates.results,
|
sales_estimates: response.data.sales_estimates.results,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ESTIMATES_PAGINATION_SET,
|
type: t.ESTIMATES_PAGINATION_SET,
|
||||||
payload: {
|
payload: {
|
||||||
pagination: response.data.estimates.pagination,
|
pagination: response.data.sales_estimates.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId: response.data.customViewId || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,27 +8,28 @@ const initialState = {
|
|||||||
views: {},
|
views: {},
|
||||||
loading: false,
|
loading: false,
|
||||||
tableQuery: {
|
tableQuery: {
|
||||||
page_size: 12,
|
page_size: 5,
|
||||||
page: 1,
|
page: 1,
|
||||||
},
|
},
|
||||||
currentViewId: -1,
|
currentViewId: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultEstimate = {
|
const defaultEstimate = {
|
||||||
products: [],
|
entries: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const reducer = createReducer(initialState, {
|
const reducer = createReducer(initialState, {
|
||||||
[t.ESTIMATE_SET]: (state, action) => {
|
[t.ESTIMATE_SET]: (state, action) => {
|
||||||
const { id, estiamate } = action.payload;
|
const { id, estimate } = action.payload;
|
||||||
const _estimate = state.items[id] || {};
|
const _estimate = state.items[id] || {};
|
||||||
|
|
||||||
state.items[id] = { ...defaultEstimate, ..._estimate, ...estiamate };
|
state.items[id] = { ...defaultEstimate, ..._estimate, ...estimate };
|
||||||
},
|
},
|
||||||
|
|
||||||
[t.ESTIMATES_ITEMS_SET]: (state, action) => {
|
[t.ESTIMATES_ITEMS_SET]: (state, action) => {
|
||||||
const { estiamates } = action.payload;
|
const { sales_estimates } = action.payload;
|
||||||
const _estimates = {};
|
const _estimates = {};
|
||||||
estiamates.forEach((estimate) => {
|
sales_estimates.forEach((estimate) => {
|
||||||
_estimates[estimate.id] = {
|
_estimates[estimate.id] = {
|
||||||
...defaultEstimate,
|
...defaultEstimate,
|
||||||
...estimate,
|
...estimate,
|
||||||
@@ -58,7 +59,7 @@ const reducer = createReducer(initialState, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[t.ESTIMATES_PAGE_SET]: (state, action) => {
|
[t.ESTIMATES_PAGE_SET]: (state, action) => {
|
||||||
const { customViewId, estimates, pagination } = action.payload;
|
const { customViewId, sales_estimates, pagination } = action.payload;
|
||||||
|
|
||||||
const viewId = customViewId || -1;
|
const viewId = customViewId || -1;
|
||||||
const view = state.views[viewId] || {};
|
const view = state.views[viewId] || {};
|
||||||
@@ -68,7 +69,7 @@ const reducer = createReducer(initialState, {
|
|||||||
pages: {
|
pages: {
|
||||||
...(state.views?.[viewId]?.pages || {}),
|
...(state.views?.[viewId]?.pages || {}),
|
||||||
[pagination.page]: {
|
[pagination.page]: {
|
||||||
ids: estimates.map((i) => i.id),
|
ids: sales_estimates.map((i) => i.id),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -98,8 +99,8 @@ const reducer = createReducer(initialState, {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default createTableQueryReducers('estimates', reducer);
|
export default createTableQueryReducers('sales_estimates', reducer);
|
||||||
|
|
||||||
export const getEstimateById = (state, id) => {
|
export const getEstimateById = (state, id) => {
|
||||||
return state.estiamates.items[id];
|
return state.sales_estimates.items[id];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,44 +1,54 @@
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||||
|
|
||||||
const estimateTableQuery = (state) => state.estimates.tableQuery;
|
const estimateTableQuery = (state) => {
|
||||||
|
return state.sales_estimates.tableQuery;
|
||||||
|
};
|
||||||
|
|
||||||
export const getEstimatesTableQuery = createSelector(
|
export const getEstimatesTableQuery = createSelector(
|
||||||
paginationLocationQuery,
|
paginationLocationQuery,
|
||||||
estimateTableQuery,
|
estimateTableQuery,
|
||||||
(location, query) => ({
|
(locationQuery, tableQuery) => {
|
||||||
...location,
|
return {
|
||||||
...query,
|
...locationQuery,
|
||||||
}),
|
...tableQuery,
|
||||||
|
};
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const estimatesSelector = (state, props, query) => {
|
const estimatesPageSelector = (state, props, query) => {
|
||||||
const viewId = state.estimates.currentViewId;
|
const viewId = state.sales_estimates.currentViewId;
|
||||||
return state.estimates.views?.[viewId]?.pages?.[query.page];
|
return state.sales_estimates.views?.[viewId]?.pages?.[query.page];
|
||||||
};
|
};
|
||||||
|
|
||||||
const EstimateItemsSelector = (state) => state.estimates.items;
|
const estimateItemsSelector = (state) => state.sales_estimates.items;
|
||||||
|
|
||||||
export const getEstimateCurrentPage = () =>
|
export const getEstimateCurrentPageFactory = () =>
|
||||||
createSelector(estimatesSelector, EstimateItemsSelector, (page, items) => {
|
createSelector(
|
||||||
return typeof page === 'object'
|
estimatesPageSelector,
|
||||||
? pickItemsFromIds(items, page.ids) || []
|
estimateItemsSelector,
|
||||||
: [];
|
(estimatePage, estimateItems) => {
|
||||||
});
|
return typeof estimatePage === 'object'
|
||||||
|
? pickItemsFromIds(estimateItems, estimatePage.ids) || []
|
||||||
|
: [];
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const estimateByIdSelector = (state, props) => state.estimates.items;
|
const estimateByIdSelector = (state, props) => {
|
||||||
|
return state.sales_estimates.items[props.estimateId];
|
||||||
|
};
|
||||||
|
|
||||||
export const getEstimateByIdFactory = () =>
|
export const getEstimateByIdFactory = () =>
|
||||||
createSelector(estimateByIdSelector, (estimate) => {
|
createSelector(estimateByIdSelector, (estimate) => {
|
||||||
return estimate;
|
return estimate;
|
||||||
});
|
});
|
||||||
|
|
||||||
const paginationSelector = (state, props) => {
|
const estimatesPaginationSelector = (state, props) => {
|
||||||
const viewId = state.estimates.currentViewId;
|
const viewId = state.sales_estimates.currentViewId;
|
||||||
return state.estimates.views?.[viewId];
|
return state.sales_estimates.views?.[viewId];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getEstimatesPaginationMetaFactory = () =>
|
export const getEstimatesPaginationMetaFactory = () =>
|
||||||
createSelector(paginationSelector, (estimatePage) => {
|
createSelector(estimatesPaginationSelector, (estimatePage) => {
|
||||||
return estimatePage?.paginationMeta || {};
|
return estimatePage?.paginationMeta || {};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,9 +29,12 @@ export const submitInvoice = ({ form }) => {
|
|||||||
export const deleteInvoice = ({ id }) => {
|
export const deleteInvoice = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resovle, reject) => {
|
new Promise((resovle, reject) => {
|
||||||
ApiService.delete(`invoice/${id}`)
|
ApiService.delete(`sales/invoices/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({ type: t.INVOICE_DELETE });
|
dispatch({
|
||||||
|
type: t.INVOICE_DELETE,
|
||||||
|
payload: { id },
|
||||||
|
});
|
||||||
resovle(response);
|
resovle(response);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -46,7 +49,7 @@ export const editInvoice = (id, form) => {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
});
|
});
|
||||||
ApiService.post(`invoice/${id}`, form)
|
ApiService.post(`sales/invoices/${id}`, form)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
@@ -64,39 +67,39 @@ export const editInvoice = (id, form) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
export const fetchInvoicesTable = ({ query = {} }) => {
|
|
||||||
return (dispatch, getState) =>
|
|
||||||
new Promise((resolve, rejcet) => {
|
|
||||||
const pageQuery = getState().invoices.tableQuery;
|
|
||||||
|
|
||||||
|
export const fetchInvoicesTable = ({ query } = {}) => {
|
||||||
|
return (dispatch, getState) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const pageQuery = getState().sales_invoices.tableQuery;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICES_TABLE_LOADING,
|
type: t.INVOICES_TABLE_LOADING,
|
||||||
payload: {
|
payload: {
|
||||||
loading: true,
|
loading: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
ApiService.get('invoices', {
|
ApiService.get('sales/invoices', {
|
||||||
params: { ...pageQuery, ...query },
|
params: { ...pageQuery, ...query },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICES_PAGE_SET,
|
type: t.INVOICES_PAGE_SET,
|
||||||
payload: {
|
payload: {
|
||||||
invoices: response.data.invoices.results,
|
sales_invoices: response.data.sales_invoices.results,
|
||||||
pagination: response.data.invoices.pagination,
|
pagination: response.data.sales_invoices.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId: response.data.customViewId || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICES_ITEMS_SET,
|
type: t.INVOICES_ITEMS_SET,
|
||||||
payload: {
|
payload: {
|
||||||
invoices: response.data.invoices.results,
|
sales_invoices: response.data.sales_invoices.results,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICES_PAGINATION_SET,
|
type: t.INVOICES_PAGINATION_SET,
|
||||||
payload: {
|
payload: {
|
||||||
pagination: response.data.invoices.pagination,
|
pagination: response.data.sales_invoices.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId: response.data.customViewId || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -109,7 +112,7 @@ export const fetchInvoicesTable = ({ query = {} }) => {
|
|||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
rejcet(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -117,13 +120,13 @@ export const fetchInvoicesTable = ({ query = {} }) => {
|
|||||||
export const fetchInvoice = ({ id }) => {
|
export const fetchInvoice = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resovle, reject) => {
|
new Promise((resovle, reject) => {
|
||||||
ApiService.get(`invoices/${id}`)
|
ApiService.get(`sales/invoices/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.INVOICE_SET,
|
type: t.INVOICE_SET,
|
||||||
payload: {
|
payload: {
|
||||||
id,
|
id,
|
||||||
invoice: response.data.invoice,
|
sale_invoice: response.data.sale_invoice,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
resovle(response);
|
resovle(response);
|
||||||
|
|||||||
@@ -7,26 +7,99 @@ const initialState = {
|
|||||||
items: {},
|
items: {},
|
||||||
views: {},
|
views: {},
|
||||||
loading: false,
|
loading: false,
|
||||||
|
currentViewId: -1,
|
||||||
tableQuery: {
|
tableQuery: {
|
||||||
page_size: 12,
|
page_size: 5,
|
||||||
page: 1,
|
page: 1,
|
||||||
},
|
},
|
||||||
currentViewId: -1,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultInvoice = {
|
const defaultInvoice = {
|
||||||
entires: [],
|
entries: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const reducer = createReducer(initialState, {
|
const reducer = createReducer(initialState, {
|
||||||
[t.INVOICE_SET]:(state,actio)=>{
|
[t.INVOICE_SET]: (state, action) => {
|
||||||
|
const { id, sale_invoice } = action.payload;
|
||||||
|
const _invoice = state.items[id] || {};
|
||||||
|
|
||||||
const {id,INVOICE_SET} = action.payload;
|
state.items[id] = { ...defaultInvoice, ..._invoice, ...sale_invoice };
|
||||||
|
},
|
||||||
|
|
||||||
}
|
[t.INVOICES_ITEMS_SET]: (state, action) => {
|
||||||
|
const { sales_invoices } = action.payload;
|
||||||
|
const _invoices = {};
|
||||||
|
sales_invoices.forEach((invoice) => {
|
||||||
|
_invoices[invoice.id] = {
|
||||||
|
...defaultInvoice,
|
||||||
|
...invoice,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
state.items = {
|
||||||
|
...state.items,
|
||||||
|
..._invoices,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.INVOICES_TABLE_LOADING]: (state, action) => {
|
||||||
|
const { loading } = action.payload;
|
||||||
|
state.loading = loading;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.INVOICES_SET_CURRENT_VIEW]: (state, action) => {
|
||||||
|
state.currentViewId = action.currentViewId;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.INVOICE_DELETE]: (state, action) => {
|
||||||
|
const { id } = action.payload;
|
||||||
|
|
||||||
|
if (typeof state.items[id] !== 'undefined') {
|
||||||
|
delete state.items[id];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.INVOICES_PAGE_SET]: (state, action) => {
|
||||||
|
const { customViewId, sales_invoices, pagination } = action.payload;
|
||||||
|
|
||||||
|
const viewId = customViewId || -1;
|
||||||
|
const view = state.views[viewId] || {};
|
||||||
|
|
||||||
|
state.views[viewId] = {
|
||||||
|
...view,
|
||||||
|
pages: {
|
||||||
|
...(state.views?.[viewId]?.pages || {}),
|
||||||
|
[pagination.page]: {
|
||||||
|
ids: sales_invoices.map((i) => i.id),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.INVOICES_PAGINATION_SET]: (state, action) => {
|
||||||
|
const { pagination, customViewId } = action.payload;
|
||||||
|
|
||||||
|
const mapped = {
|
||||||
|
pageSize: parseInt(pagination.pageSize, 10),
|
||||||
|
page: parseInt(pagination.page, 10),
|
||||||
|
total: parseInt(pagination.total, 10),
|
||||||
|
};
|
||||||
|
const paginationMeta = {
|
||||||
|
...mapped,
|
||||||
|
pagesCount: Math.ceil(mapped.total / mapped.pageSize),
|
||||||
|
pageIndex: Math.max(mapped.page - 1, 0),
|
||||||
|
};
|
||||||
|
state.views = {
|
||||||
|
...state.views,
|
||||||
|
[customViewId]: {
|
||||||
|
...(state.views?.[customViewId] || {}),
|
||||||
|
paginationMeta,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default createTableQueryReducers('sales_invoices', reducer);
|
||||||
|
|
||||||
|
export const getInvoiceById = (state, id) => {
|
||||||
|
return state.sales_invoices.items[id];
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,9 +1,54 @@
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||||
|
|
||||||
const invoiceByIdSelector = (state, props) =>
|
const invoiceTableQuery = (state) => state.sales_invoices.tableQuery;
|
||||||
state.invoices.items[props.invoiceId];
|
|
||||||
|
|
||||||
export const getInvoiceById = () =>
|
export const getInvoiceTableQuery = createSelector(
|
||||||
createSelector(invoiceByIdSelector, (_invoice) => {
|
paginationLocationQuery,
|
||||||
return _invoice;
|
invoiceTableQuery,
|
||||||
|
(locationQuery, tableQuery) => {
|
||||||
|
return {
|
||||||
|
...locationQuery,
|
||||||
|
...tableQuery,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const invoicesPageSelector = (state, props, query) => {
|
||||||
|
const viewId = state.sales_invoices.currentViewId;
|
||||||
|
return state.sales_invoices.views?.[viewId]?.pages?.[query.page];
|
||||||
|
};
|
||||||
|
|
||||||
|
const invoicesItemsSelector = (state) => {
|
||||||
|
return state.sales_invoices.items;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getInvoiceCurrentPageFactory = () =>
|
||||||
|
createSelector(
|
||||||
|
invoicesPageSelector,
|
||||||
|
invoicesItemsSelector,
|
||||||
|
(invoicePage, invoicesItems) => {
|
||||||
|
return typeof invoicePage === 'object'
|
||||||
|
? pickItemsFromIds(invoicesItems, invoicePage.ids) || []
|
||||||
|
: [];
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const invoicesByIdSelector = (state, props) => {
|
||||||
|
return state.sales_invoices.items[props.invoiceId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getInvoiecsByIdFactory = () =>
|
||||||
|
createSelector(invoicesByIdSelector, (invoice) => {
|
||||||
|
return invoice;
|
||||||
|
});
|
||||||
|
|
||||||
|
const invoicesPaginationSelector = (state, props) => {
|
||||||
|
const viewId = state.sales_invoices.currentViewId;
|
||||||
|
return state.sales_invoices.views?.[viewId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getInvoicePaginationMetaFactory = () =>
|
||||||
|
createSelector(invoicesPaginationSelector, (invoicePage) => {
|
||||||
|
return invoicePage?.paginationMeta || {};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,9 +28,12 @@ export const submitReceipt = ({ form }) => {
|
|||||||
export const deleteReceipt = ({ id }) => {
|
export const deleteReceipt = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resovle, reject) => {
|
new Promise((resovle, reject) => {
|
||||||
ApiService.delete(`receipts/${id}`)
|
ApiService.delete(`sales/receipts/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({ type: t.RECEIPT_DELETE });
|
dispatch({
|
||||||
|
type: t.RECEIPT_DELETE,
|
||||||
|
payload: { id },
|
||||||
|
});
|
||||||
resovle(response);
|
resovle(response);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -45,7 +48,7 @@ export const editReceipt = (id, form) => {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
});
|
});
|
||||||
ApiService.delete(`receipt/${id}`, form)
|
ApiService.post(`sales/receipts/${id}`, form)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
@@ -66,7 +69,7 @@ export const editReceipt = (id, form) => {
|
|||||||
export const fetchReceipt = ({ id }) => {
|
export const fetchReceipt = ({ id }) => {
|
||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resovle, reject) => {
|
new Promise((resovle, reject) => {
|
||||||
ApiService.get(`receipt/${id}`)
|
ApiService.get(`sales/receipts/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.RECEIPT_SET,
|
type: t.RECEIPT_SET,
|
||||||
@@ -88,36 +91,35 @@ export const fetchReceipt = ({ id }) => {
|
|||||||
export const fetchReceiptsTable = ({ query = {} }) => {
|
export const fetchReceiptsTable = ({ query = {} }) => {
|
||||||
return (dispatch, getState) =>
|
return (dispatch, getState) =>
|
||||||
new Promise((resolve, rejcet) => {
|
new Promise((resolve, rejcet) => {
|
||||||
const pageQuery = getState().receipt.tableQuery;
|
const pageQuery = getState().sales_receipts.tableQuery;
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.RECEIPTS_TABLE_LOADING,
|
type: t.RECEIPTS_TABLE_LOADING,
|
||||||
payload: {
|
payload: {
|
||||||
loading: true,
|
loading: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
ApiService.get('receipts', {
|
ApiService.get('sales/receipts', {
|
||||||
params: { ...pageQuery, ...query },
|
params: { ...pageQuery, ...query },
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.RECEIPTS_PAGE_SET,
|
type: t.RECEIPTS_PAGE_SET,
|
||||||
payload: {
|
payload: {
|
||||||
receipts: response.data.receipts.results,
|
sales_receipts: response.data.sales_receipts.results,
|
||||||
pagination: response.data.receipts.pagination,
|
pagination: response.data.sales_receipts.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId: response.data.customViewId || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.RECEIPTS_ITEMS_SET,
|
type: t.RECEIPTS_ITEMS_SET,
|
||||||
payload: {
|
payload: {
|
||||||
receipts: response.data.receipts.results,
|
sales_receipts: response.data.sales_receipts.results,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.RECEIPTS_PAGINATION_SET,
|
type: t.RECEIPTS_PAGINATION_SET,
|
||||||
payload: {
|
payload: {
|
||||||
pagination: response.data.receipts.pagination,
|
pagination: response.data.sales_receipts.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId: response.data.customViewId || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { createReducer } from '@reduxjs/toolkit';
|
||||||
|
import { createTableQueryReducers } from 'store/queryReducers';
|
||||||
|
import t from 'store/types';
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
items: {},
|
||||||
|
views: {},
|
||||||
|
loading: false,
|
||||||
|
tableQuery: {
|
||||||
|
page_size: 5,
|
||||||
|
page: 1,
|
||||||
|
},
|
||||||
|
currentViewId: -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultReceipt = {
|
||||||
|
entries: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const reducer = createReducer(initialState, {
|
||||||
|
[t.RECEIPT_SET]: (state, action) => {
|
||||||
|
const { id, receipt } = action.payload;
|
||||||
|
const _receipt = state.items[id] || {};
|
||||||
|
state.items[id] = { ...defaultReceipt, ..._receipt, ...receipt };
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.RECEIPTS_ITEMS_SET]: (state, action) => {
|
||||||
|
const { sales_receipts } = action.payload;
|
||||||
|
const _receipts = {};
|
||||||
|
sales_receipts.forEach((receipt) => {
|
||||||
|
_receipts[receipt.id] = {
|
||||||
|
...defaultReceipt,
|
||||||
|
...receipt,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
state.items = {
|
||||||
|
...state.items,
|
||||||
|
..._receipts,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.RECEIPTS_TABLE_LOADING]: (state, action) => {
|
||||||
|
const { loading } = action.payload;
|
||||||
|
state.loading = loading;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.RECEIPT_DELETE]: (state, action) => {
|
||||||
|
const { id } = action.payload;
|
||||||
|
if (typeof state.items[id] !== 'undefined') {
|
||||||
|
delete state.items[id];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.RECEIPTS_SET_CURRENT_VIEW]: (state, action) => {
|
||||||
|
state.currentViewId = action.currentViewId;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.RECEIPTS_PAGE_SET]: (state, action) => {
|
||||||
|
const { customViewId, sales_receipts, pagination } = action.payload;
|
||||||
|
|
||||||
|
const viewId = customViewId || -1;
|
||||||
|
const view = state.views[viewId] || {};
|
||||||
|
|
||||||
|
state.views[viewId] = {
|
||||||
|
...view,
|
||||||
|
pages: {
|
||||||
|
...(state.views?.[viewId]?.pages || {}),
|
||||||
|
[pagination.page]: {
|
||||||
|
ids: sales_receipts.map((i) => i.id),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.RECEIPTS_PAGINATION_SET]: (state, action) => {
|
||||||
|
const { pagination, customViewId } = action.payload;
|
||||||
|
|
||||||
|
const mapped = {
|
||||||
|
pageSize: parseInt(pagination.pageSize, 10),
|
||||||
|
page: parseInt(pagination.page, 10),
|
||||||
|
total: parseInt(pagination.total, 10),
|
||||||
|
};
|
||||||
|
const paginationMeta = {
|
||||||
|
...mapped,
|
||||||
|
pagesCount: Math.ceil(mapped.total / mapped.pageSize),
|
||||||
|
pageIndex: Math.max(mapped.page - 1, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
state.views = {
|
||||||
|
...state.views,
|
||||||
|
[customViewId]: {
|
||||||
|
...(state.views?.[customViewId] || {}),
|
||||||
|
paginationMeta,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default createTableQueryReducers('sales_receipts', reducer);
|
||||||
|
|
||||||
|
export const getReceiptById = (state, id) => {
|
||||||
|
return state.receipts.items[id];
|
||||||
|
};
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||||
|
|
||||||
|
const receiptsPageSelector = (state, props, query) => {
|
||||||
|
const viewId = state.sales_receipts.currentViewId;
|
||||||
|
return state.sales_receipts.views?.[viewId]?.pages?.[query.page];
|
||||||
|
};
|
||||||
|
|
||||||
|
const receiptItemsSelector = (state) => {
|
||||||
|
return state.sales_receipts.items;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getReceiptCurrentPageFactory = () =>
|
||||||
|
createSelector(
|
||||||
|
receiptsPageSelector,
|
||||||
|
receiptItemsSelector,
|
||||||
|
(receiptPage, receiptItems) => {
|
||||||
|
return typeof receiptPage === 'object'
|
||||||
|
? pickItemsFromIds(receiptItems, receiptPage.ids) || []
|
||||||
|
: [];
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const receiptTableQuery = (state) => {
|
||||||
|
return state.sales_receipts.tableQuery;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getReceiptsTableQuery = createSelector(
|
||||||
|
paginationLocationQuery,
|
||||||
|
receiptTableQuery,
|
||||||
|
(locationQuery, tableQuery) => {
|
||||||
|
return {
|
||||||
|
...locationQuery,
|
||||||
|
...tableQuery,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const receiptByIdSelector = (state, props) => {
|
||||||
|
return state.sales_receipts.items[props.receiptId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getReceiptByIdFactory = () =>
|
||||||
|
createSelector(receiptByIdSelector, (receipt) => {
|
||||||
|
return receipt;
|
||||||
|
});
|
||||||
|
|
||||||
|
const receiptsPaginationSelector = (state, props) => {
|
||||||
|
const viewId = state.sales_receipts.currentViewId;
|
||||||
|
return state.sales_receipts.views?.[viewId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getReceiptsPaginationMetaFactory = () =>
|
||||||
|
createSelector(receiptsPaginationSelector, (receiptPage) => {
|
||||||
|
return receiptPage?.paginationMeta || {};
|
||||||
|
});
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ import globalSearch from './search/search.reducer';
|
|||||||
import exchangeRates from './ExchangeRate/exchange.reducer';
|
import exchangeRates from './ExchangeRate/exchange.reducer';
|
||||||
import globalErrors from './globalErrors/globalErrors.reducer';
|
import globalErrors from './globalErrors/globalErrors.reducer';
|
||||||
import customers from './customers/customers.reducer';
|
import customers from './customers/customers.reducer';
|
||||||
import estimates from './Estimate/estimates.reducer';
|
import sales_estimates from './Estimate/estimates.reducer';
|
||||||
|
import sales_invoices from './Invoice/invoices.reducer';
|
||||||
|
import sales_receipts from './receipt/receipt.reducer';
|
||||||
|
import bills from './Bills/bills.reducer';
|
||||||
|
import vendors from './vendors/vendors.reducer';
|
||||||
|
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
authentication,
|
authentication,
|
||||||
@@ -39,5 +43,9 @@ export default combineReducers({
|
|||||||
exchangeRates,
|
exchangeRates,
|
||||||
globalErrors,
|
globalErrors,
|
||||||
customers,
|
customers,
|
||||||
estimates
|
sales_estimates,
|
||||||
|
sales_invoices,
|
||||||
|
sales_receipts,
|
||||||
|
bills,
|
||||||
|
vendors,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import invoices from './Invoice/invoices.types';
|
|||||||
import receipts from './receipt/receipt.type';
|
import receipts from './receipt/receipt.type';
|
||||||
import bills from './Bills/bills.type';
|
import bills from './Bills/bills.type';
|
||||||
import paymentReceives from './PaymentReceive/paymentReceive.type';
|
import paymentReceives from './PaymentReceive/paymentReceive.type';
|
||||||
|
import vendors from './vendors/vendors.types';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
...authentication,
|
...authentication,
|
||||||
@@ -48,4 +49,5 @@ export default {
|
|||||||
...receipts,
|
...receipts,
|
||||||
...bills,
|
...bills,
|
||||||
...paymentReceives,
|
...paymentReceives,
|
||||||
|
...vendors,
|
||||||
};
|
};
|
||||||
|
|||||||
118
client/src/store/vendors/vendors.actions.js
vendored
Normal file
118
client/src/store/vendors/vendors.actions.js
vendored
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
import ApiService from 'services/ApiService';
|
||||||
|
import t from 'store/types';
|
||||||
|
|
||||||
|
export const fetchVendorsTable = ({ query }) => {
|
||||||
|
return (dispatch, getState) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const pageQuery = getState().vendors.tableQuery;
|
||||||
|
dispatch({
|
||||||
|
type: t.VENDORS_TABLE_LOADING,
|
||||||
|
payload: { loading: true },
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
|
});
|
||||||
|
ApiService.get(`vendors`, { params: { ...pageQuery, ...query } })
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.VENDORS_PAGE_SET,
|
||||||
|
payload: {
|
||||||
|
vendors: response.data.vendors.results,
|
||||||
|
pagination: response.data.vendors.pagination,
|
||||||
|
customViewId: response.data.customViewId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: t.VENDORS_ITEMS_SET,
|
||||||
|
payload: {
|
||||||
|
vendors: response.data.vendors.results,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: t.VENDORS_PAGINATION_SET,
|
||||||
|
payload: {
|
||||||
|
pagination: response.data.vendors.pagination,
|
||||||
|
customViewId: response.data.customViewId || -1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: t.VENDORS_TABLE_LOADING,
|
||||||
|
payload: { loading: false },
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const editVendor = ({ form, id }) => {
|
||||||
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
|
});
|
||||||
|
|
||||||
|
ApiService.post(`vendors/${id}`, form)
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const { response } = error;
|
||||||
|
const { data } = response;
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
});
|
||||||
|
reject(data?.errors);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteVendor = ({ id }) => {
|
||||||
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
ApiService.delete(`vendors/${id}`)
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({ type: t.VENDOR_DELETE, payload: { id } });
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
reject(error.response.data.errors || []);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const submitVendor = ({ form }) => {
|
||||||
|
return (dispatch) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_LOADING,
|
||||||
|
});
|
||||||
|
|
||||||
|
ApiService.post('vendors', form)
|
||||||
|
.then((response) => {
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const { response } = error;
|
||||||
|
const { data } = response;
|
||||||
|
dispatch({
|
||||||
|
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
||||||
|
});
|
||||||
|
reject(data?.errors);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
96
client/src/store/vendors/vendors.reducer.js
vendored
Normal file
96
client/src/store/vendors/vendors.reducer.js
vendored
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import { createReducer } from '@reduxjs/toolkit';
|
||||||
|
import { createTableQueryReducers } from 'store/queryReducers';
|
||||||
|
|
||||||
|
import t from 'store/types';
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
items: {},
|
||||||
|
views: {},
|
||||||
|
loading: false,
|
||||||
|
tableQuery: {
|
||||||
|
page_size: 5,
|
||||||
|
page: 1,
|
||||||
|
},
|
||||||
|
currentViewId: -1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const reducer = createReducer(initialState, {
|
||||||
|
[t.VENDORS_TABLE_LOADING]: (state, action) => {
|
||||||
|
const { loading } = action.payload;
|
||||||
|
state.loading = loading;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.VENDORS_ITEMS_SET]: (state, action) => {
|
||||||
|
const { vendors } = action.payload;
|
||||||
|
const _vendors = {};
|
||||||
|
vendors.forEach((vendor) => {
|
||||||
|
_vendors[vendor.id] = {
|
||||||
|
...vendor,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
state.items = {
|
||||||
|
...state.items,
|
||||||
|
..._vendors,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.VENDORS_PAGE_SET]: (state, action) => {
|
||||||
|
const { customViewId, vendors, pagination } = action.payload;
|
||||||
|
|
||||||
|
const viewId = customViewId || -1;
|
||||||
|
const view = state.views[viewId] || {};
|
||||||
|
|
||||||
|
state.views[viewId] = {
|
||||||
|
...view,
|
||||||
|
pages: {
|
||||||
|
...(state.views?.[viewId]?.pages || {}),
|
||||||
|
[pagination.page]: {
|
||||||
|
ids: vendors.map((i) => i.id),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.VENDOR_DELETE]: (state, action) => {
|
||||||
|
const { id } = action.payload;
|
||||||
|
|
||||||
|
if (typeof state.items[id] !== 'undefined') {
|
||||||
|
delete state.items[id];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.VENDORS_SET_CURRENT_VIEW]: (state, action) => {
|
||||||
|
state.currentViewId = action.currentViewId;
|
||||||
|
},
|
||||||
|
|
||||||
|
[t.VENDORS_PAGINATION_SET]: (state, action) => {
|
||||||
|
const { pagination, customViewId } = action.payload;
|
||||||
|
|
||||||
|
const mapped = {
|
||||||
|
pageSize: parseInt(pagination.pageSize, 10),
|
||||||
|
page: parseInt(pagination.page, 10),
|
||||||
|
total: parseInt(pagination.total, 10),
|
||||||
|
};
|
||||||
|
const paginationMeta = {
|
||||||
|
...mapped,
|
||||||
|
pagesCount: Math.ceil(mapped.total / mapped.pageSize),
|
||||||
|
pageIndex: Math.max(mapped.page - 1, 0),
|
||||||
|
};
|
||||||
|
|
||||||
|
state.views = {
|
||||||
|
...state.views,
|
||||||
|
[customViewId]: {
|
||||||
|
...(state.views?.[customViewId] || {}),
|
||||||
|
paginationMeta,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
// [t.VENDOR_SET]: (state, action) => {
|
||||||
|
// const { id, vendor } = action.payload;
|
||||||
|
// const _venders = state.items[id] || {};
|
||||||
|
// state.items[id] = { ..._venders, ...vendor };
|
||||||
|
// },
|
||||||
|
});
|
||||||
|
|
||||||
|
export default createTableQueryReducers('vendors', reducer);
|
||||||
54
client/src/store/vendors/vendors.selectors.js
vendored
Normal file
54
client/src/store/vendors/vendors.selectors.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { pickItemsFromIds, paginationLocationQuery } from 'store/selectors';
|
||||||
|
|
||||||
|
const vendorsTableQuery = (state) => {
|
||||||
|
return state.vendors.tableQuery;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getVendorsTableQuery = createSelector(
|
||||||
|
paginationLocationQuery,
|
||||||
|
vendorsTableQuery,
|
||||||
|
(locationQuery, tableQuery) => {
|
||||||
|
return {
|
||||||
|
...locationQuery,
|
||||||
|
...tableQuery,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const vendorsPageSelector = (state, props, query) => {
|
||||||
|
const viewId = state.vendors.currentViewId;
|
||||||
|
return state.vendors.views?.[viewId]?.pages?.[query.page];
|
||||||
|
};
|
||||||
|
|
||||||
|
const vendorsItemsSelector = (state) => state.vendors.items;
|
||||||
|
|
||||||
|
export const getVendorCurrentPageFactory = () =>
|
||||||
|
createSelector(
|
||||||
|
vendorsPageSelector,
|
||||||
|
vendorsItemsSelector,
|
||||||
|
(vendorPage, vendorItems) => {
|
||||||
|
return typeof vendorPage === 'object'
|
||||||
|
? pickItemsFromIds(vendorItems, vendorPage.ids) || []
|
||||||
|
: [];
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const vendorsPaginationSelector = (state, props) => {
|
||||||
|
const viewId = state.vendors.currentViewId;
|
||||||
|
return state.vendors.views?.[viewId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getVendorsPaginationMetaFactory = () =>
|
||||||
|
createSelector(vendorsPaginationSelector, (vendorPage) => {
|
||||||
|
return vendorPage?.paginationMeta || {};
|
||||||
|
});
|
||||||
|
|
||||||
|
const vendorByIdSelector = (state, props) => {
|
||||||
|
return state.vendors.items[props.vendorId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getEstimateByIdFactory = () =>
|
||||||
|
createSelector(vendorByIdSelector, (vendor) => {
|
||||||
|
return vendor;
|
||||||
|
});
|
||||||
11
client/src/store/vendors/vendors.types.js
vendored
Normal file
11
client/src/store/vendors/vendors.types.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export default {
|
||||||
|
VENDORS_ITEMS_SET: 'VENDORS_ITEMS_SET',
|
||||||
|
VENDOR_SET: 'VENDOR_SET',
|
||||||
|
VENDORS_PAGE_SET: 'VENDORS_PAGE_SET',
|
||||||
|
VENDORS_TABLE_LOADING: 'VENDORS_TABLE_LOADING',
|
||||||
|
VENDORS_TABLE_QUERIES_ADD: 'VENDORS_TABLE_QUERIES_ADD',
|
||||||
|
VENDOR_DELETE: 'VENDOR_DELETE',
|
||||||
|
VENDORS_BULK_DELETE: 'VENDORS_BULK_DELETE',
|
||||||
|
VENDORS_PAGINATION_SET: 'VENDORS_PAGINATION_SET',
|
||||||
|
VENDORS_SET_CURRENT_VIEW: 'VENDORS_SET_CURRENT_VIEW',
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user