1
|
import { LookupData } from './../../../shared/models/lookup-data.interface';
|
2
|
import { AuthService } from './../../../shared/services/auth.service';
|
3
|
import { USER_RIGHTS } from 'src/app/shared/enums/USER_RIGHTS.enum';
|
4
|
import { ErrorHandlingService } from 'src/app/shared/services/error-handling/error-handling.service';
|
5
|
import { IPowerClient } from './../../../shared/models/ipower-client.interface';
|
6
|
import { IpowerClientsService } from 'src/app/shared/services/administration/ipower-clients.service';
|
7
|
import { ReceivedFile } from './../../../shared/models/inbox-document.interface';
|
8
|
import { FormBuilder, Validators } from '@angular/forms';
|
9
|
import { Component, Input, OnInit, ViewChild } from '@angular/core';
|
10
|
import { ActivatedRoute } from '@angular/router';
|
11
|
import { DialogService } from 'primeng/dynamicdialog';
|
12
|
import { FileViewerPopupComponent } from '../../inbox/inbox-management/inbox-dialogs/file-viewer-popup/file-viewer-popup.component';
|
13
|
import { FullInvoiceProcess } from '../../../shared/models/full-invoice-process.interface';
|
14
|
import { InvoiceProcessesService } from '../../../shared/services/invoice-processes.service';
|
15
|
import { JournalEntry } from '../../../shared/models/journal-entry.interface';
|
16
|
import { AlteryxException } from '../../../shared/models/alteryx-exception.interface';
|
17
|
import { AlteryxUnhandledData } from '../../../shared/models/alteryx-unhandled-data.interface';
|
18
|
import { removeSummaryDuplicates } from '@angular/compiler';
|
19
|
import { ConfirmationService } from 'primeng/api';
|
20
|
import { TranslateService } from '@ngx-translate/core';
|
21
|
import { NotificationsHandlingService } from 'src/app/shared/services/notifications-handling/notifications-handling.service';
|
22
|
import { DataCapturingAndVerificationComponent } from './data-capturing-and-verification/data-capturing-and-verification.component';
|
23
|
<<<<<<< Updated upstream
|
24
|
import { Location } from '@angular/common';
|
25
|
import { Router } from '@angular/router';
|
26
|
=======
|
27
|
import {ProcessHistory} from "../../../shared/models/process-history.interface";
|
28
|
>>>>>>> Stashed changes
|
29
|
|
30
|
@Component({
|
31
|
selector: 'app-invoice-processing',
|
32
|
templateUrl: './invoice-processing.component.html',
|
33
|
styleUrls: ['./invoice-processing.component.scss']
|
34
|
})
|
35
|
export class InvoiceProcessingComponent implements OnInit {
|
36
|
|
37
|
@ViewChild('dataCapturing', { static: false })
|
38
|
dataCapturingComponent: DataCapturingAndVerificationComponent;
|
39
|
|
40
|
invoiceProcess: FullInvoiceProcess = {} as FullInvoiceProcess;
|
41
|
iPowerClient: IPowerClient;
|
42
|
receivedFiles: ReceivedFile[];
|
43
|
processWorkflowActions: string[];
|
44
|
processWorkflowButton: boolean;
|
45
|
|
46
|
rows = 10;
|
47
|
loading: boolean;
|
48
|
|
49
|
refreshedJournalEntries: JournalEntry[];
|
50
|
refreshedAlteryxExceptions: AlteryxException[];
|
51
|
refreshedAlteryxUnhandled: AlteryxUnhandledData[];
|
52
|
accordionTabStatusList: boolean[] = [false, false, false, false, false];
|
53
|
|
54
|
processForm = this.fb.group({
|
55
|
processId: [{ value: null, disabled: true }],
|
56
|
status: [{ value: null, disabled: true }],
|
57
|
iPowerClientName: [{ value: null, disabled: true }],
|
58
|
iPowerClientCode: [{ value: null, disabled: true }],
|
59
|
personalData: [{ value: null, disabled: true }],
|
60
|
assignedTo: [{ value: null, disabled: true }],
|
61
|
processWorkflow: [{ value: null, disabled: false }, [Validators.required]]
|
62
|
});
|
63
|
|
64
|
constructor(
|
65
|
private fb: FormBuilder,
|
66
|
private actRoute: ActivatedRoute,
|
67
|
private invoiceProcessesService: InvoiceProcessesService,
|
68
|
private iPowerClientsService: IpowerClientsService,
|
69
|
private dialogService: DialogService,
|
70
|
private errorHandlingService: ErrorHandlingService,
|
71
|
public authService: AuthService,
|
72
|
private confirmationService: ConfirmationService,
|
73
|
private translate: TranslateService,
|
74
|
private notificationService: NotificationsHandlingService,
|
75
|
private router: Router
|
76
|
) { }
|
77
|
|
78
|
ngOnInit(): void {
|
79
|
this.actRoute.params.subscribe((params: any) => this.initData(params.id));
|
80
|
}
|
81
|
|
82
|
initData(invoiceProcessId: number): void {
|
83
|
// Get the InvoiceProcess.
|
84
|
this.invoiceProcessesService.getFullInvoiceProcessById(invoiceProcessId).subscribe(
|
85
|
(val: FullInvoiceProcess) => {
|
86
|
this.invoiceProcess = val;
|
87
|
|
88
|
// Get the ReceivedFiles.
|
89
|
this.receivedFiles = val.filesPerProcess.map(ffp => ffp.receivedFile);
|
90
|
|
91
|
// Update display with what we have so far.
|
92
|
this.initDisplay(this.invoiceProcess, null);
|
93
|
|
94
|
// Get the IPowerClient - Yes, subscription within subscription, long live the cold observables.
|
95
|
const clientId = val.recordsPerProcess[0]?.record?.ipowerClientId;
|
96
|
this.iPowerClientsService.getClientById(clientId).subscribe((val: IPowerClient) => {
|
97
|
this.iPowerClient = val;
|
98
|
this.initDisplay(null, this.iPowerClient);
|
99
|
|
100
|
},
|
101
|
err => this.errorHandlingService.showHttpResponseError(err)
|
102
|
);
|
103
|
},
|
104
|
err => this.errorHandlingService.showHttpResponseError(err)
|
105
|
);
|
106
|
}
|
107
|
|
108
|
preview(receivedFile: ReceivedFile): void {
|
109
|
this.dialogService.open(FileViewerPopupComponent, { data: receivedFile });
|
110
|
}
|
111
|
|
112
|
initDisplay(process: FullInvoiceProcess, client: IPowerClient): void {
|
113
|
|
114
|
// Form Value-setting
|
115
|
if (process) {
|
116
|
// If even a single ReceivedFile has 'personalData', the whole InvoiceProcess is considered to have personalData.
|
117
|
const hasPersonalData: boolean = process.filesPerProcess.find(fpp => fpp.receivedFile.dmsPersonalData) != null;
|
118
|
this.processForm.get('personalData').setValue(hasPersonalData);
|
119
|
|
120
|
this.processForm.get('processId').setValue(process.id);
|
121
|
this.processForm.get('status').setValue(process.processStatus.name);
|
122
|
|
123
|
this.processForm.get('assignedTo').setValue(process.userId);
|
124
|
|
125
|
switch (process.processStatus.id) {
|
126
|
case 4:
|
127
|
case 1:
|
128
|
case 8:
|
129
|
case 6:
|
130
|
this.processWorkflowActions = ["ABBYY Verification", "Process Cancelation"];
|
131
|
break;
|
132
|
case 5:
|
133
|
this.processWorkflowActions = ["Process Cancelation"];
|
134
|
break;
|
135
|
case 3:
|
136
|
case 2:
|
137
|
this.processWorkflowActions = ["ABBYY Verification", "Process Cancelation", "Alteryx Recalculation", "Process Completed"];
|
138
|
break;
|
139
|
case 7:
|
140
|
case 9:
|
141
|
this.processForm.controls['processWorkflow'].disable();
|
142
|
this.processWorkflowButton = true;
|
143
|
break;
|
144
|
default:
|
145
|
break;
|
146
|
}
|
147
|
}
|
148
|
|
149
|
if (client) {
|
150
|
this.processForm.get('iPowerClientName').setValue(client.name);
|
151
|
this.processForm.get('iPowerClientCode').setValue(client.clientCode);
|
152
|
}
|
153
|
}
|
154
|
|
155
|
/*
|
156
|
* If Data Capturing component notifies us that an abbyy task is completed, we refresh the data, to unlock
|
157
|
*/
|
158
|
onProcessCompleted(id: number) {
|
159
|
this.initData(id);
|
160
|
this.closeAllTabsProcessWorkflow();
|
161
|
}
|
162
|
|
163
|
/*
|
164
|
* UserRights-check Methods
|
165
|
*/
|
166
|
canSeeDataCaptureAndVerification(): boolean {
|
167
|
return this.authService.userHasRightForClient(USER_RIGHTS.D04, this.iPowerClient?.id) && (this.invoiceProcess?.processStatus?.id == 5 || this.invoiceProcess?.processStatus?.id == 8 );
|
168
|
}
|
169
|
|
170
|
canSeeJournalEntriesVerification(): boolean {
|
171
|
return (this.invoiceProcess?.processStatus?.id !== 5 && this.authService.userHasRightForClient(USER_RIGHTS.D05, this.iPowerClient?.id)) || (this.invoiceProcess?.processStatus?.id !== 8 && this.authService.userHasRightForClient(USER_RIGHTS.D05, this.iPowerClient?.id)) ;
|
172
|
}
|
173
|
|
174
|
canSeeManipulationOfExceptions(): boolean {
|
175
|
return (this.invoiceProcess?.processStatus?.id !== 5 && this.authService.userHasRightForClient(USER_RIGHTS.D06, this.iPowerClient?.id)) || (this.invoiceProcess?.processStatus?.id !== 8 && this.authService.userHasRightForClient(USER_RIGHTS.D06, this.iPowerClient?.id)) ;
|
176
|
}
|
177
|
|
178
|
canSeeManipulationOfUnhandledData(): boolean {
|
179
|
return (this.invoiceProcess?.processStatus?.id !== 5 && this.authService.userHasRightForClient(USER_RIGHTS.D07, this.iPowerClient?.id)) || (this.invoiceProcess?.processStatus?.id !== 8 && this.authService.userHasRightForClient(USER_RIGHTS.D07, this.iPowerClient?.id)) ;
|
180
|
}
|
181
|
|
182
|
canSeeMissingRecords(): boolean {
|
183
|
return (this.invoiceProcess?.processStatus?.id !== 5 && this.authService.userHasRightForClient(USER_RIGHTS.D01, this.iPowerClient?.id)) || (this.invoiceProcess?.processStatus?.id !== 8 && this.authService.userHasRightForClient(USER_RIGHTS.D01, this.iPowerClient?.id)) ;
|
184
|
}
|
185
|
|
186
|
assignToMe(): void {
|
187
|
this.invoiceProcessesService.assignProcess(this.invoiceProcess.id, this.authService.userDetails.name).subscribe(result => {
|
188
|
this.processForm.get('assignedTo').setValue(this.authService.userDetails.name);
|
189
|
this.invoiceProcess.userId = this.authService.userDetails.name;
|
190
|
});
|
191
|
}
|
192
|
|
193
|
unassignFromMe(): void {
|
194
|
this.invoiceProcessesService.unassignProcess(this.invoiceProcess.id).subscribe(result => {
|
195
|
this.processForm.get('assignedTo').setValue(null);
|
196
|
this.invoiceProcess.userId = null;
|
197
|
});
|
198
|
}
|
199
|
|
200
|
closeAllTabsProcessWorkflow() {
|
201
|
let i;
|
202
|
for (i = 0; i < 4; i++) {
|
203
|
this.accordionTabStatusList[i] = false;
|
204
|
}
|
205
|
}
|
206
|
|
207
|
processWorkFlowProcedure() {
|
208
|
console.log(this.processForm.get('processWorkflow').value)
|
209
|
if (this.processForm.get('processWorkflow').value) {
|
210
|
switch (this.processForm.get('processWorkflow').value) {
|
211
|
case 'Alteryx Recalculation':
|
212
|
this.confirmationService.confirm({
|
213
|
message: this.translate.instant('ALTERYX-RECALCULATION-MESSAGE'),
|
214
|
accept: () => {
|
215
|
this.invoiceProcessesService.sendProcessToAlteryxRecalculation(this.invoiceProcess.id).subscribe(result => {
|
216
|
this.notificationService.showAlteryxRecalculation();
|
217
|
this.actRoute.params.subscribe((params: any) => this.initData(params.id));
|
218
|
this.closeAllTabsProcessWorkflow();
|
219
|
},
|
220
|
error => {
|
221
|
this.errorHandlingService.showHttpResponseError(error);
|
222
|
});
|
223
|
}, reject: () => {
|
224
|
}
|
225
|
});
|
226
|
break;
|
227
|
case 'ABBYY Verification':
|
228
|
this.confirmationService.confirm({
|
229
|
message: this.translate.instant('ABBY-VERIFICATION-MESSAGE'),
|
230
|
accept: () => {
|
231
|
this.invoiceProcessesService.sendProcessToAbbyyVerification(this.invoiceProcess.id).subscribe(result => {
|
232
|
this.notificationService.showAbbyVerification();
|
233
|
this.actRoute.params.subscribe((params: any) => this.initData(params.id));
|
234
|
this.closeAllTabsProcessWorkflow();
|
235
|
},
|
236
|
error => {
|
237
|
this.errorHandlingService.showHttpResponseError(error);
|
238
|
});
|
239
|
}, reject: () => {
|
240
|
}
|
241
|
});
|
242
|
break;
|
243
|
case 'Process Cancelation':
|
244
|
this.confirmationService.confirm({
|
245
|
message: this.translate.instant('PROCESS-CANCELATION-MESSAGE'),
|
246
|
accept: () => {
|
247
|
this.invoiceProcessesService.setProcessCanceled(this.invoiceProcess.id).subscribe(result => {
|
248
|
this.notificationService.showProcessCancelation();
|
249
|
this.actRoute.params.subscribe((params: any) => this.initData(params.id));
|
250
|
this.closeAllTabsProcessWorkflow();
|
251
|
},
|
252
|
error => {
|
253
|
this.errorHandlingService.showHttpResponseError(error);
|
254
|
});
|
255
|
}, reject: () => {
|
256
|
}
|
257
|
});
|
258
|
break;
|
259
|
case 'Process Completed':
|
260
|
this.confirmationService.confirm({
|
261
|
message: this.translate.instant('PROCESS-COMPLETED-MESSAGE'),
|
262
|
accept: () => {
|
263
|
this.invoiceProcessesService.setProcessCompleted(this.invoiceProcess.id).subscribe(result => {
|
264
|
this.notificationService.showProcessComplete();
|
265
|
this.actRoute.params.subscribe((params: any) => this.initData(params.id));
|
266
|
this.closeAllTabsProcessWorkflow();
|
267
|
},
|
268
|
error => {
|
269
|
this.errorHandlingService.showHttpResponseError(error);
|
270
|
});
|
271
|
}, reject: () => {
|
272
|
}
|
273
|
});
|
274
|
break;
|
275
|
default:
|
276
|
break;
|
277
|
}
|
278
|
}
|
279
|
}
|
280
|
|
281
|
onTabOpen(e): void {
|
282
|
if (e !== null && e.index !== null) {
|
283
|
this.accordionTabStatusList[e.index] = true;
|
284
|
}
|
285
|
}
|
286
|
|
287
|
onTabClose(e): void {
|
288
|
if (e !== null && e.index !== null) {
|
289
|
this.accordionTabStatusList[e.index] = false;
|
290
|
}
|
291
|
}
|
292
|
|
293
|
refreshTabTableData(title: string): void {
|
294
|
switch (title) {
|
295
|
case 'journal entries':
|
296
|
this.invoiceProcessesService.refreshJournalEntries(this.invoiceProcess.id).subscribe(result => {
|
297
|
if (result !== null) {
|
298
|
this.invoiceProcess.journalEntries = result;
|
299
|
}
|
300
|
});
|
301
|
break;
|
302
|
case 'manipulation of exceptions':
|
303
|
this.invoiceProcessesService.refreshAlteryxExceptions(this.invoiceProcess.id).subscribe(result => {
|
304
|
if (result !== null) {
|
305
|
this.invoiceProcess.alteryxExceptions = result;
|
306
|
}
|
307
|
});
|
308
|
break;
|
309
|
case 'manipulation of unhandled data':
|
310
|
this.invoiceProcessesService.refreshAlteryxUnhandled(this.invoiceProcess.id).subscribe(result => {
|
311
|
if (result !== null) {
|
312
|
this.invoiceProcess.alteryxUnhandled = result;
|
313
|
}
|
314
|
});
|
315
|
break;
|
316
|
case 'data capturing and verification':
|
317
|
this.dataCapturingComponent.refreshIFrame();
|
318
|
break;
|
319
|
default:
|
320
|
break;
|
321
|
}
|
322
|
}
|
323
|
|
324
|
goBack(){
|
325
|
this.router.navigate(['/pages/processes', { userPressedBack: true }]);
|
326
|
|
327
|
}
|
328
|
|
329
|
|
330
|
}
|