Park Giriş

Park Giriş Script

const resetNewInvoice = async (refreshGrid) => {
  try {
    this.recordService.formGroup.reset();
    this.recordService.formGroup.controls.CURRENCYID_CURCODE.setValue(
      angus.api.tenant.RES_DEFAULTCURRENCY
        ? angus.api.tenant.RES_DEFAULTCURRENCY
        : angus.api.tenant.DEFAULTCURRENCY
    );
    this.recordService.formGroup.controls.CURRENCYID.setValue(
      angus.api.tenant.RES_DEFAULTCURRENCYID
        ? angus.api.tenant.RES_DEFAULTCURRENCYID
        : angus.api.tenant.DEFAULTCURRENCYID
    );
    this.recordService.formGroup.controls.CURRENCYRATE.setValue(1);
    this.recordService.formGroup.controls.AGENCYID_AGENCYCODE.setValue(
      angus.api.tenant.ONLINEAGENCYCODE
        ? angus.api.tenant.ONLINEAGENCYCODE
        : null
    );
    this.recordService.formGroup.controls.AGENCYID.setValue(
      angus.api.tenant.ONLINEAGENCYID ? angus.api.tenant.ONLINEAGENCYID : null
    );
    this.recordService.formGroup.controls.ROOMTYPEID_ROOMTYPECODE.setValue(
      angus.api.tenant.RES_DEFAULTROOMTYPE
        ? angus.api.tenant.RES_DEFAULTROOMTYPE
        : null
    );
    this.recordService.formGroup.controls.ROOMTYPEID.setValue(
      angus.api.tenant.RES_DEFAULTROOMTYPEID
        ? angus.api.tenant.RES_DEFAULTROOMTYPEID
        : null
    );
    this.recordService.formGroup.controls.BOARDTYPEID_BOARDTYPE.setValue(
      angus.api.tenant.DEFAULTBOARDTYPE
        ? angus.api.tenant.DEFAULTBOARDTYPE
        : null
    );
    this.recordService.formGroup.controls.BOARDTYPEID.setValue(
      angus.api.tenant.DEFAULTBOARDTYPEID
        ? angus.api.tenant.DEFAULTBOARDTYPEID
        : null
    );
  } catch (err) {
    console.error(err);
    angus.api.angusDialog.error(err);
  }
};
const onClose = this.onClose;
this.onClose = (...args) => {
  resetNewInvoice();
  return;
};
setTimeout(() => {
  this.querySelector('.ang-field-CARDNO input').addEventListener(
    'keyup',
    (event) => {
      if (event.key === 'Enter') {
        this.querySelector('#findGuestBtn').click();
      }
    }
  );
}, 500);
const controls = this.recordService.formGroup.controls;

const fcCombineLatest = (formControlNames, debounceTime = 50) => {
  const changes = formControlNames.map((name) =>
    controls[name].valueChanges.pipe(rxjs.startWith(controls[name].value))
  );
  return rxjs.combineLatest(changes).pipe(
    //rxjs.debounceTime(debounceTime),
    rxjs.distinctUntilChanged((oldValues, newValues) => {
      return oldValues.every((oldValue, index) => {
        return oldValue === newValues[index];
      });
    }),
    rxjs.takeUntil(this.isDestroy$)
  );
};
const rates = {};
this.recordService._curFind = async (curId) => {
  //debugger;
  console.log('curId', curId);

  if (curId && curId !== window.angus.api.tenant.DEFAULTCURRENCYID) {
    if (rates[curId]) {
      return rates[curId];
    }
    let loading = this.recordService.component.loadingService.showLoadingOverlay();
    let response;
    try {
      response = await this.api
        .func({
          Object: 'FN_HOTEL_EXCHANGERATES',
          Parameters: {
            DATE: moment().format('YYYY-MM-DD HH:mm:ss'),
            TARGETCURRENCYID: curId,
            BASECURRENCYID: window.angus.api.tenant.DEFAULTCURRENCYID,
          },
        })
        .toPromise();
      let buyRate = response[0][0].BUYRATE;
      if (buyRate === 0) {
        buyRate = 1;
      }
      rates[curId] = 1 / buyRate;
    } catch (err) {
      angus.api.angusDialog.error(err);
      console.log('FN_HOTEL_EXCHANGERATES error: ', err);
    }
    loading.destroy();
    return rates[curId] || 1;
  }
  return 1;
};

