@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | public function getProdutosEstoqueMinimoComoHtml($produtos) { |
| 256 | - ob_start(); |
|
| 256 | + ob_start(); |
|
| 257 | 257 | |
| 258 | 258 | $html = ''; |
| 259 | 259 | $html .= '<html>'; |
@@ -366,11 +366,11 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | $this->Session->setFlash('Produto salvo com sucesso!'); |
| 368 | 368 | |
| 369 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 369 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 370 | 370 | } else { |
| 371 | 371 | $this->Session->setFlash('Ocorreu um erro ao salva o produto!'); |
| 372 | 372 | |
| 373 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 373 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
@@ -381,17 +381,17 @@ discard block |
||
| 381 | 381 | |
| 382 | 382 | $query = array ( |
| 383 | 383 | 'joins' => array( |
| 384 | - array( |
|
| 385 | - 'table' => 'produtos', |
|
| 386 | - 'alias' => 'Produto', |
|
| 387 | - 'type' => 'LEFT', |
|
| 388 | - 'conditions' => array( |
|
| 389 | - 'Variacao.produto_id = Produto.id', |
|
| 390 | - ), |
|
| 391 | - ) |
|
| 384 | + array( |
|
| 385 | + 'table' => 'produtos', |
|
| 386 | + 'alias' => 'Produto', |
|
| 387 | + 'type' => 'LEFT', |
|
| 388 | + 'conditions' => array( |
|
| 389 | + 'Variacao.produto_id = Produto.id', |
|
| 390 | + ), |
|
| 391 | + ) |
|
| 392 | 392 | ), |
| 393 | - 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 394 | - 'fields' => array('Produto.id, Variacao.*'), |
|
| 393 | + 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 394 | + 'fields' => array('Produto.id, Variacao.*'), |
|
| 395 | 395 | ); |
| 396 | 396 | |
| 397 | 397 | $variacoes = $this->set('variacoes', $this->Variacao->find('all', $query)); |
@@ -449,10 +449,10 @@ discard block |
||
| 449 | 449 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
| 450 | 450 | |
| 451 | 451 | $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
| 452 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 452 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 453 | 453 | } else { |
| 454 | 454 | $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
| 455 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 455 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
@@ -584,107 +584,107 @@ discard block |
||
| 584 | 584 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 585 | 585 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 586 | 586 | |
| 587 | - $objPHPExcel = new PHPExcel(); |
|
| 588 | - // Definimos o estilo da fonte |
|
| 589 | - $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
| 587 | + $objPHPExcel = new PHPExcel(); |
|
| 588 | + // Definimos o estilo da fonte |
|
| 589 | + $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
| 590 | 590 | |
| 591 | - $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
| 591 | + $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
| 592 | 592 | |
| 593 | - // Criamos as colunas |
|
| 594 | - $objPHPExcel->setActiveSheetIndex(0) |
|
| 595 | - ->setCellValue('A1', "Nome do Produto") |
|
| 596 | - ->setCellValue('B1', "Preço ") |
|
| 597 | - ->setCellValue("C1", "Peso Bruto") |
|
| 598 | - ->setCellValue("D1", "Peso Liquido") |
|
| 599 | - ->setCellValue("E1", "Estoque") |
|
| 600 | - ->setCellValue("F1", "Descrição"); |
|
| 593 | + // Criamos as colunas |
|
| 594 | + $objPHPExcel->setActiveSheetIndex(0) |
|
| 595 | + ->setCellValue('A1', "Nome do Produto") |
|
| 596 | + ->setCellValue('B1', "Preço ") |
|
| 597 | + ->setCellValue("C1", "Peso Bruto") |
|
| 598 | + ->setCellValue("D1", "Peso Liquido") |
|
| 599 | + ->setCellValue("E1", "Estoque") |
|
| 600 | + ->setCellValue("F1", "Descrição"); |
|
| 601 | 601 | |
| 602 | - // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
| 603 | - $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
| 602 | + // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
| 603 | + $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
| 604 | 604 | |
| 605 | - // Cabeçalho do arquivo para ele baixar |
|
| 606 | - header('Content-Type: application/vnd.ms-excel'); |
|
| 607 | - header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
| 608 | - header('Cache-Control: max-age=0'); |
|
| 609 | - // Se for o IE9, isso talvez seja necessário |
|
| 610 | - header('Cache-Control: max-age=1'); |
|
| 605 | + // Cabeçalho do arquivo para ele baixar |
|
| 606 | + header('Content-Type: application/vnd.ms-excel'); |
|
| 607 | + header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
| 608 | + header('Cache-Control: max-age=0'); |
|
| 609 | + // Se for o IE9, isso talvez seja necessário |
|
| 610 | + header('Cache-Control: max-age=1'); |
|
| 611 | 611 | |
| 612 | - // Acessamos o 'Writer' para poder salvar o arquivo |
|
| 613 | - $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
| 612 | + // Acessamos o 'Writer' para poder salvar o arquivo |
|
| 613 | + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
| 614 | 614 | |
| 615 | - // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
| 616 | - $objWriter->save('php://output'); |
|
| 615 | + // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
| 616 | + $objWriter->save('php://output'); |
|
| 617 | 617 | |
| 618 | - exit; |
|
| 619 | - } |
|
| 618 | + exit; |
|
| 619 | + } |
|
| 620 | 620 | |
| 621 | - public function importar_produtos_planilha() { |
|
| 622 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 623 | - { |
|
| 621 | + public function importar_produtos_planilha() { |
|
| 622 | + if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 623 | + { |
|
| 624 | 624 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 625 | 625 | $this->redirect("/produto/listar_cadastros"); |
| 626 | - } |
|
| 626 | + } |
|
| 627 | 627 | |
| 628 | - $typesPermissions = ['application/vnd.ms-excel']; |
|
| 628 | + $typesPermissions = ['application/vnd.ms-excel']; |
|
| 629 | 629 | |
| 630 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 631 | - { |
|
| 630 | + if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 631 | + { |
|
| 632 | 632 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 633 | 633 | $this->redirect("/produto/listar_cadastros"); |
| 634 | - } |
|
| 634 | + } |
|
| 635 | 635 | |
| 636 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 636 | + $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 637 | 637 | |
| 638 | - $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 638 | + $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 639 | 639 | |
| 640 | - move_uploaded_file($inputFileName, $caminho); |
|
| 640 | + move_uploaded_file($inputFileName, $caminho); |
|
| 641 | 641 | |
| 642 | - $data = [ |
|
| 643 | - 'caminho' => $caminho, |
|
| 644 | - 'usuario_id' => $this->instancia, |
|
| 645 | - 'processado' => 0, |
|
| 646 | - 'ativo' => 1 |
|
| 647 | - ]; |
|
| 642 | + $data = [ |
|
| 643 | + 'caminho' => $caminho, |
|
| 644 | + 'usuario_id' => $this->instancia, |
|
| 645 | + 'processado' => 0, |
|
| 646 | + 'ativo' => 1 |
|
| 647 | + ]; |
|
| 648 | 648 | |
| 649 | - $this->loadModel('QueueProduct'); |
|
| 649 | + $this->loadModel('QueueProduct'); |
|
| 650 | 650 | |
| 651 | - if ($this->QueueProduct->save($data)) |
|
| 652 | - { |
|
| 651 | + if ($this->QueueProduct->save($data)) |
|
| 652 | + { |
|
| 653 | 653 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 654 | 654 | $this->redirect("/produto/listar_cadastros"); |
| 655 | - } |
|
| 656 | - else |
|
| 657 | - { |
|
| 655 | + } |
|
| 656 | + else |
|
| 657 | + { |
|
| 658 | 658 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 659 | 659 | $this->redirect("/produto/listar_cadastros"); |
| 660 | - } |
|
| 661 | - } |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | 662 | |
| 663 | - public function processar_planilhas_na_fila() { |
|
| 664 | - $this->loadModel('QueueProduct'); |
|
| 663 | + public function processar_planilhas_na_fila() { |
|
| 664 | + $this->loadModel('QueueProduct'); |
|
| 665 | 665 | |
| 666 | - $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
| 666 | + $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
| 667 | 667 | |
| 668 | - $response = []; |
|
| 669 | - foreach ($planilhas as $planilha) { |
|
| 670 | - $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
| 671 | - } |
|
| 668 | + $response = []; |
|
| 669 | + foreach ($planilhas as $planilha) { |
|
| 670 | + $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | - return $response; |
|
| 674 | - } |
|
| 673 | + return $response; |
|
| 674 | + } |
|
| 675 | 675 | |
| 676 | - public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
| 676 | + public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
| 677 | 677 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 678 | 678 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 679 | 679 | |
| 680 | - $objPHPExcel = new PHPExcel(); |
|
| 680 | + $objPHPExcel = new PHPExcel(); |
|
| 681 | 681 | |
| 682 | 682 | try { |
| 683 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 684 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 685 | - $objPHPExcel = $objReader->load($inputFileName); |
|
| 683 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 684 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 685 | + $objPHPExcel = $objReader->load($inputFileName); |
|
| 686 | 686 | } catch(Exception $e) { |
| 687 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 687 | + die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | $dados = []; |
@@ -740,46 +740,46 @@ discard block |
||
| 740 | 740 | |
| 741 | 741 | echo json_encode(array('sucess' => true)); |
| 742 | 742 | exit; |
| 743 | - } |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - public function processar_lista_produtos($dados) { |
|
| 746 | - $errors = []; |
|
| 745 | + public function processar_lista_produtos($dados) { |
|
| 746 | + $errors = []; |
|
| 747 | 747 | |
| 748 | - foreach ($dados as $dado) { |
|
| 749 | - $this->loadModel('Produto'); |
|
| 748 | + foreach ($dados as $dado) { |
|
| 749 | + $this->loadModel('Produto'); |
|
| 750 | 750 | |
| 751 | - $existProduto = $this->Produto->find('all', |
|
| 752 | - array( |
|
| 753 | - 'conditions' => array( |
|
| 754 | - 'Produto.sku' => $dado['sku'], |
|
| 755 | - 'Produto.ativo' => 1 |
|
| 756 | - ) |
|
| 757 | - ) |
|
| 758 | - ); |
|
| 759 | - |
|
| 760 | - if (isset($existProduto) && !empty($existProduto)) |
|
| 761 | - { |
|
| 762 | - $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
| 763 | - $this->Produto->save($dado); |
|
| 764 | - continue; |
|
| 765 | - } |
|
| 751 | + $existProduto = $this->Produto->find('all', |
|
| 752 | + array( |
|
| 753 | + 'conditions' => array( |
|
| 754 | + 'Produto.sku' => $dado['sku'], |
|
| 755 | + 'Produto.ativo' => 1 |
|
| 756 | + ) |
|
| 757 | + ) |
|
| 758 | + ); |
|
| 759 | + |
|
| 760 | + if (isset($existProduto) && !empty($existProduto)) |
|
| 761 | + { |
|
| 762 | + $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
| 763 | + $this->Produto->save($dado); |
|
| 764 | + continue; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | 767 | $this->Produto->create(); |
| 768 | 768 | |
| 769 | - if (!$this->Produto->save($dado)) |
|
| 770 | - { |
|
| 771 | - $errors[] = $dado; |
|
| 772 | - } |
|
| 773 | - } |
|
| 769 | + if (!$this->Produto->save($dado)) |
|
| 770 | + { |
|
| 771 | + $errors[] = $dado; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | 774 | |
| 775 | - return $errors; |
|
| 776 | - } |
|
| 775 | + return $errors; |
|
| 776 | + } |
|
| 777 | 777 | |
| 778 | - public function movimentacoes_estoque($produtoId) { |
|
| 779 | - $this->layout = 'wadmin'; |
|
| 778 | + public function movimentacoes_estoque($produtoId) { |
|
| 779 | + $this->layout = 'wadmin'; |
|
| 780 | 780 | |
| 781 | - $this->set('id', $produtoId); |
|
| 782 | - } |
|
| 781 | + $this->set('id', $produtoId); |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | 784 | public function listar_cadastros_estoque_ajax($produtoId) { |
| 785 | 785 | $this->loadModel('VendaItensProduto'); |
@@ -794,16 +794,16 @@ discard block |
||
| 794 | 794 | 'VendaItensProduto.produto_id' => $produtoId |
| 795 | 795 | ), |
| 796 | 796 | 'joins' => array( |
| 797 | - array( |
|
| 798 | - 'table' => 'produtos', |
|
| 799 | - 'alias' => 'Produto', |
|
| 800 | - 'type' => 'LEFT', |
|
| 801 | - 'conditions' => array( |
|
| 802 | - 'VendaItensProduto.produto_id = Produto.id', |
|
| 803 | - ), |
|
| 804 | - ) |
|
| 797 | + array( |
|
| 798 | + 'table' => 'produtos', |
|
| 799 | + 'alias' => 'Produto', |
|
| 800 | + 'type' => 'LEFT', |
|
| 801 | + 'conditions' => array( |
|
| 802 | + 'VendaItensProduto.produto_id = Produto.id', |
|
| 803 | + ), |
|
| 804 | + ) |
|
| 805 | 805 | ), |
| 806 | - 'fields' => array('VendaItensProduto.*, Produto.*'), |
|
| 806 | + 'fields' => array('VendaItensProduto.*, Produto.*'), |
|
| 807 | 807 | ); |
| 808 | 808 | |
| 809 | 809 | $allProdutos = $this->VendaItensProduto->find('all', $conditions); |
@@ -863,14 +863,14 @@ discard block |
||
| 863 | 863 | exit; |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - public function salvar_imagem($id) { |
|
| 866 | + public function salvar_imagem($id) { |
|
| 867 | 867 | $image = $_FILES['arquivo']; |
| 868 | 868 | |
| 869 | 869 | $retorno = $this->uploadImage($image); |
| 870 | 870 | |
| 871 | 871 | if (!$retorno['status']) { |
| 872 | 872 | $this->Session->setFlash('A imagem não foi salva tente novamente ou contate o suporte!'); |
| 873 | - return $this->redirect('/produto/imagens/' . $id); |
|
| 873 | + return $this->redirect('/produto/imagens/' . $id); |
|
| 874 | 874 | } |
| 875 | 875 | |
| 876 | 876 | $photo = $this->request->data('photo'); |
@@ -891,26 +891,26 @@ discard block |
||
| 891 | 891 | |
| 892 | 892 | if (!$retorno) { |
| 893 | 893 | $this->Session->setFlash('A imagem não foi salva tente novamente ou contate o suporte!'); |
| 894 | - return $this->redirect('/produto/imagens/' . $id); |
|
| 894 | + return $this->redirect('/produto/imagens/' . $id); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | $this->Session->setFlash('A salva com sucesso!'); |
| 898 | - return $this->redirect('/produto/imagens/' . $id); |
|
| 899 | - } |
|
| 898 | + return $this->redirect('/produto/imagens/' . $id); |
|
| 899 | + } |
|
| 900 | 900 | |
| 901 | - public function imagem_excluir_cadastro($id) { |
|
| 902 | - $this->loadModel('Imagen'); |
|
| 901 | + public function imagem_excluir_cadastro($id) { |
|
| 902 | + $this->loadModel('Imagen'); |
|
| 903 | 903 | |
| 904 | - $this->Imagen->id = $id; |
|
| 904 | + $this->Imagen->id = $id; |
|
| 905 | 905 | |
| 906 | - $this->Imagen->save(['ativo' => 0]); |
|
| 906 | + $this->Imagen->save(['ativo' => 0]); |
|
| 907 | 907 | |
| 908 | - echo json_encode(array('success' => true)); |
|
| 909 | - exit; |
|
| 910 | - } |
|
| 908 | + echo json_encode(array('success' => true)); |
|
| 909 | + exit; |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | - public function produto_item() |
|
| 913 | - { |
|
| 912 | + public function produto_item() |
|
| 913 | + { |
|
| 914 | 914 | $search = strip_tags(trim($_GET['q'])); |
| 915 | 915 | |
| 916 | 916 | $conditions['limit'] = 10; |
@@ -928,6 +928,6 @@ discard block |
||
| 928 | 928 | |
| 929 | 929 | echo json_encode($data); |
| 930 | 930 | exit; |
| 931 | - } |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | 933 | } |