Example #1
0
 /**
  * Funció que retorna els descomptes aplicats amb el preu per mostrar-ho.
  * $DESC['NOM'], $DESC['PREU'], $DESC['PERCENT']
  * */
 public function getDescomptesArray($ambPreu = true)
 {
     $RET = array();
     $RET[-1] = 'Sense descompte';
     if ($ambPreu) {
         $RET[-1] .= ' (' . $this->getPreu() . '€)';
     }
     $AD = $this->getADescomptes();
     foreach ($AD as $k => $DESC) {
         if (!empty($DESC['NOM'])) {
             $RET[$k] = $DESC['NOM'];
             if ($ambPreu) {
                 $RET[$k] .= ' (' . CursosPeer::getPreuAmbDescompte($this->getIdcursos(), $k) . '€)';
             }
         }
     }
     return $RET;
 }
 /**
  * Funció que guarda una matrícula després d'enviar-ho des del gestor o bé des de l'hospici. 
  * @param $idU Identificador d'usuari
  * @param $idC Identificador de curs
  * @param $idM Identificador de matrícula si volem reutilitzar-la
  * @param $comment Comentari a guardar
  * @return new Matricules() o $error ( Codi d'error ) 
  * */
 public static function saveNewMatricula($idU, $idC, $comment = "", $idD, $Mode_pagament, $idDadesBancaries = null)
 {
     //Parametre que retornarem
     $RET = array('AVISOS' => array(), 'OM' => new Matricules());
     $OC = CursosPeer::retrieveByPK($idC);
     //Comprovem que l'usuari existeixi.
     if (is_null(UsuarisPeer::retrieveByPK($idU))) {
         $RET['AVISOS']["ERR_USUARI"] = "ERR_USUARI";
         return $RET;
     }
     //Comprovem que el curs existeixi.
     if (is_null(CursosPeer::retrieveByPK($idC))) {
         $RET['AVISOS']["ERR_CURS"] = "ERR_CURS";
         return $RET;
     }
     //Comprovem que aquest usuari no tingui ja una matrícula a aquest curs. Si ja ha estat matriculat, retornem -1.
     $OM = self::getMatriculaUsuari($idU, $idC, $OC->getSiteid());
     if (!is_null($OM)) {
         $RET['AVISOS']["ERR_JA_TE_UNA_MATRICULA"] = "ERR_JA_TE_UNA_MATRICULA";
         return $RET;
     }
     //Ara comprovem les diferents possibilitats. Calculem el preu amb reducció i deixem a 0 si no hi ha places.
     $PREU = CursosPeer::getPreuAmbDescompte($idC, $idD);
     //Entrem les dades que tenim i la deixem en procès per modificar-la després segons el que hagi passat
     $OM = new Matricules();
     $OM->setUsuarisUsuariid($idU);
     $OM->setCursosIdcursos($idC);
     $OM->setEstat(MatriculesPeer::EN_PROCES);
     $OM->setComentari($comment);
     $OM->setDatainscripcio(date('Y-m-d H:i', time()));
     $OM->setPagat($PREU);
     $OM->setTreduccio($idD);
     $OM->setTpagament($Mode_pagament);
     $OM->setSiteId($OC->getSiteid());
     $OM->setActiu(true);
     $OM->setTpvOperacio(0);
     $OM->setTpvOrder(0);
     if ($idDadesBancaries > 0) {
         $OM->setIddadesbancaries($idDadesBancaries);
     } else {
         $OM->setIddadesbancaries(null);
     }
     $OM->save();
     //Guardem l'identificador de la matrícula
     $RET['OM'] = $OM;
     //Si el curs és ple, guardem que està en espera i mostrem que el curs està ple i resta en llista d'espera
     if ($OC->isPle()) {
         if ($Mode_pagament == TipusPeer::PAGAMENT_LLISTA_ESPERA) {
             $OM->setPagat(0);
             $OM->setEstat(MatriculesPeer::EN_ESPERA);
             $OM->save();
             $RET['AVISOS']['CURS_PLE_LLISTA_ESPERA'] = "CURS_PLE_LLISTA_ESPERA";
         } else {
             $RET['AVISOS']['CURS_PLE'] = "CURS_PLE";
         }
         //Si queden places al curs
     } else {
         //Si el tipus de pagament és "reserva" ho guardem com a reservat.
         if ($Mode_pagament == TipusPeer::PAGAMENT_RESERVA) {
             $OM->setPagat(0);
             $OM->setEstat(MatriculesPeer::RESERVAT);
             $OM->setDatapagament(date('Y-m-d', time()));
             $OM->save();
             $RET['AVISOS']['RESERVA_OK'] = "RESERVA_OK";
             self::SendMailMatricula($OM, $OM->getSiteid());
             //Enviem el correu electrònic per a la reserva
         } elseif ($Mode_pagament == TipusPeer::PAGAMENT_TARGETA) {
             $OM->setEstat(MatriculesPeer::EN_PROCES);
             $OM->setDatapagament(date('Y-m-d', time()));
             $OM->save();
             $RET['AVISOS']['PAGAMENT_TPV'] = "PAGAMENT_TPV";
         } elseif ($Mode_pagament == TipusPeer::PAGAMENT_METALIC) {
             //Guardem la matrícula tal qual està.
             $OM->setEstat(MatriculesPeer::ACCEPTAT_PAGAT);
             $OM->setPagat($PREU);
             $OM->setDatapagament(date('Y-m-d', time()));
             $OM->save();
             $RET['AVISOS']['MATRICULA_METALIC_OK'] = "MATRICULA_METALIC_OK";
             self::SendMailMatricula($OM, $OM->getSiteid());
         } elseif ($Mode_pagament == TipusPeer::PAGAMENT_CODI_BARRES) {
             //Guardem la matrícula tal qual i marquem com a no pagada fins que vagi al banc a pagar-la.
             $OM->setEstat(MatriculesPeer::ACCEPTAT_NO_PAGAT);
             $OM->setPagat($PREU);
             $OM->setDatapagament(null);
             $OM->save();
             $RET['AVISOS']['MATRICULA_CODI_BARRES'] = "MATRICULA_CODI_BARRES";
             self::SendMailMatricula($OM, $OM->getSiteid());
         } elseif ($Mode_pagament == TipusPeer::PAGAMENT_DOMICILIACIO) {
             $OM->setPagat($PREU);
             $OM->setEstat(MatriculesPeer::ACCEPTAT_NO_PAGAT);
             $OM->setTpagament(MatriculesPeer::PAGAMENT_DOMICILIACIO);
             $OM->setDatapagament(null);
             $OM->save();
             $RET['AVISOS']['MATRICULA_DOMICILIACIO_OK'] = "MATRICULA_DOMICILIACIO_OK";
             self::SendMailMatricula($OM, $OM->getSiteid());
         }
         UsuarisPeer::addSite($OM->getUsuarisUsuariid(), $OM->getSiteId());
     }
     return $RET;
 }