mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
Merge pull request #224 from bigcapitalhq/abouhuolia/big-54-specific-items-filter-on-purchasessells-by-items-reports
fix(webapp): filter by customers, vendors and items in reports do not work
This commit is contained in:
@@ -1,43 +1,78 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useCallback } from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import { MenuItem } from '@blueprintjs/core';
|
import * as R from 'ramda';
|
||||||
import { MultiSelect } from '../MultiSelectTaggable';
|
import { FMultiSelect } from '../Forms';
|
||||||
|
import withDrawerActions from '@/containers/Drawer/withDrawerActions';
|
||||||
|
import { DRAWERS } from '@/constants/drawers';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contacts multi-select component.
|
* Contacts multi-select component.
|
||||||
*/
|
*/
|
||||||
export function ContactsMultiSelect({ ...multiSelectProps }) {
|
export function ContactsMultiSelect({ allowCreate, ...multiSelectProps }) {
|
||||||
// Filters accounts items.
|
// Maybe inject new item props to select component.
|
||||||
const filterContactsPredicater = useCallback(
|
const maybeCreateNewItemRenderer = allowCreate ? createNewItemRenderer : null;
|
||||||
(query, contact, _index, exactMatch) => {
|
const maybeCreateNewItemFromQuery = allowCreate
|
||||||
const normalizedTitle = contact.display_name.toLowerCase();
|
? createNewItemFromQuery
|
||||||
const normalizedQuery = query.toLowerCase();
|
: null;
|
||||||
|
|
||||||
if (exactMatch) {
|
|
||||||
return normalizedTitle === normalizedQuery;
|
|
||||||
} else {
|
|
||||||
return normalizedTitle.indexOf(normalizedQuery) >= 0;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MultiSelect
|
<FMultiSelect
|
||||||
itemRenderer={(contact, { selected, active, handleClick }) => (
|
valueAccessor={'id'}
|
||||||
<MenuItem
|
textAccessor={'display_name'}
|
||||||
active={active}
|
tagAccessor={'display_name'}
|
||||||
icon={selected ? 'tick' : 'blank'}
|
|
||||||
text={contact.display_name}
|
|
||||||
key={contact.id}
|
|
||||||
onClick={handleClick}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
fill={true}
|
fill={true}
|
||||||
itemPredicate={filterContactsPredicater}
|
createNewItemRenderer={maybeCreateNewItemRenderer}
|
||||||
tagRenderer={(item) => item.display_name}
|
createNewItemFromQuery={maybeCreateNewItemFromQuery}
|
||||||
{...multiSelectProps}
|
{...multiSelectProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customers multi-select component.
|
||||||
|
*/
|
||||||
|
function CustomersMultiSelectRoot({
|
||||||
|
// #withDrawerAction
|
||||||
|
openDrawer,
|
||||||
|
closeDrawer,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
|
const handleCreateItemClick = () => {
|
||||||
|
openDrawer(DRAWERS.QUICK_CREATE_CUSTOMER);
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<ContactsMultiSelect
|
||||||
|
onCreateItemSelect={handleCreateItemClick}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vendors multi-select component.
|
||||||
|
*/
|
||||||
|
function VendorsMultiSelectRoot({
|
||||||
|
// #withDrawerAction
|
||||||
|
openDrawer,
|
||||||
|
closeDrawer,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
|
const handleCreateItemClick = () => {
|
||||||
|
openDrawer(DRAWERS.QUICK_WRITE_VENDOR);
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<ContactsMultiSelect
|
||||||
|
onCreateItemSelect={handleCreateItemClick}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CustomersMultiSelect = R.compose(withDrawerActions)(
|
||||||
|
CustomersMultiSelectRoot,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const VendorsMultiSelect = R.compose(withDrawerActions)(
|
||||||
|
VendorsMultiSelectRoot,
|
||||||
|
);
|
||||||
|
|||||||
@@ -1,49 +1,48 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useCallback } from 'react';
|
import React from 'react';
|
||||||
import { MenuItem } from '@blueprintjs/core';
|
import * as R from 'ramda';
|
||||||
import { MultiSelect } from '@/components';
|
import { FMultiSelect } from '@/components/Forms';
|
||||||
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Items multi-select.
|
* Items multi-select.
|
||||||
*/
|
*/
|
||||||
export function ItemsMultiSelect({ ...multiSelectProps }) {
|
function ItemsMultiSelectRoot({
|
||||||
// Filters accounts items.
|
// #withDialogAction
|
||||||
const filterItemsPredicater = useCallback(
|
openDialog,
|
||||||
(query, item, _index, exactMatch) => {
|
closeDialog,
|
||||||
const normalizedTitle = item.name.toLowerCase();
|
|
||||||
const normalizedQuery = query.toLowerCase();
|
|
||||||
|
|
||||||
if (exactMatch) {
|
// #props
|
||||||
return normalizedTitle === normalizedQuery;
|
allowCreate,
|
||||||
} else {
|
...multiSelectProps
|
||||||
return `${normalizedTitle} ${item.code}`.indexOf(normalizedQuery) >= 0;
|
}) {
|
||||||
}
|
// Maybe inject new item props to select component.
|
||||||
},
|
const maybeCreateNewItemRenderer = allowCreate ? createNewItemRenderer : null;
|
||||||
[],
|
const maybeCreateNewItemFromQuery = allowCreate
|
||||||
);
|
? createNewItemFromQuery
|
||||||
|
: null;
|
||||||
|
|
||||||
|
// Handles the create item click.
|
||||||
|
const handleCreateItemClick = () => {
|
||||||
|
openDialog(DialogsName.AccountForm);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MultiSelect
|
<FMultiSelect
|
||||||
itemRenderer={(item, { selected, handleClick, active }) => (
|
valueAccessor={'id'}
|
||||||
<MenuItem
|
textAccessor={'name'}
|
||||||
active={active}
|
labelAccessor={'code'}
|
||||||
icon={selected ? 'tick' : 'blank'}
|
tagAccessor={'name'}
|
||||||
text={item.name}
|
|
||||||
label={item.code}
|
|
||||||
key={item.id}
|
|
||||||
onClick={handleClick}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
popoverProps={{ minimal: true, usePortal: false, targetTagName: 'div ' }}
|
|
||||||
fill={true}
|
fill={true}
|
||||||
itemPredicate={filterItemsPredicater}
|
popoverProps={{ minimal: true }}
|
||||||
tagRenderer={(item) => item.name}
|
|
||||||
resetOnSelect={true}
|
resetOnSelect={true}
|
||||||
|
createNewItemRenderer={maybeCreateNewItemRenderer}
|
||||||
|
createNewItemFromQuery={maybeCreateNewItemFromQuery}
|
||||||
|
onCreateItemSelect={handleCreateItemClick}
|
||||||
{...multiSelectProps}
|
{...multiSelectProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemsMultiSelect.defaultProps = {
|
export const ItemsMultiSelect =
|
||||||
initialSelectedItems: [],
|
R.compose(withDialogActions)(ItemsMultiSelectRoot);
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useState, useCallback, useEffect } from 'react';
|
import React, { useCallback, useEffect } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import { getDefaultAPAgingSummaryQuery } from './common';
|
import { useAPAgingSummaryQuery } from './common';
|
||||||
import { FinancialStatement, DashboardPageContent } from '@/components';
|
import { FinancialStatement, DashboardPageContent } from '@/components';
|
||||||
|
|
||||||
import APAgingSummaryHeader from './APAgingSummaryHeader';
|
import APAgingSummaryHeader from './APAgingSummaryHeader';
|
||||||
@@ -26,25 +26,22 @@ function APAgingSummary({
|
|||||||
// #withAPAgingSummaryActions
|
// #withAPAgingSummaryActions
|
||||||
toggleAPAgingSummaryFilterDrawer: toggleDisplayFilterDrawer,
|
toggleAPAgingSummaryFilterDrawer: toggleDisplayFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
const { query, setLocationQuery } = useAPAgingSummaryQuery();
|
||||||
...getDefaultAPAgingSummaryQuery(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle filter submit.
|
// Handle filter submit.
|
||||||
const handleFilterSubmit = useCallback((filter) => {
|
const handleFilterSubmit = useCallback(
|
||||||
const _filter = {
|
(filter) => {
|
||||||
...filter,
|
const _filter = {
|
||||||
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
...filter,
|
||||||
};
|
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
||||||
setFilter(_filter);
|
};
|
||||||
}, []);
|
setLocationQuery(_filter);
|
||||||
|
},
|
||||||
|
[setLocationQuery],
|
||||||
|
);
|
||||||
// Handle number format submit.
|
// Handle number format submit.
|
||||||
const handleNumberFormatSubmit = (numberFormat) => {
|
const handleNumberFormatSubmit = (numberFormat) => {
|
||||||
setFilter({
|
setLocationQuery({ ...filter, numberFormat });
|
||||||
...filter,
|
|
||||||
numberFormat,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
// Hide the report filter drawer once the page unmount.
|
// Hide the report filter drawer once the page unmount.
|
||||||
useEffect(
|
useEffect(
|
||||||
@@ -55,9 +52,9 @@ function APAgingSummary({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<APAgingSummaryProvider filter={filter}>
|
<APAgingSummaryProvider filter={query}>
|
||||||
<APAgingSummaryActionsBar
|
<APAgingSummaryActionsBar
|
||||||
numberFormat={filter.numberFormat}
|
numberFormat={query.numberFormat}
|
||||||
onNumberFormatSubmit={handleNumberFormatSubmit}
|
onNumberFormatSubmit={handleNumberFormatSubmit}
|
||||||
/>
|
/>
|
||||||
<APAgingSummarySheetLoadingBar />
|
<APAgingSummarySheetLoadingBar />
|
||||||
@@ -65,7 +62,7 @@ function APAgingSummary({
|
|||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<FinancialStatement name={'AP-aging-summary'}>
|
<FinancialStatement name={'AP-aging-summary'}>
|
||||||
<APAgingSummaryHeader
|
<APAgingSummaryHeader
|
||||||
pageFilter={filter}
|
pageFilter={query}
|
||||||
onSubmitFilter={handleFilterSubmit}
|
onSubmitFilter={handleFilterSubmit}
|
||||||
/>
|
/>
|
||||||
<APAgingSummaryBody organizationName={organizationName} />
|
<APAgingSummaryBody organizationName={organizationName} />
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import moment from 'moment';
|
|
||||||
import * as Yup from 'yup';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { FormattedMessage as T } from '@/components';
|
import { FormattedMessage as T } from '@/components';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
@@ -17,6 +15,10 @@ import withAPAgingSummaryActions from './withAPAgingSummaryActions';
|
|||||||
import { transformToForm, compose } from '@/utils';
|
import { transformToForm, compose } from '@/utils';
|
||||||
import { useFeatureCan } from '@/hooks/state';
|
import { useFeatureCan } from '@/hooks/state';
|
||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
|
import {
|
||||||
|
getAPAgingSummaryQuerySchema,
|
||||||
|
getDefaultAPAgingSummaryQuery,
|
||||||
|
} from './common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AP Aging Summary Report - Drawer Header.
|
* AP Aging Summary Report - Drawer Header.
|
||||||
@@ -33,39 +35,22 @@ function APAgingSummaryHeader({
|
|||||||
isFilterDrawerOpen,
|
isFilterDrawerOpen,
|
||||||
}) {
|
}) {
|
||||||
// Validation schema.
|
// Validation schema.
|
||||||
const validationSchema = Yup.object({
|
const validationSchema = getAPAgingSummaryQuerySchema();
|
||||||
asDate: Yup.date().required().label('asDate'),
|
|
||||||
agingDaysBefore: Yup.number()
|
|
||||||
.required()
|
|
||||||
.integer()
|
|
||||||
.positive()
|
|
||||||
.label('agingBeforeDays'),
|
|
||||||
agingPeriods: Yup.number()
|
|
||||||
.required()
|
|
||||||
.integer()
|
|
||||||
.positive()
|
|
||||||
.label('agingPeriods'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
const defaultValues = {
|
const defaultValues = getDefaultAPAgingSummaryQuery();
|
||||||
asDate: moment(pageFilter.asDate).toDate(),
|
|
||||||
agingDaysBefore: 30,
|
|
||||||
agingPeriods: 3,
|
|
||||||
vendorsIds: [],
|
|
||||||
branchesIds: [],
|
|
||||||
filterByOption: 'without-zero-balance',
|
|
||||||
};
|
|
||||||
// Formik initial values.
|
|
||||||
const initialValues = transformToForm({ ...pageFilter }, defaultValues);
|
|
||||||
|
|
||||||
|
// Formik initial values.
|
||||||
|
const initialValues = transformToForm(
|
||||||
|
{ ...defaultValues, ...pageFilter },
|
||||||
|
defaultValues,
|
||||||
|
);
|
||||||
// Handle form submit.
|
// Handle form submit.
|
||||||
const handleSubmit = (values, { setSubmitting }) => {
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
onSubmitFilter(values);
|
onSubmitFilter(values);
|
||||||
toggleFilterDrawerDisplay(false);
|
toggleFilterDrawerDisplay(false);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle cancel button click.
|
// Handle cancel button click.
|
||||||
const handleCancelClick = () => {
|
const handleCancelClick = () => {
|
||||||
toggleFilterDrawerDisplay(false);
|
toggleFilterDrawerDisplay(false);
|
||||||
@@ -74,9 +59,8 @@ function APAgingSummaryHeader({
|
|||||||
const handleDrawerClose = () => {
|
const handleDrawerClose = () => {
|
||||||
toggleFilterDrawerDisplay(false);
|
toggleFilterDrawerDisplay(false);
|
||||||
};
|
};
|
||||||
// Detarmines the feature whether is enabled.
|
// Detarmines whether the feature is enabled.
|
||||||
const { featureCan } = useFeatureCan();
|
const { featureCan } = useFeatureCan();
|
||||||
|
|
||||||
const isBranchesFeatureCan = featureCan(Features.Branches);
|
const isBranchesFeatureCan = featureCan(Features.Branches);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field } from 'formik';
|
import { FastField } from 'formik';
|
||||||
|
import { Intent, FormGroup, InputGroup, Position } from '@blueprintjs/core';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import {
|
|
||||||
Intent,
|
|
||||||
FormGroup,
|
|
||||||
InputGroup,
|
|
||||||
Position,
|
|
||||||
Classes,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
ContactsMultiSelect,
|
|
||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
FieldHint,
|
FieldHint,
|
||||||
|
FFormGroup,
|
||||||
|
VendorsMultiSelect,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { useAPAgingSummaryGeneralContext } from './APAgingSummaryGeneralProvider';
|
import { useAPAgingSummaryGeneralContext } from './APAgingSummaryGeneralProvider';
|
||||||
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
||||||
@@ -104,22 +98,9 @@ export default function APAgingSummaryHeaderGeneralContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<Field name={'vendorsIds'}>
|
<FFormGroup label={<T id={'specific_vendors'} />} name={'vendorsIds'}>
|
||||||
{({ form: { setFieldValue }, field: { value } }) => (
|
<VendorsMultiSelect name={'vendorsIds'} items={vendors} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'specific_vendors'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<ContactsMultiSelect
|
|
||||||
items={vendors}
|
|
||||||
onItemSelect={(vendors) => {
|
|
||||||
const vendorsIds = vendors.map((customer) => customer.id);
|
|
||||||
setFieldValue('vendorsIds', vendorsIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,18 +1,80 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { transformToCamelCase, flatObject } from '@/utils';
|
import * as Yup from 'yup';
|
||||||
|
import { transformToCamelCase, flatObject, transformToForm } from '@/utils';
|
||||||
|
import { useAppQueryString } from '@/hooks';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { castArray } from 'lodash';
|
||||||
|
|
||||||
export const transformFilterFormToQuery = (form) => {
|
export const transformFilterFormToQuery = (form) => {
|
||||||
return flatObject(transformToCamelCase(form));
|
return flatObject(transformToCamelCase(form));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default query of AP aging summary.
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export const getDefaultAPAgingSummaryQuery = () => {
|
export const getDefaultAPAgingSummaryQuery = () => {
|
||||||
return {
|
return {
|
||||||
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
||||||
agingDaysBefore: 30,
|
agingDaysBefore: 30,
|
||||||
agingPeriods: 3,
|
agingPeriods: 3,
|
||||||
|
filterByOption: 'without-zero-balance',
|
||||||
vendorsIds: [],
|
vendorsIds: [],
|
||||||
branchesIds: [],
|
branchesIds: [],
|
||||||
filterByOption: 'without-zero-balance',
|
};
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Retrieves the query validation schema.
|
||||||
|
* @returns {Yup}
|
||||||
|
*/
|
||||||
|
export const getAPAgingSummaryQuerySchema = () => {
|
||||||
|
return Yup.object({
|
||||||
|
asDate: Yup.date().required().label('asDate'),
|
||||||
|
agingDaysBefore: Yup.number()
|
||||||
|
.required()
|
||||||
|
.integer()
|
||||||
|
.positive()
|
||||||
|
.label('agingBeforeDays'),
|
||||||
|
agingPeriods: Yup.number()
|
||||||
|
.required()
|
||||||
|
.integer()
|
||||||
|
.positive()
|
||||||
|
.label('agingPeriods'),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the AP aging summary query state.
|
||||||
|
* @param locationQuery
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const parseAPAgingSummaryQuery = (locationQuery) => {
|
||||||
|
const defaultQuery = getDefaultAPAgingSummaryQuery();
|
||||||
|
|
||||||
|
const transformed = {
|
||||||
|
...defaultQuery,
|
||||||
|
...transformToForm(locationQuery, defaultQuery),
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
...transformed,
|
||||||
|
vendorsIds: castArray(transformed.vendorsIds),
|
||||||
|
branchesIds: castArray(transformed.branchesIds),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AP aging summary query state.
|
||||||
|
*/
|
||||||
|
export const useAPAgingSummaryQuery = () => {
|
||||||
|
// Retrieves location query.
|
||||||
|
const [locationQuery, setLocationQuery] = useAppQueryString();
|
||||||
|
|
||||||
|
// Merges the default filter query with location URL query.
|
||||||
|
const query = useMemo(
|
||||||
|
() => parseAPAgingSummaryQuery(locationQuery),
|
||||||
|
[locationQuery],
|
||||||
|
);
|
||||||
|
return { query, locationQuery, setLocationQuery };
|
||||||
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import React, { useState, useCallback, useEffect } from 'react';
|
import React, { useState, useCallback, useEffect } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
|
|
||||||
import ARAgingSummaryHeader from './ARAgingSummaryHeader';
|
import ARAgingSummaryHeader from './ARAgingSummaryHeader';
|
||||||
import ARAgingSummaryActionsBar from './ARAgingSummaryActionsBar';
|
import ARAgingSummaryActionsBar from './ARAgingSummaryActionsBar';
|
||||||
|
|
||||||
@@ -13,7 +12,7 @@ import { ARAgingSummaryBody } from './ARAgingSummaryBody';
|
|||||||
|
|
||||||
import withARAgingSummaryActions from './withARAgingSummaryActions';
|
import withARAgingSummaryActions from './withARAgingSummaryActions';
|
||||||
|
|
||||||
import { getDefaultARAgingSummaryQuery } from './common';
|
import { useARAgingSummaryQuery } from './common';
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,9 +22,7 @@ function ReceivableAgingSummarySheet({
|
|||||||
// #withARAgingSummaryActions
|
// #withARAgingSummaryActions
|
||||||
toggleARAgingSummaryFilterDrawer: toggleDisplayFilterDrawer,
|
toggleARAgingSummaryFilterDrawer: toggleDisplayFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
const { query, setLocationQuery } = useARAgingSummaryQuery();
|
||||||
...getDefaultARAgingSummaryQuery(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle filter submit.
|
// Handle filter submit.
|
||||||
const handleFilterSubmit = useCallback((filter) => {
|
const handleFilterSubmit = useCallback((filter) => {
|
||||||
@@ -33,25 +30,23 @@ function ReceivableAgingSummarySheet({
|
|||||||
...filter,
|
...filter,
|
||||||
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
setFilter(_filter);
|
setLocationQuery(_filter);
|
||||||
}, []);
|
}, [setLocationQuery]);
|
||||||
|
|
||||||
// Handle number format submit.
|
// Handle number format submit.
|
||||||
const handleNumberFormatSubmit = (numberFormat) => {
|
const handleNumberFormatSubmit = (numberFormat) => {
|
||||||
setFilter({ ...filter, numberFormat });
|
setLocationQuery({ ...query, numberFormat });
|
||||||
};
|
};
|
||||||
// Hide the filter drawer once the page unmount.
|
// Hide the filter drawer once the page unmount.
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => toggleDisplayFilterDrawer(false),
|
||||||
toggleDisplayFilterDrawer(false);
|
|
||||||
},
|
|
||||||
[toggleDisplayFilterDrawer],
|
[toggleDisplayFilterDrawer],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ARAgingSummaryProvider filter={filter}>
|
<ARAgingSummaryProvider filter={query}>
|
||||||
<ARAgingSummaryActionsBar
|
<ARAgingSummaryActionsBar
|
||||||
numberFormat={filter.numberFormat}
|
numberFormat={query.numberFormat}
|
||||||
onNumberFormatSubmit={handleNumberFormatSubmit}
|
onNumberFormatSubmit={handleNumberFormatSubmit}
|
||||||
/>
|
/>
|
||||||
<ARAgingSummarySheetLoadingBar />
|
<ARAgingSummarySheetLoadingBar />
|
||||||
@@ -59,7 +54,7 @@ function ReceivableAgingSummarySheet({
|
|||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<FinancialStatement>
|
<FinancialStatement>
|
||||||
<ARAgingSummaryHeader
|
<ARAgingSummaryHeader
|
||||||
pageFilter={filter}
|
pageFilter={query}
|
||||||
onSubmitFilter={handleFilterSubmit}
|
onSubmitFilter={handleFilterSubmit}
|
||||||
/>
|
/>
|
||||||
<ARAgingSummaryBody />
|
<ARAgingSummaryBody />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import { FormattedMessage as T } from '@/components';
|
import { FormattedMessage as T } from '@/components';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||||
@@ -17,6 +16,10 @@ import withARAgingSummaryActions from './withARAgingSummaryActions';
|
|||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm } from '@/utils';
|
||||||
import { useFeatureCan } from '@/hooks/state';
|
import { useFeatureCan } from '@/hooks/state';
|
||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
|
import {
|
||||||
|
getARAgingSummaryQuerySchema,
|
||||||
|
getDefaultARAgingSummaryQuery,
|
||||||
|
} from './common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AR Aging Summary Report - Drawer Header.
|
* AR Aging Summary Report - Drawer Header.
|
||||||
@@ -33,32 +36,15 @@ function ARAgingSummaryHeader({
|
|||||||
isFilterDrawerOpen,
|
isFilterDrawerOpen,
|
||||||
}) {
|
}) {
|
||||||
// Validation schema.
|
// Validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getARAgingSummaryQuerySchema();
|
||||||
asDate: Yup.date().required().label('asDate'),
|
|
||||||
agingDaysBefore: Yup.number()
|
|
||||||
.required()
|
|
||||||
.integer()
|
|
||||||
.positive()
|
|
||||||
.label('agingDaysBefore'),
|
|
||||||
agingPeriods: Yup.number()
|
|
||||||
.required()
|
|
||||||
.integer()
|
|
||||||
.positive()
|
|
||||||
.label('agingPeriods'),
|
|
||||||
});
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
const defaultValues = {
|
const defaultValues = getDefaultARAgingSummaryQuery();
|
||||||
asDate: moment().toDate(),
|
|
||||||
agingDaysBefore: 30,
|
|
||||||
agingPeriods: 3,
|
|
||||||
customersIds: [],
|
|
||||||
branchesIds: [],
|
|
||||||
filterByOption: 'without-zero-balance',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = transformToForm(
|
const initialValues = transformToForm(
|
||||||
{
|
{
|
||||||
|
...defaultValues,
|
||||||
...pageFilter,
|
...pageFilter,
|
||||||
asDate: moment(pageFilter.asDate).toDate(),
|
asDate: moment(pageFilter.asDate).toDate(),
|
||||||
},
|
},
|
||||||
@@ -80,7 +66,6 @@ function ARAgingSummaryHeader({
|
|||||||
};
|
};
|
||||||
// Detarmines the feature whether is enabled.
|
// Detarmines the feature whether is enabled.
|
||||||
const { featureCan } = useFeatureCan();
|
const { featureCan } = useFeatureCan();
|
||||||
|
|
||||||
const isBranchesFeatureCan = featureCan(Features.Branches);
|
const isBranchesFeatureCan = featureCan(Features.Branches);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -2,22 +2,16 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field } from 'formik';
|
import { FastField, Field } from 'formik';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import {
|
import { Intent, FormGroup, InputGroup, Position } from '@blueprintjs/core';
|
||||||
Intent,
|
|
||||||
FormGroup,
|
|
||||||
InputGroup,
|
|
||||||
Position,
|
|
||||||
Classes,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
|
||||||
|
|
||||||
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
ContactsMultiSelect,
|
|
||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
FieldHint,
|
FieldHint,
|
||||||
|
FInputGroup,
|
||||||
|
FFormGroup,
|
||||||
|
CustomersMultiSelect,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { momentFormatter } from '@/utils';
|
import { momentFormatter } from '@/utils';
|
||||||
import { useARAgingSummaryGeneralContext } from './ARAgingSummaryGeneralProvider';
|
import { useARAgingSummaryGeneralContext } from './ARAgingSummaryGeneralProvider';
|
||||||
@@ -81,22 +75,13 @@ export default function ARAgingSummaryHeaderGeneralContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<FastField name={'agingPeriods'}>
|
<FFormGroup
|
||||||
{({ field, meta: { error, touched } }) => (
|
name={'agingPeriods'}
|
||||||
<FormGroup
|
label={<T id={'aging_periods'} />}
|
||||||
label={<T id={'aging_periods'} />}
|
labelInfo={<FieldHint />}
|
||||||
labelInfo={<FieldHint />}
|
>
|
||||||
className={'form-group--aging-periods'}
|
<FInputGroup name={'agingPeriods'} medium={true} />
|
||||||
intent={error && Intent.DANGER}
|
</FFormGroup>
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
medium={true}
|
|
||||||
intent={error && Intent.DANGER}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
@@ -111,24 +96,12 @@ export default function ARAgingSummaryHeaderGeneralContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<Field name="customersIds">
|
<FFormGroup
|
||||||
{({ form: { setFieldValue }, field: { value } }) => (
|
name="customersIds"
|
||||||
<FormGroup
|
label={<T id={'specific_customers'} />}
|
||||||
label={<T id={'specific_customers'} />}
|
>
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
<CustomersMultiSelect name="customersIds" items={customers} />
|
||||||
>
|
</FFormGroup>
|
||||||
<ContactsMultiSelect
|
|
||||||
items={customers}
|
|
||||||
onItemSelect={(customers) => {
|
|
||||||
const customersIds = customers.map(
|
|
||||||
(customer) => customer.id,
|
|
||||||
);
|
|
||||||
setFieldValue('customersIds', customersIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { transformToCamelCase, flatObject } from '@/utils';
|
import * as Yup from 'yup';
|
||||||
|
import { transformToCamelCase, flatObject, transformToForm } from '@/utils';
|
||||||
|
import { useAppQueryString } from '@/hooks';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { castArray } from 'lodash';
|
||||||
|
|
||||||
export const transfromFilterFormToQuery = (form) => {
|
export const transfromFilterFormToQuery = (form) => {
|
||||||
return flatObject(transformToCamelCase(form));
|
return flatObject(transformToCamelCase(form));
|
||||||
@@ -14,8 +18,57 @@ export const getDefaultARAgingSummaryQuery = () => {
|
|||||||
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
||||||
agingDaysBefore: 30,
|
agingDaysBefore: 30,
|
||||||
agingPeriods: 3,
|
agingPeriods: 3,
|
||||||
customersIds: [],
|
|
||||||
filterByOption: 'without-zero-balance',
|
filterByOption: 'without-zero-balance',
|
||||||
|
customersIds: [],
|
||||||
branchesIds: [],
|
branchesIds: [],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the AR aging summary query schema.
|
||||||
|
* @returns {Yup}
|
||||||
|
*/
|
||||||
|
export const getARAgingSummaryQuerySchema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
asDate: Yup.date().required().label('asDate'),
|
||||||
|
agingDaysBefore: Yup.number()
|
||||||
|
.required()
|
||||||
|
.integer()
|
||||||
|
.positive()
|
||||||
|
.label('agingDaysBefore'),
|
||||||
|
agingPeriods: Yup.number()
|
||||||
|
.required()
|
||||||
|
.integer()
|
||||||
|
.positive()
|
||||||
|
.label('agingPeriods'),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the AR aging summary state.
|
||||||
|
*/
|
||||||
|
const parseARAgingSummaryQuery = (locationQuery) => {
|
||||||
|
const defaultQuery = getDefaultARAgingSummaryQuery();
|
||||||
|
const transformed = {
|
||||||
|
...defaultQuery,
|
||||||
|
...transformToForm(locationQuery, defaultQuery),
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
...transformed,
|
||||||
|
branchesIds: castArray(transformed.branchesIds),
|
||||||
|
customersIds: castArray(transformed.customersIds),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AR aging summary query state.
|
||||||
|
*/
|
||||||
|
export const useARAgingSummaryQuery = () => {
|
||||||
|
const [locationQuery, setLocationQuery] = useAppQueryString();
|
||||||
|
|
||||||
|
const query = useMemo(
|
||||||
|
() => parseARAgingSummaryQuery(locationQuery),
|
||||||
|
[locationQuery],
|
||||||
|
);
|
||||||
|
return { query, locationQuery, setLocationQuery };
|
||||||
|
};
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ function BalanceSheetHeader({
|
|||||||
};
|
};
|
||||||
// Detarmines the given feature whether is enabled.
|
// Detarmines the given feature whether is enabled.
|
||||||
const { featureCan } = useFeatureCan();
|
const { featureCan } = useFeatureCan();
|
||||||
|
|
||||||
const isBranchesFeatureCan = featureCan(Features.Branches);
|
const isBranchesFeatureCan = featureCan(Features.Branches);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
|
|
||||||
@@ -10,11 +10,10 @@ import CustomersBalanceSummaryHeader from './CustomersBalanceSummaryHeader';
|
|||||||
|
|
||||||
import { CustomerBalanceSummaryBody } from './CustomerBalanceSummaryBody';
|
import { CustomerBalanceSummaryBody } from './CustomerBalanceSummaryBody';
|
||||||
import { CustomersBalanceSummaryProvider } from './CustomersBalanceSummaryProvider';
|
import { CustomersBalanceSummaryProvider } from './CustomersBalanceSummaryProvider';
|
||||||
import { getDefaultCustomersBalanceQuery } from './utils';
|
import { useCustomerBalanceSummaryQuery } from './utils';
|
||||||
import { CustomersBalanceLoadingBar } from './components';
|
import { CustomersBalanceLoadingBar } from './components';
|
||||||
import withCustomersBalanceSummaryActions from './withCustomersBalanceSummaryActions';
|
import withCustomersBalanceSummaryActions from './withCustomersBalanceSummaryActions';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customers Balance summary.
|
* Customers Balance summary.
|
||||||
*/
|
*/
|
||||||
@@ -22,36 +21,33 @@ function CustomersBalanceSummary({
|
|||||||
// #withCustomersBalanceSummaryActions
|
// #withCustomersBalanceSummaryActions
|
||||||
toggleCustomerBalanceFilterDrawer,
|
toggleCustomerBalanceFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
const { query, setLocationQuery } = useCustomerBalanceSummaryQuery();
|
||||||
...getDefaultCustomersBalanceQuery(),
|
|
||||||
});
|
|
||||||
// Handle re-fetch customers balance summary after filter change.
|
// Handle re-fetch customers balance summary after filter change.
|
||||||
const handleFilterSubmit = (filter) => {
|
const handleFilterSubmit = (filter) => {
|
||||||
const _filter = {
|
const _filter = {
|
||||||
...filter,
|
...filter,
|
||||||
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
setFilter({ ..._filter });
|
setLocationQuery({ ..._filter });
|
||||||
};
|
};
|
||||||
// Handle number format.
|
// Handle number format.
|
||||||
const handleNumberFormat = (values) => {
|
const handleNumberFormat = (values) => {
|
||||||
setFilter({
|
setLocationQuery({
|
||||||
...filter,
|
...filter,
|
||||||
numberFormat: values,
|
numberFormat: values,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => toggleCustomerBalanceFilterDrawer(false),
|
||||||
toggleCustomerBalanceFilterDrawer(false);
|
|
||||||
},
|
|
||||||
[toggleCustomerBalanceFilterDrawer],
|
[toggleCustomerBalanceFilterDrawer],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CustomersBalanceSummaryProvider filter={filter}>
|
<CustomersBalanceSummaryProvider filter={query}>
|
||||||
<CustomersBalanceSummaryActionsBar
|
<CustomersBalanceSummaryActionsBar
|
||||||
numberFormat={filter?.numberFormat}
|
numberFormat={query?.numberFormat}
|
||||||
onNumberFormatSubmit={handleNumberFormat}
|
onNumberFormatSubmit={handleNumberFormat}
|
||||||
/>
|
/>
|
||||||
<CustomersBalanceLoadingBar />
|
<CustomersBalanceLoadingBar />
|
||||||
@@ -59,7 +55,7 @@ function CustomersBalanceSummary({
|
|||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<FinancialStatement>
|
<FinancialStatement>
|
||||||
<CustomersBalanceSummaryHeader
|
<CustomersBalanceSummaryHeader
|
||||||
pageFilter={filter}
|
pageFilter={query}
|
||||||
onSubmitFilter={handleFilterSubmit}
|
onSubmitFilter={handleFilterSubmit}
|
||||||
/>
|
/>
|
||||||
<CustomerBalanceSummaryBody />
|
<CustomerBalanceSummaryBody />
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field } from 'formik';
|
import { FastField } from 'formik';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { Classes, FormGroup, Position, Checkbox } from '@blueprintjs/core';
|
import { FormGroup, Position, Checkbox } from '@blueprintjs/core';
|
||||||
import {
|
import {
|
||||||
ContactsMultiSelect,
|
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
FieldHint,
|
FieldHint,
|
||||||
|
CustomersMultiSelect,
|
||||||
|
FFormGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import classNames from 'classnames';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
@@ -86,26 +85,12 @@ export default function CustomersBalanceSummaryGeneralPanelContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<Field name={'customersIds'}>
|
<FFormGroup
|
||||||
{({
|
name={'customersIds'}
|
||||||
form: { setFieldValue },
|
label={<T id={'specific_customers'} />}
|
||||||
field: { value },
|
>
|
||||||
meta: { error, touched },
|
<CustomersMultiSelect name={'customersIds'} items={customers} />
|
||||||
}) => (
|
</FFormGroup>
|
||||||
<FormGroup
|
|
||||||
label={<T id={'specific_customers'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<ContactsMultiSelect
|
|
||||||
items={customers}
|
|
||||||
onItemSelect={(contacts) => {
|
|
||||||
const customersIds = contacts.map((contact) => contact.id);
|
|
||||||
setFieldValue('customersIds', customersIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
@@ -13,6 +13,7 @@ import withCustomersBalanceSummaryActions from './withCustomersBalanceSummaryAct
|
|||||||
import CustomersBalanceSummaryGeneralPanel from './CustomersBalanceSummaryGeneralPanel';
|
import CustomersBalanceSummaryGeneralPanel from './CustomersBalanceSummaryGeneralPanel';
|
||||||
|
|
||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm } from '@/utils';
|
||||||
|
import { getCustomersBalanceQuerySchema } from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customers balance summary.
|
* Customers balance summary.
|
||||||
@@ -29,9 +30,8 @@ function CustomersBalanceSummaryHeader({
|
|||||||
toggleCustomerBalanceFilterDrawer,
|
toggleCustomerBalanceFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
// validation schema.
|
// validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getCustomersBalanceQuerySchema();
|
||||||
asDate: Yup.date().required().label('asDate'),
|
|
||||||
});
|
|
||||||
// Default form values.
|
// Default form values.
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
...pageFilter,
|
...pageFilter,
|
||||||
|
|||||||
@@ -1,9 +1,58 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import { castArray } from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
import { useAppQueryString } from '@/hooks';
|
||||||
|
import { getDefaultARAgingSummaryQuery } from '../ARAgingSummary/common';
|
||||||
|
import { transformToForm } from '@/utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default query of customers balance summary.
|
||||||
|
*/
|
||||||
export const getDefaultCustomersBalanceQuery = () => {
|
export const getDefaultCustomersBalanceQuery = () => {
|
||||||
return {
|
return {
|
||||||
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
||||||
filterByOption: 'with-transactions',
|
filterByOption: 'with-transactions',
|
||||||
|
customersIds: [],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the customers balance query schema.
|
||||||
|
* @returns {Yup}
|
||||||
|
*/
|
||||||
|
export const getCustomersBalanceQuerySchema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
asDate: Yup.date().required().label('asDate'),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the customer balance summary query.
|
||||||
|
*/
|
||||||
|
const parseCustomersBalanceSummaryQuery = (locationQuery) => {
|
||||||
|
const defaultQuery = getDefaultARAgingSummaryQuery();
|
||||||
|
|
||||||
|
const transformed = {
|
||||||
|
...defaultQuery,
|
||||||
|
...transformToForm(locationQuery, defaultQuery),
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
...transformed,
|
||||||
|
customersIds: castArray(transformed.customersIds),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter/setter query state of customers balance summary.
|
||||||
|
*/
|
||||||
|
export const useCustomerBalanceSummaryQuery = () => {
|
||||||
|
const [locationQuery, setLocationQuery] = useAppQueryString();
|
||||||
|
|
||||||
|
const query = useMemo(
|
||||||
|
() => parseCustomersBalanceSummaryQuery(locationQuery),
|
||||||
|
[locationQuery],
|
||||||
|
);
|
||||||
|
return { query, locationQuery, setLocationQuery };
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||||
@@ -15,6 +13,10 @@ import withCustomersTransactions from './withCustomersTransactions';
|
|||||||
import withCustomersTransactionsActions from './withCustomersTransactionsActions';
|
import withCustomersTransactionsActions from './withCustomersTransactionsActions';
|
||||||
|
|
||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm } from '@/utils';
|
||||||
|
import {
|
||||||
|
getCustomersTransactionsDefaultQuery,
|
||||||
|
getCustomersTransactionsQuerySchema,
|
||||||
|
} from './_utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customers transactions header.
|
* Customers transactions header.
|
||||||
@@ -31,12 +33,8 @@ function CustomersTransactionsHeader({
|
|||||||
toggleCustomersTransactionsFilterDrawer: toggleFilterDrawer,
|
toggleCustomersTransactionsFilterDrawer: toggleFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
// Default form values.
|
// Default form values.
|
||||||
const defaultValues = {
|
const defaultValues = getCustomersTransactionsDefaultQuery();
|
||||||
...pageFilter,
|
|
||||||
fromDate: moment().toDate(),
|
|
||||||
toDate: moment().toDate(),
|
|
||||||
customersIds: [],
|
|
||||||
};
|
|
||||||
// Initial form values.
|
// Initial form values.
|
||||||
const initialValues = transformToForm(
|
const initialValues = transformToForm(
|
||||||
{
|
{
|
||||||
@@ -49,13 +47,7 @@ function CustomersTransactionsHeader({
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Validation schema.
|
// Validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getCustomersTransactionsQuerySchema();
|
||||||
fromDate: Yup.date().required().label(intl.get('fromDate')),
|
|
||||||
toDate: Yup.date()
|
|
||||||
.min(Yup.ref('fromDate'))
|
|
||||||
.required()
|
|
||||||
.label(intl.get('toDate')),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle form submit.
|
// Handle form submit.
|
||||||
const handleSubmit = (values, { setSubmitting }) => {
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import classNames from 'classnames';
|
|
||||||
import { Field } from 'formik';
|
|
||||||
import { Classes, FormGroup } from '@blueprintjs/core';
|
|
||||||
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
||||||
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
||||||
import {
|
import {
|
||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
ContactsMultiSelect,
|
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
|
CustomersMultiSelect,
|
||||||
|
FFormGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { filterCustomersOptions } from '../constants';
|
import { filterCustomersOptions } from '../constants';
|
||||||
|
|
||||||
@@ -51,24 +49,12 @@ function CustomersTransactionsHeaderGeneralPanelContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={4}>
|
<Col xs={4}>
|
||||||
<Field name={'customersIds'}>
|
<FFormGroup
|
||||||
{({ form: { setFieldValue }, field: { value } }) => (
|
label={<T id={'specific_customers'} />}
|
||||||
<FormGroup
|
name={'customersIds'}
|
||||||
label={<T id={'specific_customers'} />}
|
>
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
<CustomersMultiSelect name={'customersIds'} items={customers} />
|
||||||
>
|
</FFormGroup>
|
||||||
<ContactsMultiSelect
|
|
||||||
items={customers}
|
|
||||||
onItemSelect={(customers) => {
|
|
||||||
const customersIds = customers.map(
|
|
||||||
(customer) => customer.id,
|
|
||||||
);
|
|
||||||
setFieldValue('customersIds', customersIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
export const getCustomersTransactionsQuerySchema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
fromDate: Yup.date().required().label(intl.get('fromDate')),
|
||||||
|
toDate: Yup.date()
|
||||||
|
.min(Yup.ref('fromDate'))
|
||||||
|
.required()
|
||||||
|
.label(intl.get('toDate')),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCustomersTransactionsDefaultQuery = () => ({
|
||||||
|
fromDate: moment().toDate(),
|
||||||
|
toDate: moment().toDate(),
|
||||||
|
customersIds: [],
|
||||||
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useCallback } from 'react';
|
import React, { useCallback, useEffect } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import GeneralLedgerHeader from './GeneralLedgerHeader';
|
import GeneralLedgerHeader from './GeneralLedgerHeader';
|
||||||
@@ -41,10 +41,8 @@ function GeneralLedger({
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Hide the filter drawer once the page unmount.
|
// Hide the filter drawer once the page unmount.
|
||||||
React.useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => toggleGeneralLedgerFilterDrawer(false),
|
||||||
toggleGeneralLedgerFilterDrawer(false);
|
|
||||||
},
|
|
||||||
[toggleGeneralLedgerFilterDrawer],
|
[toggleGeneralLedgerFilterDrawer],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
import { FormattedMessage as T } from '@/components';
|
import { FormattedMessage as T } from '@/components';
|
||||||
import { getDefaultGeneralLedgerQuery } from './common';
|
import {
|
||||||
|
getDefaultGeneralLedgerQuery,
|
||||||
|
getGeneralLedgerQuerySchema,
|
||||||
|
} from './common';
|
||||||
import { compose, transformToForm, saveInvoke } from '@/utils';
|
import { compose, transformToForm, saveInvoke } from '@/utils';
|
||||||
|
|
||||||
import FinancialStatementHeader from '../FinancialStatementHeader';
|
import FinancialStatementHeader from '../FinancialStatementHeader';
|
||||||
@@ -39,6 +41,7 @@ function GeneralLedgerHeader({
|
|||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = transformToForm(
|
const initialValues = transformToForm(
|
||||||
{
|
{
|
||||||
|
...defaultValues,
|
||||||
...pageFilter,
|
...pageFilter,
|
||||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||||
toDate: moment(pageFilter.toDate).toDate(),
|
toDate: moment(pageFilter.toDate).toDate(),
|
||||||
@@ -46,11 +49,8 @@ function GeneralLedgerHeader({
|
|||||||
defaultValues,
|
defaultValues,
|
||||||
);
|
);
|
||||||
// Validation schema.
|
// Validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getGeneralLedgerQuerySchema();
|
||||||
dateRange: Yup.string().optional(),
|
|
||||||
fromDate: Yup.date().required(),
|
|
||||||
toDate: Yup.date().min(Yup.ref('fromDate')).required(),
|
|
||||||
});
|
|
||||||
// Handle form submit.
|
// Handle form submit.
|
||||||
const handleSubmit = (values, { setSubmitting }) => {
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
saveInvoke(onSubmitFilter, values);
|
saveInvoke(onSubmitFilter, values);
|
||||||
@@ -68,6 +68,7 @@ function GeneralLedgerHeader({
|
|||||||
// Detarmines the feature whether is enabled.
|
// Detarmines the feature whether is enabled.
|
||||||
const { featureCan } = useFeatureCan();
|
const { featureCan } = useFeatureCan();
|
||||||
|
|
||||||
|
// Detarmine if the feature is enabled.
|
||||||
const isBranchesFeatureCan = featureCan(Features.Branches);
|
const isBranchesFeatureCan = featureCan(Features.Branches);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import * as Yup from 'yup';
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
|
|
||||||
import { useAppQueryString } from '@/hooks';
|
import { useAppQueryString } from '@/hooks';
|
||||||
@@ -26,15 +27,25 @@ export const filterAccountsOptions = [
|
|||||||
/**
|
/**
|
||||||
* Retrieves the default general ledger query.
|
* Retrieves the default general ledger query.
|
||||||
*/
|
*/
|
||||||
export const getDefaultGeneralLedgerQuery = () => {
|
export const getDefaultGeneralLedgerQuery = () => ({
|
||||||
return {
|
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
basis: 'accrual',
|
||||||
basis: 'accrual',
|
filterByOption: 'with-transactions',
|
||||||
filterByOption: 'with-transactions',
|
branchesIds: [],
|
||||||
branchesIds: [],
|
accountsIds: [],
|
||||||
accountsIds: [],
|
});
|
||||||
};
|
|
||||||
|
/**
|
||||||
|
* Retrieves the validation schema of general ledger.
|
||||||
|
* @returns {Yup}
|
||||||
|
*/
|
||||||
|
export const getGeneralLedgerQuerySchema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
dateRange: Yup.string().optional(),
|
||||||
|
fromDate: Yup.date().required(),
|
||||||
|
toDate: Yup.date().min(Yup.ref('fromDate')).required(),
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
import { FormattedMessage as T } from '@/components';
|
import { FormattedMessage as T } from '@/components';
|
||||||
@@ -16,7 +15,10 @@ import InventoryItemDetailsHeaderDimensionsPanel from './InventoryItemDetailsHea
|
|||||||
import withInventoryItemDetails from './withInventoryItemDetails';
|
import withInventoryItemDetails from './withInventoryItemDetails';
|
||||||
import withInventoryItemDetailsActions from './withInventoryItemDetailsActions';
|
import withInventoryItemDetailsActions from './withInventoryItemDetailsActions';
|
||||||
|
|
||||||
import { getInventoryItemDetailsDefaultQuery } from './utils2';
|
import {
|
||||||
|
getInventoryItemDetailsDefaultQuery,
|
||||||
|
getInventoryItemDetailsQuerySchema,
|
||||||
|
} from './utils2';
|
||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm } from '@/utils';
|
||||||
import { useFeatureCan } from '@/hooks/state';
|
import { useFeatureCan } from '@/hooks/state';
|
||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
@@ -28,6 +30,7 @@ function InventoryItemDetailsHeader({
|
|||||||
// #ownProps
|
// #ownProps
|
||||||
onSubmitFilter,
|
onSubmitFilter,
|
||||||
pageFilter,
|
pageFilter,
|
||||||
|
|
||||||
// #withInventoryItemDetails
|
// #withInventoryItemDetails
|
||||||
isFilterDrawerOpen,
|
isFilterDrawerOpen,
|
||||||
|
|
||||||
@@ -40,30 +43,29 @@ function InventoryItemDetailsHeader({
|
|||||||
// Filter form initial values.
|
// Filter form initial values.
|
||||||
const initialValues = transformToForm(
|
const initialValues = transformToForm(
|
||||||
{
|
{
|
||||||
|
...defaultValues,
|
||||||
...pageFilter,
|
...pageFilter,
|
||||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||||
toDate: moment(pageFilter.toDate).toDate(),
|
toDate: moment(pageFilter.toDate).toDate(),
|
||||||
},
|
},
|
||||||
defaultValues,
|
defaultValues,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Validation schema.
|
// Validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getInventoryItemDetailsQuerySchema();
|
||||||
fromDate: Yup.date().required().label(intl.get('fromDate')),
|
|
||||||
toDate: Yup.date()
|
|
||||||
.min(Yup.ref('fromDate'))
|
|
||||||
.required()
|
|
||||||
.label(intl.get('toDate')),
|
|
||||||
});
|
|
||||||
// Handle form submit.
|
// Handle form submit.
|
||||||
const handleSubmit = (values, { setSubmitting }) => {
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
onSubmitFilter(values);
|
onSubmitFilter(values);
|
||||||
toggleFilterDrawer(false);
|
toggleFilterDrawer(false);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle drawer close action.
|
// Handle drawer close action.
|
||||||
const handleDrawerClose = () => {
|
const handleDrawerClose = () => {
|
||||||
toggleFilterDrawer(false);
|
toggleFilterDrawer(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Detarmines the given feature whether is enabled.
|
// Detarmines the given feature whether is enabled.
|
||||||
const { featureCan } = useFeatureCan();
|
const { featureCan } = useFeatureCan();
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormGroup, Classes } from '@blueprintjs/core';
|
|
||||||
import { Field } from 'formik';
|
|
||||||
import {
|
import {
|
||||||
ItemsMultiSelect,
|
ItemsMultiSelect,
|
||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
|
FFormGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import classNames from 'classnames';
|
|
||||||
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -39,26 +37,9 @@ function InventoryItemDetailsHeaderGeneralPanelContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={4}>
|
<Col xs={4}>
|
||||||
<Field name={'itemsIds'}>
|
<FFormGroup label={<T id={'Specific items'} />} name={'itemsIds'}>
|
||||||
{({
|
<ItemsMultiSelect name={'itemsIds'} items={items} />
|
||||||
form: { setFieldValue },
|
</FFormGroup>
|
||||||
field: { value },
|
|
||||||
meta: { error, touched },
|
|
||||||
}) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'Specific items'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<ItemsMultiSelect
|
|
||||||
items={items}
|
|
||||||
onItemSelect={(items) => {
|
|
||||||
const itemsIds = items.map((item) => item.id);
|
|
||||||
setFieldValue('itemsIds', itemsIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
|
||||||
import { useAppQueryString } from '@/hooks';
|
import { useAppQueryString } from '@/hooks';
|
||||||
import { transformToForm } from '@/utils';
|
import { transformToForm } from '@/utils';
|
||||||
@@ -9,13 +11,26 @@ import { transformToForm } from '@/utils';
|
|||||||
/**
|
/**
|
||||||
* Retrieves inventory item details default query.
|
* Retrieves inventory item details default query.
|
||||||
*/
|
*/
|
||||||
export const getInventoryItemDetailsDefaultQuery = () => {
|
export const getInventoryItemDetailsDefaultQuery = () => ({
|
||||||
return {
|
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
itemsIds: [],
|
||||||
warehousesIds: [],
|
warehousesIds: [],
|
||||||
branchesIds: [],
|
branchesIds: [],
|
||||||
};
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves inventory item details query schema.
|
||||||
|
* @returns {Yup}
|
||||||
|
*/
|
||||||
|
export const getInventoryItemDetailsQuerySchema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
fromDate: Yup.date().required().label(intl.get('fromDate')),
|
||||||
|
toDate: Yup.date()
|
||||||
|
.min(Yup.ref('fromDate'))
|
||||||
|
.required()
|
||||||
|
.label(intl.get('toDate')),
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +47,8 @@ const parseInventoryItemDetailsQuery = (locationQuery) => {
|
|||||||
return {
|
return {
|
||||||
...transformed,
|
...transformed,
|
||||||
|
|
||||||
// Ensures the branches/warehouses ids is always array.
|
// Ensure the branches, warehouses and items ids is always array.
|
||||||
|
itemsIds: castArray(transformed.itemsIds),
|
||||||
branchesIds: castArray(transformed.branchesIds),
|
branchesIds: castArray(transformed.branchesIds),
|
||||||
warehousesIds: castArray(transformed.warehousesIds),
|
warehousesIds: castArray(transformed.warehousesIds),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
@@ -17,6 +16,10 @@ import withInventoryValuationActions from './withInventoryValuationActions';
|
|||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm } from '@/utils';
|
||||||
import { useFeatureCan } from '@/hooks/state';
|
import { useFeatureCan } from '@/hooks/state';
|
||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
|
import {
|
||||||
|
getInventoryValuationQuery,
|
||||||
|
getInventoryValuationQuerySchema,
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inventory valuation header.
|
* inventory valuation header.
|
||||||
@@ -33,25 +36,17 @@ function InventoryValuationHeader({
|
|||||||
toggleInventoryValuationFilterDrawer,
|
toggleInventoryValuationFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
// Form validation schema.
|
// Form validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getInventoryValuationQuerySchema();
|
||||||
asDate: Yup.date().required().label('asDate'),
|
const defaultQuery = getInventoryValuationQuery();
|
||||||
});
|
|
||||||
|
|
||||||
// Default values.
|
|
||||||
const defaultValues = {
|
|
||||||
...pageFilter,
|
|
||||||
asDate: moment().toDate(),
|
|
||||||
itemsIds: [],
|
|
||||||
warehousesIds: [],
|
|
||||||
};
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = transformToForm(
|
const initialValues = transformToForm(
|
||||||
{
|
{
|
||||||
...defaultValues,
|
...defaultQuery,
|
||||||
...pageFilter,
|
...pageFilter,
|
||||||
asDate: moment(pageFilter.asDate).toDate(),
|
asDate: moment(pageFilter.asDate).toDate(),
|
||||||
},
|
},
|
||||||
defaultValues,
|
defaultQuery,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle the form of header submit.
|
// Handle the form of header submit.
|
||||||
@@ -71,6 +66,7 @@ function InventoryValuationHeader({
|
|||||||
// Detarmines the given feature whether is enabled.
|
// Detarmines the given feature whether is enabled.
|
||||||
const { featureCan } = useFeatureCan();
|
const { featureCan } = useFeatureCan();
|
||||||
|
|
||||||
|
// Detarmine if these feature are enabled.
|
||||||
const isBranchesFeatureCan = featureCan(Features.Branches);
|
const isBranchesFeatureCan = featureCan(Features.Branches);
|
||||||
const isWarehousesFeatureCan = featureCan(Features.Warehouses);
|
const isWarehousesFeatureCan = featureCan(Features.Warehouses);
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field } from 'formik';
|
import { FastField, Field } from 'formik';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { FormGroup, Position, Classes } from '@blueprintjs/core';
|
import { FormGroup, Position } from '@blueprintjs/core';
|
||||||
import classNames from 'classnames';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
@@ -11,9 +10,9 @@ import {
|
|||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
FieldHint,
|
FieldHint,
|
||||||
|
FFormGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { filterInventoryValuationOptions } from '../constants';
|
import { filterInventoryValuationOptions } from '../constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
@@ -83,22 +82,9 @@ function InventoryValuationHeaderGeneralPanelContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={4}>
|
<Col xs={4}>
|
||||||
<Field name={'itemsIds'}>
|
<FFormGroup name={'itemsIds'} label={<T id={'Specific items'} />}>
|
||||||
{({ form: { setFieldValue } }) => (
|
<ItemsMultiSelect name={'itemsIds'} items={items} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'Specific items'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<ItemsMultiSelect
|
|
||||||
items={items}
|
|
||||||
onItemSelect={(items) => {
|
|
||||||
const itemsIds = items.map((item) => item.id);
|
|
||||||
setFieldValue('itemsIds', itemsIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,25 +2,33 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
import { useAppQueryString } from '@/hooks';
|
import { useAppQueryString } from '@/hooks';
|
||||||
import { transformToForm } from '@/utils';
|
import { transformToForm } from '@/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the inventory valuation sheet default query.
|
* Retrieves the validation schema of inventory valuation query.
|
||||||
*/
|
*/
|
||||||
export const getInventoryValuationQuery = () => {
|
export const getInventoryValuationQuerySchema = () => {
|
||||||
return {
|
return Yup.object().shape({
|
||||||
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
asDate: Yup.date().required().label('asDate'),
|
||||||
filterByOption: 'with-transactions',
|
});
|
||||||
|
|
||||||
branchesIds: [],
|
|
||||||
warehousesIds: [],
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses inventory valiation location query to report query.
|
* Retrieves the inventory valuation sheet default query.
|
||||||
|
*/
|
||||||
|
export const getInventoryValuationQuery = () => ({
|
||||||
|
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
||||||
|
filterByOption: 'with-transactions',
|
||||||
|
itemsIds: [],
|
||||||
|
branchesIds: [],
|
||||||
|
warehousesIds: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses inventory valuation location query to report query.
|
||||||
*/
|
*/
|
||||||
const parseInventoryValuationQuery = (locationQuery) => {
|
const parseInventoryValuationQuery = (locationQuery) => {
|
||||||
const defaultQuery = getInventoryValuationQuery();
|
const defaultQuery = getInventoryValuationQuery();
|
||||||
@@ -33,6 +41,7 @@ const parseInventoryValuationQuery = (locationQuery) => {
|
|||||||
...transformed,
|
...transformed,
|
||||||
|
|
||||||
// Ensures the branches/warehouses ids is always array.
|
// Ensures the branches/warehouses ids is always array.
|
||||||
|
itemsIds: castArray(transformed.itemsIds),
|
||||||
branchesIds: castArray(transformed.branchesIds),
|
branchesIds: castArray(transformed.branchesIds),
|
||||||
warehousesIds: castArray(transformed.warehousesIds),
|
warehousesIds: castArray(transformed.warehousesIds),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useEffect, useState, useCallback } from 'react';
|
import React, { useEffect, useCallback } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import PurchasesByItemsActionsBar from './PurchasesByItemsActionsBar';
|
import PurchasesByItemsActionsBar from './PurchasesByItemsActionsBar';
|
||||||
@@ -9,7 +9,7 @@ import { FinancialStatement, DashboardPageContent } from '@/components';
|
|||||||
import { PurchasesByItemsLoadingBar } from './components';
|
import { PurchasesByItemsLoadingBar } from './components';
|
||||||
import { PurchasesByItemsProvider } from './PurchasesByItemsProvider';
|
import { PurchasesByItemsProvider } from './PurchasesByItemsProvider';
|
||||||
import { PurchasesByItemsBody } from './PurchasesByItemsBody';
|
import { PurchasesByItemsBody } from './PurchasesByItemsBody';
|
||||||
import { getDefaultPurchasesByItemsQuery } from './utils';
|
import { usePurchasesByItemsQuery } from './utils';
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
|
|
||||||
import withPurchasesByItemsActions from './withPurchasesByItemsActions';
|
import withPurchasesByItemsActions from './withPurchasesByItemsActions';
|
||||||
@@ -21,9 +21,7 @@ function PurchasesByItems({
|
|||||||
// #withPurchasesByItemsActions
|
// #withPurchasesByItemsActions
|
||||||
togglePurchasesByItemsFilterDrawer,
|
togglePurchasesByItemsFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
const { query, setLocationQuery } = usePurchasesByItemsQuery();
|
||||||
...getDefaultPurchasesByItemsQuery(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle filter form submit.
|
// Handle filter form submit.
|
||||||
const handleFilterSubmit = useCallback(
|
const handleFilterSubmit = useCallback(
|
||||||
@@ -33,11 +31,10 @@ function PurchasesByItems({
|
|||||||
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
||||||
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
setFilter(parsedFilter);
|
setLocationQuery(parsedFilter);
|
||||||
},
|
},
|
||||||
[setFilter],
|
[setLocationQuery],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle number format form submit.
|
// Handle number format form submit.
|
||||||
const handleNumberFormatSubmit = (numberFormat) => {
|
const handleNumberFormatSubmit = (numberFormat) => {
|
||||||
setFilter({
|
setFilter({
|
||||||
@@ -45,7 +42,6 @@ function PurchasesByItems({
|
|||||||
numberFormat,
|
numberFormat,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hide the filter drawer once the page unmount.
|
// Hide the filter drawer once the page unmount.
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
@@ -55,9 +51,9 @@ function PurchasesByItems({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PurchasesByItemsProvider query={filter}>
|
<PurchasesByItemsProvider query={query}>
|
||||||
<PurchasesByItemsActionsBar
|
<PurchasesByItemsActionsBar
|
||||||
numberFormat={filter.numberFormat}
|
numberFormat={query.numberFormat}
|
||||||
onNumberFormatSubmit={handleNumberFormatSubmit}
|
onNumberFormatSubmit={handleNumberFormatSubmit}
|
||||||
/>
|
/>
|
||||||
<PurchasesByItemsLoadingBar />
|
<PurchasesByItemsLoadingBar />
|
||||||
@@ -65,7 +61,7 @@ function PurchasesByItems({
|
|||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<FinancialStatement>
|
<FinancialStatement>
|
||||||
<PurchasesByItemsHeader
|
<PurchasesByItemsHeader
|
||||||
pageFilter={filter}
|
pageFilter={query}
|
||||||
onSubmitFilter={handleFilterSubmit}
|
onSubmitFilter={handleFilterSubmit}
|
||||||
/>
|
/>
|
||||||
<PurchasesByItemsBody />
|
<PurchasesByItemsBody />
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormGroup, Classes } from '@blueprintjs/core';
|
|
||||||
import { Field } from 'formik';
|
|
||||||
import {
|
import {
|
||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
ItemsMultiSelect,
|
ItemsMultiSelect,
|
||||||
|
FFormGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import classNames from 'classnames';
|
|
||||||
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
||||||
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
||||||
import { filterItemsOptions } from '../constants';
|
import { filterItemsOptions } from '../constants';
|
||||||
@@ -51,22 +49,9 @@ function PurchasesByItemsGeneralPanelContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={4}>
|
<Col xs={4}>
|
||||||
<Field name={'itemsIds'}>
|
<FFormGroup name={'itemsIds'} label={<T id={'Specific items'} />}>
|
||||||
{({ form: { setFieldValue } }) => (
|
<ItemsMultiSelect name={'itemsIds'} items={items} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'Specific items'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<ItemsMultiSelect
|
|
||||||
items={items}
|
|
||||||
onItemSelect={(items) => {
|
|
||||||
const itemsIds = items.map((item) => item.id);
|
|
||||||
setFieldValue('itemsIds', itemsIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import intl from 'react-intl-universal';
|
import styled from 'styled-components';
|
||||||
import styled from 'styled-components';
|
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
import { FormattedMessage as T } from '@/components';
|
import { FormattedMessage as T } from '@/components';
|
||||||
|
|
||||||
import FinancialStatementHeader from '@/containers/FinancialStatements/FinancialStatementHeader';
|
import FinancialStatementHeader from '@/containers/FinancialStatements/FinancialStatementHeader';
|
||||||
import PurchasesByItemsGeneralPanel from './PurchasesByItemsGeneralPanel';
|
import PurchasesByItemsGeneralPanel from './PurchasesByItemsGeneralPanel';
|
||||||
|
|
||||||
@@ -16,6 +13,10 @@ import withPurchasesByItems from './withPurchasesByItems';
|
|||||||
import withPurchasesByItemsActions from './withPurchasesByItemsActions';
|
import withPurchasesByItemsActions from './withPurchasesByItemsActions';
|
||||||
|
|
||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm } from '@/utils';
|
||||||
|
import {
|
||||||
|
getDefaultPurchasesByItemsQuery,
|
||||||
|
getPurchasesByItemsQuerySchema,
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purchases by items header.
|
* Purchases by items header.
|
||||||
@@ -32,38 +33,26 @@ function PurchasesByItemsHeader({
|
|||||||
togglePurchasesByItemsFilterDrawer,
|
togglePurchasesByItemsFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
// Form validation schema.
|
// Form validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getPurchasesByItemsQuerySchema();
|
||||||
fromDate: Yup.date().required().label(intl.get('from_date')),
|
|
||||||
toDate: Yup.date()
|
const defaultQuery = getDefaultPurchasesByItemsQuery();
|
||||||
.min(Yup.ref('fromDate'))
|
|
||||||
.required()
|
|
||||||
.label(intl.get('to_date')),
|
|
||||||
});
|
|
||||||
// Default form values.
|
|
||||||
const defaultValues = {
|
|
||||||
...pageFilter,
|
|
||||||
fromDate: moment().toDate(),
|
|
||||||
toDate: moment().toDate(),
|
|
||||||
itemsIds: [],
|
|
||||||
};
|
|
||||||
// Initial form values.
|
// Initial form values.
|
||||||
const initialValues = transformToForm(
|
const initialValues = transformToForm(
|
||||||
{
|
{
|
||||||
...defaultValues,
|
...defaultQuery,
|
||||||
...pageFilter,
|
...pageFilter,
|
||||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||||
toDate: moment(pageFilter.toDate).toDate(),
|
toDate: moment(pageFilter.toDate).toDate(),
|
||||||
},
|
},
|
||||||
defaultValues,
|
defaultQuery,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle form submit.
|
// Handle form submit.
|
||||||
const handleSubmit = (values, { setSubmitting }) => {
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
onSubmitFilter(values);
|
onSubmitFilter(values);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
togglePurchasesByItemsFilterDrawer(false);
|
togglePurchasesByItemsFilterDrawer(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle drawer close & cancel action.
|
// Handle drawer close & cancel action.
|
||||||
const handleDrawerClose = () => {
|
const handleDrawerClose = () => {
|
||||||
togglePurchasesByItemsFilterDrawer(false);
|
togglePurchasesByItemsFilterDrawer(false);
|
||||||
|
|||||||
@@ -1,11 +1,62 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { useAppQueryString } from '@/hooks';
|
||||||
|
import { transformToForm } from '@/utils';
|
||||||
|
import { castArray } from 'lodash';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the purchases by items query.
|
||||||
|
*/
|
||||||
|
export const getDefaultPurchasesByItemsQuery = () => ({
|
||||||
|
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||||
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
|
filterByOption: 'with-transactions',
|
||||||
|
itemsIds: [],
|
||||||
|
});
|
||||||
|
|
||||||
export const getDefaultPurchasesByItemsQuery = () => {
|
/**
|
||||||
|
* Retrieves the purchases by items query validation schema.
|
||||||
|
* @returns {Yup}
|
||||||
|
*/
|
||||||
|
export const getPurchasesByItemsQuerySchema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
fromDate: Yup.date().required().label(intl.get('from_date')),
|
||||||
|
toDate: Yup.date()
|
||||||
|
.min(Yup.ref('fromDate'))
|
||||||
|
.required()
|
||||||
|
.label(intl.get('to_date')),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the purchases by items query.
|
||||||
|
*/
|
||||||
|
const parsePurchasesByItemsQuery = (locationQuery) => {
|
||||||
|
const defaultQuery = getDefaultPurchasesByItemsQuery();
|
||||||
|
|
||||||
|
const transformed = {
|
||||||
|
...defaultQuery,
|
||||||
|
...transformToForm(locationQuery, defaultQuery),
|
||||||
|
};
|
||||||
return {
|
return {
|
||||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
...transformed,
|
||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
itemsIds: castArray(transformed.itemsIds),
|
||||||
filterByOption: 'with-transactions',
|
};
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Purchases by items query state.
|
||||||
|
*/
|
||||||
|
export const usePurchasesByItemsQuery = () => {
|
||||||
|
// Retrieves location query.
|
||||||
|
const [locationQuery, setLocationQuery] = useAppQueryString();
|
||||||
|
|
||||||
|
const query = React.useMemo(
|
||||||
|
() => parsePurchasesByItemsQuery(locationQuery),
|
||||||
|
[locationQuery],
|
||||||
|
);
|
||||||
|
return { query, locationQuery, setLocationQuery };
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useEffect, useState, useCallback } from 'react';
|
import React, { useEffect, useCallback } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import { SalesByItemsBody } from './SalesByItemsBody';
|
import { SalesByItemsBody } from './SalesByItemsBody';
|
||||||
@@ -11,7 +11,7 @@ import SalesByItemsHeader from './SalesByItemsHeader';
|
|||||||
|
|
||||||
import withSalesByItemsActions from './withSalesByItemsActions';
|
import withSalesByItemsActions from './withSalesByItemsActions';
|
||||||
|
|
||||||
import { getDefaultSalesByItemsQuery } from './utils';
|
import { useSalesByItemsQuery } from './utils';
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,9 +21,7 @@ function SalesByItems({
|
|||||||
// #withSellsByItemsActions
|
// #withSellsByItemsActions
|
||||||
toggleSalesByItemsFilterDrawer,
|
toggleSalesByItemsFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
const { query, setLocationQuery } = useSalesByItemsQuery();
|
||||||
...getDefaultSalesByItemsQuery(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle filter form submit.
|
// Handle filter form submit.
|
||||||
const handleFilterSubmit = useCallback(
|
const handleFilterSubmit = useCallback(
|
||||||
@@ -33,30 +31,28 @@ function SalesByItems({
|
|||||||
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
||||||
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
setFilter(parsedFilter);
|
setLocationQuery(parsedFilter);
|
||||||
},
|
},
|
||||||
[setFilter],
|
[setLocationQuery],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle number format form submit.
|
// Handle number format form submit.
|
||||||
const handleNumberFormatSubmit = (numberFormat) => {
|
const handleNumberFormatSubmit = (numberFormat) => {
|
||||||
setFilter({
|
setLocationQuery({
|
||||||
...filter,
|
...filter,
|
||||||
numberFormat,
|
numberFormat,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// Hide the filter drawer once the page unmount.
|
// Hide the filter drawer once the page unmount.
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => toggleSalesByItemsFilterDrawer(false),
|
||||||
toggleSalesByItemsFilterDrawer(false);
|
|
||||||
},
|
|
||||||
[toggleSalesByItemsFilterDrawer],
|
[toggleSalesByItemsFilterDrawer],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SalesByItemProvider query={filter}>
|
<SalesByItemProvider query={query}>
|
||||||
<SalesByItemsActionsBar
|
<SalesByItemsActionsBar
|
||||||
numberFormat={filter.numberFormat}
|
numberFormat={query.numberFormat}
|
||||||
onNumberFormatSubmit={handleNumberFormatSubmit}
|
onNumberFormatSubmit={handleNumberFormatSubmit}
|
||||||
/>
|
/>
|
||||||
<SalesByItemsLoadingBar />
|
<SalesByItemsLoadingBar />
|
||||||
@@ -64,7 +60,7 @@ function SalesByItems({
|
|||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<FinancialStatement>
|
<FinancialStatement>
|
||||||
<SalesByItemsHeader
|
<SalesByItemsHeader
|
||||||
pageFilter={filter}
|
pageFilter={query}
|
||||||
onSubmitFilter={handleFilterSubmit}
|
onSubmitFilter={handleFilterSubmit}
|
||||||
/>
|
/>
|
||||||
<SalesByItemsBody />
|
<SalesByItemsBody />
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||||
@@ -14,7 +12,11 @@ import SalesByItemsHeaderGeneralPanel from './SalesByItemsHeaderGeneralPanel';
|
|||||||
import withSalesByItems from './withSalesByItems';
|
import withSalesByItems from './withSalesByItems';
|
||||||
import withSalesByItemsActions from './withSalesByItemsActions';
|
import withSalesByItemsActions from './withSalesByItemsActions';
|
||||||
|
|
||||||
import { compose } from '@/utils';
|
import { compose, transformToForm } from '@/utils';
|
||||||
|
import {
|
||||||
|
getDefaultSalesByItemsQuery,
|
||||||
|
getSalesByItemsQueryShema,
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sales by items header.
|
* Sales by items header.
|
||||||
@@ -31,21 +33,22 @@ function SalesByItemsHeader({
|
|||||||
toggleSalesByItemsFilterDrawer,
|
toggleSalesByItemsFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
// Form validation schema.
|
// Form validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getSalesByItemsQueryShema();
|
||||||
fromDate: Yup.date().required().label(intl.get('from_date')),
|
|
||||||
toDate: Yup.date()
|
const defaultQuery = getDefaultSalesByItemsQuery();
|
||||||
.min(Yup.ref('fromDate'))
|
|
||||||
.required()
|
|
||||||
.label(intl.get('to_date')),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = {
|
const initialValues = transformToForm(
|
||||||
...pageFilter,
|
{
|
||||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
...defaultQuery,
|
||||||
toDate: moment(pageFilter.toDate).toDate(),
|
...pageFilter,
|
||||||
};
|
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||||
|
toDate: moment(pageFilter.toDate).toDate(),
|
||||||
|
},
|
||||||
|
defaultQuery,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle the form submitting.
|
||||||
const handleSubmit = (values, { setSubmitting }) => {
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
onSubmitFilter(values);
|
onSubmitFilter(values);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormGroup, Classes } from '@blueprintjs/core';
|
import {
|
||||||
import { Field } from 'formik';
|
Row,
|
||||||
import classNames from 'classnames';
|
Col,
|
||||||
|
ItemsMultiSelect,
|
||||||
import { filterItemsOptions } from '../constants';
|
FormattedMessage as T,
|
||||||
import { Row, Col, ItemsMultiSelect, FormattedMessage as T } from '@/components';
|
FFormGroup,
|
||||||
|
} from '@/components';
|
||||||
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
||||||
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
||||||
|
import { filterItemsOptions } from '../constants';
|
||||||
import {
|
import {
|
||||||
SalesByItemGeneralPanelProvider,
|
SalesByItemGeneralPanelProvider,
|
||||||
useSalesByItemsGeneralPanelContext,
|
useSalesByItemsGeneralPanelContext,
|
||||||
@@ -46,22 +48,9 @@ function SalesByItemsHeaderGeneralPanelContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={4}>
|
<Col xs={4}>
|
||||||
<Field name={'itemsIds'}>
|
<FFormGroup label={<T id={'Specific items'} />} name={'itemsIds'}>
|
||||||
{({ form: { setFieldValue }, field: { value } }) => (
|
<ItemsMultiSelect name={'itemsIds'} items={items} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'Specific items'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<ItemsMultiSelect
|
|
||||||
items={items}
|
|
||||||
onItemSelect={(items) => {
|
|
||||||
const itemsIds = items.map((item) => item.id);
|
|
||||||
setFieldValue('itemsIds', itemsIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,63 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
import React from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { castArray } from 'lodash';
|
||||||
|
import { useAppQueryString } from '@/hooks';
|
||||||
|
import { transformToForm } from '@/utils';
|
||||||
|
|
||||||
export const getDefaultSalesByItemsQuery = () => {
|
/**
|
||||||
|
* Retrieves the validation schema.
|
||||||
|
* @returns {Yup}
|
||||||
|
*/
|
||||||
|
export const getSalesByItemsQueryShema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
fromDate: Yup.date().required().label(intl.get('from_date')),
|
||||||
|
toDate: Yup.date()
|
||||||
|
.min(Yup.ref('fromDate'))
|
||||||
|
.required()
|
||||||
|
.label(intl.get('to_date')),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the default query.
|
||||||
|
*/
|
||||||
|
export const getDefaultSalesByItemsQuery = () => ({
|
||||||
|
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||||
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
|
filterByOption: 'with-transactions',
|
||||||
|
itemsIds: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses sales by items query of browser location.
|
||||||
|
*/
|
||||||
|
const parseSalesByItemsQuery = (locationQuery) => {
|
||||||
|
const defaultQuery = getDefaultSalesByItemsQuery();
|
||||||
|
|
||||||
|
const transformed = {
|
||||||
|
...defaultQuery,
|
||||||
|
...transformToForm(locationQuery, defaultQuery),
|
||||||
|
};
|
||||||
return {
|
return {
|
||||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
...transformed,
|
||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
itemsIds: castArray(transformed.itemsIds),
|
||||||
filterByOption: 'with-transactions',
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sales by items query state.
|
||||||
|
*/
|
||||||
|
export const useSalesByItemsQuery = () => {
|
||||||
|
// Retrieves location query.
|
||||||
|
const [locationQuery, setLocationQuery] = useAppQueryString();
|
||||||
|
|
||||||
|
// Merges the default filter query with location URL query.
|
||||||
|
const query = React.useMemo(
|
||||||
|
() => parseSalesByItemsQuery(locationQuery),
|
||||||
|
[locationQuery],
|
||||||
|
);
|
||||||
|
return { query, locationQuery, setLocationQuery };
|
||||||
|
};
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { VendorBalanceSummaryBody } from './VendorsBalanceSummaryBody';
|
|||||||
|
|
||||||
import withVendorsBalanceSummaryActions from './withVendorsBalanceSummaryActions';
|
import withVendorsBalanceSummaryActions from './withVendorsBalanceSummaryActions';
|
||||||
|
|
||||||
import { getDefaultVendorsBalanceQuery } from './utils';
|
import { useVendorsBalanceSummaryQuery } from './utils';
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,9 +23,7 @@ function VendorsBalanceSummary({
|
|||||||
// #withVendorsBalanceSummaryActions
|
// #withVendorsBalanceSummaryActions
|
||||||
toggleVendorSummaryFilterDrawer,
|
toggleVendorSummaryFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
const { query, setLocationQuery } = useVendorsBalanceSummaryQuery();
|
||||||
...getDefaultVendorsBalanceQuery(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle refetch vendors balance summary.
|
// Handle refetch vendors balance summary.
|
||||||
const handleFilterSubmit = (filter) => {
|
const handleFilterSubmit = (filter) => {
|
||||||
@@ -33,28 +31,26 @@ function VendorsBalanceSummary({
|
|||||||
...filter,
|
...filter,
|
||||||
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
setFilter(_filter);
|
setLocationQuery(_filter);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle number format submit.
|
// Handle number format submit.
|
||||||
const handleNumberFormatSubmit = (format) => {
|
const handleNumberFormatSubmit = (format) => {
|
||||||
setFilter({
|
setLocationQuery({
|
||||||
...filter,
|
...filter,
|
||||||
numberFormat: format,
|
numberFormat: format,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => toggleVendorSummaryFilterDrawer(false),
|
||||||
toggleVendorSummaryFilterDrawer(false);
|
|
||||||
},
|
|
||||||
[toggleVendorSummaryFilterDrawer],
|
[toggleVendorSummaryFilterDrawer],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VendorsBalanceSummaryProvider filter={filter}>
|
<VendorsBalanceSummaryProvider filter={query}>
|
||||||
<VendorsBalanceSummaryActionsBar
|
<VendorsBalanceSummaryActionsBar
|
||||||
numberFormat={filter?.numberFormat}
|
numberFormat={query?.numberFormat}
|
||||||
onNumberFormatSubmit={handleNumberFormatSubmit}
|
onNumberFormatSubmit={handleNumberFormatSubmit}
|
||||||
/>
|
/>
|
||||||
<VendorsSummarySheetLoadingBar />
|
<VendorsSummarySheetLoadingBar />
|
||||||
@@ -62,7 +58,7 @@ function VendorsBalanceSummary({
|
|||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<FinancialStatement>
|
<FinancialStatement>
|
||||||
<VendorsBalanceSummaryHeader
|
<VendorsBalanceSummaryHeader
|
||||||
pageFilter={filter}
|
pageFilter={query}
|
||||||
onSubmitFilter={handleFilterSubmit}
|
onSubmitFilter={handleFilterSubmit}
|
||||||
/>
|
/>
|
||||||
<VendorBalanceSummaryBody />
|
<VendorBalanceSummaryBody />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
@@ -13,6 +13,7 @@ import FinancialStatementHeader from '../FinancialStatementHeader';
|
|||||||
import VendorsBalanceSummaryHeaderGeneral from './VendorsBalanceSummaryHeaderGeneral';
|
import VendorsBalanceSummaryHeaderGeneral from './VendorsBalanceSummaryHeaderGeneral';
|
||||||
import withVendorsBalanceSummary from './withVendorsBalanceSummary';
|
import withVendorsBalanceSummary from './withVendorsBalanceSummary';
|
||||||
import withVendorsBalanceSummaryActions from './withVendorsBalanceSummaryActions';
|
import withVendorsBalanceSummaryActions from './withVendorsBalanceSummaryActions';
|
||||||
|
import { getVendorsBalanceQuerySchema } from './utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vendors balance summary drawer header.
|
* Vendors balance summary drawer header.
|
||||||
@@ -28,10 +29,8 @@ function VendorsBalanceSummaryHeader({
|
|||||||
//#withVendorsBalanceSummaryActions
|
//#withVendorsBalanceSummaryActions
|
||||||
toggleVendorSummaryFilterDrawer,
|
toggleVendorSummaryFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
// validation schema.
|
// Validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getVendorsBalanceQuerySchema();
|
||||||
asDate: Yup.date().required().label('asDate'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// filter form initial values.
|
// filter form initial values.
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
@@ -80,6 +79,7 @@ function VendorsBalanceSummaryHeader({
|
|||||||
panel={<VendorsBalanceSummaryHeaderGeneral />}
|
panel={<VendorsBalanceSummaryHeaderGeneral />}
|
||||||
/>
|
/>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|
||||||
<div className={'financial-header-drawer__footer'}>
|
<div className={'financial-header-drawer__footer'}>
|
||||||
<Button className={'mr1'} intent={Intent.PRIMARY} type={'submit'}>
|
<Button className={'mr1'} intent={Intent.PRIMARY} type={'submit'}>
|
||||||
<T id={'calculate_report'} />
|
<T id={'calculate_report'} />
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Field, FastField } from 'formik';
|
import { FastField } from 'formik';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import classNames from 'classnames';
|
import { FormGroup, Position, Checkbox } from '@blueprintjs/core';
|
||||||
import { FormGroup, Position, Classes, Checkbox } from '@blueprintjs/core';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ContactsMultiSelect,
|
|
||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
FieldHint,
|
FieldHint,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
|
FFormGroup,
|
||||||
|
VendorsMultiSelect,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { filterVendorsOptions } from '../constants';
|
import { filterVendorsOptions } from '../constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
@@ -87,22 +86,9 @@ export default function VendorsBalanceSummaryHeaderGeneralContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<Field name={'vendorsIds'}>
|
<FFormGroup label={<T id={'specific_vendors'} />} name={'vendorsIds'}>
|
||||||
{({ form: { setFieldValue } }) => (
|
<VendorsMultiSelect name={'vendorsIds'} items={vendors} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'specific_vendors'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<ContactsMultiSelect
|
|
||||||
items={vendors}
|
|
||||||
onItemSelect={(contacts) => {
|
|
||||||
const vendorsIds = contacts.map((contact) => contact.id);
|
|
||||||
setFieldValue('vendorsIds', vendorsIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,44 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
import { castArray } from 'lodash';
|
||||||
|
import { useAppQueryString } from '@/hooks';
|
||||||
|
import { transformToForm } from '@/utils';
|
||||||
|
|
||||||
export const getDefaultVendorsBalanceQuery = () => {
|
export const getDefaultVendorsBalanceQuery = () => {
|
||||||
return {
|
return {
|
||||||
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
||||||
filterByOption: 'with-transactions',
|
filterByOption: 'with-transactions',
|
||||||
|
vendorsIds: [],
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export const getVendorsBalanceQuerySchema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
asDate: Yup.date().required().label('asDate'),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const parseVendorsBalanceSummaryQuery = (locationQuery) => {
|
||||||
|
const defaultQuery = getDefaultVendorsBalanceQuery();
|
||||||
|
|
||||||
|
const transformed = {
|
||||||
|
...defaultQuery,
|
||||||
|
...transformToForm(locationQuery, defaultQuery),
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
...transformed,
|
||||||
|
vendorsIds: castArray(transformed.vendorsIds),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useVendorsBalanceSummaryQuery = () => {
|
||||||
|
const [locationQuery, setLocationQuery] = useAppQueryString();
|
||||||
|
|
||||||
|
const query = useMemo(
|
||||||
|
() => parseVendorsBalanceSummaryQuery(locationQuery),
|
||||||
|
[locationQuery],
|
||||||
|
);
|
||||||
|
return { query, locationQuery, setLocationQuery };
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import * as Yup from 'yup';
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T } from '@/components';
|
import { FormattedMessage as T } from '@/components';
|
||||||
@@ -14,11 +13,14 @@ import withVendorsTransaction from './withVendorsTransaction';
|
|||||||
import withVendorsTransactionsActions from './withVendorsTransactionsActions';
|
import withVendorsTransactionsActions from './withVendorsTransactionsActions';
|
||||||
|
|
||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm } from '@/utils';
|
||||||
|
import {
|
||||||
|
getVendorTransactionsQuerySchema,
|
||||||
|
getVendorsTransactionsDefaultQuery,
|
||||||
|
} from './_utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vendors transactions header.
|
* Vendors transactions header.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function VendorsTransactionsHeader({
|
function VendorsTransactionsHeader({
|
||||||
// #ownProps
|
// #ownProps
|
||||||
onSubmitFilter,
|
onSubmitFilter,
|
||||||
@@ -31,12 +33,7 @@ function VendorsTransactionsHeader({
|
|||||||
toggleVendorsTransactionsFilterDrawer: toggleFilterDrawer,
|
toggleVendorsTransactionsFilterDrawer: toggleFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
// Default form values.
|
// Default form values.
|
||||||
const defaultValues = {
|
const defaultValues = getVendorsTransactionsDefaultQuery();
|
||||||
...pageFilter,
|
|
||||||
fromDate: moment().toDate(),
|
|
||||||
toDate: moment().toDate(),
|
|
||||||
vendorsIds: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initial form values.
|
// Initial form values.
|
||||||
const initialValues = transformToForm(
|
const initialValues = transformToForm(
|
||||||
@@ -48,15 +45,8 @@ function VendorsTransactionsHeader({
|
|||||||
},
|
},
|
||||||
defaultValues,
|
defaultValues,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Validation schema.
|
// Validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = getVendorTransactionsQuerySchema();
|
||||||
fromDate: Yup.date().required().label(intl.get('fromDate')),
|
|
||||||
toDate: Yup.date()
|
|
||||||
.min(Yup.ref('fromDate'))
|
|
||||||
.required()
|
|
||||||
.label(intl.get('toDate')),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle form submit.
|
// Handle form submit.
|
||||||
const handleSubmit = (values, { setSubmitting }) => {
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
@@ -64,7 +54,6 @@ function VendorsTransactionsHeader({
|
|||||||
toggleFilterDrawer(false);
|
toggleFilterDrawer(false);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle drawer close action.
|
// Handle drawer close action.
|
||||||
const handleDrawerClose = () => {
|
const handleDrawerClose = () => {
|
||||||
toggleFilterDrawer(false);
|
toggleFilterDrawer(false);
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Field } from 'formik';
|
|
||||||
import { Classes, FormGroup } from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
|
||||||
|
|
||||||
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
||||||
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
||||||
@@ -10,8 +7,9 @@ import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
|||||||
import {
|
import {
|
||||||
Row,
|
Row,
|
||||||
Col,
|
Col,
|
||||||
ContactsMultiSelect,
|
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
|
FFormGroup,
|
||||||
|
VendorsMultiSelect,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { filterVendorsOptions } from '../constants';
|
import { filterVendorsOptions } from '../constants';
|
||||||
|
|
||||||
@@ -53,22 +51,9 @@ function VendorsTransactionsHeaderGeneralPanelContent() {
|
|||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={4}>
|
<Col xs={4}>
|
||||||
<Field name={'vendorsIds'}>
|
<FFormGroup label={<T id={'specific_vendors'} />} name={'vendorsIds'}>
|
||||||
{({ form: { setFieldValue }, field: { value } }) => (
|
<VendorsMultiSelect name={'vendorsIds'} items={vendors} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'specific_vendors'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<ContactsMultiSelect
|
|
||||||
items={vendors}
|
|
||||||
onItemSelect={(vendors) => {
|
|
||||||
const vendorsIds = vendors.map((customer) => customer.id);
|
|
||||||
setFieldValue('vendorsIds', vendorsIds);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import * as Yup from 'yup';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The validation schema of vendors transactions.
|
||||||
|
*/
|
||||||
|
export const getVendorTransactionsQuerySchema = () => {
|
||||||
|
return Yup.object().shape({
|
||||||
|
fromDate: Yup.date().required().label(intl.get('fromDate')),
|
||||||
|
toDate: Yup.date()
|
||||||
|
.min(Yup.ref('fromDate'))
|
||||||
|
.required()
|
||||||
|
.label(intl.get('toDate')),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the default query of vendors transactions.
|
||||||
|
*/
|
||||||
|
export const getVendorsTransactionsDefaultQuery = () => ({
|
||||||
|
fromDate: moment().toDate(),
|
||||||
|
toDate: moment().toDate(),
|
||||||
|
vendorsIds: [],
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user