const prices = {};
let priceId = '';
this.recordService._priceFind = async (agencyid, roomtypeid, boardtypeid) => {
  debugger;
  priceId =
    agencyid.toString() +
    '-' +
    roomtypeid.toString() +
    '-' +
    boardtypeid.toString();
  if (priceId) {
    if (prices[priceId]) {
      return prices[priceId];
    }
    let loading;
    let response;
    try {
      loading = this.recordService.component.loadingService.showLoadingOverlay();
      response = await this.api
        .func({
          Object: 'FN_FINDENTRANCEPRICE',
          Parameters: {
            AGENCYID: parseInt(agencyid),
            ROOMTYPEID: parseInt(roomtypeid),
            BOARDTYPEID: parseInt(boardtypeid),
          },
        })
        .toPromise();
      if (response?.[0]?.[0]) {
        let adultPrice = response[0][0].ADULTPRICE;
        let childPrice = response[0][0].CHILDPRICE;
        let babyPrice = response[0][0].BABYPRICE;
        prices[priceId] = {
          adult: adultPrice,
          child: childPrice,
          baby: babyPrice,
        };
      } else {
        prices[priceId] = { adult: 35, child: 35, baby: 0 };
      }
    } catch (err) {
      angus.api.angusDialog.error(err);
      console.log('FN_FINDENTRANCEPRICE error: ', err);
    }
    loading.destroy();
    return prices[priceId];
  }
  return {};
};

let adult = this.recordService.formGroup.controls.ADULT;
let child = this.recordService.formGroup.controls.CHILD;
let baby = this.recordService.formGroup.controls.BABY;
let entryPrice = this.recordService.formGroup.controls.ENTRYPRICE;
let totalPrice = this.recordService.formGroup.controls.TOTALPRICE;
let extraPrice = this.recordService.formGroup.controls.EXTRAPRICE;
//entryPrice hesaplama
fcCombineLatest([
  'ADULT',
  'CHILD',
  'BABY',
  'AGENCYID',
  'ROOMTYPEID',
  'BOARDTYPEID',
]).subscribe(
  async ([ADULT, CHILD, BABY, AGENCYID, ROOMTYPEID, BOARDTYPEID]) => {
    if (ADULT || CHILD || BABY) {
      let entryPrices = await this.recordService._priceFind(
        AGENCYID,
        ROOMTYPEID,
        BOARDTYPEID
      );
      let data = this.recordService.formGroup.getRawValue();
      let total =
        (+data.ADULT ? +data.ADULT * entryPrices.adult : 0) +
        (+data.CHILD ? +data.CHILD * entryPrices.child : 0) +
        (+data.BABY ? +data.BABY * entryPrices.baby : 0);
      entryPrice.setValue(total);
    } else {
      this.recordService.formGroup.controls.ENTRYPRICE.setValue(null);
      this.recordService.formGroup.controls.EXTRAPRICE.setValue(null);
      this.recordService.formGroup.controls.TOTALPRICE.setValue(null);
      this.recordService.formGroup.controls.CTOTALPRICE.setValue(null);
    }
    if (this.recordService.formGroup.controls.ADULT.value > 10) {
      let msg = angus.languageService.staticTranslator.translate(
        'You are entering more than 10 adults. Are you sure?'
      );
      let confirmResp = await this.recordService.component.angusDialog
        .confirm(msg)
        .toPromise();
      if (confirmResp) {
        //continue;
      } else {
        this.recordService.formGroup.controls.ADULT.setValue(null);
      }
    }

    if (this.recordService.formGroup.controls.CHILD.value > 10) {
      let msg = angus.languageService.staticTranslator.translate(
        'You are entering more than 10 children. Are you sure?'
      );
      let confirmResp = await this.recordService.component.angusDialog
        .confirm(msg)
        .toPromise();
      if (confirmResp) {
        //continue;
      } else {
        this.recordService.formGroup.controls.CHILD.setValue(null);
      }
    }

    if (this.recordService.formGroup.controls.BABY.value > 10) {
      let msg = angus.languageService.staticTranslator.translate(
        'You are entering more than 10 babies. Are you sure?'
      );
      let confirmResp = await this.recordService.component.angusDialog
        .confirm(msg)
        .toPromise();
      if (confirmResp) {
        //continue;
      } else {
        this.recordService.formGroup.controls.BABY.setValue(null);
      }
    }
  }
);
//toplam hesaplama
fcCombineLatest(['ENTRYPRICE', 'EXTRAPRICE']).subscribe(
  ([ENTRYPRICE, EXTRAPRICE]) => {
    if (typeof EXTRAPRICE === 'string' || typeof ENTRYPRICE === 'string') {
      return;
    }
    let total = +ENTRYPRICE + +EXTRAPRICE;
    totalPrice.setValue(total || 0);
    console.log(ENTRYPRICE, EXTRAPRICE);
  }
);
//Ekstra hesaplama
fcCombineLatest(['TOTALPRICE']).subscribe(([TOTALPRICE]) => {
  let entryPrice = +this.recordService.formGroup.controls.ENTRYPRICE.value;
  let newExtra = +TOTALPRICE - entryPrice;
  let oldExtra = +this.recordService.formGroup.controls.EXTRAPRICE.value;
  if ((newExtra || newExtra === 0) && newExtra !== oldExtra) {
    if (newExtra < 0) newExtra = 0;
    this.recordService.formGroup.controls.EXTRAPRICE.setValue(newExtra || 0);
  }
});
//döviz hesaplama
fcCombineLatest(['TOTALPRICE', 'CURRENCYRATE']).subscribe(
  ([TOTALPRICE, CURRENCYRATE]) => {
    if (!CURRENCYRATE) {
      CURRENCYRATE = 1;
    }
    let total = +TOTALPRICE / +CURRENCYRATE;
    this.recordService.formGroup.controls.CTOTALPRICE.setValue(total || 0);
  }
);
//Ekstra ve toplam hesaplama
fcCombineLatest(['CTOTALPRICE']).subscribe(([CTOTALPRICE]) => {
  let oldTotalPrice = +this.recordService.formGroup.controls.TOTALPRICE.value;
  let newTotalPrice =
    +this.recordService.formGroup.controls.CURRENCYRATE.value * +CTOTALPRICE;
  if (Math.abs(newTotalPrice - oldTotalPrice) > 0.0001) {
    this.recordService.formGroup.controls.TOTALPRICE.setValue(
      newTotalPrice || 0
    );
  }
});
// fcCombineLatest(['CURRENCYRATE', 'TOTALPRICE']).subscribe(([TOTALPRICE, CURRENCYRATE]) => {
//   this.recordService.formGroup.controls.CTOTALPRICE.setValue(total || 0);
// });

