فهرست منبع

Modificación de calculo de días MESMHS

JeanBenitez 3 سال پیش
والد
کامیت
0d2021c9f1

+ 32 - 8
vacaciones/src/app/components/mes/mesmhs/mesmhs-form-days/mesmhs-form-days.component.ts

@@ -130,6 +130,11 @@ export class MESMHSFORMDAYSComponent implements OnInit {
   }
 
   private createFormGroup() {
+    
+    let fechaInicio2 = new Date(this.dateFormat(this.data.item.FECHAFINAL));
+    fechaInicio2 = new Date(fechaInicio2.getFullYear(), fechaInicio2.getMonth(), fechaInicio2.getDate() + 2);
+    let str_fecha_inicio = fechaInicio2.toISOString().split('T')[0]
+    
     return new FormGroup({
       numero_empleado: new FormControl({
         value: this.data.item.IDUSUARIO,
@@ -155,7 +160,7 @@ export class MESMHSFORMDAYSComponent implements OnInit {
       ),
       fecha_inicio_2: new FormControl(
         {
-          value: this.momentDate(this.dateFormat(this.data.item.FECHAFINAL)),
+          value: this.momentDate(str_fecha_inicio),
           disabled: true,
         },
         Validators.required
@@ -187,7 +192,7 @@ export class MESMHSFORMDAYSComponent implements OnInit {
     let solicitud = {
       id_solicitud: this.data.item.IDSOLICITUD,
       fecha_final: this.formatDate(this.fecha_final_2?.value),
-      extra_dias: days_auxiliar,
+      extra_dias: this.dias_vacacionales?.value,
       numero_empleado_modifica: this._encService.desencriptar(this.usuario_session.IDUSUARIO),
       rfc_empresa: this.usuario_session.RFCEMPRESA,
     };
@@ -250,8 +255,13 @@ export class MESMHSFORMDAYSComponent implements OnInit {
         (this.fecha_inicio?.value._d != null &&
           this.fecha_final_2?.value._d != null)
       ) {
-        let fecha1: Date = this.fecha_inicio?.value._d;
-        let fecha2: Date = this.fecha_final_2?.value._d;
+
+        let fecha1: Date = this.fecha_inicio_2?.value ;
+        let fecha2: Date = this.fecha_final_2?.value._d;     
+
+        console.log(fecha1);
+        console.log(fecha2);
+        
 
         this.dias = this.difference(fecha1, fecha2) + 1;
 
@@ -315,14 +325,22 @@ export class MESMHSFORMDAYSComponent implements OnInit {
     }
     return 0;
   }
-
+  
   applyFilter(e: any) {
     let dias_semana = Object.values(JSON.parse(this.politica));
     let diasVacaciones = parseInt(e.target.value);
     let cont = 0;
     let diasFeriados = 0;
-    let fecha1: Date = this.fecha_inicio?.value._d;
+    let fecha1: Date;
+    
+    if (this.fecha_inicio_2?.value._d === undefined) {
+      fecha1 = this.fecha_inicio_2?.value
+    }else{
+      fecha1 = this.fecha_inicio_2?.value._d;    
 
+    }
+    console.log(fecha1);
+    
     do {
       this.dias_feriados.forEach((element) => {
         if (
@@ -421,13 +439,19 @@ export class MESMHSFORMDAYSComponent implements OnInit {
 
   changeNewDate(event: MatDatepickerInputEvent<Date>) {
     if (event.value !== null) {
+
+      let fechaInicio2 = new Date(this.dateFormat(this.data.item.FECHAFINAL));
+      fechaInicio2 = new Date(fechaInicio2.getFullYear(), fechaInicio2.getMonth() + 1, fechaInicio2.getDate() + 2);
+      let str_fecha_inicio = `${fechaInicio2.getDate()}-${fechaInicio2.getMonth()}-${fechaInicio2.getFullYear()}`;
+      console.log(str_fecha_inicio);
+      
       if (
         new Date(event.value).getTime() >
-        this.getDateWithString(this.data.item.FECHAFINAL).getTime()
+        this.getDateWithString(str_fecha_inicio).getTime()
       ) {
         this.formGroup.patchValue({
           fecha_inicio_2: this.getDateWithString(
-            this.dateFormatInvert(this.data.item.FECHAFINAL)
+            this.dateFormatInvert(str_fecha_inicio)
           ),
         });
         this.calcular_dias();

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

@@ -79,7 +79,7 @@
 
 <!-- Periodo Actual -->
 <mat-card class="card-normal-text mat-card-text mat-elevation-z8 animated fadeIn fast" style="padding-bottom: 15px;"
-  [style.margin-bottom]="!casoAnterior && !casoEAYG ? '100px' : ''" *ngIf="!loading && casoActual">
+  [style.margin-bottom]="!casoEAYG ? '100px' : ''" *ngIf="!loading && casoActual">
   <mat-grid-list cols="12" rowHeight="100px">
     <!-- Fila 1 | Periodo | Días disponibles (título) -->
     <mat-grid-tile colspan="12">

+ 2 - 2
vacaciones/src/app/components/mes/mesmsv/mesmsv.component.html

@@ -44,12 +44,12 @@
       <mat-grid-tile colspan="12">
         <mat-form-field appearance="standard" class="input-text">
           <mat-label>Fechas solicitadas </mat-label>
-          <mat-date-range-input [min]="minDate" [rangePicker]="picker" required [disabled]="disabledFechas">
+          <mat-date-range-input [min]="minDate" [rangePicker]="picker" required [disabled]="disabledFechas" >
             <input matStartDate placeholder="Fecha Inicial" [value]="fecha_inicio" formControlName="fecha_inicio" />
             <input matEndDate placeholder="Fecha Final" [value]="fecha_fin" formControlName="fecha_fin" />
           </mat-date-range-input>
           <mat-datepicker-toggle matSuffix [for]="picker" ></mat-datepicker-toggle>
-          <mat-date-range-picker class="text" #picker [dateClass]="dateClass"></mat-date-range-picker>
+          <mat-date-range-picker class="text" #picker [dateClass]="dateClass" ></mat-date-range-picker>
           <mat-error *ngIf="fecha_inicio!.invalid && fecha_fin!.invalid">{{
             fecha_inicio!.hasError("required")
             ? "Debe ingresar este campo"

+ 58 - 11
vacaciones/src/app/components/mes/mesmsv/mesmsv.component.ts

@@ -29,6 +29,8 @@ import {
   MatCalendarCellCssClasses,
 } from '@angular/material/datepicker';
 
+
+
 import { AlertaComponent } from '../../resources/dialogos/alerta/alerta.component';
 import { USERInterface } from 'src/app/interfaces/user-interface';
 import { ENCService } from 'src/app/services/enc/enc.service';
@@ -64,6 +66,7 @@ export class MESMSVComponent implements OnInit {
     status: false,
   };
   loading = false;
+  contadorCellDate: number = 0;
 
   minDate = new Date(
     new Date().getFullYear(),
@@ -80,6 +83,7 @@ export class MESMSVComponent implements OnInit {
   public perfil: number = 0;
   public otros_usuarios_arr: Array<any> = [];
   public enable = true;
+  public enableAux = true;
 
   diasFeriados: any[] = [];
   myControl: FormControl = new FormControl();
@@ -169,8 +173,9 @@ export class MESMSVComponent implements OnInit {
     this.myControl.reset();
   }
 
-  public cambioEmpleado() {
+  public async cambioEmpleado() {
     this.enable = true;
+    this.enableAux = true;
     this.fecha_inicio?.reset();
     this.fecha_fin?.reset();
 
@@ -198,6 +203,40 @@ export class MESMSVComponent implements OnInit {
       this.disabledFechas = true;
       this.dias_vacacionales?.disable();
     }
+
+    let idpolitica:any = [];
+
+    if (this.otro_usuario?.value) {
+
+      
+
+      let campo_empleado2: string = this.myControl.value;
+      let id_empleado3 = campo_empleado2.split(' - ')[0];
+      let filtro:Array<any> = this.otros_usuarios_arr.filter(
+        (element) => element.IDUSUARIO === id_empleado3
+      );
+      idpolitica = filtro[0].POLITICA;
+    }else{
+      idpolitica = this._encService.desencriptar(this.usuario_session.POLITICA);
+    }
+
+    
+    
+    await lastValueFrom(this._mcompvService.obtenerPoliticaUsuario(idpolitica)).then(
+      (data:any) => {
+        if (!data.error) {
+          this.politica = data.response.DIASDESCANSO;
+          this.getDaysPolitician(JSON.parse(data.response.DIASDESCANSO));
+        }
+      }, (error: HttpErrorResponse) => {
+        if (!error.ok)
+            this._validationService.openSnackBar('Ocurrió un error inesperado');
+          if (error.error.msg != undefined)
+            this._validationService.openSnackBar(error.error.msg);
+          if (error.status == 408)
+            this._validationService.openSnackBar('Conexion lenta');
+      }
+    )
   }
 
   public async cambioUsuario() {
@@ -262,33 +301,36 @@ export class MESMSVComponent implements OnInit {
       );
   }
 
-  dateClass: MatCalendarCellClassFunction<Date> = (cellDate, view) => {
+  dateClass: MatCalendarCellClassFunction<Date> = async (cellDate, view) => {
     if (this.enable) {
+      this.getDaysPolitician(JSON.parse(this.politica));
       this.cambioUsuario();
       this.enable = false;
+      
     }
-
+      
     let dateToString = cellDate?.toString();
     cellDate = new Date(dateToString!);
 
-    if (view === 'month') return this.filterDays(cellDate);
+    if (view === 'month') 
+      return this.filterDays(cellDate);
+    
     return '';
   };
 
   async filterDays(cellDate: any) {
-    const sleep = (ms: number) =>
-      new Promise((resolve) => setTimeout(resolve, ms));
+
     const collection = document.getElementsByClassName(
       'mat-calendar-body-cell-content'
     ) as HTMLCollectionOf<HTMLElement>;
 
-    await sleep(400);
-
+    
     let dateToString = cellDate?.toString();
     let lastPosition = this.dates_disable[this.dates_disable.length - 1];
     cellDate = new Date(dateToString!);
-
-    for (let index = 0; index < this.dates_disable.length; index++) {
+    
+    let index = 0;
+    for await (let item of this.dates_disable) {
       if (
         cellDate.getDate() == this.dates_disable[index].getDate() &&
         cellDate.getMonth() == this.dates_disable[index].getMonth() &&
@@ -314,6 +356,8 @@ export class MESMSVComponent implements OnInit {
           return 'weekendsDays';
         }
       }
+
+      index++;
     }
 
     return '';
@@ -595,7 +639,8 @@ export class MESMSVComponent implements OnInit {
       );
   }
 
-  getDaysPolitician(convert: any) {
+  async getDaysPolitician(convert: any) {
+    
     this.days_week_disable = [];
     if (convert.Do == 'Si') this.days_week_disable.push(0);
     if (convert.Lu == 'Si') this.days_week_disable.push(1);
@@ -604,6 +649,8 @@ export class MESMSVComponent implements OnInit {
     if (convert.Ju == 'Si') this.days_week_disable.push(4);
     if (convert.Vi == 'Si') this.days_week_disable.push(5);
     if (convert.Sa == 'Si') this.days_week_disable.push(6);
+    
+
   }
 
   get numero_empleado() {

+ 5 - 0
vacaciones/src/styles.css

@@ -61,6 +61,11 @@ tr.mat-row:hover {
   padding: 20px;
 }
 
+
+.mat-date-range-input-inner[disabled] {
+  color: rgba(0, 0, 0, 0.9);
+}
+
 /* ESTILO DE CARDS */
 
 /* - Ajusta el tamaño de las cards de tamaño estandar */