2025-07-07 19:09:47 -03:00
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
|
import { Component, inject } from '@angular/core';
|
|
|
|
|
import { AngularMaterialModule } from '../../shared/module/angular-material.module';
|
|
|
|
|
import { ReactiveFormsModule } from '@angular/forms';
|
|
|
|
|
import { ApplicationComponent } from '../application/application.component';
|
|
|
|
|
import { StepperSelectionEvent } from '@angular/cdk/stepper';
|
|
|
|
|
import { GoodsComponent } from '../goods/goods.component';
|
|
|
|
|
import { HolderComponent } from '../holder/holder.component';
|
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
import { ShippingComponent } from '../shipping/shipping.component';
|
|
|
|
|
import { TravelPlanComponent } from '../travel-plan/travel-plan.component';
|
2025-07-09 13:42:16 -03:00
|
|
|
import { UserPreferences } from '../../core/models/user-preference';
|
|
|
|
|
import { UserPreferencesService } from '../../core/services/user-preference.service';
|
2025-07-02 22:40:35 -03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-edit-carnet',
|
2025-07-07 19:09:47 -03:00
|
|
|
imports: [AngularMaterialModule, CommonModule, ReactiveFormsModule,
|
2025-07-14 09:59:26 -03:00
|
|
|
ApplicationComponent, HolderComponent, GoodsComponent, TravelPlanComponent, ShippingComponent],
|
2025-07-02 22:40:35 -03:00
|
|
|
templateUrl: './edit-carnet.component.html',
|
|
|
|
|
styleUrl: './edit-carnet.component.scss'
|
|
|
|
|
})
|
|
|
|
|
export class EditCarnetComponent {
|
2025-07-07 19:09:47 -03:00
|
|
|
currentStep = 0;
|
|
|
|
|
isLinear = false;
|
|
|
|
|
applicationType: 'new' | 'additional' | 'duplicate' | 'extend' | null = 'new';
|
|
|
|
|
isEditMode = true; // Set to true for edit mode
|
|
|
|
|
headerid: number = 0;
|
2025-07-09 13:42:16 -03:00
|
|
|
userPreferences: UserPreferences;
|
2025-07-17 13:56:18 -03:00
|
|
|
applicationName: string = '';
|
2025-07-18 12:33:12 -03:00
|
|
|
refreshShippingData: boolean = false;
|
2025-07-22 21:32:12 -03:00
|
|
|
allSectionsCompleted: boolean = false;
|
2025-07-02 22:40:35 -03:00
|
|
|
|
2025-07-07 19:09:47 -03:00
|
|
|
// Track completion of each step
|
|
|
|
|
stepsCompleted = {
|
|
|
|
|
applicationDetail: true,
|
|
|
|
|
holderSelection: false,
|
|
|
|
|
goodsSection: false,
|
|
|
|
|
travelPlan: false,
|
2025-07-14 09:59:26 -03:00
|
|
|
shipping: false
|
2025-07-07 19:09:47 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private route = inject(ActivatedRoute);
|
|
|
|
|
|
2025-07-09 13:42:16 -03:00
|
|
|
constructor(userPrefenceService: UserPreferencesService) {
|
|
|
|
|
this.userPreferences = userPrefenceService.getPreferences();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 19:09:47 -03:00
|
|
|
ngOnInit(): void {
|
|
|
|
|
const idParam = this.route.snapshot.paramMap.get('headerid');
|
|
|
|
|
this.headerid = idParam ? parseInt(idParam, 10) : 0;
|
2025-07-17 13:56:18 -03:00
|
|
|
|
|
|
|
|
this.applicationName = this.route.snapshot.queryParamMap.get('applicationname') || '';
|
2025-07-17 22:21:04 -03:00
|
|
|
|
|
|
|
|
let returnTo = this.route.snapshot.queryParamMap.get('return');
|
|
|
|
|
|
|
|
|
|
if (returnTo === 'holder') {
|
|
|
|
|
this.currentStep = 1;
|
2025-07-22 21:32:12 -03:00
|
|
|
} else if (returnTo === 'shipping') {
|
|
|
|
|
this.currentStep = 4;
|
2025-07-17 22:21:04 -03:00
|
|
|
}
|
2025-07-07 19:09:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onStepChange(event: StepperSelectionEvent): void {
|
|
|
|
|
this.currentStep = event.selectedIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onHolderSelectionSaved(completed: boolean): void {
|
|
|
|
|
this.stepsCompleted.holderSelection = completed;
|
2025-07-22 21:32:12 -03:00
|
|
|
this.isAllSectionsCompleted();
|
2025-07-07 19:09:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onGoodsSectionSaved(completed: boolean): void {
|
|
|
|
|
this.stepsCompleted.goodsSection = completed;
|
2025-07-22 21:32:12 -03:00
|
|
|
this.isAllSectionsCompleted();
|
2025-07-07 19:09:47 -03:00
|
|
|
}
|
|
|
|
|
|
2025-07-18 12:33:12 -03:00
|
|
|
onHolderSelectionUpdated(updated: boolean): void {
|
|
|
|
|
this.refreshShippingData = updated;
|
2025-07-22 21:32:12 -03:00
|
|
|
this.isAllSectionsCompleted();
|
2025-07-18 12:33:12 -03:00
|
|
|
}
|
|
|
|
|
|
2025-07-07 19:09:47 -03:00
|
|
|
onTravelPlanSaved(completed: boolean): void {
|
|
|
|
|
this.stepsCompleted.travelPlan = completed;
|
2025-07-22 21:32:12 -03:00
|
|
|
this.isAllSectionsCompleted();
|
2025-07-07 19:09:47 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onShippingSaved(completed: boolean): void {
|
|
|
|
|
this.stepsCompleted.shipping = completed;
|
2025-07-22 21:32:12 -03:00
|
|
|
this.isAllSectionsCompleted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isAllSectionsCompleted() {
|
|
|
|
|
this.allSectionsCompleted = this.stepsCompleted.applicationDetail
|
|
|
|
|
&& this.stepsCompleted.holderSelection && this.stepsCompleted.goodsSection
|
|
|
|
|
&& this.stepsCompleted.shipping && this.stepsCompleted.travelPlan;
|
2025-07-07 19:09:47 -03:00
|
|
|
}
|
2025-07-02 22:40:35 -03:00
|
|
|
}
|