mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 07:40:32 +00:00
Merge branch 'master' of https://github.com/abouolia/Bigcapital
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import React, { lazy } from 'react';
|
import React, { lazy } from 'react';
|
||||||
|
|
||||||
import AccountFormDialog from 'containers/Dialogs/AccountFormDialog';
|
import AccountFormDialog from 'containers/Dialogs/AccountFormDialog';
|
||||||
|
|
||||||
import InviteUserDialog from 'containers/Dialogs/InviteUserDialog';
|
import InviteUserDialog from 'containers/Dialogs/InviteUserDialog';
|
||||||
import ItemCategoryDialog from 'containers/Dialogs/ItemCategoryDialog';
|
import ItemCategoryDialog from 'containers/Dialogs/ItemCategoryDialog';
|
||||||
import CurrencyFormDialog from 'containers/Dialogs/CurrencyFormDialog';
|
import CurrencyFormDialog from 'containers/Dialogs/CurrencyFormDialog';
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import React, { useEffect, useState, useCallback } from 'react';
|
||||||
|
import { useIntl } from 'react-intl';
|
||||||
|
import { queryCache, useQuery } from 'react-query';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
import { FinancialStatement } from 'components';
|
||||||
|
|
||||||
|
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||||
|
import ARAgingSummaryActionsBar from './ARAgingSummaryActionsBar';
|
||||||
|
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||||
|
import ARAgingSummaryHeader from './ARAgingSummaryHeader';
|
||||||
|
import ReceivableAgingSummaryTable from './ARAgingSummaryTable';
|
||||||
|
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
|
import withARAgingSummaryActions from './withARAgingSummaryActions';
|
||||||
|
import withARAgingSummary from './withARAgingSummary';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
import { transfromFilterFormToQuery } from './common';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AR aging summary report.
|
||||||
|
*/
|
||||||
|
function ReceivableAgingSummarySheet({
|
||||||
|
// #withSettings
|
||||||
|
organizationName,
|
||||||
|
|
||||||
|
// #withDashboardActions
|
||||||
|
changePageTitle,
|
||||||
|
setDashboardBackLink,
|
||||||
|
|
||||||
|
// #withARAgingSummaryActions
|
||||||
|
requestReceivableAgingSummary,
|
||||||
|
refreshARAgingSummary,
|
||||||
|
toggleFilterARAgingSummary,
|
||||||
|
|
||||||
|
// #withARAgingSummary
|
||||||
|
ARAgingSummaryRefresh,
|
||||||
|
}) {
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
const [query, setQuery] = useState({
|
||||||
|
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
||||||
|
agingBeforeDays: 30,
|
||||||
|
agingPeriods: 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
changePageTitle(formatMessage({ id: 'receivable_aging_summary' }));
|
||||||
|
}, [changePageTitle, formatMessage]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (ARAgingSummaryRefresh) {
|
||||||
|
queryCache.invalidateQueries('receivable-aging-summary');
|
||||||
|
refreshARAgingSummary(false);
|
||||||
|
}
|
||||||
|
}, [ARAgingSummaryRefresh, refreshARAgingSummary]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Show the back link on dashboard topbar.
|
||||||
|
setDashboardBackLink(true);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
// Hide the back link on dashboard topbar.
|
||||||
|
setDashboardBackLink(false);
|
||||||
|
};
|
||||||
|
}, [setDashboardBackLink]);
|
||||||
|
|
||||||
|
// Handle fetching receivable aging summary report.
|
||||||
|
const fetchARAgingSummarySheet = useQuery(
|
||||||
|
['receivable-aging-summary', query],
|
||||||
|
(key, q) =>
|
||||||
|
requestReceivableAgingSummary({
|
||||||
|
...transfromFilterFormToQuery(q),
|
||||||
|
}),
|
||||||
|
{ manual: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
// Handle fetch the data of receivable aging summary sheet.
|
||||||
|
const handleFetchData = useCallback((...args) => {}, []);
|
||||||
|
|
||||||
|
const handleFilterSubmit = useCallback(
|
||||||
|
(filter) => {
|
||||||
|
const _filter = {
|
||||||
|
...filter,
|
||||||
|
asDate: moment(filter.asDate).format('YYYY-MM-DD'),
|
||||||
|
};
|
||||||
|
setQuery(_filter);
|
||||||
|
refreshARAgingSummary(true);
|
||||||
|
toggleFilterARAgingSummary(false);
|
||||||
|
},
|
||||||
|
[refreshARAgingSummary, toggleFilterARAgingSummary],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardInsider>
|
||||||
|
<ARAgingSummaryActionsBar />
|
||||||
|
|
||||||
|
<DashboardPageContent>
|
||||||
|
<FinancialStatement>
|
||||||
|
<ARAgingSummaryHeader
|
||||||
|
pageFilter={query}
|
||||||
|
onSubmitFilter={handleFilterSubmit}
|
||||||
|
/>
|
||||||
|
<div class="financial-statement__body">
|
||||||
|
<ReceivableAgingSummaryTable
|
||||||
|
organizationName={organizationName}
|
||||||
|
receivableAgingSummaryQuery={query}
|
||||||
|
onFetchData={handleFetchData}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</FinancialStatement>
|
||||||
|
</DashboardPageContent>
|
||||||
|
</DashboardInsider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withDashboardActions,
|
||||||
|
withARAgingSummaryActions,
|
||||||
|
withSettings(({ organizationSettings }) => ({
|
||||||
|
organizationName: organizationSettings.name,
|
||||||
|
})),
|
||||||
|
withARAgingSummary(({ ARAgingSummaryRefresh }) => ({
|
||||||
|
ARAgingSummaryRefresh: ARAgingSummaryRefresh,
|
||||||
|
})),
|
||||||
|
)(ReceivableAgingSummarySheet);
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import {
|
||||||
|
NavbarDivider,
|
||||||
|
NavbarGroup,
|
||||||
|
Classes,
|
||||||
|
Button,
|
||||||
|
Popover,
|
||||||
|
PopoverInteractionKind,
|
||||||
|
Position,
|
||||||
|
} from '@blueprintjs/core';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
|
import Icon from 'components/Icon';
|
||||||
|
|
||||||
|
import withARAgingSummary from './withARAgingSummary';
|
||||||
|
import withARAgingSummaryActions from './withARAgingSummaryActions';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AR Aging summary sheet - Actions bar.
|
||||||
|
*/
|
||||||
|
function ARAgingSummaryActionsBar({
|
||||||
|
// #withReceivableAging
|
||||||
|
receivableAgingFilter,
|
||||||
|
|
||||||
|
// #withReceivableAgingActions
|
||||||
|
toggleFilterARAgingSummary,
|
||||||
|
refreshARAgingSummary,
|
||||||
|
}) {
|
||||||
|
const handleFilterToggleClick = () => {
|
||||||
|
toggleFilterARAgingSummary();
|
||||||
|
};
|
||||||
|
// Handles re-calculate report button.
|
||||||
|
const handleRecalcReport = () => {
|
||||||
|
refreshARAgingSummary(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
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={
|
||||||
|
receivableAgingFilter ? (
|
||||||
|
<T id="hide_customizer" />
|
||||||
|
) : (
|
||||||
|
<T id={'customize_report'} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onClick={handleFilterToggleClick}
|
||||||
|
active={receivableAgingFilter}
|
||||||
|
/>
|
||||||
|
<NavbarDivider />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className={Classes.MINIMAL}
|
||||||
|
text={<T id={'filter'} />}
|
||||||
|
icon={<Icon icon="filter-16" iconSize={16} />}
|
||||||
|
/>
|
||||||
|
<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(
|
||||||
|
withARAgingSummaryActions,
|
||||||
|
withARAgingSummary(({ receivableAgingSummaryFilter }) => ({
|
||||||
|
receivableAgingFilter: receivableAgingSummaryFilter,
|
||||||
|
})),
|
||||||
|
)(ARAgingSummaryActionsBar);
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
import { Formik, Form } from 'formik';
|
||||||
|
import * as Yup from 'yup';
|
||||||
|
import moment from 'moment';
|
||||||
|
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader';
|
||||||
|
import ARAgingSummaryHeaderGeneral from './ARAgingSummaryHeaderGeneral';
|
||||||
|
|
||||||
|
import withARAgingSummary from './withARAgingSummary';
|
||||||
|
import withARAgingSummaryActions from './withARAgingSummaryActions';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AR Aging Summary Report - Drawer Header.
|
||||||
|
*/
|
||||||
|
function ARAgingSummaryHeader({
|
||||||
|
pageFilter,
|
||||||
|
onSubmitFilter,
|
||||||
|
receivableAgingFilter,
|
||||||
|
|
||||||
|
// #withReceivableAgingSummary
|
||||||
|
receivableAgingRefresh,
|
||||||
|
|
||||||
|
// #withReceivableAgingSummaryActions
|
||||||
|
refreshReceivableAgingSummary,
|
||||||
|
toggleFilterARAgingSummary,
|
||||||
|
}) {
|
||||||
|
const validationSchema = Yup.object().shape({
|
||||||
|
asDate: Yup.date().required().label('asDate'),
|
||||||
|
agingBeforeDays: Yup.number()
|
||||||
|
.required()
|
||||||
|
.integer()
|
||||||
|
.positive()
|
||||||
|
.label('agingBeforeDays'),
|
||||||
|
agingPeriods: Yup.number()
|
||||||
|
.required()
|
||||||
|
.integer()
|
||||||
|
.positive()
|
||||||
|
.label('agingPeriods'),
|
||||||
|
});
|
||||||
|
// Initial values.
|
||||||
|
const initialValues = {
|
||||||
|
asDate: moment(pageFilter.asDate).toDate(),
|
||||||
|
agingBeforeDays: 30,
|
||||||
|
agingPeriods: 3,
|
||||||
|
};
|
||||||
|
// Handle form submit.
|
||||||
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
|
onSubmitFilter(values);
|
||||||
|
setSubmitting(false);
|
||||||
|
};
|
||||||
|
// Handle cancel button click.
|
||||||
|
const handleCancelClick = () => {
|
||||||
|
toggleFilterARAgingSummary();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FinancialStatementHeader isOpen={receivableAgingFilter}>
|
||||||
|
<Formik
|
||||||
|
initialValues={initialValues}
|
||||||
|
validationSchema={validationSchema}
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
>
|
||||||
|
<Form>
|
||||||
|
<Tabs animate={true} vertical={true} renderActiveTabPanelOnly={true}>
|
||||||
|
<Tab
|
||||||
|
id="general"
|
||||||
|
title={<T id={'general'} />}
|
||||||
|
panel={<ARAgingSummaryHeaderGeneral />}
|
||||||
|
/>
|
||||||
|
</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(
|
||||||
|
withARAgingSummaryActions,
|
||||||
|
withARAgingSummary(
|
||||||
|
({ receivableAgingSummaryFilter, receivableAgingSummaryRefresh }) => ({
|
||||||
|
receivableAgingFilter: receivableAgingSummaryFilter,
|
||||||
|
receivableAgingRefresh: receivableAgingSummaryRefresh,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)(ARAgingSummaryHeader);
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { FastField } from 'formik';
|
||||||
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
|
import { Intent, FormGroup, InputGroup, Position } from '@blueprintjs/core';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
import { Row, Col, FieldHint } from 'components';
|
||||||
|
import { momentFormatter } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AR Aging Summary - Drawer Header - General Fields.
|
||||||
|
*/
|
||||||
|
export default function ARAgingSummaryHeaderGeneral({}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Row>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FastField name={'asDate'}>
|
||||||
|
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'as_date'} />}
|
||||||
|
labelInfo={<FieldHint />}
|
||||||
|
fill={true}
|
||||||
|
intent={error && Intent.DANGER}
|
||||||
|
>
|
||||||
|
<DateInput
|
||||||
|
{...momentFormatter('YYYY/MM/DD')}
|
||||||
|
value={value}
|
||||||
|
onChange={(selectedDate) => {
|
||||||
|
form.setFieldValue('asDate', selectedDate);
|
||||||
|
}}
|
||||||
|
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
||||||
|
minimal={true}
|
||||||
|
fill={true}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
)}
|
||||||
|
</FastField>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FastField name={'agingBeforeDays'}>
|
||||||
|
{({ field, meta: { error, touched } }) => (
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'aging_before_days'} />}
|
||||||
|
labelInfo={<FieldHint />}
|
||||||
|
className={'form-group--aging-before-days'}
|
||||||
|
intent={error && Intent.DANGER}
|
||||||
|
>
|
||||||
|
<InputGroup medium={true} intent={error && Intent.DANGER} {...field } />
|
||||||
|
</FormGroup>
|
||||||
|
)}
|
||||||
|
</FastField>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
|
||||||
|
<Row>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FastField name={'agingPeriods'}>
|
||||||
|
{({ field, meta: { error, touched } }) => (
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'aging_periods'} />}
|
||||||
|
labelInfo={<FieldHint />}
|
||||||
|
className={'form-group--aging-periods'}
|
||||||
|
intent={error && Intent.DANGER}
|
||||||
|
>
|
||||||
|
<InputGroup medium={true} intent={error && Intent.DANGER} {...field} />
|
||||||
|
</FormGroup>
|
||||||
|
)}
|
||||||
|
</FastField>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import React, { useMemo, useCallback } from 'react';
|
||||||
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
import DataTable from 'components/DataTable';
|
||||||
|
import FinancialSheet from 'components/FinancialSheet';
|
||||||
|
|
||||||
|
import withARAgingSummary from './withARAgingSummary';
|
||||||
|
|
||||||
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AR aging summary table sheet.
|
||||||
|
*/
|
||||||
|
function ReceivableAgingSummaryTable({
|
||||||
|
// #withReceivableAgingSummary
|
||||||
|
receivableAgingRows,
|
||||||
|
receivableAgingLoading,
|
||||||
|
receivableAgingColumns,
|
||||||
|
|
||||||
|
// #ownProps
|
||||||
|
onFetchData,
|
||||||
|
organizationName,
|
||||||
|
}) {
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
|
const agingColumns = useMemo(() => {
|
||||||
|
return receivableAgingColumns.map((agingColumn) => {
|
||||||
|
return `${agingColumn.before_days} - ${
|
||||||
|
agingColumn.to_days || 'And Over'
|
||||||
|
}`;
|
||||||
|
});
|
||||||
|
}, [receivableAgingColumns]);
|
||||||
|
|
||||||
|
const columns = useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
Header: <T id={'customer_name'} />,
|
||||||
|
accessor: 'name',
|
||||||
|
className: 'customer_name',
|
||||||
|
sticky: 'left',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: <T id={'current'} />,
|
||||||
|
accessor: 'current',
|
||||||
|
className: 'current',
|
||||||
|
width: 120,
|
||||||
|
},
|
||||||
|
...agingColumns.map((agingColumn, index) => ({
|
||||||
|
Header: agingColumn,
|
||||||
|
accessor: `aging-${index }`,
|
||||||
|
width: 120,
|
||||||
|
})),
|
||||||
|
{
|
||||||
|
Header: (<T id={'total'} />),
|
||||||
|
id: 'total',
|
||||||
|
accessor: 'total',
|
||||||
|
className: 'total',
|
||||||
|
width: 140,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[agingColumns],
|
||||||
|
);
|
||||||
|
|
||||||
|
const rowClassNames = (row) => [`row-type--${row.original.rowType}`];
|
||||||
|
|
||||||
|
const handleFetchData = useCallback((...args) => {
|
||||||
|
// onFetchData && onFetchData(...args);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FinancialSheet
|
||||||
|
companyName={organizationName}
|
||||||
|
name={'receivable-aging-summary'}
|
||||||
|
sheetType={formatMessage({ id: 'receivable_aging_summary' })}
|
||||||
|
asDate={new Date()}
|
||||||
|
loading={receivableAgingLoading}
|
||||||
|
>
|
||||||
|
<DataTable
|
||||||
|
className="bigcapital-datatable--financial-report"
|
||||||
|
columns={columns}
|
||||||
|
data={receivableAgingRows}
|
||||||
|
rowClassNames={rowClassNames}
|
||||||
|
onFetchData={handleFetchData}
|
||||||
|
noInitialFetch={true}
|
||||||
|
sticky={true}
|
||||||
|
/>
|
||||||
|
</FinancialSheet>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withARAgingSummary(
|
||||||
|
({
|
||||||
|
receivableAgingSummaryLoading,
|
||||||
|
receivableAgingSummaryColumns,
|
||||||
|
receivableAgingSummaryRows,
|
||||||
|
}) => ({
|
||||||
|
receivableAgingLoading: receivableAgingSummaryLoading,
|
||||||
|
receivableAgingColumns: receivableAgingSummaryColumns,
|
||||||
|
receivableAgingRows: receivableAgingSummaryRows,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)(ReceivableAgingSummaryTable);
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { mapKeys, snakeCase } from 'lodash';
|
||||||
|
|
||||||
|
export const transfromFilterFormToQuery = (form) => {
|
||||||
|
return mapKeys(form, (v, k) => snakeCase(k));
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import {
|
||||||
|
getFinancialSheetFactory,
|
||||||
|
getFinancialSheetAccountsFactory,
|
||||||
|
getFinancialSheetColumnsFactory,
|
||||||
|
getFinancialSheetQueryFactory,
|
||||||
|
getFinancialSheetTableRowsFactory,
|
||||||
|
} from 'store/financialStatement/financialStatements.selectors';
|
||||||
|
|
||||||
|
export default (mapState) => {
|
||||||
|
const mapStateToProps = (state, props) => {
|
||||||
|
const getARAgingSheet = getFinancialSheetFactory('receivableAgingSummary');
|
||||||
|
const getARAgingSheetColumns = getFinancialSheetColumnsFactory(
|
||||||
|
'receivableAgingSummary',
|
||||||
|
);
|
||||||
|
const getARAgingSheetRows = getFinancialSheetTableRowsFactory(
|
||||||
|
'receivableAgingSummary',
|
||||||
|
);
|
||||||
|
const {
|
||||||
|
loading,
|
||||||
|
filter,
|
||||||
|
refresh,
|
||||||
|
} = state.financialStatements.receivableAgingSummary;
|
||||||
|
|
||||||
|
const mapped = {
|
||||||
|
receivableAgingSummarySheet: getARAgingSheet(state, props),
|
||||||
|
receivableAgingSummaryColumns: getARAgingSheetColumns(state, props),
|
||||||
|
receivableAgingSummaryRows: getARAgingSheetRows(state, props),
|
||||||
|
receivableAgingSummaryLoading: loading,
|
||||||
|
receivableAgingSummaryFilter: filter,
|
||||||
|
ARAgingSummaryRefresh: refresh,
|
||||||
|
};
|
||||||
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
|
};
|
||||||
|
return connect(mapStateToProps);
|
||||||
|
};
|
||||||
@@ -7,11 +7,11 @@ import {
|
|||||||
const mapActionsToProps = (dispatch) => ({
|
const mapActionsToProps = (dispatch) => ({
|
||||||
requestReceivableAgingSummary: (query) =>
|
requestReceivableAgingSummary: (query) =>
|
||||||
dispatch(fetchReceivableAgingSummary({ query })),
|
dispatch(fetchReceivableAgingSummary({ query })),
|
||||||
toggleFilterReceivableAgingSummary: () =>
|
toggleFilterARAgingSummary: () =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'RECEIVABLE_AGING_SUMMARY_FILTER_TOGGLE',
|
type: 'RECEIVABLE_AGING_SUMMARY_FILTER_TOGGLE',
|
||||||
}),
|
}),
|
||||||
refreshReceivableAgingSummary: (refresh) =>
|
refreshARAgingSummary: (refresh) =>
|
||||||
dispatch(receivableAgingSummaryRefresh(refresh)),
|
dispatch(receivableAgingSummaryRefresh(refresh)),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ function BalanceSheet({
|
|||||||
// Hide the back link on dashboard topbar.
|
// Hide the back link on dashboard topbar.
|
||||||
setDashboardBackLink(false);
|
setDashboardBackLink(false);
|
||||||
};
|
};
|
||||||
});
|
}, [setDashboardBackLink]);
|
||||||
|
|
||||||
// Handle re-fetch balance sheet after filter change.
|
// Handle re-fetch balance sheet after filter change.
|
||||||
const handleFilterSubmit = useCallback(
|
const handleFilterSubmit = useCallback(
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
import React, { useEffect, useState, useCallback } from 'react';
|
|
||||||
import { useIntl } from 'react-intl';
|
|
||||||
import { useQuery } from 'react-query';
|
|
||||||
|
|
||||||
import moment from 'moment';
|
|
||||||
import { FinancialStatement } from 'components';
|
|
||||||
|
|
||||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
|
||||||
import ReceivableAgingSummaryActionsBar from './ReceivableAgingSummaryActionsBar';
|
|
||||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
|
||||||
import ReceivableAgingSummaryHeader from './ReceivableAgingSummaryHeader'
|
|
||||||
import ReceivableAgingSummaryTable from './ReceivableAgingSummaryTable';
|
|
||||||
|
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
|
||||||
import withReceivableAgingSummaryActions from './withReceivableAgingSummaryActions';
|
|
||||||
import { compose } from 'utils';
|
|
||||||
|
|
||||||
|
|
||||||
function ReceivableAgingSummarySheet({
|
|
||||||
// #withDashboardActions
|
|
||||||
changePageTitle,
|
|
||||||
|
|
||||||
// #withReceivableAgingSummaryActions
|
|
||||||
requestReceivableAgingSummary,
|
|
||||||
}) {
|
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
const [query, setQuery] = useState({
|
|
||||||
as_date: moment().endOf('day').format('YYYY-MM-DD'),
|
|
||||||
aging_before_days: 30,
|
|
||||||
aging_periods: 3,
|
|
||||||
});
|
|
||||||
const [refresh, setRefresh] = useState(true);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
changePageTitle(formatMessage({ id: 'receivable_aging_summary' }));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const fetchSheet = useQuery(
|
|
||||||
['receivable-aging-summary', query],
|
|
||||||
(key, q) => requestReceivableAgingSummary(q),
|
|
||||||
{ manual: true });
|
|
||||||
|
|
||||||
// Handle fetch the data of receivable aging summary sheet.
|
|
||||||
const handleFetchData = useCallback((...args) => {
|
|
||||||
setRefresh(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleFilterSubmit = useCallback((filter) => {
|
|
||||||
const _filter = {
|
|
||||||
...filter,
|
|
||||||
as_date: moment(filter.as_date).format('YYYY-MM-DD'),
|
|
||||||
};
|
|
||||||
setQuery(_filter);
|
|
||||||
setRefresh(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (refresh) {
|
|
||||||
fetchSheet.refetch({ force: true });
|
|
||||||
setRefresh(false);
|
|
||||||
}
|
|
||||||
}, [fetchSheet, refresh]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DashboardInsider>
|
|
||||||
<ReceivableAgingSummaryActionsBar />
|
|
||||||
|
|
||||||
<DashboardPageContent>
|
|
||||||
<FinancialStatement>
|
|
||||||
<ReceivableAgingSummaryHeader
|
|
||||||
pageFilter={query}
|
|
||||||
onSubmitFilter={handleFilterSubmit} />
|
|
||||||
|
|
||||||
<div class="financial-statement__body">
|
|
||||||
<ReceivableAgingSummaryTable
|
|
||||||
receivableAgingSummaryQuery={query}
|
|
||||||
onFetchData={handleFetchData}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</FinancialStatement>
|
|
||||||
</DashboardPageContent>
|
|
||||||
</DashboardInsider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withDashboardActions,
|
|
||||||
withReceivableAgingSummaryActions
|
|
||||||
)(ReceivableAgingSummarySheet);
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import {
|
|
||||||
NavbarDivider,
|
|
||||||
NavbarGroup,
|
|
||||||
Classes,
|
|
||||||
Button,
|
|
||||||
Popover,
|
|
||||||
PopoverInteractionKind,
|
|
||||||
Position,
|
|
||||||
} from "@blueprintjs/core";
|
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
|
||||||
import classNames from 'classnames';
|
|
||||||
|
|
||||||
import DashboardActionsBar from "components/Dashboard/DashboardActionsBar";
|
|
||||||
import Icon from 'components/Icon';
|
|
||||||
import { If } from 'components';
|
|
||||||
|
|
||||||
import withReceivableAging from './withReceivableAgingSummary';
|
|
||||||
import withReceivableAgingActions from './withReceivableAgingSummaryActions';
|
|
||||||
|
|
||||||
import { compose } from 'utils';
|
|
||||||
|
|
||||||
|
|
||||||
function ReceivableAgingSummaryActionsBar({
|
|
||||||
// #withReceivableAging
|
|
||||||
receivableAgingFilter,
|
|
||||||
|
|
||||||
// #withReceivableAgingActions
|
|
||||||
toggleFilterReceivableAgingSummary,
|
|
||||||
refreshReceivableAgingSummary,
|
|
||||||
}) {
|
|
||||||
const handleFilterToggleClick = () => {
|
|
||||||
toggleFilterReceivableAgingSummary();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRecalcReport = () => {
|
|
||||||
refreshReceivableAgingSummary(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DashboardActionsBar>
|
|
||||||
<NavbarGroup>
|
|
||||||
<Button
|
|
||||||
className={classNames(Classes.MINIMAL, 'button--table-views')}
|
|
||||||
icon={<Icon icon="cog-16" iconSize={16} />}
|
|
||||||
text={<T id={'customize_report'} />}
|
|
||||||
/>
|
|
||||||
<NavbarDivider />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
className={classNames(
|
|
||||||
Classes.MINIMAL,
|
|
||||||
'button--gray-highlight',
|
|
||||||
)}
|
|
||||||
text={<T id={'recalc_report'} />}
|
|
||||||
icon={<Icon icon="refresh-16" iconSize={16} />}
|
|
||||||
onClick={handleRecalcReport}
|
|
||||||
/>
|
|
||||||
<If condition={receivableAgingFilter}>
|
|
||||||
<Button
|
|
||||||
className={Classes.MINIMAL}
|
|
||||||
text={<T id={'hide_filter'} />}
|
|
||||||
onClick={handleFilterToggleClick}
|
|
||||||
icon={<Icon icon="arrow-to-top" />}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
|
|
||||||
<If condition={!receivableAgingFilter}>
|
|
||||||
<Button
|
|
||||||
className={Classes.MINIMAL}
|
|
||||||
text={<T id={'show_filter'} />}
|
|
||||||
onClick={handleFilterToggleClick}
|
|
||||||
icon={<Icon icon="arrow-to-bottom" />}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
|
|
||||||
<Popover
|
|
||||||
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(
|
|
||||||
withReceivableAgingActions,
|
|
||||||
withReceivableAging(({ receivableAgingSummaryFilter }) => ({
|
|
||||||
receivableAgingFilter: receivableAgingSummaryFilter,
|
|
||||||
})),
|
|
||||||
)(ReceivableAgingSummaryActionsBar)
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
import React, { useCallback, useEffect } from 'react';
|
|
||||||
import { useIntl, FormattedMessage as T } from 'react-intl';
|
|
||||||
import { useFormik } from 'formik';
|
|
||||||
import { Row, Col } from 'react-grid-system';
|
|
||||||
import * as Yup from 'yup';
|
|
||||||
import {
|
|
||||||
Intent,
|
|
||||||
FormGroup,
|
|
||||||
InputGroup,
|
|
||||||
Position,
|
|
||||||
Button,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
|
||||||
import moment from 'moment';
|
|
||||||
import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader';
|
|
||||||
import { ErrorMessage, FieldHint, FieldRequiredHint } from 'components';
|
|
||||||
import { momentFormatter } from 'utils';
|
|
||||||
|
|
||||||
import withReceivableAging from './withReceivableAgingSummary';
|
|
||||||
import withReceivableAgingActions from './withReceivableAgingSummaryActions';
|
|
||||||
|
|
||||||
import { compose } from 'utils';
|
|
||||||
|
|
||||||
|
|
||||||
function ReceivableAgingSummaryHeader({
|
|
||||||
pageFilter,
|
|
||||||
onSubmitFilter,
|
|
||||||
receivableAgingFilter,
|
|
||||||
|
|
||||||
// #withReceivableAgingSummary
|
|
||||||
receivableAgingRefresh,
|
|
||||||
|
|
||||||
// #withReceivableAgingSummaryActions
|
|
||||||
refreshReceivableAgingSummary
|
|
||||||
}) {
|
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
|
|
||||||
const {
|
|
||||||
values,
|
|
||||||
errors,
|
|
||||||
touched,
|
|
||||||
setFieldValue,
|
|
||||||
getFieldProps,
|
|
||||||
submitForm,
|
|
||||||
isSubmitting,
|
|
||||||
} = useFormik({
|
|
||||||
enableReinitialize: true,
|
|
||||||
initialValues: {
|
|
||||||
as_date: moment(pageFilter.as_date).toDate(),
|
|
||||||
aging_before_days: 30,
|
|
||||||
aging_periods: 3,
|
|
||||||
},
|
|
||||||
validationSchema: Yup.object().shape({
|
|
||||||
as_date: Yup.date().required().label('as_date'),
|
|
||||||
aging_before_days: Yup.number()
|
|
||||||
.required()
|
|
||||||
.integer()
|
|
||||||
.positive()
|
|
||||||
.label('aging_before_days'),
|
|
||||||
aging_periods: Yup.number()
|
|
||||||
.required()
|
|
||||||
.integer()
|
|
||||||
.positive()
|
|
||||||
.label('aging_periods'),
|
|
||||||
}),
|
|
||||||
onSubmit: (values, { setSubmitting }) => {
|
|
||||||
onSubmitFilter(values);
|
|
||||||
setSubmitting(false);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleDateChange = useCallback(
|
|
||||||
(name) => (date) => {
|
|
||||||
setFieldValue(name, date);
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Handle submit filter submit button.
|
|
||||||
useEffect(() => {
|
|
||||||
if (receivableAgingRefresh) {
|
|
||||||
submitForm();
|
|
||||||
refreshReceivableAgingSummary(false);
|
|
||||||
}
|
|
||||||
}, [submitForm, receivableAgingRefresh]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FinancialStatementHeader show={receivableAgingFilter}>
|
|
||||||
<Row>
|
|
||||||
<Col width={260}>
|
|
||||||
<FormGroup
|
|
||||||
label={formatMessage({ id: 'as_date' })}
|
|
||||||
labelInfo={<FieldHint />}
|
|
||||||
fill={true}
|
|
||||||
intent={errors.as_date && Intent.DANGER}
|
|
||||||
>
|
|
||||||
<DateInput
|
|
||||||
{...momentFormatter('YYYY/MM/DD')}
|
|
||||||
value={values.as_date}
|
|
||||||
onChange={handleDateChange('as_date')}
|
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
|
||||||
minimal={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<Col width={260}>
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'aging_before_days'} />}
|
|
||||||
labelInfo={<FieldHint />}
|
|
||||||
className={'form-group--aging-before-days'}
|
|
||||||
intent={errors.aging_before_days && Intent.DANGER}
|
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
medium={true}
|
|
||||||
intent={errors.aging_before_days && Intent.DANGER}
|
|
||||||
{...getFieldProps('aging_before_days')}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<Col width={260}>
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'aging_periods'} />}
|
|
||||||
labelInfo={<FieldHint />}
|
|
||||||
className={'form-group--aging-periods'}
|
|
||||||
intent={errors.aging_before_days && Intent.DANGER}
|
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
medium={true}
|
|
||||||
intent={errors.aging_before_days && Intent.DANGER}
|
|
||||||
{...getFieldProps('aging_periods')}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</FinancialStatementHeader>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withReceivableAgingActions,
|
|
||||||
withReceivableAging(({ receivableAgingSummaryFilter, receivableAgingSummaryRefresh }) => ({
|
|
||||||
receivableAgingFilter: receivableAgingSummaryFilter,
|
|
||||||
receivableAgingRefresh: receivableAgingSummaryRefresh
|
|
||||||
})),
|
|
||||||
)(ReceivableAgingSummaryHeader);
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
import React, { useMemo, useCallback } from 'react';
|
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
|
||||||
import DataTable from "components/DataTable";
|
|
||||||
import FinancialSheet from 'components/FinancialSheet';
|
|
||||||
import Money from 'components/Money';
|
|
||||||
|
|
||||||
import withSettings from 'containers/Settings/withSettings';
|
|
||||||
|
|
||||||
import { compose } from 'utils';
|
|
||||||
import withReceivableAgingSummary from './withReceivableAgingSummary';
|
|
||||||
import withReceivableAgingSummaryTable from './withReceivableAgingSummaryTable';
|
|
||||||
|
|
||||||
function ReceivableAgingSummaryTable({
|
|
||||||
// #withPreferences
|
|
||||||
organizationSettings,
|
|
||||||
|
|
||||||
// #withReceivableAgingSummary
|
|
||||||
receivableAgingRows,
|
|
||||||
receivableAgingLoading,
|
|
||||||
receivableAgingColumns,
|
|
||||||
|
|
||||||
// #ownProps
|
|
||||||
onFetchData,
|
|
||||||
}) {
|
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
|
|
||||||
const agingColumns = useMemo(() => {
|
|
||||||
return receivableAgingColumns.map((agingColumn) => {
|
|
||||||
return `${agingColumn.before_days} - ${agingColumn.to_days || 'And Over'}`;
|
|
||||||
});
|
|
||||||
}, [receivableAgingColumns]);
|
|
||||||
|
|
||||||
const columns = useMemo(() => ([
|
|
||||||
{
|
|
||||||
Header: (<T id={'customer_name'} />),
|
|
||||||
accessor: 'customer_name',
|
|
||||||
className: 'customer_name',
|
|
||||||
sticky: 'left',
|
|
||||||
},
|
|
||||||
...agingColumns.map((agingColumn, index) => ({
|
|
||||||
Header: agingColumn,
|
|
||||||
accessor: (row) => {
|
|
||||||
const amount = row[`aging-${index}`];
|
|
||||||
if (row.rowType === 'total') {
|
|
||||||
return <Money amount={amount} currency={'USD'} />
|
|
||||||
}
|
|
||||||
return amount > 0 ? amount : '';
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
{
|
|
||||||
Header: (<T id={'total'} />),
|
|
||||||
id: 'total',
|
|
||||||
accessor: (row) => {
|
|
||||||
return <Money amount={row.total} currency={'USD'} />;
|
|
||||||
},
|
|
||||||
className: 'total',
|
|
||||||
},
|
|
||||||
]), [agingColumns]);
|
|
||||||
|
|
||||||
const rowClassNames = (row) => [`row-type--${row.original.rowType}`];
|
|
||||||
|
|
||||||
const handleFetchData = useCallback((...args) => {
|
|
||||||
onFetchData && onFetchData(...args);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FinancialSheet
|
|
||||||
companyName={organizationSettings.name}
|
|
||||||
name={'receivable-aging-summary'}
|
|
||||||
sheetType={formatMessage({ id: 'receivable_aging_summary' })}
|
|
||||||
asDate={new Date()}
|
|
||||||
loading={receivableAgingLoading}>
|
|
||||||
|
|
||||||
<DataTable
|
|
||||||
className="bigcapital-datatable--financial-report"
|
|
||||||
columns={columns}
|
|
||||||
data={receivableAgingRows}
|
|
||||||
rowClassNames={rowClassNames}
|
|
||||||
onFetchData={handleFetchData}
|
|
||||||
noInitialFetch={true}
|
|
||||||
sticky={true}
|
|
||||||
/>
|
|
||||||
</FinancialSheet>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withSettings,
|
|
||||||
withReceivableAgingSummaryTable,
|
|
||||||
withReceivableAgingSummary(({
|
|
||||||
receivableAgingSummaryLoading,
|
|
||||||
receivableAgingSummaryColumns,
|
|
||||||
receivableAgingSummaryRows,
|
|
||||||
}) => ({
|
|
||||||
receivableAgingLoading: receivableAgingSummaryLoading,
|
|
||||||
receivableAgingColumns: receivableAgingSummaryColumns,
|
|
||||||
receivableAgingRows: receivableAgingSummaryRows,
|
|
||||||
})),
|
|
||||||
)(ReceivableAgingSummaryTable);
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import { connect } from 'react-redux';
|
|
||||||
import {
|
|
||||||
getFinancialSheet,
|
|
||||||
getFinancialSheetColumns,
|
|
||||||
getFinancialSheetTableRows,
|
|
||||||
} from 'store/financialStatement/financialStatements.selectors';
|
|
||||||
|
|
||||||
export default (mapState) => {
|
|
||||||
const mapStateToProps = (state, props) => {
|
|
||||||
const { receivableAgingSummaryIndex } = props;
|
|
||||||
|
|
||||||
const mapped = {
|
|
||||||
receivableAgingSummarySheet: getFinancialSheet(
|
|
||||||
state.financialStatements.receivableAgingSummary.sheets,
|
|
||||||
receivableAgingSummaryIndex,
|
|
||||||
),
|
|
||||||
receivableAgingSummaryColumns: getFinancialSheetColumns(
|
|
||||||
state.financialStatements.receivableAgingSummary.sheets,
|
|
||||||
receivableAgingSummaryIndex,
|
|
||||||
),
|
|
||||||
receivableAgingSummaryRows: getFinancialSheetTableRows(
|
|
||||||
state.financialStatements.receivableAgingSummary.sheets,
|
|
||||||
receivableAgingSummaryIndex,
|
|
||||||
),
|
|
||||||
receivableAgingSummaryLoading:
|
|
||||||
state.financialStatements.receivableAgingSummary.loading,
|
|
||||||
receivableAgingSummaryFilter:
|
|
||||||
state.financialStatements.receivableAgingSummary.filter,
|
|
||||||
receivableAgingSummaryRefresh:
|
|
||||||
state.financialStatements.receivableAgingSummary.refresh,
|
|
||||||
};
|
|
||||||
return mapState ? mapState(mapped, state, props) : mapped;
|
|
||||||
};
|
|
||||||
return connect(mapStateToProps);
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { getFinancialSheetIndexByQuery } from 'store/financialStatement/financialStatements.selectors';
|
|
||||||
import { connect } from 'react-redux';
|
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => {
|
|
||||||
const { receivableAgingSummaryQuery } = props;
|
|
||||||
|
|
||||||
return {
|
|
||||||
receivableAgingSummaryIndex: getFinancialSheetIndexByQuery(
|
|
||||||
state.financialStatements.receivableAgingSummary.sheets,
|
|
||||||
receivableAgingSummaryQuery,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
export default connect(mapStateToProps);
|
|
||||||
@@ -968,4 +968,5 @@ export default {
|
|||||||
you_could_not_delete_item_that_has_associated_inventory_adjustments_transacions:
|
you_could_not_delete_item_that_has_associated_inventory_adjustments_transacions:
|
||||||
'You could not delete item that has associated inventory adjustments transactions',
|
'You could not delete item that has associated inventory adjustments transactions',
|
||||||
format: 'Format',
|
format: 'Format',
|
||||||
|
current: 'Current',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -135,16 +135,16 @@ export default [
|
|||||||
}),
|
}),
|
||||||
breadcrumb: 'Profit Loss Sheet',
|
breadcrumb: 'Profit Loss Sheet',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: '/financial-reports/receivable-aging-summary',
|
path: '/financial-reports/receivable-aging-summary',
|
||||||
// component: LazyLoader({
|
component: LazyLoader({
|
||||||
// loader: () =>
|
loader: () =>
|
||||||
// import(
|
import(
|
||||||
// 'containers/FinancialStatements/ReceivableAgingSummary/ReceivableAgingSummary'
|
'containers/FinancialStatements/ARAgingSummary/ARAgingSummary'
|
||||||
// ),
|
),
|
||||||
// }),
|
}),
|
||||||
// breadcrumb: 'Receivable Aging Summary',
|
breadcrumb: 'Receivable Aging Summary',
|
||||||
// },
|
},
|
||||||
{
|
{
|
||||||
path: `/financial-reports/journal-sheet`,
|
path: `/financial-reports/journal-sheet`,
|
||||||
component: LazyLoader({
|
component: LazyLoader({
|
||||||
@@ -236,7 +236,7 @@ export default [
|
|||||||
breadcrumb: 'Vendors',
|
breadcrumb: 'Vendors',
|
||||||
},
|
},
|
||||||
|
|
||||||
//Estimates
|
// Estimates
|
||||||
{
|
{
|
||||||
path: `/estimates/:id/edit`,
|
path: `/estimates/:id/edit`,
|
||||||
component: LazyLoader({
|
component: LazyLoader({
|
||||||
|
|||||||
@@ -157,7 +157,8 @@ export const fetchReceivableAgingSummary = ({ query }) => {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: t.RECEIVABLE_AGING_SUMMARY_SET,
|
type: t.RECEIVABLE_AGING_SUMMARY_SET,
|
||||||
payload: {
|
payload: {
|
||||||
aging: response.data.aging,
|
customers: response.data.data.customers,
|
||||||
|
total: response.data.data.total,
|
||||||
columns: response.data.columns,
|
columns: response.data.columns,
|
||||||
query,
|
query,
|
||||||
},
|
},
|
||||||
@@ -172,7 +173,7 @@ export const fetchReceivableAgingSummary = ({ query }) => {
|
|||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
reject(error);
|
reject(error);
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,51 @@ export const generalLedgerToTableRows = (accounts) => {
|
|||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ARAgingSummaryTableRowsMapper = (sheet, total) => {
|
||||||
|
const rows = [];
|
||||||
|
|
||||||
|
const mapAging = (agingPeriods) => {
|
||||||
|
return agingPeriods.reduce((acc, aging, index) => {
|
||||||
|
acc[`aging-${index}`] = aging.total.formatted_amount;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
};
|
||||||
|
sheet.customers.forEach((customer) => {
|
||||||
|
const agingRow = mapAging(customer.aging);
|
||||||
|
|
||||||
|
rows.push({
|
||||||
|
rowType: 'customer',
|
||||||
|
name: customer.customer_name,
|
||||||
|
...agingRow,
|
||||||
|
current: customer.current.formatted_amount,
|
||||||
|
total: customer.total.formatted_amount,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if (rows.length <= 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
...rows,
|
||||||
|
{
|
||||||
|
name: 'TOTAL',
|
||||||
|
rowType: 'total',
|
||||||
|
current: sheet.total.current.formatted_amount,
|
||||||
|
...mapAging(sheet.total.aging),
|
||||||
|
total: sheet.total.total.formatted_amount,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mapTrialBalanceSheetToRows = (sheet) => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
name: 'Total',
|
||||||
|
...sheet.total,
|
||||||
|
},
|
||||||
|
...sheet.accounts,
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
export const profitLossToTableRowsMapper = (profitLoss) => {
|
export const profitLossToTableRowsMapper = (profitLoss) => {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { createReducer } from '@reduxjs/toolkit';
|
import { createReducer } from '@reduxjs/toolkit';
|
||||||
import t from 'store/types';
|
import t from 'store/types';
|
||||||
import { omit } from 'lodash';
|
|
||||||
import {
|
import {
|
||||||
mapBalanceSheetToTableRows,
|
mapBalanceSheetToTableRows,
|
||||||
journalToTableRowsMapper,
|
journalToTableRowsMapper,
|
||||||
generalLedgerToTableRows,
|
generalLedgerToTableRows,
|
||||||
profitLossToTableRowsMapper
|
profitLossToTableRowsMapper,
|
||||||
|
ARAgingSummaryTableRowsMapper,
|
||||||
|
mapTrialBalanceSheetToRows,
|
||||||
} from './financialStatements.mappers';
|
} from './financialStatements.mappers';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
@@ -41,7 +42,7 @@ const initialState = {
|
|||||||
filter: true,
|
filter: true,
|
||||||
},
|
},
|
||||||
receivableAgingSummary: {
|
receivableAgingSummary: {
|
||||||
sheets: [],
|
sheet: {},
|
||||||
loading: false,
|
loading: false,
|
||||||
tableRows: [],
|
tableRows: [],
|
||||||
filter: true,
|
filter: true,
|
||||||
@@ -49,38 +50,6 @@ const initialState = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const mapContactAgingSummary = (sheet) => {
|
|
||||||
const rows = [];
|
|
||||||
|
|
||||||
const mapAging = (agingPeriods) => {
|
|
||||||
return agingPeriods.reduce((acc, aging, index) => {
|
|
||||||
acc[`aging-${index}`] = aging.formatted_total;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
};
|
|
||||||
sheet.customers.forEach((customer) => {
|
|
||||||
const agingRow = mapAging(customer.aging);
|
|
||||||
|
|
||||||
rows.push({
|
|
||||||
rowType: 'customer',
|
|
||||||
customer_name: customer.customer_name,
|
|
||||||
...agingRow,
|
|
||||||
total: customer.total,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
rows.push({
|
|
||||||
rowType: 'total',
|
|
||||||
customer_name: 'Total',
|
|
||||||
...mapAging(sheet.total),
|
|
||||||
total: 0,
|
|
||||||
});
|
|
||||||
return rows;
|
|
||||||
};
|
|
||||||
|
|
||||||
const financialStatementFilterToggle = (financialName, statePath) => {
|
const financialStatementFilterToggle = (financialName, statePath) => {
|
||||||
return {
|
return {
|
||||||
[`${financialName}_FILTER_TOGGLE`]: (state, action) => {
|
[`${financialName}_FILTER_TOGGLE`]: (state, action) => {
|
||||||
@@ -112,8 +81,10 @@ export default createReducer(initialState, {
|
|||||||
...financialStatementFilterToggle('BALANCE_SHEET', 'balanceSheet'),
|
...financialStatementFilterToggle('BALANCE_SHEET', 'balanceSheet'),
|
||||||
|
|
||||||
[t.TRAIL_BALANCE_STATEMENT_SET]: (state, action) => {
|
[t.TRAIL_BALANCE_STATEMENT_SET]: (state, action) => {
|
||||||
|
debugger;
|
||||||
const trailBalanceSheet = {
|
const trailBalanceSheet = {
|
||||||
data: action.data.data,
|
sheet: action.data.data,
|
||||||
|
tableRows: mapTrialBalanceSheetToRows(action.data.data),
|
||||||
query: action.data.query,
|
query: action.data.query,
|
||||||
};
|
};
|
||||||
state.trialBalance.sheet = trailBalanceSheet;
|
state.trialBalance.sheet = trailBalanceSheet;
|
||||||
@@ -187,34 +158,28 @@ export default createReducer(initialState, {
|
|||||||
|
|
||||||
...financialStatementFilterToggle('PROFIT_LOSS', 'profitLoss'),
|
...financialStatementFilterToggle('PROFIT_LOSS', 'profitLoss'),
|
||||||
|
|
||||||
// [t.RECEIVABLE_AGING_SUMMARY_LOADING]: (state, action) => {
|
|
||||||
// const { loading } = action.payload;
|
|
||||||
// state.receivableAgingSummary.loading = loading;
|
|
||||||
// },
|
|
||||||
|
|
||||||
// [t.RECEIVABLE_AGING_SUMMARY_SET]: (state, action) => {
|
|
||||||
// const { aging, columns, query } = action.payload;
|
|
||||||
// const index = getFinancialSheetIndexByQuery(
|
|
||||||
// state.receivableAgingSummary.sheets,
|
|
||||||
// query,
|
|
||||||
// );
|
|
||||||
|
|
||||||
// const receivableSheet = {
|
[t.RECEIVABLE_AGING_SUMMARY_SET]: (state, action) => {
|
||||||
// query,
|
const { customers, total, columns, query } = action.payload;
|
||||||
// columns,
|
|
||||||
// aging,
|
const receivableSheet = {
|
||||||
// tableRows: mapContactAgingSummary(aging),
|
query,
|
||||||
// };
|
columns,
|
||||||
// if (index !== -1) {
|
customers,
|
||||||
// state.receivableAgingSummary[index] = receivableSheet;
|
total,
|
||||||
// } else {
|
tableRows: ARAgingSummaryTableRowsMapper({ customers, columns, total }),
|
||||||
// state.receivableAgingSummary.sheets.push(receivableSheet);
|
};
|
||||||
// }
|
state.receivableAgingSummary.sheet = receivableSheet;
|
||||||
// },
|
},
|
||||||
// [t.RECEIVABLE_AGING_SUMMARY_REFRESH]: (state, action) => {
|
[t.RECEIVABLE_AGING_SUMMARY_REFRESH]: (state, action) => {
|
||||||
// const { refresh } = action.payload;
|
const { refresh } = action.payload;
|
||||||
// state.receivableAgingSummary.refresh = !!refresh;
|
state.receivableAgingSummary.refresh = !!refresh;
|
||||||
// },
|
},
|
||||||
|
[t.RECEIVABLE_AGING_SUMMARY_LOADING]: (state, action) => {
|
||||||
|
const { loading } = action.payload;
|
||||||
|
state.receivableAgingSummary.loading = loading;
|
||||||
|
},
|
||||||
...financialStatementFilterToggle(
|
...financialStatementFilterToggle(
|
||||||
'RECEIVABLE_AGING_SUMMARY',
|
'RECEIVABLE_AGING_SUMMARY',
|
||||||
'receivableAgingSummary',
|
'receivableAgingSummary',
|
||||||
|
|||||||
@@ -145,7 +145,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.financial-sheet{
|
.financial-sheet{
|
||||||
border: 2px solid #EBEBEB;
|
border: 2px solid #f0f0f0;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
min-width: 640px;
|
min-width: 640px;
|
||||||
width: auto;
|
width: auto;
|
||||||
@@ -366,14 +366,25 @@
|
|||||||
&--receivable-aging-summary{
|
&--receivable-aging-summary{
|
||||||
|
|
||||||
.financial-sheet__table{
|
.financial-sheet__table{
|
||||||
|
|
||||||
|
.bigcapital-datatable{
|
||||||
|
.tbody,
|
||||||
|
.thead{
|
||||||
|
.tr .td.customer_name ~ .td,
|
||||||
|
.tr .th.customer_name ~ .th{
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
}
|
||||||
.tbody{
|
.tbody{
|
||||||
|
|
||||||
.row-type--total{
|
.row-type--total{
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
|
||||||
.td{
|
.td{
|
||||||
background-color: #fafbff;
|
border-top-color: #BBB;
|
||||||
border-bottom-color: #666;
|
border-top-style: solid;
|
||||||
border-bottom-style: dotted;
|
border-bottom: 3px double #666;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hapi/boom": "^7.4.3",
|
"@hapi/boom": "^7.4.3",
|
||||||
"@types/i18n": "^0.8.7",
|
"@types/i18n": "^0.8.7",
|
||||||
|
"accounting": "^0.4.1",
|
||||||
"agenda": "^3.1.0",
|
"agenda": "^3.1.0",
|
||||||
"agendash": "^1.0.0",
|
"agendash": "^1.0.0",
|
||||||
"app-root-path": "^3.0.0",
|
"app-root-path": "^3.0.0",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query } from 'express-validator';
|
import { query } from 'express-validator';
|
||||||
import { Inject } from 'typedi';
|
import { Inject } from 'typedi';
|
||||||
import BaseController from 'api/controllers/BaseController';
|
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
import APAgingSummaryReportService from 'services/FinancialStatements/AgingSummary/APAgingSummaryService';
|
import APAgingSummaryReportService from 'services/FinancialStatements/AgingSummary/APAgingSummaryService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
export default class APAgingSummaryReportController extends BaseController {
|
export default class APAgingSummaryReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
APAgingSummaryService: APAgingSummaryReportService;
|
APAgingSummaryService: APAgingSummaryReportService;
|
||||||
|
|
||||||
@@ -28,11 +28,10 @@ export default class APAgingSummaryReportController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get validationSchema() {
|
get validationSchema() {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
query('as_date').optional().isISO8601(),
|
query('as_date').optional().isISO8601(),
|
||||||
query('aging_days_before').optional().isNumeric().toInt(),
|
query('aging_days_before').optional().isNumeric().toInt(),
|
||||||
query('aging_periods').optional().isNumeric().toInt(),
|
query('aging_periods').optional().isNumeric().toInt(),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
|
||||||
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
|
||||||
query('vendors_ids').optional().isArray({ min: 1 }),
|
query('vendors_ids').optional().isArray({ min: 1 }),
|
||||||
query('vendors_ids.*').isInt({ min: 1 }).toInt(),
|
query('vendors_ids.*').isInt({ min: 1 }).toInt(),
|
||||||
query('none_zero').default(true).isBoolean().toBoolean(),
|
query('none_zero').default(true).isBoolean().toBoolean(),
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { Router, Request, Response } from 'express';
|
import { Router, Request, Response } from 'express';
|
||||||
import { castArray } from 'lodash';
|
import { query } from 'express-validator';
|
||||||
import { query, oneOf } from 'express-validator';
|
|
||||||
import { IARAgingSummaryQuery } from 'interfaces';
|
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import ARAgingSummaryService from 'services/FinancialStatements/AgingSummary/ARAgingSummaryService';
|
import ARAgingSummaryService from 'services/FinancialStatements/AgingSummary/ARAgingSummaryService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ARAgingSummaryReportController extends BaseController {
|
export default class ARAgingSummaryReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
ARAgingSummaryService: ARAgingSummaryService;
|
ARAgingSummaryService: ARAgingSummaryService;
|
||||||
|
|
||||||
@@ -31,11 +29,11 @@ export default class ARAgingSummaryReportController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get validationSchema() {
|
get validationSchema() {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
|
|
||||||
query('as_date').optional().isISO8601(),
|
query('as_date').optional().isISO8601(),
|
||||||
query('aging_days_before').optional().isInt({ max: 500 }).toInt(),
|
query('aging_days_before').optional().isInt({ max: 500 }).toInt(),
|
||||||
query('aging_periods').optional().isInt({ max: 12 }).toInt(),
|
query('aging_periods').optional().isInt({ max: 12 }).toInt(),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
|
||||||
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
|
||||||
query('customers_ids').optional().isArray({ min: 1 }),
|
query('customers_ids').optional().isArray({ min: 1 }),
|
||||||
query('customers_ids.*').isInt({ min: 1 }).toInt(),
|
query('customers_ids.*').isInt({ min: 1 }).toInt(),
|
||||||
query('none_zero').default(true).isBoolean().toBoolean(),
|
query('none_zero').default(true).isBoolean().toBoolean(),
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { Router, Request, Response, NextFunction } from 'express';
|
|||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import BalanceSheetStatementService from 'services/FinancialStatements/BalanceSheet/BalanceSheetService';
|
import BalanceSheetStatementService from 'services/FinancialStatements/BalanceSheet/BalanceSheetService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class BalanceSheetStatementController extends BaseController {
|
export default class BalanceSheetStatementController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
balanceSheetService: BalanceSheetStatementService;
|
balanceSheetService: BalanceSheetStatementService;
|
||||||
|
|
||||||
@@ -32,6 +32,8 @@ export default class BalanceSheetStatementController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get balanceSheetValidationSchema(): ValidationChain[] {
|
get balanceSheetValidationSchema(): ValidationChain[] {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
|
|
||||||
query('accounting_method').optional().isIn(['cash', 'accural']),
|
query('accounting_method').optional().isIn(['cash', 'accural']),
|
||||||
query('from_date').optional(),
|
query('from_date').optional(),
|
||||||
query('to_date').optional(),
|
query('to_date').optional(),
|
||||||
@@ -39,8 +41,6 @@ export default class BalanceSheetStatementController extends BaseController {
|
|||||||
query('display_columns_by')
|
query('display_columns_by')
|
||||||
.optional({ nullable: true, checkFalsy: true })
|
.optional({ nullable: true, checkFalsy: true })
|
||||||
.isIn(['year', 'month', 'week', 'day', 'quarter']),
|
.isIn(['year', 'month', 'week', 'day', 'quarter']),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
|
||||||
query('number_format.divide_1000').optional().isBoolean().toBoolean(),
|
|
||||||
query('account_ids').isArray().optional(),
|
query('account_ids').isArray().optional(),
|
||||||
query('account_ids.*').isNumeric().toInt(),
|
query('account_ids.*').isNumeric().toInt(),
|
||||||
query('none_zero').optional().isBoolean().toBoolean(),
|
query('none_zero').optional().isBoolean().toBoolean(),
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { query } from 'express-validator';
|
||||||
|
import BaseController from "../BaseController";
|
||||||
|
|
||||||
|
export default class BaseFinancialReportController extends BaseController {
|
||||||
|
|
||||||
|
|
||||||
|
get sheetNumberFormatValidationSchema() {
|
||||||
|
return [
|
||||||
|
query('number_format.precision')
|
||||||
|
.optional()
|
||||||
|
.isInt({ min: 0, max: 5 })
|
||||||
|
.toInt(),
|
||||||
|
query('number_format.divide_on_1000').optional().isBoolean().toBoolean(),
|
||||||
|
query('number_format.show_zero').optional().isBoolean().toBoolean(),
|
||||||
|
query('number_format.format_money')
|
||||||
|
.optional()
|
||||||
|
.isIn(['total', 'always', 'none'])
|
||||||
|
.trim(),
|
||||||
|
query('number_format.negative_format')
|
||||||
|
.optional()
|
||||||
|
.isIn(['parentheses', 'mines'])
|
||||||
|
.trim()
|
||||||
|
.escape(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
import GeneralLedgerService from 'services/FinancialStatements/GeneralLedger/GeneralLedgerService';
|
import GeneralLedgerService from 'services/FinancialStatements/GeneralLedger/GeneralLedgerService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class GeneralLedgerReportController extends BaseController {
|
export default class GeneralLedgerReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
generalLedgetService: GeneralLedgerService;
|
generalLedgetService: GeneralLedgerService;
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { Inject, Service } from 'typedi';
|
|||||||
import { Request, Response, Router, NextFunction } from 'express';
|
import { Request, Response, Router, NextFunction } from 'express';
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
import { query, oneOf } from 'express-validator';
|
import { query, oneOf } from 'express-validator';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
import JournalSheetService from 'services/FinancialStatements/JournalSheet/JournalSheetService';
|
import JournalSheetService from 'services/FinancialStatements/JournalSheet/JournalSheetService';
|
||||||
import BaseController from '../BaseController';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class JournalSheetController extends BaseController {
|
export default class JournalSheetController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
journalService: JournalSheetService;
|
journalService: JournalSheetService;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import ProfitLossSheetService from 'services/FinancialStatements/ProfitLossSheet/ProfitLossSheetService';
|
import ProfitLossSheetService from 'services/FinancialStatements/ProfitLossSheet/ProfitLossSheetService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ProfitLossSheetController extends BaseController {
|
export default class ProfitLossSheetController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
profitLossSheetService: ProfitLossSheetService;
|
profitLossSheetService: ProfitLossSheetService;
|
||||||
|
|
||||||
@@ -29,11 +29,10 @@ export default class ProfitLossSheetController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get validationSchema(): ValidationChain[] {
|
get validationSchema(): ValidationChain[] {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
query('basis').optional(),
|
query('basis').optional(),
|
||||||
query('from_date').optional().isISO8601(),
|
query('from_date').optional().isISO8601(),
|
||||||
query('to_date').optional().isISO8601(),
|
query('to_date').optional().isISO8601(),
|
||||||
query('number_format.no_cents').optional().isBoolean(),
|
|
||||||
query('number_format.divide_1000').optional().isBoolean(),
|
|
||||||
query('basis').optional(),
|
query('basis').optional(),
|
||||||
query('none_zero').optional().isBoolean().toBoolean(),
|
query('none_zero').optional().isBoolean().toBoolean(),
|
||||||
query('none_transactions').optional().isBoolean().toBoolean(),
|
query('none_transactions').optional().isBoolean().toBoolean(),
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { Request, Response, Router, NextFunction } from 'express';
|
import { Request, Response, Router, NextFunction } from 'express';
|
||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
|
||||||
import BaseController from '../BaseController';
|
|
||||||
import TrialBalanceSheetService from 'services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService';
|
|
||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
|
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||||
|
import TrialBalanceSheetService from 'services/FinancialStatements/TrialBalanceSheet/TrialBalanceSheetService';
|
||||||
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class TrialBalanceSheetController extends BaseController {
|
export default class TrialBalanceSheetController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
trialBalanceSheetService: TrialBalanceSheetService;
|
trialBalanceSheetService: TrialBalanceSheetService;
|
||||||
|
|
||||||
@@ -17,7 +17,8 @@ export default class TrialBalanceSheetController extends BaseController {
|
|||||||
router() {
|
router() {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/',
|
router.get(
|
||||||
|
'/',
|
||||||
this.trialBalanceSheetValidationSchema,
|
this.trialBalanceSheetValidationSchema,
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.trialBalanceSheet.bind(this))
|
asyncMiddleware(this.trialBalanceSheet.bind(this))
|
||||||
@@ -31,11 +32,10 @@ export default class TrialBalanceSheetController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
get trialBalanceSheetValidationSchema(): ValidationChain[] {
|
get trialBalanceSheetValidationSchema(): ValidationChain[] {
|
||||||
return [
|
return [
|
||||||
|
...this.sheetNumberFormatValidationSchema,
|
||||||
query('basis').optional(),
|
query('basis').optional(),
|
||||||
query('from_date').optional().isISO8601(),
|
query('from_date').optional().isISO8601(),
|
||||||
query('to_date').optional().isISO8601(),
|
query('to_date').optional().isISO8601(),
|
||||||
query('number_format.no_cents').optional().isBoolean().toBoolean(),
|
|
||||||
query('number_format.1000_divide').optional().isBoolean().toBoolean(),
|
|
||||||
query('account_ids').isArray().optional(),
|
query('account_ids').isArray().optional(),
|
||||||
query('account_ids.*').isNumeric().toInt(),
|
query('account_ids.*').isNumeric().toInt(),
|
||||||
query('basis').optional(),
|
query('basis').optional(),
|
||||||
@@ -46,7 +46,11 @@ export default class TrialBalanceSheetController extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the trial balance sheet.
|
* Retrieve the trial balance sheet.
|
||||||
*/
|
*/
|
||||||
public async trialBalanceSheet(req: Request, res: Response, next: NextFunction) {
|
public async trialBalanceSheet(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
const { tenantId, settings } = req;
|
const { tenantId, settings } = req;
|
||||||
let filter = this.matchedQueryData(req);
|
let filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
@@ -54,18 +58,29 @@ export default class TrialBalanceSheetController extends BaseController {
|
|||||||
...filter,
|
...filter,
|
||||||
accountsIds: castArray(filter.accountsIds),
|
accountsIds: castArray(filter.accountsIds),
|
||||||
};
|
};
|
||||||
const organizationName = settings.get({ group: 'organization', key: 'name' });
|
const organizationName = settings.get({
|
||||||
const baseCurrency = settings.get({ group: 'organization', key: 'base_currency' });
|
group: 'organization',
|
||||||
|
key: 'name',
|
||||||
|
});
|
||||||
|
const baseCurrency = settings.get({
|
||||||
|
group: 'organization',
|
||||||
|
key: 'base_currency',
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data, query } = await this.trialBalanceSheetService
|
const {
|
||||||
.trialBalanceSheet(tenantId, filter);
|
data,
|
||||||
|
query,
|
||||||
|
} = await this.trialBalanceSheetService.trialBalanceSheet(
|
||||||
|
tenantId,
|
||||||
|
filter
|
||||||
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
organization_name: organizationName,
|
organization_name: organizationName,
|
||||||
base_currency: baseCurrency,
|
base_currency: baseCurrency,
|
||||||
data: this.transfromToResponse(data),
|
data: this.transfromToResponse(data),
|
||||||
query: this.transfromToResponse(query)
|
query: this.transfromToResponse(query),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
|
|||||||
@@ -1,30 +1,32 @@
|
|||||||
import {
|
import {
|
||||||
IAgingPeriod,
|
IAgingPeriod,
|
||||||
IAgingPeriodTotal
|
IAgingPeriodTotal,
|
||||||
|
IAgingAmount
|
||||||
} from './AgingReport';
|
} from './AgingReport';
|
||||||
|
import {
|
||||||
|
INumberFormatQuery
|
||||||
|
} from './FinancialStatements';
|
||||||
|
|
||||||
export interface IAPAgingSummaryQuery {
|
export interface IAPAgingSummaryQuery {
|
||||||
asDate: Date | string;
|
asDate: Date | string;
|
||||||
agingDaysBefore: number;
|
agingDaysBefore: number;
|
||||||
agingPeriods: number;
|
agingPeriods: number;
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery;
|
||||||
noCents: boolean;
|
|
||||||
divideOn1000: boolean;
|
|
||||||
};
|
|
||||||
vendorsIds: number[];
|
vendorsIds: number[];
|
||||||
noneZero: boolean;
|
noneZero: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAPAgingSummaryVendor {
|
export interface IAPAgingSummaryVendor {
|
||||||
vendorName: string,
|
vendorName: string,
|
||||||
current: IAgingPeriodTotal,
|
current: IAgingAmount,
|
||||||
aging: (IAgingPeriod & IAgingPeriodTotal)[],
|
aging: IAgingPeriodTotal[],
|
||||||
total: IAgingPeriodTotal,
|
total: IAgingAmount,
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IAPAgingSummaryTotal {
|
export interface IAPAgingSummaryTotal {
|
||||||
current: IAgingPeriodTotal,
|
current: IAgingAmount,
|
||||||
aging: (IAgingPeriodTotal & IAgingPeriod)[],
|
aging: IAgingPeriodTotal[],
|
||||||
|
total: IAgingAmount,
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IAPAgingSummaryData {
|
export interface IAPAgingSummaryData {
|
||||||
|
|||||||
@@ -1,35 +1,31 @@
|
|||||||
import {
|
import { IAgingPeriod, IAgingPeriodTotal, IAgingAmount } from './AgingReport';
|
||||||
IAgingPeriod,
|
import { INumberFormatQuery } from './FinancialStatements';
|
||||||
IAgingPeriodTotal
|
|
||||||
} from './AgingReport';
|
|
||||||
|
|
||||||
export interface IARAgingSummaryQuery {
|
export interface IARAgingSummaryQuery {
|
||||||
asDate: Date | string;
|
asDate: Date | string;
|
||||||
agingDaysBefore: number;
|
agingDaysBefore: number;
|
||||||
agingPeriods: number;
|
agingPeriods: number;
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery;
|
||||||
noCents: boolean;
|
|
||||||
divideOn1000: boolean;
|
|
||||||
};
|
|
||||||
customersIds: number[];
|
customersIds: number[];
|
||||||
noneZero: boolean;
|
noneZero: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IARAgingSummaryCustomer {
|
export interface IARAgingSummaryCustomer {
|
||||||
customerName: string;
|
customerName: string;
|
||||||
current: IAgingPeriodTotal,
|
current: IAgingAmount;
|
||||||
aging: (IAgingPeriodTotal & IAgingPeriod)[];
|
aging: IAgingPeriodTotal[];
|
||||||
total: IAgingPeriodTotal;
|
total: IAgingAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IARAgingSummaryTotal {
|
export interface IARAgingSummaryTotal {
|
||||||
current: IAgingPeriodTotal,
|
current: IAgingAmount;
|
||||||
aging: (IAgingPeriodTotal & IAgingPeriod)[],
|
aging: IAgingPeriodTotal[];
|
||||||
};
|
total: IAgingAmount;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IARAgingSummaryData {
|
export interface IARAgingSummaryData {
|
||||||
customers: IARAgingSummaryCustomer[],
|
customers: IARAgingSummaryCustomer[];
|
||||||
total: IARAgingSummaryTotal,
|
total: IARAgingSummaryTotal;
|
||||||
};
|
}
|
||||||
|
|
||||||
export type IARAgingSummaryColumns = IAgingPeriod[];
|
export type IARAgingSummaryColumns = IAgingPeriod[];
|
||||||
@@ -1,12 +1,22 @@
|
|||||||
export interface IAgingPeriodTotal {
|
export interface IAgingPeriodTotal extends IAgingPeriod {
|
||||||
total: number;
|
total: IAgingAmount;
|
||||||
formattedTotal: string;
|
};
|
||||||
|
|
||||||
|
export interface IAgingAmount {
|
||||||
|
amount: number;
|
||||||
|
formattedAmount: string;
|
||||||
currencyCode: string;
|
currencyCode: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAgingPeriod {
|
export interface IAgingPeriod {
|
||||||
fromPeriod: Date|string;
|
fromPeriod: Date | string;
|
||||||
toPeriod: Date|string;
|
toPeriod: Date | string;
|
||||||
beforeDays: number;
|
beforeDays: number;
|
||||||
toDays: number;
|
toDays: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IAgingSummaryContact {
|
||||||
|
current: IAgingAmount;
|
||||||
|
aging: IAgingPeriodTotal[];
|
||||||
|
total: IAgingAmount;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,74 +1,79 @@
|
|||||||
|
import {
|
||||||
|
INumberFormatQuery,
|
||||||
|
IFormatNumberSettings,
|
||||||
|
} from './FinancialStatements';
|
||||||
|
|
||||||
export interface IBalanceSheetQuery{
|
export interface IBalanceSheetQuery {
|
||||||
displayColumnsType: 'total' | 'date_periods',
|
displayColumnsType: 'total' | 'date_periods';
|
||||||
displayColumnsBy: string,
|
displayColumnsBy: string;
|
||||||
fromDate: Date|string,
|
fromDate: Date | string;
|
||||||
toDate: Date|string,
|
toDate: Date | string;
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery;
|
||||||
noCents: boolean,
|
noneZero: boolean;
|
||||||
divideOn1000: boolean,
|
noneTransactions: boolean;
|
||||||
},
|
basis: 'cash' | 'accural';
|
||||||
noneZero: boolean,
|
accountIds: number[];
|
||||||
noneTransactions: boolean,
|
}
|
||||||
basis: 'cash' | 'accural',
|
|
||||||
accountIds: number[],
|
export interface IBalanceSheetFormatNumberSettings
|
||||||
|
extends IFormatNumberSettings {
|
||||||
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetStatementService {
|
export interface IBalanceSheetStatementService {
|
||||||
balanceSheet(tenantId: number, query: IBalanceSheetQuery): Promise<IBalanceSheetStatement>;
|
balanceSheet(
|
||||||
|
tenantId: number,
|
||||||
|
query: IBalanceSheetQuery
|
||||||
|
): Promise<IBalanceSheetStatement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetStatementColumns {
|
export interface IBalanceSheetStatementColumns {}
|
||||||
|
|
||||||
}
|
export interface IBalanceSheetStatementData {}
|
||||||
|
|
||||||
export interface IBalanceSheetStatementData {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IBalanceSheetStatement {
|
export interface IBalanceSheetStatement {
|
||||||
query: IBalanceSheetQuery,
|
query: IBalanceSheetQuery;
|
||||||
columns: IBalanceSheetStatementColumns,
|
columns: IBalanceSheetStatementColumns;
|
||||||
data: IBalanceSheetStatementData,
|
data: IBalanceSheetStatementData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetStructureSection {
|
export interface IBalanceSheetStructureSection {
|
||||||
name: string,
|
name: string;
|
||||||
sectionType?: string,
|
sectionType?: string;
|
||||||
type: 'section' | 'accounts_section',
|
type: 'section' | 'accounts_section';
|
||||||
children?: IBalanceSheetStructureSection[],
|
children?: IBalanceSheetStructureSection[];
|
||||||
accountsTypesRelated?: string[],
|
accountsTypesRelated?: string[];
|
||||||
alwaysShow?: boolean,
|
alwaysShow?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetAccountTotal {
|
export interface IBalanceSheetAccountTotal {
|
||||||
amount: number,
|
amount: number;
|
||||||
formattedAmount: string,
|
formattedAmount: string;
|
||||||
currencyCode: string,
|
currencyCode: string;
|
||||||
date?: string|Date,
|
date?: string | Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetAccount {
|
export interface IBalanceSheetAccount {
|
||||||
id: number,
|
id: number;
|
||||||
index: number,
|
index: number;
|
||||||
name: string,
|
name: string;
|
||||||
code: string,
|
code: string;
|
||||||
parentAccountId: number,
|
parentAccountId: number;
|
||||||
type: 'account',
|
type: 'account';
|
||||||
hasTransactions: boolean,
|
hasTransactions: boolean;
|
||||||
children?: IBalanceSheetAccount[],
|
children?: IBalanceSheetAccount[];
|
||||||
total: IBalanceSheetAccountTotal,
|
total: IBalanceSheetAccountTotal;
|
||||||
totalPeriods?: IBalanceSheetAccountTotal[],
|
totalPeriods?: IBalanceSheetAccountTotal[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBalanceSheetSection {
|
export interface IBalanceSheetSection {
|
||||||
name: string,
|
name: string;
|
||||||
sectionType?: string,
|
sectionType?: string;
|
||||||
type: 'section' | 'accounts_section',
|
type: 'section' | 'accounts_section';
|
||||||
children: IBalanceSheetAccount[] | IBalanceSheetSection[],
|
children: IBalanceSheetAccount[] | IBalanceSheetSection[];
|
||||||
total: IBalanceSheetAccountTotal,
|
total: IBalanceSheetAccountTotal;
|
||||||
totalPeriods?: IBalanceSheetAccountTotal[];
|
totalPeriods?: IBalanceSheetAccountTotal[];
|
||||||
|
|
||||||
accountsTypesRelated?: string[],
|
accountsTypesRelated?: string[];
|
||||||
_forceShow?: boolean,
|
_forceShow?: boolean;
|
||||||
}
|
}
|
||||||
@@ -1,2 +1,19 @@
|
|||||||
|
export interface INumberFormatQuery {
|
||||||
|
precision: number;
|
||||||
|
divideOn1000: boolean;
|
||||||
|
showZero: boolean;
|
||||||
|
formatMoney: 'total' | 'always' | 'none';
|
||||||
|
negativeFormat: 'parentheses' | 'mines';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IFormatNumberSettings {
|
||||||
|
precision?: number;
|
||||||
|
divideOn1000?: boolean;
|
||||||
|
excerptZero?: boolean;
|
||||||
|
negativeFormat?: 'parentheses' | 'mines';
|
||||||
|
thousand?: string;
|
||||||
|
decimal?: string;
|
||||||
|
zeroSign?: string;
|
||||||
|
symbol?: string;
|
||||||
|
money?: boolean,
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ export interface IJournalEntry {
|
|||||||
referenceType: string,
|
referenceType: string,
|
||||||
referenceId: number,
|
referenceId: number,
|
||||||
|
|
||||||
|
referenceTypeFormatted: string,
|
||||||
|
|
||||||
transactionType?: string,
|
transactionType?: string,
|
||||||
note?: string,
|
note?: string,
|
||||||
userId?: number,
|
userId?: number,
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
|
import {
|
||||||
|
INumberFormatQuery,
|
||||||
|
} from './FinancialStatements';
|
||||||
|
|
||||||
export interface IProfitLossSheetQuery {
|
export interface IProfitLossSheetQuery {
|
||||||
basis: string,
|
basis: string,
|
||||||
fromDate: Date | string,
|
fromDate: Date | string,
|
||||||
toDate: Date | string,
|
toDate: Date | string,
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery,
|
||||||
noCents: boolean,
|
|
||||||
divideOn1000: boolean,
|
|
||||||
},
|
|
||||||
noneZero: boolean,
|
noneZero: boolean,
|
||||||
noneTransactions: boolean,
|
noneTransactions: boolean,
|
||||||
accountsIds: number[],
|
accountsIds: number[],
|
||||||
@@ -34,8 +33,8 @@ export interface IProfitLossSheetAccount {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface IProfitLossSheetAccountsSection {
|
export interface IProfitLossSheetAccountsSection {
|
||||||
sectionTitle: string,
|
name: string,
|
||||||
entryNormal: 'credit',
|
entryNormal: 'credit' | 'debit',
|
||||||
accounts: IProfitLossSheetAccount[],
|
accounts: IProfitLossSheetAccount[],
|
||||||
total: IProfitLossSheetTotal,
|
total: IProfitLossSheetTotal,
|
||||||
totalPeriods?: IProfitLossSheetTotal[],
|
totalPeriods?: IProfitLossSheetTotal[],
|
||||||
|
|||||||
@@ -1,38 +1,41 @@
|
|||||||
|
import { INumberFormatQuery } from './FinancialStatements';
|
||||||
|
|
||||||
export interface ITrialBalanceSheetQuery {
|
export interface ITrialBalanceSheetQuery {
|
||||||
fromDate: Date|string,
|
fromDate: Date | string;
|
||||||
toDate: Date|string,
|
toDate: Date | string;
|
||||||
numberFormat: {
|
numberFormat: INumberFormatQuery;
|
||||||
noCents: boolean,
|
basis: 'cash' | 'accural';
|
||||||
divideOn1000: boolean,
|
noneZero: boolean;
|
||||||
},
|
noneTransactions: boolean;
|
||||||
basis: 'cash' | 'accural',
|
accountIds: number[];
|
||||||
noneZero: boolean,
|
|
||||||
noneTransactions: boolean,
|
|
||||||
accountIds: number[],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITrialBalanceAccount {
|
export interface ITrialBalanceTotal {
|
||||||
id: number,
|
credit: number;
|
||||||
parentAccountId: number,
|
debit: number;
|
||||||
name: string,
|
balance: number;
|
||||||
code: string,
|
currencyCode: string;
|
||||||
accountNormal: string,
|
|
||||||
hasTransactions: boolean,
|
|
||||||
|
|
||||||
credit: number,
|
formattedCredit: string;
|
||||||
debit: number,
|
formattedDebit: string;
|
||||||
balance: number,
|
formattedBalance: string;
|
||||||
currencyCode: string,
|
|
||||||
|
|
||||||
formattedCredit: string,
|
|
||||||
formattedDebit: string,
|
|
||||||
formattedBalance: string,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ITrialBalanceSheetData = IBalanceSheetSection[];
|
export interface ITrialBalanceAccount extends ITrialBalanceTotal {
|
||||||
|
id: number;
|
||||||
|
parentAccountId: number;
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
accountNormal: string;
|
||||||
|
hasTransactions: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ITrialBalanceSheetData = {
|
||||||
|
accounts: ITrialBalanceAccount[];
|
||||||
|
total: ITrialBalanceTotal;
|
||||||
|
};
|
||||||
|
|
||||||
export interface ITrialBalanceStatement {
|
export interface ITrialBalanceStatement {
|
||||||
data: ITrialBalanceSheetData,
|
data: ITrialBalanceSheetData;
|
||||||
query: ITrialBalanceSheetQuery,
|
query: ITrialBalanceSheetQuery;
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ export default class CustomerRepository extends TenantRepository {
|
|||||||
*/
|
*/
|
||||||
constructor(knex, cache) {
|
constructor(knex, cache) {
|
||||||
super(knex, cache);
|
super(knex, cache);
|
||||||
this.repositoryName = 'ContactRepository';
|
this.repositoryName = 'CustomerRepository';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export default class VendorRepository extends TenantRepository {
|
|||||||
*/
|
*/
|
||||||
constructor(knex, cache) {
|
constructor(knex, cache) {
|
||||||
super(knex, cache);
|
super(knex, cache);
|
||||||
this.repositoryName = 'ContactRepository';
|
this.repositoryName = 'VendorRepository';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,6 +17,10 @@ export default class VendorRepository extends TenantRepository {
|
|||||||
return Vendor.bindKnex(this.knex);
|
return Vendor.bindKnex(this.knex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unpaid() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
changeBalance(vendorId: number, amount: number) {
|
changeBalance(vendorId: number, amount: number) {
|
||||||
return super.changeNumber({ id: vendorId }, 'balance', amount);
|
return super.changeNumber({ id: vendorId }, 'balance', amount);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,17 @@ export default class PayableAgingSummaryService {
|
|||||||
/**
|
/**
|
||||||
* Default report query.
|
* Default report query.
|
||||||
*/
|
*/
|
||||||
get defaultQuery() {
|
get defaultQuery(): IAPAgingSummaryQuery {
|
||||||
return {
|
return {
|
||||||
asDate: moment().format('YYYY-MM-DD'),
|
asDate: moment().format('YYYY-MM-DD'),
|
||||||
agingDaysBefore: 30,
|
agingDaysBefore: 30,
|
||||||
agingPeriods: 3,
|
agingPeriods: 3,
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: false,
|
precision: 2,
|
||||||
divideOn1000: false,
|
divideOn1000: false,
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
negativeFormat: 'mines'
|
||||||
},
|
},
|
||||||
vendorsIds: [],
|
vendorsIds: [],
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ import {
|
|||||||
IVendor,
|
IVendor,
|
||||||
IAPAgingSummaryData,
|
IAPAgingSummaryData,
|
||||||
IAPAgingSummaryVendor,
|
IAPAgingSummaryVendor,
|
||||||
IAPAgingSummaryColumns
|
IAPAgingSummaryColumns,
|
||||||
|
IAPAgingSummaryTotal
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import { Dictionary } from 'tsyringe/dist/typings/types';
|
import { Dictionary } from 'tsyringe/dist/typings/types';
|
||||||
|
|
||||||
export default class APAgingSummarySheet extends AgingSummaryReport {
|
export default class APAgingSummarySheet extends AgingSummaryReport {
|
||||||
readonly tenantId: number;
|
readonly tenantId: number;
|
||||||
readonly query: IAPAgingSummaryQuery;
|
readonly query: IAPAgingSummaryQuery;
|
||||||
@@ -56,6 +58,23 @@ export default class APAgingSummarySheet extends AgingSummaryReport {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the vendors aging and current total.
|
||||||
|
* @param {IAPAgingSummaryTotal} vendorsAgingPeriods
|
||||||
|
* @return {IAPAgingSummaryTotal}
|
||||||
|
*/
|
||||||
|
getVendorsTotal(vendorsAgingPeriods): IAPAgingSummaryTotal {
|
||||||
|
const totalAgingPeriods = this.getTotalAgingPeriods(vendorsAgingPeriods);
|
||||||
|
const totalCurrent = this.getTotalCurrent(vendorsAgingPeriods);
|
||||||
|
const totalVendorsTotal = this.getTotalContactsTotals(vendorsAgingPeriods);
|
||||||
|
|
||||||
|
return {
|
||||||
|
current: this.formatTotalAmount(totalCurrent),
|
||||||
|
aging: totalAgingPeriods,
|
||||||
|
total: this.formatTotalAmount(totalVendorsTotal),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the vendor section data.
|
* Retrieve the vendor section data.
|
||||||
* @param {IVendor} vendor
|
* @param {IVendor} vendor
|
||||||
@@ -85,7 +104,7 @@ export default class APAgingSummarySheet extends AgingSummaryReport {
|
|||||||
.map((vendor) => this.vendorData(vendor))
|
.map((vendor) => this.vendorData(vendor))
|
||||||
.filter(
|
.filter(
|
||||||
(vendor: IAPAgingSummaryVendor) =>
|
(vendor: IAPAgingSummaryVendor) =>
|
||||||
!(vendor.total.total === 0 && this.query.noneZero)
|
!(vendor.total.amount === 0 && this.query.noneZero)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,16 +114,12 @@ export default class APAgingSummarySheet extends AgingSummaryReport {
|
|||||||
*/
|
*/
|
||||||
public reportData(): IAPAgingSummaryData {
|
public reportData(): IAPAgingSummaryData {
|
||||||
const vendorsAgingPeriods = this.vendorsWalker(this.contacts);
|
const vendorsAgingPeriods = this.vendorsWalker(this.contacts);
|
||||||
const totalAgingPeriods = this.getTotalAgingPeriods(vendorsAgingPeriods);
|
const vendorsTotal = this.getVendorsTotal(vendorsAgingPeriods);
|
||||||
const totalCurrent = this.getTotalCurrent(vendorsAgingPeriods);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
vendors: vendorsAgingPeriods,
|
vendors: vendorsAgingPeriods,
|
||||||
total: {
|
total: vendorsTotal,
|
||||||
current: this.formatTotalAmount(totalCurrent),
|
};
|
||||||
aging: totalAgingPeriods,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,14 +15,17 @@ export default class ARAgingSummaryService {
|
|||||||
/**
|
/**
|
||||||
* Default report query.
|
* Default report query.
|
||||||
*/
|
*/
|
||||||
get defaultQuery() {
|
get defaultQuery(): IARAgingSummaryQuery {
|
||||||
return {
|
return {
|
||||||
asDate: moment().format('YYYY-MM-DD'),
|
asDate: moment().format('YYYY-MM-DD'),
|
||||||
agingDaysBefore: 30,
|
agingDaysBefore: 30,
|
||||||
agingPeriods: 3,
|
agingPeriods: 3,
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
no_cents: false,
|
divideOn1000: false,
|
||||||
divide_1000: false,
|
negativeFormat: 'mines',
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
precision: 2,
|
||||||
},
|
},
|
||||||
customersIds: [],
|
customersIds: [],
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
@@ -50,6 +53,7 @@ export default class ARAgingSummaryService {
|
|||||||
});
|
});
|
||||||
// Settings tenant service.
|
// Settings tenant service.
|
||||||
const settings = this.tenancy.settings(tenantId);
|
const settings = this.tenancy.settings(tenantId);
|
||||||
|
|
||||||
const baseCurrency = settings.get({
|
const baseCurrency = settings.get({
|
||||||
group: 'organization',
|
group: 'organization',
|
||||||
key: 'base_currency',
|
key: 'base_currency',
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
ISaleInvoice,
|
ISaleInvoice,
|
||||||
IARAgingSummaryData,
|
IARAgingSummaryData,
|
||||||
IARAgingSummaryColumns,
|
IARAgingSummaryColumns,
|
||||||
|
IARAgingSummaryTotal,
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import AgingSummaryReport from './AgingSummary';
|
import AgingSummaryReport from './AgingSummary';
|
||||||
import { Dictionary } from 'tsyringe/dist/typings/types';
|
import { Dictionary } from 'tsyringe/dist/typings/types';
|
||||||
@@ -44,8 +45,14 @@ export default class ARAgingSummarySheet extends AgingSummaryReport {
|
|||||||
this.baseCurrency = baseCurrency;
|
this.baseCurrency = baseCurrency;
|
||||||
this.numberFormat = this.query.numberFormat;
|
this.numberFormat = this.query.numberFormat;
|
||||||
|
|
||||||
this.overdueInvoicesByContactId = groupBy(overdueSaleInvoices, 'customerId');
|
this.overdueInvoicesByContactId = groupBy(
|
||||||
this.currentInvoicesByContactId = groupBy(currentSaleInvoices, 'customerId');
|
overdueSaleInvoices,
|
||||||
|
'customerId'
|
||||||
|
);
|
||||||
|
this.currentInvoicesByContactId = groupBy(
|
||||||
|
currentSaleInvoices,
|
||||||
|
'customerId'
|
||||||
|
);
|
||||||
|
|
||||||
// Initializes the aging periods.
|
// Initializes the aging periods.
|
||||||
this.agingPeriods = this.agingRangePeriods(
|
this.agingPeriods = this.agingRangePeriods(
|
||||||
@@ -68,7 +75,7 @@ export default class ARAgingSummarySheet extends AgingSummaryReport {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
customerName: customer.displayName,
|
customerName: customer.displayName,
|
||||||
current: this.formatTotalAmount(currentTotal),
|
current: this.formatAmount(currentTotal),
|
||||||
aging: agingPeriods,
|
aging: agingPeriods,
|
||||||
total: this.formatTotalAmount(amount),
|
total: this.formatTotalAmount(amount),
|
||||||
};
|
};
|
||||||
@@ -84,25 +91,41 @@ export default class ARAgingSummarySheet extends AgingSummaryReport {
|
|||||||
.map((customer) => this.customerData(customer))
|
.map((customer) => this.customerData(customer))
|
||||||
.filter(
|
.filter(
|
||||||
(customer: IARAgingSummaryCustomer) =>
|
(customer: IARAgingSummaryCustomer) =>
|
||||||
!(customer.total.total === 0 && this.query.noneZero)
|
!(customer.total.amount === 0 && this.query.noneZero)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the customers aging and current total.
|
||||||
|
* @param {IARAgingSummaryCustomer} customersAgingPeriods
|
||||||
|
*/
|
||||||
|
private getCustomersTotal(
|
||||||
|
customersAgingPeriods: IARAgingSummaryCustomer[]
|
||||||
|
): IARAgingSummaryTotal {
|
||||||
|
const totalAgingPeriods = this.getTotalAgingPeriods(customersAgingPeriods);
|
||||||
|
const totalCurrent = this.getTotalCurrent(customersAgingPeriods);
|
||||||
|
const totalCustomersTotal = this.getTotalContactsTotals(
|
||||||
|
customersAgingPeriods
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
current: this.formatTotalAmount(totalCurrent),
|
||||||
|
aging: totalAgingPeriods,
|
||||||
|
total: this.formatTotalAmount(totalCustomersTotal),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve A/R aging summary report data.
|
* Retrieve A/R aging summary report data.
|
||||||
* @return {IARAgingSummaryData}
|
* @return {IARAgingSummaryData}
|
||||||
*/
|
*/
|
||||||
public reportData(): IARAgingSummaryData {
|
public reportData(): IARAgingSummaryData {
|
||||||
const customersAgingPeriods = this.customersWalker(this.contacts);
|
const customersAgingPeriods = this.customersWalker(this.contacts);
|
||||||
const totalAgingPeriods = this.getTotalAgingPeriods(customersAgingPeriods);
|
const customersTotal = this.getCustomersTotal(customersAgingPeriods);
|
||||||
const totalCurrent = this.getTotalCurrent(customersAgingPeriods);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
customers: customersAgingPeriods,
|
customers: customersAgingPeriods,
|
||||||
total: {
|
total: customersTotal,
|
||||||
current: this.formatTotalAmount(totalCurrent),
|
|
||||||
aging: totalAgingPeriods,
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import {
|
|||||||
IARAgingSummaryCustomer,
|
IARAgingSummaryCustomer,
|
||||||
IContact,
|
IContact,
|
||||||
IARAgingSummaryQuery,
|
IARAgingSummaryQuery,
|
||||||
|
IFormatNumberSettings,
|
||||||
|
IAgingAmount,
|
||||||
|
IAgingSummaryContact
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import AgingReport from './AgingReport';
|
import AgingReport from './AgingReport';
|
||||||
import { Dictionary } from 'tsyringe/dist/typings/types';
|
import { Dictionary } from 'tsyringe/dist/typings/types';
|
||||||
@@ -24,58 +27,61 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setes initial aging periods to the given customer id.
|
* Setes initial aging periods to the contact.
|
||||||
* @param {number} customerId - Customer id.
|
|
||||||
*/
|
*/
|
||||||
protected getInitialAgingPeriodsTotal() {
|
protected getInitialAgingPeriodsTotal(): IAgingPeriodTotal[] {
|
||||||
return this.agingPeriods.map((agingPeriod) => ({
|
return this.agingPeriods.map((agingPeriod) => ({
|
||||||
...agingPeriod,
|
...agingPeriod,
|
||||||
...this.formatTotalAmount(0),
|
total: this.formatAmount(0),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the given contact aging periods.
|
* Calculates the given contact aging periods.
|
||||||
* @param {ICustomer} customer
|
* @param {number} contactId - Contact id.
|
||||||
* @return {(IAgingPeriod & IAgingPeriodTotal)[]}
|
* @return {IAgingPeriodTotal[]}
|
||||||
*/
|
*/
|
||||||
protected getContactAgingPeriods(
|
protected getContactAgingPeriods(contactId: number): IAgingPeriodTotal[] {
|
||||||
contactId: number
|
|
||||||
): (IAgingPeriod & IAgingPeriodTotal)[] {
|
|
||||||
const unpaidInvoices = this.getUnpaidInvoicesByContactId(contactId);
|
const unpaidInvoices = this.getUnpaidInvoicesByContactId(contactId);
|
||||||
const initialAgingPeriods = this.getInitialAgingPeriodsTotal();
|
const initialAgingPeriods = this.getInitialAgingPeriodsTotal();
|
||||||
|
|
||||||
return unpaidInvoices.reduce((agingPeriods, unpaidInvoice) => {
|
return unpaidInvoices.reduce(
|
||||||
|
(agingPeriods: IAgingPeriodTotal[], unpaidInvoice) => {
|
||||||
const newAgingPeriods = this.getContactAgingDueAmount(
|
const newAgingPeriods = this.getContactAgingDueAmount(
|
||||||
agingPeriods,
|
agingPeriods,
|
||||||
unpaidInvoice.dueAmount,
|
unpaidInvoice.dueAmount,
|
||||||
unpaidInvoice.getOverdueDays(this.query.asDate)
|
unpaidInvoice.getOverdueDays(this.query.asDate)
|
||||||
);
|
);
|
||||||
return newAgingPeriods;
|
return newAgingPeriods;
|
||||||
}, initialAgingPeriods);
|
},
|
||||||
|
initialAgingPeriods
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the customer aging due amount to the table. (Xx)
|
* Sets the contact aging due amount to the table.
|
||||||
* @param {number} customerId - Customer id.
|
* @param {IAgingPeriodTotal} agingPeriods - Aging periods.
|
||||||
* @param {number} dueAmount - Due amount.
|
* @param {number} dueAmount - Due amount.
|
||||||
* @param {number} overdueDays - Overdue days.
|
* @param {number} overdueDays - Overdue days.
|
||||||
|
* @return {IAgingPeriodTotal[]}
|
||||||
*/
|
*/
|
||||||
protected getContactAgingDueAmount(
|
protected getContactAgingDueAmount(
|
||||||
agingPeriods: any,
|
agingPeriods: IAgingPeriodTotal[],
|
||||||
dueAmount: number,
|
dueAmount: number,
|
||||||
overdueDays: number
|
overdueDays: number
|
||||||
): (IAgingPeriod & IAgingPeriodTotal)[] {
|
): IAgingPeriodTotal[] {
|
||||||
const newAgingPeriods = agingPeriods.map((agingPeriod) => {
|
const newAgingPeriods = agingPeriods.map((agingPeriod) => {
|
||||||
const isInAgingPeriod =
|
const isInAgingPeriod =
|
||||||
agingPeriod.beforeDays <= overdueDays &&
|
agingPeriod.beforeDays <= overdueDays &&
|
||||||
(agingPeriod.toDays > overdueDays || !agingPeriod.toDays);
|
(agingPeriod.toDays > overdueDays || !agingPeriod.toDays);
|
||||||
|
|
||||||
|
const total: number = isInAgingPeriod
|
||||||
|
? agingPeriod.total.amount + dueAmount
|
||||||
|
: agingPeriod.total.amount;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...agingPeriod,
|
...agingPeriod,
|
||||||
total: isInAgingPeriod
|
total: this.formatAmount(total),
|
||||||
? agingPeriod.total + dueAmount
|
|
||||||
: agingPeriod.total,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return newAgingPeriods;
|
return newAgingPeriods;
|
||||||
@@ -84,16 +90,37 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
/**
|
/**
|
||||||
* Retrieve the aging period total object.
|
* Retrieve the aging period total object.
|
||||||
* @param {number} amount
|
* @param {number} amount
|
||||||
* @return {IAgingPeriodTotal}
|
* @param {IFormatNumberSettings} settings - Override the format number settings.
|
||||||
|
* @return {IAgingAmount}
|
||||||
*/
|
*/
|
||||||
protected formatTotalAmount(amount: number): IAgingPeriodTotal {
|
protected formatAmount(
|
||||||
|
amount: number,
|
||||||
|
settings: IFormatNumberSettings = {}
|
||||||
|
): IAgingAmount {
|
||||||
return {
|
return {
|
||||||
total: amount,
|
amount,
|
||||||
formattedTotal: this.formatNumber(amount),
|
formattedAmount: this.formatNumber(amount, settings),
|
||||||
currencyCode: this.baseCurrency,
|
currencyCode: this.baseCurrency,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the aging period total object.
|
||||||
|
* @param {number} amount
|
||||||
|
* @param {IFormatNumberSettings} settings - Override the format number settings.
|
||||||
|
* @return {IAgingPeriodTotal}
|
||||||
|
*/
|
||||||
|
protected formatTotalAmount(
|
||||||
|
amount: number,
|
||||||
|
settings: IFormatNumberSettings = {}
|
||||||
|
): IAgingAmount {
|
||||||
|
return this.formatAmount(amount, {
|
||||||
|
money: true,
|
||||||
|
excerptZero: false,
|
||||||
|
...settings,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the total of the aging period by the given index.
|
* Calculates the total of the aging period by the given index.
|
||||||
* @param {number} index
|
* @param {number} index
|
||||||
@@ -101,9 +128,9 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
*/
|
*/
|
||||||
protected getTotalAgingPeriodByIndex(
|
protected getTotalAgingPeriodByIndex(
|
||||||
contactsAgingPeriods: any,
|
contactsAgingPeriods: any,
|
||||||
index: number
|
index: number,
|
||||||
): number {
|
): number {
|
||||||
return this.contacts.reduce((acc, customer) => {
|
return this.contacts.reduce((acc, contact) => {
|
||||||
const totalPeriod = contactsAgingPeriods[index]
|
const totalPeriod = contactsAgingPeriods[index]
|
||||||
? contactsAgingPeriods[index].total
|
? contactsAgingPeriods[index].total
|
||||||
: 0;
|
: 0;
|
||||||
@@ -113,9 +140,9 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the due invoices by the given customer id.
|
* Retrieve the due invoices by the given contact id.
|
||||||
* @param {number} customerId -
|
* @param {number} contactId -
|
||||||
* @return {ISaleInvoice[]}
|
* @return {(ISaleInvoice | IBill)[]}
|
||||||
*/
|
*/
|
||||||
protected getUnpaidInvoicesByContactId(
|
protected getUnpaidInvoicesByContactId(
|
||||||
contactId: number
|
contactId: number
|
||||||
@@ -129,20 +156,30 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
*/
|
*/
|
||||||
protected getTotalAgingPeriods(
|
protected getTotalAgingPeriods(
|
||||||
contactsAgingPeriods: IARAgingSummaryCustomer[]
|
contactsAgingPeriods: IARAgingSummaryCustomer[]
|
||||||
): (IAgingPeriodTotal & IAgingPeriod)[] {
|
): IAgingPeriodTotal[] {
|
||||||
return this.agingPeriods.map((agingPeriod, index) => {
|
return this.agingPeriods.map((agingPeriod, index) => {
|
||||||
const total = sumBy(contactsAgingPeriods, `aging[${index}].total`);
|
const total = sumBy(
|
||||||
|
contactsAgingPeriods,
|
||||||
|
(summary: IARAgingSummaryCustomer) => {
|
||||||
|
const aging = summary.aging[index];
|
||||||
|
|
||||||
|
if (!aging) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return aging.total.amount;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...agingPeriod,
|
...agingPeriod,
|
||||||
...this.formatTotalAmount(total),
|
total: this.formatTotalAmount(total),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current invoices by the given contact id.
|
* Retrieve the current invoices by the given contact id.
|
||||||
* @param {number} contactId
|
* @param {number} contactId - Specific contact id.
|
||||||
* @return {(ISaleInvoice | IBill)[]}
|
* @return {(ISaleInvoice | IBill)[]}
|
||||||
*/
|
*/
|
||||||
protected getCurrentInvoicesByContactId(
|
protected getCurrentInvoicesByContactId(
|
||||||
@@ -153,23 +190,23 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the contact total due amount.
|
* Retrieve the contact total due amount.
|
||||||
* @param {number} contactId
|
* @param {number} contactId - Specific contact id.
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
protected getContactCurrentTotal(contactId: number): number {
|
protected getContactCurrentTotal(contactId: number): number {
|
||||||
const currentInvoices = this.getCurrentInvoicesByContactId(contactId);
|
const currentInvoices = this.getCurrentInvoicesByContactId(contactId);
|
||||||
return sumBy(currentInvoices, invoice => invoice.dueAmount);
|
return sumBy(currentInvoices, (invoice) => invoice.dueAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve to total sumation of the given customers sections.
|
* Retrieve to total sumation of the given contacts summeries sections.
|
||||||
* @param {IARAgingSummaryCustomer[]} contactsSections -
|
* @param {IARAgingSummaryCustomer[]} contactsSections -
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
protected getTotalCurrent(
|
protected getTotalCurrent(
|
||||||
customersSummary: IARAgingSummaryCustomer[]
|
contactsSummaries: IAgingSummaryContact[]
|
||||||
): number {
|
): number {
|
||||||
return sumBy(customersSummary, summary => summary.current.total);
|
return sumBy(contactsSummaries, (summary) => summary.current.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,9 +214,17 @@ export default abstract class AgingSummaryReport extends AgingReport {
|
|||||||
* @param {IAgingPeriodTotal[]} agingPeriods
|
* @param {IAgingPeriodTotal[]} agingPeriods
|
||||||
* @return {number}
|
* @return {number}
|
||||||
*/
|
*/
|
||||||
protected getAgingPeriodsTotal(
|
protected getAgingPeriodsTotal(agingPeriods: IAgingPeriodTotal[]): number {
|
||||||
agingPeriods: IAgingPeriodTotal[],
|
return sumBy(agingPeriods, (period) => period.total.amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve total of contacts totals.
|
||||||
|
* @param {IAgingSummaryContact[]} contactsSummaries
|
||||||
|
*/
|
||||||
|
protected getTotalContactsTotals(
|
||||||
|
contactsSummaries: IAgingSummaryContact[]
|
||||||
): number {
|
): number {
|
||||||
return sumBy(agingPeriods, 'total');
|
return sumBy(contactsSummaries, (summary) => summary.total.amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
sections: IBalanceSheetSection[]
|
sections: IBalanceSheetSection[]
|
||||||
): IBalanceSheetAccountTotal {
|
): IBalanceSheetAccountTotal {
|
||||||
const amount = sumBy(sections, 'total.amount');
|
const amount = sumBy(sections, 'total.amount');
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { amount, formattedAmount, currencyCode };
|
return { amount, formattedAmount, currencyCode };
|
||||||
@@ -89,7 +89,25 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
): IBalanceSheetAccountTotal[] {
|
): IBalanceSheetAccountTotal[] {
|
||||||
return this.dateRangeSet.map((date, index) => {
|
return this.dateRangeSet.map((date, index) => {
|
||||||
const amount = sumBy(sections, `totalPeriods[${index}].amount`);
|
const amount = sumBy(sections, `totalPeriods[${index}].amount`);
|
||||||
const formattedAmount = this.formatNumber(amount);
|
|
||||||
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
|
return { date, amount, formattedAmount, currencyCode };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve accounts total periods.
|
||||||
|
* @param {Array<IBalanceSheetAccount>} accounts -
|
||||||
|
* @return {IBalanceSheetAccountTotal[]}
|
||||||
|
*/
|
||||||
|
private getAccountsTotalPeriods(
|
||||||
|
accounts: Array<IBalanceSheetAccount>
|
||||||
|
): IBalanceSheetAccountTotal[] {
|
||||||
|
return this.dateRangeSet.map((date, index) => {
|
||||||
|
const amount = sumBy(accounts, `totalPeriods[${index}].amount`);
|
||||||
|
const formattedAmount = this.formatNumber(amount)
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { date, amount, formattedAmount, currencyCode };
|
return { date, amount, formattedAmount, currencyCode };
|
||||||
@@ -190,12 +208,12 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
}),
|
}),
|
||||||
total: {
|
total: {
|
||||||
amount: totalAmount,
|
amount: totalAmount,
|
||||||
formattedAmount: this.formatNumber(totalAmount),
|
formattedAmount: this.formatTotalNumber(totalAmount),
|
||||||
currencyCode: this.baseCurrency,
|
currencyCode: this.baseCurrency,
|
||||||
},
|
},
|
||||||
...(this.query.displayColumnsType === 'date_periods'
|
...(this.query.displayColumnsType === 'date_periods'
|
||||||
? {
|
? {
|
||||||
totalPeriods: this.getSectionTotalPeriods(filteredAccounts),
|
totalPeriods: this.getAccountsTotalPeriods(filteredAccounts),
|
||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
};
|
};
|
||||||
@@ -232,7 +250,7 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private balanceSheetStructureMapper(
|
private balanceSheetStructureMapper(
|
||||||
structure: IBalanceSheetStructureSection,
|
structure: IBalanceSheetStructureSection,
|
||||||
accounts: IAccount & { type: IAccountType }[]
|
accounts: IAccount & { type: IAccountType }[],
|
||||||
): IBalanceSheetSection {
|
): IBalanceSheetSection {
|
||||||
const result = {
|
const result = {
|
||||||
name: structure.name,
|
name: structure.name,
|
||||||
@@ -276,14 +294,9 @@ export default class BalanceSheetStatement extends FinancialSheet {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
// Mappes the balance sheet scetions only
|
// Mappes the balance sheet scetions only
|
||||||
.map(
|
.map(([sheetSection]: [IBalanceSheetSection]) => {
|
||||||
([sheetSection, structure]: [
|
|
||||||
IBalanceSheetSection,
|
|
||||||
IBalanceSheetStructureSection
|
|
||||||
]) => {
|
|
||||||
return sheetSection;
|
return sheetSection;
|
||||||
}
|
})
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,11 @@ export default class BalanceSheetStatementService
|
|||||||
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'),
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: false,
|
precision: 2,
|
||||||
divideOn1000: false,
|
divideOn1000: false,
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
negativeFormat: 'mines'
|
||||||
},
|
},
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
noneTransactions: false,
|
noneTransactions: false,
|
||||||
|
|||||||
@@ -1,16 +1,56 @@
|
|||||||
import {
|
import { IFormatNumberSettings, INumberFormatQuery } from 'interfaces';
|
||||||
formatNumber
|
import { formatNumber } from 'utils';
|
||||||
} from 'utils';
|
|
||||||
|
|
||||||
export default class FinancialSheet {
|
export default class FinancialSheet {
|
||||||
numberFormat: { noCents: boolean, divideOn1000: boolean };
|
numberFormat: INumberFormatQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transformes the number format query to settings
|
||||||
|
*/
|
||||||
|
protected transfromFormatQueryToSettings(): IFormatNumberSettings {
|
||||||
|
const { numberFormat } = this;
|
||||||
|
|
||||||
|
return {
|
||||||
|
precision: numberFormat.precision,
|
||||||
|
divideOn1000: numberFormat.divideOn1000,
|
||||||
|
excerptZero: !numberFormat.showZero,
|
||||||
|
negativeFormat: numberFormat.negativeFormat,
|
||||||
|
money: numberFormat.formatMoney === 'always',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formating amount based on the given report query.
|
* Formating amount based on the given report query.
|
||||||
* @param {number} number
|
* @param {number} number -
|
||||||
|
* @param {IFormatNumberSettings} overrideSettings -
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
protected formatNumber(number): string {
|
protected formatNumber(
|
||||||
return formatNumber(number, this.numberFormat);
|
number,
|
||||||
|
overrideSettings: IFormatNumberSettings = {}
|
||||||
|
): string {
|
||||||
|
const settings = {
|
||||||
|
...this.transfromFormatQueryToSettings(),
|
||||||
|
...overrideSettings,
|
||||||
|
};
|
||||||
|
return formatNumber(number, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formatting full amount with different format settings.
|
||||||
|
* @param {number} amount -
|
||||||
|
* @param {IFormatNumberSettings} settings -
|
||||||
|
*/
|
||||||
|
protected formatTotalNumber(
|
||||||
|
amount: number,
|
||||||
|
settings: IFormatNumberSettings = {}
|
||||||
|
): string {
|
||||||
|
const { numberFormat } = this;
|
||||||
|
|
||||||
|
return this.formatNumber(amount, {
|
||||||
|
money: numberFormat.formatMoney === 'none' ? false : true,
|
||||||
|
excerptZero: false,
|
||||||
|
...settings
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,9 @@ import {
|
|||||||
IAccount,
|
IAccount,
|
||||||
IJournalPoster,
|
IJournalPoster,
|
||||||
IAccountType,
|
IAccountType,
|
||||||
IJournalEntry
|
IJournalEntry,
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import FinancialSheet from "../FinancialSheet";
|
import FinancialSheet from '../FinancialSheet';
|
||||||
|
|
||||||
export default class GeneralLedgerSheet extends FinancialSheet {
|
export default class GeneralLedgerSheet extends FinancialSheet {
|
||||||
tenantId: number;
|
tenantId: number;
|
||||||
@@ -35,7 +35,7 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
transactions: IJournalPoster,
|
transactions: IJournalPoster,
|
||||||
openingBalancesJournal: IJournalPoster,
|
openingBalancesJournal: IJournalPoster,
|
||||||
closingBalancesJournal: IJournalPoster,
|
closingBalancesJournal: IJournalPoster,
|
||||||
baseCurrency: string,
|
baseCurrency: string
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -59,7 +59,8 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
): IGeneralLedgerSheetAccountTransaction[] {
|
): IGeneralLedgerSheetAccountTransaction[] {
|
||||||
const entries = this.transactions.getAccountEntries(account.id);
|
const entries = this.transactions.getAccountEntries(account.id);
|
||||||
|
|
||||||
return entries.map((transaction: IJournalEntry): IGeneralLedgerSheetAccountTransaction => {
|
return entries.map(
|
||||||
|
(transaction: IJournalEntry): IGeneralLedgerSheetAccountTransaction => {
|
||||||
let amount = 0;
|
let amount = 0;
|
||||||
|
|
||||||
if (account.type.normal === 'credit') {
|
if (account.type.normal === 'credit') {
|
||||||
@@ -70,13 +71,21 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatNumber(amount);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...pick(transaction, ['id', 'note', 'transactionType', 'referenceType',
|
...pick(transaction, [
|
||||||
'referenceId', 'date']),
|
'id',
|
||||||
|
'note',
|
||||||
|
'transactionType',
|
||||||
|
'referenceType',
|
||||||
|
'referenceId',
|
||||||
|
'referenceTypeFormatted',
|
||||||
|
'date',
|
||||||
|
]),
|
||||||
amount,
|
amount,
|
||||||
formattedAmount,
|
formattedAmount,
|
||||||
currencyCode: this.baseCurrency,
|
currencyCode: this.baseCurrency,
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,9 +93,11 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
* @param {IAccount} account
|
* @param {IAccount} account
|
||||||
* @return {IGeneralLedgerSheetAccountBalance}
|
* @return {IGeneralLedgerSheetAccountBalance}
|
||||||
*/
|
*/
|
||||||
private accountOpeningBalance(account: IAccount): IGeneralLedgerSheetAccountBalance {
|
private accountOpeningBalance(
|
||||||
|
account: IAccount
|
||||||
|
): IGeneralLedgerSheetAccountBalance {
|
||||||
const amount = this.openingBalancesJournal.getAccountBalance(account.id);
|
const amount = this.openingBalancesJournal.getAccountBalance(account.id);
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
const date = this.query.fromDate;
|
const date = this.query.fromDate;
|
||||||
|
|
||||||
@@ -98,9 +109,11 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
* @param {IAccount} account
|
* @param {IAccount} account
|
||||||
* @return {IGeneralLedgerSheetAccountBalance}
|
* @return {IGeneralLedgerSheetAccountBalance}
|
||||||
*/
|
*/
|
||||||
private accountClosingBalance(account: IAccount): IGeneralLedgerSheetAccountBalance {
|
private accountClosingBalance(
|
||||||
|
account: IAccount
|
||||||
|
): IGeneralLedgerSheetAccountBalance {
|
||||||
const amount = this.closingBalancesJournal.getAccountBalance(account.id);
|
const amount = this.closingBalancesJournal.getAccountBalance(account.id);
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
const date = this.query.toDate;
|
const date = this.query.toDate;
|
||||||
|
|
||||||
@@ -113,14 +126,14 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
* @return {IGeneralLedgerSheetAccount}
|
* @return {IGeneralLedgerSheetAccount}
|
||||||
*/
|
*/
|
||||||
private accountMapper(
|
private accountMapper(
|
||||||
account: IAccount & { type: IAccountType },
|
account: IAccount & { type: IAccountType }
|
||||||
): IGeneralLedgerSheetAccount {
|
): IGeneralLedgerSheetAccount {
|
||||||
return {
|
return {
|
||||||
...pick(account, ['id', 'name', 'code', 'index', 'parentAccountId']),
|
...pick(account, ['id', 'name', 'code', 'index', 'parentAccountId']),
|
||||||
opening: this.accountOpeningBalance(account),
|
opening: this.accountOpeningBalance(account),
|
||||||
transactions: this.accountTransactionsMapper(account),
|
transactions: this.accountTransactionsMapper(account),
|
||||||
closing: this.accountClosingBalance(account),
|
closing: this.accountClosingBalance(account),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,13 +144,20 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
private accountsWalker(
|
private accountsWalker(
|
||||||
accounts: IAccount & { type: IAccountType }[]
|
accounts: IAccount & { type: IAccountType }[]
|
||||||
): IGeneralLedgerSheetAccount[] {
|
): IGeneralLedgerSheetAccount[] {
|
||||||
return accounts
|
return (
|
||||||
.map((account: IAccount & { type: IAccountType }) => this.accountMapper(account))
|
accounts
|
||||||
|
.map((account: IAccount & { type: IAccountType }) =>
|
||||||
|
this.accountMapper(account)
|
||||||
|
)
|
||||||
// Filter general ledger accounts that have no transactions when `noneTransactions` is on.
|
// Filter general ledger accounts that have no transactions when `noneTransactions` is on.
|
||||||
.filter((generalLedgerAccount: IGeneralLedgerSheetAccount) => (
|
.filter(
|
||||||
!(generalLedgerAccount.transactions.length === 0 && this.query.noneTransactions)
|
(generalLedgerAccount: IGeneralLedgerSheetAccount) =>
|
||||||
));
|
!(
|
||||||
|
generalLedgerAccount.transactions.length === 0 &&
|
||||||
|
this.query.noneTransactions
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -85,8 +85,7 @@ export default class GeneralLedgerService {
|
|||||||
group: 'organization',
|
group: 'organization',
|
||||||
key: 'base_currency',
|
key: 'base_currency',
|
||||||
});
|
});
|
||||||
|
// Retrieve all accounts with associated type from the storage.
|
||||||
// Retrieve all accounts from the storage.
|
|
||||||
const accounts = await accountRepository.all('type');
|
const accounts = await accountRepository.all('type');
|
||||||
const accountsGraph = await accountRepository.getDependencyGraph();
|
const accountsGraph = await accountRepository.getDependencyGraph();
|
||||||
|
|
||||||
@@ -111,11 +110,13 @@ export default class GeneralLedgerService {
|
|||||||
tenantId,
|
tenantId,
|
||||||
accountsGraph
|
accountsGraph
|
||||||
);
|
);
|
||||||
|
// Accounts opening transactions.
|
||||||
const openingTransJournal = Journal.fromTransactions(
|
const openingTransJournal = Journal.fromTransactions(
|
||||||
openingBalanceTrans,
|
openingBalanceTrans,
|
||||||
tenantId,
|
tenantId,
|
||||||
accountsGraph
|
accountsGraph
|
||||||
);
|
);
|
||||||
|
// Accounts closing transactions.
|
||||||
const closingTransJournal = Journal.fromTransactions(
|
const closingTransJournal = Journal.fromTransactions(
|
||||||
closingBalanceTrans,
|
closingBalanceTrans,
|
||||||
tenantId,
|
tenantId,
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ export default class JournalSheetService {
|
|||||||
group: 'organization',
|
group: 'organization',
|
||||||
key: 'base_currency',
|
key: 'base_currency',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Retrieve all accounts on the storage.
|
// Retrieve all accounts on the storage.
|
||||||
const accountsGraph = await accountRepository.getDependencyGraph();
|
const accountsGraph = await accountRepository.getDependencyGraph();
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
accounts: IProfitLossSheetAccount[]
|
accounts: IProfitLossSheetAccount[]
|
||||||
): IProfitLossSheetTotal {
|
): IProfitLossSheetTotal {
|
||||||
const amount = sumBy(accounts, 'total.amount');
|
const amount = sumBy(accounts, 'total.amount');
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { amount, formattedAmount, currencyCode };
|
return { amount, formattedAmount, currencyCode };
|
||||||
@@ -203,7 +203,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
): IProfitLossSheetTotal[] {
|
): IProfitLossSheetTotal[] {
|
||||||
return this.dateRangeSet.map((date, index) => {
|
return this.dateRangeSet.map((date, index) => {
|
||||||
const amount = sumBy(accounts, `totalPeriods[${index}].amount`);
|
const amount = sumBy(accounts, `totalPeriods[${index}].amount`);
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { amount, formattedAmount, currencyCode };
|
return { amount, formattedAmount, currencyCode };
|
||||||
@@ -229,7 +229,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private get incomeSection(): IProfitLossSheetAccountsSection {
|
private get incomeSection(): IProfitLossSheetAccountsSection {
|
||||||
return {
|
return {
|
||||||
sectionTitle: 'Income accounts',
|
name: 'Income accounts',
|
||||||
entryNormal: 'credit',
|
entryNormal: 'credit',
|
||||||
...this.sectionMapper(this.incomeAccounts),
|
...this.sectionMapper(this.incomeAccounts),
|
||||||
};
|
};
|
||||||
@@ -241,7 +241,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private get expensesSection(): IProfitLossSheetAccountsSection {
|
private get expensesSection(): IProfitLossSheetAccountsSection {
|
||||||
return {
|
return {
|
||||||
sectionTitle: 'Expense accounts',
|
name: 'Expense accounts',
|
||||||
entryNormal: 'debit',
|
entryNormal: 'debit',
|
||||||
...this.sectionMapper(this.expensesAccounts),
|
...this.sectionMapper(this.expensesAccounts),
|
||||||
};
|
};
|
||||||
@@ -253,7 +253,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private get otherExpensesSection(): IProfitLossSheetAccountsSection {
|
private get otherExpensesSection(): IProfitLossSheetAccountsSection {
|
||||||
return {
|
return {
|
||||||
sectionTitle: 'Other expenses accounts',
|
name: 'Other expenses accounts',
|
||||||
entryNormal: 'debit',
|
entryNormal: 'debit',
|
||||||
...this.sectionMapper(this.otherExpensesAccounts),
|
...this.sectionMapper(this.otherExpensesAccounts),
|
||||||
};
|
};
|
||||||
@@ -265,7 +265,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
*/
|
*/
|
||||||
private get costOfSalesSection(): IProfitLossSheetAccountsSection {
|
private get costOfSalesSection(): IProfitLossSheetAccountsSection {
|
||||||
return {
|
return {
|
||||||
sectionTitle: 'Cost of sales',
|
name: 'Cost of sales',
|
||||||
entryNormal: 'debit',
|
entryNormal: 'debit',
|
||||||
...this.sectionMapper(this.costOfSalesAccounts),
|
...this.sectionMapper(this.costOfSalesAccounts),
|
||||||
};
|
};
|
||||||
@@ -283,7 +283,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
const totalMines = sumBy(minesSections, `totalPeriods[${index}].amount`);
|
const totalMines = sumBy(minesSections, `totalPeriods[${index}].amount`);
|
||||||
|
|
||||||
const amount = totalPositive - totalMines;
|
const amount = totalPositive - totalMines;
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { date, amount, formattedAmount, currencyCode };
|
return { date, amount, formattedAmount, currencyCode };
|
||||||
@@ -298,7 +298,7 @@ export default class ProfitLossSheet extends FinancialSheet {
|
|||||||
const totalMinesSections = sumBy(minesSections, 'total.amount');
|
const totalMinesSections = sumBy(minesSections, 'total.amount');
|
||||||
|
|
||||||
const amount = totalPositiveSections - totalMinesSections;
|
const amount = totalPositiveSections - totalMinesSections;
|
||||||
const formattedAmount = this.formatNumber(amount);
|
const formattedAmount = this.formatTotalNumber(amount);
|
||||||
const currencyCode = this.baseCurrency;
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
return { amount, formattedAmount, currencyCode };
|
return { amount, formattedAmount, currencyCode };
|
||||||
|
|||||||
@@ -27,8 +27,11 @@ export default class ProfitLossSheetService {
|
|||||||
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'),
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: false,
|
|
||||||
divideOn1000: false,
|
divideOn1000: false,
|
||||||
|
negativeFormat: 'mines',
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
precision: 2,
|
||||||
},
|
},
|
||||||
basis: 'accural',
|
basis: 'accural',
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
@@ -55,16 +58,24 @@ export default class ProfitLossSheetService {
|
|||||||
...this.defaultQuery,
|
...this.defaultQuery,
|
||||||
...query,
|
...query,
|
||||||
};
|
};
|
||||||
this.logger.info('[profit_loss_sheet] trying to calculate the report.', { tenantId, filter });
|
this.logger.info('[profit_loss_sheet] trying to calculate the report.', {
|
||||||
|
tenantId,
|
||||||
|
filter,
|
||||||
|
});
|
||||||
|
|
||||||
// Get the given accounts or throw not found service error.
|
// Get the given accounts or throw not found service error.
|
||||||
if (filter.accountsIds.length > 0) {
|
if (filter.accountsIds.length > 0) {
|
||||||
await this.accountsService.getAccountsOrThrowError(tenantId, filter.accountsIds);
|
await this.accountsService.getAccountsOrThrowError(
|
||||||
|
tenantId,
|
||||||
|
filter.accountsIds
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// Settings tenant service.
|
// Settings tenant service.
|
||||||
const settings = this.tenancy.settings(tenantId);
|
const settings = this.tenancy.settings(tenantId);
|
||||||
const baseCurrency = settings.get({ group: 'organization', key: 'base_currency' });
|
const baseCurrency = settings.get({
|
||||||
|
group: 'organization',
|
||||||
|
key: 'base_currency',
|
||||||
|
});
|
||||||
// Retrieve all accounts on the storage.
|
// Retrieve all accounts on the storage.
|
||||||
const accounts = await accountRepository.all('type');
|
const accounts = await accountRepository.all('type');
|
||||||
const accountsGraph = await accountRepository.getDependencyGraph();
|
const accountsGraph = await accountRepository.getDependencyGraph();
|
||||||
@@ -75,8 +86,11 @@ export default class ProfitLossSheetService {
|
|||||||
toDate: query.toDate,
|
toDate: query.toDate,
|
||||||
});
|
});
|
||||||
// Transform transactions to journal collection.
|
// Transform transactions to journal collection.
|
||||||
const transactionsJournal = Journal.fromTransactions(transactions, tenantId, accountsGraph);
|
const transactionsJournal = Journal.fromTransactions(
|
||||||
|
transactions,
|
||||||
|
tenantId,
|
||||||
|
accountsGraph
|
||||||
|
);
|
||||||
// Profit/Loss report instance.
|
// Profit/Loss report instance.
|
||||||
const profitLossInstance = new ProfitLossSheet(
|
const profitLossInstance = new ProfitLossSheet(
|
||||||
tenantId,
|
tenantId,
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
|
import { sumBy } from 'lodash';
|
||||||
import {
|
import {
|
||||||
ITrialBalanceSheetQuery,
|
ITrialBalanceSheetQuery,
|
||||||
ITrialBalanceAccount,
|
ITrialBalanceAccount,
|
||||||
IAccount,
|
IAccount,
|
||||||
|
ITrialBalanceTotal,
|
||||||
IAccountType,
|
IAccountType,
|
||||||
} from 'interfaces';
|
} from 'interfaces';
|
||||||
import FinancialSheet from '../FinancialSheet';
|
import FinancialSheet from '../FinancialSheet';
|
||||||
import { flatToNestedArray } from 'utils';
|
import { flatToNestedArray } from 'utils';
|
||||||
|
|
||||||
|
const AMOUNT_TYPE = {
|
||||||
|
TOTAL: 'TOTAL',
|
||||||
|
SECTION_TOTAL: 'SECTION_TOTAL',
|
||||||
|
};
|
||||||
|
|
||||||
export default class TrialBalanceSheet extends FinancialSheet {
|
export default class TrialBalanceSheet extends FinancialSheet {
|
||||||
tenantId: number;
|
tenantId: number;
|
||||||
query: ITrialBalanceSheetQuery;
|
query: ITrialBalanceSheetQuery;
|
||||||
@@ -103,10 +110,37 @@ export default class TrialBalanceSheet extends FinancialSheet {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve trial balance total section.
|
||||||
|
* @param {ITrialBalanceAccount[]} accountsBalances
|
||||||
|
* @return {ITrialBalanceTotal}
|
||||||
|
*/
|
||||||
|
private tatalSection(
|
||||||
|
accountsBalances: ITrialBalanceAccount[]
|
||||||
|
): ITrialBalanceTotal {
|
||||||
|
const credit = sumBy(accountsBalances, 'credit');
|
||||||
|
const debit = sumBy(accountsBalances, 'debit');
|
||||||
|
const balance = sumBy(accountsBalances, 'balance');
|
||||||
|
const currencyCode = this.baseCurrency;
|
||||||
|
|
||||||
|
return {
|
||||||
|
credit,
|
||||||
|
debit,
|
||||||
|
balance,
|
||||||
|
currencyCode,
|
||||||
|
formattedCredit: this.formatTotalNumber(credit),
|
||||||
|
formattedDebit: this.formatTotalNumber(debit),
|
||||||
|
formattedBalance: this.formatTotalNumber(balance),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve trial balance sheet statement data.
|
* Retrieve trial balance sheet statement data.
|
||||||
*/
|
*/
|
||||||
public reportData() {
|
public reportData() {
|
||||||
return this.accountsWalker(this.accounts);
|
const accounts = this.accountsWalker(this.accounts);
|
||||||
|
const total = this.tatalSection(accounts);
|
||||||
|
|
||||||
|
return { accounts, total };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import TenancyService from 'services/Tenancy/TenancyService';
|
import TenancyService from 'services/Tenancy/TenancyService';
|
||||||
import { ITrialBalanceSheetQuery, ITrialBalanceStatement } from 'interfaces';
|
|
||||||
import TrialBalanceSheet from './TrialBalanceSheet';
|
|
||||||
import Journal from 'services/Accounting/JournalPoster';
|
import Journal from 'services/Accounting/JournalPoster';
|
||||||
|
import { INumberFormatQuery, ITrialBalanceSheetQuery, ITrialBalanceStatement } from 'interfaces';
|
||||||
|
import TrialBalanceSheet from './TrialBalanceSheet';
|
||||||
|
import FinancialSheet from '../FinancialSheet';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class TrialBalanceSheetService {
|
export default class TrialBalanceSheetService extends FinancialSheet {
|
||||||
@Inject()
|
@Inject()
|
||||||
tenancy: TenancyService;
|
tenancy: TenancyService;
|
||||||
|
|
||||||
@@ -22,8 +23,11 @@ export default class TrialBalanceSheetService {
|
|||||||
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'),
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: false,
|
|
||||||
divideOn1000: false,
|
divideOn1000: false,
|
||||||
|
negativeFormat: 'mines',
|
||||||
|
showZero: false,
|
||||||
|
formatMoney: 'total',
|
||||||
|
precision: 2,
|
||||||
},
|
},
|
||||||
basis: 'accural',
|
basis: 'accural',
|
||||||
noneZero: false,
|
noneZero: false,
|
||||||
@@ -42,7 +46,7 @@ export default class TrialBalanceSheetService {
|
|||||||
*/
|
*/
|
||||||
public async trialBalanceSheet(
|
public async trialBalanceSheet(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
query: ITrialBalanceSheetQuery
|
query: ITrialBalanceSheetQuery,
|
||||||
): Promise<ITrialBalanceStatement> {
|
): Promise<ITrialBalanceStatement> {
|
||||||
const filter = {
|
const filter = {
|
||||||
...this.defaultQuery,
|
...this.defaultQuery,
|
||||||
|
|||||||
@@ -239,9 +239,7 @@ export default class InventoryAdjustmentService {
|
|||||||
inventoryAdjustmentId,
|
inventoryAdjustmentId,
|
||||||
});
|
});
|
||||||
// Publish the inventory adjustment transaction.
|
// Publish the inventory adjustment transaction.
|
||||||
await InventoryAdjustment.query()
|
await InventoryAdjustment.query().findById(inventoryAdjustmentId).patch({
|
||||||
.findById(inventoryAdjustmentId)
|
|
||||||
.patch({
|
|
||||||
publishedAt: moment().toMySqlDateTime(),
|
publishedAt: moment().toMySqlDateTime(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from 'bcryptjs';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import accounting from 'accounting';
|
||||||
import definedOptions from 'data/options';
|
import definedOptions from 'data/options';
|
||||||
|
|
||||||
const hashPassword = (password) =>
|
const hashPassword = (password) =>
|
||||||
@@ -192,7 +193,7 @@ const entriesAmountDiff = (
|
|||||||
.groupBy(idAttribute)
|
.groupBy(idAttribute)
|
||||||
.mapValues((group) => _.sumBy(group, amountAttribute) || 0)
|
.mapValues((group) => _.sumBy(group, amountAttribute) || 0)
|
||||||
.mergeWith(oldEntriesTable, (objValue, srcValue) => {
|
.mergeWith(oldEntriesTable, (objValue, srcValue) => {
|
||||||
return (_.isNumber(objValue) ? objValue - srcValue : srcValue * -1);
|
return _.isNumber(objValue) ? objValue - srcValue : srcValue * -1;
|
||||||
})
|
})
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
@@ -214,27 +215,56 @@ const convertEmptyStringToNull = (value) => {
|
|||||||
: value;
|
: value;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatNumber = (balance, { noCents = false, divideOn1000 = false }) => {
|
const getNegativeFormat = (formatName) => {
|
||||||
|
switch (formatName) {
|
||||||
|
case 'parentheses':
|
||||||
|
return '(%s%v)';
|
||||||
|
case 'mines':
|
||||||
|
return '-%s%v';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatNumber = (
|
||||||
|
balance,
|
||||||
|
{
|
||||||
|
precision = 2,
|
||||||
|
divideOn1000 = false,
|
||||||
|
excerptZero = false,
|
||||||
|
negativeFormat = 'mines',
|
||||||
|
thousand = ',',
|
||||||
|
decimal = '.',
|
||||||
|
zeroSign = '',
|
||||||
|
symbol = '$',
|
||||||
|
money = true,
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
const negForamt = getNegativeFormat(negativeFormat);
|
||||||
|
const format = '%s%v';
|
||||||
|
|
||||||
let formattedBalance = parseFloat(balance);
|
let formattedBalance = parseFloat(balance);
|
||||||
|
|
||||||
if (noCents) {
|
|
||||||
formattedBalance = parseInt(formattedBalance, 10);
|
|
||||||
}
|
|
||||||
if (divideOn1000) {
|
if (divideOn1000) {
|
||||||
formattedBalance /= 1000;
|
formattedBalance /= 1000;
|
||||||
}
|
}
|
||||||
return formattedBalance + '';
|
return accounting.formatMoney(
|
||||||
|
formattedBalance,
|
||||||
|
money ? symbol : '',
|
||||||
|
precision,
|
||||||
|
thousand,
|
||||||
|
decimal,
|
||||||
|
{
|
||||||
|
pos: format,
|
||||||
|
neg: negForamt,
|
||||||
|
zero: excerptZero ? zeroSign : format,
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isBlank = (value) => {
|
const isBlank = (value) => {
|
||||||
return _.isEmpty(value) && !_.isNumber(value) || _.isNaN(value);
|
return (_.isEmpty(value) && !_.isNumber(value)) || _.isNaN(value);
|
||||||
}
|
};
|
||||||
|
|
||||||
function defaultToTransform(
|
function defaultToTransform(value, defaultOrTransformedValue, defaultValue) {
|
||||||
value,
|
|
||||||
defaultOrTransformedValue,
|
|
||||||
defaultValue,
|
|
||||||
) {
|
|
||||||
const _defaultValue =
|
const _defaultValue =
|
||||||
typeof defaultValue === 'undefined'
|
typeof defaultValue === 'undefined'
|
||||||
? defaultOrTransformedValue
|
? defaultOrTransformedValue
|
||||||
@@ -248,7 +278,6 @@ function defaultToTransform(
|
|||||||
: _transfromedValue;
|
: _transfromedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
hashPassword,
|
hashPassword,
|
||||||
origin,
|
origin,
|
||||||
|
|||||||
Reference in New Issue
Block a user