|
|
@@ -1,17 +1,23 @@
|
|
|
import { HttpErrorResponse } from '@angular/common/http';
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
+import { Component, Inject, OnInit } from '@angular/core';
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
import { MatTableDataSource } from '@angular/material/table';
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
-import { lastValueFrom } from 'rxjs';
|
|
|
+import countryCodeEmoji from 'country-code-emoji';
|
|
|
+import { Observable, lastValueFrom, map, startWith } from 'rxjs';
|
|
|
import { AlertComponent } from 'src/app/components/resources/dialogs/alert/alert.component';
|
|
|
-import { CountriesList, CountriesListResponse } from 'src/app/interfaces/countries-list.interface';
|
|
|
+import { CitySettings, CitySettingsResponse } from 'src/app/interfaces/city-settings.interface';
|
|
|
+import { CityTown, CityTownsResponse } from 'src/app/interfaces/city-towns.interface';
|
|
|
+import { CountriesList, CountriesListResponse, LadaSelection } from 'src/app/interfaces/countries-list.interface';
|
|
|
+import { CountryState, CountryStatesResponse } from 'src/app/interfaces/country-states.interface';
|
|
|
import { DownoloadEmployeeInfo, Employee, FilesDocuments } from 'src/app/interfaces/personal-managment/employee.interface';
|
|
|
import { SubcontratistItem, SubcontratistsResponse } from 'src/app/interfaces/personal-managment/subcontratists.interface';
|
|
|
import { ResponseData } from 'src/app/interfaces/response-data';
|
|
|
+import { StateCitiesResponse, StateCity } from 'src/app/interfaces/state-cities.interface';
|
|
|
import { UsersResponse, UserResponse } from 'src/app/interfaces/users.interface';
|
|
|
import { EncService } from 'src/app/services/enc/enc.service';
|
|
|
+import { FunctionsService } from 'src/app/services/functions.service';
|
|
|
import { LocateService } from 'src/app/services/locate/locate.service';
|
|
|
import { EmployeeService } from 'src/app/services/personal-management/employee.service';
|
|
|
import { SubcontratistService } from 'src/app/services/personal-management/subcontratist.service';
|
|
|
@@ -20,6 +26,9 @@ import { ResourcesService } from 'src/app/services/resources/resources.service';
|
|
|
import { SystemAdminService } from 'src/app/services/system-admin.service';
|
|
|
import { UsersProfilesService } from 'src/app/services/users-profiles.service';
|
|
|
import { hostJean } from 'src/environments/environment';
|
|
|
+import flag from 'country-code-emoji';
|
|
|
+import { DOCUMENT } from '@angular/common';
|
|
|
+import { AddressByZipCodeResponse } from 'src/app/interfaces/address-by-zip-code.interface';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-employee-form',
|
|
|
@@ -62,8 +71,35 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
public hasError: boolean;
|
|
|
public errorStr: string;
|
|
|
public users: UserResponse[];
|
|
|
+ public enableSearchByZipCode: boolean;
|
|
|
+ public countryStates: CountryState[];
|
|
|
+ public stateCities: StateCity[];
|
|
|
+ public cityTowns: CityTown[];
|
|
|
+ public citySettings: CitySettings[];
|
|
|
+ public ladas: LadaSelection[];
|
|
|
+
|
|
|
+ public countriesStr: string[];
|
|
|
+ public countryStatesStr: string[];
|
|
|
+ public stateCitiesStr: string[];
|
|
|
+ public cityTownsStr: string[];
|
|
|
+ public citySettingsStr: string[];
|
|
|
+ public ladasStr: string[];
|
|
|
+
|
|
|
+ filteredCountries?: Observable<string[]>;
|
|
|
+ filteredStates?: Observable<string[]>;
|
|
|
+ filteredCities?: Observable<string[]>;
|
|
|
+ filteredTowns?: Observable<string[]>;
|
|
|
+ filteredSettings?: Observable<string[]>;
|
|
|
+
|
|
|
+ public searchingStates: boolean;
|
|
|
+ public citiesInput: boolean;
|
|
|
+ public searchingCities: boolean;
|
|
|
+ public searchingTowns: boolean;
|
|
|
+ public searchingSettings: boolean;
|
|
|
+ public searchingAddress: boolean;
|
|
|
|
|
|
constructor(
|
|
|
+ @Inject(DOCUMENT) private _document: Document,
|
|
|
private _activatedRoute: ActivatedRoute,
|
|
|
private _employeeService: EmployeeService,
|
|
|
private _resourcesService: ResourcesService,
|
|
|
@@ -74,6 +110,7 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
private _router: Router,
|
|
|
private _dialog: MatDialog,
|
|
|
private _usersProfilesService: UsersProfilesService,
|
|
|
+ private _functionsService: FunctionsService,
|
|
|
) {
|
|
|
this.action = "";
|
|
|
this.idEmployee = this._activatedRoute.snapshot.paramMap.get('id')!;
|
|
|
@@ -96,13 +133,33 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
this.documentTipe = 0;
|
|
|
this.dataSource = new MatTableDataSource<any>();
|
|
|
|
|
|
+ this.workteams = [];
|
|
|
+ this.subcontratists = [];
|
|
|
+ this.countries = [];
|
|
|
this.isLoading = true;
|
|
|
this.hasError = false;
|
|
|
this.errorStr = "";
|
|
|
this.users = [];
|
|
|
- this.workteams = [];
|
|
|
- this.subcontratists = [];
|
|
|
- this.countries = [];
|
|
|
+ this.enableSearchByZipCode = true;
|
|
|
+ this.countryStates = [];
|
|
|
+ this.stateCities = [];
|
|
|
+ this.cityTowns = [];
|
|
|
+ this.citySettings = [];
|
|
|
+ this.ladas = [];
|
|
|
+
|
|
|
+ this.countriesStr = [];
|
|
|
+ this.countryStatesStr = [];
|
|
|
+ this.stateCitiesStr = [];
|
|
|
+ this.cityTownsStr = [];
|
|
|
+ this.citySettingsStr = [];
|
|
|
+ this.ladasStr = [];
|
|
|
+
|
|
|
+ this.searchingStates = false;
|
|
|
+ this.citiesInput = false;
|
|
|
+ this.searchingCities = false;
|
|
|
+ this.searchingTowns = false;
|
|
|
+ this.searchingSettings = false;
|
|
|
+ this.searchingAddress = false;
|
|
|
}
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
@@ -111,6 +168,525 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
this.getWorkteams();
|
|
|
this.getSubcontratists();
|
|
|
this.getCountries();*/
|
|
|
+
|
|
|
+ this.formGroup.controls['federalEntity'].valueChanges.subscribe(value => {
|
|
|
+ let countryVal = this.formGroup.controls['country'].value;
|
|
|
+ let countryArr = countryVal.split('(').reverse();
|
|
|
+ let countryCode = countryArr[0].replace(')', '');
|
|
|
+
|
|
|
+ if(countryCode == 'MEX' || countryCode == 'USA' || countryCode == 'CAN'){
|
|
|
+ let validValue = this.countryStatesStr.filter(item => item == value);
|
|
|
+ if(validValue.length > 0){
|
|
|
+ let valueArr = value.split('(').reverse();
|
|
|
+ let stateCode = valueArr[0].replace(')', '');
|
|
|
+
|
|
|
+ this.verifyState(stateCode);
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['city'].setValue('');
|
|
|
+ this.formGroup.controls['city'].disable();
|
|
|
+ this.formGroup.controls['town'].setValue('');
|
|
|
+ this.formGroup.controls['town'].disable();
|
|
|
+ this.formGroup.controls['suburb'].setValue('');
|
|
|
+ this.formGroup.controls['suburb'].disable();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['city'].enable();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.formGroup.controls['city'].valueChanges.subscribe(value => {
|
|
|
+ let countryVal = this.formGroup.controls['country'].value;
|
|
|
+ let countryArr = countryVal.split('(').reverse();
|
|
|
+ let countryCode = countryArr[0].replace(')', '');
|
|
|
+
|
|
|
+ if(countryCode == 'MEX'){
|
|
|
+ let validValue = this.stateCitiesStr.filter(item => item == value);
|
|
|
+ if(validValue.length > 0){
|
|
|
+ let valueArr = value.split('(').reverse();
|
|
|
+ let cityCode = valueArr[0].replace(')', '');
|
|
|
+
|
|
|
+ this.verifyCity(cityCode);
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['town'].setValue('');
|
|
|
+ this.formGroup.controls['town'].disable();
|
|
|
+ this.formGroup.controls['suburb'].setValue('');
|
|
|
+ this.formGroup.controls['suburb'].disable();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['town'].enable();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.formGroup.controls['town'].valueChanges.subscribe(value => {
|
|
|
+ let countryVal = this.formGroup.controls['country'].value;
|
|
|
+ let countryArr = countryVal.split('(').reverse();
|
|
|
+ let countryCode = countryArr[0].replace(')', '');
|
|
|
+
|
|
|
+ if(countryCode == 'MEX'){
|
|
|
+ let validValue = this.cityTownsStr.filter(item => item == value);
|
|
|
+ if(validValue.length > 0){
|
|
|
+ let valueArr = value.split('(').reverse();
|
|
|
+ let townCode = valueArr[0].replace(')', '');
|
|
|
+
|
|
|
+ this.verifyTown(townCode);
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['suburb'].setValue('');
|
|
|
+ this.formGroup.controls['suburb'].disable();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['suburb'].enable();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.formGroup.controls['suburb'].valueChanges.subscribe(value => {
|
|
|
+ let validValue = this.citySettingsStr.filter(item => item == value);
|
|
|
+ if(validValue.length > 0){
|
|
|
+ let valueArr = value.split('(').reverse();
|
|
|
+ let settingCode = valueArr[0].replace(')', '');
|
|
|
+
|
|
|
+ this.verifySetting(settingCode);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ this.filteredCountries = this.formGroup.controls['country'].valueChanges.pipe(
|
|
|
+ startWith(''),
|
|
|
+ map(value => this._filterCountries(value || ''))
|
|
|
+ );
|
|
|
+
|
|
|
+ this.filteredStates = this.formGroup.controls['federalEntity'].valueChanges.pipe(
|
|
|
+ startWith(''),
|
|
|
+ map(value => this._filterStates(value || ''))
|
|
|
+ );
|
|
|
+
|
|
|
+ this.filteredCities = this.formGroup.controls['city'].valueChanges.pipe(
|
|
|
+ startWith(''),
|
|
|
+ map(value => this._filterCities(value || ''))
|
|
|
+ );
|
|
|
+
|
|
|
+ this.filteredTowns = this.formGroup.controls['town'].valueChanges.pipe(
|
|
|
+ startWith(''),
|
|
|
+ map(value => this._filterTowns(value || ''))
|
|
|
+ );
|
|
|
+
|
|
|
+ this.filteredSettings = this.formGroup.controls['suburb'].valueChanges.pipe(
|
|
|
+ startWith(''),
|
|
|
+ map(value => this._filterSettings(value || ''))
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private _filterCountries(value: string): string[]{
|
|
|
+ const filterValue = value.toLowerCase();
|
|
|
+ return this.countriesStr.filter(item => item.toLowerCase().includes(filterValue));
|
|
|
+ }
|
|
|
+
|
|
|
+ private _filterStates(value: string): string[]{
|
|
|
+ const filterValue = value.toLowerCase();
|
|
|
+ return this.countryStatesStr.filter(item => item.toLowerCase().includes(filterValue));
|
|
|
+ }
|
|
|
+
|
|
|
+ private _filterCities(value: string): string[]{
|
|
|
+ const filterValue = value.toLowerCase();
|
|
|
+ return this.stateCitiesStr.filter(item => item.toLowerCase().includes(filterValue));
|
|
|
+ }
|
|
|
+
|
|
|
+ private _filterTowns(value: string): string[]{
|
|
|
+ const filterValue = value.toLowerCase();
|
|
|
+ return this.cityTownsStr.filter(item => item.toLowerCase().includes(filterValue));
|
|
|
+ }
|
|
|
+
|
|
|
+ private _filterSettings(value: string): string[]{
|
|
|
+ const filterValue = value.toLowerCase();
|
|
|
+ return this.citySettingsStr.filter(item => item.toLowerCase().includes(filterValue));
|
|
|
+ }
|
|
|
+
|
|
|
+ checkIfAddress(value: string){
|
|
|
+ if(this.formGroup.controls['foreigner'].value == 'Si' && value == 'México (MEX)') return;
|
|
|
+ if(this.formGroup.controls['foreigner'].value == 'No' && value != 'México (MEX)') return;
|
|
|
+
|
|
|
+ let validValue = this.countriesStr.filter(item => item == value);
|
|
|
+ this.formGroup.controls['postalCode'].setValue('', {
|
|
|
+ emitEvent: false,
|
|
|
+ });
|
|
|
+
|
|
|
+ if(validValue.length > 0){
|
|
|
+ let valueArr = value.split('(').reverse();
|
|
|
+ let countryCode = valueArr[0].replace(')', '');
|
|
|
+
|
|
|
+ this.formGroup.controls['postalCode'].disable();
|
|
|
+ this.enableSearchByZipCode = false;
|
|
|
+ this.verifyCountry(countryCode);
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['federalEntity'].setValue('');
|
|
|
+ this.formGroup.controls['federalEntity'].disable();
|
|
|
+ this.formGroup.controls['city'].setValue('');
|
|
|
+ this.formGroup.controls['city'].disable();
|
|
|
+ this.formGroup.controls['town'].setValue('');
|
|
|
+ this.formGroup.controls['town'].disable();
|
|
|
+ this.formGroup.controls['suburb'].setValue('');
|
|
|
+ this.formGroup.controls['suburb'].disable();
|
|
|
+
|
|
|
+ this.formGroup.controls['postalCode'].enable();
|
|
|
+ this.enableSearchByZipCode = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ verifyCountry(countryCode: string){
|
|
|
+ this.formGroup.controls['federalEntity'].disable();
|
|
|
+ this.countryStates = [];
|
|
|
+ this.countryStatesStr = [];
|
|
|
+ this.stateCities = [];
|
|
|
+ this.stateCitiesStr = [];
|
|
|
+ this.cityTowns = [];
|
|
|
+ this.cityTownsStr = [];
|
|
|
+ this.citySettings = [];
|
|
|
+ this.citySettingsStr = [];
|
|
|
+
|
|
|
+ if(countryCode != 'MEX'){
|
|
|
+ this.formGroup.controls['postalCode'].enable();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(countryCode == 'CAN' || countryCode == 'MEX' || countryCode == 'USA'){
|
|
|
+ this.searchCountryStates(countryCode);
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['federalEntity'].enable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ verifyState(value: string){
|
|
|
+ let countryVal = this.formGroup.controls['country'].value;
|
|
|
+ let countryArr = countryVal.split('(').reverse();
|
|
|
+ let countryCode = countryArr[0].replace(')', '');
|
|
|
+ this.stateCities = [];
|
|
|
+ this.stateCitiesStr = [];
|
|
|
+ this.cityTowns = [];
|
|
|
+ this.cityTownsStr = [];
|
|
|
+ this.citySettings = [];
|
|
|
+ this.citySettingsStr = [];
|
|
|
+
|
|
|
+ if(countryCode == 'MEX'){
|
|
|
+ this.citiesInput = false;
|
|
|
+ this.searchStateCities(value);
|
|
|
+ }else{
|
|
|
+ this.citiesInput = true;
|
|
|
+ this.formGroup.controls['city'].enable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ verifyCity(value: string){
|
|
|
+ let stateVal = this.formGroup.controls['federalEntity'].value;
|
|
|
+ let stateArr = stateVal.split('(').reverse();
|
|
|
+ let stateCode = stateArr[0].replace(')', '');
|
|
|
+
|
|
|
+ this.cityTowns = [];
|
|
|
+ this.cityTownsStr = [];
|
|
|
+ this.citySettings = [];
|
|
|
+ this.citySettingsStr = [];
|
|
|
+
|
|
|
+ this.searchStateTowns(stateCode, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ verifyTown(value: string){
|
|
|
+ let stateVal = this.formGroup.controls['federalEntity'].value;
|
|
|
+ let stateArr = stateVal.split('(').reverse();
|
|
|
+ let stateCode = stateArr[0].replace(')', '');
|
|
|
+
|
|
|
+ let cityVal = this.formGroup.controls['city'].value;
|
|
|
+ let cityArr = cityVal.split('(').reverse();
|
|
|
+ let cityCode = cityArr[0].replace(')', '');
|
|
|
+
|
|
|
+ this.citySettings = [];
|
|
|
+ this.citySettingsStr = [];
|
|
|
+
|
|
|
+ let townCode = value == 'Sin localidad' ? '-' : value;
|
|
|
+ this.searchCitySettings(stateCode, cityCode, townCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ verifySetting(value: string){
|
|
|
+ let settingValid = this.citySettings.filter(item => item.CODIGOCOLONIA == value);
|
|
|
+ if(settingValid.length > 0){
|
|
|
+ this.formGroup.controls['postalCode'].setValue(settingValid[0].CODIGOPOSTAL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ searchZipCode(value: string){
|
|
|
+ let valArr = value.split('');
|
|
|
+ let validChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
|
+ let validVal = "";
|
|
|
+
|
|
|
+ valArr.forEach(char => {
|
|
|
+ if(validChars.includes(char)){
|
|
|
+ validVal += char;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ let zipCodeInput = this._document.getElementById('zipCode') as HTMLInputElement;
|
|
|
+ if(validVal.length < 5 && this.enableSearchByZipCode){
|
|
|
+ zipCodeInput.value = validVal;
|
|
|
+
|
|
|
+ let countryInput = this._document.getElementById('country') as HTMLInputElement;
|
|
|
+ countryInput.value = '';
|
|
|
+
|
|
|
+ let stateInput = this._document.getElementById('state') as HTMLInputElement;
|
|
|
+ stateInput.value = '';
|
|
|
+
|
|
|
+ let cityInput = this._document.getElementById('city') as HTMLInputElement;
|
|
|
+ cityInput.value = '';
|
|
|
+
|
|
|
+ let townInput = this._document.getElementById('town') as HTMLInputElement;
|
|
|
+ townInput.value = '';
|
|
|
+
|
|
|
+ let settingInput = this._document.getElementById('setting') as HTMLInputElement;
|
|
|
+ settingInput.value = '';
|
|
|
+
|
|
|
+ this.citySettings = [];
|
|
|
+ this.citySettingsStr = [];
|
|
|
+ }else{
|
|
|
+ let finalVal = validVal.substring(0, 5);
|
|
|
+ zipCodeInput.value = finalVal;
|
|
|
+
|
|
|
+ this.searchAddressByZipCode(finalVal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async searchCountryStates(contryCode: string){
|
|
|
+ try{
|
|
|
+ this.searchingStates = true;
|
|
|
+
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let countryCodeEnc = await this._encService.encrypt(contryCode);
|
|
|
+ let states: CountryStatesResponse = await lastValueFrom(this._sysAdminService.getStatesByCountryCode(
|
|
|
+ countryCodeEnc,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ if(!states.error){
|
|
|
+ this.countryStatesStr = [];
|
|
|
+ this.countryStates = states.response;
|
|
|
+
|
|
|
+ this.countryStates.forEach(item => {
|
|
|
+ this.countryStatesStr.push(`${item.NOMBREESTADO} (${item.CODIGOESTADO})`);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.formGroup.controls['federalEntity'].enable();
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingStates = false;
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else{
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingStates = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async searchStateCities(stateCode: string){
|
|
|
+ try{
|
|
|
+ this.searchingCities = true;
|
|
|
+
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let stateCodeEnc = await this._encService.encrypt(stateCode);
|
|
|
+ let cities: StateCitiesResponse = await lastValueFrom(this._sysAdminService.getCitiesByStateCode(
|
|
|
+ stateCodeEnc,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ if(!cities.error){
|
|
|
+ this.stateCities = cities.response;
|
|
|
+ this.stateCitiesStr = [];
|
|
|
+
|
|
|
+ this.stateCities.forEach(item => {
|
|
|
+ this.stateCitiesStr.push(`${item.NOMBREMUNICIPIO} (${item.CODIGOMUNICIPIO})`);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.formGroup.controls['city'].enable();
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingCities = false;
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else{
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingCities = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async searchStateTowns(stateCode: string, cityCode: string){
|
|
|
+ try{
|
|
|
+ this.searchingTowns = true;
|
|
|
+
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let stateCodeEnc = await this._encService.encrypt(stateCode);
|
|
|
+ let cityCodeEnc = await this._encService.encrypt(cityCode);
|
|
|
+ let towns: CityTownsResponse = await lastValueFrom(this._sysAdminService.getTowns(
|
|
|
+ stateCodeEnc,
|
|
|
+ cityCodeEnc,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ if(!towns.error){
|
|
|
+ this.cityTownsStr = [];
|
|
|
+ this.cityTowns = towns.response;
|
|
|
+
|
|
|
+ this.cityTowns.forEach(town => {
|
|
|
+ if(town.CODIGOLOCALIDAD == null){
|
|
|
+ this.cityTownsStr.push('Sin localidad');
|
|
|
+ }else{
|
|
|
+ this.cityTownsStr.push(`${town.NOMBRELOCALIDAD} (${town.CODIGOLOCALIDAD})`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if(towns.response.length > 1){
|
|
|
+ this.formGroup.controls['town'].enable();
|
|
|
+ }else if(towns.response.length == 1 && towns.response[0].CODIGOLOCALIDAD != null){
|
|
|
+ this.formGroup.controls['town'].enable();
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['town'].disable();
|
|
|
+ this.formGroup.controls['town'].setValue('Sin localidad');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingTowns = false;
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else{
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingTowns = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async searchCitySettings(stateCode: string, cityCode: string, townCode: string){
|
|
|
+ try{
|
|
|
+ this.searchingSettings = true;
|
|
|
+
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let stateCodeEnc = await this._encService.encrypt(stateCode);
|
|
|
+ let cityCodeEnc = await this._encService.encrypt(cityCode);
|
|
|
+ let townCodeEnc = await this._encService.encrypt(townCode);
|
|
|
+ let settings: CitySettingsResponse = await lastValueFrom(this._sysAdminService.getCitySettings(
|
|
|
+ stateCodeEnc,
|
|
|
+ cityCodeEnc,
|
|
|
+ townCodeEnc,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ if(!settings.error){
|
|
|
+ this.citySettings = settings.response;
|
|
|
+ this.citySettingsStr = [];
|
|
|
+
|
|
|
+ this.citySettings.forEach(setting => {
|
|
|
+ this.citySettingsStr.push(`${setting.NOMBRECOLONIA} (${setting.CODIGOCOLONIA})`);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.formGroup.controls['suburb'].enable();
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingSettings = false;
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else{
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingSettings = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async searchAddressByZipCode(zipCode: string){
|
|
|
+ try{
|
|
|
+ if(!this.enableSearchByZipCode) return;
|
|
|
+
|
|
|
+ this.searchingAddress = true;
|
|
|
+
|
|
|
+ let idUser = localStorage.getItem('idusuario')!;
|
|
|
+ let zipCodeEnc = await this._encService.encrypt(zipCode);
|
|
|
+ let address: AddressByZipCodeResponse = await lastValueFrom(this._sysAdminService.getAddressByZipCode(
|
|
|
+ zipCodeEnc,
|
|
|
+ idUser,
|
|
|
+ 1
|
|
|
+ ))
|
|
|
+
|
|
|
+ if(address.error){
|
|
|
+ this._resourcesService.openSnackBar(address.msg);
|
|
|
+ }else{
|
|
|
+ let countryInput = this._document.getElementById('country') as HTMLInputElement;
|
|
|
+ let countryVal = countryInput.value;
|
|
|
+ if(countryVal == '' || countryVal == null || countryVal == undefined){
|
|
|
+ countryInput.value = 'México (MEX)';
|
|
|
+ this.formGroup.controls['country'].setValue('México (MEX)', {
|
|
|
+ emitValue: false,
|
|
|
+ });
|
|
|
+
|
|
|
+ let stateInput = this._document.getElementById('state') as HTMLInputElement;
|
|
|
+ stateInput.value = `${address.response.NOMBRE_ESTADO} (${address.response.CODIGO_ESTADO})`;
|
|
|
+
|
|
|
+ let cityInput = this._document.getElementById('city') as HTMLInputElement;
|
|
|
+ if(address.response.CODIGO_MUNICIPIO == null){
|
|
|
+ cityInput.value = 'Sin municipio';
|
|
|
+ }else{
|
|
|
+ cityInput.value = `${address.response.NOMBRE_MUNICIPIO} (${address.response.CODIGO_MUNICIPIO})`;
|
|
|
+ }
|
|
|
+
|
|
|
+ let townInput = this._document.getElementById('town') as HTMLInputElement;
|
|
|
+ if(address.response.CODIGO_LOCALIDAD == null){
|
|
|
+ townInput.value = 'Sin localidad';
|
|
|
+ }else{
|
|
|
+ townInput.value = `${address.response.NOMBRE_LOCALIDAD} (${address.response.CODIGO_LOCALIDAD})`;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(address.response.COLONIAS.length > 0){
|
|
|
+ address.response.COLONIAS.forEach(item => {
|
|
|
+ let setting: CitySettings = {
|
|
|
+ CODIGOCOLONIA: item.CODIGO_COLONIA,
|
|
|
+ CODIGOPOSTAL: zipCode,
|
|
|
+ NOMBRECOLONIA: item.NOMBRE_COLONIA,
|
|
|
+ };
|
|
|
+
|
|
|
+ this.citySettings.push(setting);
|
|
|
+ this.citySettingsStr.push(`${item.NOMBRE_COLONIA} (${item.CODIGO_COLONIA})`);
|
|
|
+
|
|
|
+ this.formGroup.controls['suburb'].enable();
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ let settingInput = this._document.getElementById('setting') as HTMLInputElement;
|
|
|
+ settingInput.value = 'Sin colonia';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingAddress = false;
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ }else{
|
|
|
+ this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.searchingAddress = false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async init(){
|
|
|
@@ -150,22 +726,32 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
this.errorStr = users.msg;
|
|
|
this.isLoading = false;
|
|
|
}else{
|
|
|
- users.response.forEach(user => {
|
|
|
+ for(const user of users.response){
|
|
|
if(user.ESTATUS == 'Activo'){
|
|
|
+ let completeName = this._functionsService.buildName(user.NOMBRE, user.APEPAT, user.APEMAT);
|
|
|
+ completeName = `${completeName} (${user.IDUSUARIO})`;
|
|
|
+
|
|
|
+ let idEnc = await this._encService.encrypt(user.IDUSUARIO);
|
|
|
+ user.NOMBRE = completeName;
|
|
|
+ user.IDUSUARIO = idEnc;
|
|
|
+
|
|
|
this.users.push(user);
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
this.getWorkteams();
|
|
|
}
|
|
|
}catch(error: any){
|
|
|
if(error.error == undefined){
|
|
|
- this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ this.errorStr = "Ocurrió un error inesperado.";
|
|
|
}else if(error.error.msg == undefined){
|
|
|
- this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ this.errorStr = "Ocurrió un error inesperado.";
|
|
|
}else{
|
|
|
- this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ this.errorStr = error.error.msg;
|
|
|
}
|
|
|
+
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -175,18 +761,30 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
|
|
|
private createFormGroup() {
|
|
|
return new FormGroup({
|
|
|
+ userId: new FormControl({ value: '', disabled: false }, Validators.required),
|
|
|
+ workteamId: new FormControl('', Validators.required),
|
|
|
+ contractType: new FormControl('', Validators.required),
|
|
|
+ subcontratistId: new FormControl('', Validators.required),
|
|
|
+ speciality: new FormControl('', Validators.required),
|
|
|
+ foreigner: new FormControl('', Validators.required),
|
|
|
+ RFC: new FormControl({value: '', disabled: true}, [Validators.required, Validators.minLength(12), Validators.maxLength(12), Validators.pattern(new RegExp(/^([A-ZÑ&]{3,4}) ?(?:- ?)?(\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])) ?(?:- ?)?([A-Z\d]{2})([A\d])$/))]),
|
|
|
+ tax: new FormControl({value: '', disabled: true}, [Validators.required, Validators.minLength(12), Validators.maxLength(12), Validators.pattern(new RegExp(/^([A-ZÑ&]{3,4}) ?(?:- ?)?(\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])) ?(?:- ?)?([A-Z\d]{2})([A\d])$/))]),
|
|
|
+ country: new FormControl({value: '', disabled: true}, Validators.required),
|
|
|
+ federalEntity: new FormControl({value: '', disabled: true}, Validators.required),
|
|
|
+ city: new FormControl({value: '', disabled: true}, Validators.required),
|
|
|
+ town: new FormControl({value: '', disabled: true}),
|
|
|
+ suburb: new FormControl({value: '', disabled: true}, Validators.required),
|
|
|
+ street: new FormControl('', [Validators.required, Validators.maxLength(150)]),
|
|
|
+ exteriorNumber: new FormControl('', [Validators.required, Validators.maxLength(10)]),
|
|
|
+ interiorNumber: new FormControl('', Validators.maxLength(10)),
|
|
|
+ postalCode: new FormControl('', Validators.required),
|
|
|
documentsAutho: new FormControl(''),
|
|
|
documentOffice: new FormControl(''),
|
|
|
documentsCert: new FormControl(''),
|
|
|
- userId: new FormControl({ value: '', disabled: this.enable != "2" }, Validators.required),
|
|
|
contactName: new FormControl('', Validators.required),
|
|
|
contactLada: new FormControl('', Validators.required),
|
|
|
contactTelephone: new FormControl('', Validators.required),
|
|
|
contactAddress: new FormControl('', Validators.required),
|
|
|
- contractType: new FormControl('', Validators.required),
|
|
|
- speciality: new FormControl('', Validators.required),
|
|
|
- subcontratistId: new FormControl('', Validators.required),
|
|
|
- workteamId: new FormControl('', Validators.required),
|
|
|
updateDocuments: new FormControl(''),
|
|
|
})
|
|
|
}
|
|
|
@@ -273,23 +871,28 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
this.errorStr = workTeams.msg;
|
|
|
this.isLoading = false;
|
|
|
}else{
|
|
|
- workTeams.response.forEach((workteam: any) => {
|
|
|
+ for(const workteam of workTeams.response){
|
|
|
if(workteam.STATUS == 'Activo'){
|
|
|
+ let idEnc = await this._encService.encrypt(`${workteam.WORKTEAM_ID}`);
|
|
|
+ workteam.WORKTEAM_ID = idEnc;
|
|
|
+
|
|
|
this.workteams.push(workteam);
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
this.getSubcontratists();
|
|
|
}
|
|
|
}catch(error: any){
|
|
|
- console.log(error);
|
|
|
if(error.error == undefined){
|
|
|
- this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ this.errorStr = "Ocurrió un error inesperado.";
|
|
|
}else if(error.error.msg == undefined){
|
|
|
- this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
+ this.errorStr = "Ocurrió un error inesperado.";
|
|
|
}else{
|
|
|
- this._resourcesService.openSnackBar(error.error.msg);
|
|
|
+ this.errorStr = error.error.msg;
|
|
|
}
|
|
|
+
|
|
|
+ this.hasError = true;
|
|
|
+ this.isLoading = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -312,7 +915,6 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
this.getCountries();
|
|
|
}
|
|
|
}catch(error: any){
|
|
|
- console.log(error);
|
|
|
if(error.error == undefined){
|
|
|
this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
}else if(error.error.msg == undefined){
|
|
|
@@ -332,14 +934,69 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
this.errorStr = countries.msg;
|
|
|
|
|
|
if(!this.hasError){
|
|
|
+ let mex = countries.response.filter(item => item.COUNTRY_ID == 'MEX');
|
|
|
+ this.countries.push(mex[0]);
|
|
|
+ this.countriesStr.push(`${mex[0].NAME} (${mex[0].COUNTRY_ID})`);
|
|
|
+
|
|
|
+ let mexLada: LadaSelection = {
|
|
|
+ FLAG: [mex[0].NOMECLARUTA_ISO2!].map(countryCodeEmoji)[0],
|
|
|
+ LADA: mex[0].LADA!
|
|
|
+ };
|
|
|
+
|
|
|
+ this.ladas.push(mexLada);
|
|
|
+ this.ladasStr.push(`${mexLada.FLAG} ${mexLada.LADA}`);
|
|
|
+
|
|
|
+ let usa = countries.response.filter(item => item.COUNTRY_ID == 'USA');
|
|
|
+ this.countries.push(usa[0]);
|
|
|
+ this.countriesStr.push(`${usa[0].NAME} (${usa[0].COUNTRY_ID})`);
|
|
|
+
|
|
|
+ let usaLada: LadaSelection = {
|
|
|
+ FLAG: [usa[0].NOMECLARUTA_ISO2!].map(countryCodeEmoji)[0],
|
|
|
+ LADA: usa[0].LADA!
|
|
|
+ };
|
|
|
+
|
|
|
+ this.ladas.push(usaLada);
|
|
|
+ this.ladasStr.push(`${usaLada.FLAG} ${usaLada.LADA}`);
|
|
|
+
|
|
|
+ let can = countries.response.filter(item => item.COUNTRY_ID == 'CAN');
|
|
|
+ this.countries.push(can[0]);
|
|
|
+ this.countriesStr.push(`${can[0].NAME} (${can[0].COUNTRY_ID})`);
|
|
|
+
|
|
|
+ let canLada: LadaSelection = {
|
|
|
+ FLAG: [can[0].NOMECLARUTA_ISO2!].map(countryCodeEmoji)[0],
|
|
|
+ LADA: can[0].LADA!
|
|
|
+ };
|
|
|
+
|
|
|
+ this.ladas.push(canLada);
|
|
|
+ this.ladasStr.push(`${canLada.FLAG} ${canLada.LADA}`);
|
|
|
+
|
|
|
countries.response.forEach(country => {
|
|
|
- console.log(country);
|
|
|
+ if(country.COUNTRY_ID != null && country.COUNTRY_ID != 'MEX' && country.COUNTRY_ID != 'USA' && country.COUNTRY_ID != 'CAN'){
|
|
|
+ this.countries.push(country);
|
|
|
+ this.countriesStr.push(`${country.NAME} (${country.COUNTRY_ID})`);
|
|
|
+
|
|
|
+ try{
|
|
|
+ flag(country.NOMECLARUTA_ISO2!);
|
|
|
+ let hasLada = country.LADA != '';
|
|
|
+
|
|
|
+ if(hasLada){
|
|
|
+ let lada: LadaSelection = {
|
|
|
+ FLAG: [country.NOMECLARUTA_ISO2!].map(countryCodeEmoji)[0],
|
|
|
+ LADA: country.LADA!
|
|
|
+ };
|
|
|
+
|
|
|
+ this.ladas.push(lada);
|
|
|
+ this.ladasStr.push(`${lada.FLAG} ${lada.LADA}`);
|
|
|
+ }
|
|
|
+ }catch(error: any){
|
|
|
+ //Saltar país
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
this.isLoading = false;
|
|
|
}catch(error: any){
|
|
|
- console.log(error);
|
|
|
if(error.error == undefined){
|
|
|
this._resourcesService.openSnackBar("Ocurrió un error inesperado.");
|
|
|
}else if(error.error.msg == undefined){
|
|
|
@@ -348,11 +1005,6 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
this._resourcesService.openSnackBar(error.error.msg);
|
|
|
}
|
|
|
}
|
|
|
- /*await lastValueFrom(this._locateService.getCountries()).then(
|
|
|
- (responseData: any) => {
|
|
|
- this.countries = responseData.response;
|
|
|
- }, (error: HttpErrorResponse) => this._resourcesService.checkErrors(error)
|
|
|
- );*/
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -473,11 +1125,11 @@ export class EmployeeFormComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-private enableDocumentButtons(){
|
|
|
- this.authoButton = false;
|
|
|
- this.officeButton = false;
|
|
|
- this.certButton = false;
|
|
|
-}
|
|
|
+ private enableDocumentButtons(){
|
|
|
+ this.authoButton = false;
|
|
|
+ this.officeButton = false;
|
|
|
+ this.certButton = false;
|
|
|
+ }
|
|
|
|
|
|
public checkFile(event: any, type: string) {
|
|
|
let file: any = event.target.files[0];
|
|
|
@@ -630,6 +1282,20 @@ private enableDocumentButtons(){
|
|
|
this.btnSmall = window.innerWidth <= 1405;
|
|
|
}
|
|
|
|
|
|
+ public changeNationality() {
|
|
|
+ let foreigner = this.formGroup.controls['foreigner'].value;
|
|
|
+ this.formGroup.controls['country'].enable();
|
|
|
+ if(foreigner == 'Si'){
|
|
|
+ this.formGroup.controls['RFC'].disable();
|
|
|
+ this.formGroup.controls['RFC'].setValue(null);
|
|
|
+ this.formGroup.controls['tax'].enable();
|
|
|
+ }else{
|
|
|
+ this.formGroup.controls['tax'].disable();
|
|
|
+ this.formGroup.controls['tax'].setValue(null);
|
|
|
+ this.formGroup.controls['RFC'].enable();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
get contactName() {
|
|
|
return this.formGroup.get('contactName')!;
|
|
|
}
|