/**
  * Deletes an existing Itempedido model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $idPedido
  * @param integer $idProduto
  * @return mixed
  */
 public function actionDelete($idPedido, $idProduto)
 {
     $model = $this->findModel($idPedido, $idProduto);
     Insumo::atualizaQtdNoEstoqueDelete($idProduto, $model->quantidade);
     $this->findModel($idPedido, $idProduto)->delete();
     return $this->redirect(['index']);
 }
 /**
  * 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]);
 }
 /**
  * Atualiza a quantidade de estoque do Produto
  */
 public function removerItemPedido()
 {
     if (Insumo::atualizaQtdNoEstoqueDelete($this->idProduto, $this->quantidade)) {
         $this->delete();
     }
 }