public function excel($params) { $query = Bitacora::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, 'estado_rce_examen_id' => $this->estado_rce_examen_id, 'rce_examen_id' => $this->rce_examen_id, 'persona_id_ingresa_bitacora' => $this->persona_id_ingresa_bitacora]); $query->andFilterWhere(['like', 'observacion', $this->observacion]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getBitacoras() { return $this->hasMany(Bitacora::className(), ['estado_rce_examen_id' => 'id']); }
/** * Finds the Bitacora model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Bitacora the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Bitacora::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function putUpdate($id) { $user = User::fromToken(); $bit = Bitacora::crear($user->user_id); try { $bit->periodo_id = $user->periodo_id; $nota = Nota::findOrFail($id); $bit->affected_element_old_value_int = $nota->nota; // Guardo la nota antigua $nota->nota = Request::input('nota'); $bit->affected_element_new_value_int = $nota->nota; // Guardo la nota nueva $nota->updated_by = $user->user_id; $nota->save(); } catch (Exception $e) { return abort(400, 'No se pudo guardar la nota'); } $bit->saveUpdateNota($nota); return $nota; }
/** * 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]); }
/** * @return \yii\db\ActiveQuery */ public function getBitacoras() { return $this->hasMany(Bitacora::className(), ['persona_id_ingresa_bitacora' => 'id']); }
public function getEstadoRCE() { $bitacora = Bitacora::find()->where(['rce_examen_id' => $this->id])->one(); $EstadoRCE = EstadoRceExamen::find()->where(['id' => $bitacora->estado_rce_examen_id])->one(); return $EstadoRCE->descripcion; }