Skip to content

Commit

Permalink
fix: round off mileage amount (#3099)
Browse files Browse the repository at this point in the history
* fix: round off mileage amount

* moved interface to separate file
  • Loading branch information
suyashpatil78 authored Jul 2, 2024
1 parent 7541aaf commit ad0460e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/app/core/models/location-info.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Position } from '@capacitor/geolocation';
import { ExtendedOrgUser } from './extended-org-user.model';

export interface LocationInfo {
recentStartLocation: string;
eou: ExtendedOrgUser;
currentLocation: Position;
}
22 changes: 11 additions & 11 deletions src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ChangeDetectorRef, Component, ElementRef, EventEmitter, HostListener, O
import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ActivatedRoute, Router } from '@angular/router';
import { Position } from '@capacitor/geolocation';
import { ModalController, NavController, PopoverController } from '@ionic/angular';
import * as dayjs from 'dayjs';
import { cloneDeep, intersection, isEmpty, isEqual, isNumber } from 'lodash';
Expand Down Expand Up @@ -43,7 +42,6 @@ import { CostCenterOptions } from 'src/app/core/models/cost-center-options.model
import { Destination } from 'src/app/core/models/destination.model';
import { Expense } from 'src/app/core/models/expense.model';
import { ExtendedAccount } from 'src/app/core/models/extended-account.model';
import { ExtendedOrgUser } from 'src/app/core/models/extended-org-user.model';
import { ExtendedStatus } from 'src/app/core/models/extended_status.model';
import { FileObject } from 'src/app/core/models/file-obj.model';
import { Location } from 'src/app/core/models/location.model';
Expand Down Expand Up @@ -113,6 +111,7 @@ import { MileageFormValue } from 'src/app/core/models/mileage-form-value.model';
import { CommuteDetailsResponse } from 'src/app/core/models/platform/commute-details-response.model';
import { AdvanceWallet } from 'src/app/core/models/platform/v1/advance-wallet.model';
import { AdvanceWalletsService } from 'src/app/core/services/platform/v1/spender/advance-wallets.service';
import { LocationInfo } from 'src/app/core/models/location-info.model';

@Component({
selector: 'app-add-edit-mileage',
Expand Down Expand Up @@ -832,8 +831,6 @@ export class AddEditMileagePage implements OnInit {
mileageRates: this.mileageRates$,
}).pipe(map(({ defaultVehicle, mileageRates }) => this.getMileageByVehicleType(mileageRates, defaultVehicle)));

type locationInfo = { recentStartLocation: string; eou: ExtendedOrgUser; currentLocation: Position };

const autofillLocation$ = forkJoin({
eou: this.authService.getEou(),
currentLocation: this.locationService.getCurrentLocation(),
Expand Down Expand Up @@ -862,7 +859,7 @@ export class AddEditMileagePage implements OnInit {
return of(null);
}
}),
concatMap((info: locationInfo) => {
concatMap((info: LocationInfo) => {
if (info && info.recentStartLocation && info.eou && info.currentLocation) {
return this.locationService.getAutocompletePredictions(
info.recentStartLocation,
Expand Down Expand Up @@ -2416,7 +2413,7 @@ export class AddEditMileagePage implements OnInit {
});
const calculatedDistance = +res.calculatedDistance;

const amount = res.amount;
const amount = parseFloat(res.amount.toFixed(2));
const skipReimbursement =
(formValue?.paymentMode?.acc?.type === AccountType.PERSONAL &&
!formValue?.paymentMode?.acc?.isReimbursable) ||
Expand All @@ -2442,11 +2439,14 @@ export class AddEditMileagePage implements OnInit {
orig_currency: null,
orig_amount: null,
mileage_calculated_distance: calculatedDistance,
mileage_calculated_amount:
(rate ||
etxn.tx.mileage_rate ||
this.getRateByVehicleType(res.mileageRates, formValue.mileage_rate_name?.vehicle_type)) *
calculatedDistance,
mileage_calculated_amount: parseFloat(
(
(rate ||
etxn.tx.mileage_rate ||
this.getRateByVehicleType(res.mileageRates, formValue.mileage_rate_name?.vehicle_type)) *
calculatedDistance
).toFixed(2)
),
project_id: formValue.project && formValue.project.project_id,
purpose: formValue.purpose,
custom_properties: customProperties || [],
Expand Down

0 comments on commit ad0460e

Please sign in to comment.