mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
feat: export reports csv and xlsx (#286)
This commit is contained in:
@@ -139,11 +139,4 @@ export default class TransactionsByCustomers extends TransactionsByContact {
|
||||
public reportData(): ITransactionsByCustomersData {
|
||||
return this.customersMapper(this.customers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the report columns.
|
||||
*/
|
||||
public reportColumns() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
ITransactionsByCustomersFilter,
|
||||
ITransactionsByCustomersStatement,
|
||||
} from '@/interfaces';
|
||||
import { TransactionsByCustomersTableInjectable } from './TransactionsByCustomersTableInjectable';
|
||||
import { TransactionsByCustomersExportInjectable } from './TransactionsByCustomersExportInjectable';
|
||||
import { TransactionsByCustomersSheet } from './TransactionsByCustomersService';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByCustomerApplication {
|
||||
@Inject()
|
||||
private transactionsByCustomersTable: TransactionsByCustomersTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private transactionsByCustomersExport: TransactionsByCustomersExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private transactionsByCustomersSheet: TransactionsByCustomersSheet;
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by customers sheet in json format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<ITransactionsByCustomersStatement>}
|
||||
*/
|
||||
public sheet(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<ITransactionsByCustomersStatement> {
|
||||
return this.transactionsByCustomersSheet.transactionsByCustomers(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendors sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<ITransactionsByCustomersTable>}
|
||||
*/
|
||||
public table(tenantId: number, query: ITransactionsByCustomersFilter) {
|
||||
return this.transactionsByCustomersTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendors sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public csv(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<string> {
|
||||
return this.transactionsByCustomersExport.csv(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendors sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<Buffer> {
|
||||
return this.transactionsByCustomersExport.xlsx(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ITransactionsByCustomersFilter } from '@/interfaces';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { TransactionsByCustomersTableInjectable } from './TransactionsByCustomersTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByCustomersExportInjectable {
|
||||
@Inject()
|
||||
private transactionsByCustomerTable: TransactionsByCustomersTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<Buffer> {
|
||||
const table = await this.transactionsByCustomerTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: ITransactionsByCustomersFilter
|
||||
): Promise<string> {
|
||||
const table = await this.transactionsByCustomerTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Inject } from 'typedi';
|
||||
import { isEmpty, map } from 'lodash';
|
||||
import { IAccount, IAccountTransaction } from '@/interfaces';
|
||||
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Inject } from 'typedi';
|
||||
|
||||
export default class TransactionsByCustomersRepository {
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieve the report customers.
|
||||
* @param {number} tenantId
|
||||
* @param {number} tenantId
|
||||
* @returns {Promise<ICustomer[]>}
|
||||
*/
|
||||
public async getCustomers(tenantId: number, customersIds?: number[]) {
|
||||
|
||||
@@ -13,23 +13,20 @@ import Ledger from '@/services/Accounting/Ledger';
|
||||
import TransactionsByCustomersRepository from './TransactionsByCustomersRepository';
|
||||
import { Tenant } from '@/system/models';
|
||||
|
||||
export default class TransactionsByCustomersService
|
||||
export class TransactionsByCustomersSheet
|
||||
implements ITransactionsByCustomersService
|
||||
{
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
private tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
reportRepository: TransactionsByCustomersRepository;
|
||||
private reportRepository: TransactionsByCustomersRepository;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
* @return {ICustomerBalanceSummaryQuery}
|
||||
*/
|
||||
get defaultQuery(): ITransactionsByCustomersFilter {
|
||||
private get defaultQuery(): ITransactionsByCustomersFilter {
|
||||
return {
|
||||
fromDate: moment().startOf('month').format('YYYY-MM-DD'),
|
||||
toDate: moment().format('YYYY-MM-DD'),
|
||||
@@ -165,7 +162,6 @@ export default class TransactionsByCustomersService
|
||||
|
||||
return {
|
||||
data: reportInstance.reportData(),
|
||||
columns: reportInstance.reportColumns(),
|
||||
query: filter,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as R from 'ramda';
|
||||
import { tableRowMapper, tableMapper } from 'utils';
|
||||
import { ITransactionsByCustomersCustomer, ITableRow } from '@/interfaces';
|
||||
import { tableRowMapper } from 'utils';
|
||||
import { ITransactionsByCustomersCustomer, ITableRow, ITableColumn } from '@/interfaces';
|
||||
import TransactionsByContactsTableRows from '../TransactionsByContact/TransactionsByContactTableRows';
|
||||
|
||||
enum ROW_TYPE {
|
||||
@@ -10,17 +10,14 @@ enum ROW_TYPE {
|
||||
CUSTOMER = 'CUSTOMER',
|
||||
}
|
||||
|
||||
export default class TransactionsByCustomersTableRows extends TransactionsByContactsTableRows {
|
||||
export class TransactionsByCustomersTable extends TransactionsByContactsTableRows {
|
||||
private customersTransactions: ITransactionsByCustomersCustomer[];
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {ITransactionsByCustomersCustomer[]} customersTransactions - Customers transactions.
|
||||
*/
|
||||
constructor(
|
||||
customersTransactions: ITransactionsByCustomersCustomer[],
|
||||
i18n
|
||||
) {
|
||||
constructor(customersTransactions: ITransactionsByCustomersCustomer[], i18n) {
|
||||
super();
|
||||
this.customersTransactions = customersTransactions;
|
||||
this.i18n = i18n;
|
||||
@@ -75,4 +72,12 @@ export default class TransactionsByCustomersTableRows extends TransactionsByCont
|
||||
this.customersTransactions
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the table columns of transactions by customers report.
|
||||
* @returns {ITableColumn[]}
|
||||
*/
|
||||
public tableColumns = (): ITableColumn[] => {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ITransactionsByCustomersFilter, ITransactionsByCustomersTable } from '@/interfaces';
|
||||
import { TransactionsByCustomersSheet } from './TransactionsByCustomersService';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { TransactionsByCustomersTable } from './TransactionsByCustomersTable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByCustomersTableInjectable {
|
||||
@Inject()
|
||||
private transactionsByCustomerService: TransactionsByCustomersSheet;
|
||||
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by customers sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByCustomersFilter} filter
|
||||
* @returns {Promise<ITransactionsByCustomersFilter>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
filter: ITransactionsByCustomersFilter
|
||||
): Promise<ITransactionsByCustomersTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const customersTransactions =
|
||||
await this.transactionsByCustomerService.transactionsByCustomers(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const table = new TransactionsByCustomersTable(
|
||||
customersTransactions.data,
|
||||
i18n
|
||||
);
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query: customersTransactions.query,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user