chrone: sperate client and server to different repos.

This commit is contained in:
a.bouhuolia
2021-09-21 17:13:53 +02:00
parent e011b2a82b
commit 18df5530c7
10015 changed files with 17686 additions and 97524 deletions

View File

@@ -0,0 +1,86 @@
import React, { useEffect, useState, useCallback } from 'react';
import moment from 'moment';
import 'style/pages/FinancialStatements/SalesAndPurchasesSheet.scss';
import { InventoryValuationProvider } from './InventoryValuationProvider';
import InventoryValuationActionsBar from './InventoryValuationActionsBar';
import InventoryValuationHeader from './InventoryValuationHeader';
import InventoryValuationTable from './InventoryValuationTable';
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
import { InventoryValuationLoadingBar } from './components';
import withInventoryValuationActions from './withInventoryValuationActions';
import withCurrentOrganization from '../../../containers/Organization/withCurrentOrganization';
import { compose } from 'utils';
/**
* Inventory valuation.
*/
function InventoryValuation({
// #withPreferences
organizationName,
// #withInventoryValuationActions
toggleInventoryValuationFilterDrawer,
}) {
const [filter, setFilter] = useState({
asDate: moment().endOf('day').format('YYYY-MM-DD'),
});
// Handle filter form submit.
const handleFilterSubmit = useCallback((filter) => {
const _filter = {
...filter,
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
};
setFilter(_filter);
}, []);
// Handle number format form submit.
const handleNumberFormatSubmit = (numberFormat) => {
setFilter({
...filter,
numberFormat,
});
};
// Hide the filter drawer once the page unmount.
useEffect(
() => () => {
toggleInventoryValuationFilterDrawer(false);
},
[toggleInventoryValuationFilterDrawer],
);
return (
<InventoryValuationProvider query={filter}>
<InventoryValuationActionsBar
numberFormat={filter.numberFormat}
onNumberFormatSubmit={handleNumberFormatSubmit}
/>
<InventoryValuationLoadingBar />
<DashboardPageContent>
<div class="financial-statement financial-statement--inventory-valuation">
<InventoryValuationHeader
pageFilter={filter}
onSubmitFilter={handleFilterSubmit}
/>
<div class="financial-statement__body">
<InventoryValuationTable companyName={organizationName} />
</div>
</div>
</DashboardPageContent>
</InventoryValuationProvider>
);
}
export default compose(
withInventoryValuationActions,
withCurrentOrganization(({ organization }) => ({
organizationName: organization.name,
})),
)(InventoryValuation);

View File

@@ -0,0 +1,128 @@
import React from 'react';
import {
NavbarGroup,
Button,
Classes,
NavbarDivider,
Popover,
PopoverInteractionKind,
Position,
} from '@blueprintjs/core';
import classNames from 'classnames';
import { FormattedMessage as T } from 'components';
import { Icon } from 'components';
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
import NumberFormatDropdown from 'components/NumberFormatDropdown';
import withInventoryValuation from './withInventoryValuation';
import withInventoryValuationActions from './withInventoryValuationActions';
import { useInventoryValuationContext } from './InventoryValuationProvider';
import { compose, saveInvoke } from 'utils';
function InventoryValuationActionsBar({
// #withInventoryValuation
isFilterDrawerOpen,
// #withInventoryValuationActions
toggleInventoryValuationFilterDrawer,
// #ownProps
numberFormat,
onNumberFormatSubmit,
}) {
const { refetchSheet, isLoading } = useInventoryValuationContext();
// Handle filter toggle click.
const handleFilterToggleClick = () => {
toggleInventoryValuationFilterDrawer();
};
// Handle re-calc button click.
const handleRecalculateReport = () => {
refetchSheet();
};
// Handle number format submit.
const handleNumberFormatSubmit = (numberFormat) => {
saveInvoke(onNumberFormatSubmit, numberFormat);
};
return (
<DashboardActionsBar>
<NavbarGroup>
<Button
className={classNames(Classes.MINIMAL, 'button--gray-highlight')}
text={<T id={'recalc_report'} />}
onClick={handleRecalculateReport}
icon={<Icon icon="refresh-16" iconSize={16} />}
/>
<NavbarDivider />
<Button
className={classNames(Classes.MINIMAL, 'button--table-views')}
icon={<Icon icon="cog-16" iconSize={16} />}
text={
isFilterDrawerOpen ? (
<T id={'hide_customizer'} />
) : (
<T id={'customize_report'} />
)
}
onClick={handleFilterToggleClick}
active={isFilterDrawerOpen}
/>
<NavbarDivider />
<Popover
content={
<NumberFormatDropdown
numberFormat={numberFormat}
onSubmit={handleNumberFormatSubmit}
submitDisabled={isLoading}
/>
}
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
className={classNames(Classes.MINIMAL, 'button--filter')}
text={<T id={'format'} />}
icon={<Icon icon="numbers" width={23} height={16} />}
/>
</Popover>
<Popover
// content={}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
className={classNames(Classes.MINIMAL, 'button--filter')}
text={<T id={'filter'} />}
icon={<Icon icon="filter-16" iconSize={16} />}
/>
</Popover>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="print-16" iconSize={16} />}
text={<T id={'print'} />}
/>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="file-export-16" iconSize={16} />}
text={<T id={'export'} />}
/>
</NavbarGroup>
</DashboardActionsBar>
);
}
export default compose(
withInventoryValuation(({ inventoryValuationDrawerFilter }) => ({
isFilterDrawerOpen: inventoryValuationDrawerFilter,
})),
withInventoryValuationActions,
)(InventoryValuationActionsBar);

