Exemplo n.º 1
0
 public function excel($params)
 {
     $query = RceExamenExamen::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, 'rce_examen_id' => $this->rce_examen_id, 'examen_id' => $this->examen_id, 'monto_a_pagar' => $this->monto_a_pagar]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRceExamenExamens()
 {
     return $this->hasMany(RceExamenExamen::className(), ['examen_id' => 'id']);
 }
 /**
  * Finds the RceExamenExamen model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return RceExamenExamen the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = RceExamenExamen::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 4
0
 /**
  * Updates an existing RceExamen model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsPago = $model->pagos;
     $modelsBitacora = $model->bitacoras;
     $modelsExamenes = $model->rceExamenExamens;
     foreach ($modelsExamenes as $modelExamen) {
         $examen = Examen::find()->where(['id' => $modelExamen->examen_id])->one();
         $modelExamen->descripcion = $examen->descripcion;
         $modelExamen->observaciones = $examen->observaciones;
     }
     if ($model->load(Yii::$app->request->post())) {
         $oldIDsPago = ArrayHelper::map($modelsPago, 'id', 'id');
         $modelsPago = Model::createMultiple(Pago::classname(), $modelsPago);
         Model::loadMultiple($modelsPago, Yii::$app->request->post());
         $deletedIDsPago = array_diff($oldIDsPago, array_filter(ArrayHelper::map($modelsPago, 'id', 'id')));
         $oldIDsExamen = ArrayHelper::map($modelsExamenes, 'id', 'id');
         $modelsExamenes = Model::createMultiple(Examen::classname(), $modelsExamenes);
         Model::loadMultiple($modelsExamenes, Yii::$app->request->post());
         $deletedIDsExamen = array_diff($oldIDsExamen, array_filter(ArrayHelper::map($modelsExamenes, 'id', 'id')));
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsPago) && $valid;
         $valid = Model::validateMultiple($modelsBitacora) && $valid;
         $valid = Model::validateMultiple($modelsExamenes) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDsPago)) {
                         Pago::deleteAll(['id' => $deletedIDsPago]);
                     } else {
                         if (!empty($deletedIDsBitacora)) {
                             Bitacora::deleteAll(['id' => $deletedIDsBitacora]);
                         } else {
                             if (!empty($deletedIDsREE)) {
                                 RceExamenExamen::deleteAll(['id' => $deletedIDsREE]);
                             }
                         }
                     }
                     foreach ($modelsPago as $modelPago) {
                         $modelPago->rce_examen_id = $model->id;
                         if (!($flag = $modelPago->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                     foreach ($modelsBitacora as $modelBitacora) {
                         $modelBitacora->rce_examen_id = $model->id;
                         if (!($flag = $modelBitacora->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                     $reserva = Reserva::find()->where(['id' => $model->reserva_id])->one();
                     $hora = Hora::find()->where(['id' => $reserva->hora_medica_id])->one();
                     $examenes = HoraExamenSolicitado::find()->where(['hora_id' => $hora->id])->all();
                     for ($i = 0; $i < count($examenes); ++$i) {
                         $examen = Examen::find()->where(['id' => $examenes[$i]->examen_id])->one();
                         $modelsExamenes[$i] = new RceExamenExamen();
                         $modelsExamenes[$i]->rce_examen_id = $model->id;
                         $modelsExamenes[$i]->examen_id = $examenes[$i]->examen_id;
                         $modelsExamenes[$i]->monto_a_pagar = $examen->monto;
                         if (!($flag = $modelsExamenes[$i]->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelsPago' => empty($modelsPago) ? [new Pago()] : $modelsPago, 'modelsBitacora' => empty($modelsBitacora) ? [new Bitacora()] : $modelsBitacora, 'modelsExamenes' => empty($modelsExamenes) ? [new RceExamenExamen()] : $modelsExamenes]);
 }