@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | public function getProdutosEstoqueMinimoComoHtml($produtos) { |
| 216 | - ob_start(); |
|
| 216 | + ob_start(); |
|
| 217 | 217 | |
| 218 | 218 | $html = ''; |
| 219 | 219 | $html .= '<html>'; |
@@ -316,11 +316,11 @@ discard block |
||
| 316 | 316 | |
| 317 | 317 | $this->Session->setFlash('Produto salvo com sucesso!'); |
| 318 | 318 | |
| 319 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 319 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 320 | 320 | } else { |
| 321 | 321 | $this->Session->setFlash('Ocorreu um erro ao salva o produto!'); |
| 322 | 322 | |
| 323 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 323 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
@@ -331,17 +331,17 @@ discard block |
||
| 331 | 331 | |
| 332 | 332 | $query = array ( |
| 333 | 333 | 'joins' => array( |
| 334 | - array( |
|
| 335 | - 'table' => 'produtos', |
|
| 336 | - 'alias' => 'Produto', |
|
| 337 | - 'type' => 'LEFT', |
|
| 338 | - 'conditions' => array( |
|
| 339 | - 'Variacao.produto_id = Produto.id', |
|
| 340 | - ), |
|
| 341 | - ) |
|
| 334 | + array( |
|
| 335 | + 'table' => 'produtos', |
|
| 336 | + 'alias' => 'Produto', |
|
| 337 | + 'type' => 'LEFT', |
|
| 338 | + 'conditions' => array( |
|
| 339 | + 'Variacao.produto_id = Produto.id', |
|
| 340 | + ), |
|
| 341 | + ) |
|
| 342 | 342 | ), |
| 343 | - 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 344 | - 'fields' => array('Produto.id, Variacao.*'), |
|
| 343 | + 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 344 | + 'fields' => array('Produto.id, Variacao.*'), |
|
| 345 | 345 | ); |
| 346 | 346 | |
| 347 | 347 | $variacoes = $this->set('variacoes', $this->Variacao->find('all', $query)); |
@@ -398,10 +398,10 @@ discard block |
||
| 398 | 398 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
| 399 | 399 | |
| 400 | 400 | $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
| 401 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 401 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 402 | 402 | } else { |
| 403 | 403 | $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
| 404 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 404 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
@@ -515,107 +515,107 @@ discard block |
||
| 515 | 515 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 516 | 516 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 517 | 517 | |
| 518 | - $objPHPExcel = new PHPExcel(); |
|
| 519 | - // Definimos o estilo da fonte |
|
| 520 | - $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
| 518 | + $objPHPExcel = new PHPExcel(); |
|
| 519 | + // Definimos o estilo da fonte |
|
| 520 | + $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
| 521 | 521 | |
| 522 | - $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
| 522 | + $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
| 523 | 523 | |
| 524 | - // Criamos as colunas |
|
| 525 | - $objPHPExcel->setActiveSheetIndex(0) |
|
| 526 | - ->setCellValue('A1', "Nome do Produto") |
|
| 527 | - ->setCellValue('B1', "Preço ") |
|
| 528 | - ->setCellValue("C1", "Peso Bruto") |
|
| 529 | - ->setCellValue("D1", "Peso Liquido") |
|
| 530 | - ->setCellValue("E1", "Estoque") |
|
| 531 | - ->setCellValue("F1", "Descrição"); |
|
| 524 | + // Criamos as colunas |
|
| 525 | + $objPHPExcel->setActiveSheetIndex(0) |
|
| 526 | + ->setCellValue('A1', "Nome do Produto") |
|
| 527 | + ->setCellValue('B1', "Preço ") |
|
| 528 | + ->setCellValue("C1", "Peso Bruto") |
|
| 529 | + ->setCellValue("D1", "Peso Liquido") |
|
| 530 | + ->setCellValue("E1", "Estoque") |
|
| 531 | + ->setCellValue("F1", "Descrição"); |
|
| 532 | 532 | |
| 533 | - // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
| 534 | - $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
| 533 | + // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
| 534 | + $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
| 535 | 535 | |
| 536 | - // Cabeçalho do arquivo para ele baixar |
|
| 537 | - header('Content-Type: application/vnd.ms-excel'); |
|
| 538 | - header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
| 539 | - header('Cache-Control: max-age=0'); |
|
| 540 | - // Se for o IE9, isso talvez seja necessário |
|
| 541 | - header('Cache-Control: max-age=1'); |
|
| 536 | + // Cabeçalho do arquivo para ele baixar |
|
| 537 | + header('Content-Type: application/vnd.ms-excel'); |
|
| 538 | + header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
| 539 | + header('Cache-Control: max-age=0'); |
|
| 540 | + // Se for o IE9, isso talvez seja necessário |
|
| 541 | + header('Cache-Control: max-age=1'); |
|
| 542 | 542 | |
| 543 | - // Acessamos o 'Writer' para poder salvar o arquivo |
|
| 544 | - $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
| 543 | + // Acessamos o 'Writer' para poder salvar o arquivo |
|
| 544 | + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
| 545 | 545 | |
| 546 | - // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
| 547 | - $objWriter->save('php://output'); |
|
| 546 | + // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
| 547 | + $objWriter->save('php://output'); |
|
| 548 | 548 | |
| 549 | - exit; |
|
| 550 | - } |
|
| 549 | + exit; |
|
| 550 | + } |
|
| 551 | 551 | |
| 552 | - public function importar_produtos_planilha() { |
|
| 553 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 554 | - { |
|
| 552 | + public function importar_produtos_planilha() { |
|
| 553 | + if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 554 | + { |
|
| 555 | 555 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 556 | 556 | $this->redirect("/produto/listar_cadastros"); |
| 557 | - } |
|
| 557 | + } |
|
| 558 | 558 | |
| 559 | - $typesPermissions = ['application/vnd.ms-excel']; |
|
| 559 | + $typesPermissions = ['application/vnd.ms-excel']; |
|
| 560 | 560 | |
| 561 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 562 | - { |
|
| 561 | + if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 562 | + { |
|
| 563 | 563 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 564 | 564 | $this->redirect("/produto/listar_cadastros"); |
| 565 | - } |
|
| 565 | + } |
|
| 566 | 566 | |
| 567 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 567 | + $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 568 | 568 | |
| 569 | - $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 569 | + $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 570 | 570 | |
| 571 | - move_uploaded_file($inputFileName, $caminho); |
|
| 571 | + move_uploaded_file($inputFileName, $caminho); |
|
| 572 | 572 | |
| 573 | - $data = [ |
|
| 574 | - 'caminho' => $caminho, |
|
| 575 | - 'usuario_id' => $this->instancia, |
|
| 576 | - 'processado' => 0, |
|
| 577 | - 'ativo' => 1 |
|
| 578 | - ]; |
|
| 573 | + $data = [ |
|
| 574 | + 'caminho' => $caminho, |
|
| 575 | + 'usuario_id' => $this->instancia, |
|
| 576 | + 'processado' => 0, |
|
| 577 | + 'ativo' => 1 |
|
| 578 | + ]; |
|
| 579 | 579 | |
| 580 | - $this->loadModel('QueueProduct'); |
|
| 580 | + $this->loadModel('QueueProduct'); |
|
| 581 | 581 | |
| 582 | - if ($this->QueueProduct->save($data)) |
|
| 583 | - { |
|
| 582 | + if ($this->QueueProduct->save($data)) |
|
| 583 | + { |
|
| 584 | 584 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 585 | 585 | $this->redirect("/produto/listar_cadastros"); |
| 586 | - } |
|
| 587 | - else |
|
| 588 | - { |
|
| 586 | + } |
|
| 587 | + else |
|
| 588 | + { |
|
| 589 | 589 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 590 | 590 | $this->redirect("/produto/listar_cadastros"); |
| 591 | - } |
|
| 592 | - } |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | 593 | |
| 594 | - public function processar_planilhas_na_fila() { |
|
| 595 | - $this->loadModel('QueueProduct'); |
|
| 594 | + public function processar_planilhas_na_fila() { |
|
| 595 | + $this->loadModel('QueueProduct'); |
|
| 596 | 596 | |
| 597 | - $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
| 597 | + $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
| 598 | 598 | |
| 599 | - $response = []; |
|
| 600 | - foreach ($planilhas as $planilha) { |
|
| 601 | - $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
| 602 | - } |
|
| 599 | + $response = []; |
|
| 600 | + foreach ($planilhas as $planilha) { |
|
| 601 | + $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - return $response; |
|
| 605 | - } |
|
| 604 | + return $response; |
|
| 605 | + } |
|
| 606 | 606 | |
| 607 | - public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
| 607 | + public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
| 608 | 608 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 609 | 609 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 610 | 610 | |
| 611 | - $objPHPExcel = new PHPExcel(); |
|
| 611 | + $objPHPExcel = new PHPExcel(); |
|
| 612 | 612 | |
| 613 | 613 | try { |
| 614 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 615 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 616 | - $objPHPExcel = $objReader->load($inputFileName); |
|
| 614 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 615 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 616 | + $objPHPExcel = $objReader->load($inputFileName); |
|
| 617 | 617 | } catch(Exception $e) { |
| 618 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 618 | + die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | $dados = []; |
@@ -671,39 +671,39 @@ discard block |
||
| 671 | 671 | |
| 672 | 672 | echo json_encode(array('sucess' => true)); |
| 673 | 673 | exit; |
| 674 | - } |
|
| 674 | + } |
|
| 675 | 675 | |
| 676 | - public function processar_lista_produtos($dados) { |
|
| 677 | - $errors = []; |
|
| 676 | + public function processar_lista_produtos($dados) { |
|
| 677 | + $errors = []; |
|
| 678 | 678 | |
| 679 | - foreach ($dados as $dado) { |
|
| 680 | - $this->loadModel('Produto'); |
|
| 679 | + foreach ($dados as $dado) { |
|
| 680 | + $this->loadModel('Produto'); |
|
| 681 | 681 | |
| 682 | - $existProduto = $this->Produto->find('all', |
|
| 683 | - array( |
|
| 684 | - 'conditions' => array( |
|
| 685 | - 'Produto.sku' => $dado['sku'], |
|
| 686 | - 'Produto.ativo' => 1 |
|
| 687 | - ) |
|
| 688 | - ) |
|
| 689 | - ); |
|
| 690 | - |
|
| 691 | - if (isset($existProduto) && !empty($existProduto)) |
|
| 692 | - { |
|
| 693 | - $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
| 694 | - $this->Produto->save($dado); |
|
| 695 | - continue; |
|
| 696 | - } |
|
| 682 | + $existProduto = $this->Produto->find('all', |
|
| 683 | + array( |
|
| 684 | + 'conditions' => array( |
|
| 685 | + 'Produto.sku' => $dado['sku'], |
|
| 686 | + 'Produto.ativo' => 1 |
|
| 687 | + ) |
|
| 688 | + ) |
|
| 689 | + ); |
|
| 690 | + |
|
| 691 | + if (isset($existProduto) && !empty($existProduto)) |
|
| 692 | + { |
|
| 693 | + $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
| 694 | + $this->Produto->save($dado); |
|
| 695 | + continue; |
|
| 696 | + } |
|
| 697 | 697 | |
| 698 | 698 | $this->Produto->create(); |
| 699 | 699 | |
| 700 | - if (!$this->Produto->save($dado)) |
|
| 701 | - { |
|
| 702 | - $errors[] = $dado; |
|
| 703 | - } |
|
| 704 | - } |
|
| 700 | + if (!$this->Produto->save($dado)) |
|
| 701 | + { |
|
| 702 | + $errors[] = $dado; |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | 705 | |
| 706 | - return $errors; |
|
| 707 | - } |
|
| 706 | + return $errors; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | 709 | } |
@@ -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 | } |
@@ -86,15 +86,15 @@ discard block |
||
| 86 | 86 | exit; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - public function listar_cadastros_estoque_minimo(){ |
|
| 89 | + public function listar_cadastros_estoque_minimo() { |
|
| 90 | 90 | $this->layout = 'wadmin'; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - public function listar_cadastros_estoque_minimo_ajax(){ |
|
| 93 | + public function listar_cadastros_estoque_minimo_ajax() { |
|
| 94 | 94 | |
| 95 | 95 | $this->layout = 'ajax'; |
| 96 | 96 | |
| 97 | - $aColumns = array( 'sku', 'imagem', 'nome', 'preco', 'estoque' ); |
|
| 97 | + $aColumns = array('sku', 'imagem', 'nome', 'preco', 'estoque'); |
|
| 98 | 98 | |
| 99 | 99 | $this->loadModel('Usuario'); |
| 100 | 100 | |
@@ -116,26 +116,26 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $allProdutos = $this->Produto->find('all', $conditions); |
| 118 | 118 | |
| 119 | - if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) |
|
| 119 | + if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') |
|
| 120 | 120 | { |
| 121 | 121 | $conditions['offset'] = $_GET['iDisplayStart']; |
| 122 | 122 | $conditions['limit'] = $_GET['iDisplayLength']; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ( isset( $_GET['iSortCol_0'] ) ) |
|
| 125 | + if (isset($_GET['iSortCol_0'])) |
|
| 126 | 126 | { |
| 127 | - for ( $i=0 ; $i < intval( $_GET['iSortingCols'] ) ; $i++ ) |
|
| 127 | + for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) |
|
| 128 | 128 | { |
| 129 | - if ( $_GET[ 'bSortable_' . intval($_GET['iSortCol_' . $i]) ] == "true" ) |
|
| 129 | + if ($_GET['bSortable_'.intval($_GET['iSortCol_'.$i])] == "true") |
|
| 130 | 130 | { |
| 131 | - $conditions['order'] = array('Produto.' . $aColumns[intval($_GET['iSortCol_' . $i])] => $_GET['sSortDir_'.$i]); |
|
| 131 | + $conditions['order'] = array('Produto.'.$aColumns[intval($_GET['iSortCol_'.$i])] => $_GET['sSortDir_'.$i]); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if ( isset( $_GET['sSearch'] ) && !empty( $_GET['sSearch'] ) ) |
|
| 136 | + if (isset($_GET['sSearch']) && ! empty($_GET['sSearch'])) |
|
| 137 | 137 | { |
| 138 | - $conditions['conditions']['Produto.nome LIKE '] = '%' . $_GET['sSearch'] . '%'; |
|
| 138 | + $conditions['conditions']['Produto.nome LIKE '] = '%'.$_GET['sSearch'].'%'; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $produtos = $this->Produto->find('all', $conditions); |
@@ -147,19 +147,19 @@ discard block |
||
| 147 | 147 | "aaData" => array() |
| 148 | 148 | ); |
| 149 | 149 | |
| 150 | - foreach ( $produtos as $i => $produto ) |
|
| 150 | + foreach ($produtos as $i => $produto) |
|
| 151 | 151 | { |
| 152 | 152 | $row = array(); |
| 153 | 153 | |
| 154 | - for ( $i=0 ; $i < count($aColumns) ; $i++ ) |
|
| 154 | + for ($i = 0; $i < count($aColumns); $i++) |
|
| 155 | 155 | { |
| 156 | 156 | $value = $produto['Produto'][$aColumns[$i]]; |
| 157 | 157 | |
| 158 | 158 | if ($aColumns[$i] == "imagem") |
| 159 | 159 | { |
| 160 | - $value = '<img src="/uploads/produto/imagens/' . $produto['Produto'][$aColumns[$i]] . '" width="120" height="120">'; |
|
| 160 | + $value = '<img src="/uploads/produto/imagens/'.$produto['Produto'][$aColumns[$i]].'" width="120" height="120">'; |
|
| 161 | 161 | |
| 162 | - if (!isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
| 162 | + if ( ! isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
| 163 | 163 | { |
| 164 | 164 | $value = '<img src="/images/no_image.png" width="120" height="120">'; |
| 165 | 165 | } |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | break; |
| 256 | 256 | |
| 257 | 257 | $html .= ' <tr>'; |
| 258 | - $html .= ' <td>' . $produto['Produto']['nome'] . '</td>'; |
|
| 259 | - $html .= ' <td>' . $produto['Produto']['estoque'] . '</td>'; |
|
| 260 | - $html .= ' <td>R$ ' . number_format($produto['Produto']['custo'], 2, ',', '.') . '</td>'; |
|
| 258 | + $html .= ' <td>'.$produto['Produto']['nome'].'</td>'; |
|
| 259 | + $html .= ' <td>'.$produto['Produto']['estoque'].'</td>'; |
|
| 260 | + $html .= ' <td>R$ '.number_format($produto['Produto']['custo'], 2, ',', '.').'</td>'; |
|
| 261 | 261 | $html .= ' </tr>'; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -289,15 +289,15 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | public function s_adicionar_cadastro() { |
| 292 | - $dados = $this->request->data('dados'); |
|
| 292 | + $dados = $this->request->data('dados'); |
|
| 293 | 293 | |
| 294 | 294 | $variacoes = $this->request->data('variacao'); |
| 295 | 295 | |
| 296 | - $image = $_FILES['imagem']; |
|
| 296 | + $image = $_FILES['imagem']; |
|
| 297 | 297 | |
| 298 | 298 | $retorno = $this->uploadImage($image); |
| 299 | 299 | |
| 300 | - if (!$retorno['status']) |
|
| 300 | + if ( ! $retorno['status']) |
|
| 301 | 301 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
| 302 | 302 | |
| 303 | 303 | $dados['imagem'] = $retorno['nome']; |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | $dados['ativo'] = 1; |
| 306 | 306 | $dados['id_alias'] = $this->id_alias(); |
| 307 | 307 | |
| 308 | - if($this->Produto->save($dados)) { |
|
| 308 | + if ($this->Produto->save($dados)) { |
|
| 309 | 309 | $produto_id = $this->Produto->getLastInsertId(); |
| 310 | 310 | |
| 311 | 311 | require 'VariacaoController.php'; |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | |
| 330 | 330 | $this->loadModel('Variacao'); |
| 331 | 331 | |
| 332 | - $query = array ( |
|
| 332 | + $query = array( |
|
| 333 | 333 | 'joins' => array( |
| 334 | 334 | array( |
| 335 | 335 | 'table' => 'produtos', |
@@ -372,12 +372,12 @@ discard block |
||
| 372 | 372 | |
| 373 | 373 | $variacoes = $this->request->data('variacao'); |
| 374 | 374 | |
| 375 | - $image = $_FILES['imagem']; |
|
| 375 | + $image = $_FILES['imagem']; |
|
| 376 | 376 | |
| 377 | - if (!empty($image['name'])) { |
|
| 377 | + if ( ! empty($image['name'])) { |
|
| 378 | 378 | $retorno = $this->uploadImage($image); |
| 379 | 379 | |
| 380 | - if (!$retorno['status']) |
|
| 380 | + if ( ! $retorno['status']) |
|
| 381 | 381 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
| 382 | 382 | |
| 383 | 383 | $dados['imagem'] = $retorno['nome']; |
@@ -397,10 +397,10 @@ discard block |
||
| 397 | 397 | $objVariacaoController->desativar_variacoes($id); |
| 398 | 398 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
| 399 | 399 | |
| 400 | - $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
|
| 400 | + $this->Session->setFlash('Produto editado com sucesso!', 'default', 'good'); |
|
| 401 | 401 | return $this->redirect('/produto/listar_cadastros'); |
| 402 | 402 | } else { |
| 403 | - $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
|
| 403 | + $this->Session->setFlash('Ocorreu um erro ao editar o produto!', 'default', 'good'); |
|
| 404 | 404 | return $this->redirect('/produto/listar_cadastros'); |
| 405 | 405 | } |
| 406 | 406 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | ) |
| 443 | 443 | ); |
| 444 | 444 | |
| 445 | - if (!$this->validar_estoque($retorno)) { |
|
| 445 | + if ( ! $this->validar_estoque($retorno)) { |
|
| 446 | 446 | return false; |
| 447 | 447 | } |
| 448 | 448 | |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | public function validar_estoque($produto) { |
| 457 | - if (empty($produto) && !isset($produto)) { |
|
| 457 | + if (empty($produto) && ! isset($produto)) { |
|
| 458 | 458 | return false; |
| 459 | 459 | } |
| 460 | 460 | |
@@ -466,11 +466,11 @@ discard block |
||
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | public function calcular_preco_produto_venda($preco, $qnt) { |
| 469 | - if (empty($preco) || !isset($preco)) { |
|
| 469 | + if (empty($preco) || ! isset($preco)) { |
|
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - if (!is_numeric($qnt)) { |
|
| 473 | + if ( ! is_numeric($qnt)) { |
|
| 474 | 474 | return false; |
| 475 | 475 | } |
| 476 | 476 | |
@@ -481,12 +481,12 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | public function uploadImage(&$image) { |
| 483 | 483 | $type = substr($image['name'], -4); |
| 484 | - $nameImage = uniqid() . md5($image['name']) . $type; |
|
| 485 | - $dir = APP . 'webroot/uploads/produto/imagens/'; |
|
| 484 | + $nameImage = uniqid().md5($image['name']).$type; |
|
| 485 | + $dir = APP.'webroot/uploads/produto/imagens/'; |
|
| 486 | 486 | |
| 487 | - $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); |
|
| 487 | + $returnUpload = move_uploaded_file($image['tmp_name'], $dir.$nameImage); |
|
| 488 | 488 | |
| 489 | - if (!$returnUpload) |
|
| 489 | + if ( ! $returnUpload) |
|
| 490 | 490 | return array('nome' => null, 'status' => false); |
| 491 | 491 | |
| 492 | 492 | return array('nome' => $nameImage, 'status' => true); |
@@ -512,8 +512,8 @@ discard block |
||
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | public function exportar_excel_exemplo() { |
| 515 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 516 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 515 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 516 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 517 | 517 | |
| 518 | 518 | $objPHPExcel = new PHPExcel(); |
| 519 | 519 | // Definimos o estilo da fonte |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | public function importar_produtos_planilha() { |
| 553 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 553 | + if ( ! isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 554 | 554 | { |
| 555 | 555 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 556 | 556 | $this->redirect("/produto/listar_cadastros"); |
@@ -558,13 +558,13 @@ discard block |
||
| 558 | 558 | |
| 559 | 559 | $typesPermissions = ['application/vnd.ms-excel']; |
| 560 | 560 | |
| 561 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 561 | + if ( ! in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 562 | 562 | { |
| 563 | 563 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 564 | 564 | $this->redirect("/produto/listar_cadastros"); |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 567 | + $caminho = APP.'webroot/uploads/produto/planilhas/'.uniqid().'.xls'; |
|
| 568 | 568 | |
| 569 | 569 | $inputFileName = $_FILES['arquivo']['tmp_name']; |
| 570 | 570 | |
@@ -605,17 +605,17 @@ discard block |
||
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
| 608 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 609 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 608 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 609 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 610 | 610 | |
| 611 | 611 | $objPHPExcel = new PHPExcel(); |
| 612 | 612 | |
| 613 | 613 | try { |
| 614 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 615 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 616 | - $objPHPExcel = $objReader->load($inputFileName); |
|
| 617 | - } catch(Exception $e) { |
|
| 618 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 614 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 615 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 616 | + $objPHPExcel = $objReader->load($inputFileName); |
|
| 617 | + } catch (Exception $e) { |
|
| 618 | + die('Error loading file "'.pathinfo($inputFileName, PATHINFO_BASENAME).'": '.$e->getMessage()); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | $dados = []; |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | |
| 663 | 663 | $errors = $this->processar_lista_produtos($dados); |
| 664 | 664 | |
| 665 | - if (isset($errors) && !empty($errors)) |
|
| 665 | + if (isset($errors) && ! empty($errors)) |
|
| 666 | 666 | { |
| 667 | 667 | $this->QueueProduct->planilhaProcessedIncomplete($planilhaId); |
| 668 | 668 | } |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | ) |
| 689 | 689 | ); |
| 690 | 690 | |
| 691 | - if (isset($existProduto) && !empty($existProduto)) |
|
| 691 | + if (isset($existProduto) && ! empty($existProduto)) |
|
| 692 | 692 | { |
| 693 | 693 | $this->Produto->id = $existProduto[0]['Produto']['id']; |
| 694 | 694 | $this->Produto->save($dado); |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | |
| 698 | 698 | $this->Produto->create(); |
| 699 | 699 | |
| 700 | - if (!$this->Produto->save($dado)) |
|
| 700 | + if ( ! $this->Produto->save($dado)) |
|
| 701 | 701 | { |
| 702 | 702 | $errors[] = $dado; |
| 703 | 703 | } |
@@ -251,8 +251,9 @@ discard block |
||
| 251 | 251 | $html .= ''; |
| 252 | 252 | |
| 253 | 253 | foreach ($produtos as $i => $produto) { |
| 254 | - if ($i > 30) |
|
| 255 | - break; |
|
| 254 | + if ($i > 30) { |
|
| 255 | + break; |
|
| 256 | + } |
|
| 256 | 257 | |
| 257 | 258 | $html .= ' <tr>'; |
| 258 | 259 | $html .= ' <td>' . $produto['Produto']['nome'] . '</td>'; |
@@ -297,8 +298,9 @@ discard block |
||
| 297 | 298 | |
| 298 | 299 | $retorno = $this->uploadImage($image); |
| 299 | 300 | |
| 300 | - if (!$retorno['status']) |
|
| 301 | - $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 301 | + if (!$retorno['status']) { |
|
| 302 | + $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 303 | + } |
|
| 302 | 304 | |
| 303 | 305 | $dados['imagem'] = $retorno['nome']; |
| 304 | 306 | $dados['id_usuario'] = $this->instancia; |
@@ -377,8 +379,9 @@ discard block |
||
| 377 | 379 | if (!empty($image['name'])) { |
| 378 | 380 | $retorno = $this->uploadImage($image); |
| 379 | 381 | |
| 380 | - if (!$retorno['status']) |
|
| 381 | - $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 382 | + if (!$retorno['status']) { |
|
| 383 | + $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 384 | + } |
|
| 382 | 385 | |
| 383 | 386 | $dados['imagem'] = $retorno['nome']; |
| 384 | 387 | } |
@@ -486,8 +489,9 @@ discard block |
||
| 486 | 489 | |
| 487 | 490 | $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); |
| 488 | 491 | |
| 489 | - if (!$returnUpload) |
|
| 490 | - return array('nome' => null, 'status' => false); |
|
| 492 | + if (!$returnUpload) { |
|
| 493 | + return array('nome' => null, 'status' => false); |
|
| 494 | + } |
|
| 491 | 495 | |
| 492 | 496 | return array('nome' => $nameImage, 'status' => true); |
| 493 | 497 | } |
@@ -583,8 +587,7 @@ discard block |
||
| 583 | 587 | { |
| 584 | 588 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 585 | 589 | $this->redirect("/produto/listar_cadastros"); |
| 586 | - } |
|
| 587 | - else |
|
| 590 | + } else |
|
| 588 | 591 | { |
| 589 | 592 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 590 | 593 | $this->redirect("/produto/listar_cadastros"); |