import { Component, OnInit, Input, OnChanges, ViewChild } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { JobassignmentService } from './jobassignment.service';
import { ToastrService } from 'ngx-toastr';
import { DashboardService } from '../dashboard.service';
import { UserService } from 'src/app/masters/user/user.service';
import { environment } from 'src/environments/environment';
import { NgxSpinnerService } from 'ngx-spinner';
declare var $: any;
import { DatePipe } from '@angular/common';
import { DialogService } from 'ng2-bootstrap-modal';
import { CommondialogComponent } from 'src/app/Shared/commondialog/commondialog.component';
import { CollectionprocessService } from 'src/app/ccstageprocess/collectionprocess/collectionprocess.service';
import { DxDataGridComponent } from 'devextreme-angular';
@Component({
  selector: 'app-jobassignment',
  templateUrl: './jobassignment.component.html',
  styleUrls: ['./jobassignment.component.css']
})

export class JobassignmentComponent implements OnInit, OnChanges, ViewChild {
@ViewChild(DxDataGridComponent, { static: false }) dataGrid: DxDataGridComponent;
  actionRights: any;
  stagelist: any[] = [];
  @Input() _projectdefenitionid: number;
  @Input() _project_subtitle: string;
  @Input() _currentjobno: number;
  @Input() supplementlotids: any = [];
 automailprojectid:number  =environment.automail_projectid;	
  _ddljobSettings: any;
  _ddluserSettings: any;
  joblist: any[];
  userlist: any[];
  AssignedLot: any[] = [];
  ReAssignedLot: any[] = [];
  allotuserjobs: any[] = [];
  AssignedLotvisible: boolean;
  ReAssignedLotvisible: boolean;
  AssignedLotLoading1: boolean;
  AssignedLotLoading: boolean;
  allotjob_output: any[] = [];
  allotuser_output: any[] = [];
  jobtitlemodel: number=0;
  empmodel: number;
  workflowid: number;
  searchuserjob: string;
  searchalljob: string;
  key = 'assignedUser'; //set default
  reverse = false;
  metaall: any[] = [];
  userid: string = localStorage.getItem('userid');
  useralldata: any[];
  showuserlist=false;
  selectstage_name:string;
  joblist_org: any[] = [];
  projectidlst : any[];
  projectduplicatelst : any =[];
  _ddlprojectidSettings : any;
  projectid_output: any;
  originallst : any = [];
  myForm: FormGroup;
  userid_:number;
  selected_assginlot: any=[];
  selected_reassginlot: any=[];
  Projectid_filter : any;
  joblist_bkp: any[];
  job_search_filter: string;
  projectid_search_filter: string='';
  lot_filter_orginial: any =[];
  lot_filter: any=[];
  startdate:any;
  enddate:any;
  loadtype=1;
  vendor_pass: boolean = false;
  fromorder:number;
  toorder:number;
  p_option :string='F';
  mode_p:string=''; 
  p_vendor:string='Vendor';
  reassign = 0;
  constructor(private jobassignmentservice: JobassignmentService,
    private toastr: ToastrService,
    private userservice:UserService,
    private formBuilder: FormBuilder,
    private SpinnerService: NgxSpinnerService,
    private datepipe :DatePipe,
    private collectionprocessservice: CollectionprocessService,
    private dialogService: DialogService
  ) {
    this.myForm = this.formBuilder.group({
      projectid: ['0'],
      // Add more form controls as needed
    })
  }
  descendants: boolean;
  first: boolean;
  read: any;
  isViewQuery: boolean;
  selector: any;
  static: boolean;
  collapse : boolean =false;
  reassign_collapse:boolean =true;
  stageorder: number;
  collapse_assignedlot : boolean =true;
  dateRange:any;

  ngOnChanges(changes: import('@angular/core').SimpleChanges): void {
    this.Clear();
    var today=new Date();
    this.startdate = this.datepipe.transform(today, 'dd-MMM-yyyy');
    this.enddate = this.datepipe.transform(today, 'dd-MMM-yyyy');
    this.loadStageList(this._projectdefenitionid);
    this.loadalluserdata(); //get current user detail
  }

