|
|
@@ -5,6 +5,8 @@ import { lastValueFrom } from 'rxjs';
|
|
|
import { PreventiveOrderSimulation, PreventiveOrderSimulationResponse } from 'src/app/interfaces/preventive-order-simulation.interface';
|
|
|
import { EncService } from 'src/app/services/enc/enc.service';
|
|
|
import { PreventiveMaintenanceService } from 'src/app/services/preventive-maintenance.service';
|
|
|
+import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
+import { DocumentManagementService } from 'src/app/services/document-management/document-management.service';
|
|
|
|
|
|
interface ToolInfo{
|
|
|
ID: string;
|
|
|
@@ -59,6 +61,7 @@ const SPARE_PARTS_TMP: ToolInfo[] = [
|
|
|
{ID: 'S20', NOMB: 'Cable HDMI 2m', MODE: 'ASD-181', CANTDISP: 6, TYPE: 'Refaccción', UNIT: 'Pieza'},
|
|
|
];
|
|
|
interface ExecutionStep{
|
|
|
+ id: number;
|
|
|
icon: string;
|
|
|
label: string;
|
|
|
isMain: boolean;
|
|
|
@@ -82,6 +85,9 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
eventIcon: string;
|
|
|
collectResources: boolean;
|
|
|
steps: ExecutionStep[];
|
|
|
+ simulating: boolean;
|
|
|
+ includeCharge: boolean;
|
|
|
+ hasBeenSimulated: boolean;
|
|
|
|
|
|
@ViewChild('simulationContainer', {static: false}) simulationContainer?: ElementRef;
|
|
|
private scrollContainer: any;
|
|
|
@@ -90,7 +96,9 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
@Inject(MAT_DIALOG_DATA) private _data: any,
|
|
|
@Inject(DOCUMENT) private _document: Document,
|
|
|
private _encService: EncService,
|
|
|
- private _prevMaintService: PreventiveMaintenanceService
|
|
|
+ private _prevMaintService: PreventiveMaintenanceService,
|
|
|
+ private _snackBar: MatSnackBar,
|
|
|
+ private _docMangeService: DocumentManagementService,
|
|
|
){
|
|
|
this.idOrder = 0;
|
|
|
this.isLoading = true;
|
|
|
@@ -103,6 +111,9 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.eventIcon = "";
|
|
|
this.collectResources = false;
|
|
|
this.steps = [];
|
|
|
+ this.simulating = false;
|
|
|
+ this.includeCharge = false;
|
|
|
+ this.hasBeenSimulated = false;
|
|
|
|
|
|
this.scrollContainer = this.simulationContainer?.nativeElement;
|
|
|
}
|
|
|
@@ -130,7 +141,6 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
|
|
|
if(!this.hasError){
|
|
|
this.orderSimulation = simulation.response;
|
|
|
- this.makeSimulation();
|
|
|
}
|
|
|
|
|
|
this.isLoading = false;
|
|
|
@@ -148,13 +158,22 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ startSimulation(){
|
|
|
+ this.steps = [];
|
|
|
+ this.makeSimulation();
|
|
|
+ }
|
|
|
+
|
|
|
async makeSimulation(){
|
|
|
+ this.hasBeenSimulated = false;
|
|
|
+ this.simulating = true;
|
|
|
this.starting = true;
|
|
|
await this.timeout(2500);
|
|
|
this.starting = false;
|
|
|
+ let idStep = 1;
|
|
|
|
|
|
if(this.orderSimulation?.TIPOACTIVADOR == 'Calendario'){
|
|
|
let step: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'event',
|
|
|
label: ` Activación de la ejecución de la órden #${this.idOrder}`,
|
|
|
isMain: true
|
|
|
@@ -163,6 +182,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(step);
|
|
|
}else if(this.orderSimulation?.TIPOACTIVADOR == 'Sintoma'){
|
|
|
let step: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'sensors',
|
|
|
label: ` Activación de la ejecución de la órden #${this.idOrder}`,
|
|
|
isMain: true
|
|
|
@@ -171,6 +191,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(step);
|
|
|
}else if(this.orderSimulation?.TIPOACTIVADOR == 'Medida'){
|
|
|
let step: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'device_thermostat',
|
|
|
label: ` Activación de la ejecución de la órden #${this.idOrder}`,
|
|
|
isMain: true
|
|
|
@@ -179,6 +200,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(step);
|
|
|
}else if(this.orderSimulation?.TIPOACTIVADOR == 'Valor'){
|
|
|
let step: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'speed',
|
|
|
label: ` Activación de la ejecución de la órden #${this.idOrder}`,
|
|
|
isMain: true
|
|
|
@@ -190,8 +212,10 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
await this.timeout(750);
|
|
|
this.scrollToBottom();
|
|
|
this.collectResources = true;
|
|
|
+ idStep++;
|
|
|
|
|
|
let stepTwo: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'fact_check',
|
|
|
label: 'Recolección de los materiales necesarios',
|
|
|
isMain: true
|
|
|
@@ -200,6 +224,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(stepTwo);
|
|
|
this.scrollToBottom();
|
|
|
await this.timeout(750);
|
|
|
+ idStep++;
|
|
|
|
|
|
let resources = JSON.parse(this.orderSimulation?.RECURSOS!);
|
|
|
let noResources = 0;
|
|
|
@@ -214,6 +239,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
if(type == 'S'){
|
|
|
let part = this.spareParts.filter(item2 => item2.ID == id)[0];
|
|
|
let subStep: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'remove',
|
|
|
label: `${part.NOMB}, ${resource.REQ} ${part.UNIT}(s) requerida(s).`,
|
|
|
isMain: false
|
|
|
@@ -223,6 +249,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
}else{
|
|
|
let tool = this.tools.filter(item2 => item2.ID == id)[0];
|
|
|
let subStep: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'remove',
|
|
|
label: `${tool.NOMB}, ${resource.REQ} ${tool.UNIT}(s) requerida(s).`,
|
|
|
isMain: false
|
|
|
@@ -232,6 +259,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
this.scrollToBottom();
|
|
|
+ idStep++;
|
|
|
|
|
|
if(cont == resources.length){
|
|
|
await this.timeout(750);
|
|
|
@@ -245,6 +273,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
|
|
|
if(noResources > 1){
|
|
|
let resStep: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'remove',
|
|
|
label: 'No se requieren materiales',
|
|
|
isMain: false
|
|
|
@@ -253,6 +282,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(resStep);
|
|
|
this.scrollToBottom();
|
|
|
await this.timeout(750);
|
|
|
+ idStep++;
|
|
|
}
|
|
|
|
|
|
let startArr = this.orderSimulation?.FECHAINICIO.split(' ')!;
|
|
|
@@ -263,6 +293,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
startHour = startHour > 12 ? startHour - 12 : startHour;
|
|
|
|
|
|
let stepThree: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'play_arrow',
|
|
|
label: `Inicio de las actividades de mantenimiento, ${startHour}:${startHourArr[1]} ${startPeriod}`,
|
|
|
isMain: true
|
|
|
@@ -271,11 +302,13 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(stepThree);
|
|
|
this.scrollToBottom();
|
|
|
await this.timeout(750);
|
|
|
+ idStep++;
|
|
|
|
|
|
let instructions = JSON.parse(this.orderSimulation?.INSTRUCCIONES!);
|
|
|
cont = 1;
|
|
|
for(const instruction of instructions){
|
|
|
let insStep: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'remove',
|
|
|
label: instruction.INSTRUCCION,
|
|
|
isMain: false
|
|
|
@@ -290,7 +323,8 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
await this.timeout(500);
|
|
|
}
|
|
|
|
|
|
- cont++
|
|
|
+ cont++;
|
|
|
+ idStep++;
|
|
|
}
|
|
|
|
|
|
let intHourTot = Math.trunc(this.orderSimulation?.TIETOTEST!);
|
|
|
@@ -334,6 +368,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
let stepFour: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'stop',
|
|
|
label: fourLabel,
|
|
|
isMain: true
|
|
|
@@ -342,8 +377,10 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(stepFour);
|
|
|
this.scrollToBottom();
|
|
|
await this.timeout(750);
|
|
|
+ idStep++;
|
|
|
|
|
|
let stepFive: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'attach_money',
|
|
|
label: 'Resultado del costo de los operadores de mantenimiento',
|
|
|
isMain: true
|
|
|
@@ -352,6 +389,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(stepFive);
|
|
|
this.scrollToBottom();
|
|
|
await this.timeout(750);
|
|
|
+ idStep++;
|
|
|
|
|
|
let analisisObj = JSON.parse(this.orderSimulation?.ANALISIS!);
|
|
|
let presonalObj = JSON.parse(this.orderSimulation?.PERSONAL!);
|
|
|
@@ -366,6 +404,7 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
for(const user of team){
|
|
|
let usrLabel = `${user.USER}, ${teamConf.NOMB} - ${teamConf.ESP}, costo por hora: $${user.COST}, horas requeridas: ${user.HOURS}, costo total: $${parseInt(user.COST) * parseInt(user.HOURS)}`;
|
|
|
let usrStep: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'remove',
|
|
|
label: usrLabel,
|
|
|
isMain: false
|
|
|
@@ -376,10 +415,12 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
this.steps.push(usrStep);
|
|
|
this.scrollToBottom();
|
|
|
await this.timeout(500);
|
|
|
+ idStep++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
let stepSix: ExecutionStep = {
|
|
|
+ id: idStep,
|
|
|
icon: 'payments',
|
|
|
label: `Costo total de los operadores: $${totalCost}`,
|
|
|
isMain: true
|
|
|
@@ -387,6 +428,31 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
|
|
|
this.steps.push(stepSix);
|
|
|
this.scrollToBottom();
|
|
|
+ idStep++;
|
|
|
+
|
|
|
+ this.simulating = false;
|
|
|
+ this.hasBeenSimulated = true;
|
|
|
+
|
|
|
+ try{
|
|
|
+ let idUser = localStorage.getItem('idusuario');
|
|
|
+ let idOrderEnc = await this._encService.encrypt(`${this.idOrder}`);
|
|
|
+ let formData = new FormData();
|
|
|
+
|
|
|
+ formData.append('id_user', idUser!);
|
|
|
+ formData.append('linea', '1');
|
|
|
+ formData.append('id_order', idOrderEnc);
|
|
|
+ formData.append('content', JSON.stringify(this.steps));
|
|
|
+
|
|
|
+ await lastValueFrom(this._prevMaintService.saveOrderSimulation(formData));
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ this.openSnackBar(error.error.msg );
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async timeout(ms: number): Promise<void>{
|
|
|
@@ -404,4 +470,48 @@ export class SimulationDialogComponent implements OnInit {
|
|
|
});
|
|
|
}, 1);
|
|
|
}
|
|
|
+
|
|
|
+ async printPDF(){
|
|
|
+ try{
|
|
|
+ this.openSnackBar('Generando PDF...');
|
|
|
+ let idUser = localStorage.getItem('idusuario');
|
|
|
+ let shortEnc = await lastValueFrom(this._encService.shortEncrypt(idUser!));
|
|
|
+ let idOrderEnc = await this._encService.encrypt(`${this.idOrder}`);
|
|
|
+ let idOrderShort = await lastValueFrom(this._encService.shortEncrypt(idOrderEnc));
|
|
|
+
|
|
|
+ let orderSimulation = await lastValueFrom(this._prevMaintService.printOrderSimulation(
|
|
|
+ idOrderShort.response.encrypted,
|
|
|
+ shortEnc.response.encrypted,
|
|
|
+ 1
|
|
|
+ ))
|
|
|
+
|
|
|
+ let idFileEnc = await this._encService.encrypt(orderSimulation.response.fileID);
|
|
|
+ let idFileShort = await lastValueFrom(this._encService.shortEncrypt(idFileEnc));
|
|
|
+ let download = this._document.getElementById(`download`) as HTMLAnchorElement;
|
|
|
+
|
|
|
+ let downloadToken = await lastValueFrom(this._docMangeService.getDownloadToken(
|
|
|
+ idFileShort.response.encrypted,
|
|
|
+ shortEnc.response.encrypted,
|
|
|
+ 1
|
|
|
+ ));
|
|
|
+
|
|
|
+ download.href = `http://git.ittec.mx/sam/public/api/download-file/${downloadToken.response.TOKEN}/${shortEnc.response.encrypted}/1`;
|
|
|
+ download.download = orderSimulation.response.fileID;
|
|
|
+ download.click();
|
|
|
+ }catch(error: any){
|
|
|
+ if(error.error == undefined){
|
|
|
+ this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else if(error.error.msg == undefined){
|
|
|
+ this.openSnackBar('Ocurrió un error inesperado.');
|
|
|
+ }else{
|
|
|
+ this.openSnackBar(error.error.msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ openSnackBar(msg: string){
|
|
|
+ this._snackBar.open(msg, undefined, {
|
|
|
+ duration: 2500,
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|