/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Detallecompra();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Detallecompra'])) {
         $model->attributes = $_POST['Detallecompra'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->NumCompra));
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#2
0
 public function actionUpdate($id)
 {
     //                $model=$this->loadModel($id);
     $member = new Detallecompra();
     if (isset($_POST['Detallecompra'])) {
         $cantidad_inicial = $member->Cantidad;
         $member->attributes = $_POST['Detallecompra'];
         //$cantidadinicial = $model->Cantidad;
         //SaldoAct = salcdo actua;l - cantidad incial
         if ($member->save()) {
             $criteria = new CDbCriteria();
             $criteria->condition = 'CodProducto=:CodProducto';
             $criteria->params = array(':CodProducto' => $model->CodProducto);
             $objProducto = Productos::model()->find($criteria);
             $objProducto->CanExistencia = $objProducto->CanExistencia + $member->Cantidad;
             $objProducto->save();
             //                                        $this->redirect(array('view', 'id' => $model->Id));
         }
     }
     $this->render('update', array('model' => $model));
 }