//KUR BULMA
fcCombineLatest(['CURRENCYID']).subscribe(async ([CURRENCYID]) => {
  if (CURRENCYID == null) {
    this.recordService.formGroup.controls.CURRENCYRATE.setValue(1);
    return;
  }
  if (typeof CURRENCYID !== 'number') {
    return;
  }
  const currencyRate = await this.recordService._curFind(CURRENCYID);
  this.recordService.formGroup.controls.CURRENCYRATE.setValue(currencyRate);
});

fcCombineLatest(['AGENCYID', 'ROOMTYPEID', 'BOARDTYPEID']).subscribe(
  async ([CURRENCYID]) => {
    if (AGENCYID == null || ROOMTYPEID == null || BOARDTYPEID == null) {
      return;
    }
    const currencyRate = await this.recordService._curFind(CURRENCYID);
    this.recordService.formGroup.controls.CURRENCYRATE.setValue(currencyRate);
  }
);

const enableButton = (query, state) => {
  try {
    const btn = this.recordService.component.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);
  }
};

this.recordService._insertInvoice = async (paymentTypeId) => {
  let data = this.recordService.formGroup.getRawValue();
  if (data.TOTALPRICE <= 0 && paymentTypeId != -3) {
    angus.api.angusDialog.warn('Can not save without price.');
    return;
  }
  try {
    enableButton('#cashBtn', false);
    enableButton('#cardBtn', false);
    enableButton('#refundBtn', false);
    let request = {
      Object: 'SP_POS_ENTRYCARDSAVE',
      BaseObject: 'HOTEL_FOLIOTRANS',
      Parameters: {
        CARDNO: data.CARDNO,
        GUESTNAME: data.FNAME,
        GUESTSURNAME: data.LNAME,
        AMOUNT: paymentTypeId == -3 ? 0 : data.ENTRYPRICE,
        DEPOSIT: paymentTypeId == -3 ? 0 : data.EXTRAPRICE,
        RESNAMEID: data.ID,
        PAYMENTDEPID: paymentTypeId,
        REBATE: paymentTypeId == -3 ? 1 : null,
        AGENCYID: data.AGENCYID,
        ROOMTYPEID: data.ROOMTYPEID,
        BOARDTYPEID: data.BOARDTYPEID,
        POSDISCOUNTGROUPID: data.POSDISCOUNTGROUPID,
      },
    };
    let resp = await angus.api.execSP(request).toPromise();
    if (resp?.[0]?.[0]) {
      let row = resp[0][0];
      //this.recordService.formGroup.controls.ID.setValue(row.ID);
      //this.recordService.formGroup.controls.BALANCE.setValue(row.BALANCE);
      if (!data.ID) {
        await angus.popupFormService.openFastReport({
          params: {
            form: 'QR_EntryCard.frx',
            PARAMID: row.ID,
          },
        });
      } else if (paymentTypeId == -3) {
        await angus.popupFormService.openFastReport({
          params: {
            form: 'QR_EntryCardRefund.frx',
            PARAMID: row.ID,
          },
        });
      }
      this.recordService.formGroup.reset();
      this.recordService.formGroup.controls.CURRENCYID_CURCODE.setValue(
        angus.api.tenant.RES_DEFAULTCURRENCY
          ? angus.api.tenant.RES_DEFAULTCURRENCY
          : angus.api.tenant.DEFAULTCURRENCY
      );
      this.recordService.formGroup.controls.CURRENCYID.setValue(
        angus.api.tenant.RES_DEFAULTCURRENCYID
          ? angus.api.tenant.RES_DEFAULTCURRENCYID
          : angus.api.tenant.DEFAULTCURRENCYID
      );
      this.recordService.formGroup.controls.CURRENCYRATE.setValue(1);

      this.recordService.formGroup.controls.AGENCYID_AGENCYCODE.setValue(
        angus.api.tenant.ONLINEAGENCYCODE
          ? angus.api.tenant.ONLINEAGENCYCODE
          : null
      );
      this.recordService.formGroup.controls.AGENCYID.setValue(
        angus.api.tenant.ONLINEAGENCYID ? angus.api.tenant.ONLINEAGENCYID : null
      );
      this.recordService.formGroup.controls.ROOMTYPEID_ROOMTYPECODE.setValue(
        angus.api.tenant.RES_DEFAULTROOMTYPE
          ? angus.api.tenant.RES_DEFAULTROOMTYPE
          : null
      );
      this.recordService.formGroup.controls.ROOMTYPEID.setValue(
        angus.api.tenant.RES_DEFAULTROOMTYPEID
          ? angus.api.tenant.RES_DEFAULTROOMTYPEID
          : null
      );
      this.recordService.formGroup.controls.BOARDTYPEID_BOARDTYPE.setValue(
        angus.api.tenant.DEFAULTBOARDTYPE
          ? angus.api.tenant.DEFAULTBOARDTYPE
          : null
      );
      this.recordService.formGroup.controls.BOARDTYPEID.setValue(
        angus.api.tenant.DEFAULTBOARDTYPEID
          ? angus.api.tenant.DEFAULTBOARDTYPEID
          : null
      );
    }
    enableButton('#cashBtn', true);
    enableButton('#cardBtn', true);
    enableButton('#refundBtn', true);
  } catch (err) {
    enableButton('#cashBtn', true);
    enableButton('#cardBtn', true);
    enableButton('#refundBtn', true);
    angus.api.angusDialog.error(err);
    console.log('SP_POS_ENTRYCARDSAVE insert error: ', err);
  }
};

