|
|
@@ -1,4 +1,10 @@
|
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
+import {
|
|
|
+ Component,
|
|
|
+ Input,
|
|
|
+ OnInit,
|
|
|
+ ViewEncapsulation,
|
|
|
+ AfterViewInit,
|
|
|
+} from '@angular/core';
|
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
@@ -15,17 +21,17 @@ import {
|
|
|
MAT_DATE_FORMATS,
|
|
|
MAT_DATE_LOCALE,
|
|
|
} from '@angular/material/core';
|
|
|
-import 'moment/locale/es';
|
|
|
+import {
|
|
|
+ MatCalendarCellClassFunction,
|
|
|
+ MatCalendarCellCssClasses,
|
|
|
+} from '@angular/material/datepicker';
|
|
|
+
|
|
|
import { AlertaComponent } from '../../resources/dialogos/alerta/alerta.component';
|
|
|
import { USERInterface } from 'src/app/interfaces/user-interface';
|
|
|
-import { ThisReceiver } from '@angular/compiler';
|
|
|
-import { threadId } from 'worker_threads';
|
|
|
-import { throws } from 'assert';
|
|
|
import { ENCService } from 'src/app/services/enc/enc.service';
|
|
|
import { MCOMDFService } from 'src/app/services/mco/mcomdf/mcomdf.service';
|
|
|
import { MCOMPVService } from 'src/app/services/mco/mcompv/mcompv.service';
|
|
|
-import { MCOMDFInterface } from 'src/app/interfaces/mco/mcomdf/mcomdf-interface';
|
|
|
-import { ValidationsService } from 'src/app/services/validations.service';
|
|
|
+import { Call } from '@angular/compiler';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-mesmsv',
|
|
|
@@ -40,8 +46,13 @@ import { ValidationsService } from 'src/app/services/validations.service';
|
|
|
},
|
|
|
{ provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS },
|
|
|
],
|
|
|
+ encapsulation: ViewEncapsulation.None,
|
|
|
})
|
|
|
export class MESMSVComponent implements OnInit {
|
|
|
+ newData = new Date();
|
|
|
+ array_disables: any[] = [];
|
|
|
+ dates_disable: any = [];
|
|
|
+ days_week_disable: any = [];
|
|
|
formGroup: FormGroup;
|
|
|
dias: number = 0;
|
|
|
fechaActual = new Date();
|
|
|
@@ -49,7 +60,13 @@ export class MESMSVComponent implements OnInit {
|
|
|
text: 'Enviar',
|
|
|
status: false,
|
|
|
};
|
|
|
- minDate = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1);
|
|
|
+ loading = false;
|
|
|
+
|
|
|
+ minDate = new Date(
|
|
|
+ new Date().getFullYear(),
|
|
|
+ new Date().getMonth(),
|
|
|
+ new Date().getDate() + 1
|
|
|
+ );
|
|
|
todayDate = new Date();
|
|
|
dias_feriados: any[] = null!;
|
|
|
politica: string = null!;
|
|
|
@@ -72,8 +89,7 @@ export class MESMSVComponent implements OnInit {
|
|
|
private _mcomdfService: MCOMDFService,
|
|
|
private _mcompvService: MCOMPVService,
|
|
|
private _snackBar: MatSnackBar,
|
|
|
- private _mesmsv: MESMSVService,
|
|
|
- private _validationService: ValidationsService
|
|
|
+ private _mesmsv: MESMSVService
|
|
|
) {
|
|
|
this.formGroup = this.createFormGroup();
|
|
|
}
|
|
|
@@ -82,6 +98,63 @@ export class MESMSVComponent implements OnInit {
|
|
|
this.obtenerDiasFeriados();
|
|
|
}
|
|
|
|
|
|
+ dateClass: MatCalendarCellClassFunction<Date> = (cellDate, view) => {
|
|
|
+ let dateToString = cellDate?.toString();
|
|
|
+ cellDate = new Date(dateToString!);
|
|
|
+
|
|
|
+ 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(100);
|
|
|
+
|
|
|
+ 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++) {
|
|
|
+ if (
|
|
|
+ cellDate.getDate() == this.dates_disable[index].getDate() &&
|
|
|
+ cellDate.getMonth() == this.dates_disable[index].getMonth() &&
|
|
|
+ cellDate.getFullYear() == lastPosition.getFullYear()
|
|
|
+ ) {
|
|
|
+ collection[cellDate.getDate() - 1].style.color = 'white';
|
|
|
+ collection[cellDate.getDate() - 1].style.background = 'orange';
|
|
|
+
|
|
|
+ return 'example-custom-date-class';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (
|
|
|
+ cellDate.getDay() == this.days_week_disable[0] ||
|
|
|
+ cellDate.getDay() == this.days_week_disable[1] ||
|
|
|
+ cellDate.getDay() == this.days_week_disable[2] ||
|
|
|
+ cellDate.getDay() == this.days_week_disable[3] ||
|
|
|
+ cellDate.getDay() == this.days_week_disable[4] ||
|
|
|
+ cellDate.getDay() == this.days_week_disable[5] ||
|
|
|
+ cellDate.getDay() == this.days_week_disable[6]
|
|
|
+ ) {
|
|
|
+ if (cellDate.getFullYear() == lastPosition.getFullYear()) {
|
|
|
+ collection[cellDate.getDate() - 1].style.background = '';
|
|
|
+
|
|
|
+ collection[cellDate.getDate() - 1].style.fontWeight = 'bold';
|
|
|
+
|
|
|
+ return 'weekendsDays';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
private createFormGroup() {
|
|
|
return new FormGroup({
|
|
|
numero_empleado: new FormControl({
|
|
|
@@ -116,22 +189,22 @@ export class MESMSVComponent implements OnInit {
|
|
|
this._mesmsv.crear(insertar).subscribe(
|
|
|
(data) => {
|
|
|
if (!data.error) {
|
|
|
- this._validationService.openSnackBar('¡Solicitud enviada!');
|
|
|
+ this.snackAlert('¡Solicitud enviada!');
|
|
|
} else {
|
|
|
- this._validationService.openSnackBar(data.msg);
|
|
|
+ this.snackAlert(data.msg);
|
|
|
}
|
|
|
this.envioForm.text = 'Enviar';
|
|
|
this.envioForm.status = false;
|
|
|
},
|
|
|
(error) => {
|
|
|
if (!error.ok) {
|
|
|
- this._validationService.openSnackBar('Ocurrió un error inesperado');
|
|
|
+ this.snackAlert('Ocurrió un error inesperado');
|
|
|
}
|
|
|
if (error.error.msg != undefined) {
|
|
|
- this._validationService.openSnackBar(error.error.msg);
|
|
|
+ this.snackAlert(error.error.msg);
|
|
|
}
|
|
|
if (error.status == 408) {
|
|
|
- this._validationService.openSnackBar('Conexion lenta');
|
|
|
+ this.snackAlert('Conexion lenta');
|
|
|
}
|
|
|
this.envioForm.text = 'Enviar';
|
|
|
this.envioForm.status = false;
|
|
|
@@ -367,16 +440,21 @@ export class MESMSVComponent implements OnInit {
|
|
|
this._mcomdfService.obtener().subscribe(
|
|
|
(response) => {
|
|
|
this.dias_feriados = response.response;
|
|
|
+ this.dates_disable = response.response.map((object: any) => {
|
|
|
+ return new Date(object.ANIO, object.MES - 1, object.DIA);
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log(this.dates_disable);
|
|
|
},
|
|
|
(error) => {
|
|
|
if (!error.ok) {
|
|
|
- this._validationService.openSnackBar('Ocurrió un error inesperado');
|
|
|
+ this.snackAlert('Ocurrió un error inesperado');
|
|
|
}
|
|
|
if (error.error.msg != undefined) {
|
|
|
- this._validationService.openSnackBar(error.error.msg);
|
|
|
+ this.snackAlert(error.error.msg);
|
|
|
}
|
|
|
if (error.status == 408) {
|
|
|
- this._validationService.openSnackBar('Conexion lenta');
|
|
|
+ this.snackAlert('Conexion lenta');
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
@@ -384,21 +462,53 @@ export class MESMSVComponent implements OnInit {
|
|
|
this._mcompvService.obtenerPolitica().subscribe(
|
|
|
(response) => {
|
|
|
this.politica = response.response.DIASDESCANSO;
|
|
|
+ let convert = JSON.parse(response.response.DIASDESCANSO);
|
|
|
+ this.getDaysPolitician(convert);
|
|
|
},
|
|
|
(error) => {
|
|
|
if (!error.ok) {
|
|
|
- this._validationService.openSnackBar('Ocurrió un error inesperado');
|
|
|
+ this.snackAlert('Ocurrió un error inesperado');
|
|
|
}
|
|
|
if (error.error.msg != undefined) {
|
|
|
- this._validationService.openSnackBar(error.error.msg);
|
|
|
+ this.snackAlert(error.error.msg);
|
|
|
}
|
|
|
if (error.status == 408) {
|
|
|
- this._validationService.openSnackBar('Conexion lenta');
|
|
|
+ this.snackAlert('Conexion lenta');
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ getDaysPolitician(convert: any) {
|
|
|
+ if (convert.Do == 'Si') {
|
|
|
+ this.days_week_disable.push(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (convert.Lu == 'Si') {
|
|
|
+ this.days_week_disable.push(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (convert.Ma == 'Si') {
|
|
|
+ this.days_week_disable.push(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (convert.Mi == 'Si') {
|
|
|
+ this.days_week_disable.push(3);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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() {
|
|
|
return this.formGroup.get('numero_empleado');
|
|
|
}
|
|
|
@@ -429,4 +539,10 @@ export class MESMSVComponent implements OnInit {
|
|
|
let day = 1000 * 60 * 60 * 24;
|
|
|
return (date2utc - date1utc) / day;
|
|
|
}
|
|
|
+
|
|
|
+ private snackAlert(mensaje: string) {
|
|
|
+ this._snackBar.open(mensaje, 'Cerrar', {
|
|
|
+ duration: 4000,
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|