Medikal BeforeSave Script

Medikal BeforeSave Script

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));
    }
  });
};
return (async () => {
  // Tolga 2020-06-15
  let ADULT =
    +(this.recordService.component.allFormControls.ADULT.value || 0) || 0;
  let CHD1 =
    +(this.recordService.component.allFormControls.CHD1.value || 0) || 0;
  let CHD2 =
    +(this.recordService.component.allFormControls.CHD2.value || 0) || 0;
  let BABY =
    +(this.recordService.component.allFormControls.BABY.value || 0) || 0;
  let pax = ADULT + CHD1 + CHD2 + BABY;
  let gridCount = 0;
  await awaitIf(
    () => this.recordService.grids?.medical-resname?.api?.forEachNode
  );
  this.recordService.grids.medical-resname.api.forEachNode((node) => {
    if (!node['toBeDeleted'] && node.data.DEPARTED !== true) {
      gridCount++;
    }
  });
  if (pax > 0 && gridCount > pax) {
    let msg = `Can Have Maximum {{${pax}}} Guests.`;
    msg = angus.languageService.staticTranslator.translate(msg);
    throw msg;
  }

  //çift rez engelle
  if (angus.api.tenant.CHECK_SAME_RES == 1) {
    //!this.recordService.component.allFormControls['ID'].value &&
    if (
      !this.recordService.component.allFormControls['ID'].value &&
      this.recordService.grids.medical-resname.grid.rowCount > 0
    ) {
      let GName = '';
      let GLName = '';

      let ResId = '';
      this.recordService.grids.medical-resname.api.forEachNode((node) => {
        GName = node.data.NAME;
        GLName = node.data.LNAME;
      });

      this.recordService.component.api
        .execSP({
          Object: 'SP_EASYPMS_CHECKSAMERES',
          Parameters: {
            GUESTNAME: GName,
            GUESTLNAME: GLName,
            AGENCYID: this.recordService.component.allFormControls.AGENCYID
              .value,
            CHECKIN: this.recordService.component.allFormControls.CHECKIN.value,
            CHECKOUT: this.recordService.component.allFormControls.CHECKOUT
              .value,
            VOUCHER: this.recordService.component.allFormControls.VOUCHERNO
              .value,
            RESID: this.recordService.component.allFormControls.ID.value,
          },
        })
        .subscribe((resp) => {
          if (resp[0][0].SUCCESS == '0')
            this.recordService.component.angusDialog.warn(resp[0][0].MESSAGE);
        });
    }
  }
  
  //konaklayanlarda oda değişitirildiğinde değişim nedenini soran sp nin rowaction olarak çalıştırılması
  if(this.recordService.component.mode.value === "update" && this.recordService.lastData.RESSTATEID === 3 && 
  this.recordService.component.allFormControls.ROOMCOUNTTYPE.value != 2 && 
  this.recordService.lastData.ROOMCOUNTTYPE != 6 &&
  this.recordService.component.allFormControls.ROOMID.value &&
  this.recordService.lastData.ROOMID != this.recordService.component.allFormControls.ROOMID.value){
    const roomChangeReason = await this.runRowAction('roomChangeReason');
  }
})();

Last updated