// rxjs
//     .combineLatest(
//       this.recordService.formGroup.controls.AGENCYID.valueChanges.pipe(rxjs.startWith(this.recordService.formGroup.controls.AGENCYID.value)),
//       this.recordService.formGroup.controls.ROOMTYPEID.valueChanges.pipe(rxjs.startWith(this.recordService.formGroup.controls.ROOMTYPEID.value)),
//       this.recordService.formGroup.controls.BOARDTYPEID.valueChanges.pipe(rxjs.startWith(this.recordService.formGroup.controls.BOARDTYPEID.value))
//     ).pipe(
//       rxjs.debounceTime(100),
//       rxjs.distinctUntilChanged(([oldAgencyId, oldLRoomTypeId, oldBoardTypeId], [newAgencyId, newLRoomTypeId, newBoardTypeId]) => {
//         return oldAgencyId === newAgencyId && oldLRoomTypeId === newLRoomTypeId && oldBoardTypeId === newBoardTypeId
//       }),
//       rxjs.takeUntil(this.isDestroy$),
//       ).subscribe(async ([AGENCYID, ROOMTYPEID, BOARDTYPEID]) => {
//       if (AGENCYID || ROOMTYPEID || BOARDTYPEID) {
//         let data = this.recordService.formGroup.getRawValue();
//         (async () => {
//           let data = this.recordService.formGroup.getRawValue();
//           let entryPrices = await this.recordService._priceFind(
//             AGENCYID,
//             ROOMTYPEID,
//             BOARDTYPEID
//           );
//           let total =
//             (+data.ADULT ? +data.ADULT * entryPrices.adult : 0) +
//             (+data.CHILD ? +data.CHILD * entryPrices.child : 0) +
//             (+data.BABY ? +data.BABY * entryPrices.baby : 0);
//           this.recordService.formGroup.controls.ENTRYPRICE.setValue(total);
//         })();

//       }
//     });

Last updated