refactor: reports to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-01-21 11:53:29 +02:00
parent b46f2a91c3
commit 2e1c57438c
41 changed files with 71 additions and 50 deletions

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import * as R from 'ramda';
import { isEmpty, sumBy } from 'lodash';
import { ERRORS, MatchedTransactionPOJO } from './types';

View File

@@ -1,5 +1,5 @@
import * as R from 'ramda';
import moment from 'moment';
import * as moment from 'moment';
import { first, sumBy } from 'lodash';
import { PromisePool } from '@supercharge/promise-pool';
import { Inject, Injectable } from '@nestjs/common';

View File

@@ -1,5 +1,5 @@
/* eslint-disable global-require */
import moment from 'moment';
import * as moment from 'moment';
import { Model } from 'objection';
// import TenantModel from 'models/TenantModel';
// import ModelSettings from './ModelSetting';

View File

@@ -1,6 +1,6 @@
import { Inject, Injectable } from '@nestjs/common';
import { omit, sumBy } from 'lodash';
import moment from 'moment';
import * as moment from 'moment';
import * as R from 'ramda';
import * as composeAsync from 'async/compose';
import { formatDateFields } from '@/utils/format-date-fields';

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import { Inject, Injectable } from '@nestjs/common';
import { ERRORS } from '../Bills.constants';
import { BillsValidators } from './BillsValidators.service';

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import { defaultTo, omit, isEmpty } from 'lodash';
import { Injectable } from '@nestjs/common';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';

View File

@@ -1,5 +1,5 @@
// @ts-nocheck
import moment from 'moment';
import * as moment from 'moment';
import * as R from 'ramda';
import { IFilterRole, IDynamicFilter } from './DynamicFilter.types';
import { Parser } from '@/libs/logic-evaluation/Parser';

View File

@@ -1,5 +1,5 @@
import { Model, raw } from 'objection';
import moment from 'moment';
import * as moment from 'moment';
import { ExpenseCategory } from './ExpenseCategory.model';
import { Account } from '@/modules/Accounts/models/Account.model';
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import { IDateRange, IFinancialDatePeriodsUnit } from '../types/Report.types';
import { GConstructor } from '@/common/types/Constructor';
import { FinancialSheet } from './FinancialSheet';

View File

@@ -1,7 +1,7 @@
import moment from 'moment';
import * as moment from 'moment';
import { ITableColumn, ITableColumnAccessor } from '../types/Table.types';
import { IDateRange } from '../types/Report.types';
import { Constructor, GConstructor } from '@/common/types/Constructor';
import { GConstructor } from '@/common/types/Constructor';
import { I18nService } from 'nestjs-i18n';
import { FinancialSheet } from './FinancialSheet';

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import { ITableColumn, ITableColumnAccessor } from '../types/Table.types';
import { IDateRange } from '../types/Report.types';
import { GConstructor } from '@/common/types/Constructor';

View File

