/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Compra();
     $model->id_usuario = Yii::app()->session['userModel']->id_usuario;
     $this->performAjaxValidation($model, 'compra-form');
     // var_dump($_POST['Compra']);die;
     if (isset($_POST['Compra'])) {
         $model->attributes = $_POST['Compra'];
         if ($model->save()) {
             foreach ($_POST as $key => $value) {
                 if ("DetalleCompra_" == substr($key, 0, 14)) {
                     $modelDetalle = new DetalleCompra();
                     $modelDetalle->id_compra = $model->id_compra;
                     $modelDetalle->id_producto = $value['id_producto'];
                     $modelDetalle->valor_unidad = $value['valor_unidad'];
                     $modelDetalle->cantidad = $value['cantidad'];
                     $modelDetalle->valor_total = $value['valor_total'];
                     $modelDetalle->save();
                 }
             }
             $this->redirect(array('view', 'id' => $model->id_compra));
         }
     }
     $this->render('create', array('model' => $model));
 }