  ngOnInit(): void {
    this.userid_ = Number(this.userid);
    this.searchuserjob = '';
    this.searchalljob = '';
    this.jobtitlemodel = this._currentjobno;
   /*  this._ddljobSettings = {
      singleSelection: false,
      idField: 'jobid',
      textField: 'jobtitle',
      selectAllText: 'Select All'+this.joblist.length,
      allowSearchFilter: true,
      // itemsShowLimit: 7
    }; */

    this._ddluserSettings = {
      singleSelection: true,
      idField: 'userid',
      textField: 'username',
      allowSearchFilter: true
    };

  }
  loadStageList(projectdefid) {
    this.SpinnerService.show();
    this.jobassignmentservice.GetStageList(projectdefid).subscribe(res => {
      let Jresult: any;
      if (res[0] !== undefined) {
        Jresult = JSON.parse(res[0]);
        if (Jresult[0].wfdid !== '') {
          this.stagelist = JSON.parse(res[0]);
          this._project_subtitle = this.stagelist[0].project_subtitle;
          this.stagelist[0].selectstage = 'true';
          this.stageorder = this.stagelist[0].stageorder;
          this.selectstage_name=this.stagelist[0].stagename_alias;
          this.workflowid = this.stagelist[0].wfdid;
          this.get_assign_details(this._projectdefenitionid, this.stagelist[0].wfdid,"onload");

        }
      }
    }, error => { this.toastr.error('Error while getting StageList data'); });
  }
  get_assign_details(prdefid, wfdefid,mode){
    debugger;
    this.AssignedLot = []; 
    this.ReAssignedLot=[];
    this.joblist = [];    
    this.userlist = []; 
    this.lot_filter_orginial = []; 
    this.myForm.controls['projectid'].setValue('0');
    let userid_ : number;
    if(mode == 'onload'){
      userid_ = Number(this.userid);
    }else if(mode == 'user'){
      userid_ = this.empmodel;
    }else if(mode == 'assign'){
      userid_ = this.empmodel == 0 ? Number(this.userid) : this.empmodel;
    }

    this.jobassignmentservice.GetJobAssigment(prdefid, wfdefid, 0, userid_,this.startdate,this.enddate,this.loadtype).subscribe(
      res => {
        debugger;
        this.SpinnerService.hide();
    //job
    if (res.joblst[0] !== undefined && res.joblst[0] !== null) {
    this.joblist = JSON.parse(res.joblst);
    this._ddljobSettings = {
      singleSelection: false,
      idField: 'jobid',
      textField: 'jobtitle',
      selectAllText: 'Select All'+' '+'['+this.joblist.length+']',
      unSelectAllText: 'UnSelect All'+' '+'['+this.joblist.length+']',
      allowSearchFilter: true,
       itemsShowLimit: 7
    };
    this.joblist_org = JSON.parse(res.joblst);
    if(this.selectstage_name=="Bid Entry"){
      this.joblist = this.joblist_org.sort((a, b) => {
        if(a.bid_date != null && b.bid_date != null){
       var date1:any= new Date(a.bid_date);
       var date2:any= new Date(b.bid_date);
                  return date1-date2;
                  }
                });
    } 
    this.joblist_bkp=this.joblist;
    this.allotjob_output = [];
    if(this._currentjobno!=0){
    this.allotjob_output.push((this.joblist.filter(u => u.jobid === this._currentjobno)
      .map(i => ({ jobid: i.jobid, jobno: i.jobno, jobtitle: i.jobtitle })))[0]);
   let jobid_arr=this.joblist.filter(u => u.jobid === this._currentjobno);
     if(jobid_arr.length>0) this.jobtitlemodel = jobid_arr[0].jobid;
  }
    if(this.allotjob_output[0] == undefined){
    this.allotjob_output = [];
   }
    }else{
      this._ddljobSettings = {
        singleSelection: false,
        idField: 'jobid',
        textField: 'jobtitle',
        selectAllText: 'Select All',
        unSelectAllText:'UnSelect All',
        allowSearchFilter: true,
         itemsShowLimit: 7
      };
    }
    //user
    if (res.userlst[0] !== undefined && res.userlst[0] !== null) {
    this.userlist = JSON.parse(res.userlst);
    this.empmodel = Number(this.userid);
    this.allotuser_output=this.userlist.filter(x=>x.userid===this.empmodel);
     if(this.allotuser_output.length>0){
       this.allotuser_output.forEach(element => {
         if(element.department=="Production"){
           this.showuserlist=true;
         }else{
           this.showuserlist=false;
         }
       });
     }else{
       if(this.useralldata[0].department=="Production")this.showuserlist=true;
       this.toastr.error('Stage not mapping. Contact admin.');
     }
    }
    if (this.jobtitlemodel > 0 && this.empmodel > 0) {
      this.loadJobDetails(this.jobtitlemodel);
      this.getuserwiseassignlot("user","withoutproid");
    }
      },
      error => {  this.SpinnerService.hide(); this.toastr.error('Error while getting job assignment data'); }
    );
  }
  stageclick(wid) {
    if(this.loadtype==0){
      var today=new Date();
         this.startdate = this.datepipe.transform(today, 'dd-MMM-yyyy');
         this.enddate = this.datepipe.transform(today, 'dd-MMM-yyyy'); 
    }
    this.loadtype=1;
    this.SpinnerService.show();
    this.projectidlst = [];
    this.myForm.controls['projectid'].setValue('0');
    this.stagelist.forEach(element => {
      if (element.wfdid === wid) {
        element.selectstage = 'true';
        this.selectstage_name=element.stagename_alias;
        this.stageorder = element.stageorder;
      } else {
        element.selectstage = 'false';
      }
    });

    this._currentjobno = 0;
    this.workflowid = wid;
    this.projectid_search_filter = '';
    this.get_assign_details(this._projectdefenitionid,wid,"onload");
    this.allotjob_output = [];
    this.allotuser_output = [];
    this.jobtitlemodel = 0;
    this.empmodel = 0;
    this.AssignedLotvisible = false;
    this.AssignedLotLoading = false;
  }

  calculateDiff(Startdate,Enddate){
    Enddate = new Date(Enddate);
    Startdate = new Date(Startdate);
    return Math.floor((Date.UTC(Enddate.getFullYear(), Enddate.getMonth(), Enddate.getDate()) - Date.UTC(Startdate.getFullYear(), Startdate.getMonth(), Startdate.getDate()) ) /(1000 * 60 * 60 * 24));
  }
  onrepdateValueChange(value: Date): void {
    debugger;
    this.startdate = this.datepipe.transform(value[0], 'dd-MMM-yyyy');
    this.enddate = this.datepipe.transform(value[1], 'dd-MMM-yyyy');
    if(this.startdate !=null && this.startdate !=undefined &&
      this.startdate !='' && this.enddate !=null && this.enddate !=''  && this.enddate !=undefined ){
    var difference=this.calculateDiff(value[0],value[1]);
    if(difference<=7){
               this.SpinnerService.show();
         this.loadtype=1;
         this.projectid_search_filter = '';
         this.get_assign_details(this._projectdefenitionid, this.workflowid,"onload");
       }else{
        this.toastr.error('Kindly select one week jobs');
        this.dateRange =[];
          return;
      }
    }
  } 
  loadall(){
   var today=new Date();
   this.startdate = this.datepipe.transform(today, 'dd-MMM-yyyy');
   this.enddate = this.datepipe.transform(today, 'dd-MMM-yyyy');
    this.SpinnerService.show();
    this.loadtype=0;    
    this.projectid_search_filter = '';
    this.get_assign_details(this._projectdefenitionid, this.workflowid,"onload");
    this.dateRange =[];
  }

