mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
fix: sales by items TS types
This commit is contained in:
@@ -24,7 +24,7 @@ export default class SalesByItemsReportController extends BaseFinancialReportCon
|
|||||||
CheckPolicies(ReportsAction.READ_SALES_BY_ITEMS, AbilitySubject.Report),
|
CheckPolicies(ReportsAction.READ_SALES_BY_ITEMS, AbilitySubject.Report),
|
||||||
this.validationSchema,
|
this.validationSchema,
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.purchasesByItems.bind(this))
|
asyncMiddleware(this.salesByItems.bind(this))
|
||||||
);
|
);
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
@@ -61,11 +61,7 @@ export default class SalesByItemsReportController extends BaseFinancialReportCon
|
|||||||
* @param {Request} req -
|
* @param {Request} req -
|
||||||
* @param {Response} res -
|
* @param {Response} res -
|
||||||
*/
|
*/
|
||||||
private async purchasesByItems(
|
private async salesByItems(req: Request, res: Response, next: NextFunction) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) {
|
|
||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
const accept = this.accepts(req);
|
const accept = this.accepts(req);
|
||||||
|
|||||||
@@ -1,45 +1,54 @@
|
|||||||
import {
|
import { INumberFormatQuery } from './FinancialStatements';
|
||||||
INumberFormatQuery,
|
import { IFinancialTable } from './Table';
|
||||||
} from './FinancialStatements';
|
|
||||||
|
|
||||||
export interface ISalesByItemsReportQuery {
|
export interface ISalesByItemsReportQuery {
|
||||||
fromDate: Date | string;
|
fromDate: Date | string;
|
||||||
toDate: Date | string;
|
toDate: Date | string;
|
||||||
itemsIds: number[],
|
itemsIds: number[];
|
||||||
numberFormat: INumberFormatQuery;
|
numberFormat: INumberFormatQuery;
|
||||||
noneTransactions: boolean;
|
noneTransactions: boolean;
|
||||||
onlyActive: boolean;
|
onlyActive: boolean;
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface ISalesByItemsSheetMeta {
|
export interface ISalesByItemsSheetMeta {
|
||||||
organizationName: string,
|
organizationName: string;
|
||||||
baseCurrency: string,
|
baseCurrency: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface ISalesByItemsItem {
|
export interface ISalesByItemsItem {
|
||||||
id: number,
|
id: number;
|
||||||
name: string,
|
name: string;
|
||||||
code: string,
|
code: string;
|
||||||
quantitySold: number,
|
quantitySold: number;
|
||||||
soldCost: number,
|
soldCost: number;
|
||||||
averageSellPrice: number,
|
averageSellPrice: number;
|
||||||
|
|
||||||
quantitySoldFormatted: string,
|
quantitySoldFormatted: string;
|
||||||
soldCostFormatted: string,
|
soldCostFormatted: string;
|
||||||
averageSellPriceFormatted: string,
|
averageSellPriceFormatted: string;
|
||||||
currencyCode: string,
|
currencyCode: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface ISalesByItemsTotal {
|
export interface ISalesByItemsTotal {
|
||||||
quantitySold: number,
|
quantitySold: number;
|
||||||
soldCost: number,
|
soldCost: number;
|
||||||
quantitySoldFormatted: string,
|
quantitySoldFormatted: string;
|
||||||
soldCostFormatted: string,
|
soldCostFormatted: string;
|
||||||
currencyCode: string,
|
currencyCode: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ISalesByItemsSheetData = {
|
||||||
|
items: ISalesByItemsItem[];
|
||||||
|
total: ISalesByItemsTotal;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ISalesByItemsSheetStatement = {
|
export interface ISalesByItemsSheet {
|
||||||
items: ISalesByItemsItem[],
|
data: ISalesByItemsSheetData;
|
||||||
total: ISalesByItemsTotal
|
query: ISalesByItemsReportQuery;
|
||||||
};
|
meta: ISalesByItemsSheetMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ISalesByItemsTable extends IFinancialTable {
|
||||||
|
query: ISalesByItemsReportQuery;
|
||||||
|
meta: ISalesByItemsSheetMeta;
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
import { ISalesByItemsReportQuery } from '@/interfaces';
|
import { Inject, Service } from 'typedi';
|
||||||
|
import {
|
||||||
|
ISalesByItemsReportQuery,
|
||||||
|
ISalesByItemsSheet,
|
||||||
|
ISalesByItemsSheetData,
|
||||||
|
ISalesByItemsTable,
|
||||||
|
} from '@/interfaces';
|
||||||
import { SalesByItemsReportService } from './SalesByItemsService';
|
import { SalesByItemsReportService } from './SalesByItemsService';
|
||||||
import { SalesByItemsTableInjectable } from './SalesByItemsTableInjectable';
|
import { SalesByItemsTableInjectable } from './SalesByItemsTableInjectable';
|
||||||
import { SalesByItemsExport } from './SalesByItemsExport';
|
import { SalesByItemsExport } from './SalesByItemsExport';
|
||||||
import { Inject, Service } from 'typedi';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class SalesByItemsApplication {
|
export class SalesByItemsApplication {
|
||||||
@@ -19,9 +24,12 @@ export class SalesByItemsApplication {
|
|||||||
* Retrieves the sales by items report in json format.
|
* Retrieves the sales by items report in json format.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {ISalesByItemsReportQuery} filter
|
* @param {ISalesByItemsReportQuery} filter
|
||||||
* @returns {Promise<ISalesByItemsTable>}
|
* @returns {Promise<ISalesByItemsSheetData>}
|
||||||
*/
|
*/
|
||||||
public sheet(tenantId: number, filter: ISalesByItemsReportQuery) {
|
public sheet(
|
||||||
|
tenantId: number,
|
||||||
|
filter: ISalesByItemsReportQuery
|
||||||
|
): Promise<ISalesByItemsSheet> {
|
||||||
return this.salesByItemsSheet.salesByItems(tenantId, filter);
|
return this.salesByItemsSheet.salesByItems(tenantId, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +39,10 @@ export class SalesByItemsApplication {
|
|||||||
* @param {ISalesByItemsReportQuery} filter
|
* @param {ISalesByItemsReportQuery} filter
|
||||||
* @returns {Promise<ISalesByItemsTable>}
|
* @returns {Promise<ISalesByItemsTable>}
|
||||||
*/
|
*/
|
||||||
public table(tenantId: number, filter: ISalesByItemsReportQuery) {
|
public table(
|
||||||
|
tenantId: number,
|
||||||
|
filter: ISalesByItemsReportQuery
|
||||||
|
): Promise<ISalesByItemsTable> {
|
||||||
return this.salesByItemsTable.table(tenantId, filter);
|
return this.salesByItemsTable.table(tenantId, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,9 +50,12 @@ export class SalesByItemsApplication {
|
|||||||
* Retrieves the sales by items report in csv format.
|
* Retrieves the sales by items report in csv format.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {ISalesByItemsReportQuery} filter
|
* @param {ISalesByItemsReportQuery} filter
|
||||||
* @returns {Promise<Buffer>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
public csv(tenantId: number, filter: ISalesByItemsReportQuery) {
|
public csv(
|
||||||
|
tenantId: number,
|
||||||
|
filter: ISalesByItemsReportQuery
|
||||||
|
): Promise<string> {
|
||||||
return this.salesByItemsExport.csv(tenantId, filter);
|
return this.salesByItemsExport.csv(tenantId, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +65,10 @@ export class SalesByItemsApplication {
|
|||||||
* @param {ISalesByItemsReportQuery} filter
|
* @param {ISalesByItemsReportQuery} filter
|
||||||
* @returns {Promise<Buffer>}
|
* @returns {Promise<Buffer>}
|
||||||
*/
|
*/
|
||||||
public xlsx(tenantId: number, filter: ISalesByItemsReportQuery) {
|
public xlsx(
|
||||||
|
tenantId: number,
|
||||||
|
filter: ISalesByItemsReportQuery
|
||||||
|
): Promise<Buffer> {
|
||||||
return this.salesByItemsExport.xlsx(tenantId, filter);
|
return this.salesByItemsExport.xlsx(tenantId, filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import { Service, Inject } from 'typedi';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import {
|
import {
|
||||||
ISalesByItemsReportQuery,
|
ISalesByItemsReportQuery,
|
||||||
ISalesByItemsSheetStatement,
|
ISalesByItemsSheetMeta,
|
||||||
ISalesByItemsSheetMeta
|
ISalesByItemsSheet,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import SalesByItems from './SalesByItems';
|
import SalesByItems from './SalesByItems';
|
||||||
@@ -63,20 +63,14 @@ export class SalesByItemsReportService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve balance sheet statement.
|
* Retrieve balance sheet statement.
|
||||||
* -------------
|
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {IBalanceSheetQuery} query
|
* @param {IBalanceSheetQuery} query
|
||||||
*
|
* @return {Promise<ISalesByItemsSheet>}
|
||||||
* @return {IBalanceSheetStatement}
|
|
||||||
*/
|
*/
|
||||||
public async salesByItems(
|
public async salesByItems(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
query: ISalesByItemsReportQuery
|
query: ISalesByItemsReportQuery
|
||||||
): Promise<{
|
): Promise<ISalesByItemsSheet> {
|
||||||
data: ISalesByItemsSheetStatement,
|
|
||||||
query: ISalesByItemsReportQuery,
|
|
||||||
meta: ISalesByItemsSheetMeta,
|
|
||||||
}> {
|
|
||||||
const { Item, InventoryTransaction } = this.tenancy.models(tenantId);
|
const { Item, InventoryTransaction } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const tenant = await Tenant.query()
|
const tenant = await Tenant.query()
|
||||||
@@ -107,20 +101,19 @@ export class SalesByItemsReportService {
|
|||||||
builder.whereIn('itemId', inventoryItemsIds);
|
builder.whereIn('itemId', inventoryItemsIds);
|
||||||
|
|
||||||
// Filter the date range of the sheet.
|
// Filter the date range of the sheet.
|
||||||
builder.modify('filterDateRange', filter.fromDate, filter.toDate)
|
builder.modify('filterDateRange', filter.fromDate, filter.toDate);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
const sheet = new SalesByItems(
|
||||||
const purchasesByItemsInstance = new SalesByItems(
|
|
||||||
filter,
|
filter,
|
||||||
inventoryItems,
|
inventoryItems,
|
||||||
inventoryTransactions,
|
inventoryTransactions,
|
||||||
tenant.metadata.baseCurrency,
|
tenant.metadata.baseCurrency
|
||||||
);
|
);
|
||||||
const purchasesByItemsData = purchasesByItemsInstance.reportData();
|
const salesByItemsData = sheet.reportData();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: purchasesByItemsData,
|
data: salesByItemsData,
|
||||||
query: filter,
|
query: filter,
|
||||||
meta: this.reportMetadata(tenantId),
|
meta: this.reportMetadata(tenantId),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { ISalesByItemsReportQuery } from '@/interfaces';
|
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { ISalesByItemsReportQuery } from '@/interfaces';
|
||||||
import { SalesByItemsReportService } from './SalesByItemsService';
|
import { SalesByItemsReportService } from './SalesByItemsService';
|
||||||
import { SalesByItemsTable } from './SalesByItemsTable';
|
import { SalesByItemsTable } from './SalesByItemsTable';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class SalesByItemsTableInjectable {
|
export class SalesByItemsTableInjectable {
|
||||||
@Inject()
|
@Inject()
|
||||||
salesByItemSheet: SalesByItemsReportService;
|
private salesByItemSheet: SalesByItemsReportService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the sales by items report in table format.
|
* Retrieves the sales by items report in table format.
|
||||||
Reference in New Issue
Block a user