Rezervasyon Kartı BeforeSave Script

Rezervasyon Kartı

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 () => {
  
  await awaitIf(() => this.allGrids["HOTEL_RES_DetailView"].grid);
  if (
    angus.api.tenant.RES_NAMES_REQUIRED && this.recordService.formGroup.controls.ROOMCOUNTTYPE.value != 6 && 
    this.allGrids['HOTEL_RES_DetailView'].grid.rowCount === 0
  ) {
    throw new Error(
      angus.languageService.dynamicTranslator.translate(
        'Guest field cannot be empty'
      )
    );
  }
  
  const formControls = this.recordService.component.allFormControls;
  let ADULT = +(formControls.ADULT.value || 0) || 0;
  let CHD1 = +(formControls.CHD1.value || 0) || 0;
  let CHD2 = +(formControls.CHD2.value || 0) || 0;
  let BABY = +(formControls.BABY.value || 0) || 0;
  let pax = ADULT + CHD1 + CHD2 + BABY;
  let gridCount = 0;
  await awaitIf(
    () => this.recordService.grids?.HOTEL_RES_DetailView?.api?.forEachNode
  );
  this.recordService.grids.HOTEL_RES_DetailView.api.forEachNode((node) => {
    if (!node['toBeDeleted'] && node.data.DEPARTED !== true) {
      gridCount++;
    }
  });
  
  if (pax < 0 || [ADULT, CHD1, CHD2, BABY].some((x) => x < 0)) {
    let msg = `Cannot enter negative guest count.`;
    msg = angus.languageService.staticTranslator.translate(msg);
    throw msg;
  }
  
  if (pax > 0 && gridCount > pax) {
    let msg = `Can Have Maximum {{${pax}}} Guests.`;
    msg = angus.languageService.staticTranslator.translate(msg);
    throw msg;
  }

  
  if (angus.api.tenant.CHECK_SAME_RES == 1) {
    
    if (
      !this.recordService.component.allFormControls['ID'].value &&
      this.recordService.grids.HOTEL_RES_DetailView.grid.rowCount > 0
    ) {
      let GName = '';
      let GLName = '';

      let ResId = '';
      this.recordService.grids.HOTEL_RES_DetailView.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);
        });
    }
  }

  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