public function actionOut()
    {
        if (isset($_POST['GoodsTransaction'])) {
            $err = 0;
            foreach ($_POST['GoodsTransaction'] as $postrans) {
                $model = new GoodsTransaction();
                //id_trans, qty, date_time, decsription, balance_history, goods_id, user_id
                $model->goods_id = $postrans['goods_id'];
                $model->decsription = $postrans['decsription'];
                $model->balance_history = 0;
                $model->qty = $postrans['qty'];
                $model->in = 0;
                $model->out = $postrans['qty'];
                $model->type_order = $postrans['order_name'];
                $model->warehouse_from = $postrans['warehouse_from'];
                $model->warehouse_to = $postrans['warehouse_to'];
                $model->date_time = date("Y-m-d H:i:s");
                $model->user_id = 1;
                if (!$model->save()) {
                    $errors = $model->getErrors();
                    foreach ($errors as $e) {
                        $messageError .= '
						<p id="error" class="info">
							<span class="info_inner">' . $e[0] . '</span>
						</p>';
                        var_dum($model->save);
                    }
                    Yii::app()->user->setFlash('error', $messageError);
                    $err++;
                } else {
                    $stock_input = StockGoods::model()->findByAttributes(array('goods_id' => $model->goods_id, 'warehouse_id' => $model->warehouse_to));
                    //var_dump($stock_input);
                    if ($stock_input != null) {
                        $stock_input->stock = $stock_input->stock + $model->out;
                        $stock_input->save();
                    } else {
                        $stock_input = new StockGoods();
                        $stock_input->goods_id = $model->goods_id;
                        $stock_input->warehouse_id = $model->warehouse_to;
                        $stock_input->stock = $model->out;
                        $stock_input->save();
                        //var_dump($stock_input->save);
                        //break;
                    }
                    $stock_output = StockGoods::model()->findByAttributes(array('goods_id' => $model->goods_id, 'warehouse_id' => $model->warehouse_from));
                    if ($stock_output != null) {
                        $stock_output->stock = $stock_output->stock - $model->out;
                        $stock_output->save();
                    }
                }
            }
            if ($err == 0) {
                Yii::app()->user->setFlash('success', '<p id="success" class="info">
							<span class="info_inner">Your transaction has been save successfully</span>
						</p>');
            }
            //echo "kookokokok";
            $this->redirect(array('out'));
        }
        $this->render('exit');
    }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = GoodsTransaction::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }