From e763f172b32b3954bac42c8ebad1535f66c664b1 Mon Sep 17 00:00:00 2001 From: Sumrender Singh <78428003+sumrender@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:05:10 +0530 Subject: [PATCH] fix: migrate expense suggestions to platform (#3298) Co-authored-by: Arjun --- ...sonal-card-txn-expense-suggestions.data.ts | 218 ++++++++++++++++++ ...sonal-card-txn-expense-suggestion.model.ts | 8 + .../services/personal-cards.service.spec.ts | 50 ++-- .../core/services/personal-cards.service.ts | 44 +++- .../personal-cards-matched-expenses.page.html | 4 +- ...rsonal-cards-matched-expenses.page.spec.ts | 10 +- .../personal-cards-matched-expenses.page.ts | 13 +- .../personal-cards.page.spec.ts | 28 ++- .../personal-cards/personal-cards.page.ts | 35 +-- 9 files changed, 342 insertions(+), 68 deletions(-) create mode 100644 src/app/core/mock-data/personal-card-txn-expense-suggestions.data.ts create mode 100644 src/app/core/models/personal-card-txn-expense-suggestion.model.ts diff --git a/src/app/core/mock-data/personal-card-txn-expense-suggestions.data.ts b/src/app/core/mock-data/personal-card-txn-expense-suggestions.data.ts new file mode 100644 index 0000000000..b0d05ce0ba --- /dev/null +++ b/src/app/core/mock-data/personal-card-txn-expense-suggestions.data.ts @@ -0,0 +1,218 @@ +import deepFreeze from 'deep-freeze-strict'; +import { PersonalCardTxnExpenseSuggestion } from '../models/personal-card-txn-expense-suggestion.model'; + +export const platformPersonalCardTxnExpenseSuggestionsRes = deepFreeze({ + data: [ + { + accounting_export_summary: {}, + activity_details: null, + added_to_report_at: null, + admin_amount: null, + advance_wallet_id: null, + amount: 90, + approvals: [ + { + approver_user: { + email: 'aastha.b@fyle.in', + full_name: 'aastha', + id: 'usRjTPO4r69K', + }, + approver_user_id: 'usRjTPO4r69K', + state: 'APPROVAL_PENDING', + }, + ], + approver_comments: [], + category: { + code: null, + display_name: 'Unspecified', + id: 38927, + name: 'Unspecified', + sub_category: null, + system_category: 'Unspecified', + }, + category_id: 38927, + claim_amount: 90, + code: null, + commute_deduction: null, + commute_details: null, + commute_details_id: null, + cost_center: { + code: null, + id: 6335, + name: 'test-1', + }, + cost_center_id: 6335, + created_at: '2024-10-24T10:34:31.922365+00:00', + creator_user_id: 'us2KhpQLpzX4', + currency: 'USD', + custom_fields: [], + custom_fields_flattened: { + dependent_field_1: null, + pp1: null, + project_field: null, + }, + distance: null, + distance_unit: null, + employee: { + business_unit: null, + code: null, + custom_fields: [ + { + name: 'Account Number', + value: 123, + }, + ], + department: { + code: null, + display_name: '1234', + id: 'deptfOJFLA8wxt', + name: '1234', + sub_department: null, + }, + department_id: 'deptfOJFLA8wxt', + flattened_custom_field: { + account_number: 123, + }, + has_accepted_invite: true, + id: 'ou6kAM3CXV7d', + is_enabled: true, + joined_at: null, + level: null, + location: null, + mobile: '+12512603805', + org_id: 'orrb8EW1zZsy', + org_name: 'CCC - Multiple statement support - USD', + title: null, + user: { + email: 'kavya.hl@fyle.in', + full_name: 'Kavya 2', + id: 'us2KhpQLpzX4', + }, + user_id: 'us2KhpQLpzX4', + }, + employee_id: 'ou6kAM3CXV7d', + ended_at: null, + expense_rule_data: null, + expense_rule_id: null, + extracted_data: null, + file_ids: [], + files: [], + foreign_amount: null, + foreign_currency: null, + hotel_is_breakfast_provided: false, + id: 'txhoujHIA4OD', + invoice_number: null, + is_billable: true, + is_corporate_card_transaction_auto_matched: false, + is_duplicate_present: false, + is_exported: null, + is_manually_flagged: null, + is_physical_bill_submitted: null, + is_policy_flagged: null, + is_receipt_mandatory: null, + is_reimbursable: true, + is_split: false, + is_verified: false, + last_exported_at: null, + last_settled_at: null, + last_verified_at: null, + locations: [], + matched_corporate_card_transaction_ids: [], + matched_corporate_card_transactions: [], + merchant: 'UTILITY BILL PAYMENT', + mileage_calculated_amount: null, + mileage_calculated_distance: null, + mileage_is_round_trip: null, + mileage_rate: null, + mileage_rate_id: null, + missing_mandatory_fields: { + amount: false, + currency: false, + expense_field_ids: [], + receipt: true, + }, + org_id: 'orrb8EW1zZsy', + per_diem_num_days: null, + per_diem_rate: null, + per_diem_rate_id: null, + physical_bill_submitted_at: null, + policy_amount: null, + policy_checks: { + are_approvers_added: false, + is_amount_limit_applied: false, + is_flagged_ever: false, + violations: null, + }, + project: { + code: null, + display_name: 'asdf', + id: 305743, + name: 'asdf', + sub_project: null, + }, + project_id: 305743, + purpose: 'UTILITY BILL PAYMENT', + report: null, + report_id: null, + report_last_approved_at: null, + report_last_paid_at: null, + seq_num: 'E/2024/10/T/21', + source: 'WEBAPP', + source_account: { + id: 'acc8vyjNsN3zh', + type: 'PERSONAL_CASH_ACCOUNT', + }, + source_account_id: 'acc8vyjNsN3zh', + spent_at: new Date('2024-09-11T00:00:00+00:00'), + split_group_amount: null, + split_group_id: 'txhoujHIA4OD', + started_at: null, + state: 'DRAFT', + state_display_name: 'Incomplete', + tax_amount: 16.83, + tax_group: { + name: 'GST', + percentage: 0.23, + }, + tax_group_id: 'tg6RDX1flCnt', + travel_classes: [], + updated_at: '2024-10-24T10:34:36.313431+00:00', + user: { + email: 'kavya.hl@fyle.in', + full_name: 'Kavya 2', + id: 'us2KhpQLpzX4', + }, + user_id: 'us2KhpQLpzX4', + verifications: [], + verifier_comments: [], + }, + ], +}); + +export const platformPersonalCardTxnExpenseSuggestions = deepFreeze([ + { + purpose: 'UTILITY BILL PAYMENT', + vendor: 'UTILITY BILL PAYMENT', + txn_dt: new Date('2024-09-11T00:00:00+00:00'), + currency: 'USD', + amount: 90, + split_group_id: 'txhoujHIA4OD', + }, +]); + +export const publicPersonalCardTxnExpenseSuggestionsRes: PersonalCardTxnExpenseSuggestion[] = deepFreeze([ + { + id: 'txsZt7eBrWHN', + txn_dt: new Date('2024-09-14T00:00:00.000Z'), + amount: 20, + currency: 'USD', + split_group_id: 'txsZt7eBrWHN', + split_group_user_amount: 20, + orig_amount: null, + orig_currency: null, + purpose: 'sumrender ONLINE SUBSCRIPTION', + vendor: 'ONLINE SUBSCRIPTION', + ranking: 1, + distance: 0.0, + }, +]); diff --git a/src/app/core/models/personal-card-txn-expense-suggestion.model.ts b/src/app/core/models/personal-card-txn-expense-suggestion.model.ts new file mode 100644 index 0000000000..8e32558af5 --- /dev/null +++ b/src/app/core/models/personal-card-txn-expense-suggestion.model.ts @@ -0,0 +1,8 @@ +export interface PersonalCardTxnExpenseSuggestion { + purpose: string; + vendor: string; + txn_dt: Date; + currency: string; + amount: number; + split_group_id: string; +} diff --git a/src/app/core/services/personal-cards.service.spec.ts b/src/app/core/services/personal-cards.service.spec.ts index 3321533f23..9c20154875 100644 --- a/src/app/core/services/personal-cards.service.spec.ts +++ b/src/app/core/services/personal-cards.service.spec.ts @@ -34,6 +34,11 @@ import * as dayjs from 'dayjs'; import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service'; import { PlatformPersonalCardQueryParams } from '../models/platform/platform-personal-card-query-params.model'; import { personalCardAccessTokenResponse } from '../mock-data/personal-cards-access-token.data'; +import { + platformPersonalCardTxnExpenseSuggestions, + platformPersonalCardTxnExpenseSuggestionsRes, + publicPersonalCardTxnExpenseSuggestionsRes, +} from '../mock-data/personal-card-txn-expense-suggestions.data'; describe('PersonalCardsService', () => { let personalCardsService: PersonalCardsService; @@ -1423,34 +1428,37 @@ describe('PersonalCardsService', () => { }); }); - it('getMatchedExpenses(): should get matched expenses', (done) => { - apiService.get.and.returnValue(of(apiExpenseRes)); + describe('getMatchedExpensesSuggestions()', () => { + it('should get expense suggestions using public api', (done) => { + apiService.get.and.returnValue(of(publicPersonalCardTxnExpenseSuggestionsRes)); - const amount = 3; - const txnDate = '2021-07-29T06:30:00.000Z'; + const amount = 3; + const txnDate = '2021-07-29T06:30:00.000Z'; + const usePlatformApi = false; - personalCardsService.getMatchedExpenses(amount, txnDate).subscribe((res) => { - expect(res).toEqual(apiExpenseRes); - expect(apiService.get).toHaveBeenCalledOnceWith('/expense_suggestions/personal_cards', { - params: { - amount, - txn_dt: txnDate, - }, + personalCardsService.getMatchedExpensesSuggestions(amount, txnDate, usePlatformApi).subscribe((res) => { + expect(res).toEqual(publicPersonalCardTxnExpenseSuggestionsRes); + expect(apiService.get).toHaveBeenCalledOnceWith('/expense_suggestions/personal_cards', { + params: { + amount, + txn_dt: txnDate, + }, + }); + done(); }); - done(); }); - }); - it('getMatchedExpensesCount(): should get matched expenses count', (done) => { - spyOn(personalCardsService, 'getMatchedExpenses').and.returnValue(of(apiExpenseRes)); + it('should get expense suggestions using platform api', (done) => { + spenderPlatformV1ApiService.get.and.returnValue(of(platformPersonalCardTxnExpenseSuggestionsRes)); - const amount = 3; - const txnDate = '2021-07-29T06:30:00.000Z'; + const amount = 3; + const txnDate = '2021-07-29T06:30:00.000Z'; + const usePlatformApi = true; - personalCardsService.getMatchedExpensesCount(amount, txnDate).subscribe((res) => { - expect(res).toEqual(apiExpenseRes.length); - expect(personalCardsService.getMatchedExpenses).toHaveBeenCalledOnceWith(amount, txnDate); - done(); + personalCardsService.getMatchedExpensesSuggestions(amount, txnDate, usePlatformApi).subscribe((res) => { + expect(res).toEqual(platformPersonalCardTxnExpenseSuggestions); + done(); + }); }); }); diff --git a/src/app/core/services/personal-cards.service.ts b/src/app/core/services/personal-cards.service.ts index 58c06dac9a..8a69f88dea 100644 --- a/src/app/core/services/personal-cards.service.ts +++ b/src/app/core/services/personal-cards.service.ts @@ -7,7 +7,7 @@ import { PersonalCardFilter } from '../models/personal-card-filters.model'; import { ApiV2Service } from './api-v2.service'; import { ApiService } from './api.service'; import { ExpenseAggregationService } from './expense-aggregation.service'; -import { Expense } from '../models/expense.model'; +import { Expense } from '../models/platform/v1/expense.model'; import { DateService } from './date.service'; import { SelectedFilters } from 'src/app/shared/components/fy-filters/selected-filters.interface'; import { DateFilters } from 'src/app/shared/components/fy-filters/date-filters.enum'; @@ -26,6 +26,7 @@ import { TxnDetail } from '../models/v2/txn-detail.model'; import { PlatformPersonalCardQueryParams } from '../models/platform/platform-personal-card-query-params.model'; import { PersonalCardSyncTxns } from '../models/platform/platform-personal-card-syn-txns.model'; import { environment } from 'src/environments/environment'; +import { PersonalCardTxnExpenseSuggestion } from '../models/personal-card-txn-expense-suggestion.model'; @Injectable({ providedIn: 'root', @@ -107,6 +108,20 @@ export class PersonalCardsService { }); } + transformPlatformPersonalCardTxnExpenseSuggestions(expenses: Expense[]): PersonalCardTxnExpenseSuggestion[] { + return expenses.map((expense) => { + const expenseSuggestion: PersonalCardTxnExpenseSuggestion = { + purpose: expense.purpose, + vendor: expense.merchant, + txn_dt: expense.spent_at, + currency: expense.currency, + amount: expense.amount, + split_group_id: expense.split_group_id, + }; + return expenseSuggestion; + }); + } + mapPublicQueryParamsToPlatform(queryParams: { btxn_status?: string; ba_id?: string; @@ -223,7 +238,28 @@ export class PersonalCardsService { .pipe(map((res) => res.count)); } - getMatchedExpenses(amount: number, txnDate: string): Observable { + getMatchedExpensesSuggestionsPlatform( + amount: number, + txnDate: string + ): Observable { + return this.spenderPlatformV1ApiService + .get>('/personal_card_transactions/expense_suggestion', { + params: { + amount, + spent_at: txnDate, + }, + }) + .pipe(map((res) => this.transformPlatformPersonalCardTxnExpenseSuggestions(res.data))); + } + + getMatchedExpensesSuggestions( + amount: number, + txnDate: string, + usePlatformApi: boolean + ): Observable { + if (usePlatformApi) { + return this.getMatchedExpensesSuggestionsPlatform(amount, txnDate); + } return this.apiService.get('/expense_suggestions/personal_cards', { params: { amount, @@ -321,10 +357,6 @@ export class PersonalCardsService { }); } - getMatchedExpensesCount(amount: number, txnDate: string): Observable { - return this.getMatchedExpenses(amount, txnDate).pipe(map((res) => res.length)); - } - matchExpensePlatform( transactionSplitGroupId: string, externalExpenseId: string diff --git a/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.html b/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.html index 4ff5b95b69..125fd4a339 100644 --- a/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.html +++ b/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.html @@ -47,8 +47,8 @@
SELECT A MATCHING EXPENSE
- - + +
diff --git a/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.spec.ts b/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.spec.ts index 69c4e8138d..138b4514d1 100644 --- a/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.spec.ts +++ b/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.spec.ts @@ -2,7 +2,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { Navigation, Router, RouterModule, UrlSerializer, UrlTree } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { IonicModule, ModalController } from '@ionic/angular'; -import { of } from 'rxjs'; import { apiExpenseRes } from 'src/app/core/mock-data/expense.data'; import { apiPersonalCardTxnsRes } from 'src/app/core/mock-data/personal-card-txns.data'; import { ModalPropertiesService } from 'src/app/core/services/modal-properties.service'; @@ -10,7 +9,6 @@ import { PersonalCardsService } from 'src/app/core/services/personal-cards.servi import { PersonalCardsMatchedExpensesPage } from './personal-cards-matched-expenses.page'; import { CurrencyPipe, DatePipe } from '@angular/common'; import { CurrencySymbolPipe } from 'src/app/shared/pipes/currency-symbol.pipe'; -import * as dayjs from 'dayjs'; import { ExpensePreviewComponent } from './expense-preview/expense-preview.component'; import { click, getElementBySelector, getTextContent } from 'src/app/core/dom-helpers'; @@ -23,7 +21,7 @@ describe('PersonalCardsMatchedExpensesPage', () => { let modalPropertiesService: jasmine.SpyObj; const data: Navigation = { - extras: { state: { txnDetails: apiPersonalCardTxnsRes.data[0] } }, + extras: { state: { txnDetails: apiPersonalCardTxnsRes.data[0], expenseSuggestions: apiExpenseRes } }, id: 0, initialUrl: '', extractedUrl: new UrlTree(), @@ -62,6 +60,7 @@ describe('PersonalCardsMatchedExpensesPage', () => { fixture = TestBed.createComponent(PersonalCardsMatchedExpensesPage); component = fixture.componentInstance; component.txnDetails = data.extras.state.txnDetails; + component.expenseSuggestions = data.extras.state.expenseSuggestions; fixture.detectChanges(); })); @@ -71,11 +70,8 @@ describe('PersonalCardsMatchedExpensesPage', () => { it('should set matched expenses and display information correctly', () => { component.txnDetails = data.extras.state.txnDetails; - const txnDate = dayjs(component.txnDetails.btxn_transaction_dt).format('YYYY-MM-DD'); - personalCardsService.getMatchedExpenses.and.returnValue(of(apiExpenseRes)); + component.expenseSuggestions = data.extras.state.expenseSuggestions; fixture.detectChanges(); - component.ionViewWillEnter(); - expect(personalCardsService.getMatchedExpenses).toHaveBeenCalledOnceWith(component.txnDetails.btxn_amount, txnDate); expect(getTextContent(getElementBySelector(fixture, '.matched-expenses--purpose'))).toEqual( component.txnDetails.btxn_description diff --git a/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.ts b/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.ts index e5b1e35436..b54eb264c4 100644 --- a/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.ts +++ b/src/app/fyle/personal-cards-matched-expenses/personal-cards-matched-expenses.page.ts @@ -1,12 +1,11 @@ import { Component } from '@angular/core'; import { HeaderState } from '../../shared/components/fy-header/header-state.enum'; -import { PersonalCardsService } from 'src/app/core/services/personal-cards.service'; import { Router } from '@angular/router'; import { ModalController } from '@ionic/angular'; import { ExpensePreviewComponent } from './expense-preview/expense-preview.component'; import { ModalPropertiesService } from 'src/app/core/services/modal-properties.service'; -import * as dayjs from 'dayjs'; import { PersonalCardTxn } from 'src/app/core/models/personal_card_txn.model'; +import { PersonalCardTxnExpenseSuggestion } from 'src/app/core/models/personal-card-txn-expense-suggestion.model'; @Component({ selector: 'app-personal-cards-matched-expenses', templateUrl: './personal-cards-matched-expenses.page.html', @@ -19,20 +18,16 @@ export class PersonalCardsMatchedExpensesPage { txnDetails: PersonalCardTxn; - matchedExpenses$; + expenseSuggestions: PersonalCardTxnExpenseSuggestion[]; constructor( - private personalCardsService: PersonalCardsService, private router: Router, private modalController: ModalController, private modalProperties: ModalPropertiesService ) { this.txnDetails = this.router.getCurrentNavigation().extras.state.txnDetails as PersonalCardTxn; - } - - ionViewWillEnter(): void { - const txnDate = dayjs(this.txnDetails.btxn_transaction_dt).format('YYYY-MM-DD'); - this.matchedExpenses$ = this.personalCardsService.getMatchedExpenses(this.txnDetails.btxn_amount, txnDate); + this.expenseSuggestions = this.router.getCurrentNavigation().extras.state + .expenseSuggestions as PersonalCardTxnExpenseSuggestion[]; } createExpense(): void { diff --git a/src/app/fyle/personal-cards/personal-cards.page.spec.ts b/src/app/fyle/personal-cards/personal-cards.page.spec.ts index 92be19de05..f5ab98ae12 100644 --- a/src/app/fyle/personal-cards/personal-cards.page.spec.ts +++ b/src/app/fyle/personal-cards/personal-cards.page.spec.ts @@ -43,6 +43,7 @@ import { PersonalCardsPage } from './personal-cards.page'; import { PersonalCardFilter } from 'src/app/core/models/personal-card-filters.model'; import { LaunchDarklyService } from 'src/app/core/services/launch-darkly.service'; import { PersonalCard } from 'src/app/core/models/personal_card.model'; +import { publicPersonalCardTxnExpenseSuggestionsRes } from 'src/app/core/mock-data/personal-card-txn-expense-suggestions.data'; describe('PersonalCardsPage', () => { let component: PersonalCardsPage; @@ -79,8 +80,8 @@ describe('PersonalCardsPage', () => { 'convertFilters', 'generateTxnDateParams', 'generateCreditParams', - 'getMatchedExpensesCount', 'generateDateParams', + 'getMatchedExpensesSuggestions', ]); const networkServiceSpy = jasmine.createSpyObj('NetworkService', ['connectivityWatcher', 'isOnline']); const routerSpy = jasmine.createSpyObj('Router', ['navigate']); @@ -692,13 +693,15 @@ describe('PersonalCardsPage', () => { it('should create an expense and navigate to add edit expense if count is 0', () => { component.selectionMode = false; component.loadingMatchedExpenseCount = false; - personalCardsService.getMatchedExpensesCount.and.returnValue(of(0)); + const usePlatformApi = false; + personalCardsService.getMatchedExpensesSuggestions.and.returnValue(of([])); component.createExpense(apiPersonalCardTxnsRes.data[0]); - expect(personalCardsService.getMatchedExpensesCount).toHaveBeenCalledOnceWith( + expect(personalCardsService.getMatchedExpensesSuggestions).toHaveBeenCalledOnceWith( apiPersonalCardTxnsRes.data[0].btxn_amount, - '2021-09-19' + '2021-09-19', + usePlatformApi ); expect(router.navigate).toHaveBeenCalledOnceWith([ '/', @@ -711,16 +714,23 @@ describe('PersonalCardsPage', () => { it('should create an expense and navigate to personal cards page if count is more than 0', () => { component.selectionMode = false; component.loadingMatchedExpenseCount = false; - personalCardsService.getMatchedExpensesCount.and.returnValue(of(1)); + const usePlatformApi = false; + personalCardsService.getMatchedExpensesSuggestions.and.returnValue( + of(publicPersonalCardTxnExpenseSuggestionsRes) + ); component.createExpense(apiPersonalCardTxnsRes.data[0]); - expect(personalCardsService.getMatchedExpensesCount).toHaveBeenCalledOnceWith( + expect(personalCardsService.getMatchedExpensesSuggestions).toHaveBeenCalledOnceWith( apiPersonalCardTxnsRes.data[0].btxn_amount, - '2021-09-19' + '2021-09-19', + usePlatformApi ); expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'personal_cards_matched_expenses'], { - state: { txnDetails: apiPersonalCardTxnsRes.data[0] }, + state: { + txnDetails: apiPersonalCardTxnsRes.data[0], + expenseSuggestions: publicPersonalCardTxnExpenseSuggestionsRes, + }, }); }); @@ -730,7 +740,7 @@ describe('PersonalCardsPage', () => { component.createExpense(matchedPersonalCardTxn); - expect(personalCardsService.getMatchedExpensesCount).not.toHaveBeenCalled(); + expect(personalCardsService.getMatchedExpensesSuggestions).not.toHaveBeenCalled(); }); it('should open expense if the expense has been matched', () => { diff --git a/src/app/fyle/personal-cards/personal-cards.page.ts b/src/app/fyle/personal-cards/personal-cards.page.ts index 23e8e3215d..2d3b5ee18b 100644 --- a/src/app/fyle/personal-cards/personal-cards.page.ts +++ b/src/app/fyle/personal-cards/personal-cards.page.ts @@ -746,20 +746,27 @@ export class PersonalCardsPage implements OnInit, AfterViewInit { this.loadingMatchedExpenseCount = true; this.loadingTxnId = txnDetails.btxn_id; - this.personalCardsService.getMatchedExpensesCount(txnDetails.btxn_amount, txnDate).subscribe((count) => { - this.loadingMatchedExpenseCount = false; - this.loadingTxnId = null; - if (count === 0) { - this.router.navigate([ - '/', - 'enterprise', - 'add_edit_expense', - { personalCardTxn: JSON.stringify(txnDetails), navigate_back: true }, - ]); - } else { - this.router.navigate(['/', 'enterprise', 'personal_cards_matched_expenses'], { state: { txnDetails } }); - } - }); + this.personalCardsService + .getMatchedExpensesSuggestions(txnDetails.btxn_amount, txnDate, this.usePlatformApi) + .subscribe((expenseSuggestions) => { + this.loadingMatchedExpenseCount = false; + this.loadingTxnId = null; + if (expenseSuggestions.length === 0) { + this.router.navigate([ + '/', + 'enterprise', + 'add_edit_expense', + { personalCardTxn: JSON.stringify(txnDetails), navigate_back: true }, + ]); + } else { + this.router.navigate(['/', 'enterprise', 'personal_cards_matched_expenses'], { + state: { + txnDetails, + expenseSuggestions, + }, + }); + } + }); } async openExpensePreview(txnDetails: PersonalCardTxn): Promise {