diff --git a/src/app/carnet/terms-conditions/terms-conditions.component.html b/src/app/carnet/terms-conditions/terms-conditions.component.html index 8cf9ed3..9bc63ac 100644 --- a/src/app/carnet/terms-conditions/terms-conditions.component.html +++ b/src/app/carnet/terms-conditions/terms-conditions.component.html @@ -73,10 +73,17 @@

8. Fees and Charges

8.1 The following fees apply:

9. Dispute Resolution

diff --git a/src/app/carnet/terms-conditions/terms-conditions.component.ts b/src/app/carnet/terms-conditions/terms-conditions.component.ts index 16bfe08..0b7b3f0 100644 --- a/src/app/carnet/terms-conditions/terms-conditions.component.ts +++ b/src/app/carnet/terms-conditions/terms-conditions.component.ts @@ -7,10 +7,11 @@ import { MatCheckboxModule } from '@angular/material/checkbox'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { ApiErrorHandlerService } from '../../core/services/common/api-error-handler.service'; -import { CommonService } from '../../core/services/common/common.service'; import { NavigationService } from '../../core/services/common/navigation.service'; import { NotificationService } from '../../core/services/common/notification.service'; import { StorageService } from '../../core/services/common/storage.service'; +import { CarnetService } from '../../core/services/carnet/carnet.service'; +import { Fees } from '../../core/models/carnet/fee'; @Component({ selector: 'app-terms-conditions', @@ -28,23 +29,57 @@ export class TermsConditionsComponent { currentDate = new Date(); hasReadAllTerms = false; currentApplicationDetails: { headerid: number, applicationName: string } | null = null; + isLoading: boolean = false; + estimatedFees: Fees = {}; private notificationService = inject(NotificationService); - private commonService = inject(CommonService); private errorHandler = inject(ApiErrorHandlerService); private storageService = inject(StorageService); private navigationService = inject(NavigationService); + private carnetService = inject(CarnetService); constructor() { this.currentApplicationDetails = this.storageService.get<{ headerid: number, applicationName: string }>('currentapplication') } + ngOnInit(): void { + if (this.currentApplicationDetails?.headerid) { + this.carnetService.getEstimatedFees(this.currentApplicationDetails?.headerid).subscribe({ + next: (data: Fees) => { + if (data) { + this.estimatedFees = data; + } + }, + error: (error: any) => { + let errorMessage = this.errorHandler.handleApiError(error, 'Failed to get estimated fees'); + this.notificationService.showError(errorMessage); + console.error('Error getting estimated fees:', error); + } + }); + } + } + onAccept(): void { - console.log('Terms accepted'); + + this.isLoading = true; + this.carnetService.submitApplication(this.currentApplicationDetails?.headerid!).subscribe({ + next: () => { + this.notificationService.showSuccess('Application submitted successfully'); + this.storageService.removeItem('currentapplication'); + this.navigationService.navigate(["home"]); + this.isLoading = false; + }, + error: (error) => { + let errorMessage = this.errorHandler.handleApiError(error, 'Failed to submit application'); + this.notificationService.showError(errorMessage); + console.error('Error submitting the application', error); + this.isLoading = false; + } + }); } onDecline(): void { - this.storageService.removeItem('currentapplication') + this.storageService.removeItem('currentapplication'); this.navigationService.navigate(["edit-carnet", this.currentApplicationDetails?.headerid], { state: { isEditMode: true }, diff --git a/src/app/core/models/carnet/fee.ts b/src/app/core/models/carnet/fee.ts new file mode 100644 index 0000000..c87d9d4 --- /dev/null +++ b/src/app/core/models/carnet/fee.ts @@ -0,0 +1,10 @@ +export interface Fees { + basicFee?: number | null | undefined; + counterFoilFee?: number | null | undefined; + continuationSheetFee?: number | null | undefined; + expeditedFee?: number | null | undefined; + shippingFee?: number | null | undefined; + bondPremium?: number | null | undefined; + cargoPremium?: number | null | undefined; + ldiPremium?: number | null | undefined; +} diff --git a/src/app/core/services/carnet/carnet.service.ts b/src/app/core/services/carnet/carnet.service.ts new file mode 100644 index 0000000..2b94f28 --- /dev/null +++ b/src/app/core/services/carnet/carnet.service.ts @@ -0,0 +1,49 @@ +import { HttpClient } from '@angular/common/http'; +import { inject, Injectable } from '@angular/core'; +import { Observable, filter, map } from 'rxjs'; +import { environment } from '../../../../environments/environment'; +import { UserService } from '../common/user.service'; +import { Fees } from '../../models/carnet/fee'; + +@Injectable({ + providedIn: 'root' +}) +export class CarnetService { + private apiUrl = environment.apiUrl; + private apiDb = environment.apiDb; + + private http = inject(HttpClient); + private userService = inject(UserService); + + getEstimatedFees(headerid: number): Observable { + return this.http.get(`${this.apiUrl}/${this.apiDb}/EstimatedFees/${this.userService.getUserSpid()}/${this.userService.getUser()}/${headerid}`).pipe( + filter(response => response.length > 0), + map(response => this.mapToFeesData(response?.[0]))); + } + + private mapToFeesData(estimatedFeesDetails: any): Fees { + let estimatedFeesData: Fees = { + basicFee: estimatedFeesDetails.BASICFEE, + counterFoilFee: estimatedFeesDetails.CFFEE, + continuationSheetFee: estimatedFeesDetails.CSFEE, + expeditedFee: estimatedFeesDetails.EFFEE, + shippingFee: estimatedFeesDetails.SHIPFEE, + bondPremium: estimatedFeesDetails.BONDPREMIUM, + cargoPremium: estimatedFeesDetails.CARGOPREMIUM, + ldiPremium: estimatedFeesDetails.LDIPREMIUM, + }; + + return estimatedFeesData; + } + + submitApplication(headerid: number): Observable { + + let appData = { + P_SPID: this.userService.getUserSpid(), + P_USERID: this.userService.getUser(), + P_HEADERID: headerid + } + + return this.http.post(`${this.apiUrl}/${this.apiDb}/TransmitApplicationtoProcess`, appData); + } +}