mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
feat: export reports csv and xlsx (#286)
This commit is contained in:
@@ -101,8 +101,4 @@ export class VendorBalanceSummaryReport extends ContactBalanceSummaryReport {
|
||||
|
||||
return { vendors, total };
|
||||
}
|
||||
|
||||
reportColumns() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IVendorBalanceSummaryQuery } from '@/interfaces';
|
||||
import { VendorBalanceSummaryTableInjectable } from './VendorBalanceSummaryTableInjectable';
|
||||
import { VendorBalanceSummaryExportInjectable } from './VendorBalanceSummaryExportInjectable';
|
||||
import { VendorBalanceSummaryService } from './VendorBalanceSummaryService';
|
||||
|
||||
@Service()
|
||||
export class VendorBalanceSummaryApplication {
|
||||
@Inject()
|
||||
private vendorBalanceSummaryTable: VendorBalanceSummaryTableInjectable;
|
||||
|
||||
@Inject()
|
||||
private vendorBalanceSummarySheet: VendorBalanceSummaryService;
|
||||
|
||||
@Inject()
|
||||
private vendorBalanceSummaryExport: VendorBalanceSummaryExportInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in sheet format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
*/
|
||||
public sheet(tenantId: number, query: IVendorBalanceSummaryQuery) {
|
||||
return this.vendorBalanceSummarySheet.vendorBalanceSummary(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {}
|
||||
*/
|
||||
public table(tenantId: number, query: IVendorBalanceSummaryQuery) {
|
||||
return this.vendorBalanceSummaryTable.table(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in xlsx format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public xlsx(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<Buffer> {
|
||||
return this.vendorBalanceSummaryExport.xlsx(tenantId, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in csv format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public csv(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<string> {
|
||||
return this.vendorBalanceSummaryExport.csv(tenantId, query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { IVendorBalanceSummaryQuery } from '@/interfaces';
|
||||
import { VendorBalanceSummaryTableInjectable } from './VendorBalanceSummaryTableInjectable';
|
||||
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||
|
||||
@Service()
|
||||
export class VendorBalanceSummaryExportInjectable {
|
||||
@Inject()
|
||||
private customerBalanceSummaryTable: VendorBalanceSummaryTableInjectable;
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in XLSX format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
public async xlsx(tenantId: number, query: IVendorBalanceSummaryQuery) {
|
||||
const table = await this.customerBalanceSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToXLSX();
|
||||
|
||||
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in CSV format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
public async csv(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<string> {
|
||||
const table = await this.customerBalanceSummaryTable.table(tenantId, query);
|
||||
|
||||
const tableSheet = new TableSheet(table.table);
|
||||
const tableCsv = tableSheet.convertToCSV();
|
||||
|
||||
return tableCsv;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { ACCOUNT_TYPE } from '@/data/AccountTypes';
|
||||
@Service()
|
||||
export default class VendorBalanceSummaryRepository {
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieve the report vendors.
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { Inject } from 'typedi';
|
||||
import moment from 'moment';
|
||||
import { map } from 'lodash';
|
||||
import * as R from 'ramda';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import {
|
||||
IVendor,
|
||||
IVendorBalanceSummaryService,
|
||||
IVendorBalanceSummaryQuery,
|
||||
IVendorBalanceSummaryStatement,
|
||||
@@ -15,15 +13,12 @@ import Ledger from '@/services/Accounting/Ledger';
|
||||
import VendorBalanceSummaryRepository from './VendorBalanceSummaryRepository';
|
||||
import { Tenant } from '@/system/models';
|
||||
|
||||
export default class VendorBalanceSummaryService
|
||||
export class VendorBalanceSummaryService
|
||||
implements IVendorBalanceSummaryService
|
||||
{
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject('logger')
|
||||
logger: any;
|
||||
|
||||
@Inject()
|
||||
reportRepo: VendorBalanceSummaryRepository;
|
||||
|
||||
@@ -31,7 +26,7 @@ export default class VendorBalanceSummaryService
|
||||
* Defaults balance sheet filter query.
|
||||
* @return {IVendorBalanceSummaryQuery}
|
||||
*/
|
||||
get defaultQuery(): IVendorBalanceSummaryQuery {
|
||||
private get defaultQuery(): IVendorBalanceSummaryQuery {
|
||||
return {
|
||||
asDate: moment().format('YYYY-MM-DD'),
|
||||
numberFormat: {
|
||||
@@ -72,7 +67,7 @@ export default class VendorBalanceSummaryService
|
||||
* @param {IVendorBalanceSummaryQuery} query -
|
||||
* @return {Promise<IVendorBalanceSummaryStatement>}
|
||||
*/
|
||||
async vendorBalanceSummary(
|
||||
public async vendorBalanceSummary(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<IVendorBalanceSummaryStatement> {
|
||||
@@ -81,13 +76,7 @@ export default class VendorBalanceSummaryService
|
||||
.withGraphFetched('metadata');
|
||||
|
||||
const filter = { ...this.defaultQuery, ...query };
|
||||
this.logger.info(
|
||||
'[customer_balance_summary] trying to calculate the report.',
|
||||
{
|
||||
filter,
|
||||
tenantId,
|
||||
}
|
||||
);
|
||||
|
||||
// Retrieve the vendors transactions.
|
||||
const vendorsEntries = await this.getReportVendorsEntries(
|
||||
tenantId,
|
||||
@@ -111,7 +100,6 @@ export default class VendorBalanceSummaryService
|
||||
|
||||
return {
|
||||
data: reportInstance.reportData(),
|
||||
columns: reportInstance.reportColumns(),
|
||||
query: filter,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
IVendorBalanceSummaryQuery,
|
||||
IVendorBalanceSummaryTable,
|
||||
} from '@/interfaces';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { VendorBalanceSummaryTable } from './VendorBalanceSummaryTableRows';
|
||||
import { VendorBalanceSummaryService } from './VendorBalanceSummaryService';
|
||||
|
||||
@Service()
|
||||
export class VendorBalanceSummaryTableInjectable {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private vendorBalanceSummarySheet: VendorBalanceSummaryService;
|
||||
|
||||
/**
|
||||
* Retrieves the vendor balance summary sheet in table format.
|
||||
* @param {number} tenantId
|
||||
* @param {IVendorBalanceSummaryQuery} query
|
||||
* @returns {Promise<IVendorBalanceSummaryTable>}
|
||||
*/
|
||||
public async table(
|
||||
tenantId: number,
|
||||
query: IVendorBalanceSummaryQuery
|
||||
): Promise<IVendorBalanceSummaryTable> {
|
||||
const i18n = this.tenancy.i18n(tenantId);
|
||||
|
||||
const { data } = await this.vendorBalanceSummarySheet.vendorBalanceSummary(
|
||||
tenantId,
|
||||
query
|
||||
);
|
||||
const table = new VendorBalanceSummaryTable(data, query, i18n);
|
||||
|
||||
return {
|
||||
table: {
|
||||
columns: table.tableColumns(),
|
||||
rows: table.tableRows(),
|
||||
},
|
||||
query,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ enum TABLE_ROWS_TYPES {
|
||||
TOTAL = 'TOTAL',
|
||||
}
|
||||
|
||||
export default class VendorBalanceSummaryTable {
|
||||
export class VendorBalanceSummaryTable {
|
||||
i18n: any;
|
||||
report: IVendorBalanceSummaryData;
|
||||
query: IVendorBalanceSummaryQuery;
|
||||
|
||||
Reference in New Issue
Block a user