@@ -1,10 +1,13 @@
import { IARAgingSummaryQuery } from './ARAgingSummary.types';
import { Get, Headers } from '@nestjs/common';
import { Controller, Get, Headers } from '@nestjs/common';
import { Query, Res } from '@nestjs/common';
import { ARAgingSummaryApplication } from './ARAgingSummaryApplication';
import { AcceptType } from '@/constants/accept-type';
import { Response } from 'express';
import { PublicRoute } from '@/modules/Auth/Jwt.guard';
@Controller('reports/receivable-aging-summary')
@PublicRoute()
export class ARAgingSummaryController {
constructor(private readonly ARAgingSummaryApp: ARAgingSummaryApplication) {}

View File

@@ -7,9 +7,12 @@ import { AgingSummaryModule } from '../AgingSummary/AgingSummary.module';
import { ARAgingSummaryRepository } from './ARAgingSummaryRepository';
import { ARAgingSummaryApplication } from './ARAgingSummaryApplication';
import { ARAgingSummaryController } from './ARAgingSummary.controller';
import { ARAgingSummaryMeta } from './ARAgingSummaryMeta';
import { FinancialSheetCommonModule } from '../../common/FinancialSheetCommon.module';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
@Module({
imports: [AgingSummaryModule],
imports: [AgingSummaryModule, FinancialSheetCommonModule],
controllers: [ARAgingSummaryController],
providers: [
ARAgingSummaryTableInjectable,
@@ -18,6 +21,8 @@ import { ARAgingSummaryController } from './ARAgingSummary.controller';
ARAgingSummaryPdfInjectable,
ARAgingSummaryRepository,
ARAgingSummaryApplication,
ARAgingSummaryMeta,
TenancyContext,
],
})
export class ARAgingSummaryModule {}

View File

@@ -16,7 +16,7 @@ export class ARAgingSummaryApplication {
/**
* Retrieve the A/R aging summary sheet.
* @param {IAPAgingSummaryQuery} query
* @param {IARAgingSummaryQuery} query
*/
public sheet(query: IARAgingSummaryQuery) {
return this.ARAgingSummarySheet.ARAgingSummary(query);
@@ -24,7 +24,6 @@ export class ARAgingSummaryApplication {
/**
* Retrieve the A/R aging summary in table format.
* @param {number} tenantId
* @param {IAPAgingSummaryQuery} query
*/
public table(query: IARAgingSummaryQuery) {
@@ -33,7 +32,6 @@ export class ARAgingSummaryApplication {
/**
* Retrieve the A/R aging summary in XLSX format.
* @param {number} tenantId
* @param {IAPAgingSummaryQuery} query
*/
public xlsx(query: IARAgingSummaryQuery) {
@@ -42,7 +40,6 @@ export class ARAgingSummaryApplication {
/**
* Retrieve the A/R aging summary in CSV format.
* @param {number} tenantId
* @param {IAPAgingSummaryQuery} query
*/
public csv(query: IARAgingSummaryQuery) {

View File

@@ -1,10 +1,10 @@
import { Inject } from '@nestjs/common';
import { isEmpty, groupBy } from 'lodash';
import { Customer } from '@/modules/Customers/models/Customer';
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
import { ModelObject } from 'objection';
import { IARAgingSummaryQuery } from './ARAgingSummary.types';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
import { Inject } from '@nestjs/common';
export class ARAgingSummaryRepository {
@Inject(TenancyContext)

View File

@@ -1,4 +1,4 @@
import * as moment from 'moment';
export const getARAgingSummaryDefaultQuery = () => {

View File

@@ -2,7 +2,7 @@ import * as moment from 'moment';
import { IAgingPeriod } from './AgingSummary.types';
import { FinancialSheet } from '../../common/FinancialSheet';
export abstract class AgingReport extends FinancialSheet {
export class AgingReport extends FinancialSheet {
/**
* Retrieve the aging periods range.
* @param {string} asDay

View File

@@ -1,7 +1,9 @@
import { Module } from '@nestjs/common';
import { AgingSummaryMeta } from './AgingSummaryMeta';
import { FinancialSheetCommonModule } from '../../common/FinancialSheetCommon.module';
@Module({
imports: [FinancialSheetCommonModule],
exports: [AgingSummaryMeta],
providers: [AgingSummaryMeta],
})

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import { Injectable } from '@nestjs/common';
import { FinancialSheetMeta } from '../../common/FinancialSheetMeta';
import { IAgingSummaryMeta, IAgingSummaryQuery } from './AgingSummary.types';

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import {
ICustomerBalanceSummaryMeta,
ICustomerBalanceSummaryQuery,

View File

@@ -1,9 +1,9 @@
import * as moment from 'moment';
import { Injectable } from '@nestjs/common';
import {
IGeneralLedgerMeta,
IGeneralLedgerSheetQuery,
} from './GeneralLedger.types';
import moment from 'moment';
import { Injectable } from '@nestjs/common';
import { FinancialSheetMeta } from '../../common/FinancialSheetMeta';
@Injectable()

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import * as R from 'ramda';
import {
IGeneralLedgerSheetQuery,

View File

@@ -1,6 +1,6 @@
import { ModelObject, raw } from 'objection';
import { isEmpty } from 'lodash';
import moment from 'moment';
import * as moment from 'moment';
import { IInventoryDetailsQuery } from './InventoryItemDetails.types';
import { Item } from '@/modules/Items/models/Item';
import { InventoryTransaction } from '@/modules/InventoryCost/models/InventoryTransaction';

View File

@@ -5,14 +5,23 @@ import { InventoryValuationMetaInjectable } from './InventoryValuationSheetMeta'
import { InventoryValuationController } from './InventoryValuation.controller';
import { InventoryValuationSheetService } from './InventoryValuationSheetService';
import { InventoryValuationSheetApplication } from './InventoryValuationSheetApplication';
import { FinancialSheetCommonModule } from '../../common/FinancialSheetCommon.module';
import { InventoryValuationSheetRepository } from './InventoryValuationSheetRepository';
import { InventoryValuationSheetExportable } from './InventoryValuationSheetExportable';
import { InventoryCostModule } from '@/modules/InventoryCost/InventoryCost.module';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
@Module({
imports: [FinancialSheetCommonModule, InventoryCostModule],
providers: [
InventoryValuationSheetPdf,
InventoryValuationSheetTableInjectable,
InventoryValuationMetaInjectable,
InventoryValuationSheetService,
InventoryValuationSheetApplication,
InventoryValuationSheetRepository,
InventoryValuationSheetExportable,
TenancyContext
],
controllers: [InventoryValuationController],
exports: [InventoryValuationSheetApplication],

View File

@@ -1,3 +1,5 @@
import * as moment from 'moment';
export enum ROW_TYPE {
ITEM = 'ITEM',
TOTAL = 'TOTAL',

View File

@@ -1,22 +1,21 @@
import moment from 'moment';
import { FinancialSheetMeta } from '../../common/FinancialSheetMeta';
import { ISalesByItemsReportQuery, ISalesByItemsSheetMeta } from './SalesByItems.types';
import * as moment from 'moment';
import { Injectable } from '@nestjs/common';
import { I18nService } from 'nestjs-i18n';
import { FinancialSheetMeta } from '../../common/FinancialSheetMeta';
import {
ISalesByItemsReportQuery,
ISalesByItemsSheetMeta,
} from './SalesByItems.types';
@Injectable()
export class SalesByItemsMeta {
constructor(
private financialSheetMeta: FinancialSheetMeta,
private i18n: I18nService,
) {}
constructor(private financialSheetMeta: FinancialSheetMeta) {}
/**
* Retrieve the sales by items meta.
* @returns {IBalanceSheetMeta}
*/
public async meta(
query: ISalesByItemsReportQuery
query: ISalesByItemsReportQuery,
): Promise<ISalesByItemsSheetMeta> {
const commonMeta = await this.financialSheetMeta.meta();
const formattedToDate = moment(query.toDate).format('YYYY/MM/DD');

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import * as R from 'ramda';
import { ITransactionsByContactsContact } from './TransactionsByContact.types';
import { ITableRow } from '../../types/Table.types';

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import bluebird from 'bluebird';
import { deleteImportFile } from './_utils';
import { Injectable } from '@nestjs/common';

View File

@@ -1,5 +1,5 @@
import * as Yup from 'yup';
import moment from 'moment';
import * as moment from 'moment';
import * as R from 'ramda';
import { Knex } from 'knex';
import fs from 'fs/promises';

View File

@@ -1,6 +1,7 @@
import { Model } from 'objection';
import { castArray } from 'lodash';
import moment, { unitOfTime } from 'moment';
import * as moment from 'moment';
import { unitOfTime } from 'moment';
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
import { SaleReceipt } from '@/modules/SaleReceipts/models/SaleReceipt';
import { Item } from '@/modules/Items/models/Item';

View File

@@ -1,7 +1,7 @@
import * as moment from 'moment';
import { Inject, Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Knex } from 'knex';
import moment from 'moment';
import { SaleEstimate } from '../models/SaleEstimate';
import { events } from '@/common/events/events';

View File

@@ -1,5 +1,5 @@
import { Knex } from 'knex';
import moment from 'moment';
import * as moment from 'moment';
import { Inject, Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import {

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import { Model } from 'objection';
import { Injectable } from '@nestjs/common';
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';

View File

@@ -1,5 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import moment from 'moment';
import * as moment from 'moment';
import { Knex } from 'knex';
import {
ISaleReceiptEventClosedPayload,

View File

@@ -2,7 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import * as R from 'ramda';
import { sumBy, omit } from 'lodash';
import * as composeAsync from 'async/compose';
import moment from 'moment';
import * as moment from 'moment';
import { SaleReceiptIncrement } from './SaleReceiptIncrement.service';
import { ItemsEntriesService } from '@/modules/Items/ItemsEntries.service';
import { BranchTransactionDTOTransformer } from '@/modules/Branches/integrations/BranchTransactionDTOTransform';

View File

@@ -1,4 +1,5 @@
import moment, { unitOfTime } from 'moment';
import * as moment from 'moment';
import { unitOfTime } from 'moment';
export class SubscriptionPeriod {
private start: Date;

View File

@@ -1,5 +1,5 @@
import { Model, mixin } from 'objection';
import moment from 'moment';
import * as moment from 'moment';
import { SubscriptionPeriod } from '../SubscriptionPeriod';
import { SystemModel } from '@/modules/System/models/SystemModel';
import { SubscriptionPaymentStatus } from '@/interfaces/SubscriptionPlan';

View File

@@ -1,4 +1,5 @@
import moment, { MomentInput } from 'moment';
import * as moment from 'moment';
import { MomentInput } from 'moment';
import { Injectable } from '@nestjs/common';
import { TransactionsLockingGroup } from '../types/TransactionsLocking.types';
import { TransactionsLockingRepository } from '../TransactionsLockingRepository';

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import { omit } from 'lodash';
import * as R from 'ramda';
import { ERRORS } from '../constants';

View File

@@ -1,4 +1,4 @@
import moment from 'moment';
import * as moment from 'moment';
import { defaultTo, isEmpty } from 'lodash';
import { Injectable } from '@nestjs/common';
import { IVendorEditDTO, IVendorNewDTO } from '../types/Vendors.types';

View File

@@ -2,5 +2,6 @@ export const transformToMapKeyValue = <T, K extends string | number>(
collection: T[],
key: keyof T,
): Map<K, T> => {
// @ts-ignore
return new Map(collection.map((item) => [item[key], item]));
};