  getuserwiseassignlot(loadmode,type){
    debugger;
  this.SpinnerService.show();
  if(this.loadtype==0){
    var today=new Date();
       this.startdate = this.datepipe.transform(today, 'dd-MMM-yyyy');
       this.enddate = this.datepipe.transform(today, 'dd-MMM-yyyy'); 
  }
  let userid_ : number;
    if(loadmode == 'onload'){
      userid_ = Number(this.userid);
    }else if(loadmode == 'user'){
      userid_ = this.empmodel;
    }else if(loadmode == 'assign'){
      userid_ = this.empmodel == 0 ? Number(this.userid) : this.empmodel;
    }else if(loadmode == 'reassign') { // monicaa
      this.reassign = 1; 
      userid_ = this.empmodel == 0 ? Number(this.userid) : this.empmodel;
    }
    if(type=="withoutproid"){
      //this.jobtitlemodel=0;
      this.projectid_search_filter = '';
    }else{
      let temp = "";
      if (
        this.projectid_search_filter != null &&
        this.projectid_search_filter != undefined &&
        this.projectid_search_filter != ""
      ) {
        if (this.projectid_search_filter.includes(",")) {
          let value = this.projectid_search_filter.split(",");
          value.forEach((element) => {
            if (temp == "") {
              temp = "%" + element + "%";
            } else {
              temp = temp + "," + "%" + element + "%";
            }
          });
        } else {
          temp = "%" + this.projectid_search_filter + "%";
        }
      }
    }
  let input = [];
  input.push({
    p_projectdefinitionid:this._projectdefenitionid, 
    p_wfdid:this.workflowid,
    p_userid:userid_,
    p_jobid:this.jobtitlemodel,
    p_startdate:this.startdate,
    p_enddate:this.enddate,
    mode:type,
    p_projectid:this.projectid_search_filter,
    p_type:this.loadtype
    //isAssigned: this.reassign //monicaa
  });
  this.jobassignmentservice.getuserwiseassignlot(input[0]).subscribe(res=> {
      if (res.body !== undefined && res.body !== null) {
        this.SpinnerService.hide();
        let arr=res.body;
        arr.forEach(i=>{
          var val=JSON.parse(i);
          debugger;
          if(val.assigned_user == 0 && val.assignedUser==null){
           var check_already_exist= this.AssignedLot.filter(x => x.lotid == val.lotid);
            if(check_already_exist.length==0)this.AssignedLot.push(val);
          }else{
            var check_already_exist= this.ReAssignedLot.filter(x => x.lotid == val.lotid);
           if(check_already_exist.length==0)this.ReAssignedLot.push(val);
          }         
          });
             this.AssignedLotLoading = true;
             this.AssignedLotvisible = true;
}
  }, err => {  this.SpinnerService.hide();this.toastr.error(err); });
  }
  projectid_filter(mode){
  if(this.projectid_search_filter == "" && mode == 'ontype'){
      this.AssignedLot = [];this.ReAssignedLot =[];
    }else if((this.projectid_search_filter != '' && this.projectid_search_filter
     != undefined && this.projectid_search_filter != null) || 
     this.AssignedLot.length == 0 && mode =='ontype'){
      if(this.allotjob_output.length != 0){
        this.allotjob_output = [];
      }
      this.jobtitlemodel = 0;
      this.AssignedLot=[];
      this.ReAssignedLot=[];
      this.getuserwiseassignlot("onload","withproid")
        this.AssignedLotLoading = true;
        this.AssignedLotvisible = true;
    }
    if(mode == 'assign'){
      this.AssignedLot=[];
      this.ReAssignedLot=[];
      this.getuserwiseassignlot(mode,"withproid")
        this.AssignedLotLoading = true;
        this.AssignedLotvisible = true;
    }
  } 
  onJobSelect(item: any) {
    if(this.projectid_search_filter != '')
    {
      this.projectid_search_filter = '';
      this.AssignedLot= [];
      this.ReAssignedLot=[];
    }
    this.myForm.controls['projectid'].setValue('0');
    this.AssignedLotLoading = false;
    this.jobtitlemodel = item.jobid;
  	this.loadJobDetails(item.jobid);
    this.empmodel = Number(this.userid);
    if (this.jobtitlemodel > 0 && this.empmodel > 0) {
      //this.viewlot();
      this.getuserwiseassignlot("user","withoutproid");
    }
  }
  onJobDeSelect(item: any) {
     if(this.allotjob_output.length === 0){
      this.AssignedLotvisible = false;
      this.AssignedLotLoading = false;
    }
    this.jobtitlemodel = 0;
    this.AssignedLot=this.AssignedLot.filter(x => x.jobid != item.jobid)
    this.joblist=this.joblist_bkp;
  }
  reset(){
    this.joblist=this.joblist_bkp; 
  }
  onSelectAll(item: any){
    
    if(this.projectid_search_filter != '')
    {this.projectid_search_filter = '';
    this.AssignedLot= [];
    this.ReAssignedLot=[];
    }
    this.AssignedLotLoading = false;
    this.AssignedLot = [];
    this.ReAssignedLot=[];
    item.forEach(element => {
      if(this.job_search_filter != "" && this.job_search_filter != undefined && this.job_search_filter != null)
      {
        var jobname=element.jobtitle
        if(jobname.includes(this.job_search_filter.toUpperCase())){
        this.jobtitlemodel = element.jobid;
        this.empmodel = Number(this.userid);
        this.allotuser_output=this.userlist.filter(x=>x.userid===this.empmodel);
        if (this.jobtitlemodel > 0 && this.empmodel > 0) {
          //this.AssignedLot = [];
          this.myForm.controls['projectid'].setValue('0');
          //this.viewlot();
          this.getuserwiseassignlot("user","withoutproid");
        }
      }
      }else{
        this.jobtitlemodel =element.jobid;
        this.empmodel = Number(this.userid);
        this.allotuser_output=this.userlist.filter(x=>x.userid===this.empmodel);
        this.AssignedLot = [];
        this.ReAssignedLot=[];
        this.getuserwiseassignlot("user","withoutproid");
       /* if (this.jobtitlemodel > 0 && this.empmodel > 0) {
          this.AssignedLot = [];
          this.myForm.controls['projectid'].setValue('0');
          this.viewlot();
        }*/
      }
    });
  }
  onFilterChange(item: any) {
    this.joblist=this.joblist_bkp;
    this.job_search_filter=item;
    if(item !="" && item != null && item != undefined){
      this.joblist=this.joblist_bkp.filter(x=>x.jobtitle.includes(item.toUpperCase()));
    }
    if(this.joblist.length==0)this.joblist=this.joblist_bkp;
  }
  onDeSelectAll(item: any){
    this.AssignedLotLoading = true;
    this.AssignedLotvisible =false;
    this.jobtitlemodel = 0;
    this.AssignedLot = [];
    this.ReAssignedLot=[];
    this.joblist=this.joblist_bkp;
    var grid = $('#gridContainer').dxDataGrid('instance');  
grid.option('dataSource', []);  
  }
  onUserSelect(item: any) {
    debugger;
    this.AssignedLotLoading = false;
    this.empmodel = item.userid;
    if (this.jobtitlemodel > 0 && this.empmodel > 0) {
      if(this.projectid_search_filter == '' || this.projectid_search_filter == undefined || this.projectid_search_filter == null){
        this.AssignedLot = [];
        this.ReAssignedLot=[];
          this.allotjob_output.forEach(element => {
            this.jobtitlemodel = element.jobid;
            //this.viewlot();
            this.getuserwiseassignlot("user","withoutproid");
          });
        }
    }else{
      if(this.projectid_search_filter != '' && this.projectid_search_filter != undefined && this.projectid_search_filter != null){
        //this.viewlot_filterlst('user');
        this.AssignedLot = [];
        this.ReAssignedLot=[];
        this.getuserwiseassignlot("user","withproid")
        
      }
      
    }
   
  }
  onUserDeSelect(item: any) {
    // console.log(item);
    this.AssignedLotLoading = true;
    this.empmodel = 0;
    this.AssignedLot = [];
    this.ReAssignedLot=[];
  }

