mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
feat: export reports csv and xlsx (#286)
This commit is contained in:
@@ -137,11 +137,4 @@ export default class TransactionsByVendors extends TransactionsByContact {
|
||||
public reportData(): ITransactionsByVendorsData {
|
||||
return this.vendorsMapper(this.contacts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the report columns.
|
||||
*/
|
||||
public reportColumns() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import {
|
||||
ITransactionsByVendorTable,
|
||||
ITransactionsByVendorsFilter,
|
||||
ITransactionsByVendorsStatement,
|
||||
} from '@/interfaces';
|
||||
import { TransactionsByVendorExportInjectable } from './TransactionsByVendorExportInjectable';
|
||||
import { TransactionsByVendorTableInjectable } from './TransactionsByVendorTableInjectable';
|
||||
import { TransactionsByVendorsInjectable } from './TransactionsByVendorInjectable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByVendorApplication {
|
||||
@Inject()
|
||||
private transactionsByVendorTable: TransactionsByVendorTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private transactionsByVendorExport: TransactionsByVendorExportInjectable;
|
||||
|
||||
@Inject()
|
||||
private transactionsByVendorSheet: TransactionsByVendorsInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in sheet format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
* @returns {Promise<ITransactionsByVendorsStatement>}
|
||||
*/
|
||||
public sheet(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<ITransactionsByVendorsStatement> {
|
||||
return this.transactionsByVendorSheet.transactionsByVendors(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
* @returns {Promise<ITransactionsByVendorTable>}
|
||||
*/
|
||||
public table(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<ITransactionsByVendorTable> {
|
||||
return this.transactionsByVendorTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public csv(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<string> {
|
||||
return this.transactionsByVendorExport.csv(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
*/
|
||||
public xlsx(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<Buffer> {
|
||||
return this.transactionsByVendorExport.xlsx(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ITransactionsByVendorsFilter } from '@/interfaces';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
import { TransactionsByVendorTableInjectable } from './TransactionsByVendorTableInjectable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByVendorExportInjectable {
|
||||
@Inject()
|
||||
private transactionsByVendorTable: TransactionsByVendorTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the cashflow sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByVendorsFilter} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<Buffer> {
|
||||
const table = await this.transactionsByVendorTable.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 {ICashFlowStatementQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<string> {
|
||||
const table = await this.transactionsByVendorTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Inject } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import * as R from 'ramda';
|
||||
import { map } from 'lodash';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import {
|
||||
ITransactionsByVendorsService,
|
||||
@@ -14,17 +13,14 @@ import Ledger from '@/services/Accounting/Ledger';
|
||||
import TransactionsByVendorRepository from './TransactionsByVendorRepository';
|
||||
import { Tenant } from '@/system/models';
|
||||
|
||||
export default class TransactionsByVendorsService
|
||||
export class TransactionsByVendorsInjectable
|
||||
implements ITransactionsByVendorsService
|
||||
{
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
private tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
reportRepository: TransactionsByVendorRepository;
|
||||
private reportRepository: TransactionsByVendorRepository;
|
||||
|
||||
/**
|
||||
* Defaults balance sheet filter query.
|
||||
@@ -136,7 +132,7 @@ export default class TransactionsByVendorsService
|
||||
const { accountRepository } = this.tenancy.repositories(tenantId);
|
||||
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
|
||||
const tenant = await Tenant.query()
|
||||
.findById(tenantId)
|
||||
.withGraphFetched('metadata');
|
||||
@@ -171,7 +167,6 @@ export default class TransactionsByVendorsService
|
||||
);
|
||||
return {
|
||||
data: reportInstance.reportData(),
|
||||
columns: reportInstance.reportColumns(),
|
||||
query: filter,
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
import * as R from 'ramda';
|
||||
import { tableRowMapper } from 'utils';
|
||||
import { ITransactionsByVendorsVendor, ITableRow } from '@/interfaces';
|
||||
import {
|
||||
ITransactionsByVendorsVendor,
|
||||
ITableRow,
|
||||
ITableColumn,
|
||||
} from '@/interfaces';
|
||||
import TransactionsByContactsTableRows from '../TransactionsByContact/TransactionsByContactTableRows';
|
||||
|
||||
enum ROW_TYPE {
|
||||
@@ -10,16 +14,15 @@ enum ROW_TYPE {
|
||||
VENDOR = 'VENDOR',
|
||||
}
|
||||
|
||||
export default class TransactionsByVendorsTableRows extends TransactionsByContactsTableRows {
|
||||
vendorsTransactions: ITransactionsByVendorsVendor[];
|
||||
export class TransactionsByVendorsTable extends TransactionsByContactsTableRows {
|
||||
private vendorsTransactions: ITransactionsByVendorsVendor[];
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {ITransactionsByVendorsVendor[]} vendorsTransactions -
|
||||
* @param {any} i18n
|
||||
*/
|
||||
constructor(
|
||||
vendorsTransactions: ITransactionsByVendorsVendor[],
|
||||
i18n
|
||||
) {
|
||||
constructor(vendorsTransactions: ITransactionsByVendorsVendor[], i18n) {
|
||||
super();
|
||||
|
||||
this.vendorsTransactions = vendorsTransactions;
|
||||
@@ -73,4 +76,12 @@ export default class TransactionsByVendorsTableRows extends TransactionsByContac
|
||||
public tableRows = (): ITableRow[] => {
|
||||
return R.map(this.vendorRowsMapper)(this.vendorsTransactions);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve the table columns of transactions by vendors report.
|
||||
* @returns {ITableColumn[]}
|
||||
*/
|
||||
public tableColumns = (): ITableColumn[] => {
|
||||
return [];
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { TransactionsByVendorsTable } from './TransactionsByVendorTable';
|
||||
import {
|
||||
ITransactionsByVendorTable,
|
||||
ITransactionsByVendorsFilter,
|
||||
} from '@/interfaces';
|
||||
import { TransactionsByVendorsInjectable } from './TransactionsByVendorInjectable';
|
||||
|
||||
@Service()
|
||||
export class TransactionsByVendorTableInjectable {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private transactionsByVendor: TransactionsByVendorsInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the transactions by vendor in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {ITransactionsByReferenceQuery} query
|
||||
* @returns {Promise<ITransactionsByVendorTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: ITransactionsByVendorsFilter
|
||||
): Promise<ITransactionsByVendorTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const sheet = await this.transactionsByVendor.transactionsByVendors(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
const table = new TransactionsByVendorsTable(sheet.data, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
rows: table.tableRows(),
|
||||
columns: table.tableColumns(),
|
||||
},
|
||||
query,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user