mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
WIP/ Feature : Estimate & Receipt & Bill & Invoice
This commit is contained in:
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);
|
||||
};
|
||||
Reference in New Issue
Block a user