  loadJobDetails(jobid) {
    debugger;
    var inputData = [];
     inputData.push({
       jobid: jobid,
       projectdefinitionid : localStorage.getItem('prdefid')
     });
    this.collectionprocessservice.getJobDetails(inputData[0]).subscribe(res => {
      if (res.body[1] !== undefined && res.body[1] !== null && JSON.parse(res.body[1]).length > 0) {
        debugger;
        var stagelist=JSON.parse(res.body[1]);
        this.fromorder=this.stageorder;
        this.toorder=stagelist[stagelist.length-1].stageorder;

        console.log('from order and to order',this.fromorder ,'/',this.toorder);
      }
    }, err => { this.toastr.error('Loading Lot detail failed.'); });

  }
  vendor_user_check(jobworkflowid, lotid, userid, assigned_user,sflag, sType, ta,mode,transactionid,assigntype) {
    debugger;
    if(this.allotuser_output[0].userid != userid){
      userid = this.allotuser_output[0].userid 
    }else{
      userid =this.empmodel;
    }
      //if (this.stageorder == 2) {
        if (this.selectstage_name == 'Bid Entry') {
        let vendorid = this.userlist.filter((x) => x.userid == userid);
        if (vendorid[0].department.toString().toLowerCase() == "vendor") {
          this.mode_p = 'Assigned to vendor('+vendorid[0].username.toString().replace(/\s+/g, '')+')';
          console.log('vendor',this.mode_p);
          this.dialogService
            .addDialog(CommondialogComponent, {
              title: "Please Confirm",
              message: "Do you want to assign the lot (s) to vendor? Vendor assigned lots will skip further stages in LAPS.",
              hclass: "modelsuccess",
              oktext: "Yes",
              canceltext: "No",
              okshow: true,
              cancelshow: true,
            })
            .subscribe((isConfirmed) => {
              if (isConfirmed) {
                debugger;
                this.vendor_pass = true;
                if(mode=='S'){
                  this.lotAssign(jobworkflowid, lotid, userid,assigned_user, sflag, sType, ta,transactionid,assigntype);
                }else if(mode=='M'){
                  this.multiple_assignlot(assigntype);
                }
              }
            });
        } else {
          if(mode=='S'){
            this.lotAssign(jobworkflowid, lotid, userid, assigned_user,sflag, sType, ta,transactionid,assigntype);
          }else if(mode=='M'){
            this.multiple_assignlot(assigntype);
          }
        }
      }else{
        if(mode=='S'){
          this.lotAssign(jobworkflowid, lotid, userid,assigned_user, sflag, sType, ta,transactionid,assigntype);
        }else if(mode=='M'){
          this.multiple_assignlot(assigntype);
        }
      }
  }
  async lotAssign(jobworkflowid, lotid, select_userid, assigned_user, sflag, sType, ta,transactionid,assigntype) {
    let filestatus_: any;
    let sTempuser: any;
    if(assigntype=='reassign'){
      filestatus_ = this.ReAssignedLot.filter((b) => b.lotid === lotid)[0];
    }else{
      filestatus_ = this.AssignedLot.filter((b) => b.lotid === lotid)[0];
    }
  
    if (filestatus_) {
      sTempuser = filestatus_.assigned_user;
      filestatus_.assigned_user = -1;
    }
    let input =[];
    if(this.vendor_pass == true){
      input.push({
        assigned_user:assigned_user,
        jobworkflowid:jobworkflowid,
        lotid:lotid,
        selectUser:select_userid,
        sType:sType,
        sflag:sflag,
        fromorder:this.fromorder,
        toorder:this.toorder,
        p_option:this.p_option,
        mode_p:this.mode_p,
        p_vendor:this.p_vendor,
        tranid:transactionid
      });
    }else{
      input.push({
        assigned_user:assigned_user,
        jobworkflowid:jobworkflowid,
        lotid:lotid,
        selectUser:select_userid,
        sType:sType,
        sflag:sflag
      });
    }
    
    let fileData = new FormData();
    fileData.append("model", JSON.stringify(input));
    // return;
    this.SpinnerService.show();
    this.jobassignmentservice
      // .SetLotAssignDetails(jobworkflowid, lotid, userid, sflag,this.fromorder,this.toorder,this.p_option,this.mode_p,sType)
      .SetLotAssignDetails_multiple(fileData)
      .subscribe(
        (res) => {
          debugger;
          this.vendor_pass=false;
          //filestatus_.assigned_user = sTempuser;
          let AssignedLot_temp: any;
          let filestatus: any;
          if(assigntype=='reassign'){
          AssignedLot_temp = this.ReAssignedLot.filter(
            (b) => (b.jobworkflowid = jobworkflowid)
          );
          }else{
            AssignedLot_temp = this.AssignedLot.filter(
              (b) => (b.jobworkflowid = jobworkflowid)
            );
          }
          filestatus = AssignedLot_temp.filter((b) => (b.lotid = lotid))[0];
         // filestatus.assigned_user = res[0];
          if (
            this._projectdefenitionid == this.automailprojectid &&
            ta.stageorder == 1
          ) {
           
            let field = [
              {
                selectUser: select_userid,
                assignedUser: ta.assignedUser,
                lotid: lotid,
                uniquemailid: ta.uniquemailid,
                sflag: sflag,
                stageorder: ta.stageorder,
                lotstatus: ta.lotstatus,
                parentmailid: ta.parentmailid,
              },
            ];
            let fileData = new FormData();
            fileData.append("model", JSON.stringify(field));

            this.jobassignmentservice
              .movemailtoassignuserfold(fileData)
              .subscribe(
                (res1) => {
                  debugger;
                  this.SpinnerService.hide();
                  if (res1.body !== undefined && res1.body !== null) {
                    if (res1.body[0] == "done") {
                      if (sflag === "1") {
                        this.toastr.success(
                          "Successfully Assigned.Mail moved to user folder"
                        );
                      } else if (sflag === "3") {
                        this.toastr.success(
                          "Successfully UnAssigned.Mail revert to folder"
                        );
                      }
                      if (
                        this.jobtitlemodel > 0 &&
                        this.empmodel > 0 &&
                        (this.projectid_search_filter == "" ||
                          this.projectid_search_filter == undefined ||
                          this.projectid_search_filter == null)
                      ) {
                        this.AssignedLot = [];this.ReAssignedLot=[];
                        this.allotjob_output.forEach((element) => {
                          this.jobtitlemodel = element.jobid;
                          // this.viewlot();
                          this.getuserwiseassignlot("assign", "withoutproid");
                        });
                      } else {
                        this.AssignedLot = [];this.ReAssignedLot=[];
                        //this.viewlot_filterlst('assigned')
                        this.getuserwiseassignlot("assign", "withproid");
                      }
					 
                    } else {
                      this.toastr.error(res1.body[0]);
									  
                    }
							   
								  
                  }
                },
                (error) => {
                  this.SpinnerService.hide();
                  this.toastr.error("Error in moving mail details");
                }
              );
          } else {
            this.SpinnerService.hide();
            if (
              this.jobtitlemodel > 0 &&
              this.empmodel > 0 &&
              (this.projectid_search_filter == "" ||
                this.projectid_search_filter == undefined ||
                this.projectid_search_filter == null)
            ) {
              this.AssignedLot = [];this.ReAssignedLot=[];
              this.allotjob_output.forEach((element) => {
                this.jobtitlemodel = element.jobid;
                //this.viewlot();
                this.getuserwiseassignlot("assign", "withoutproid");
              });
            } else {
              this.AssignedLot = [];this.ReAssignedLot=[];
              //this.viewlot_filterlst('assign');
              this.getuserwiseassignlot("assign", "withproid");
            }
            if (sflag === "1") {
              this.toastr.success("Successfully Assigned..");
            } else if (sflag === "3") {
              this.toastr.success("Successfully UnAssigned..");
            }
          }
        },
        (error) => {
          filestatus_.assigned_user = sTempuser;
          this.SpinnerService.hide();
          this.toastr.error("Error while assign lot");
        }
      );
  }
  multiple_assignlot(assigntype) {
    if(assigntype=='reassign'){
      if (this.selected_reassginlot.length === 0) {
        this.toastr.error("Please select anyone of the lot to be re-assign.");
        return;
      }
    }else{
      if (this.selected_assginlot.length === 0) {
        this.toastr.error("Please select anyone of the lot to be assign.");
        return;
      }
    }
    
    let filestatus_: any;
    let sTempuser: any;
    let input = [
      {
        jobid: 1,
      },
    ];
    let fileData = new FormData();

    if(this.vendor_pass == true){
      if(assigntype=='reassign'){
      let temp = [];
      temp = this.selected_reassginlot;
      this.selected_reassginlot = [];
      temp.forEach(element => {
        this.selected_reassginlot.push({
          assigned_user:element.assigned_user,
          jobworkflowid:element.jobworkflowid,
          lotid:element.lotid,
          selectUser:element.selectUser,
          sType:element.sType,
          fromorder:this.fromorder,
          toorder:this.toorder,
          p_option:this.p_option,
          mode_p:this.mode_p,
          p_vendor:this.p_vendor,
          tranid:element.transactionid
        })
      });
    }else{
      let temp = [];
      temp = this.selected_assginlot;
      this.selected_assginlot = [];
      temp.forEach(element => {
        this.selected_assginlot.push({
          assigned_user:element.assigned_user,
          jobworkflowid:element.jobworkflowid,
          lotid:element.lotid,
          selectUser:element.selectUser,
          sType:element.sType,
          fromorder:this.fromorder,
          toorder:this.toorder,
          p_option:this.p_option,
          mode_p:this.mode_p,
          p_vendor:this.p_vendor,
          tranid:element.transactionid
        })
      });
    }
    }
    if(assigntype=='reassign'){
      fileData.append("model", JSON.stringify(this.selected_reassginlot));
    }else{
      fileData.append("model", JSON.stringify(this.selected_assginlot));
    }
   
    this.SpinnerService.show();
    this.jobassignmentservice.SetLotAssignDetails_multiple(fileData).subscribe(
      (res) => {
        this.vendor_pass = false;
        let AssignedLot_temp: any;
        let filestatus: any;
        if (
          this._projectdefenitionid == this.automailprojectid &&
          this.stageorder == 1
        ) {
          let field = [];
          let fileData = new FormData();
          if(assigntype=='reassign'){
            fileData.append("model", JSON.stringify(this.selected_reassginlot));
          }else{
            fileData.append("model", JSON.stringify(this.selected_assginlot));
          }
          this.jobassignmentservice
            .movemailtoassignuserfold(fileData)
            .subscribe(
              (res1) => {
                debugger;
                this.SpinnerService.hide();
                if (res1.body !== undefined && res1.body !== null) {
                  if (res1.body[0] == "done") {
                    if (
                      (this.jobtitlemodel > 0 &&
                        this.empmodel > 0 &&
                        this.projectid_search_filter == "") ||
                      this.projectid_search_filter == undefined ||
                      this.projectid_search_filter == null
                    ) {
                      this.AssignedLot = [];this.ReAssignedLot=[];
                      this.allotjob_output.forEach((element) => {
                        this.jobtitlemodel = element.jobid;
                        this.toastr.success(
                          "Successfully Assigned / UnAssigned . Mail moved to user folder"
                        );
                        //this.viewlot();
                        this.getuserwiseassignlot("assign", "withoutproid");
                      });
                    } else {
                      this.AssignedLot = [];this.ReAssignedLot=[];
                      this.toastr.success(
                        "Successfully Assigned / UnAssigned . Mail moved to user folder"
                      );
                      //this.viewlot_filterlst('assign');
                      this.getuserwiseassignlot("assign", "withproid");												  
																				  
                    }
                  } else {
                    this.toastr.error(res1.body[0]);
                  }
                }
              },
              (error) => {
                this.SpinnerService.hide();
                this.toastr.error("Error in moving mail details");
              }
            );
        } else {
          this.SpinnerService.hide();
          //  this.loadUsersJobs();
          if (
            (this.jobtitlemodel > 0 &&
              this.empmodel > 0 &&
              this.projectid_search_filter == "") ||
            this.projectid_search_filter == undefined ||
            this.projectid_search_filter == null
          ) {
            this.AssignedLot = [];this.ReAssignedLot=[];
            this.allotjob_output.forEach((element) => {
              this.jobtitlemodel = element.jobid;
              //this.viewlot();
              this.getuserwiseassignlot("assign", "withoutproid");
            });
            this.toastr.success("Successfully Assigned / Unassigned..");
          } else {
            this.AssignedLot = [];this.ReAssignedLot=[];
            //this.viewlot_filterlst('assign');
            this.getuserwiseassignlot("assign", "withproid");
            this.toastr.success("Successfully Assigned / Unassigned..");
          }
        }
      },
      (error) => {
        // filestatus_.assigned_user = sTempuser;
        this.SpinnerService.hide();
        this.toastr.error("Error while assign lot");
      }
    );
  
  }
/*   lotAssign(jobworkflowid, lotid, userid, sflag, sType,ta) {
    let filestatus_: any;
    let sTempuser: any;
    filestatus_ = this.AssignedLot.filter(b => b.lotid === lotid)[0];
    if (filestatus_) {
      sTempuser = filestatus_.assigned_user;
      filestatus_.assigned_user = -1;
    }
    // return;
    this.SpinnerService.show();
    this.jobassignmentservice.SetLotAssignDetails(jobworkflowid, lotid, userid, sflag, sType).subscribe(
      res => {
        debugger;
        filestatus_.assigned_user = sTempuser;
        let AssignedLot_temp: any;
        let filestatus: any;
        AssignedLot_temp = this.AssignedLot.filter(b => b.jobworkflowid = jobworkflowid);
        filestatus = AssignedLot_temp.filter(b => b.lotid = lotid)[0];
        filestatus.assigned_user = res[0];
             if(this._projectdefenitionid == this.automailprojectid && ta.stageorder == 1 ){
              let field =[{selectUser:userid, assignedUser:ta.assignedUser, lotid:lotid,uniquemailid:ta.uniquemailid
                ,sflag:sflag,stageorder:ta.stageorder,lotstatus:ta.lotstatus,parentmailid:ta.parentmailid}];
              let fileData = new FormData();
          fileData.append('model', JSON.stringify(field));

                  this.jobassignmentservice.movemailtoassignuserfold(fileData).subscribe(res1 => {
                    debugger;
                    this.SpinnerService.hide();
                    if (res1.body !== undefined && res1.body !== null) {          
                     if(res1.body[0]=="done"){
                      if (sflag === '1') {
                        this.toastr.success('Successfully Assigned.Mail moved to user folder');
                      } else if (sflag === '3') {
                        this.toastr.success('Successfully UnAssigned.Mail revert to folder');
                           }
                      if (this.jobtitlemodel > 0 && this.empmodel > 0 &&
                         (this.projectid_search_filter == '' || this.projectid_search_filter == undefined
                         || this.projectid_search_filter == null)) {
                        this.AssignedLot=[];
                          this.allotjob_output.forEach(element => {
                            this.jobtitlemodel = element.jobid;
                           // this.viewlot();
                           this.getuserwiseassignlot("assign","withoutproid")
                          });
                      }else{
                        this.AssignedLot=[];
                        //this.viewlot_filterlst('assigned')
                        this.getuserwiseassignlot("assign","withproid")
                      }
                    }
                     else{
                      this.toastr.error(res1.body[0]); 
                     }                
                    }
                  }, error => {
                    this.SpinnerService.hide();
                    this.toastr.error('Error in moving mail details'); });        
                  }else{
                  this.SpinnerService.hide();
                  if (this.jobtitlemodel > 0 && this.empmodel > 0 &&
                    (this.projectid_search_filter == '' || this.projectid_search_filter == undefined
                    || this.projectid_search_filter == null)) {
                    this.AssignedLot=[];
                      this.allotjob_output.forEach(element => {
                        this.jobtitlemodel = element.jobid;
                        //this.viewlot();
                        this.getuserwiseassignlot("assign","withoutproid")
                      });
                  }else{
                    this.AssignedLot=[];
                    //this.viewlot_filterlst('assign');
                    this.getuserwiseassignlot("assign","withproid")
                  }
                    if (sflag === '1') {
                      this.toastr.success('Successfully Assigned..');
                    } else if (sflag === '3') {
                      this.toastr.success('Successfully UnAssigned..');
                         }
                  }
      },
      error => {
        filestatus_.assigned_user = sTempuser;
        this.SpinnerService.hide();
        this.toastr.error('Error while assign lot');
      }
    );
  }
  multiple_assignlot(){
    if(this.selected_assginlot.length === 0){
      this.toastr.error('Please select anyone of the lot to be assign.');
      return;
    }
    let filestatus_: any;
    let sTempuser: any;
 let input = [{
  jobid : 1
 }]
 let fileData = new FormData();
          fileData.append('model', JSON.stringify(this.selected_assginlot));
          this.SpinnerService.show();
    this.jobassignmentservice.SetLotAssignDetails_multiple(fileData).subscribe(
      res => {
        let AssignedLot_temp: any;
        let filestatus: any;
             if(this._projectdefenitionid == this.automailprojectid && this.stageorder == 1 ){
              let field = [];            
              let fileData = new FormData();
          fileData.append('model', JSON.stringify(this.selected_assginlot));
                  this.jobassignmentservice.movemailtoassignuserfold(fileData).subscribe(res1 => {
                    debugger;
                    this.SpinnerService.hide();
                    if (res1.body !== undefined && res1.body !== null) {          
                     if(res1.body[0]=="done"){
                     if (this.jobtitlemodel > 0 && this.empmodel > 0 && this.projectid_search_filter == '' || this.projectid_search_filter == undefined || this.projectid_search_filter== null) {
                      this.AssignedLot=[];
                        this.allotjob_output.forEach(element => {
                          this.jobtitlemodel = element.jobid;
                          this.toastr.success('Successfully Assigned / UnAssigned . Mail moved to user folder');
                          //this.viewlot();
                          this.getuserwiseassignlot("assign","withoutproid")
                        });
                    }else{
                      this.AssignedLot=[];
                      this.toastr.success('Successfully Assigned / UnAssigned . Mail moved to user folder');
                      //this.viewlot_filterlst('assign');
                      this.getuserwiseassignlot("assign","withproid")
                    }
                    }
                     else{
                      this.toastr.error(res1.body[0]); 
                     }                
                    }
                  }, error => {
                    this.SpinnerService.hide();
                    this.toastr.error('Error in moving mail details'); });        
                  }else{
                    this.SpinnerService.hide();
                  //  this.loadUsersJobs();
                    if (this.jobtitlemodel > 0 && this.empmodel > 0 && this.projectid_search_filter == '' || this.projectid_search_filter == undefined || this.projectid_search_filter == null) {
                      this.AssignedLot=[];
                        this.allotjob_output.forEach(element => {
                          this.jobtitlemodel = element.jobid;
                          //this.viewlot();
                          this.getuserwiseassignlot("assign","withoutproid")
                        });
                      this.toastr.success('Successfully Assigned / Unassigned..');
                    }else{
                      this.AssignedLot=[];
                       //this.viewlot_filterlst('assign');
                       this.getuserwiseassignlot("assign","withproid")
                      this.toastr.success('Successfully Assigned / Unassigned..');
                    }
                  }
      },
      error => {
        // filestatus_.assigned_user = sTempuser;
        this.SpinnerService.hide();
        this.toastr.error('Error while assign lot');
      }
    );
  
  } */ 
  loadUsersJobs() {
    debugger;
    // load current user already assigned lot
    this.jobassignmentservice.GetUserJobs(this._projectdefenitionid,Number(this.userid)).subscribe(
      res => {
        this.AssignedLotLoading1 = true;
        if (res !== undefined) {
          this.allotuserjobs = [];
          let arrs=JSON.parse(res[0])
          arrs.forEach(i=>{
              this.allotuserjobs.push(i);
            });
        }
      },
      error => { this.toastr.error('Error while getting UserJobs data'); }
    );
  }
  sort(key){ 
    this.key = key;
    this.reverse = !this.reverse;
  }
  Clear() {
    this.stagelist = [];
    this.joblist = [];
    this.userlist = [];
    this.AssignedLot = [];
    this.ReAssignedLot = [];
    this.allotuserjobs = [];
    this.allotjob_output = [];
    this.allotuser_output = [];
    this.workflowid = 0;
    this.jobtitlemodel = 0;
    this.empmodel = 0;
    this.AssignedLotvisible = false;
    this.AssignedLotLoading1 = false;
    this.AssignedLotLoading = false;
    this.joblist_bkp=[];
    this.joblist_org=[];
  }
  loadalluserdata(){
    this.userservice.GetActive().subscribe(res=> {
   let result= JSON.parse(res[0]);
      this.useralldata= result.filter(r=>r.userid == this.userid);
    });
  }
  toggle_assginedlotuser(mode){
    debugger;
    if(mode == 1){
      //AVAILABLE FOR ASSIGNMENT 
      this.collapse =!this.collapse;
      this.loadUsersJobs();
      $("#assginedlotuser").collapse('toggle');
    }else if(mode == 3){
      //AVAILABLE FOR RE-ASSIGNMENT
      this.reassign_collapse =!this.reassign_collapse;
      if (this.jobtitlemodel > 0 && this.empmodel > 0) {
        //this.viewlot();
        this.getuserwiseassignlot("reassign","withoutproid");
      }
      $("#reassignedlot").collapse('toggle');
    }
  }
  selectionChangedHandler(){
    console.log('selected assigend lot',this.selected_assginlot);
  }
   /*async  loadUserAssignedJob(prdefid, wfdefid) {
    this.myForm.controls['projectid'].setValue('0');
    await this.jobassignmentservice.GetUserAssignedJob(prdefid, wfdefid).subscribe(
      async res => {
        this.loadUserAssignedUser(this._projectdefenitionid, this.stagelist[0].wfdid);
        if (res !== undefined) {
          this.joblist = [];
          this.joblist = JSON.parse(res[0]);
          this.joblist_org= JSON.parse(res[0]);
           if(this.selectstage_name==2){
            this.joblist = this.joblist_org.sort((a, b) => {
              if(a.bid_date != null && b.bid_date != null){
             var date1:any= new Date(a.bid_date);
             var date2:any= new Date(b.bid_date);
                        return date1-date2;
                        }
                      });
          } 
          this.joblist_bkp=this.joblist;
          this.allotjob_output = [];
          this.allotjob_output.push((this.joblist.filter(u => u.jobid === this._currentjobno)
            .map(i => ({ jobid: i.jobid, jobno: i.jobno, jobtitle: i.jobtitle })))[0]);
        }
        // await this.Getallassignedjob();
      }, error => { this.toastr.error('Error while getting UserAssignedJob data'); }
    );
  }*/

