Project

General

Profile

1
import { ActivatedRoute } from '@angular/router';
2
import { environment } from './../../../../environments/environment.dev-docker';
3
import { USER_RIGHTS } from './../../../shared/enums/USER_RIGHTS.enum';
4
import { InvoiceProcessesRouterParams } from './../../../shared/models/invoice-processes-router-params.interface';
5
import { InvoiceProcessCriteriaInterface } from './../../../shared/models/invoice-process-search-criteria.interface';
6
import { UtilsService } from './../../../shared/utils/utils.service';
7
import { InvoiceProcessesService } from './../../../shared/services/invoice-processes.service';
8
import { AuthService } from './../../../shared/services/auth.service';
9
import { FormBuilder } from '@angular/forms';
10
import { Component, OnInit, ViewChild } from '@angular/core';
11
import { InvoiceProcessingComponent } from '../invoice-processing/invoice-processing.component';
12
import { SearchListStateService } from 'src/app/shared/back-button/search-list-state.service';
13

    
14
@Component({
15
  selector: 'app-invoice-process-management',
16
  templateUrl: './invoice-process-management.component.html',
17
  styleUrls: ['./invoice-process-management.component.scss']
18
})
19
export class InvoiceProcessManagementComponent implements OnInit {
20

    
21
  documentRequest: InvoiceProcessCriteriaInterface;
22
  valueForm : InvoiceProcessCriteriaInterface;
23
  searchCriteriaForm = this.fb.group({
24
    userId: [this.auth.userDetails.id],
25
    fromDate: [null],
26
    toDate: [null],
27
    docClassification: [null],
28
    fileCode: [null],
29
    fileType: [null],
30
    processId: [null],
31
    processStatus: [null],
32
    ipowerClientName: [null],
33
    ipowerClientCode: [null],
34
    personalData: [null],
35
    username: [null]
36
  });
37

    
38
  parameters: InvoiceProcessesRouterParams = { clientCode: null, docClassification: null };
39
  isFirstSearch: boolean = true;
40
  userPressedBack: boolean;
41
  documentRequestOutput: InvoiceProcessCriteriaInterface;
42

    
43
  constructor(public route: ActivatedRoute, public fb: FormBuilder, public auth: AuthService, public invoice: InvoiceProcessesService, public utils: UtilsService, private searchListState: SearchListStateService) { }
44

    
45
  ngOnInit(): void {
46
    console.log(this.searchListState);
47
    this.route.params.subscribe(params => {
48
      this.parameters.clientCode = params.clientId || null;
49
      this.parameters.docClassification = params.type ? parseInt(params.type) : null;
50
      this.userPressedBack = params.userPressedBack;
51
    });
52
    if(this.parameters.clientCode || this.parameters.docClassification){
53
      this.searchByCriteria();
54
    }
55
    if(this.userPressedBack){
56
      this.searchByCriteria();
57
    }else{
58
      this.searchListState.resetLastPage();
59
    }
60
  }
61

    
62
  public formValue(): InvoiceProcessCriteriaInterface {
63
    this.valueForm = this.searchCriteriaForm.value;
64

    
65
    let formValue: InvoiceProcessCriteriaInterface = {
66
      userId: this.auth.userDetails ? this.auth.userDetails.id.toString() : '',
67
      fromDate: this.valueForm?.fromDate ? new Date(Date.UTC(this.valueForm.fromDate?.getFullYear(), this.valueForm.fromDate?.getMonth(), this.valueForm.fromDate?.getDate())) : null,
68
      toDate: this.valueForm?.toDate ? new Date(Date.UTC(this.valueForm.toDate?.getFullYear(), this.valueForm.toDate?.getMonth(), this.valueForm.toDate?.getDate() + 1)) : null,
69
      docClassification: this.valueForm?.docClassification ? this.valueForm.docClassification : null,
70
      fileCode:this.valueForm?.fileCode ? this.valueForm?.fileCode: null ,
71
      fileType:this.valueForm?.fileType ? this.valueForm?.fileType: null,
72
      processId:this.valueForm?.processId ? this.valueForm?.processId : null ,
73
      processStatus: this.valueForm?.processStatus ?  this.valueForm?.processStatus : null,
74
      ipowerClientName: this.valueForm?.ipowerClientName ? this.valueForm?.ipowerClientName : null ,
75
      ipowerClientCode: this.valueForm?.ipowerClientCode ? this.valueForm?.ipowerClientCode : null  ,
76
      personalData: this.valueForm?.personalData ? this.valueForm?.personalData : null ,
77
      username: this.valueForm?.username ? this.valueForm?.username : null
78
    }
79
    formValue?.toDate?.setMilliseconds(this.valueForm.toDate?.getMilliseconds() -1);
80

    
81
    return formValue;
82
  }
83

    
84
  searchButton(): void {
85
    this.searchListState.resetLastPage();
86
    this.searchListState.clearState();
87
    this.searchByCriteria();
88
  }
89

    
90
  searchByCriteria(): void {
91
    if (this.parameters?.docClassification && this.isFirstSearch) {
92
      this.searchCriteriaForm.get('docClassification').patchValue(this.parameters.docClassification);
93
    }
94
    if (this.parameters?.clientCode && this.isFirstSearch) {
95
      this.searchCriteriaForm.get('ipowerClientCode').patchValue(this.parameters.clientCode);
96
    }
97
    this.isFirstSearch = false;
98
    let verificationRulesSearchFormValue: InvoiceProcessCriteriaInterface = this.formValue();
99
    this.documentRequest = verificationRulesSearchFormValue;
100
  }
101

    
102

    
103
  passOutputDocument(documentRequestOutput) {
104
    this.documentRequestOutput = documentRequestOutput;
105
    this.searchCriteriaForm?.patchValue(this.documentRequestOutput);
106
  }
107

    
108
  clear() {
109
    this.searchCriteriaForm.reset({
110
      userId: this.searchCriteriaForm.get('userId').value
111
    });
112
  }
113

    
114
  canPreviewByUA(): boolean {
115
    return this.auth.userRights.find(rdc => USER_RIGHTS.D02.isGrantedToUser(rdc.rights)) != null;
116
  }
117

    
118
  canPreviewAll(): boolean {
119
    return this.auth.userHasRightForClient(USER_RIGHTS.D01, environment.globalRightsClientID);
120
  }
121
}
(4-4/4)