@@ -2,12 +2,12 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | ini_set('max_execution_time', 300); |
| 4 | 4 | |
| 5 | -require_once(ROOT . DS . 'vendor' . DS . 'autoload.php'); |
|
| 5 | +require_once(ROOT.DS.'vendor'.DS.'autoload.php'); |
|
| 6 | 6 | |
| 7 | 7 | use Dompdf\Dompdf; |
| 8 | 8 | |
| 9 | 9 | |
| 10 | -class ProdutoController extends AppController{ |
|
| 10 | +class ProdutoController extends AppController { |
|
| 11 | 11 | |
| 12 | 12 | public function listar_cadastros() { |
| 13 | 13 | $this->layout = 'wadmin'; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | public function listar_cadastros_ajax() { |
| 17 | 17 | $this->layout = 'ajax'; |
| 18 | 18 | |
| 19 | - $aColumns = array( 'sku', 'imagem', 'nome', 'preco', 'estoque' ); |
|
| 19 | + $aColumns = array('sku', 'imagem', 'nome', 'preco', 'estoque'); |
|
| 20 | 20 | |
| 21 | 21 | $conditions = array('conditions' => |
| 22 | 22 | array( |
@@ -27,26 +27,26 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | $allProdutos = $this->Produto->find('all', $conditions); |
| 29 | 29 | |
| 30 | - if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) |
|
| 30 | + if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') |
|
| 31 | 31 | { |
| 32 | 32 | $conditions['offset'] = $_GET['iDisplayStart']; |
| 33 | 33 | $conditions['limit'] = $_GET['iDisplayLength']; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if ( isset( $_GET['iSortCol_0'] ) ) |
|
| 36 | + if (isset($_GET['iSortCol_0'])) |
|
| 37 | 37 | { |
| 38 | - for ( $i=0 ; $i < intval( $_GET['iSortingCols'] ) ; $i++ ) |
|
| 38 | + for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) |
|
| 39 | 39 | { |
| 40 | - if ( $_GET[ 'bSortable_' . intval($_GET['iSortCol_' . $i]) ] == "true" ) |
|
| 40 | + if ($_GET['bSortable_'.intval($_GET['iSortCol_'.$i])] == "true") |
|
| 41 | 41 | { |
| 42 | - $conditions['order'] = array('Produto.' . $aColumns[intval($_GET['iSortCol_' . $i])] => $_GET['sSortDir_'.$i]); |
|
| 42 | + $conditions['order'] = array('Produto.'.$aColumns[intval($_GET['iSortCol_'.$i])] => $_GET['sSortDir_'.$i]); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - if ( isset( $_GET['sSearch'] ) && !empty( $_GET['sSearch'] ) ) |
|
| 47 | + if (isset($_GET['sSearch']) && ! empty($_GET['sSearch'])) |
|
| 48 | 48 | { |
| 49 | - $conditions['conditions']['Produto.nome LIKE '] = '%' . $_GET['sSearch'] . '%'; |
|
| 49 | + $conditions['conditions']['Produto.nome LIKE '] = '%'.$_GET['sSearch'].'%'; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $produtos = $this->Produto->find('all', $conditions); |
@@ -58,19 +58,19 @@ discard block |
||
| 58 | 58 | "aaData" => array() |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - foreach ( $produtos as $i => $produto ) |
|
| 61 | + foreach ($produtos as $i => $produto) |
|
| 62 | 62 | { |
| 63 | 63 | $row = array(); |
| 64 | 64 | |
| 65 | - for ( $i=0 ; $i < count($aColumns) ; $i++ ) |
|
| 65 | + for ($i = 0; $i < count($aColumns); $i++) |
|
| 66 | 66 | { |
| 67 | 67 | $value = $produto['Produto'][$aColumns[$i]]; |
| 68 | 68 | |
| 69 | 69 | if ($aColumns[$i] == "imagem") |
| 70 | 70 | { |
| 71 | - $value = '<img src="/uploads/produto/imagens/' . $produto['Produto'][$aColumns[$i]] . '" width="120" height="120">'; |
|
| 71 | + $value = '<img src="/uploads/produto/imagens/'.$produto['Produto'][$aColumns[$i]].'" width="120" height="120">'; |
|
| 72 | 72 | |
| 73 | - if (!isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
| 73 | + if ( ! isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
| 74 | 74 | { |
| 75 | 75 | $value = '<img src="/images/no_image.png" width="120" height="120">'; |
| 76 | 76 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $row[] = $value; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - $btEdit = '<a class="btn btn-info" href="/produto/editar_cadastro/' . $produto['Produto']['id'] . '"><i class="fa fa-pencil"></i></a>'; |
|
| 82 | + $btEdit = '<a class="btn btn-info" href="/produto/editar_cadastro/'.$produto['Produto']['id'].'"><i class="fa fa-pencil"></i></a>'; |
|
| 83 | 83 | |
| 84 | 84 | $row[] = $btEdit; |
| 85 | 85 | |
@@ -90,15 +90,15 @@ discard block |
||
| 90 | 90 | exit; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - public function listar_cadastros_estoque_minimo(){ |
|
| 93 | + public function listar_cadastros_estoque_minimo() { |
|
| 94 | 94 | $this->layout = 'wadmin'; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - public function listar_cadastros_estoque_minimo_ajax(){ |
|
| 97 | + public function listar_cadastros_estoque_minimo_ajax() { |
|
| 98 | 98 | |
| 99 | 99 | $this->layout = 'ajax'; |
| 100 | 100 | |
| 101 | - $aColumns = array( 'sku', 'imagem', 'nome', 'preco', 'estoque' ); |
|
| 101 | + $aColumns = array('sku', 'imagem', 'nome', 'preco', 'estoque'); |
|
| 102 | 102 | |
| 103 | 103 | $this->loadModel('Usuario'); |
| 104 | 104 | |
@@ -120,26 +120,26 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $allProdutos = $this->Produto->find('all', $conditions); |
| 122 | 122 | |
| 123 | - if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) |
|
| 123 | + if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') |
|
| 124 | 124 | { |
| 125 | 125 | $conditions['offset'] = $_GET['iDisplayStart']; |
| 126 | 126 | $conditions['limit'] = $_GET['iDisplayLength']; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - if ( isset( $_GET['iSortCol_0'] ) ) |
|
| 129 | + if (isset($_GET['iSortCol_0'])) |
|
| 130 | 130 | { |
| 131 | - for ( $i=0 ; $i < intval( $_GET['iSortingCols'] ) ; $i++ ) |
|
| 131 | + for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) |
|
| 132 | 132 | { |
| 133 | - if ( $_GET[ 'bSortable_' . intval($_GET['iSortCol_' . $i]) ] == "true" ) |
|
| 133 | + if ($_GET['bSortable_'.intval($_GET['iSortCol_'.$i])] == "true") |
|
| 134 | 134 | { |
| 135 | - $conditions['order'] = array('Produto.' . $aColumns[intval($_GET['iSortCol_' . $i])] => $_GET['sSortDir_'.$i]); |
|
| 135 | + $conditions['order'] = array('Produto.'.$aColumns[intval($_GET['iSortCol_'.$i])] => $_GET['sSortDir_'.$i]); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ( isset( $_GET['sSearch'] ) && !empty( $_GET['sSearch'] ) ) |
|
| 140 | + if (isset($_GET['sSearch']) && ! empty($_GET['sSearch'])) |
|
| 141 | 141 | { |
| 142 | - $conditions['conditions']['Produto.nome LIKE '] = '%' . $_GET['sSearch'] . '%'; |
|
| 142 | + $conditions['conditions']['Produto.nome LIKE '] = '%'.$_GET['sSearch'].'%'; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | $produtos = $this->Produto->find('all', $conditions); |
@@ -151,19 +151,19 @@ discard block |
||
| 151 | 151 | "aaData" => array() |
| 152 | 152 | ); |
| 153 | 153 | |
| 154 | - foreach ( $produtos as $i => $produto ) |
|
| 154 | + foreach ($produtos as $i => $produto) |
|
| 155 | 155 | { |
| 156 | 156 | $row = array(); |
| 157 | 157 | |
| 158 | - for ( $i=0 ; $i < count($aColumns) ; $i++ ) |
|
| 158 | + for ($i = 0; $i < count($aColumns); $i++) |
|
| 159 | 159 | { |
| 160 | 160 | $value = $produto['Produto'][$aColumns[$i]]; |
| 161 | 161 | |
| 162 | 162 | if ($aColumns[$i] == "imagem") |
| 163 | 163 | { |
| 164 | - $value = '<img src="/uploads/produto/imagens/' . $produto['Produto'][$aColumns[$i]] . '" width="120" height="120">'; |
|
| 164 | + $value = '<img src="/uploads/produto/imagens/'.$produto['Produto'][$aColumns[$i]].'" width="120" height="120">'; |
|
| 165 | 165 | |
| 166 | - if (!isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
| 166 | + if ( ! isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
| 167 | 167 | { |
| 168 | 168 | $value = '<img src="/images/no_image.png" width="120" height="120">'; |
| 169 | 169 | } |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | break; |
| 260 | 260 | |
| 261 | 261 | $html .= ' <tr>'; |
| 262 | - $html .= ' <td>' . $produto['Produto']['nome'] . '</td>'; |
|
| 263 | - $html .= ' <td>' . $produto['Produto']['estoque'] . '</td>'; |
|
| 264 | - $html .= ' <td>R$ ' . number_format($produto['Produto']['custo'], 2, ',', '.') . '</td>'; |
|
| 262 | + $html .= ' <td>'.$produto['Produto']['nome'].'</td>'; |
|
| 263 | + $html .= ' <td>'.$produto['Produto']['estoque'].'</td>'; |
|
| 264 | + $html .= ' <td>R$ '.number_format($produto['Produto']['custo'], 2, ',', '.').'</td>'; |
|
| 265 | 265 | $html .= ' </tr>'; |
| 266 | 266 | } |
| 267 | 267 | |
@@ -293,15 +293,15 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | public function s_adicionar_cadastro() { |
| 296 | - $dados = $this->request->data('dados'); |
|
| 296 | + $dados = $this->request->data('dados'); |
|
| 297 | 297 | |
| 298 | 298 | $variacoes = $this->request->data('variacao'); |
| 299 | 299 | |
| 300 | - $image = $_FILES['imagem']; |
|
| 300 | + $image = $_FILES['imagem']; |
|
| 301 | 301 | |
| 302 | 302 | $retorno = $this->uploadImage($image); |
| 303 | 303 | |
| 304 | - if (!$retorno['status']) |
|
| 304 | + if ( ! $retorno['status']) |
|
| 305 | 305 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
| 306 | 306 | |
| 307 | 307 | $dados['imagem'] = $retorno['nome']; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | $dados['ativo'] = 1; |
| 310 | 310 | $dados['id_alias'] = $this->id_alias(); |
| 311 | 311 | |
| 312 | - if($this->Produto->save($dados)) { |
|
| 312 | + if ($this->Produto->save($dados)) { |
|
| 313 | 313 | $produto_id = $this->Produto->getLastInsertId(); |
| 314 | 314 | |
| 315 | 315 | require 'VariacaoController.php'; |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | $this->loadModel('Variacao'); |
| 335 | 335 | |
| 336 | - $query = array ( |
|
| 336 | + $query = array( |
|
| 337 | 337 | 'joins' => array( |
| 338 | 338 | array( |
| 339 | 339 | 'table' => 'produtos', |
@@ -376,12 +376,12 @@ discard block |
||
| 376 | 376 | |
| 377 | 377 | $variacoes = $this->request->data('variacao'); |
| 378 | 378 | |
| 379 | - $image = $_FILES['imagem']; |
|
| 379 | + $image = $_FILES['imagem']; |
|
| 380 | 380 | |
| 381 | - if (!empty($image['name'])) { |
|
| 381 | + if ( ! empty($image['name'])) { |
|
| 382 | 382 | $retorno = $this->uploadImage($image); |
| 383 | 383 | |
| 384 | - if (!$retorno['status']) |
|
| 384 | + if ( ! $retorno['status']) |
|
| 385 | 385 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
| 386 | 386 | |
| 387 | 387 | $dados['imagem'] = $retorno['nome']; |
@@ -401,10 +401,10 @@ discard block |
||
| 401 | 401 | $objVariacaoController->desativar_variacoes($id); |
| 402 | 402 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
| 403 | 403 | |
| 404 | - $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
|
| 404 | + $this->Session->setFlash('Produto editado com sucesso!', 'default', 'good'); |
|
| 405 | 405 | return $this->redirect('/produto/listar_cadastros'); |
| 406 | 406 | } else { |
| 407 | - $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
|
| 407 | + $this->Session->setFlash('Ocorreu um erro ao editar o produto!', 'default', 'good'); |
|
| 408 | 408 | return $this->redirect('/produto/listar_cadastros'); |
| 409 | 409 | } |
| 410 | 410 | } |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | ) |
| 447 | 447 | ); |
| 448 | 448 | |
| 449 | - if (!$this->validar_estoque($retorno)) { |
|
| 449 | + if ( ! $this->validar_estoque($retorno)) { |
|
| 450 | 450 | return false; |
| 451 | 451 | } |
| 452 | 452 | |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | if ($user_active[0]['Usuario']['sale_without_stock']) |
| 477 | 477 | return true; |
| 478 | 478 | |
| 479 | - if (empty($produto) && !isset($produto)) { |
|
| 479 | + if (empty($produto) && ! isset($produto)) { |
|
| 480 | 480 | return false; |
| 481 | 481 | } |
| 482 | 482 | |
@@ -488,11 +488,11 @@ discard block |
||
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | public function calcular_preco_produto_venda($preco, $qnt) { |
| 491 | - if (empty($preco) || !isset($preco)) { |
|
| 491 | + if (empty($preco) || ! isset($preco)) { |
|
| 492 | 492 | return false; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - if (!is_numeric($qnt)) { |
|
| 495 | + if ( ! is_numeric($qnt)) { |
|
| 496 | 496 | return false; |
| 497 | 497 | } |
| 498 | 498 | |
@@ -503,12 +503,12 @@ discard block |
||
| 503 | 503 | |
| 504 | 504 | public function uploadImage(&$image) { |
| 505 | 505 | $type = substr($image['name'], -4); |
| 506 | - $nameImage = uniqid() . md5($image['name']) . $type; |
|
| 507 | - $dir = APP . 'webroot/uploads/produto/imagens/'; |
|
| 506 | + $nameImage = uniqid().md5($image['name']).$type; |
|
| 507 | + $dir = APP.'webroot/uploads/produto/imagens/'; |
|
| 508 | 508 | |
| 509 | - $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); |
|
| 509 | + $returnUpload = move_uploaded_file($image['tmp_name'], $dir.$nameImage); |
|
| 510 | 510 | |
| 511 | - if (!$returnUpload) |
|
| 511 | + if ( ! $returnUpload) |
|
| 512 | 512 | return array('nome' => null, 'status' => false); |
| 513 | 513 | |
| 514 | 514 | return array('nome' => $nameImage, 'status' => true); |
@@ -534,8 +534,8 @@ discard block |
||
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | public function exportar_excel_exemplo() { |
| 537 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 538 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 537 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 538 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 539 | 539 | |
| 540 | 540 | $objPHPExcel = new PHPExcel(); |
| 541 | 541 | // Definimos o estilo da fonte |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | public function importar_produtos_planilha() { |
| 575 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 575 | + if ( ! isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 576 | 576 | { |
| 577 | 577 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 578 | 578 | $this->redirect("/produto/listar_cadastros"); |
@@ -580,13 +580,13 @@ discard block |
||
| 580 | 580 | |
| 581 | 581 | $typesPermissions = ['application/vnd.ms-excel']; |
| 582 | 582 | |
| 583 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 583 | + if ( ! in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 584 | 584 | { |
| 585 | 585 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 586 | 586 | $this->redirect("/produto/listar_cadastros"); |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 589 | + $caminho = APP.'webroot/uploads/produto/planilhas/'.uniqid().'.xls'; |
|
| 590 | 590 | |
| 591 | 591 | $inputFileName = $_FILES['arquivo']['tmp_name']; |
| 592 | 592 | |
@@ -627,17 +627,17 @@ discard block |
||
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
| 630 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 631 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 630 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 631 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 632 | 632 | |
| 633 | 633 | $objPHPExcel = new PHPExcel(); |
| 634 | 634 | |
| 635 | 635 | try { |
| 636 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 637 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 638 | - $objPHPExcel = $objReader->load($inputFileName); |
|
| 639 | - } catch(Exception $e) { |
|
| 640 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 636 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 637 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 638 | + $objPHPExcel = $objReader->load($inputFileName); |
|
| 639 | + } catch (Exception $e) { |
|
| 640 | + die('Error loading file "'.pathinfo($inputFileName, PATHINFO_BASENAME).'": '.$e->getMessage()); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | $dados = []; |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | |
| 685 | 685 | $errors = $this->processar_lista_produtos($dados); |
| 686 | 686 | |
| 687 | - if (isset($errors) && !empty($errors)) |
|
| 687 | + if (isset($errors) && ! empty($errors)) |
|
| 688 | 688 | { |
| 689 | 689 | $this->QueueProduct->planilhaProcessedIncomplete($planilhaId); |
| 690 | 690 | } |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | ) |
| 711 | 711 | ); |
| 712 | 712 | |
| 713 | - if (isset($existProduto) && !empty($existProduto)) |
|
| 713 | + if (isset($existProduto) && ! empty($existProduto)) |
|
| 714 | 714 | { |
| 715 | 715 | $this->Produto->id = $existProduto[0]['Produto']['id']; |
| 716 | 716 | $this->Produto->save($dado); |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | |
| 720 | 720 | $this->Produto->create(); |
| 721 | 721 | |
| 722 | - if (!$this->Produto->save($dado)) |
|
| 722 | + if ( ! $this->Produto->save($dado)) |
|
| 723 | 723 | { |
| 724 | 724 | $errors[] = $dado; |
| 725 | 725 | } |