From c11842b463c8412a46ddc8752e08c1079c3de87f Mon Sep 17 00:00:00 2001 From: aastha Date: Mon, 29 Apr 2024 10:27:01 +0530 Subject: [PATCH] Minor --- src/app/core/mock-data/report-stats.data.ts | 70 ++++++++++++++++--- .../v1/report-stats-response.model.ts | 9 +++ src/app/core/models/report-stats.model.ts | 11 +-- .../platform/v1/approver/reports.service.ts | 5 +- .../platform/v1/spender/reports.service.ts | 5 +- src/app/fyle/dashboard/dashboard.service.ts | 62 +++------------- .../fyle/dashboard/stats/stats.component.html | 10 +-- .../fyle/dashboard/stats/stats.component.ts | 10 +-- 8 files changed, 102 insertions(+), 80 deletions(-) create mode 100644 src/app/core/models/platform/v1/report-stats-response.model.ts diff --git a/src/app/core/mock-data/report-stats.data.ts b/src/app/core/mock-data/report-stats.data.ts index fccb6d9720..89d6ade35a 100644 --- a/src/app/core/mock-data/report-stats.data.ts +++ b/src/app/core/mock-data/report-stats.data.ts @@ -3,45 +3,95 @@ import { ReportStats } from '../models/report-stats.model'; export const expectedReportStats: ReportStats = { draft: { count: 6, - sum: 93165.91, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, + total_amount: 93165.91, }, report: { count: 45, - sum: 5177243929.65219, + total_amount: 5177243929.65219, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, approved: { count: 56, - sum: 28758273650702.816, + total_amount: 28758273650702.816, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, paymentPending: { count: 4, - sum: 501602.12, + total_amount: 501602.12, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, processing: { count: 7, - sum: 5012.12, + total_amount: 5012.12, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, }; export const expectedEmptyReportStats: ReportStats = { draft: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, report: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, approved: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, paymentPending: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, processing: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, }; diff --git a/src/app/core/models/platform/v1/report-stats-response.model.ts b/src/app/core/models/platform/v1/report-stats-response.model.ts new file mode 100644 index 0000000000..2648c910cd --- /dev/null +++ b/src/app/core/models/platform/v1/report-stats-response.model.ts @@ -0,0 +1,9 @@ +export interface ReportsStatsResponsePlatform { + count: number; + failed_amount: number; + failed_count: number; + processing_amount: number; + processing_count: number; + reimbursable_amount: number; + total_amount: number; +} diff --git a/src/app/core/models/report-stats.model.ts b/src/app/core/models/report-stats.model.ts index 81c0285fb6..5aac064b5e 100644 --- a/src/app/core/models/report-stats.model.ts +++ b/src/app/core/models/report-stats.model.ts @@ -1,9 +1,10 @@ +import { ReportsStatsResponsePlatform } from './platform/v1/report-stats-response.model'; import { StatsResponse } from './platform/v1/stats-response.model'; export interface ReportStats { - draft: StatsResponse; - report: StatsResponse; - approved: StatsResponse; - paymentPending: StatsResponse; - processing: StatsResponse; + draft: ReportsStatsResponsePlatform; + report: ReportsStatsResponsePlatform; + approved: ReportsStatsResponsePlatform; + paymentPending: ReportsStatsResponsePlatform; + processing: ReportsStatsResponsePlatform; } diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 0905bd1171..b7c5e74fa4 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -7,6 +7,7 @@ import { PAGINATION_SIZE } from 'src/app/constants'; import { Report } from 'src/app/core/models/platform/v1/report.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; +import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Injectable({ providedIn: 'root', @@ -53,9 +54,9 @@ export class ApproverReportsService { return this.approverPlatformApiService.get>('/reports', config); } - getReportsStats(params: PlatformStatsRequestParams): Observable { + getReportsStats(params: PlatformStatsRequestParams): Observable { return this.approverPlatformApiService - .post<{ data: StatsResponse }>('/reports/stats', { + .post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', { data: { query_params: `state=${params.state}`, }, diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index e4f1b2d58d..b97969cf83 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -10,6 +10,7 @@ import { CreateDraftParams } from 'src/app/core/models/platform/v1/create-draft- import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-payload.model'; import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; +import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Injectable({ providedIn: 'root', @@ -85,9 +86,9 @@ export class SpenderReportsService { return this.spenderPlatformV1ApiService.post('/reports/eject_expenses', payload); } - getReportsStats(params: PlatformStatsRequestParams): Observable { + getReportsStats(params: PlatformStatsRequestParams): Observable { return this.spenderPlatformV1ApiService - .post<{ data: StatsResponse }>('/reports/stats', { + .post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', { data: { query_params: `state=${params.state}`, }, diff --git a/src/app/fyle/dashboard/dashboard.service.ts b/src/app/fyle/dashboard/dashboard.service.ts index d7e0bfa9c6..cd3846016d 100644 --- a/src/app/fyle/dashboard/dashboard.service.ts +++ b/src/app/fyle/dashboard/dashboard.service.ts @@ -9,8 +9,6 @@ import { Stats } from '../../core/models/stats.model'; import { StatsResponse } from '../../core/models/v2/stats-response.model'; import { ReportService } from '../../core/services/report.service'; import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; -import { report } from 'process'; -import { approversData1 } from 'src/app/core/mock-data/approver.data'; @Injectable() export class DashboardService { @@ -61,61 +59,21 @@ export class DashboardService { state: 'eq.APPROVED', }); const paymentPendingStats = this.spenderReportsService.getReportsStats({ - state: 'eq.DRAFT', + state: 'eq.PAYMENT_PENDING', }); - const draftStats = this.spenderReportsService.getReportsStats({ - state: 'eq.DRAFT', + const paymentProcessingStats = this.spenderReportsService.getReportsStats({ + state: 'eq.PAYMENT_PROCESSING', + }); + const reportStatsObservable$ = forkJoin({ + draft: draftStats, + report: reportedStats, + approved: approvedStats, + paymentPending: paymentPendingStats, + processing: paymentProcessingStats, }); - const reportStatsObservable$ = forkJoin([]); - draft; - report; - approvers; - paymentPending; - paymentProcessing; return reportStatsObservable$; } - getReportAggregates(reportsStatsResponse: StatsResponse): ReportStats { - const reportDatum = reportsStatsResponse.getDatum(0); - const reportAggregateValues = reportDatum.value; - const stateWiseAggregatesMap = reportAggregateValues - .map((reportAggregateValue) => { - const key = reportAggregateValue.key[0].column_value; - const countAggregate = reportAggregateValue.aggregates.find( - (aggregate) => aggregate.function_name === 'count(rp_id)' - ); - const sumAggregate = reportAggregateValue.aggregates.find( - (aggregate) => aggregate.function_name === 'sum(rp_amount)' - ); - return { - key, - count: countAggregate && countAggregate.function_value, - sum: sumAggregate && sumAggregate.function_value, - }; - }) - .reduce((acc, curr) => { - acc[curr.key] = { - count: curr.count, - sum: curr.sum, - }; - return acc; - }, {} as { [key: string]: { count: number; sum: number } }); - - const draftReportStats = stateWiseAggregatesMap.DRAFT || { sum: 0, count: 0 }; - const reportedReportStats = stateWiseAggregatesMap.APPROVER_PENDING || { sum: 0, count: 0 }; - const approvedReportStats = stateWiseAggregatesMap.APPROVED || { sum: 0, count: 0 }; - const paymentPendingReportStats = stateWiseAggregatesMap.PAYMENT_PENDING || { sum: 0, count: 0 }; - const processingReportStats = stateWiseAggregatesMap.PAYMENT_PROCESSING || { sum: 0, count: 0 }; - - return { - draft: draftReportStats, - report: reportedReportStats, - approved: approvedReportStats, - paymentPending: paymentPendingReportStats, - processing: processingReportStats, - }; - } - getCCCDetails(): Observable { return this.corporateCreditCardExpenseService.getAssignedCards(); } diff --git a/src/app/fyle/dashboard/stats/stats.component.html b/src/app/fyle/dashboard/stats/stats.component.html index 837864ffa1..40220b269a 100644 --- a/src/app/fyle/dashboard/stats/stats.component.html +++ b/src/app/fyle/dashboard/stats/stats.component.html @@ -15,7 +15,7 @@ [name]="'Draft'" [reportState]="ReportStates.DRAFT" [count]="reportStatsData.reportStats?.draft?.count" - [value]="reportStatsData.reportStats?.draft?.sum" + [value]="reportStatsData.reportStats?.draft?.total_amount" (badgeClicked)="goToReportsPage($event)" > @@ -26,7 +26,7 @@ [name]="reportStatsData.simplifyReportsSettings.enabled ? 'Submitted' : 'Reported'" [reportState]="ReportStates.APPROVER_PENDING" [count]="reportStatsData.reportStats?.report?.count" - [value]="reportStatsData.reportStats?.report?.sum" + [value]="reportStatsData.reportStats?.report?.total_amount" (badgeClicked)="goToReportsPage($event)" > @@ -42,7 +42,7 @@ [name]="'Approved'" [reportState]="ReportStates.APPROVED" [count]="reportStatsData.reportStats?.approved?.count" - [value]="reportStatsData.reportStats?.approved?.sum" + [value]="reportStatsData.reportStats?.approved?.total_amount" (badgeClicked)="goToReportsPage($event)" > @@ -57,7 +57,7 @@ [name]="'Processing'" [reportState]="ReportStates.PAYMENT_PROCESSING" [count]="reportStatsData.reportStats?.processing?.count" - [value]="reportStatsData.reportStats?.processing?.sum" + [value]="reportStatsData.reportStats?.processing?.total_amount" (badgeClicked)="goToReportsPage($event)" > @@ -68,7 +68,7 @@ [name]="'Payment Pending'" [reportState]="ReportStates.PAYMENT_PENDING" [count]="reportStatsData.reportStats?.paymentPending?.count" - [value]="reportStatsData.reportStats?.paymentPending?.sum" + [value]="reportStatsData.reportStats?.paymentPending?.total_amount" (badgeClicked)="goToReportsPage($event)" > diff --git a/src/app/fyle/dashboard/stats/stats.component.ts b/src/app/fyle/dashboard/stats/stats.component.ts index 47db5fe852..ff86ee6f21 100644 --- a/src/app/fyle/dashboard/stats/stats.component.ts +++ b/src/app/fyle/dashboard/stats/stats.component.ts @@ -15,6 +15,8 @@ import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { OrgService } from 'src/app/core/services/org.service'; import { PaymentModesService } from 'src/app/core/services/payment-modes.service'; import { ReportStatsData } from 'src/app/core/models/report-stats-data.model'; +import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; +import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Component({ selector: 'app-stats', @@ -22,13 +24,13 @@ import { ReportStatsData } from 'src/app/core/models/report-stats-data.model'; styleUrls: ['./stats.component.scss'], }) export class StatsComponent implements OnInit { - draftStats$: Observable<{ count: number; sum: number }>; + draftStats$: Observable; - approvedStats$: Observable<{ count: number; sum: number }>; + approvedStats$: Observable; - paymentPendingStats$: Observable<{ count: number; sum: number }>; + paymentPendingStats$: Observable; - processingStats$: Observable<{ count: number; sum: number }>; + processingStats$: Observable; homeCurrency$: Observable;