Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha committed Apr 29, 2024
1 parent c7a604f commit c11842b
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 80 deletions.
70 changes: 60 additions & 10 deletions src/app/core/mock-data/report-stats.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 6 additions & 5 deletions src/app/core/models/report-stats.model.ts
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 3 additions & 2 deletions src/app/core/services/platform/v1/approver/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -53,9 +54,9 @@ export class ApproverReportsService {
return this.approverPlatformApiService.get<PlatformApiResponse<Report>>('/reports', config);
}

getReportsStats(params: PlatformStatsRequestParams): Observable<StatsResponse> {
getReportsStats(params: PlatformStatsRequestParams): Observable<ReportsStatsResponsePlatform> {
return this.approverPlatformApiService
.post<{ data: StatsResponse }>('/reports/stats', {
.post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', {
data: {
query_params: `state=${params.state}`,
},
Expand Down
5 changes: 3 additions & 2 deletions src/app/core/services/platform/v1/spender/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -85,9 +86,9 @@ export class SpenderReportsService {
return this.spenderPlatformV1ApiService.post<void>('/reports/eject_expenses', payload);
}

getReportsStats(params: PlatformStatsRequestParams): Observable<StatsResponse> {
getReportsStats(params: PlatformStatsRequestParams): Observable<ReportsStatsResponsePlatform> {
return this.spenderPlatformV1ApiService
.post<{ data: StatsResponse }>('/reports/stats', {
.post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', {
data: {
query_params: `state=${params.state}`,
},
Expand Down
62 changes: 10 additions & 52 deletions src/app/fyle/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<CCCDetails> {
return this.corporateCreditCardExpenseService.getAssignedCards();
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/fyle/dashboard/stats/stats.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
></app-stat-badge>
</ion-col>
Expand All @@ -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)"
></app-stat-badge>
</ion-col>
Expand All @@ -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)"
></app-stat-badge>
</ion-col>
Expand All @@ -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)"
></app-stat-badge>
</ng-container>
Expand All @@ -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)"
></app-stat-badge>
</ng-template>
Expand Down
10 changes: 6 additions & 4 deletions src/app/fyle/dashboard/stats/stats.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ 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',
templateUrl: './stats.component.html',
styleUrls: ['./stats.component.scss'],
})
export class StatsComponent implements OnInit {
draftStats$: Observable<{ count: number; sum: number }>;
draftStats$: Observable<ReportsStatsResponsePlatform>;

approvedStats$: Observable<{ count: number; sum: number }>;
approvedStats$: Observable<ReportsStatsResponsePlatform>;

paymentPendingStats$: Observable<{ count: number; sum: number }>;
paymentPendingStats$: Observable<ReportsStatsResponsePlatform>;

processingStats$: Observable<{ count: number; sum: number }>;
processingStats$: Observable<ReportsStatsResponsePlatform>;

homeCurrency$: Observable<string>;

Expand Down

0 comments on commit c11842b

Please sign in to comment.