public function excel($params)
 {
     $query = Administrador::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => array('pageSize' => 10000)]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'persona_id' => $this->persona_id]);
     return $dataProvider;
 }
 /**
  * Creates a new Reserva model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Reserva();
     $modelHora = new Hora();
     $modelsExamen = [new HoraExamenSolicitado()];
     if ($model->load(Yii::$app->request->post()) && $modelHora->load(Yii::$app->request->post())) {
         $modelsExamen = Model::createMultiple(HoraExamenSolicitado::classname());
         Model::loadMultiple($modelsExamen, Yii::$app->request->post());
         $valid = $model->validate();
         $valid = $modelHora->validate() && $valid;
         $valid = Model::validateMultiple($modelsExamen) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 $administrador = Administrador::find()->where(['id' => Yii::$app->user->getId()])->one();
                 $modelHora->administrador_id = $administrador->id;
                 $modelHora->save(false);
                 $profesional = Profesional::find()->where(['id' => $modelHora->profesional_id])->one();
                 $persona = Persona::find()->where(['id' => $profesional->persona_id])->one();
                 $model->hora_medica_id = $modelHora->id;
                 $model->persona_id_ingresa_reserva = $persona->id;
                 $model->save(false);
                 foreach ($modelsExamen as $modelExamen) {
                     $modelExamen->hora_id = $model->hora_medica_id;
                     if (!($flag = $modelExamen->save(false))) {
                         $transaction->rollBack();
                         break;
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render('create', ['model' => $model, 'modelHora' => $modelHora, 'modelsExamen' => empty($modelsExamen) ? [new HoraExamenSolicitado()] : $modelsExamen]);
     }
 }
Beispiel #3
0
<div class="hora-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'tipo_hora_id')->dropDownList(ArrayHelper::map(TipoHora::find()->all(), 'id', 'nombre'), ['prompt' => 'Seleccionar Tipo de Hora', 'style' => 'width:300px']);
?>

    <?php 
echo $form->field($model, 'profesional_id')->dropDownList(ArrayHelper::map(Profesional::find()->all(), 'id', 'Nombres'), ['prompt' => 'Seleccionar Profesional', 'style' => 'width:300px']);
?>

    <?php 
echo $form->field($model, 'administrador_id')->dropDownList(ArrayHelper::map(Administrador::find()->all(), 'id', 'Nombres'), ['prompt' => 'Seleccionar Administrador', 'style' => 'width:300px']);
?>

    <?php 
echo $form->field($model, 'hora_inicio')->widget(TimePicker::className(), ['pluginOptions' => ['format' => 'HH:MM', 'showMeridian' => false, 'minuteStep' => 1], 'options' => ['style' => 'width:260px'], 'addonOptions' => ['asButton' => true, 'inline-addon' => true]]);
?>

    <?php 
echo $form->field($model, 'tiempo_periodo')->textInput(['style' => 'width:300px']);
?>

    <?php 
echo $form->field($model, 'fecha')->widget(DatePicker::className(), ['removeButton' => false, 'pluginOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd'], 'options' => ['style' => 'width:260px']]);
?>

 /**
  * Finds the Administrador model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Administrador the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Administrador::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAdministrador()
 {
     return $this->hasOne(Administrador::className(), ['id' => 'administrador_id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIDADMIN()
 {
     return $this->hasOne(Administrador::className(), ['ID_ADMIN' => 'ID_ADMIN']);
 }
Beispiel #7
0
 public function getPerfil()
 {
     if (Administrador::find()->where(['persona_id' => $this->id])->exists()) {
         return 'Administrador';
     } else {
         if (Profesional::find()->where(['persona_id' => $this->id])->exists()) {
             return 'Profesional';
         } else {
             if (Paciente::find()->where(['persona_id' => $this->id])->exists()) {
                 return 'Paciente';
             }
         }
     }
 }
 /**
  * Deletes an existing Persona model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if (Administrador::find()->where(['persona_id' => $model->id])->exists()) {
         $admin = Administrador::find()->where(['persona_id' => $model->id])->one();
         $admin->delete();
         $model->delete();
     } else {
         if (Profesional::find()->where(['persona_id' => $model->id])->exists()) {
             $profesional = Profesional::find()->where(['persona_id' => $model->id])->one();
             $profesional->delete();
             $model->delete();
         } else {
             if (Paciente::find()->where(['persona_id' => $model->id])->exists()) {
                 $paciente = Paciente::find()->where(['persona_id' => $model->id])->one();
                 $paciente->delete();
                 $model->delete();
             }
         }
     }
     return $this->redirect(['index']);
 }