/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new HistorialFormulacionDetalle();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['HistorialFormulacionDetalle'])) {
         $model->attributes = $_POST['HistorialFormulacionDetalle'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionActualizarFormulacion()
 {
     $model = HistorialFormulacion::model()->findByPk($_GET['id']);
     if (isset($_GET['idCita'])) {
         $idCita = $_GET['idCita'];
     } else {
         $idCita = null;
     }
     $model->paciente_id = $_GET['idPaciente'];
     $model->personal_id = Yii::app()->user->usuarioId;
     $model->cita_id = $idCita;
     $model->fecha = date("Y-m-d");
     if ($model->save()) {
         $detalleP = HistorialFormulacionDetalle::model()->findAll("historial_formulacion_id = {$model->id}");
         foreach ($detalleP as $detalle_P) {
             $detalle_P->delete();
         }
         $eltotal = 0;
         for ($i = 0; $i <= $_POST['variable']; $i++) {
             //$x = $i+1;
             //
             if (isset($_POST['formula_' . $i])) {
                 $detalleP = new HistorialFormulacionDetalle();
                 $detalleP->historial_formulacion_id = $model->id;
                 $detalleP->otra_formulacion = $_POST['otra_' . $i];
                 $detalleP->formulacion_id = $_POST['formula_' . $i];
                 $detalleP->formulacion = $_POST['formulacion_' . $i];
                 $detalleP->save();
             }
         }
         $this->redirect(array('view', 'id' => $model->id));
     }
     //}
     // $this->render('create',array(
     // 	'model'=>$model,
     // ));
 }