@@ -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 | } |
@@ -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 |