示例#1
0
 public function existe_usuario_activo($atributo, $params)
 {
     $retorno = false;
     $usuario = Usuarios::findOne($this->cedula);
     if ($usuario == null) {
         $this->addError($atributo, 'Usuario no existe');
         $retorno = false;
     } else {
         $fechaprestamo = date("Y-m-d");
         //$usuario->fecha_suspension = date ( 'Y-m-d' , $usuario->fecha_suspension );
         if ($usuario->id_status == 2) {
             if ($fechaprestamo >= $usuario->fecha_suspension) {
                 $retorno = true;
             } else {
                 $this->addError($atributo, 'Usuario Suspendido');
                 return false;
             }
         } else {
             $retorno = true;
         }
     }
     return $retorno;
 }
 public function actionDevolucion($id)
 {
     $model = $this->findModel($id);
     $model->id_status = 4;
     $model->fecha_entregado = date('Y-m-d');
     if ($model->save()) {
         $fecha_actual = strtotime(date('Y-m-d'));
         $fecha_entrada = strtotime($model->fecha_devolucion);
         if ($fecha_actual > $fecha_entrada) {
             $usuario = Usuarios::findOne($model->cedula);
             $usuario->id_status = 2;
             $usuario->update();
             $recurso = Recursos::findOne($model->codigo);
             $fecha = strtotime('+5 day', strtotime(date('Y-m-d')));
             $activacion = date('d-m-Y', $fecha);
             $content = "<p>Estimado usuario " . $usuario->nombre . ",</p>";
             $content .= "<p>La biblioteca de la institucion le informa que le ha sido suspendido su servicio de prestamo.</p>";
             $content .= "<p>Motivo: Devolucion retardada del recurso: " . $recurso->titulo . "</p>";
             $content .= "<p>Podra volver a utilizar el servicio a partir de la fecha: " . $activacion . "</p>";
             // Enviar mail.
             Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $content])->setFrom(Yii::$app->params['adminEmail'])->setTo($usuario->email)->setSubject("Notificacion suspension")->setTextBody($content)->setHtmlBody($content)->send();
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->redirect(['view', 'id' => $model->id]);
 }
示例#3
0
 /**
  * Finds the Usuarios model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Usuarios the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Usuarios::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Updates an existing GrupoUsuarios model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionEdit($id)
 {
     $model = $this->findModel($id);
     if (Yii::$app->request->isPost) {
         $request = Yii::$app->request->post('GrupoUsuarios');
         $usuarios = [];
         foreach ($request['usuarios'] as $usuario) {
             $usuarios[] = Usuarios::findOne($usuario);
         }
         $model->linkAll('usuarios', $usuarios, [], true, true);
         $model->modificado_por = Yii::$app->user->getId();
         $model->modificado_em = date('Y-m-d G:i:s');
         if ($model->save()) {
             return $this->redirect(['index']);
         } else {
             return $this->render(['include', 'model' => $model]);
         }
     } else {
         return $this->render('include', ['model' => $model]);
     }
 }