mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
refactor(PurchaseByItem)
This commit is contained in:
@@ -3,31 +3,30 @@ import moment from 'moment';
|
|||||||
|
|
||||||
import 'style/pages/FinancialStatements/SalesAndPurchasesSheet.scss';
|
import 'style/pages/FinancialStatements/SalesAndPurchasesSheet.scss';
|
||||||
|
|
||||||
|
import { FinancialStatement } from 'components';
|
||||||
|
|
||||||
import { PurchasesByItemsProvider } from './PurchasesByItemsProvider';
|
import { PurchasesByItemsProvider } from './PurchasesByItemsProvider';
|
||||||
import PurchasesByItemsActionsBar from './PurchasesByItemsActionsBar';
|
import PurchasesByItemsActionsBar from './PurchasesByItemsActionsBar';
|
||||||
import PurchasesByItemsHeader from './PurchasesByItemsHeader';
|
import PurchasesByItemsHeader from './PurchasesByItemsHeader';
|
||||||
import PurchasesByItemsTable from './PurchasesByItemsTable';
|
|
||||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||||
import { PurchasesByItemsLoadingBar } from './components';
|
import { PurchasesByItemsLoadingBar } from './components';
|
||||||
|
import { PurchasesByItemsBody } from './PurchasesByItemsBody';
|
||||||
|
|
||||||
import withPurchasesByItemsActions from './withPurchasesByItemsActions';
|
import withPurchasesByItemsActions from './withPurchasesByItemsActions';
|
||||||
import withCurrentOrganization from '../../../containers/Organization/withCurrentOrganization';
|
|
||||||
|
import { getDefaultPurchasesByItemsQuery } from './utils';
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purchases by items.
|
* Purchases by items.
|
||||||
*/
|
*/
|
||||||
function PurchasesByItems({
|
function PurchasesByItems({
|
||||||
// #withPreferences
|
|
||||||
organizationName,
|
|
||||||
|
|
||||||
// #withPurchasesByItemsActions
|
// #withPurchasesByItemsActions
|
||||||
togglePurchasesByItemsFilterDrawer,
|
togglePurchasesByItemsFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
const [filter, setFilter] = useState({
|
||||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
...getDefaultPurchasesByItemsQuery(),
|
||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
|
||||||
filterByOption: 'with-transactions',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle filter form submit.
|
// Handle filter form submit.
|
||||||
@@ -68,23 +67,16 @@ function PurchasesByItems({
|
|||||||
<PurchasesByItemsLoadingBar />
|
<PurchasesByItemsLoadingBar />
|
||||||
|
|
||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<div className="financial-statement financial-statement--purchases-by-items">
|
<FinancialStatement>
|
||||||
<PurchasesByItemsHeader
|
<PurchasesByItemsHeader
|
||||||
pageFilter={filter}
|
pageFilter={filter}
|
||||||
onSubmitFilter={handleFilterSubmit}
|
onSubmitFilter={handleFilterSubmit}
|
||||||
/>
|
/>
|
||||||
</div>
|
<PurchasesByItemsBody />
|
||||||
<div className="financial-statement__body">
|
</FinancialStatement>
|
||||||
<PurchasesByItemsTable companyName={organizationName} />
|
|
||||||
</div>
|
|
||||||
</DashboardPageContent>
|
</DashboardPageContent>
|
||||||
</PurchasesByItemsProvider>
|
</PurchasesByItemsProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
export default compose(withPurchasesByItemsActions)(PurchasesByItems);
|
||||||
withPurchasesByItemsActions,
|
|
||||||
withCurrentOrganization(({ organization }) => ({
|
|
||||||
organizationName: organization.name,
|
|
||||||
})),
|
|
||||||
)(PurchasesByItems);
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import * as R from 'ramda';
|
||||||
|
|
||||||
|
import { FinancialReportBody } from '../FinancialReportPage';
|
||||||
|
import { FinancialSheetSkeleton } from '../../../components/FinancialSheet';
|
||||||
|
import PurchasesByItemsTable from './PurchasesByItemsTable';
|
||||||
|
|
||||||
|
import { usePurchaseByItemsContext } from './PurchasesByItemsProvider';
|
||||||
|
|
||||||
|
import withCurrentOrganization from '../../../containers/Organization/withCurrentOrganization';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchases by items.
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
function PurchasesByItemsBodyJSX({
|
||||||
|
// #withPreferences
|
||||||
|
organizationName,
|
||||||
|
}) {
|
||||||
|
const { isLoading } = usePurchaseByItemsContext();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FinancialReportBody>
|
||||||
|
{isLoading ? (
|
||||||
|
<FinancialSheetSkeleton />
|
||||||
|
) : (
|
||||||
|
<PurchasesByItemsTable companyName={organizationName} />
|
||||||
|
)}
|
||||||
|
</FinancialReportBody>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PurchasesByItemsBody = R.compose(
|
||||||
|
withCurrentOrganization(({ organization }) => ({
|
||||||
|
organizationName: organization.name,
|
||||||
|
})),
|
||||||
|
)(PurchasesByItemsBodyJSX);
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
import { DataTable, FinancialSheet } from 'components';
|
import { DataTable, FinancialSheet } from 'components';
|
||||||
|
|
||||||
import { usePurchaseByItemsContext } from './PurchasesByItemsProvider';
|
import { usePurchaseByItemsContext } from './PurchasesByItemsProvider';
|
||||||
import { usePurchasesByItemsTableColumns } from './components';
|
import { usePurchasesByItemsTableColumns } from './components';
|
||||||
|
|
||||||
|
import { tableRowTypesToClassnames } from 'utils';
|
||||||
|
import { TableStyle } from 'common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* purchases by items data table.
|
* Purchases by items data table.
|
||||||
*/
|
*/
|
||||||
export default function PurchasesByItemsTable({ companyName }) {
|
export default function PurchasesByItemsTable({ companyName }) {
|
||||||
// Purchases by items context.
|
// Purchases by items context.
|
||||||
@@ -19,20 +23,6 @@ export default function PurchasesByItemsTable({ companyName }) {
|
|||||||
// Purchases by items table columns.
|
// Purchases by items table columns.
|
||||||
const columns = usePurchasesByItemsTableColumns();
|
const columns = usePurchasesByItemsTableColumns();
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
<FinancialSheet
|
<FinancialSheet
|
||||||
companyName={companyName}
|
companyName={companyName}
|
||||||
@@ -42,19 +32,36 @@ export default function PurchasesByItemsTable({ companyName }) {
|
|||||||
name="purchases-by-items"
|
name="purchases-by-items"
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
<DataTable
|
<PurchasesByItemsDataTable
|
||||||
className="bigcapital-datatable--financial-report"
|
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={tableRows}
|
data={tableRows}
|
||||||
expandable={true}
|
expandable={true}
|
||||||
expandToggleColumn={1}
|
expandToggleColumn={1}
|
||||||
expandColumnSpace={1}
|
expandColumnSpace={1}
|
||||||
sticky={true}
|
sticky={true}
|
||||||
rowClassNames={rowClassNames}
|
rowClassNames={tableRowTypesToClassnames}
|
||||||
noResults={intl.get(
|
noResults={intl.get(
|
||||||
'there_were_no_purchases_during_the_selected_date_range',
|
'there_were_no_purchases_during_the_selected_date_range',
|
||||||
)}
|
)}
|
||||||
|
styleName={TableStyle.Constrant}
|
||||||
/>
|
/>
|
||||||
</FinancialSheet>
|
</FinancialSheet>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PurchasesByItemsDataTable = styled(DataTable)`
|
||||||
|
.table {
|
||||||
|
.tbody {
|
||||||
|
.tr .td {
|
||||||
|
border-bottom: 0;
|
||||||
|
padding-top: 0.4rem;
|
||||||
|
padding-bottom: 0.4rem;
|
||||||
|
}
|
||||||
|
.tr.row_type--total .td {
|
||||||
|
border-top: 1px solid #bbb;
|
||||||
|
font-weight: 500;
|
||||||
|
border-bottom: 3px double #000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Button } from '@blueprintjs/core';
|
|
||||||
import { getColumnWidth } from 'utils';
|
import { If } from 'components';
|
||||||
import { If, Icon } from 'components';
|
|
||||||
import { CellTextSpan } from 'components/Datatable/Cells';
|
import { CellTextSpan } from 'components/Datatable/Cells';
|
||||||
import { usePurchaseByItemsContext } from './PurchasesByItemsProvider';
|
import { usePurchaseByItemsContext } from './PurchasesByItemsProvider';
|
||||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||||
|
|
||||||
|
import { getColumnWidth } from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve purchases by items table columns.
|
* Retrieve purchases by items table columns.
|
||||||
*/
|
*/
|
||||||
export const usePurchasesByItemsTableColumns = () => {
|
export const usePurchasesByItemsTableColumns = () => {
|
||||||
|
|
||||||
|
|
||||||
// purchases by items context.
|
// purchases by items context.
|
||||||
const {
|
const {
|
||||||
purchaseByItems: { tableRows },
|
purchaseByItems: { tableRows },
|
||||||
|
|||||||
10
src/containers/FinancialStatements/PurchasesByItems/utils.js
Normal file
10
src/containers/FinancialStatements/PurchasesByItems/utils.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
|
||||||
|
export const getDefaultPurchasesByItemsQuery = () => {
|
||||||
|
return {
|
||||||
|
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||||
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
|
filterByOption: 'with-transactions',
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
import 'style/pages/FinancialStatements/TrialBalanceSheet.scss';
|
|
||||||
|
|
||||||
import { FinancialStatement } from 'components';
|
import { FinancialStatement } from 'components';
|
||||||
import { TrialBalanceSheetProvider } from './TrialBalanceProvider';
|
import { TrialBalanceSheetProvider } from './TrialBalanceProvider';
|
||||||
import TrialBalanceActionsBar from './TrialBalanceActionsBar';
|
import TrialBalanceActionsBar from './TrialBalanceActionsBar';
|
||||||
|
|||||||
Reference in New Issue
Block a user