View File

@@ -0,0 +1,99 @@
import React from 'react';
import * as Yup from 'yup';
import moment from 'moment';
import { FormattedMessage as T } from 'components';
import { Formik, Form } from 'formik';
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader';
import InventoryValuationHeaderGeneralPanel from './InventoryValuationHeaderGeneralPanel';
import withInventoryValuation from './withInventoryValuation';
import withInventoryValuationActions from './withInventoryValuationActions';
import { compose, transformToForm } from 'utils';
/**
* inventory valuation header.
*/
function InventoryValuationHeader({
// #ownProps
pageFilter,
onSubmitFilter,
// #withInventoryValuation
isFilterDrawerOpen,
// #withInventoryValuationActions
toggleInventoryValuationFilterDrawer,
}) {
// Form validation schema.
const validationSchema = Yup.object().shape({
asDate: Yup.date().required().label('asDate'),
});
// Default values.
const defaultValues = {
asDate: moment().toDate(),
itemsIds: [],
};
// Initial values.
const initialValues = transformToForm({
...pageFilter,
asDate: moment(pageFilter.asDate).toDate(),
}, defaultValues);
// Handle the form of header submit.
const handleSubmit = (values, { setSubmitting }) => {
onSubmitFilter(values);
toggleInventoryValuationFilterDrawer(false);
setSubmitting(false);
};
// Handle drawer close action.
const handleDrawerClose = () => {
toggleInventoryValuationFilterDrawer(false);
};
// Handle cancel button click.
const handleCancelClick = () => {
toggleInventoryValuationFilterDrawer(false);
};
return (
<FinancialStatementHeader
isOpen={isFilterDrawerOpen}
drawerProps={{ onClose: handleDrawerClose }}
>
<Formik
initialValues={initialValues}
validationSchema={validationSchema}
onSubmit={handleSubmit}
>
<Form>
<Tabs animate={true} vertical={true} renderActiveTabPanelOnly={true}>
<Tab
id="general"
title={<T id={'general'} />}
panel={<InventoryValuationHeaderGeneralPanel />}
/>
</Tabs>
<div class="financial-header-drawer__footer">
<Button className={'mr1'} intent={Intent.PRIMARY} type={'submit'}>
<T id={'calculate_report'} />
</Button>
<Button onClick={handleCancelClick} minimal={true}>
<T id={'cancel'} />
</Button>
</div>
</Form>
</Formik>
</FinancialStatementHeader>
);
}
export default compose(
withInventoryValuation(({ inventoryValuationDrawerFilter }) => ({
isFilterDrawerOpen: inventoryValuationDrawerFilter,
})),
withInventoryValuationActions,
)(InventoryValuationHeader);

View File

