mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
refactor: financial reports to nestjs
This commit is contained in:
@@ -18,8 +18,8 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
|
||||
/**
|
||||
* Calculates the contact percentage of column.
|
||||
* @param {number} customerBalance - Contact balance.
|
||||
* @param {number} totalBalance - Total contacts balance.
|
||||
* @param {number} customerBalance - Contact balance.
|
||||
* @param {number} totalBalance - Total contacts balance.
|
||||
* @returns {number}
|
||||
*/
|
||||
protected getContactPercentageOfColumn = (
|
||||
@@ -56,7 +56,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
|
||||
/**
|
||||
* Retrieve the contacts total section.
|
||||
* @param {IContactBalanceSummaryContact[]} contacts
|
||||
* @param {IContactBalanceSummaryContact[]} contacts
|
||||
* @returns {IContactBalanceSummaryTotal}
|
||||
*/
|
||||
protected getContactsTotalSection = (
|
||||
@@ -66,6 +66,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
const node = {
|
||||
total: this.getTotalFormat(customersTotal),
|
||||
};
|
||||
// @ts-ignore
|
||||
return R.compose(
|
||||
R.when(
|
||||
R.always(this.filter.percentageColumn),
|
||||
@@ -76,8 +77,8 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
|
||||
/**
|
||||
* Retrieve the contact summary section with percentage of column.
|
||||
* @param {number} total
|
||||
* @param {IContactBalanceSummaryContact} contact
|
||||
* @param {number} total
|
||||
* @param {IContactBalanceSummaryContact} contact
|
||||
* @returns {IContactBalanceSummaryContact}
|
||||
*/
|
||||
private contactCamparsionPercentageOfColumnMapper = (
|
||||
@@ -107,6 +108,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
this.contactCamparsionPercentageOfColumnMapper
|
||||
)(customersTotal);
|
||||
|
||||
// @ts-ignore
|
||||
return contacts.map(camparsionPercentageOfColummn);
|
||||
};
|
||||
|
||||
@@ -127,7 +129,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
|
||||
/**
|
||||
* Retrieve the total amount of contacts sections.
|
||||
* @param {number} amount
|
||||
* @param {number} amount
|
||||
* @returns {IContactBalanceSummaryAmount}
|
||||
*/
|
||||
protected getTotalFormat = (amount: number): IContactBalanceSummaryAmount => {
|
||||
@@ -140,7 +142,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
|
||||
/**
|
||||
* Retrieve the percentage amount object.
|
||||
* @param {number} amount
|
||||
* @param {number} amount
|
||||
* @returns {IContactBalanceSummaryPercentage}
|
||||
*/
|
||||
protected getPercentageMeta = (
|
||||
@@ -154,7 +156,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
|
||||
/**
|
||||
* Filters customer has none transactions.
|
||||
* @param {ICustomerBalanceSummaryCustomer} customer -
|
||||
* @param {ICustomerBalanceSummaryCustomer} customer - Customer total node.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private filterContactNoneTransactions = (
|
||||
@@ -167,7 +169,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
|
||||
/**
|
||||
* Filters the customer that has zero total amount.
|
||||
* @param {ICustomerBalanceSummaryCustomer} customer
|
||||
* @param {ICustomerBalanceSummaryCustomer} customer - Customer total node.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private filterContactNoneZero = (
|
||||
@@ -178,7 +180,7 @@ export class ContactBalanceSummaryReport extends FinancialSheet {
|
||||
|
||||
/**
|
||||
* Filters the given customer node;
|
||||
* @param {ICustomerBalanceSummaryCustomer} customer
|
||||
* @param {ICustomerBalanceSummaryCustomer} customer - Customer total node.
|
||||
*/
|
||||
private contactNodeFilter = (contact: IContactBalanceSummaryContact) => {
|
||||
const { noneTransactions, noneZero } = this.filter;
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface IContactBalanceSummaryPercentage {
|
||||
}
|
||||
|
||||
export interface IContactBalanceSummaryContact {
|
||||
id: number;
|
||||
total: IContactBalanceSummaryAmount;
|
||||
percentageOfColumn?: IContactBalanceSummaryPercentage;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ export class CustomerBalanceSummaryReport extends ContactBalanceSummaryReport {
|
||||
private getCustomersSection = (
|
||||
customers: ModelObject<Customer>[]
|
||||
): ICustomerBalanceSummaryCustomer[] => {
|
||||
// @ts-ignore
|
||||
return R.compose(
|
||||
R.when(this.isCustomersPostFilter, this.contactsFilter),
|
||||
R.when(
|
||||
|
||||
@@ -35,6 +35,7 @@ export class CustomerBalanceSummaryService {
|
||||
await this.reportRepository.getCustomersTransactions(asDate);
|
||||
const commonProps = { accountNormal: 'debit', date: asDate };
|
||||
|
||||
// @ts-ignore
|
||||
return R.map(R.merge(commonProps))(transactions);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ export class CustomerBalanceSummaryTable {
|
||||
{ key: 'name', value: this.i18n.t('Total') },
|
||||
{ key: 'total', accessor: 'total.formattedAmount' },
|
||||
];
|
||||
// @ts-ignore
|
||||
return R.compose(
|
||||
R.concat(columns),
|
||||
R.when(
|
||||
@@ -142,6 +143,7 @@ export class CustomerBalanceSummaryTable {
|
||||
},
|
||||
{ key: 'total', label: this.i18n.t('contact_summary_balance.total') },
|
||||
];
|
||||
// @ts-ignore
|
||||
return R.compose(
|
||||
R.when(
|
||||
R.always(this.query.percentageColumn),
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
IGeneralLedgerSheetAccount,
|
||||
IGeneralLedgerSheetAccountBalance,
|
||||
IGeneralLedgerSheetAccountTransaction,
|
||||
IGeneralLedgerNumberFormat,
|
||||
} from './GeneralLedger.types';
|
||||
import { GeneralLedgerRepository } from './GeneralLedgerRepository';
|
||||
import { calculateRunningBalance } from './_utils';
|
||||
@@ -43,7 +44,7 @@ export class GeneralLedgerSheet extends R.compose(FinancialSheetStructure)(
|
||||
this.query = query;
|
||||
this.numberFormat = this.query.numberFormat;
|
||||
this.repository = repository;
|
||||
this.baseCurrency = this.repository.tenant.metadata.currencyCode;
|
||||
this.baseCurrency = this.repository.tenant.metadata.baseCurrency;
|
||||
this.i18n = i18n;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { IFinancialSheetCommonMeta } from "../../types/Report.types";
|
||||
import { IFinancialSheetCommonMeta, INumberFormatQuery } from "../../types/Report.types";
|
||||
import { IFinancialTable } from "../../types/Table.types";
|
||||
|
||||
export interface IGeneralLedgerSheetQuery {
|
||||
fromDate: Date | string;
|
||||
toDate: Date | string;
|
||||
basis: string;
|
||||
numberFormat: {
|
||||
noCents: boolean;
|
||||
divideOn1000: boolean;
|
||||
};
|
||||
numberFormat: IGeneralLedgerNumberFormat;
|
||||
noneTransactions: boolean;
|
||||
accountsIds: number[];
|
||||
branchesIds?: number[];
|
||||
}
|
||||
|
||||
export interface IGeneralLedgerNumberFormat extends INumberFormatQuery{
|
||||
}
|
||||
|
||||
export interface IGeneralLedgerSheetAccountTransaction {
|
||||
id: number;
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ export class GeneralLedgerRepository {
|
||||
* Initialize the accounts.
|
||||
*/
|
||||
public async initAccounts() {
|
||||
// @ts-ignore
|
||||
this.accounts = await this.accountRepository
|
||||
.all()
|
||||
.orderBy('name', 'ASC');
|
||||
@@ -170,7 +171,7 @@ export class GeneralLedgerRepository {
|
||||
|
||||
return R.concat(childrenIds, parentIds);
|
||||
});
|
||||
|
||||
// @ts-ignore\
|
||||
this.accountNodeInclude = R.compose(
|
||||
R.uniq,
|
||||
R.flatten,
|
||||
|
||||
@@ -168,7 +168,8 @@ export class GeneralLedgerTable extends R.compose(
|
||||
|
||||
/**
|
||||
* Maps the given transaction node to table row.
|
||||
* @param {IGeneralLedgerSheetAccountTransaction} transaction
|
||||
* @param {IGeneralLedgerSheetAccount} account - Account.
|
||||
* @param {IGeneralLedgerSheetAccountTransaction} transaction - Transaction.
|
||||
* @returns {ITableRow}
|
||||
*/
|
||||
private transactionMapper = R.curry(
|
||||
@@ -195,6 +196,7 @@ export class GeneralLedgerTable extends R.compose(
|
||||
): ITableRow[] => {
|
||||
const transactionMapper = this.transactionMapper(account);
|
||||
|
||||
// @ts-ignore
|
||||
return R.map(transactionMapper)(account.transactions);
|
||||
};
|
||||
|
||||
@@ -279,6 +281,7 @@ export class GeneralLedgerTable extends R.compose(
|
||||
const isAppendClosingSubaccounts = () =>
|
||||
account.children?.length > 0 && !!account.closingBalanceSubaccounts;
|
||||
|
||||
// @ts-ignore
|
||||
const children = R.compose(
|
||||
R.when(
|
||||
isAppendClosingSubaccounts,
|
||||
|
||||
@@ -12,7 +12,7 @@ export class GeneralLedgerTableInjectable {
|
||||
|
||||
/**
|
||||
* Retrieves the G/L table.
|
||||
* @param {IGeneralLedgerSheetQuery} query
|
||||
* @param {IGeneralLedgerSheetQuery} query - general ledger query.
|
||||
* @returns {Promise<IGeneralLedgerTableData>}
|
||||
*/
|
||||
public async table(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as R from 'ramda';
|
||||
import {
|
||||
ISalesByItemsItem,
|
||||
ISalesByItemsSheetData,
|
||||
ISalesByItemsTotal,
|
||||
} from './SalesByItems.types';
|
||||
import { ROW_TYPE } from './constants';
|
||||
@@ -14,13 +15,13 @@ export class SalesByItemsTable extends R.compose(
|
||||
FinancialTable,
|
||||
FinancialSheetStructure
|
||||
)(FinancialSheet) {
|
||||
private readonly data: ISalesByItemsSheetStatement;
|
||||
private readonly data: ISalesByItemsSheetData;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {ISalesByItemsSheetStatement} data
|
||||
*/
|
||||
constructor(data: ISalesByItemsSheetStatement) {
|
||||
constructor(data: ISalesByItemsSheetData) {
|
||||
super();
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user