Ver código fonte

Modificación de fechas en Historial de Solicitudes

Alan Garcia 3 anos atrás
pai
commit
921fe50f63

+ 2 - 2
vacaciones/src/app/components/mes/mesmhs/mesmhs-form-days/mesmhs-form-days.component.html

@@ -38,12 +38,12 @@
                 <mat-label>Nueva fecha solicitada</mat-label>
                 <mat-date-range-input
                   [formGroup]="formGroup"
-                  [min]="today"
+                  [min]="formGroup.value.fecha_minima"
                   [rangePicker]="fechaNuevaPicker"
                   [comparisonStart]="formGroup.value.fecha_inicio"
                   [comparisonEnd]="formGroup.value.fecha_final">
                   <input matStartDate placeholder="Start date" formControlName="fecha_inicio_2">
-                  <input matEndDate placeholder="End date"  formControlName="fecha_final_2" (dateChange)="changeNewDate($event)">
+                  <input matEndDate placeholder="End date" formControlName="fecha_final_2" (dateChange)="changeNewDate($event)">
                 </mat-date-range-input>
                 <mat-datepicker-toggle matSuffix [for]="fechaNuevaPicker"></mat-datepicker-toggle>
                 <mat-date-range-picker #fechaNuevaPicker></mat-date-range-picker>

+ 26 - 6
vacaciones/src/app/components/mes/mesmhs/mesmhs-form-days/mesmhs-form-days.component.ts

@@ -39,9 +39,6 @@ import { MESMSVService } from 'src/app/services/mes/mesmsv/mesmsv.service';
 export class MESMHSFORMDAYSComponent implements OnInit {
   formGroup: FormGroup;
   dias: number = 0;
-
-  today = new Date();
-
   dias_feriados: any[] = null!;
   politica: string = null!;
 
@@ -92,6 +89,13 @@ export class MESMHSFORMDAYSComponent implements OnInit {
         },
         Validators.required
       ),
+      fecha_minima: new FormControl(
+        { 
+          value: this.momentDate(this.dateFormat(this.data.item.FECHAFINAL)).add(1, 'day'), 
+          disabled: false 
+        },
+        Validators.required
+      ),
       fecha_final_2: new FormControl(
         { 
           value: '', 
@@ -340,7 +344,7 @@ export class MESMHSFORMDAYSComponent implements OnInit {
     if (event.value !== null) {
       if (new Date(event.value).getTime() > this.getDateWithString(this.data.item.FECHAFINAL).getTime()) {
         this.formGroup.patchValue({
-          fecha_inicio_2: this.getDateWithString(this.data.item.FECHAFINAL),
+          fecha_inicio_2: this.getDateWithString(this.dateFormatInvert(this.data.item.FECHAFINAL)),
         });
         this.calcular_dias();
       } else {
@@ -369,8 +373,8 @@ export class MESMHSFORMDAYSComponent implements OnInit {
 
   private getDateWithString(fecha: string) {
     let fechaAux = fecha.split('-');
-
-    return new Date(parseInt(fechaAux[0]), parseInt(fechaAux[1]) - 1, parseInt(fechaAux[2]));
+    
+    return new Date(parseInt(fechaAux[2]), parseInt(fechaAux[1]) - 1, parseInt(fechaAux[0]));
   }
 
   private dateFormat(fecha: string) {
@@ -379,6 +383,18 @@ export class MESMHSFORMDAYSComponent implements OnInit {
     return `${fechaAux[2]}-${fechaAux[1]}-${fechaAux[0]}`;
   }
 
+  private dateFormatInvert(fecha: string) {
+    let fechaAux = fecha.split('-');
+
+    return `${fechaAux[0]}-${fechaAux[1]}-${fechaAux[2]}`;
+  }
+
+  private addDayDate(fecha: Date) {
+    fecha.setDate(fecha.getDate() + 1)
+    
+    return fecha;
+  }
+
   private obtenerDiasFeriados() {
     this._mcomdfService.obtener().subscribe(
       (response) => {
@@ -435,6 +451,10 @@ export class MESMHSFORMDAYSComponent implements OnInit {
     return this.formGroup.get('fecha_final_2');
   }
 
+  get fecha_minima() {
+    return this.formGroup.get('fecha_minima');
+  }
+
   get dias_vacacionales() {
     return this.formGroup.get('dias_vacacionales');
   }

+ 1 - 1
vacaciones/src/app/components/mes/mesmhs/mesmhs.component.html

@@ -112,7 +112,7 @@
           class="mr-1 success"
           matTooltip="Agregar días vacacionales"
           (click)="openDialogAddDays(element)"
-          [disabled]="validatedDateNow(element)"
+          [disabled]="element.ISDISABLED"
         >
           <mat-icon>add</mat-icon>
         </button>

+ 10 - 12
vacaciones/src/app/components/mes/mesmhs/mesmhs.component.ts

@@ -327,10 +327,18 @@ export class MESMHSComponent implements AfterViewInit {
     this.solicitudes.map( (
       solicitud: any
     ) => {
+      let finalDate = this.getDateWithString(this.dateFormat(solicitud.FECHAFINAL));
+
       if (solicitud.PERIODOVACACIONAL == null) {
         solicitud.PERIODOVACACIONAL = 'N/A';
       } else {
-        solicitud.PERIODOVACACIONAL = this.formatoFechaPeriodo(solicitud.PERIODOVACACIONAL);
+        solicitud.PERIODOVACACIONAL = this.formatoFechaPeriodo(solicitud.PERIODOVACACIONAL).join();
+      }
+      
+      if (solicitud.ESTATUS != 'Aprobado' || this.today.getTime() > finalDate.getTime()) {
+        solicitud.ISDISABLED = true;
+      } else {
+        solicitud.ISDISABLED = false;
       }
 
       solicitud.FECHAINICIAL = this.formato(solicitud.FECHAINICIAL);
@@ -340,16 +348,6 @@ export class MESMHSComponent implements AfterViewInit {
     });
   }
 
-  validatedDateNow(element:any) {
-    let finalDate = this.getDateWithString(this.dateFormat(element.FECHAFINAL));
-    
-    if (element.ESTATUS !== 'Aprobado' && finalDate.getTime() > this.today.getTime()) {
-      return false;
-    }
-    
-    return true;
-  }
-
   openDialogForm(item: any) {
     let dataAction = {
       action: 'Detalles solicitud',
@@ -381,7 +379,7 @@ export class MESMHSComponent implements AfterViewInit {
   private dateFormat(fecha: string) {
     let fechaAux = fecha.split('-');
 
-    return `${fechaAux[2]}-${fechaAux[1]}-${fechaAux[0]}`;
+    return `${fechaAux[0]}-${fechaAux[1]}-${fechaAux[2]}`;
   }
 
   obtenerIDUsuario(item: any) {