예제 #1
0
 /**
  * Lists all Pedido models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PedidoSearch();
     if (Yii::$app->user->identity != null && Yii::$app->user->identity->username == "admin") {
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     } else {
         $dataProvider = $searchModel->search2(Yii::$app->request->queryParams);
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
예제 #2
0
 /**
  * Lists all Pedido models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PedidoSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
예제 #3
0
 /**
  * Deletes an existing Pedido model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     //Guarda a mensagem
     $mensagem = "";
     $transaction = \Yii::$app->db->beginTransaction();
     try {
         $itenspedido = Itempedido::find()->where(['idPedido' => $id])->all();
         foreach ($itenspedido as $p) {
             Insumo::atualizaQtdNoEstoqueDelete($p->idProduto, $p->quantidade);
         }
         if ($this->findModel($id)->delete()) {
             $transaction->commit();
         }
     } catch (\Exception $exception) {
         $transaction->rollBack();
         $mensagem = "Ocorreu uma falha inesperada ao tentar salvar ";
     }
     $searchModel = new PedidoSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'mensagem' => $mensagem]);
 }