  /*loadUserAssignedUser(prdefid, wfdefid) {
    this.jobassignmentservice.GetUserAssignedUser(prdefid, wfdefid).subscribe(
      res => {
        this.SpinnerService.hide();
        if (res !== undefined) {
          this.userlist = [];
          this.userlist = JSON.parse(res[0]);
        }

      }, error => {  this.SpinnerService.hide();
        this.toastr.error('Error while getting userAssignedUser data'); }
    );
  }*/
 /*  // async Getallassignedjob(){
  //   debugger;
  //   console.log("Getallassignedjob")
  //   const temp_lst : any= [];
  //   let originallst_assignedjob :any=[];
  //   this.AssignedLot=[];
  //   this.originallst = [];
  //    this.projectidlst =[];
  //    if(this.joblist.length != 0){
  //   this.projectduplicatelst=[];
  //     await this.joblist.forEach(  async element => {
  //       this.jobtitlemodel = element.jobid;
  //       this.empmodel = Number(this.userid);
  //       if (this.jobtitlemodel > 0 && this.empmodel > 0) {
  //           await this.jobassignmentservice.GetUserAssignedLot(this._projectdefenitionid, this.workflowid, this.jobtitlemodel, this.empmodel).subscribe(
  //           res => {
  //             //this.AssignedLotLoading = true;
  //             //this.AssignedLotvisible = true;
  //             if (res !== undefined) {
  //               let arr=JSON.parse(res[0])
  //               if(arr != null){
  //               arr.forEach(i=>{
  //                 var mdata= i.lotmastermetafields;
  //                 if(mdata != null){
  //                   mdata.forEach(j => {
  //                     if(j.FieldName=="Company Name")i.CompanyName=j.FieldValue;
  //                     if(j.FieldName=="Type")i.Type=j.FieldValue;
  //                     if(j.FieldName=="Frequency")i.Frequency=j.FieldValue;
  //                     if(j.FieldName=="Ranking")i.Ranking=j.FieldValue;
  //                     if(j.FieldName=="City")i.City=j.FieldValue;
  //                     if(j.FieldName=="State")i.State=j.FieldValue;
  //                     if(j.FieldName=="Project ID")i.ProjectID=j.FieldValue;
  //                     if(j.FieldName=="URL")i.URL=j.FieldValue;
  //                     if(j.FieldName=="Follow Up Date")i.FollowUpDate=j.FieldValue;
  //                   });
  //                   }
  //                   this.originallst.push(i);
  //                     if(i.ProjectID != null && i.ProjectID != "" && i.ProjectID != undefined){
  //                       if(this.projectduplicatelst.length !=0){
  //                         let index = this.projectduplicatelst.findIndex(x=>x.projectid == i.ProjectID);
  //                         if(index === -1){
  //                           let item ={
  //                             lotid : i.lotid,
  //                             projectid : i.ProjectID,
  //                             lottitle: i.lottitle
  //                           }
  //                            this.projectduplicatelst.push(item);
  //                         } 
  //                     }else{
  //                       let item ={
  //                         lotid : i.lotid,
  //                         projectid : i.ProjectID,
  //                         lottitle: i.lottitle
  //                       }
  //                        this.projectduplicatelst.push(item);
  //                     }
  //                   }
  //                 });
  //               }
  //                       }
  //           },
  //           error => { this.toastr.error('Error while getting Viewlot data'); }
  //         );
  //       }

  //   });            
  //                 this.projectidlst=this.projectduplicatelst;
  // }
  // } */
/* projectidonItemSelect(item){
    if(item != "0" && item!=0){
      this.empmodel = Number(this.userid);
      this.AssignedLotvisible = true;
      this.AssignedLotLoading = true;
      this.allotjob_output = [];
      this.allotuser_output=this.userlist.filter(x=>x.userid === this.empmodel);
      this.AssignedLot = this.originallst.filter(x=> x.ProjectID === item);
      this.jobtitlemodel = this.AssignedLot[0].jobid;
    }else{
      this.AssignedLotvisible = false;
      this.AssignedLotLoading = false;
      this.allotuser_output=[];
      this.AssignedLot = [];
      this.jobtitlemodel = 0;
    }
  }*/
 /* viewlot() {
    this.SpinnerService.show();
    if(this.loadtype==0){
      var today=new Date();
         this.startdate = this.datepipe.transform(today, 'dd-MMM-yyyy');
         this.enddate = this.datepipe.transform(today, 'dd-MMM-yyyy'); 
    }
    this.jobassignmentservice.GetUserAssignedLot(this._projectdefenitionid, this.workflowid, this.jobtitlemodel, this.empmodel,this.startdate,this.enddate,this.loadtype).subscribe(
      res => {
        this.SpinnerService.hide();
        this.AssignedLotLoading = true;
        this.AssignedLotvisible = true;
        if (res !== undefined) {
         // this.AssignedLot = []; 
          let arr=JSON.parse(res[0])
          arr.forEach(i=>{
            var mdata= i.lotmastermetafields;
            if(mdata != null){
              mdata.forEach(j => {
                if(j.FieldName=="Company Name")i.CompanyName=j.FieldValue;
                //if(j.FieldName=="Type")i.Type=j.FieldValue;
                //if(j.FieldName=="Frequency")i.Frequency=j.FieldValue;
                //if(j.FieldName=="Ranking")i.Ranking=j.FieldValue;
                if(j.FieldName=="City")i.City=j.FieldValue;
                if(j.FieldName=="State")i.State=j.FieldValue;
                if(j.FieldName=="Project ID")i.ProjectID=j.FieldValue;
                //if(j.FieldName=="URL")i.URL=j.FieldValue;
                //if(j.FieldName=="Follow Up Date")i.FollowUpDate=j.FieldValue;
                if(j.FieldName=="Bid Date")i.BidDate=this.datepipe.transform(j.FieldValue, 'dd-MMM-yyyy');
              });
              }
              this.AssignedLot.push(i);
            });
            console.log('assigning lot',this.AssignedLot);
            if(this.projectid_search_filter != '' && this.projectid_search_filter != undefined && this.projectid_search_filter != null ){
              this.viewlot_filterlst('assign');
            }
                  }
      },
      error => { this.toastr.error('Error while getting Viewlot data'); }
    );
  } */
  
/* viewlot_filterlst(mode){
  if(this.loadtype==0){
    var today=new Date();
       this.startdate = this.datepipe.transform(today, 'dd-MMM-yyyy');
       this.enddate = this.datepipe.transform(today, 'dd-MMM-yyyy'); 
  }
  let userid_ : number;
  if(mode == 'onload'){
    userid_ = Number(this.userid);
  }else if(mode == 'user'){
    userid_ = this.empmodel;
  }else if(mode == 'assign'){
    userid_ = this.empmodel == 0 ? Number(this.userid) : this.empmodel;
  }
  this.jobassignmentservice.GetUserAssignedLot(this._projectdefenitionid, this.workflowid, 0, userid_,this.startdate,this.enddate,this.loadtype).subscribe(
    res => {

      // this.AssignedLotLoading = true;
      // this.AssignedLotvisible = true;
      debugger;
      if (res !== undefined) {
       this.lot_filter_orginial = []; 
        let arr=JSON.parse(res[0])
        arr.forEach(i=>{
          var mdata= i.lotmastermetafields;
          if(mdata != null){
            mdata.forEach(j => {
              if(j.FieldName=="Company Name")i.CompanyName=j.FieldValue;
             // if(j.FieldName=="Type")i.Type=j.FieldValue;
              //if(j.FieldName=="Frequency")i.Frequency=j.FieldValue;
              //if(j.FieldName=="Ranking")i.Ranking=j.FieldValue;
              if(j.FieldName=="City")i.City=j.FieldValue;
              if(j.FieldName=="State")i.State=j.FieldValue;
              if(j.FieldName=="Project ID")i.ProjectID=j.FieldValue;
             // if(j.FieldName=="URL")i.URL=j.FieldValue;
              //if(j.FieldName=="Follow Up Date")i.FollowUpDate=j.FieldValue;
              if(j.FieldName=="Bid Date")i.BidDate=this.datepipe.transform(j.FieldValue, 'dd-MMM-yyyy');
            });
            }
            this.lot_filter_orginial.push(i);
          });
          if(mode == 'user'){
            this.AssignedLot = [];
            this.projectid_search_filter = '';
            this.AssignedLotLoading = false;
            this.AssignedLotvisible = false;
          }else if(mode =='assign'){
            this.projectid_filter('assign');
          }
                }
    },
    error => { this.toastr.error('Error while getting Viewlot data'); }
  );
} */
}
