Exemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $products = new Products();
     $provider = new Provider();
     $prodList = $products->getUseProdList();
     $provList = $provider->getProvList();
     $model = new Realize();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['provider'])) {
         $fakturaId = $this->beforeSave($_POST['provider']);
         $currentDate = date('Y-m-d');
         //echo $fakturaId;
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $messageType = 'warning';
             $message = "There are some errors " . count($_POST['product_id']);
             if ($_POST['product_id']) {
                 for ($i = 0; $i < count($_POST['product_id']); $i++) {
                     $models = new Realize();
                     $models->faktura_id = $fakturaId;
                     $models->prod_id = $_POST['product_id'][$i];
                     $models->price = $_POST['price'][$i];
                     $models->count = $this->changeToFloat($_POST['count'][$i]);
                     if ($models->save()) {
                         $messageType = 'success';
                         $message = "<strong>Well done!</strong> You successfully create data ";
                     }
                 }
             }
             Yii::app()->user->setFlash($messageType, $message);
             $transaction->commit();
             $this->redirect(array('dishes/checkMargin'));
         } catch (Exception $e) {
             $transaction->rollBack();
             Yii::app()->user->setFlash('error', "{$e->getMessage()}");
             //$this->refresh();
         }
     }
     $this->render('create', array('model' => $model, 'prodList' => $prodList, 'provList' => $provList));
 }
Exemplo n.º 2
0
 public function actionRequest()
 {
     $products = new Products();
     $provider = new Provider();
     $prodList = $products->getUseProdList();
     $provList = $provider->getProvList();
     $depId = Department::model()->findAll();
     $dates = date('Y-m-d H:i:s');
     $command = Yii::app()->db->createCommand();
     $expense = new Expense();
     if (isset($_POST['request'])) {
         $command->insert('request', array('req_date' => $dates, 'provider_id' => $_POST['provider']));
         $lastId = Yii::app()->db->lastInsertID;
         foreach ($_POST['request'] as $key => $val) {
             foreach ($val as $keys => $value) {
                 $count = $expense->changeToFloat($value['count']);
                 $command->insert('request_prod', array('request_id' => $lastId, 'prod_id' => $keys, 'depId' => $key, 'count' => $count));
             }
         }
         $this->redirect(array('view', 'id' => $lastId));
     }
     $this->render('request', array('depId' => $depId, 'prodList' => $prodList, 'provList' => $provList));
 }