Sfoglia il codice sorgente

Deshabilitar botón en base a la fecha actual

Alan Garcia 3 anni fa
parent
commit
f7f3984c26

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

@@ -38,7 +38,7 @@
                 <mat-label>Nueva fecha solicitada</mat-label>
                 <mat-date-range-input
                   [formGroup]="formGroup"
-                  [min]="formGroup.value.fecha_final"
+                  [min]="today"
                   [rangePicker]="fechaNuevaPicker"
                   [comparisonStart]="formGroup.value.fecha_inicio"
                   [comparisonEnd]="formGroup.value.fecha_final">

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

@@ -40,6 +40,8 @@ export class MESMHSFORMDAYSComponent implements OnInit {
   formGroup: FormGroup;
   dias: number = 0;
 
+  today = new Date();
+
   dias_feriados: any[] = null!;
   politica: string = null!;
 

+ 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]="element.ESTATUS !== 'Aprobado'"
+          [disabled]="validatedDateNow(element)"
         >
           <mat-icon>add</mat-icon>
         </button>

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

@@ -32,6 +32,7 @@ export class MESMHSComponent implements AfterViewInit {
   dataSource = new MatTableDataSource<any>(this.solicitudes);
   subordinados: any;
   isAdmin = false;
+  today = new Date();
   @ViewChild(MatPaginator) paginator!: MatPaginator;
 
   constructor(
@@ -98,7 +99,6 @@ export class MESMHSComponent implements AfterViewInit {
           this.loading = false;
           this.dataSource.data = res.response;
           this.historial_admin = res.response;
-          this.data_empty = false;
           this.cargarTabla(res.response);
         } else {
           this.solicitudes = [];
@@ -329,6 +329,8 @@ export class MESMHSComponent implements AfterViewInit {
     ) => {
       if (solicitud.PERIODOVACACIONAL == null) {
         solicitud.PERIODOVACACIONAL = 'N/A';
+      } else {
+        solicitud.PERIODOVACACIONAL = this.formatoFechaPeriodo(solicitud.PERIODOVACACIONAL);
       }
 
       solicitud.FECHAINICIAL = this.formato(solicitud.FECHAINICIAL);
@@ -338,6 +340,16 @@ 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',
@@ -360,6 +372,18 @@ export class MESMHSComponent implements AfterViewInit {
     });
   }
 
+  private getDateWithString(fecha: string) {
+    let fechaAux = fecha.split('-');
+
+    return new Date(parseInt(fechaAux[0]), parseInt(fechaAux[1]) - 1, parseInt(fechaAux[2]));
+  }
+
+  private dateFormat(fecha: string) {
+    let fechaAux = fecha.split('-');
+
+    return `${fechaAux[2]}-${fechaAux[1]}-${fechaAux[0]}`;
+  }
+
   obtenerIDUsuario(item: any) {
 
     let arr1 = item.split('(');