Files
doneit-web/src/app/pages/gabinete-digital/diplomas-assinar/diploma-assinar/diploma-assinar.page.ts
T
2023-10-31 11:56:34 +01:00

520 lines
14 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ModalController, PopoverController, ToastController } from '@ionic/angular';
import { ProcessesService } from 'src/app/services/processes.service';
import { momentG } from 'src/plugin/momentG';
import { ActivatedRoute } from '@angular/router';
import { DiplomaOptionsPage } from 'src/app/shared/popover/deploma-options/deploma-options.page';
import { ToastService } from 'src/app/services/toast.service';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { ThemeService } from 'src/app/services/theme.service'
import { RouteService } from 'src/app/services/route.service';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { AddNotePage } from 'src/app/modals/add-note/add-note.page';
import { DespachoService } from 'src/app/Rules/despacho.service'
import { AttachmentList } from 'src/app/models/Excludetask';
import { CreateProcessPage } from 'src/app/modals/create-process/create-process.page';
import { DiscartExpedientModalPage } from '../../discart-expedient-modal/discart-expedient-modal.page';
import { TaskService } from 'src/app/services/task.service'
import { TinyMCEPage } from 'src/app/tiny-mce/tiny-mce.page';
import { PopupQuestionPage } from 'src/app/modals/popup-question/popup-question.page';
import { PermissionService } from 'src/app/services/permission.service';
@Component({
selector: 'app-diploma-assinar',
templateUrl: './diploma-assinar.page.html',
styleUrls: ['./diploma-assinar.page.scss'],
})
export class DiplomaAssinarPage implements OnInit {
months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
serialnumber: string;
profile: string;
task: any
fulltask: any
intervenientes: any = []
cc: any = [];
attachments: any;
customDate: any;
caller: string;
mergedArray: any = [];
draftArray: any = [];
DraftIds = ""
DraftNames = ""
asDraft = true;
constructor(
private processes: ProcessesService,
public popoverController: PopoverController,
private modalController: ModalController,
private activatedRoute: ActivatedRoute,
private toastService: ToastService,
private RouteService: RouteService,
public ThemeService: ThemeService,
private httpErroHandle: HttpErrorHandle,
private despachoService: DespachoService,
public TaskService: TaskService,
private toastController: ToastController,
public p: PermissionService,
) {
this.activatedRoute.paramMap.subscribe(params => {
if (params["params"].SerialNumber) {
this.serialnumber = params["params"].SerialNumber;
}
if (params["params"].caller) {
this.caller = params["params"].caller;
}
});
window['tinyupdate'] = () => {
this.LoadTaskDetail(this.serialnumber);
}
}
ngOnInit() {
this.profile = "mdgpr";
this.LoadTaskDetail(this.serialnumber);
}
goBack() {
this.RouteService.goBack();
}
async openOptions(taskAction?: any) {
const popover = await this.popoverController.create({
component: DiplomaOptionsPage,
cssClass: 'exp-options',
componentProps: {
serialNumber: this.task.SerialNumber,
task: this.task,
showEnviarPendentes: false,
fulltask: this.fulltask,
DraftNames: this.DraftNames,
DraftIds: this.DraftIds,
asDraft: this.asDraft
},
translucent: true
});
return await popover.present().then(() => {
this.TaskService.loadDiplomas()
}, (error) => {
console.log(error)
})
}
async LoadTaskDetail(serial: string) {
this.processes.GetTask(serial).subscribe(res => {
this.TaskService.loadDiplomas();
this.task = {
"SerialNumber": res.serialNumber,
"Folio": res.workflowInstanceDataFields.Subject,
"Senders": res.originator.email,
"CreateDate": momentG(new Date(res.taskStartDate), 'yyyy-MM-dd HH:mm:ss'),
"DocumentURL": res.workflowInstanceDataFields.ViewerRequest,
"Remetente": res.workflowInstanceDataFields.Sender,
"Note": res.workflowInstanceDataFields.TaskMessage || res.workflowInstanceDataFields.Note,
"FolderId": res.workflowInstanceDataFields.FolderID,
"FsId": '361',
"DocId": res.workflowInstanceDataFields.DispatchDocId,
"WorkflowName": res.workflowDisplayName,
"DeadlineType": res.workflowInstanceDataFields.DeadlineType,
"activityInstanceName": res.activityInstanceName,
"Deadline": res.deadline,
"TaskStartDate": res.taskStartDate,
"InstanceID": res.workflowInstanceDataFields.InstanceID,
"FolderID": res.workflowInstanceDataFields.FolderID,
}
this.fulltask = res;
let stringDraft = res.workflowInstanceDataFields.DraftIds;
this.DraftIds = stringDraft
let split_stringDraft = stringDraft?.split(";").filter(Boolean);
this.mergedArray = []
try {
this.getDraft(split_stringDraft);
} catch (error) {
console.log(error)
}
this.getDocumentPdf(this.fulltask.Documents)
let thedate = new Date(this.task.CreateDate);
this.customDate = this.days[thedate.getDay()] + ", " + thedate.getDate() + " de " + (this.months[thedate.getMonth()]);
this.processes.GetTaskParticipants(this.task.FolderId).subscribe(users => {
this.intervenientes = users.filter(user => {
return user.Type == 'I';
});
this.cc = users.filter(user => {
return user.Type == 'CC';
});
});
this.getDocumentDetails(this.task.FolderId, '361');
}, (error) => {
try {
this.httpErroHandle.httpStatusHandle(error)
this.goBack()
} catch (e) {
window.history.back();
} finally {
this.httpErroHandle.httpStatusHandle(error)
}
});
}
async viewDocument({ Document, content }) {
if (Document.content == "") {
const modal = await this.modalController.create({
component: ViewDocumentPage,
componentProps: {
trustedUrl: '',
file: {
title: Document.Assunto,
url: '',
title_link: '',
},
Document,
applicationId: Document.ApplicationId,
docId: Document.DocId || Document.SourceId,
folderId: this.task.FolderId,
task: this.fulltask
},
cssClass: 'modal modal-desktop'
});
await modal.present();
} else {
const modal = await this.modalController.create({
component: TinyMCEPage,
componentProps: {
Document,
content,
InstanceID: this.task.InstanceID,
FolderId: this.task.FolderID,
DraftIds: this.DraftIds,
OriginalFileName: this.DraftNames,
Serialnumber:this.serialnumber
},
cssClass: 'modal modal-desktop'
});
await modal.present();
}
}
getDocumentDetails(forlderId: string, applicationId: string) {
this.processes.GetDocumentDetails(forlderId, applicationId).subscribe(res => {
this.attachments = res.Documents;
})
}
async Assinar() {
let body = {
"serialNumber": this.serialnumber,
"action": "Assinado",
"ActionTypeId": 99999842,
"FolderId": this.task.FolderID,
"dataFields": {
"ReviewUserComment": '',
"InstanceIDNew": this.task.InstanceID,
"DraftIds": "",
},
"AttachmentList": {
"ProcessInstanceID": this.task.InstanceID,
"DraftIds": null,
"Attachments": []
},
}
try {
await this.processes.CompleteTask(body).toPromise()
this.httpErroHandle.httpsSucessMessagge('Assinado')
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
}
finally { }
}
async AssinarDraft() {
if (this.asDraft) {
const modal = await this.modalController.create({
component: PopupQuestionPage,
componentProps: {
title: 'Deseja assinar este Diploma?',
/* message: 'Nota: Ao Efetuar esta operação, o tratamento deste diploma não poderá ser realizado a partir da caixa de correspondência' */
},
cssClass: "popup-question discart-expedient-modal",
backdropDismiss: true
});
modal.onDidDismiss().then(async (res) => {
const data = res.data
if (data == "Yes") {
let body = {
"InstanceId": this.task.InstanceID,
"FolderId": this.task.FolderID,
"DraftIds": this.DraftIds,
"OriginalFileName": this.DraftNames
}
const loader = this.toastService.loading()
try {
await this.processes.presidentialActionsSignature(body).toPromise()
await this.Assinar();
this.TaskService.loadDiplomas();
this.goBack();
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
}, (error) => {
console.log(error)
});
await modal.present();
} else {
this.httpErroHandle.validationMessagge("diplomaAsDraft");
}
}
async openAddNoteModal(actionName: string) {
let classs;
if (window.innerWidth <= 800) {
classs = 'modal modal-desktop'
} else {
classs = 'add-note-modal-no-height'
}
const modal = await this.modalController.create({
component: AddNotePage,
componentProps: {
showAttachmentBtn: true,
actionName: actionName
},
cssClass: classs,
backdropDismiss: true
});
modal.onDidDismiss().then(async (res) => {
if (res.data) {
const DocumentToSave = res.data.documents.map((e) => {
return {
ApplicationId: e.ApplicationType,
SourceId: e.Id,
}
});
let docs = {
ProcessInstanceID: "",
Attachments: DocumentToSave,
}
if (actionName == 'Executado') {
/* await this.executado(res.data.note, docs);
this.goBack(); */
}
else if (actionName == 'Arquivo') {
await this.arquivar(res.data.note, docs);
this.goBack();
}
else if (actionName == 'Reexecução') {
/* await this.reexecute(res.data.note, docs);
this.goBack(); */
} else if (actionName == 'Gerar Diploma') {
/* await this.generateDiploma(res.data.note, docs);
this.goBack(); */
}
this.TaskService.loadDiplomas()
}
}, (error) => {
console.log(error)
});
await modal.present();
}
async arquivar(note: string, documents: AttachmentList) {
const loader = this.toastService.loading()
try {
await this.despachoService.arquivar(note, documents, this.serialnumber).toPromise()
this.httpErroHandle.httpsSucessMessagge('Arquivar')
this.close();
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
async openExpedientActionsModal(taskAction: any, task: any) {
let classs;
if (window.innerWidth <= 800) {
classs = 'modal modal-desktop'
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: CreateProcessPage,
componentProps: {
taskAction: taskAction,
task: task,
profile: this.profile,
fulltask: this.fulltask,
asDrat: this.asDraft
},
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then(async (res) => {
if (res['data'] == 'openDiscart') {
await this.distartExpedientModal();
}
this.goBack();
}, (error) => {
console.log(error)
});
}
async distartExpedientModal() {
const modal = await this.modalController.create({
component: DiscartExpedientModalPage,
componentProps: {
serialNumber: this.fulltask.serialNumber,
folderId: this.fulltask.workflowInstanceDataFields.FolderID,
action: 'complete',
},
cssClass: 'discart-expedient-modal',
backdropDismiss: false
});
modal.onDidDismiss().then(res => {
if (res['data'] == 'close') {
this.close();
/*
this.close();
this.openMenu(); */
}
}, (error) => {
console.log(error)
});
await modal.present();
}
toDateString(e) {
return new Date(e).toDateString()
}
close() {
this.modalController.dismiss();
}
getDocumentPdf(Documents: any) {
Documents.forEach(element => {
let docObject = {
"ApplicationId": element.ApplicationId,
"Assunto": element.Assunto,
"DocDate": element.DocDate,
"DocId": element.DocId,
"DocNumber": element.DocNumber,
"FolderId": element.FolderId,
"Sender": element.Sender,
"SourceDocId": element.SourceDocId,
"content": "",
"path": "",
"ownerId": "",
"status": "",
}
this.mergedArray.push(docObject);
});
}
async getDraft(split_stringDraft: string[]) {
this.DraftNames = "";
this.DraftIds = "";
const draftPromises = split_stringDraft.map(async (strg) => {
console.log('List of ids', strg);
try {
const resd = await this.processes.GetDraftByID(strg).toPromise();
let object = {
"ApplicationId": "",
"Assunto": resd.data.description,
"DocDate": "",
"DocId": resd.data.id,
"DocNumber": "",
"FolderId": "",
"Sender": "",
"SourceDocId": "",
"content": resd.data.content,
"path": resd.data.path,
"ownerId": resd.data.ownerId,
"status": resd.data.status,
};
this.draftArray.push(object);
this.mergedArray.push(object);
this.DraftNames += resd.data.description + ";";
this.DraftIds += resd.data.id + ";";
console.log('List of draft', resd);
} catch (error) {
console.log('Error getting draft', error);
}
});
await Promise.all(draftPromises);
if (this.draftArray.length == 0) {
console.log('No draft found.');
this.asDraft = false
}
if (this.DraftNames) {
this.DraftNames = this.DraftNames.slice(0, -1);
this.DraftIds = this.DraftIds.slice(0, -1);
}
}
}