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