mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
refactoring: vendors transactions.
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import moment from 'moment';
|
||||
import 'style/pages/FinancialStatements/ContactsTransactions.scss';
|
||||
|
||||
import { FinancialStatement } from 'components';
|
||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||
|
||||
import VendorsTransactionsHeader from './VendorsTransactionsHeader';
|
||||
import VendorsTransactionsActionsBar from './VendorsTransactionsActionsBar';
|
||||
import VendorsTransactionsTable from './VendorsTransactionsTable';
|
||||
|
||||
import withVendorsTransactionsActions from './withVendorsTransactionsActions';
|
||||
import withSettings from 'containers/Settings/withSettings';
|
||||
|
||||
import { VendorsTransactionsProvider } from './VendorsTransactionsProvider';
|
||||
import { VendorsTransactionsLoadingBar } from './components';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Vendors transactions.
|
||||
*/
|
||||
function VendorsTransactions({
|
||||
// #withPreferences
|
||||
organizationName,
|
||||
|
||||
//#withVendorsTransactionsActions
|
||||
toggleVendorsTransactionsFilterDrawer,
|
||||
}) {
|
||||
// filter
|
||||
const [filter, setFilter] = useState({
|
||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||
});
|
||||
|
||||
const handleFilterSubmit = (filter) => {
|
||||
const _filter = {
|
||||
...filter,
|
||||
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
||||
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
||||
};
|
||||
setFilter({ ..._filter });
|
||||
};
|
||||
|
||||
// Handle number format submit.
|
||||
const handleNumberFormatSubmit = (values) => {
|
||||
setFilter({
|
||||
...filter,
|
||||
numberFormat: values,
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
toggleVendorsTransactionsFilterDrawer(false);
|
||||
},
|
||||
[toggleVendorsTransactionsFilterDrawer],
|
||||
);
|
||||
|
||||
return (
|
||||
<VendorsTransactionsProvider filter={filter}>
|
||||
<VendorsTransactionsActionsBar
|
||||
numberFormat={filter.numberFormat}
|
||||
onNumberFormatSubmit={handleNumberFormatSubmit}
|
||||
/>
|
||||
<VendorsTransactionsLoadingBar />
|
||||
<DashboardPageContent>
|
||||
<FinancialStatement>
|
||||
<div className={'financial-statement--transactions'}>
|
||||
<VendorsTransactionsHeader
|
||||
pageFilter={filter}
|
||||
onSubmitFilter={handleFilterSubmit}
|
||||
/>
|
||||
<div class="financial-statement__body">
|
||||
<VendorsTransactionsTable companyName={organizationName} />
|
||||
</div>
|
||||
</div>
|
||||
</FinancialStatement>
|
||||
</DashboardPageContent>
|
||||
</VendorsTransactionsProvider>
|
||||
);
|
||||
}
|
||||
export default compose(
|
||||
withSettings(({ organizationSettings }) => ({
|
||||
organizationName: organizationSettings.name,
|
||||
})),
|
||||
withVendorsTransactionsActions,
|
||||
)(VendorsTransactions);
|
||||
@@ -0,0 +1,134 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
NavbarGroup,
|
||||
Button,
|
||||
Classes,
|
||||
NavbarDivider,
|
||||
Popover,
|
||||
PopoverInteractionKind,
|
||||
Position,
|
||||
} from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from 'react-intl';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import Icon from 'components/Icon';
|
||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||
import NumberFormatDropdown from 'components/NumberFormatDropdown';
|
||||
|
||||
import { useVendorsTranscationsContext } from './VendorsTransactionsProvider';
|
||||
import withVendorsTransaction from './withVendorsTransaction';
|
||||
import withVendorsTransactionsActions from './withVendorsTransactionsActions';
|
||||
|
||||
import { compose, saveInvoke } from 'utils';
|
||||
|
||||
/**
|
||||
* vendors transcations actions bar.
|
||||
*/
|
||||
function VendorsTransactionsActionsBar({
|
||||
// #ownProps
|
||||
numberFormat,
|
||||
onNumberFormatSubmit,
|
||||
|
||||
//#withVendorsTransaction
|
||||
isFilterDrawerOpen,
|
||||
|
||||
//#withVendorsTransactionsActions
|
||||
toggleVendorsTransactionsFilterDrawer,
|
||||
}) {
|
||||
const {
|
||||
isVendorsTransactionsLoading,
|
||||
refetch,
|
||||
} = useVendorsTranscationsContext();
|
||||
|
||||
// Handle filter toggle click.
|
||||
const handleFilterToggleClick = () => {
|
||||
toggleVendorsTransactionsFilterDrawer();
|
||||
};
|
||||
|
||||
// Handle recalculate the report button.
|
||||
const handleRecalcReport = () => {
|
||||
refetch();
|
||||
};
|
||||
|
||||
// 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={isVendorsTransactionsLoading}
|
||||
/>
|
||||
}
|
||||
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(
|
||||
withVendorsTransaction(({ vendorsTransactionsDrawerFilter }) => ({
|
||||
isFilterDrawerOpen: vendorsTransactionsDrawerFilter,
|
||||
})),
|
||||
withVendorsTransactionsActions,
|
||||
)(VendorsTransactionsActionsBar);
|
||||
@@ -0,0 +1,100 @@
|
||||
import React from 'react';
|
||||
import * as Yup from 'yup';
|
||||
import moment from 'moment';
|
||||
import { Formik, Form } from 'formik';
|
||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
|
||||
import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader';
|
||||
import VendorsTransactionsHeaderGeneralPanel from './VendorsTransactionsHeaderGeneralPanel';
|
||||
|
||||
import withVendorsTransaction from './withVendorsTransaction';
|
||||
import withVendorsTransactionsActions from './withVendorsTransactionsActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Vendors transactions header.
|
||||
*/
|
||||
|
||||
function VendorsTransactionsHeader({
|
||||
// #ownProps
|
||||
onSubmitFilter,
|
||||
pageFilter,
|
||||
|
||||
//#withVendorsTransaction
|
||||
isFilterDrawerOpen,
|
||||
|
||||
//#withVendorsTransactionsActions
|
||||
toggleVendorsTransactionsFilterDrawer: toggleFilterDrawer,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
// Filter form initial values.
|
||||
const initialValues = {
|
||||
...pageFilter,
|
||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||
toDate: moment(pageFilter.toDate).toDate(),
|
||||
};
|
||||
|
||||
// Validation schema.
|
||||
const validationSchema = Yup.object().shape({
|
||||
fromDate: Yup.date()
|
||||
.required()
|
||||
.label(formatMessage({ id: 'fromDate' })),
|
||||
toDate: Yup.date()
|
||||
.min(Yup.ref('fromDate'))
|
||||
.required()
|
||||
.label(formatMessage({ id: 'toDate' })),
|
||||
});
|
||||
|
||||
// Handle form submit.
|
||||
const handleSubmit = (values, { setSubmitting }) => {
|
||||
onSubmitFilter(values);
|
||||
toggleFilterDrawer(false);
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
// Handle drawer close action.
|
||||
const handleDrawerClose = () => {
|
||||
toggleFilterDrawer(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={<VendorsTransactionsHeaderGeneralPanel />}
|
||||
/>
|
||||
</Tabs>
|
||||
|
||||
<div class="financial-header-drawer__footer">
|
||||
<Button className={'mr1'} intent={Intent.PRIMARY} type={'submit'}>
|
||||
<T id={'calculate_report'} />
|
||||
</Button>
|
||||
<Button onClick={handleDrawerClose} minimal={true}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Formik>
|
||||
</FinancialStatementHeader>
|
||||
);
|
||||
}
|
||||
export default compose(
|
||||
withVendorsTransactionsActions,
|
||||
withVendorsTransaction(({ vendorsTransactionsDrawerFilter }) => ({
|
||||
isFilterDrawerOpen: vendorsTransactionsDrawerFilter,
|
||||
})),
|
||||
)(VendorsTransactionsHeader);
|
||||
@@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import FinancialStatementDateRange from 'containers/FinancialStatements/FinancialStatementDateRange';
|
||||
|
||||
/**
|
||||
* Vendors transactions header - General panel.
|
||||
*/
|
||||
export default function VendorsTransactionsHeaderGeneralPanel() {
|
||||
return (
|
||||
<div>
|
||||
<FinancialStatementDateRange />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import React, { createContext, useContext, useMemo } from 'react';
|
||||
import FinancialReportPage from '../FinancialReportPage';
|
||||
import { useVendorsTranscationsReport } from 'hooks/query';
|
||||
|
||||
|
||||
const VendorsTransactionsContext = createContext();
|
||||
|
||||
/**
|
||||
* Vendors transcations provider.
|
||||
*/
|
||||
function VendorsTransactionsProvider({ filter, ...props }) {
|
||||
const {
|
||||
data: vendorsTransactions,
|
||||
isFetching: isVendorsTransactionFetching,
|
||||
isLoading: isVendorsTransactionsLoading,
|
||||
refetch,
|
||||
} = useVendorsTranscationsReport();
|
||||
|
||||
const provider = {
|
||||
vendorsTransactions,
|
||||
isVendorsTransactionsLoading,
|
||||
isVendorsTransactionFetching,
|
||||
refetch,
|
||||
filter,
|
||||
};
|
||||
|
||||
return (
|
||||
<FinancialReportPage name={'vendor-transactions'}>
|
||||
<VendorsTransactionsContext.Provider value={provider} {...props} />
|
||||
</FinancialReportPage>
|
||||
);
|
||||
}
|
||||
|
||||
const useVendorsTranscationsContext = () =>
|
||||
useContext(VendorsTransactionsContext);
|
||||
|
||||
export { VendorsTransactionsProvider, useVendorsTranscationsContext };
|
||||
@@ -0,0 +1,60 @@
|
||||
import React, { useMemo, useCallback } from 'react';
|
||||
import { useIntl } from 'react-intl';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import FinancialSheet from 'components/FinancialSheet';
|
||||
import DataTable from 'components/DataTable';
|
||||
import { useVendorsTransactionsColumns } from './components';
|
||||
import { useVendorsTranscationsContext } from './VendorsTransactionsProvider';
|
||||
|
||||
import { defaultExpanderReducer, getColumnWidth } from 'utils';
|
||||
|
||||
/**
|
||||
* Vendors transcations table.
|
||||
*/
|
||||
|
||||
export default function VendorsTransactionsTable({
|
||||
// #ownProps
|
||||
companyName,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const {
|
||||
vendorsTransactions: { tableRows },
|
||||
isVendorsTransactionsLoading,
|
||||
filter,
|
||||
} = useVendorsTranscationsContext();
|
||||
|
||||
const columns = useVendorsTransactionsColumns();
|
||||
|
||||
const expandedRows = useMemo(() => defaultExpanderReducer(tableRows, 5), [
|
||||
tableRows,
|
||||
]);
|
||||
|
||||
const rowClassNames = (row) => {
|
||||
return [`row-type--${row.original.rowTypes}`];
|
||||
};
|
||||
|
||||
return (
|
||||
<FinancialSheet
|
||||
name="vendor-transactions"
|
||||
companyName={companyName}
|
||||
sheetType={formatMessage({ id: 'vendors_transactions' })}
|
||||
loading={isVendorsTransactionsLoading}
|
||||
fromDate={filter.fromDate}
|
||||
toDate={filter.toDate}
|
||||
>
|
||||
<DataTable
|
||||
className="bigcapital-datatable--financial-report"
|
||||
columns={columns}
|
||||
data={tableRows}
|
||||
rowClassNames={rowClassNames}
|
||||
noInitialFetch={true}
|
||||
expandable={true}
|
||||
expanded={expandedRows}
|
||||
expandToggleColumn={1}
|
||||
expandColumnSpace={0.8}
|
||||
/>
|
||||
</FinancialSheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import React from 'react';
|
||||
import { formatMessage } from 'services/intl';
|
||||
import { If } from 'components';
|
||||
import { useVendorsTranscationsContext } from './VendorsTransactionsProvider';
|
||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||
import { defaultExpanderReducer, getColumnWidth, getForceWidth } from 'utils';
|
||||
import { CellTextSpan } from 'components/Datatable/Cells';
|
||||
|
||||
/**
|
||||
* Retrieve vendors transcations columns.
|
||||
*/
|
||||
export const useVendorsTransactionsColumns = () => {
|
||||
const {
|
||||
vendorsTransactions: { tableRows },
|
||||
} = useVendorsTranscationsContext();
|
||||
|
||||
return React.useMemo(
|
||||
() => [
|
||||
{
|
||||
Header: formatMessage({ id: 'vendor_name' }),
|
||||
accessor: ({ cells }) => {
|
||||
return (
|
||||
<span
|
||||
className={'force-width'}
|
||||
style={{ minWidth: getForceWidth(cells[0].key) }}
|
||||
>
|
||||
{cells[0].value}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
className: 'vendor_name',
|
||||
textOverview: true,
|
||||
// width: 240,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'account_name' }),
|
||||
accessor: 'cells[1].value',
|
||||
className: 'name',
|
||||
textOverview: true,
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'reference_type' }),
|
||||
accessor: 'cells[2].value',
|
||||
textOverview: true,
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'transaction_type' }),
|
||||
accessor: 'cells[3].value',
|
||||
textOverview: true,
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'credit' }),
|
||||
accessor: 'cells[4].value',
|
||||
className: 'credit',
|
||||
textOverview: true,
|
||||
width: getColumnWidth(tableRows, 'credit', {
|
||||
minWidth: 140,
|
||||
magicSpacing: 10,
|
||||
}),
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'debit' }),
|
||||
accessor: 'cells[5].value',
|
||||
className: 'debit',
|
||||
textOverview: true,
|
||||
width: getColumnWidth(tableRows, 'debit', {
|
||||
minWidth: 140,
|
||||
magicSpacing: 10,
|
||||
}),
|
||||
},
|
||||
{
|
||||
Header: formatMessage({ id: 'running_balance' }),
|
||||
accessor: 'cells[6].value',
|
||||
className: 'running_balance',
|
||||
textOverview: true,
|
||||
width: getColumnWidth(tableRows, 'running_balance', {
|
||||
minWidth: 140,
|
||||
magicSpacing: 10,
|
||||
}),
|
||||
},
|
||||
],
|
||||
[tableRows, formatMessage],
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* vendors transcations loading bar.
|
||||
*/
|
||||
export function VendorsTransactionsLoadingBar() {
|
||||
const { isVendorsTransactionsLoading } = useVendorsTranscationsContext();
|
||||
return (
|
||||
<If condition={isVendorsTransactionsLoading}>
|
||||
<FinancialLoadingBar />
|
||||
</If>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { getVendorsTransactionsFilterDrawer } from 'store/financialStatement/financialStatements.selectors';
|
||||
|
||||
export default (mapState) => {
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
vendorsTransactionsDrawerFilter: getVendorsTransactionsFilterDrawer(
|
||||
state,
|
||||
props,
|
||||
),
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
return connect(mapStateToProps);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { toggleVendorsTransactionsFilterDrawer } from 'store/financialStatement/financialStatements.actions';
|
||||
|
||||
const mapActionsToProps = (dispatch) => ({
|
||||
toggleVendorsTransactionsFilterDrawer: (toggle) =>
|
||||
dispatch(toggleVendorsTransactionsFilterDrawer(toggle)),
|
||||
});
|
||||
|
||||
export default connect(null, mapActionsToProps);
|
||||
@@ -0,0 +1,75 @@
|
||||
.financial-sheet {
|
||||
&--customer-transactions,
|
||||
&--vendor-transactions {
|
||||
.financial-sheet__table {
|
||||
.tbody,
|
||||
.thead {
|
||||
.tr .td,
|
||||
.tr .th {
|
||||
&.credit,
|
||||
&.debit,
|
||||
&.running_balance {
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
}
|
||||
.tbody {
|
||||
.tr .td {
|
||||
padding-top: 0.2rem;
|
||||
padding-bottom: 0.2rem;
|
||||
border-top-color: transparent;
|
||||
border-bottom-color: transparent;
|
||||
|
||||
&.customer_name,
|
||||
&.vendor_name {
|
||||
> div {
|
||||
display: flex;
|
||||
}
|
||||
span.force-width {
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
}
|
||||
.tr:not(.no-results) .td {
|
||||
// border-left: 1px solid #ececec;
|
||||
}
|
||||
|
||||
.tr.row-type {
|
||||
&--CUSTOMER,
|
||||
&--VENDOR {
|
||||
.td {
|
||||
&.customer_name,
|
||||
&.vendor_name {
|
||||
font-weight: 500;
|
||||
}
|
||||
&.name {
|
||||
border-left-color: transparent;
|
||||
}
|
||||
}
|
||||
&:not(:first-child).is-expanded .td {
|
||||
border-top: 1px solid #ddd;
|
||||
}
|
||||
}
|
||||
&--OPENING_BALANCE,
|
||||
// &--TRANSACTION,
|
||||
&--CLOSING_BALANCE {
|
||||
font-weight: 500;
|
||||
}
|
||||
&--CUSTOMER:last-child {
|
||||
.td {
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.financial-statement--transactions {
|
||||
.financial-header-drawer {
|
||||
.bp3-drawer {
|
||||
max-height: 350px;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user