Talep

Talep Script

const enableButton = (query, state) => {
  try {
    const btn = this.querySelector(query);
    if (state) {
      btn.disabled = false;
      btn.classList.remove("mat-button-disabled", "mat-disabled-button");
    } else {
      btn.disabled = true;
      btn.classList.add("mat-button-disabled", "mat-disabled-button");
    }
  } catch (e) {
    console.error("query not found", query, e);
  }
}
(async () => {
  const awaitIf = async (fn, ms = 100) => {
    await new Promise(async (resolve, reject) => {
      let result = false;
      try {
        result = fn();
      } catch (e) {
        console.error(e);
      }
      
      if(result) {
        resolve(true);
      } else {
        await rxjs.timer(ms).toPromise();
        resolve(await awaitIf(fn));
      }
    });
  }

  if (this.allGrids["stock-demand-fiches-details"] != null) {
    return this.allGrids["stock-demand-fiches-details"].grid
  } else {
    return undefined
  }
  

  const typeidControl = this.recordService.formGroup.controls.TYPEID;
  
  const primary = this.recordService.formGroup.controls.ID;
  

  document.querySelector('.ang-record-store-demand-fiches .ang-panel-stocks').style.display = 'none';
  document.querySelector('.ang-record-store-demand-fiches .ang-panel-stocks').parentElement.style.display = 'none';
  document.querySelector('.ang-record-store-demand-fiches .dynamic-container').style.gridTemplateAreas = 
  `"P1" "P2" "T1"`;
  document.querySelector('#openStocks .mat-icon').style.transform= 'rotate(0deg)' 
 
  const storeRecipientControl = this.recordService.elements.storeRecipientLookup.api.innerComponent.innerComponent.formControl;
  this.allFormControls['BRANCHID'].valueChanges.pipe(
    rxjs.filter((value ,index) => index > 1 || this.mode.value === 'insert'),
    rxjs.distinctUntilChanged()
  ).subscribe((branchID) => {
    this.recordService.formGroup.controls.RECIPIENTSTOREID.setValue(null);
    storeRecipientControl.setValue('abc');
    storeRecipientControl.setValue('');
  });
  
  primary.valueChanges
    .pipe(
      rxjs.startWith(primary.value),
      rxjs.debounceTime(100),
      rxjs.takeUntil(this.isDestroy$)
    )
    .subscribe(async (statusId) => {
       if(!this.recordService.lastData){
  this.recordService.formGroup.controls.TYPEID.setValue(100);
  this.recordService.formGroup.controls.TYPEID_NAME.setValue('New Requisition');
  this.recordService.formGroup.controls.TDATE.setValue(moment());
  this.recordService.formGroup.controls.TTIME.setValue(moment().format('YYYY-MM-DD HH:mm:ss'));
  this.recordService.formGroup.controls.CREATORID_USERCODE.setValue('');
  
}
      
    });
    
    
  typeidControl.valueChanges.pipe(rxjs.startWith(typeidControl.value)).subscribe(async typeId => {
        
    enableButton("#splitByQty", typeidControl.value <= 102);
  
    
    enableButton("#splitBySelection", typeidControl.value <= 102);
  
 
    try {
    document.getElementById('openStocks').disabled = (typeidControl.value != 100) ? true : false;
    } catch (e) {
    console.error('openStocks not found', e);
  }
  
    try {
    this.recordService.children.T1.component.tabGroupService.children[1].componentRef.instance.hide = (typeidControl.value == 100) ? true : false;
    this.recordService.children.T1.component.tabGroupService.children[2].componentRef.instance.hide = (typeidControl.value == 100) ? true : false;
    this.recordService.children.T1.component.tabGroupService.children[3].componentRef.instance.hide = (typeidControl.value == 100) ? true : false;
    this.recordService.children.T1.component.tabGroupService.children[4].componentRef.instance.hide = (typeidControl.value == 100) ? true : false;
    this.recordService.children.T1.component.updateTabs();
    document.querySelector('.ang-record-store-demand-fiches .ang-tab-groupT1 .mat-tab-label-active')?.click();
    } catch (e) {
    console.error('tabs hide not found', e);
  }
  
    const stockGrid = this.allGrids["stock-demand-fiches-details"];
    try {
    if(!stockGrid){
      throw new Error('stockGrid null')
    }
    await awaitIf(() => stockGrid.grid && stockGrid.grid.agGrid);
    
    stockGrid.grid.agGrid.columnApi.setColumnsVisible(['VENDORID_NAME','VENDORACTIONID', 'MAINSTOREQUANTITY'], (typeidControl.value >= 102));
    } catch (e) {
    console.error('stock-demand-fiches-details grid not found', e);
  }
  
  try {
    console.log(stockGrid,'grid');
    stockGrid.grid.buttonsForTemplate.addButton = (typeidControl.value > 100) ? false : stockGrid.grid.buttonsForTemplate.addButton;
    } catch (e) {
    console.error('stock-demand-fiches-details grid not found or buttonsForTemplate eror', e);
  }
  
    try{
    const buttonNames = {
      100 : 'Send To Main Store',
      101 : 'Send To Get Offers',
      102 : 'Send To Get Approvals',
      103 : 'Send To Order Confirmation',
      104 : 'Send To Expected Deliveries',
      105 : 'Send To Received Deliveries',
      106 : 'Send To Transferred'
    };
    document.querySelector('#nextStateBtn span').childNodes[0].textContent = angus.languageService.dynamicTranslator.translate(
      buttonNames[typeidControl.value] ? buttonNames[typeidControl.value] : ' '
    );}
    catch (e) {
    console.error('nextStateBtn not found', e);
  }
  
    try{
    if(typeidControl.value == 101 || typeidControl.value == 107) { 
      document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-mainStore').style.display = "grid";
    }
    else if(typeidControl.value == 104) { 
      setTimeout(() => {
        document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-sendOrdersMail').style.display = "grid";
      },5000);
    }
    else if(typeidControl.value == 102 ) {   
      setTimeout(() => {
        document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-getOfferMail').style.display = "grid";
      },5000);
      document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-getOffers').style.display = "grid";
      document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-offerAnalysis').style.display = "grid";
      document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-openVendorCard').style.display = "grid";
    }
    
    else if(typeidControl.value > 102) { 
      document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-offerAnalysis').style.display = "grid";
    }
    else {  
      document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-getOffers').style.display = "none";
      document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-mainStore').style.display = "none";
    
    }
    } catch (e) {
    console.error('', e);
  }
  
    try{
      this.recordService.children.T1.component.tabGroup.selectedTabChange.subscribe(x => {
      if(typeidControl.value == 102){ 
       console.log('içerdeyim 1*2');
       document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-getOfferMail').style.display = "grid";
      }
      else if(typeidControl.value == 104){ 
       console.log('içerdeyim 104');
       document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-sendOrdersMail').style.display = "grid";
      }
      else{
      console.log('elsedeyim');
       document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-getOfferMail').style.display = "none";
       document.querySelector('.ang-record-store-demand-fiches div.group.ang-group-sendOrdersMail').style.display = "none";
      }
      })
     }
    catch (e) {
    console.error('selectedTabChange not found', e);
  }
    
  }); 
})();

Last updated