mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
// @ts-nocheck
|
||||
import React, { useEffect } from 'react';
|
||||
import moment from 'moment';
|
||||
|
||||
import {
|
||||
ProjectProfitabilitySummaryAlerts,
|
||||
ProjectProfitabilitySummaryLoadingBar,
|
||||
} from './components';
|
||||
import { FinancialStatement, DashboardPageContent } from '@/components';
|
||||
|
||||
import ProjectProfitabilitySummaryHeader from './ProjectProfitabilitySummaryHeader';
|
||||
import ProjectProfitabilitySummaryActionsBar from './ProjectProfitabilitySummaryActionsBar';
|
||||
import { ProjectProfitabilitySummaryBody } from './ProjectProfitabilitySummaryBody';
|
||||
import { ProjectProfitabilitySummaryProvider } from './ProjectProfitabilitySummaryProvider';
|
||||
import { useProjectProfitabilitySummaryQuery } from './utils';
|
||||
import withProjectProfitabilitySummaryActions from './withProjectProfitabilitySummaryActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* Project profitability summary.
|
||||
* @returns {React.JSX}
|
||||
*/
|
||||
function ProjectProfitabilitySummary({
|
||||
// #withProjectProfitabilitySummaryActions
|
||||
toggleProjectProfitabilitySummaryFilterDrawer,
|
||||
}) {
|
||||
// Project profitability summary query.
|
||||
const { query, setLocationQuery } = useProjectProfitabilitySummaryQuery();
|
||||
|
||||
// Handle refetch project profitability summary filter changer.
|
||||
const handleFilterSubmit = (filter) => {
|
||||
const newFilter = {
|
||||
...filter,
|
||||
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
||||
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
||||
};
|
||||
setLocationQuery({ ...newFilter });
|
||||
};
|
||||
// Handle number format submit.
|
||||
const handleNumberFormatSubmit = (values) => {
|
||||
setLocationQuery({
|
||||
...query,
|
||||
numberFormat: values,
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
toggleProjectProfitabilitySummaryFilterDrawer(false);
|
||||
},
|
||||
[toggleProjectProfitabilitySummaryFilterDrawer],
|
||||
);
|
||||
|
||||
return (
|
||||
<ProjectProfitabilitySummaryProvider filter={query}>
|
||||
<ProjectProfitabilitySummaryActionsBar
|
||||
numberFormat={query.numberFormat}
|
||||
onNumberFormatSubmit={handleNumberFormatSubmit}
|
||||
/>
|
||||
<ProjectProfitabilitySummaryLoadingBar />
|
||||
<ProjectProfitabilitySummaryAlerts />
|
||||
|
||||
<DashboardPageContent>
|
||||
<FinancialStatement>
|
||||
<ProjectProfitabilitySummaryHeader
|
||||
pageFilter={query}
|
||||
onFilterSubmit={handleFilterSubmit}
|
||||
/>
|
||||
<ProjectProfitabilitySummaryBody />
|
||||
</FinancialStatement>
|
||||
</DashboardPageContent>
|
||||
</ProjectProfitabilitySummaryProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withProjectProfitabilitySummaryActions)(
|
||||
ProjectProfitabilitySummary,
|
||||
);
|
||||
@@ -0,0 +1,132 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import {
|
||||
NavbarGroup,
|
||||
NavbarDivider,
|
||||
Button,
|
||||
Classes,
|
||||
Popover,
|
||||
PopoverInteractionKind,
|
||||
Position,
|
||||
} from '@blueprintjs/core';
|
||||
import { DashboardActionsBar, FormattedMessage as T, Icon } from '@/components';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import NumberFormatDropdown from '@/components/NumberFormatDropdown';
|
||||
|
||||
import { compose, saveInvoke } from '@/utils';
|
||||
import { useProjectProfitabilitySummaryContext } from './ProjectProfitabilitySummaryProvider';
|
||||
import withProjectProfitabilitySummary from './withProjectProfitabilitySummary';
|
||||
import withProjectProfitabilitySummaryActions from './withProjectProfitabilitySummaryActions';
|
||||
|
||||
/**
|
||||
* Project profitability summary actions bar.
|
||||
*/
|
||||
function ProjectProfitabilitySummaryActionsBar({
|
||||
// #withProjectProfitabilitySummary
|
||||
isFilterDrawerOpen,
|
||||
|
||||
// #withProjectProfitabilitySummaryActions
|
||||
toggleProjectProfitabilitySummaryFilterDrawer: toggleFilterDrawer,
|
||||
|
||||
// #ownProps
|
||||
numberFormat,
|
||||
onNumberFormatSubmit,
|
||||
}) {
|
||||
const { isLoading, refetchProjectProfitabilitySummary } =
|
||||
useProjectProfitabilitySummaryContext();
|
||||
|
||||
// Handle filter toggle click.
|
||||
const handleFilterToggleClick = () => {
|
||||
toggleFilterDrawer();
|
||||
};
|
||||
|
||||
// Handle recalculate the report button.
|
||||
const handleRecalcReport = () => {
|
||||
refetchProjectProfitabilitySummary();
|
||||
};
|
||||
|
||||
// Handle number format form submit.
|
||||
const handleNumberFormatSubmit = (values) => {
|
||||
saveInvoke(onNumberFormatSubmit, values);
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<Button
|
||||
className={classNames(Classes.MINIMAL, 'button--gray-highlight')}
|
||||
text={<T id={'recalc_report'} />}
|
||||
onClick={handleRecalcReport}
|
||||
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={'customize_report'} />
|
||||
) : (
|
||||
<T id={'hide_customizer'} />
|
||||
)
|
||||
}
|
||||
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>
|
||||
|
||||
<NavbarDivider />
|
||||
|
||||
<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(
|
||||
withProjectProfitabilitySummary(
|
||||
({ projectProfitabilitySummaryDrawerFilter }) => ({
|
||||
isFilterDrawerOpen: projectProfitabilitySummaryDrawerFilter,
|
||||
}),
|
||||
),
|
||||
withProjectProfitabilitySummaryActions,
|
||||
)(ProjectProfitabilitySummaryActionsBar);
|
||||
@@ -0,0 +1,39 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import ProjectProfitabilitySummaryTable from './ProjectProfitabilitySummaryTable';
|
||||
import { FinancialReportBody } from '../FinancialReportPage';
|
||||
import { FinancialSheetSkeleton } from '@/components/FinancialSheet';
|
||||
import { useProjectProfitabilitySummaryContext } from './ProjectProfitabilitySummaryProvider';
|
||||
|
||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* Project profitability summary body JSX.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
function ProjectProfitabilitySummaryBodyJSX({
|
||||
// #withCurrentOrganization
|
||||
organizationName,
|
||||
}) {
|
||||
const { isProjectProfitabilitySummaryLoading } =
|
||||
useProjectProfitabilitySummaryContext();
|
||||
|
||||
return (
|
||||
<FinancialReportBody>
|
||||
{isProjectProfitabilitySummaryLoading ? (
|
||||
<FinancialSheetSkeleton />
|
||||
) : (
|
||||
<ProjectProfitabilitySummaryTable companyName={organizationName} />
|
||||
)}
|
||||
</FinancialReportBody>
|
||||
);
|
||||
}
|
||||
|
||||
export const ProjectProfitabilitySummaryBody = compose(
|
||||
withCurrentOrganization(({ organization }) => ({
|
||||
organizationName: organization?.name,
|
||||
})),
|
||||
)(ProjectProfitabilitySummaryBodyJSX);
|
||||
@@ -0,0 +1,115 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import moment from 'moment';
|
||||
import { Formik, Form } from 'formik';
|
||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from '@/components';
|
||||
|
||||
import withProjectProfitabilitySummary from './withProjectProfitabilitySummary';
|
||||
import withProjectProfitabilitySummaryActions from './withProjectProfitabilitySummaryActions';
|
||||
|
||||
import ProjectProfitabilitySummaryHeaderGeneralPanal from './ProjectProfitabilitySummaryHeaderGeneralPanal';
|
||||
import FinancialStatementHeader from '../FinancialStatementHeader';
|
||||
|
||||
import {
|
||||
getProjectProfitabilitySummaryValidationSchema,
|
||||
getDefaultProjectProfitabilitySummaryQuery,
|
||||
} from './utils';
|
||||
import { compose, transformToForm } from '@/utils';
|
||||
|
||||
/**
|
||||
* Project profitability summary header.
|
||||
*/
|
||||
function ProjectProfitabilitySummaryHeader({
|
||||
// #ownProps
|
||||
onSubmitFilter,
|
||||
pageFilter,
|
||||
|
||||
// #withProjectProfitabilitySummary
|
||||
isFilterDrawerOpen,
|
||||
|
||||
// #withProjectProfitabilitySummaryActions
|
||||
toggleProjectProfitabilitySummaryFilterDrawer: toggleFilterDrawer,
|
||||
}) {
|
||||
// Filter form default values.
|
||||
const defaultValues = getDefaultProjectProfitabilitySummaryQuery();
|
||||
|
||||
// Filter form initial values.
|
||||
const initialValues = transformToForm(
|
||||
{
|
||||
...pageFilter,
|
||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||
toDate: moment(pageFilter.toDate).toDate(),
|
||||
},
|
||||
defaultValues,
|
||||
);
|
||||
|
||||
// Validation schema.
|
||||
const validationSchema = getProjectProfitabilitySummaryValidationSchema();
|
||||
|
||||
// Handle form submit.
|
||||
const handleSubmit = (values, { setSubmitting }) => {
|
||||
onSubmitFilter(values);
|
||||
toggleFilterDrawer(false);
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
// Handle cancel button click.
|
||||
const handleCancelClick = () => {
|
||||
toggleFilterDrawer(false);
|
||||
};
|
||||
|
||||
// Handle drawer close action.
|
||||
const handleDrawerClose = () => {
|
||||
toggleFilterDrawer(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<ProjectProfitabilityDrawerHeader
|
||||
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={<ProjectProfitabilitySummaryHeaderGeneralPanal />}
|
||||
/>
|
||||
</Tabs>
|
||||
<div className="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>
|
||||
</ProjectProfitabilityDrawerHeader>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withProjectProfitabilitySummary(
|
||||
({ projectProfitabilitySummaryDrawerFilter }) => ({
|
||||
isFilterDrawerOpen: projectProfitabilitySummaryDrawerFilter,
|
||||
}),
|
||||
),
|
||||
withProjectProfitabilitySummaryActions,
|
||||
)(ProjectProfitabilitySummaryHeader);
|
||||
|
||||
const ProjectProfitabilityDrawerHeader = styled(FinancialStatementHeader)`
|
||||
.bp3-drawer {
|
||||
max-height: 520px;
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,49 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import { filterProjectProfitabilityOptions } from './constants';
|
||||
import { Classes } from '@blueprintjs/core';
|
||||
import { ProjectMultiSelect } from '@/containers/Projects/components';
|
||||
import { Row, Col, FFormGroup, FormattedMessage as T } from '@/components';
|
||||
|
||||
import FinancialStatementDateRange from '../FinancialStatementDateRange';
|
||||
import FinancialStatementsFilter from '../FinancialStatementsFilter';
|
||||
import RadiosAccountingBasis from '../RadiosAccountingBasis';
|
||||
|
||||
import { useProjectProfitabilitySummaryContext } from './ProjectProfitabilitySummaryProvider';
|
||||
|
||||
/**
|
||||
* Project profitability summary header - General panal.
|
||||
*/
|
||||
export default function ProjectProfitabilitySummaryHeaderGeneralPanal() {
|
||||
const { projects } = useProjectProfitabilitySummaryContext();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<FinancialStatementDateRange />
|
||||
<Row>
|
||||
<Col xs={4}>
|
||||
<FinancialStatementsFilter
|
||||
items={filterProjectProfitabilityOptions}
|
||||
initialSelectedItem={'with-transactions'}
|
||||
label={
|
||||
<T id={'project_profitability_summary.filter_options.label'} />
|
||||
}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col xs={4}>
|
||||
<FFormGroup
|
||||
name={'projectsIds'}
|
||||
label={<T id={'projects_multi_select.label'} />}
|
||||
className={Classes.FILL}
|
||||
>
|
||||
<ProjectMultiSelect name={'projectsIds'} projects={projects} />
|
||||
</FFormGroup>
|
||||
</Col>
|
||||
</Row>
|
||||
<RadiosAccountingBasis key={'basis'} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// @ts-nocheck
|
||||
import React, { createContext, useMemo, useContext } from 'react';
|
||||
|
||||
import FinancialReportPage from '../FinancialReportPage';
|
||||
import { useProjectProfitabilitySummary } from './hooks';
|
||||
import { useProjects } from '@/containers/Projects/hooks';
|
||||
import { transformFilterFormToQuery } from '../common';
|
||||
|
||||
const ProjectProfitabilitySummaryContext = createContext();
|
||||
|
||||
function ProjectProfitabilitySummaryProvider({ filter, ...props }) {
|
||||
// Transformes the given filter to query.
|
||||
const query = useMemo(() => transformFilterFormToQuery(filter), [filter]);
|
||||
|
||||
// Handle fetching the items table based on the given query.
|
||||
const {
|
||||
data: projectProfitabilitySummary,
|
||||
isFetching: isProjectProfitabilitySummaryFetching,
|
||||
isLoading: isProjectProfitabilitySummaryLoading,
|
||||
refetch: refetchProjectProfitabilitySummary,
|
||||
} = useProjectProfitabilitySummary(query, { keepPreviousData: true });
|
||||
|
||||
// Fetch project list.
|
||||
const {
|
||||
data: { projects },
|
||||
isLoading: isProjectsLoading,
|
||||
} = useProjects();
|
||||
|
||||
const provider = {
|
||||
projectProfitabilitySummary,
|
||||
isProjectProfitabilitySummaryFetching,
|
||||
isProjectProfitabilitySummaryLoading,
|
||||
refetchProjectProfitabilitySummary,
|
||||
projects,
|
||||
|
||||
query,
|
||||
filter,
|
||||
};
|
||||
return (
|
||||
<FinancialReportPage name={'project-profitability-summary'}>
|
||||
<ProjectProfitabilitySummaryContext.Provider
|
||||
value={provider}
|
||||
{...props}
|
||||
/>
|
||||
</FinancialReportPage>
|
||||
);
|
||||
}
|
||||
|
||||
const useProjectProfitabilitySummaryContext = () =>
|
||||
useContext(ProjectProfitabilitySummaryContext);
|
||||
|
||||
export {
|
||||
ProjectProfitabilitySummaryProvider,
|
||||
useProjectProfitabilitySummaryContext,
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
// @ts-nocheck
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { TableStyle } from '@/constants';
|
||||
import { ReportDataTable, FinancialSheet } from '@/components';
|
||||
import { useProjectProfitabilitySummaryContext } from './ProjectProfitabilitySummaryProvider';
|
||||
import { useProjectProfitabilitySummaryColumns } from './components';
|
||||
import { defaultExpanderReducer, tableRowTypesToClassnames } from '@/utils';
|
||||
|
||||
/**
|
||||
* Project profitability summary table.
|
||||
*/
|
||||
export default function ProjectProfitabilitySummaryTable({
|
||||
// #ownProps
|
||||
companyName,
|
||||
}) {
|
||||
// Project profitability summary context.
|
||||
const {
|
||||
projectProfitabilitySummary: { tableRows },
|
||||
query,
|
||||
} = useProjectProfitabilitySummaryContext();
|
||||
|
||||
// Retrieve the database columns.
|
||||
const tableColumns = useProjectProfitabilitySummaryColumns();
|
||||
|
||||
return (
|
||||
<FinancialSheet
|
||||
companyName={companyName}
|
||||
sheetType={intl.get('project_profitability_summary')}
|
||||
fromDate={query.from_date}
|
||||
toDate={query.to_date}
|
||||
basis={query.basis}
|
||||
name="project-profitability-summary"
|
||||
>
|
||||
<ProjectProfitabilitySummaryDataTable
|
||||
columns={tableColumns}
|
||||
data={tableRows}
|
||||
rowClassNames={tableRowTypesToClassnames}
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
styleName={TableStyle.Constrant}
|
||||
/>
|
||||
</FinancialSheet>
|
||||
);
|
||||
}
|
||||
|
||||
const ProjectProfitabilitySummaryDataTable = styled(ReportDataTable)`
|
||||
.table {
|
||||
.tbody .tr {
|
||||
.td {
|
||||
border-bottom: 0;
|
||||
padding-top: 0.32rem;
|
||||
padding-bottom: 0.32rem;
|
||||
}
|
||||
&.row_type--TOTAL .td {
|
||||
border-top: 1px solid #bbb;
|
||||
font-weight: 500;
|
||||
border-bottom: 3px double #000;
|
||||
}
|
||||
&:last-of-type .td {
|
||||
border-bottom: 1px solid #bbb;
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,56 @@
|
||||
// @ts-nocheck
|
||||
import React, { useMemo } from 'react';
|
||||
import { Button } from '@blueprintjs/core';
|
||||
|
||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||
|
||||
import { dynamicColumns } from './dynamicColumns';
|
||||
import { FinancialComputeAlert } from '../FinancialReportPage';
|
||||
import { FormattedMessage as T, Icon, If } from '@/components';
|
||||
import { useProjectProfitabilitySummaryContext } from './ProjectProfitabilitySummaryProvider';
|
||||
|
||||
/**
|
||||
* Project profitability summary alerts.
|
||||
*/
|
||||
export function ProjectProfitabilitySummaryAlerts() {
|
||||
// Handle refetch the report sheet.
|
||||
const handleRecalcReport = () => {};
|
||||
|
||||
// Can't display any error if the report is loading.
|
||||
// if (isLoading) return null;
|
||||
|
||||
return (
|
||||
<If condition={false}>
|
||||
<FinancialComputeAlert>
|
||||
<Icon icon="info-block" iconSize={12} />
|
||||
<T id={'just_a_moment_we_re_calculating_your_cost_transactions'} />
|
||||
</FinancialComputeAlert>
|
||||
</If>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Project profitability summary loading bar.
|
||||
*/
|
||||
export function ProjectProfitabilitySummaryLoadingBar() {
|
||||
return (
|
||||
<If condition={false}>
|
||||
<FinancialLoadingBar />
|
||||
</If>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Project profitability summary columns.
|
||||
*/
|
||||
export function useProjectProfitabilitySummaryColumns() {
|
||||
// Balance sheet context.
|
||||
const {
|
||||
projectProfitabilitySummary: { columns, tableRows },
|
||||
} = useProjectProfitabilitySummaryContext();
|
||||
|
||||
return useMemo(
|
||||
() => dynamicColumns(columns, tableRows),
|
||||
[tableRows, columns],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// @ts-nocheck
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
export const filterProjectProfitabilityOptions = [
|
||||
{
|
||||
key: 'all-projects',
|
||||
name: intl.get(
|
||||
'project_profitability_summary.filter_projects.all_projects',
|
||||
),
|
||||
hint: intl.get(
|
||||
'project_profitability_summary.filter_projects.all_projects.hint',
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'without-zero-balance',
|
||||
name: intl.get(
|
||||
'project_profitability_summary.filter_projects.without_zero_balance',
|
||||
),
|
||||
hint: intl.get(
|
||||
'project_profitability_summary.filter_projects.without_zero_balance.hint',
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'with-transactions',
|
||||
name: intl.get(
|
||||
'project_profitability_summary.filter_projects.with_transactions',
|
||||
),
|
||||
hint: intl.get(
|
||||
'project_profitability_summary.filter_projects.with_transactions.hint',
|
||||
),
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,70 @@
|
||||
// @ts-nocheck
|
||||
import * as R from 'ramda';
|
||||
|
||||
import { getColumnWidth } from '@/utils';
|
||||
import { Align } from '@/constants';
|
||||
|
||||
const characterColumn = R.curry((data, index, column) => ({
|
||||
id: column.key,
|
||||
key: column.key,
|
||||
Header: column.label,
|
||||
accessor: `cells[${index}].value`,
|
||||
className: column.key,
|
||||
width: getColumnWidth(data, `cells.${index}.key`, {
|
||||
minWidth: 200,
|
||||
magicSpacing: 10,
|
||||
}),
|
||||
disableSortBy: true,
|
||||
textOverview: true,
|
||||
sticky: Align.Left,
|
||||
}));
|
||||
|
||||
const numericColumn = R.curry((data, index, column) => ({
|
||||
id: column.key,
|
||||
key: column.key,
|
||||
Header: column.label,
|
||||
accessor: `cells[${index}].value`,
|
||||
className: column.key,
|
||||
width: getColumnWidth(data, `cells.${index}.key`, {
|
||||
minWidth: 130,
|
||||
magicSpacing: 10,
|
||||
}),
|
||||
disableSortBy: true,
|
||||
align: Align.Right,
|
||||
}));
|
||||
|
||||
/**
|
||||
* columns mapper.
|
||||
*/
|
||||
const columnsMapper = R.curry((data, index, column) => ({
|
||||
id: column.key,
|
||||
key: column.key,
|
||||
Header: column.label,
|
||||
accessor: `cells[${index}].value`,
|
||||
className: column.key,
|
||||
width: getColumnWidth(data, `cells.${index}.key`, {
|
||||
minWidth: 130,
|
||||
magicSpacing: 10,
|
||||
}),
|
||||
disableSortBy: true,
|
||||
textOverview: true,
|
||||
}));
|
||||
|
||||
/**
|
||||
* project profitability summary columns mapper.
|
||||
*/
|
||||
export const dynamicColumns = (columns, data) => {
|
||||
const mapper = (column, index) => {
|
||||
return R.compose(
|
||||
R.cond([
|
||||
[R.pathEq(['key'], 'name'), characterColumn(data, index)],
|
||||
[R.pathEq(['key'], 'customer_name'), characterColumn(data, index)],
|
||||
[R.pathEq(['key'], 'income'), numericColumn(data, index)],
|
||||
[R.pathEq(['key'], 'expenses'), numericColumn(data, index)],
|
||||
[R.pathEq(['key'], 'profit'), numericColumn(data, index)],
|
||||
[R.T, columnsMapper(data, index)],
|
||||
]),
|
||||
)(column);
|
||||
};
|
||||
return columns.map(mapper);
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
// @ts-nocheck
|
||||
import { useRequestQuery } from '@/hooks/useQueryRequest';
|
||||
import t from '@/hooks/query/types';
|
||||
|
||||
/**
|
||||
* Retrieve the profitability summary for the project
|
||||
*/
|
||||
export function useProjectProfitabilitySummary(query, props) {
|
||||
return useRequestQuery(
|
||||
[t.FINANCIAL_REPORT, t.PROJECT_PROFITABILITY_SUMMARY, query],
|
||||
{
|
||||
method: 'get',
|
||||
url: '/financial_statements/project-profitability-summary',
|
||||
params: query,
|
||||
headers: {
|
||||
Accept: 'application/json+table',
|
||||
},
|
||||
},
|
||||
{
|
||||
select: (res) => ({
|
||||
columns: res.data.table.columns,
|
||||
tableRows: res.data.table.data,
|
||||
}),
|
||||
defaultData: {
|
||||
tableRows: [],
|
||||
columns: [],
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// @ts-nocheck
|
||||
import React, { useMemo } from 'react';
|
||||
import moment from 'moment';
|
||||
import { castArray } from 'lodash';
|
||||
|
||||
import intl from 'react-intl-universal';
|
||||
import * as R from 'ramda';
|
||||
import * as Yup from 'yup';
|
||||
|
||||
import { transformToForm } from '@/utils';
|
||||
import { useAppQueryString } from '@/hooks';
|
||||
|
||||
/**
|
||||
* Retrieves the project profitability validation schema.
|
||||
*/
|
||||
export const getProjectProfitabilitySummaryValidationSchema = () =>
|
||||
Yup.object().shape({
|
||||
dateRange: Yup.string().optional(),
|
||||
fromDate: Yup.date().required().label(intl.get('fromDate')),
|
||||
toDate: Yup.date()
|
||||
.min(Yup.ref('fromDate'))
|
||||
.required()
|
||||
.label(intl.get('toDate')),
|
||||
filterByOption: Yup.string(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Retrieves the project profitability summary default values.
|
||||
*/
|
||||
export const getDefaultProjectProfitabilitySummaryQuery = () => ({
|
||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||
basis: 'cash',
|
||||
filterByOption: 'without-zero-balance',
|
||||
projectsIds: [],
|
||||
});
|
||||
|
||||
/**
|
||||
* Parses project profitability summary query.
|
||||
*/
|
||||
const parseProjectProfitabilityQuery = (locationQuery) => {
|
||||
const defaultQuery = getDefaultProjectProfitabilitySummaryQuery();
|
||||
|
||||
const transformed = {
|
||||
...defaultQuery,
|
||||
...transformToForm(locationQuery, defaultQuery),
|
||||
};
|
||||
return {
|
||||
...transformed,
|
||||
projectsIds: castArray(transformed.projectsIds),
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the project profitability summary query.
|
||||
*/
|
||||
export const useProjectProfitabilitySummaryQuery = () => {
|
||||
// Retrieves location query.
|
||||
const [locationQuery, setLocationQuery] = useAppQueryString();
|
||||
|
||||
// Merges the default filter query with location URL query.
|
||||
const query = useMemo(
|
||||
() => parseProjectProfitabilityQuery(locationQuery),
|
||||
[locationQuery],
|
||||
);
|
||||
return {
|
||||
query,
|
||||
locationQuery,
|
||||
setLocationQuery,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import { connect } from 'react-redux';
|
||||
import { getProjectProfitabilitySummaryFilterDrawer } from '@/store/financialStatement/financialStatements.selectors';
|
||||
|
||||
export default (mapState) => {
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
projectProfitabilitySummaryDrawerFilter:
|
||||
getProjectProfitabilitySummaryFilterDrawer(state),
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
|
||||
return connect(mapStateToProps);
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
// @ts-nocheck
|
||||
import { connect } from 'react-redux';
|
||||
import { toggleProjectProfitabilitySummaryFilterDrawer } from '@/store/financialStatement/financialStatements.actions';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
toggleProjectProfitabilitySummaryFilterDrawer: (toggle) =>
|
||||
dispatch(toggleProjectProfitabilitySummaryFilterDrawer(toggle)),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
Reference in New Issue
Block a user