diff --git a/packages/server/src/modules/EventsTracker/events/ReportsEventsTracker.ts b/packages/server/src/modules/EventsTracker/events/ReportsEventsTracker.ts index 59f63fcff..76f371397 100644 --- a/packages/server/src/modules/EventsTracker/events/ReportsEventsTracker.ts +++ b/packages/server/src/modules/EventsTracker/events/ReportsEventsTracker.ts @@ -18,16 +18,15 @@ import { PURCHASES_BY_ITEM_VIEWED, } from '../event-tracker'; import { events } from '@/common/events/events'; -import { POSTHOG_PROVIDER } from '../PostHog.constants'; +import { EventTrackerService } from '../EventTracker.service'; @Injectable() export class ReportsEventsTracker { - constructor(@Inject(POSTHOG_PROVIDER) private readonly posthog: any) {} + constructor(private readonly posthog: EventTrackerService) {} @OnEvent(events.reports.onBalanceSheetViewed) handleTrackBalanceSheetViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: BALANCE_SHEET_VIEWED, properties: {}, }); @@ -36,7 +35,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onTrialBalanceSheetView) handleTrackTrialBalanceSheetViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: TRIAL_BALANCE_SHEET_VIEWED, properties: {}, }); @@ -45,7 +43,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onProfitLossSheetViewed) handleTrackProfitLossSheetViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: PROFIT_LOSS_SHEET_VIEWED, properties: {}, }); @@ -54,7 +51,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onCashflowStatementViewed) handleTrackCashflowStatementViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: CASHFLOW_STATEMENT_VIEWED, properties: {}, }); @@ -63,7 +59,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onGeneralLedgerViewed) handleTrackGeneralLedgerViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: GENERAL_LEDGER_VIEWED, properties: {}, }); @@ -72,7 +67,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onJournalViewed) handleTrackJournalViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: JOURNAL_VIEWED, properties: {}, }); @@ -81,7 +75,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onReceivableAgingViewed) handleTrackReceivableAgingViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: RECEIVABLE_AGING_VIEWED, properties: {}, }); @@ -90,7 +83,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onPayableAgingViewed) handleTrackPayableAgingViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: PAYABLE_AGING_VIEWED, properties: {}, }); @@ -99,7 +91,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onCustomerBalanceSummaryViewed) handleTrackCustomerBalanceSummaryViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: CUSTOMER_BALANCE_SUMMARY_VIEWED, properties: {}, }); @@ -108,7 +99,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onVendorBalanceSummaryViewed) handleTrackVendorBalanceSummaryViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: VENDOR_BALANCE_SUMMARY_VIEWED, properties: {}, }); @@ -117,7 +107,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onInventoryValuationViewed) handleTrackInventoryValuationViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: INVENTORY_VALUATION_VIEWED, properties: {}, }); @@ -126,7 +115,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onCustomerTransactionsViewed) handleTrackCustomerTransactionsViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: CUSTOMER_TRANSACTIONS_VIEWED, properties: {}, }); @@ -135,7 +123,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onVendorTransactionsViewed) handleTrackVendorTransactionsViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: VENDOR_TRANSACTIONS_VIEWED, properties: {}, }); @@ -144,7 +131,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onSalesByItemViewed) handleTrackSalesByItemViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: SALES_BY_ITEM_VIEWED, properties: {}, }); @@ -153,7 +139,6 @@ export class ReportsEventsTracker { @OnEvent(events.reports.onPurchasesByItemViewed) handleTrackPurchasesByItemViewedEvent({ tenantId }: ReportsEvents) { this.posthog.trackEvent({ - distinctId: `tenant-${tenantId}`, event: PURCHASES_BY_ITEM_VIEWED, properties: {}, }); diff --git a/packages/server/src/modules/Export/Export.controller.ts b/packages/server/src/modules/Export/Export.controller.ts index 5cd14a4e9..efee75976 100644 --- a/packages/server/src/modules/Export/Export.controller.ts +++ b/packages/server/src/modules/Export/Export.controller.ts @@ -15,7 +15,7 @@ export class ExportController { @ApiOperation({ summary: 'Retrieves exported the given resource.' }) async export( @Query() query: ExportQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { const applicationFormat = convertAcceptFormatToFormat(acceptHeader); diff --git a/packages/server/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts index 200d911e8..a45cf7886 100644 --- a/packages/server/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/APAgingSummary/APAgingSummary.controller.ts @@ -14,14 +14,13 @@ export class APAgingSummaryController { @ApiOperation({ summary: 'Get payable aging summary' }) public async get( @Query() filter: IAPAgingSummaryQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.APAgingSummaryApp.table(filter); + return this.APAgingSummaryApp.table(filter); - res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const csv = await this.APAgingSummaryApp.csv(filter); @@ -51,9 +50,7 @@ export class APAgingSummaryController { res.send(pdfContent); // Retrieves the json format. } else { - const sheet = await this.APAgingSummaryApp.sheet(filter); - - res.status(200).send(sheet); + return this.APAgingSummaryApp.sheet(filter); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts index e356831fb..d37ac4f5e 100644 --- a/packages/server/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/ARAgingSummary/ARAgingSummary.controller.ts @@ -15,7 +15,7 @@ export class ARAgingSummaryController { @ApiOperation({ summary: 'Get receivable aging summary' }) public async get( @Query() filter: IARAgingSummaryQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the xlsx format. @@ -30,9 +30,8 @@ export class ARAgingSummaryController { res.send(buffer); // Retrieves the table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.ARAgingSummaryApp.table(filter); + return this.ARAgingSummaryApp.table(filter); - res.status(200).send(table); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.ARAgingSummaryApp.csv(filter); @@ -52,9 +51,7 @@ export class ARAgingSummaryController { res.send(pdfContent); // Retrieves the json format. } else { - const sheet = await this.ARAgingSummaryApp.sheet(filter); - - res.status(200).send(sheet); + return this.ARAgingSummaryApp.sheet(filter); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/BalanceSheet/BalanceSheet.controller.ts b/packages/server/src/modules/FinancialStatements/modules/BalanceSheet/BalanceSheet.controller.ts index 2d266a611..9cecc0b4b 100644 --- a/packages/server/src/modules/FinancialStatements/modules/BalanceSheet/BalanceSheet.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/BalanceSheet/BalanceSheet.controller.ts @@ -21,14 +21,14 @@ export class BalanceSheetStatementController { @ApiResponse({ status: 200, description: 'Balance sheet statement' }) public async balanceSheet( @Query() query: IBalanceSheetQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { const table = await this.balanceSheetApp.table(query); - res.status(200).send(table); + return table; // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.balanceSheetApp.csv(query); @@ -59,7 +59,7 @@ export class BalanceSheetStatementController { } else { const sheet = await this.balanceSheetApp.sheet(query); - res.status(200).send(sheet); + return sheet; } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/CashFlowTable.ts b/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/CashFlowTable.ts index 180ca7a26..61ddfead9 100644 --- a/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/CashFlowTable.ts +++ b/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/CashFlowTable.ts @@ -1,7 +1,7 @@ // @ts-nocheck import * as R from 'ramda'; import { isEmpty } from 'lodash'; -import moment from 'moment'; +import * as moment from 'moment'; import { I18nService } from 'nestjs-i18n'; import { ICashFlowStatementSection, diff --git a/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts b/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts index bc7a3814b..70ca276f2 100644 --- a/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/CashFlowStatement/Cashflow.controller.ts @@ -15,14 +15,12 @@ export class CashflowController { @ApiOperation({ summary: 'Get cashflow statement report' }) async getCashflow( @Query() query: ICashFlowStatementQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.cashflowSheetApp.table(query); - - res.status(200).send(table); + return this.cashflowSheetApp.table(query); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.cashflowSheetApp.csv(query); @@ -52,9 +50,7 @@ export class CashflowController { res.send(pdfContent); // Retrieves the json format. } else { - const cashflow = await this.cashflowSheetApp.sheet(query); - - res.status(200).send(cashflow); + return this.cashflowSheetApp.sheet(query); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts index 8c355a4a3..55124fe26 100644 --- a/packages/server/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/CustomerBalanceSummary/CustomerBalanceSummary.controller.ts @@ -17,7 +17,7 @@ export class CustomerBalanceSummaryController { @ApiOperation({ summary: 'Get customer balance summary report' }) async customerBalanceSummary( @Query() filter: ICustomerBalanceSummaryQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the xlsx format. @@ -38,8 +38,8 @@ export class CustomerBalanceSummaryController { res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.customerBalanceSummaryApp.table(filter); - res.status(200).send(table); + return this.customerBalanceSummaryApp.table(filter); + // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const buffer = await this.customerBalanceSummaryApp.pdf(filter); @@ -51,8 +51,7 @@ export class CustomerBalanceSummaryController { res.send(buffer); // Retrieves the json format. } else { - const sheet = await this.customerBalanceSummaryApp.sheet(filter); - res.status(200).send(sheet); + return this.customerBalanceSummaryApp.sheet(filter); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts b/packages/server/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts index 9458dfe9c..6abf923ef 100644 --- a/packages/server/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/GeneralLedger/GeneralLedger.controller.ts @@ -17,14 +17,12 @@ export class GeneralLedgerController { @ApiOperation({ summary: 'Get general ledger report' }) public async getGeneralLedger( @Query() query: IGeneralLedgerSheetQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.generalLedgerApplication.table(query); - - res.status(200).send(table); + return this.generalLedgerApplication.table(query); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.generalLedgerApplication.csv(query); @@ -53,9 +51,7 @@ export class GeneralLedgerController { res.send(pdfContent); // Retrieves the json format. } else { - const sheet = await this.generalLedgerApplication.sheet(query); - - res.status(200).send(sheet); + return this.generalLedgerApplication.sheet(query); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts b/packages/server/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts index 3552a6b92..fac125b02 100644 --- a/packages/server/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/InventoryItemDetails/InventoryItemDetails.controller.ts @@ -16,7 +16,7 @@ export class InventoryItemDetailsController { @ApiOperation({ summary: 'Get inventory item details' }) async inventoryItemDetails( @Query() query: IInventoryDetailsQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { if (acceptHeader.includes(AcceptType.ApplicationCsv)) { @@ -38,8 +38,7 @@ export class InventoryItemDetailsController { res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.inventoryItemDetailsApp.table(query); - res.status(200).send(table); + return this.inventoryItemDetailsApp.table(query); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const buffer = await this.inventoryItemDetailsApp.pdf(query); @@ -50,9 +49,7 @@ export class InventoryItemDetailsController { }); res.send(buffer); } else { - const sheet = await this.inventoryItemDetailsApp.sheet(query); - - res.status(200).send(sheet); + return this.inventoryItemDetailsApp.sheet(query); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts b/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts index d286af74b..e6a090295 100644 --- a/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuation.controller.ts @@ -20,14 +20,12 @@ export class InventoryValuationController { }) public async getInventoryValuationSheet( @Query() query: IInventoryValuationReportQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.inventoryValuationApp.table(query); - - res.status(200).send(table); + return this.inventoryValuationApp.table(query); // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.inventoryValuationApp.csv(query); @@ -57,9 +55,7 @@ export class InventoryValuationController { res.status(200).send(pdfContent); // Retrieves the json format. } else { - const sheet = await this.inventoryValuationApp.sheet(query); - - res.status(200).send(sheet); + return this.inventoryValuationApp.sheet(query); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts index 5eca0ee7d..db3196bfe 100644 --- a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.controller.ts @@ -15,14 +15,13 @@ export class JournalSheetController { @ApiOperation({ summary: 'Journal report' }) async journalSheet( @Query() query: IJournalReportQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.journalSheetApp.table(query); - res.status(200).send(table); - + return this.journalSheetApp.table(query); + // Retrieves the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.journalSheetApp.csv(query); @@ -51,9 +50,7 @@ export class JournalSheetController { }); res.send(pdfContent); } else { - const sheet = await this.journalSheetApp.sheet(query); - - res.status(200).send(sheet); + return this.journalSheetApp.sheet(query); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.ts b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.ts index 5696a6a9d..1d4d18ae1 100644 --- a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.ts +++ b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheet.ts @@ -1,6 +1,6 @@ import { I18nService } from 'nestjs-i18n'; import { sumBy, chain, get, head } from 'lodash'; -import moment from 'moment'; +import * as moment from 'moment'; import { IJournalReportEntriesGroup, IJournalReportQuery, @@ -9,17 +9,18 @@ import { } from './JournalSheet.types'; import { FinancialSheet } from '../../common/FinancialSheet'; import { JournalSheetRepository } from './JournalSheetRepository'; -import { Ledger } from '@/modules/Ledger/Ledger'; import { ILedgerEntry } from '@/modules/Ledger/types/Ledger.types'; export class JournalSheet extends FinancialSheet { - readonly ledger: Ledger; readonly query: IJournalReportQuery; readonly repository: JournalSheetRepository; readonly i18n: I18nService; /** * Constructor method. + * @param {IJournalReportQuery} query - + * @param {JournalSheetRepository} repository - + * @param {I18nService} i18n - */ constructor( query: IJournalReportQuery, @@ -130,6 +131,6 @@ export class JournalSheet extends FinancialSheet { * @return {IJournalReport} */ reportData(): IJournalTableData { - return this.entriesWalker(this.ledger.entries); + return this.entriesWalker(this.repository.ledger.entries); } } diff --git a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetApplication.ts b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetApplication.ts index ea1cdb21c..de876bc57 100644 --- a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetApplication.ts +++ b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetApplication.ts @@ -1,9 +1,11 @@ +import { Injectable } from '@nestjs/common'; import { JournalSheetService } from './JournalSheetService'; import { JournalSheetTableInjectable } from './JournalSheetTableInjectable'; import { JournalSheetExportInjectable } from './JournalSheetExport'; import { JournalSheetPdfInjectable } from './JournalSheetPdfInjectable'; import { IJournalReportQuery, IJournalTable } from './JournalSheet.types'; +@Injectable() export class JournalSheetApplication { constructor( private readonly journalSheetTable: JournalSheetTableInjectable, diff --git a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetMeta.ts b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetMeta.ts index 5b68c2ded..da6afbd81 100644 --- a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetMeta.ts +++ b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetMeta.ts @@ -1,4 +1,4 @@ -import moment from 'moment'; +import * as moment from 'moment'; import { Injectable } from '@nestjs/common'; import { FinancialSheetMeta } from '../../common/FinancialSheetMeta'; import { IJournalReportQuery, IJournalSheetMeta } from './JournalSheet.types'; diff --git a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetTableInjectable.ts b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetTableInjectable.ts index e7d8dfae6..34a8b65a4 100644 --- a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetTableInjectable.ts +++ b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/JournalSheetTableInjectable.ts @@ -1,8 +1,10 @@ +import { Injectable } from '@nestjs/common'; +import { I18nService } from 'nestjs-i18n'; import { JournalSheetService } from './JournalSheetService'; import { IJournalReportQuery, IJournalTable } from './JournalSheet.types'; import { JournalSheetTable } from './JournalSheetTable'; -import { I18nService } from 'nestjs-i18n'; +@Injectable() export class JournalSheetTableInjectable { constructor( private readonly journalSheetService: JournalSheetService, diff --git a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/constant.ts b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/constant.ts index e93dfdc62..ce0fd7b1b 100644 --- a/packages/server/src/modules/FinancialStatements/modules/JournalSheet/constant.ts +++ b/packages/server/src/modules/FinancialStatements/modules/JournalSheet/constant.ts @@ -1,3 +1,5 @@ +import * as moment from 'moment'; + export const HtmlTableCustomCss = ` table tr.row-type--total td{ font-weight: 600; diff --git a/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts b/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts index 03cc0bf8a..5f663f13d 100644 --- a/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheet.controller.ts @@ -23,7 +23,7 @@ export class ProfitLossSheetController { @ApiOperation({ summary: 'Get profit/loss statement report' }) async profitLossSheet( @Query() query: IProfitLossSheetQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the csv format. @@ -36,9 +36,8 @@ export class ProfitLossSheetController { res.send(sheet); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.profitLossSheetApp.table(query); + return this.profitLossSheetApp.table(query); - res.status(200).send(table); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const sheet = await this.profitLossSheetApp.xlsx(query); @@ -59,9 +58,7 @@ export class ProfitLossSheetController { }); res.send(pdfContent); } else { - const sheet = await this.profitLossSheetApp.sheet(query); - - res.status(200).send(sheet); + return this.profitLossSheetApp.sheet(query); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheetTableDatePeriods.ts b/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheetTableDatePeriods.ts index f03bdf412..b5d014bdd 100644 --- a/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheetTableDatePeriods.ts +++ b/packages/server/src/modules/FinancialStatements/modules/ProfitLossSheet/ProfitLossSheetTableDatePeriods.ts @@ -1,6 +1,6 @@ // @ts-nocheck import * as R from 'ramda'; -import moment from 'moment'; +import * as moment from 'moment'; import { ITableColumn, ITableColumnAccessor } from '../../types/Table.types'; import { ProfitLossSheetTablePercentage } from './ProfitLossSheetTablePercentage'; import { ProfitLossTablePreviousPeriod } from './ProfitLossTablePreviousPeriod'; diff --git a/packages/server/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts b/packages/server/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts index 5e8b1a52a..23a84588d 100644 --- a/packages/server/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/PurchasesByItems/PurchasesByItems.controller.ts @@ -17,14 +17,12 @@ export class PurchasesByItemReportController { @ApiOperation({ summary: 'Get purchases by items report' }) async purchasesByItems( @Query() filter: IPurchasesByItemsReportQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // JSON table response format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.purchasesByItemsApp.table(filter); - - res.status(200).send(table); + return this.purchasesByItemsApp.table(filter); // CSV response format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { const buffer = await this.purchasesByItemsApp.csv(filter); @@ -54,9 +52,7 @@ export class PurchasesByItemReportController { res.send(pdfContent); // Json response format. } else { - const sheet = await this.purchasesByItemsApp.sheet(filter); - - res.status(200).send(sheet); + return this.purchasesByItemsApp.sheet(filter); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/SalesByItems/SalesByItems.controller.ts b/packages/server/src/modules/FinancialStatements/modules/SalesByItems/SalesByItems.controller.ts index 2b4029f29..4b2edfe90 100644 --- a/packages/server/src/modules/FinancialStatements/modules/SalesByItems/SalesByItems.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/SalesByItems/SalesByItems.controller.ts @@ -23,7 +23,7 @@ export class SalesByItemsController { @ApiOperation({ summary: 'Get sales by items report' }) public async salesByitems( @Query() filter: ISalesByItemsReportQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the csv format. @@ -36,9 +36,7 @@ export class SalesByItemsController { res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.salesByItemsApp.table(filter); - - res.status(200).send(table); + return this.salesByItemsApp.table(filter); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = this.salesByItemsApp.xlsx(filter); @@ -59,8 +57,7 @@ export class SalesByItemsController { }); res.send(pdfContent); } else { - const sheet = await this.salesByItemsApp.sheet(filter); - res.status(200).send(sheet); + return this.salesByItemsApp.sheet(filter); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts index 970d8cf89..36307eb12 100644 --- a/packages/server/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/SalesTaxLiabilitySummary/SalesTaxLiabilitySummary.controller.ts @@ -1,9 +1,9 @@ +import { Response } from 'express'; +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { Controller, Get, Headers, Query, Res } from '@nestjs/common'; import { SalesTaxLiabilitySummaryQuery } from './SalesTaxLiability.types'; import { AcceptType } from '@/constants/accept-type'; import { SalesTaxLiabilitySummaryApplication } from './SalesTaxLiabilitySummaryApplication'; -import { Response } from 'express'; -import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('/reports/sales-tax-liability-summary') @ApiTags('reports') @@ -20,16 +20,16 @@ export class SalesTaxLiabilitySummaryController { @ApiOperation({ summary: 'Get sales tax liability summary report' }) public async getSalesTaxLiabilitySummary( @Query() query: SalesTaxLiabilitySummaryQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.salesTaxLiabilitySummaryApp.table(query); - res.status(200).send(table); + return this.salesTaxLiabilitySummaryApp.table(query); // Retrieves the xlsx format. } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.salesTaxLiabilitySummaryApp.xlsx(query); + res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx'); res.setHeader( 'Content-Type', @@ -52,8 +52,7 @@ export class SalesTaxLiabilitySummaryController { }); res.status(200).send(pdfContent); } else { - const sheet = await this.salesTaxLiabilitySummaryApp.sheet(query); - res.status(200).send(sheet); + return this.salesTaxLiabilitySummaryApp.sheet(query); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts b/packages/server/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts index a50deb7af..bb717e9d0 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TransactionsByCustomer/TransactionsByCustomer.controller.ts @@ -17,13 +17,12 @@ export class TransactionsByCustomerController { @ApiResponse({ status: 200, description: 'Transactions by customer' }) async transactionsByCustomer( @Query() filter: ITransactionsByCustomersFilter, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.transactionsByCustomersApp.table(filter); - res.status(200).send(table); + return this.transactionsByCustomersApp.table(filter); // Retrieve the csv format. } else if (acceptHeader.includes(AcceptType.ApplicationCsv)) { @@ -53,8 +52,7 @@ export class TransactionsByCustomerController { }); res.send(pdfContent); } else { - const sheet = await this.transactionsByCustomersApp.sheet(filter); - res.status(200).send(sheet); + return this.transactionsByCustomersApp.sheet(filter); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts b/packages/server/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts index 8086db30e..a66447523 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TransactionsByVendor/TransactionsByVendor.controller.ts @@ -17,7 +17,7 @@ export class TransactionsByVendorController { @ApiResponse({ status: 200, description: 'Transactions by vendor' }) async transactionsByVendor( @Query() filter: ITransactionsByVendorsFilter, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the xlsx format. @@ -38,9 +38,7 @@ export class TransactionsByVendorController { res.send(buffer); // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.transactionsByVendorsApp.table(filter); - - res.status(200).send(table); + return this.transactionsByVendorsApp.table(filter); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.transactionsByVendorsApp.pdf(filter); @@ -51,8 +49,7 @@ export class TransactionsByVendorController { res.send(pdfContent); // Retrieves the json format. } else { - const sheet = await this.transactionsByVendorsApp.sheet(filter); - res.status(200).send(sheet); + return this.transactionsByVendorsApp.sheet(filter); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts b/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts index a89d30f39..4787eb216 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.controller.ts @@ -18,7 +18,7 @@ export class TrialBalanceSheetController { @ApiResponse({ status: 200, description: 'Trial balance sheet' }) async getTrialBalanceSheet( @Query() query: ITrialBalanceSheetQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { const filter = { @@ -27,12 +27,11 @@ export class TrialBalanceSheetController { }; // Retrieves in json table format. if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const { table, meta, query } = - await this.trialBalanceSheetApp.table(filter); - res.status(200).send({ table, meta, query }); + return this.trialBalanceSheetApp.table(filter); // Retrieves in xlsx format } else if (acceptHeader.includes(AcceptType.ApplicationXlsx)) { const buffer = await this.trialBalanceSheetApp.xlsx(filter); + res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx'); res.setHeader( 'Content-Type', @@ -50,6 +49,7 @@ export class TrialBalanceSheetController { // Retrieves in pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.trialBalanceSheetApp.pdf(filter); + res.set({ 'Content-Type': 'application/pdf', 'Content-Length': pdfContent.length, @@ -57,9 +57,7 @@ export class TrialBalanceSheetController { res.send(pdfContent); // Retrieves in json format. } else { - const { data, query, meta } = - await this.trialBalanceSheetApp.sheet(filter); - res.status(200).send({ data, query, meta }); + return this.trialBalanceSheetApp.sheet(filter); } } } diff --git a/packages/server/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts b/packages/server/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts index b0efa4741..db5b57f29 100644 --- a/packages/server/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts +++ b/packages/server/src/modules/FinancialStatements/modules/VendorBalanceSummary/VendorBalanceSummary.controller.ts @@ -17,7 +17,7 @@ export class VendorBalanceSummaryController { @ApiResponse({ status: 200, description: 'Vendor balance summary' }) async vendorBalanceSummary( @Query() filter: IVendorBalanceSummaryQuery, - @Res() res: Response, + @Res({ passthrough: true }) res: Response, @Headers('accept') acceptHeader: string, ) { // Retrieves the csv format. @@ -38,9 +38,7 @@ export class VendorBalanceSummaryController { // Retrieves the json table format. } else if (acceptHeader.includes(AcceptType.ApplicationJsonTable)) { - const table = await this.vendorBalanceSummaryApp.table(filter); - - res.status(200).send(table); + return this.vendorBalanceSummaryApp.table(filter); // Retrieves the pdf format. } else if (acceptHeader.includes(AcceptType.ApplicationPdf)) { const pdfContent = await this.vendorBalanceSummaryApp.pdf(filter); @@ -52,8 +50,7 @@ export class VendorBalanceSummaryController { res.send(pdfContent); // Retrieves the json format. } else { - const sheet = await this.vendorBalanceSummaryApp.sheet(filter); - res.status(200).send(sheet); + return this.vendorBalanceSummaryApp.sheet(filter); } } } diff --git a/packages/server/src/modules/PaymentLinks/GetInvoicePaymentLinkMetadata.ts b/packages/server/src/modules/PaymentLinks/GetInvoicePaymentLinkMetadata.ts index f9660cf95..02691cce9 100644 --- a/packages/server/src/modules/PaymentLinks/GetInvoicePaymentLinkMetadata.ts +++ b/packages/server/src/modules/PaymentLinks/GetInvoicePaymentLinkMetadata.ts @@ -1,4 +1,4 @@ -import moment from 'moment'; +import * as moment from 'moment'; import { Inject, Injectable } from '@nestjs/common'; import { TenantModelProxy } from '../System/models/TenantBaseModel'; import { SaleInvoice } from '../SaleInvoices/models/SaleInvoice'; diff --git a/packages/server/src/modules/Roles/Roles.controller.ts b/packages/server/src/modules/Roles/Roles.controller.ts index ab79ab228..0ce6bf7f5 100644 --- a/packages/server/src/modules/Roles/Roles.controller.ts +++ b/packages/server/src/modules/Roles/Roles.controller.ts @@ -86,7 +86,7 @@ export class RolesController { @Get() @ApiOperation({ summary: 'Get all roles' }) @ApiResponse({ status: HttpStatus.OK, description: 'List of all roles' }) - async getRoles(@Res() res: Response) { + async getRoles() { const roles = await this.rolesApp.getRoles(); return { roles }; diff --git a/packages/server/src/modules/SaleInvoices/SalesInvoicesCost.ts b/packages/server/src/modules/SaleInvoices/SalesInvoicesCost.ts index 551d5bb0a..7625b8fa3 100644 --- a/packages/server/src/modules/SaleInvoices/SalesInvoicesCost.ts +++ b/packages/server/src/modules/SaleInvoices/SalesInvoicesCost.ts @@ -1,6 +1,6 @@ import { Mutex } from 'async-mutex'; import { chain } from 'lodash'; -import moment from 'moment'; +import * as moment from 'moment'; import { Knex } from 'knex'; import { Injectable } from '@nestjs/common'; import { UnitOfWork } from '../Tenancy/TenancyDB/UnitOfWork.service'; diff --git a/packages/webapp/src/hooks/query/FinancialReports/use-journal-sheet.ts b/packages/webapp/src/hooks/query/FinancialReports/use-journal-sheet.ts index 90c6cb447..61362057a 100644 --- a/packages/webapp/src/hooks/query/FinancialReports/use-journal-sheet.ts +++ b/packages/webapp/src/hooks/query/FinancialReports/use-journal-sheet.ts @@ -12,7 +12,7 @@ export function useJournalSheet(query, props) { [t.FINANCIAL_REPORT, t.JOURNAL, query], { method: 'get', - url: '/financial_statements/journal', + url: '/reports/journal', params: query, headers: { Accept: 'application/json+table',