@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | } |
247 | 247 | |
248 | 248 | public function getProdutosEstoqueMinimoComoHtml($produtos) { |
249 | - ob_start(); |
|
249 | + ob_start(); |
|
250 | 250 | |
251 | 251 | $html = ''; |
252 | 252 | $html .= '<html>'; |
@@ -359,11 +359,11 @@ discard block |
||
359 | 359 | |
360 | 360 | $this->Session->setFlash('Produto salvo com sucesso!'); |
361 | 361 | |
362 | - return $this->redirect('/produto/listar_cadastros'); |
|
362 | + return $this->redirect('/produto/listar_cadastros'); |
|
363 | 363 | } else { |
364 | 364 | $this->Session->setFlash('Ocorreu um erro ao salva o produto!'); |
365 | 365 | |
366 | - return $this->redirect('/produto/listar_cadastros'); |
|
366 | + return $this->redirect('/produto/listar_cadastros'); |
|
367 | 367 | } |
368 | 368 | } |
369 | 369 | |
@@ -374,17 +374,17 @@ discard block |
||
374 | 374 | |
375 | 375 | $query = array ( |
376 | 376 | 'joins' => array( |
377 | - array( |
|
378 | - 'table' => 'produtos', |
|
379 | - 'alias' => 'Produto', |
|
380 | - 'type' => 'LEFT', |
|
381 | - 'conditions' => array( |
|
382 | - 'Variacao.produto_id = Produto.id', |
|
383 | - ), |
|
384 | - ) |
|
377 | + array( |
|
378 | + 'table' => 'produtos', |
|
379 | + 'alias' => 'Produto', |
|
380 | + 'type' => 'LEFT', |
|
381 | + 'conditions' => array( |
|
382 | + 'Variacao.produto_id = Produto.id', |
|
383 | + ), |
|
384 | + ) |
|
385 | 385 | ), |
386 | - 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
387 | - 'fields' => array('Produto.id, Variacao.*'), |
|
386 | + 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
387 | + 'fields' => array('Produto.id, Variacao.*'), |
|
388 | 388 | ); |
389 | 389 | |
390 | 390 | $variacoes = $this->set('variacoes', $this->Variacao->find('all', $query)); |
@@ -442,10 +442,10 @@ discard block |
||
442 | 442 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
443 | 443 | |
444 | 444 | $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
445 | - return $this->redirect('/produto/listar_cadastros'); |
|
445 | + return $this->redirect('/produto/listar_cadastros'); |
|
446 | 446 | } else { |
447 | 447 | $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
448 | - return $this->redirect('/produto/listar_cadastros'); |
|
448 | + return $this->redirect('/produto/listar_cadastros'); |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | |
@@ -577,107 +577,107 @@ discard block |
||
577 | 577 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
578 | 578 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
579 | 579 | |
580 | - $objPHPExcel = new PHPExcel(); |
|
581 | - // Definimos o estilo da fonte |
|
582 | - $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
580 | + $objPHPExcel = new PHPExcel(); |
|
581 | + // Definimos o estilo da fonte |
|
582 | + $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
583 | 583 | |
584 | - $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
584 | + $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
585 | 585 | |
586 | - // Criamos as colunas |
|
587 | - $objPHPExcel->setActiveSheetIndex(0) |
|
588 | - ->setCellValue('A1', "Nome do Produto") |
|
589 | - ->setCellValue('B1', "Preço ") |
|
590 | - ->setCellValue("C1", "Peso Bruto") |
|
591 | - ->setCellValue("D1", "Peso Liquido") |
|
592 | - ->setCellValue("E1", "Estoque") |
|
593 | - ->setCellValue("F1", "Descrição"); |
|
586 | + // Criamos as colunas |
|
587 | + $objPHPExcel->setActiveSheetIndex(0) |
|
588 | + ->setCellValue('A1', "Nome do Produto") |
|
589 | + ->setCellValue('B1', "Preço ") |
|
590 | + ->setCellValue("C1", "Peso Bruto") |
|
591 | + ->setCellValue("D1", "Peso Liquido") |
|
592 | + ->setCellValue("E1", "Estoque") |
|
593 | + ->setCellValue("F1", "Descrição"); |
|
594 | 594 | |
595 | - // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
596 | - $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
595 | + // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
596 | + $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
597 | 597 | |
598 | - // Cabeçalho do arquivo para ele baixar |
|
599 | - header('Content-Type: application/vnd.ms-excel'); |
|
600 | - header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
601 | - header('Cache-Control: max-age=0'); |
|
602 | - // Se for o IE9, isso talvez seja necessário |
|
603 | - header('Cache-Control: max-age=1'); |
|
598 | + // Cabeçalho do arquivo para ele baixar |
|
599 | + header('Content-Type: application/vnd.ms-excel'); |
|
600 | + header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
601 | + header('Cache-Control: max-age=0'); |
|
602 | + // Se for o IE9, isso talvez seja necessário |
|
603 | + header('Cache-Control: max-age=1'); |
|
604 | 604 | |
605 | - // Acessamos o 'Writer' para poder salvar o arquivo |
|
606 | - $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
605 | + // Acessamos o 'Writer' para poder salvar o arquivo |
|
606 | + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
607 | 607 | |
608 | - // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
609 | - $objWriter->save('php://output'); |
|
608 | + // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
609 | + $objWriter->save('php://output'); |
|
610 | 610 | |
611 | - exit; |
|
612 | - } |
|
611 | + exit; |
|
612 | + } |
|
613 | 613 | |
614 | - public function importar_produtos_planilha() { |
|
615 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
616 | - { |
|
614 | + public function importar_produtos_planilha() { |
|
615 | + if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
616 | + { |
|
617 | 617 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
618 | 618 | $this->redirect("/produto/listar_cadastros"); |
619 | - } |
|
619 | + } |
|
620 | 620 | |
621 | - $typesPermissions = ['application/vnd.ms-excel']; |
|
621 | + $typesPermissions = ['application/vnd.ms-excel']; |
|
622 | 622 | |
623 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
624 | - { |
|
623 | + if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
624 | + { |
|
625 | 625 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
626 | 626 | $this->redirect("/produto/listar_cadastros"); |
627 | - } |
|
627 | + } |
|
628 | 628 | |
629 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
629 | + $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
630 | 630 | |
631 | - $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
631 | + $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
632 | 632 | |
633 | - move_uploaded_file($inputFileName, $caminho); |
|
633 | + move_uploaded_file($inputFileName, $caminho); |
|
634 | 634 | |
635 | - $data = [ |
|
636 | - 'caminho' => $caminho, |
|
637 | - 'usuario_id' => $this->instancia, |
|
638 | - 'processado' => 0, |
|
639 | - 'ativo' => 1 |
|
640 | - ]; |
|
635 | + $data = [ |
|
636 | + 'caminho' => $caminho, |
|
637 | + 'usuario_id' => $this->instancia, |
|
638 | + 'processado' => 0, |
|
639 | + 'ativo' => 1 |
|
640 | + ]; |
|
641 | 641 | |
642 | - $this->loadModel('QueueProduct'); |
|
642 | + $this->loadModel('QueueProduct'); |
|
643 | 643 | |
644 | - if ($this->QueueProduct->save($data)) |
|
645 | - { |
|
644 | + if ($this->QueueProduct->save($data)) |
|
645 | + { |
|
646 | 646 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
647 | 647 | $this->redirect("/produto/listar_cadastros"); |
648 | - } |
|
649 | - else |
|
650 | - { |
|
648 | + } |
|
649 | + else |
|
650 | + { |
|
651 | 651 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
652 | 652 | $this->redirect("/produto/listar_cadastros"); |
653 | - } |
|
654 | - } |
|
653 | + } |
|
654 | + } |
|
655 | 655 | |
656 | - public function processar_planilhas_na_fila() { |
|
657 | - $this->loadModel('QueueProduct'); |
|
656 | + public function processar_planilhas_na_fila() { |
|
657 | + $this->loadModel('QueueProduct'); |
|
658 | 658 | |
659 | - $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
659 | + $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
660 | 660 | |
661 | - $response = []; |
|
662 | - foreach ($planilhas as $planilha) { |
|
663 | - $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
664 | - } |
|
661 | + $response = []; |
|
662 | + foreach ($planilhas as $planilha) { |
|
663 | + $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
664 | + } |
|
665 | 665 | |
666 | - return $response; |
|
667 | - } |
|
666 | + return $response; |
|
667 | + } |
|
668 | 668 | |
669 | - public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
669 | + public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
670 | 670 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
671 | 671 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
672 | 672 | |
673 | - $objPHPExcel = new PHPExcel(); |
|
673 | + $objPHPExcel = new PHPExcel(); |
|
674 | 674 | |
675 | 675 | try { |
676 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
677 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
678 | - $objPHPExcel = $objReader->load($inputFileName); |
|
676 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
677 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
678 | + $objPHPExcel = $objReader->load($inputFileName); |
|
679 | 679 | } catch(Exception $e) { |
680 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
680 | + die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | $dados = []; |
@@ -733,49 +733,49 @@ discard block |
||
733 | 733 | |
734 | 734 | echo json_encode(array('sucess' => true)); |
735 | 735 | exit; |
736 | - } |
|
736 | + } |
|
737 | 737 | |
738 | - public function processar_lista_produtos($dados) { |
|
739 | - $errors = []; |
|
738 | + public function processar_lista_produtos($dados) { |
|
739 | + $errors = []; |
|
740 | 740 | |
741 | - foreach ($dados as $dado) { |
|
742 | - $this->loadModel('Produto'); |
|
741 | + foreach ($dados as $dado) { |
|
742 | + $this->loadModel('Produto'); |
|
743 | 743 | |
744 | - $existProduto = $this->Produto->find('all', |
|
745 | - array( |
|
746 | - 'conditions' => array( |
|
747 | - 'Produto.sku' => $dado['sku'], |
|
748 | - 'Produto.ativo' => 1 |
|
749 | - ) |
|
750 | - ) |
|
751 | - ); |
|
752 | - |
|
753 | - if (isset($existProduto) && !empty($existProduto)) |
|
754 | - { |
|
755 | - $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
756 | - $this->Produto->save($dado); |
|
757 | - continue; |
|
758 | - } |
|
744 | + $existProduto = $this->Produto->find('all', |
|
745 | + array( |
|
746 | + 'conditions' => array( |
|
747 | + 'Produto.sku' => $dado['sku'], |
|
748 | + 'Produto.ativo' => 1 |
|
749 | + ) |
|
750 | + ) |
|
751 | + ); |
|
752 | + |
|
753 | + if (isset($existProduto) && !empty($existProduto)) |
|
754 | + { |
|
755 | + $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
756 | + $this->Produto->save($dado); |
|
757 | + continue; |
|
758 | + } |
|
759 | 759 | |
760 | 760 | $this->Produto->create(); |
761 | 761 | |
762 | - if (!$this->Produto->save($dado)) |
|
763 | - { |
|
764 | - $errors[] = $dado; |
|
765 | - } |
|
766 | - } |
|
762 | + if (!$this->Produto->save($dado)) |
|
763 | + { |
|
764 | + $errors[] = $dado; |
|
765 | + } |
|
766 | + } |
|
767 | 767 | |
768 | - return $errors; |
|
769 | - } |
|
768 | + return $errors; |
|
769 | + } |
|
770 | 770 | |
771 | - public function salvar_imagem($id) { |
|
771 | + public function salvar_imagem($id) { |
|
772 | 772 | $image = $_FILES['arquivo']; |
773 | 773 | |
774 | 774 | $retorno = $this->uploadImage($image); |
775 | 775 | |
776 | 776 | if (!$retorno['status']) { |
777 | 777 | $this->Session->setFlash('A imagem não foi salva tente novamente ou contate o suporte!'); |
778 | - return $this->redirect('/produto/imagens/' . $id); |
|
778 | + return $this->redirect('/produto/imagens/' . $id); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | $photo = $this->request->data('photo'); |
@@ -796,22 +796,22 @@ discard block |
||
796 | 796 | |
797 | 797 | if (!$retorno) { |
798 | 798 | $this->Session->setFlash('A imagem não foi salva tente novamente ou contate o suporte!'); |
799 | - return $this->redirect('/produto/imagens/' . $id); |
|
799 | + return $this->redirect('/produto/imagens/' . $id); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | $this->Session->setFlash('A salva com sucesso!'); |
803 | - return $this->redirect('/produto/imagens/' . $id); |
|
804 | - } |
|
803 | + return $this->redirect('/produto/imagens/' . $id); |
|
804 | + } |
|
805 | 805 | |
806 | - public function imagem_excluir_cadastro($id) { |
|
807 | - $this->loadModel('Imagen'); |
|
806 | + public function imagem_excluir_cadastro($id) { |
|
807 | + $this->loadModel('Imagen'); |
|
808 | 808 | |
809 | - $this->Imagen->id = $id; |
|
809 | + $this->Imagen->id = $id; |
|
810 | 810 | |
811 | - $this->Imagen->save(['ativo' => 0]); |
|
811 | + $this->Imagen->save(['ativo' => 0]); |
|
812 | 812 | |
813 | - echo json_encode(array('success' => true)); |
|
814 | - exit; |
|
815 | - } |
|
813 | + echo json_encode(array('success' => true)); |
|
814 | + exit; |
|
815 | + } |
|
816 | 816 | |
817 | 817 | } |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(ROOT . DS . 'vendor' . DS . 'autoload.php'); |
|
3 | +require_once(ROOT.DS.'vendor'.DS.'autoload.php'); |
|
4 | 4 | |
5 | 5 | use Dompdf\Dompdf; |
6 | 6 | |
7 | -class ProdutoController extends AppController{ |
|
7 | +class ProdutoController extends AppController { |
|
8 | 8 | |
9 | 9 | public function listar_cadastros() { |
10 | 10 | $this->layout = 'wadmin'; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | public function listar_cadastros_ajax() { |
14 | 14 | $this->layout = 'ajax'; |
15 | 15 | |
16 | - $aColumns = array( 'sku', 'imagem', 'nome', 'preco', 'estoque' ); |
|
16 | + $aColumns = array('sku', 'imagem', 'nome', 'preco', 'estoque'); |
|
17 | 17 | |
18 | 18 | $conditions = array('conditions' => |
19 | 19 | array( |
@@ -24,26 +24,26 @@ discard block |
||
24 | 24 | |
25 | 25 | $allProdutos = $this->Produto->find('all', $conditions); |
26 | 26 | |
27 | - if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) |
|
27 | + if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') |
|
28 | 28 | { |
29 | 29 | $conditions['offset'] = $_GET['iDisplayStart']; |
30 | 30 | $conditions['limit'] = $_GET['iDisplayLength']; |
31 | 31 | } |
32 | 32 | |
33 | - if ( isset( $_GET['iSortCol_0'] ) ) |
|
33 | + if (isset($_GET['iSortCol_0'])) |
|
34 | 34 | { |
35 | - for ( $i=0 ; $i < intval( $_GET['iSortingCols'] ) ; $i++ ) |
|
35 | + for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) |
|
36 | 36 | { |
37 | - if ( $_GET[ 'bSortable_' . intval($_GET['iSortCol_' . $i]) ] == "true" ) |
|
37 | + if ($_GET['bSortable_'.intval($_GET['iSortCol_'.$i])] == "true") |
|
38 | 38 | { |
39 | - $conditions['order'] = array('Produto.' . $aColumns[intval($_GET['iSortCol_' . $i])] => $_GET['sSortDir_'.$i]); |
|
39 | + $conditions['order'] = array('Produto.'.$aColumns[intval($_GET['iSortCol_'.$i])] => $_GET['sSortDir_'.$i]); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - if ( isset( $_GET['sSearch'] ) && !empty( $_GET['sSearch'] ) ) |
|
44 | + if (isset($_GET['sSearch']) && ! empty($_GET['sSearch'])) |
|
45 | 45 | { |
46 | - $conditions['conditions']['Produto.nome LIKE '] = '%' . $_GET['sSearch'] . '%'; |
|
46 | + $conditions['conditions']['Produto.nome LIKE '] = '%'.$_GET['sSearch'].'%'; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | $produtos = $this->Produto->find('all', $conditions); |
@@ -55,19 +55,19 @@ discard block |
||
55 | 55 | "aaData" => array() |
56 | 56 | ); |
57 | 57 | |
58 | - foreach ( $produtos as $i => $produto ) |
|
58 | + foreach ($produtos as $i => $produto) |
|
59 | 59 | { |
60 | 60 | $row = array(); |
61 | 61 | |
62 | - for ( $i=0 ; $i < count($aColumns) ; $i++ ) |
|
62 | + for ($i = 0; $i < count($aColumns); $i++) |
|
63 | 63 | { |
64 | 64 | $value = $produto['Produto'][$aColumns[$i]]; |
65 | 65 | |
66 | 66 | if ($aColumns[$i] == "imagem") |
67 | 67 | { |
68 | - $value = '<img src="/uploads/produto/imagens/' . $produto['Produto'][$aColumns[$i]] . '" width="120" height="120">'; |
|
68 | + $value = '<img src="/uploads/produto/imagens/'.$produto['Produto'][$aColumns[$i]].'" width="120" height="120">'; |
|
69 | 69 | |
70 | - if (!isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
70 | + if ( ! isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
71 | 71 | { |
72 | 72 | $value = '<img src="/images/no_image.png" width="120" height="120">'; |
73 | 73 | } |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | $row[] = $value; |
77 | 77 | } |
78 | 78 | |
79 | - $btEdit = '<a class="btn btn-info" href="/produto/editar_cadastro/' . $produto['Produto']['id'] . '"><i class="fa fa-pencil"></i></a>'; |
|
79 | + $btEdit = '<a class="btn btn-info" href="/produto/editar_cadastro/'.$produto['Produto']['id'].'"><i class="fa fa-pencil"></i></a>'; |
|
80 | 80 | |
81 | - $btImage = ' <a class="btn btn-primary" href="/produto/imagens/' . $produto['Produto']['id'] . '"><i class="fa fa-picture-o"></i></a>'; |
|
81 | + $btImage = ' <a class="btn btn-primary" href="/produto/imagens/'.$produto['Produto']['id'].'"><i class="fa fa-picture-o"></i></a>'; |
|
82 | 82 | |
83 | - $row[] = $btEdit . $btImage; |
|
83 | + $row[] = $btEdit.$btImage; |
|
84 | 84 | |
85 | 85 | $output['aaData'][] = $row; |
86 | 86 | } |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | $this->set('produto', $produto); |
114 | 114 | } |
115 | 115 | |
116 | - public function listar_cadastros_estoque_minimo(){ |
|
116 | + public function listar_cadastros_estoque_minimo() { |
|
117 | 117 | $this->layout = 'wadmin'; |
118 | 118 | } |
119 | 119 | |
120 | - public function listar_cadastros_estoque_minimo_ajax(){ |
|
120 | + public function listar_cadastros_estoque_minimo_ajax() { |
|
121 | 121 | |
122 | 122 | $this->layout = 'ajax'; |
123 | 123 | |
124 | - $aColumns = array( 'sku', 'imagem', 'nome', 'preco', 'estoque' ); |
|
124 | + $aColumns = array('sku', 'imagem', 'nome', 'preco', 'estoque'); |
|
125 | 125 | |
126 | 126 | $this->loadModel('Usuario'); |
127 | 127 | |
@@ -143,30 +143,30 @@ discard block |
||
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | |
146 | - $allProdutos = $this->Produto->query("select * from produtos where estoque < quantidade_minima and id_usuario = " . $this->instancia . " and ativo = 1"); |
|
146 | + $allProdutos = $this->Produto->query("select * from produtos where estoque < quantidade_minima and id_usuario = ".$this->instancia." and ativo = 1"); |
|
147 | 147 | |
148 | 148 | |
149 | - $sql = "select * from produtos as Produto where estoque < quantidade_minima and id_usuario = " . $this->instancia . " and ativo = 1"; |
|
149 | + $sql = "select * from produtos as Produto where estoque < quantidade_minima and id_usuario = ".$this->instancia." and ativo = 1"; |
|
150 | 150 | |
151 | - if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) |
|
151 | + if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') |
|
152 | 152 | { |
153 | - $sql .= ' LIMIT ' . $_GET['iDisplayLength'] . ' OFFSET ' . $_GET['iDisplayStart']; |
|
153 | + $sql .= ' LIMIT '.$_GET['iDisplayLength'].' OFFSET '.$_GET['iDisplayStart']; |
|
154 | 154 | } |
155 | 155 | |
156 | - if ( isset( $_GET['iSortCol_0'] ) ) |
|
156 | + if (isset($_GET['iSortCol_0'])) |
|
157 | 157 | { |
158 | - for ( $i=0 ; $i < intval( $_GET['iSortingCols'] ) ; $i++ ) |
|
158 | + for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) |
|
159 | 159 | { |
160 | - if ( $_GET[ 'bSortable_' . intval($_GET['iSortCol_' . $i]) ] == "true" ) |
|
160 | + if ($_GET['bSortable_'.intval($_GET['iSortCol_'.$i])] == "true") |
|
161 | 161 | { |
162 | - $conditions['order'] = array('Produto.' . $aColumns[intval($_GET['iSortCol_' . $i])] => $_GET['sSortDir_'.$i]); |
|
162 | + $conditions['order'] = array('Produto.'.$aColumns[intval($_GET['iSortCol_'.$i])] => $_GET['sSortDir_'.$i]); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | - if ( isset( $_GET['sSearch'] ) && !empty( $_GET['sSearch'] ) ) |
|
167 | + if (isset($_GET['sSearch']) && ! empty($_GET['sSearch'])) |
|
168 | 168 | { |
169 | - $conditions['conditions']['Produto.nome LIKE '] = '%' . $_GET['sSearch'] . '%'; |
|
169 | + $conditions['conditions']['Produto.nome LIKE '] = '%'.$_GET['sSearch'].'%'; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | $produtos = $this->Produto->query($sql); |
@@ -178,19 +178,19 @@ discard block |
||
178 | 178 | "aaData" => array() |
179 | 179 | ); |
180 | 180 | |
181 | - foreach ( $produtos as $i => $produto ) |
|
181 | + foreach ($produtos as $i => $produto) |
|
182 | 182 | { |
183 | 183 | $row = array(); |
184 | 184 | |
185 | - for ( $i=0 ; $i < count($aColumns) ; $i++ ) |
|
185 | + for ($i = 0; $i < count($aColumns); $i++) |
|
186 | 186 | { |
187 | 187 | $value = $produto['Produto'][$aColumns[$i]]; |
188 | 188 | |
189 | 189 | if ($aColumns[$i] == "imagem") |
190 | 190 | { |
191 | - $value = '<img src="/uploads/produto/imagens/' . $produto['Produto'][$aColumns[$i]] . '" width="120" height="120">'; |
|
191 | + $value = '<img src="/uploads/produto/imagens/'.$produto['Produto'][$aColumns[$i]].'" width="120" height="120">'; |
|
192 | 192 | |
193 | - if (!isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
193 | + if ( ! isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
194 | 194 | { |
195 | 195 | $value = '<img src="/images/no_image.png" width="120" height="120">'; |
196 | 196 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | ) |
231 | 231 | ); |
232 | 232 | |
233 | - $produtos = $this->Produto->query("select * from produtos as Produto where estoque < quantidade_minima and id_usuario = " . $this->instancia . " and ativo = 1"); |
|
233 | + $produtos = $this->Produto->query("select * from produtos as Produto where estoque < quantidade_minima and id_usuario = ".$this->instancia." and ativo = 1"); |
|
234 | 234 | |
235 | 235 | $html = $this->getProdutosEstoqueMinimoComoHtml($produtos); |
236 | 236 | |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | |
286 | 286 | foreach ($produtos as $i => $produto) { |
287 | 287 | $html .= ' <tr>'; |
288 | - $html .= ' <td>' . $produto['Produto']['nome'] . '</td>'; |
|
289 | - $html .= ' <td>' . $produto['Produto']['estoque'] . '</td>'; |
|
290 | - $html .= ' <td>R$ ' . number_format($produto['Produto']['custo'], 2, ',', '.') . '</td>'; |
|
288 | + $html .= ' <td>'.$produto['Produto']['nome'].'</td>'; |
|
289 | + $html .= ' <td>'.$produto['Produto']['estoque'].'</td>'; |
|
290 | + $html .= ' <td>R$ '.number_format($produto['Produto']['custo'], 2, ',', '.').'</td>'; |
|
291 | 291 | $html .= ' </tr>'; |
292 | 292 | } |
293 | 293 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $html .= ''; |
300 | 300 | $html .= '</body>'; |
301 | 301 | $html .= '</html>'; |
302 | - echo $html;exit; |
|
302 | + echo $html; exit; |
|
303 | 303 | return $html; |
304 | 304 | } |
305 | 305 | |
@@ -319,15 +319,15 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | public function s_adicionar_cadastro() { |
322 | - $dados = $this->request->data('dados'); |
|
322 | + $dados = $this->request->data('dados'); |
|
323 | 323 | |
324 | 324 | $variacoes = $this->request->data('variacao'); |
325 | 325 | |
326 | - $image = $_FILES['imagem']; |
|
326 | + $image = $_FILES['imagem']; |
|
327 | 327 | |
328 | 328 | $retorno = $this->uploadImage($image); |
329 | 329 | |
330 | - if (!$retorno['status']) |
|
330 | + if ( ! $retorno['status']) |
|
331 | 331 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
332 | 332 | |
333 | 333 | $dados['imagem'] = $retorno['nome']; |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $dados['id_alias'] = $this->id_alias(); |
337 | 337 | $dados['preco'] = str_replace(',', '', $dados['preco']); |
338 | 338 | |
339 | - if($this->Produto->save($dados)) { |
|
339 | + if ($this->Produto->save($dados)) { |
|
340 | 340 | $produto_id = $this->Produto->getLastInsertId(); |
341 | 341 | |
342 | 342 | require 'VariacaoController.php'; |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $objPluggTo = new PluggtoController(); |
352 | 352 | $produto_pluggto = $objPluggTo->enviar_produto($dados, $variacoes); |
353 | 353 | |
354 | - if (!isset($produto_pluggto->Product->id)) |
|
354 | + if ( ! isset($produto_pluggto->Product->id)) |
|
355 | 355 | { |
356 | 356 | $this->Session->setFlash('Produto não foi enviado para o Plugg.to!'); |
357 | 357 | } |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | |
373 | 373 | $this->loadModel('Variacao'); |
374 | 374 | |
375 | - $query = array ( |
|
375 | + $query = array( |
|
376 | 376 | 'joins' => array( |
377 | 377 | array( |
378 | 378 | 'table' => 'produtos', |
@@ -415,12 +415,12 @@ discard block |
||
415 | 415 | |
416 | 416 | $variacoes = $this->request->data('variacao'); |
417 | 417 | |
418 | - $image = $_FILES['imagem']; |
|
418 | + $image = $_FILES['imagem']; |
|
419 | 419 | |
420 | - if (!empty($image['name'])) { |
|
420 | + if ( ! empty($image['name'])) { |
|
421 | 421 | $retorno = $this->uploadImage($image); |
422 | 422 | |
423 | - if (!$retorno['status']) |
|
423 | + if ( ! $retorno['status']) |
|
424 | 424 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
425 | 425 | |
426 | 426 | $dados['imagem'] = $retorno['nome']; |
@@ -441,10 +441,10 @@ discard block |
||
441 | 441 | $objVariacaoController->desativar_variacoes($id); |
442 | 442 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
443 | 443 | |
444 | - $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
|
444 | + $this->Session->setFlash('Produto editado com sucesso!', 'default', 'good'); |
|
445 | 445 | return $this->redirect('/produto/listar_cadastros'); |
446 | 446 | } else { |
447 | - $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
|
447 | + $this->Session->setFlash('Ocorreu um erro ao editar o produto!', 'default', 'good'); |
|
448 | 448 | return $this->redirect('/produto/listar_cadastros'); |
449 | 449 | } |
450 | 450 | } |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | ) |
487 | 487 | ); |
488 | 488 | |
489 | - if (!$this->validar_estoque($retorno)) { |
|
489 | + if ( ! $this->validar_estoque($retorno)) { |
|
490 | 490 | return false; |
491 | 491 | } |
492 | 492 | |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | if ($user_active[0]['Usuario']['sale_without_stock']) |
517 | 517 | return true; |
518 | 518 | |
519 | - if (empty($produto) && !isset($produto)) { |
|
519 | + if (empty($produto) && ! isset($produto)) { |
|
520 | 520 | return false; |
521 | 521 | } |
522 | 522 | |
@@ -528,11 +528,11 @@ discard block |
||
528 | 528 | } |
529 | 529 | |
530 | 530 | public function calcular_preco_produto_venda($preco, $qnt) { |
531 | - if (empty($preco) || !isset($preco)) { |
|
531 | + if (empty($preco) || ! isset($preco)) { |
|
532 | 532 | return false; |
533 | 533 | } |
534 | 534 | |
535 | - if (!is_numeric($qnt)) { |
|
535 | + if ( ! is_numeric($qnt)) { |
|
536 | 536 | return false; |
537 | 537 | } |
538 | 538 | |
@@ -543,12 +543,12 @@ discard block |
||
543 | 543 | |
544 | 544 | public function uploadImage(&$image) { |
545 | 545 | $type = substr($image['name'], -4); |
546 | - $nameImage = uniqid() . md5($image['name']) . $type; |
|
547 | - $dir = APP . 'webroot/uploads/produto/imagens/'; |
|
546 | + $nameImage = uniqid().md5($image['name']).$type; |
|
547 | + $dir = APP.'webroot/uploads/produto/imagens/'; |
|
548 | 548 | |
549 | - $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); |
|
549 | + $returnUpload = move_uploaded_file($image['tmp_name'], $dir.$nameImage); |
|
550 | 550 | |
551 | - if (!$returnUpload) |
|
551 | + if ( ! $returnUpload) |
|
552 | 552 | return array('nome' => null, 'status' => false); |
553 | 553 | |
554 | 554 | return array('nome' => $nameImage, 'status' => true); |
@@ -574,8 +574,8 @@ discard block |
||
574 | 574 | } |
575 | 575 | |
576 | 576 | public function exportar_excel_exemplo() { |
577 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
578 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
577 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
578 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
579 | 579 | |
580 | 580 | $objPHPExcel = new PHPExcel(); |
581 | 581 | // Definimos o estilo da fonte |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | } |
613 | 613 | |
614 | 614 | public function importar_produtos_planilha() { |
615 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
615 | + if ( ! isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
616 | 616 | { |
617 | 617 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
618 | 618 | $this->redirect("/produto/listar_cadastros"); |
@@ -620,13 +620,13 @@ discard block |
||
620 | 620 | |
621 | 621 | $typesPermissions = ['application/vnd.ms-excel']; |
622 | 622 | |
623 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
623 | + if ( ! in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
624 | 624 | { |
625 | 625 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
626 | 626 | $this->redirect("/produto/listar_cadastros"); |
627 | 627 | } |
628 | 628 | |
629 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
629 | + $caminho = APP.'webroot/uploads/produto/planilhas/'.uniqid().'.xls'; |
|
630 | 630 | |
631 | 631 | $inputFileName = $_FILES['arquivo']['tmp_name']; |
632 | 632 | |
@@ -667,17 +667,17 @@ discard block |
||
667 | 667 | } |
668 | 668 | |
669 | 669 | public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
670 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
671 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
670 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
671 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
672 | 672 | |
673 | 673 | $objPHPExcel = new PHPExcel(); |
674 | 674 | |
675 | 675 | try { |
676 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
677 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
678 | - $objPHPExcel = $objReader->load($inputFileName); |
|
679 | - } catch(Exception $e) { |
|
680 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
676 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
677 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
678 | + $objPHPExcel = $objReader->load($inputFileName); |
|
679 | + } catch (Exception $e) { |
|
680 | + die('Error loading file "'.pathinfo($inputFileName, PATHINFO_BASENAME).'": '.$e->getMessage()); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | $dados = []; |
@@ -724,7 +724,7 @@ discard block |
||
724 | 724 | |
725 | 725 | $errors = $this->processar_lista_produtos($dados); |
726 | 726 | |
727 | - if (isset($errors) && !empty($errors)) |
|
727 | + if (isset($errors) && ! empty($errors)) |
|
728 | 728 | { |
729 | 729 | $this->QueueProduct->planilhaProcessedIncomplete($planilhaId); |
730 | 730 | } |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | ) |
751 | 751 | ); |
752 | 752 | |
753 | - if (isset($existProduto) && !empty($existProduto)) |
|
753 | + if (isset($existProduto) && ! empty($existProduto)) |
|
754 | 754 | { |
755 | 755 | $this->Produto->id = $existProduto[0]['Produto']['id']; |
756 | 756 | $this->Produto->save($dado); |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | |
760 | 760 | $this->Produto->create(); |
761 | 761 | |
762 | - if (!$this->Produto->save($dado)) |
|
762 | + if ( ! $this->Produto->save($dado)) |
|
763 | 763 | { |
764 | 764 | $errors[] = $dado; |
765 | 765 | } |
@@ -769,13 +769,13 @@ discard block |
||
769 | 769 | } |
770 | 770 | |
771 | 771 | public function salvar_imagem($id) { |
772 | - $image = $_FILES['arquivo']; |
|
772 | + $image = $_FILES['arquivo']; |
|
773 | 773 | |
774 | 774 | $retorno = $this->uploadImage($image); |
775 | 775 | |
776 | - if (!$retorno['status']) { |
|
776 | + if ( ! $retorno['status']) { |
|
777 | 777 | $this->Session->setFlash('A imagem não foi salva tente novamente ou contate o suporte!'); |
778 | - return $this->redirect('/produto/imagens/' . $id); |
|
778 | + return $this->redirect('/produto/imagens/'.$id); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | $photo = $this->request->data('photo'); |
@@ -794,13 +794,13 @@ discard block |
||
794 | 794 | |
795 | 795 | $retorno = $this->Imagen->save($data); |
796 | 796 | |
797 | - if (!$retorno) { |
|
797 | + if ( ! $retorno) { |
|
798 | 798 | $this->Session->setFlash('A imagem não foi salva tente novamente ou contate o suporte!'); |
799 | - return $this->redirect('/produto/imagens/' . $id); |
|
799 | + return $this->redirect('/produto/imagens/'.$id); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | $this->Session->setFlash('A salva com sucesso!'); |
803 | - return $this->redirect('/produto/imagens/' . $id); |
|
803 | + return $this->redirect('/produto/imagens/'.$id); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | public function imagem_excluir_cadastro($id) { |
@@ -3,14 +3,14 @@ |
||
3 | 3 | class Imagen extends Model { |
4 | 4 | |
5 | 5 | public $belongsTo = array( |
6 | - 'Usuario' => array( |
|
7 | - 'className' => 'Usuario' , |
|
8 | - 'foreignKey' => 'usuario_id' |
|
9 | - ), |
|
10 | - 'Produto' => array( |
|
11 | - 'className' => 'Produto' , |
|
12 | - 'foreignKey' => 'produto_id' |
|
13 | - ) |
|
14 | - ); |
|
6 | + 'Usuario' => array( |
|
7 | + 'className' => 'Usuario' , |
|
8 | + 'foreignKey' => 'usuario_id' |
|
9 | + ), |
|
10 | + 'Produto' => array( |
|
11 | + 'className' => 'Produto' , |
|
12 | + 'foreignKey' => 'produto_id' |
|
13 | + ) |
|
14 | + ); |
|
15 | 15 | |
16 | 16 | } |
17 | 17 | \ No newline at end of file |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | public $belongsTo = array( |
6 | 6 | 'Usuario' => array( |
7 | - 'className' => 'Usuario' , |
|
7 | + 'className' => 'Usuario', |
|
8 | 8 | 'foreignKey' => 'usuario_id' |
9 | 9 | ), |
10 | 10 | 'Produto' => array( |
11 | - 'className' => 'Produto' , |
|
11 | + 'className' => 'Produto', |
|
12 | 12 | 'foreignKey' => 'produto_id' |
13 | 13 | ) |
14 | 14 | ); |