HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/academy-period/academy-period.page.ts
import { Component, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { AcademyService } from '../../services/academy.service';
import { UtilsService } from '../../services/utils.service';
import { AlertController, ModalController } from '@ionic/angular';

@Component({
  selector: 'app-academy-period',
  templateUrl: './academy-period.page.html',
  styleUrls: ['./academy-period.page.scss'],
})
export class AcademyPeriodPage implements OnInit {

  academyUserId;
  periods: any = [];
  months;
  availableMonths: any = [];
  showMonthSelect;
  academyPurchaseId = null;
  location: number;
  isHideMonth: boolean = true;

  //---------------------------------------------------ng_models--------------------------------------------------------
  period;
  month = null;
  amount = 1;
  //-------------------------------------------------END_ng_models------------------------------------------------------

  constructor(
    private utilsService: UtilsService,
    public translateService: TranslateService,
    private academyService: AcademyService,
    public modalCtrl: ModalController,
    public alertCtrl: AlertController,
  ) { }

  ngOnInit() {
    this.loadInit();
  }

  cancel(status?) {
    this.modalCtrl.dismiss(status);
  }

  loadInit(time = 0) {
    setTimeout(() => {
      return new Promise((resolve, reject) => {
        this.utilsService.presentLoading(this.translateService.instant("all.loading")).then(() => {
          Promise.all([
            this.setMonths(),
            this.getPeriods()
          ]).then(() => {
            this.utilsService.dismissLoading();
            resolve(false);
          }).catch((error) => {
            this.utilsService.dismissLoading();
            console.log('Error loadInit AcademyPeriodPage', error);
            reject(error);
          });
        });
      });
    }, time);
  }

  setMonths() {
    this.months = Array.from({ length: 12 }, (item, i) => {
      return new Date(0, i).toLocaleString('es', { month: 'long' })
    });
  }

  async getPeriods() {

    let params = {
      academyUserId: this.academyUserId,
      location: this.location
    };
    (await this.academyService.getAcademyPeriods(params)).subscribe(
      (resp) => {
        this.periods = resp;
      },
      (error) => {
        console.log("error", error);
      }
    );
  }

  createPaymentSchedule() {
    let info = {
      academyUserId: this.academyUserId,
      periodId: this.period,
      initMonth: this.month,
      amount: this.amount,
      academyPurchaseId: this.academyPurchaseId
    };

    this.utilsService.presentLoading(this.translateService.instant("all.loading")).then(async () => {
      (await this.academyService.createPaymentSchedule(info)).subscribe({
        next: (res: any) => {
          if (!res.r) {
            this.utilsService.closeAllAlerts();
            this.presentConfirmationAlert(res.m);
            return;
          } else {
            this.utilsService.closeAllAlerts();
            this.utilsService.presentToast(4000, "success", "top", res.m);
            this.cancel(true);
          }
        },
        error: (err) => {
          console.error("error provider createPaymentSchedule: ", err);
        },
        complete: () => { },
      });
    });
  }

  async presentConfirmationAlert(message: string) {
    const alert = await this.alertCtrl.create({
      header: this.translateService.instant("error.alert"),
      message: message,
      backdropDismiss: false,
      buttons: [
        {
          text: this.translateService.instant("all.accept"),
          handler: () => {
            this.cancel(true);
          }
        }
      ]
    });

    await alert.present();
  }
}