@@ -0,0 +1,92 @@
import React from 'react';
import { FastField, Field } from 'formik';
import { DateInput } from '@blueprintjs/datetime';
import { FormGroup, Position, Classes } from '@blueprintjs/core';
import classNames from 'classnames';
import {
FormattedMessage as T,
ItemsMultiSelect,
Row,
Col,
FieldHint,
} from '../../../components';
import {
momentFormatter,
tansformDateValue,
inputIntent,
handleDateChange,
} from 'utils';
import {
InventoryValuationGeneralPanelProvider,
useInventoryValuationGeneralPanelContext,
} from './InventoryValuationHeaderGeneralPanelProvider';
/**
* Inventory valuation - Drawer Header - General panel.
*/
export default function InventoryValuationHeaderGeneralPanel() {
return (
<InventoryValuationGeneralPanelProvider>
<InventoryValuationHeaderGeneralPanelContent />
</InventoryValuationGeneralPanelProvider>
);
}
/**
* Inventory valuation - Drawer Header - General panel - Content.
*/
function InventoryValuationHeaderGeneralPanelContent() {
const { items } = useInventoryValuationGeneralPanelContext();
return (
<div>
<Row>
<Col xs={5}>
<FastField name={'asDate'}>
{({ form, field: { value }, meta: { error } }) => (
<FormGroup
label={<T id={'as_date'} />}
labelInfo={<FieldHint />}
fill={true}
intent={inputIntent({ error })}
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
value={tansformDateValue(value)}
onChange={handleDateChange((selectedDate) => {
form.setFieldValue('asDate', selectedDate);
})}
popoverProps={{ position: Position.BOTTOM, minimal: true }}
minimal={true}
fill={true}
/>
</FormGroup>
)}
</FastField>
</Col>
</Row>
<Row>
<Col xs={5}>
<Field name={'itemsIds'}>
{({ form: { setFieldValue } }) => (
<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>
</Row>
</div>
);
}

View File

@@ -0,0 +1,45 @@
import React from 'react';
import { FinancialHeaderLoadingSkeleton } from '../FinancialHeaderLoadingSkeleton';
import { useItems } from 'hooks/query';
const InventoryValuationGeneralPanelContext = React.createContext();
function InventoryValuationGeneralPanelProvider({ query, ...props }) {
// Handle fetching the items based on the given query.
const {
data: { items },
isLoading: isItemsLoading,
isFetching: isItemsFetching,
} = useItems({
stringified_filter_roles: JSON.stringify([
{ fieldKey: 'type', comparator: 'is', value: 'inventory', index: 1 },
]),
page_size: 10000,
});
// Provider data.
const provider = {
items,
isItemsFetching,
isItemsLoading,
};
const loading = isItemsLoading;
return loading ? (
<FinancialHeaderLoadingSkeleton />
) : (
<InventoryValuationGeneralPanelContext.Provider
value={provider}
{...props}
/>
);
}
const useInventoryValuationGeneralPanelContext = () =>
React.useContext(InventoryValuationGeneralPanelContext);
export {
InventoryValuationGeneralPanelProvider,
useInventoryValuationGeneralPanelContext,
};

View File

@@ -0,0 +1,42 @@
import React from 'react';
import FinancialReportPage from '../FinancialReportPage';
import { useInventoryValuation } from 'hooks/query';
import { transformFilterFormToQuery } from '../common';
const InventoryValuationContext = React.createContext();
function InventoryValuationProvider({ query, ...props }) {
const {
data: inventoryValuation,
isFetching,
isLoading,
refetch,
} = useInventoryValuation(
{
...transformFilterFormToQuery(query),
},
{
keepPreviousData: true,
},
);
// Provider data.
const provider = {
inventoryValuation,
isLoading,
isFetching,
refetchSheet: refetch,
};
return (
<FinancialReportPage name={'inventory-valuation'}>
<InventoryValuationContext.Provider value={provider} {...props} />
</FinancialReportPage>
);
}
const useInventoryValuationContext = () =>
React.useContext(InventoryValuationContext);
export { InventoryValuationProvider, useInventoryValuationContext };

View File

@@ -0,0 +1,63 @@
import React from 'react';
import intl, { init } from 'react-intl-universal';
import FinancialSheet from 'components/FinancialSheet';
import { DataTable } from 'components';
import { useInventoryValuationContext } from './InventoryValuationProvider';
import { useInventoryValuationTableColumns } from './components';
/**
* inventory valuation data table.
*/
export default function InventoryValuationTable({
//#ownProps
companyName,
}) {
// inventory valuation context.
const {
inventoryValuation: { tableRows },
isLoading,
} = useInventoryValuationContext();
// inventory valuation table columns.
const columns = useInventoryValuationTableColumns();
const rowClassNames = (row) => {
const { original } = row;
const rowTypes = Array.isArray(original.rowType)
? original.rowType
: [original.rowType];
return {
...rowTypes.reduce((acc, rowType) => {
acc[`row_type--${rowType}`] = rowType;
return acc;
}, {}),
};
};
return (
<FinancialSheet
companyName={companyName}
name="inventory-valuation"
sheetType={intl.get('inventory_valuation')}
asDate={new Date()}
loading={isLoading}
>
<DataTable
className="bigcapital-datatable--financial-report"
columns={columns}
data={tableRows}
expandable={true}
expandToggleColumn={1}
expandColumnSpace={1}
sticky={true}
rowClassNames={rowClassNames}
noResults={intl.get(
'there_were_no_inventory_transactions_during_the_selected_date_range',
)}
/>
</FinancialSheet>
);
}

View File

@@ -0,0 +1,76 @@
import React, { useMemo } from 'react';
import intl from 'react-intl-universal';
import { getColumnWidth } from 'utils';
import { If } from 'components';
import { CellTextSpan } from 'components/Datatable/Cells';
import { useInventoryValuationContext } from './InventoryValuationProvider';
import FinancialLoadingBar from '../FinancialLoadingBar';
/**
* Retrieve inventory valuation table columns.
*/
export const useInventoryValuationTableColumns = () => {
// inventory valuation context
const {
inventoryValuation: { tableRows },
} = useInventoryValuationContext();
return useMemo(
() => [
{
Header: intl.get('item_name'),
accessor: (row) => (row.code ? `${row.name} - ${row.code}` : row.name),
className: 'name',
width: 240,
textOverview: true,
},
{
Header: intl.get('quantity'),
accessor: 'quantity_formatted',
Cell: CellTextSpan,
className: 'quantity_formatted',
width: getColumnWidth(tableRows, `quantity_formatted`, {
minWidth: 120,
}),
textOverview: true,
},
{
Header: intl.get('asset_value'),
accessor: 'valuation_formatted',
Cell: CellTextSpan,
className: 'valuation',
width: getColumnWidth(tableRows, `valuation_formatted`, {
minWidth: 120,
}),
textOverview: true,
},
{
Header: intl.get('average'),
accessor: 'average_formatted',
Cell: CellTextSpan,
className: 'average_formatted',
width: getColumnWidth(tableRows, `average_formatted`, {
minWidth: 120,
}),
textOverview: true,
},
],
[tableRows],
);
};
/**
* inventory valuation progress loading bar.
*/
export function InventoryValuationLoadingBar() {
const { isFetching } = useInventoryValuationContext();
return (
<If condition={isFetching}>
<FinancialLoadingBar />
</If>
);
}

View File

@@ -0,0 +1,12 @@
import { connect } from 'react-redux';
import { getInventoryValuationFilterDrawer } from 'store/financialStatement/financialStatements.selectors';
export default (mapState) => {
const mapStateToProps = (state, props) => {
const mapped = {
inventoryValuationDrawerFilter: getInventoryValuationFilterDrawer(state),
};
return mapState ? mapState(mapped, state, props) : mapped;
};
return connect(mapStateToProps);
};

View File

@@ -0,0 +1,9 @@
import { connect } from 'react-redux';
import { toggleInventoryValuationFilterDrawer } from 'store/financialStatement/financialStatements.actions';
export const mapDispatchToProps = (dispatch) => ({
toggleInventoryValuationFilterDrawer: (toggle) =>
dispatch(toggleInventoryValuationFilterDrawer(toggle)),
});
export default connect(null, mapDispatchToProps);