@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | $this->Session->setFlash('Produto salvo com sucesso!'); |
| 62 | 62 | |
| 63 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 63 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 64 | 64 | } else { |
| 65 | 65 | $this->Session->setFlash('Ocorreu um erro ao salva o produto!'); |
| 66 | 66 | |
| 67 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 67 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -75,17 +75,17 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | $query = array ( |
| 77 | 77 | 'joins' => array( |
| 78 | - array( |
|
| 79 | - 'table' => 'produtos', |
|
| 80 | - 'alias' => 'Produto', |
|
| 81 | - 'type' => 'LEFT', |
|
| 82 | - 'conditions' => array( |
|
| 83 | - 'Variacao.produto_id = Produto.id', |
|
| 84 | - ), |
|
| 85 | - ) |
|
| 78 | + array( |
|
| 79 | + 'table' => 'produtos', |
|
| 80 | + 'alias' => 'Produto', |
|
| 81 | + 'type' => 'LEFT', |
|
| 82 | + 'conditions' => array( |
|
| 83 | + 'Variacao.produto_id = Produto.id', |
|
| 84 | + ), |
|
| 85 | + ) |
|
| 86 | 86 | ), |
| 87 | - 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 88 | - 'fields' => array('Produto.id, Variacao.*'), |
|
| 87 | + 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 88 | + 'fields' => array('Produto.id, Variacao.*'), |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | 91 | $variacoes = $this->set('variacoes', $this->Variacao->find('all', $query)); |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
| 143 | 143 | |
| 144 | 144 | $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
| 145 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 145 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 146 | 146 | } else { |
| 147 | 147 | $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
| 148 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 148 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
@@ -259,152 +259,152 @@ discard block |
||
| 259 | 259 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 260 | 260 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 261 | 261 | |
| 262 | - $objPHPExcel = new PHPExcel(); |
|
| 263 | - // Definimos o estilo da fonte |
|
| 264 | - $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
| 262 | + $objPHPExcel = new PHPExcel(); |
|
| 263 | + // Definimos o estilo da fonte |
|
| 264 | + $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
| 265 | 265 | |
| 266 | - $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
| 266 | + $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
| 267 | 267 | |
| 268 | - // Criamos as colunas |
|
| 269 | - $objPHPExcel->setActiveSheetIndex(0) |
|
| 270 | - ->setCellValue('A1', "Nome do Produto") |
|
| 271 | - ->setCellValue('B1', "Preço ") |
|
| 272 | - ->setCellValue("C1", "Peso Bruto") |
|
| 273 | - ->setCellValue("D1", "Peso Liquido") |
|
| 274 | - ->setCellValue("E1", "Estoque") |
|
| 275 | - ->setCellValue("F1", "Descrição"); |
|
| 268 | + // Criamos as colunas |
|
| 269 | + $objPHPExcel->setActiveSheetIndex(0) |
|
| 270 | + ->setCellValue('A1', "Nome do Produto") |
|
| 271 | + ->setCellValue('B1', "Preço ") |
|
| 272 | + ->setCellValue("C1", "Peso Bruto") |
|
| 273 | + ->setCellValue("D1", "Peso Liquido") |
|
| 274 | + ->setCellValue("E1", "Estoque") |
|
| 275 | + ->setCellValue("F1", "Descrição"); |
|
| 276 | 276 | |
| 277 | - // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
| 278 | - $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
| 277 | + // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
| 278 | + $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
| 279 | 279 | |
| 280 | - // Cabeçalho do arquivo para ele baixar |
|
| 281 | - header('Content-Type: application/vnd.ms-excel'); |
|
| 282 | - header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
| 283 | - header('Cache-Control: max-age=0'); |
|
| 284 | - // Se for o IE9, isso talvez seja necessário |
|
| 285 | - header('Cache-Control: max-age=1'); |
|
| 280 | + // Cabeçalho do arquivo para ele baixar |
|
| 281 | + header('Content-Type: application/vnd.ms-excel'); |
|
| 282 | + header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
| 283 | + header('Cache-Control: max-age=0'); |
|
| 284 | + // Se for o IE9, isso talvez seja necessário |
|
| 285 | + header('Cache-Control: max-age=1'); |
|
| 286 | 286 | |
| 287 | - // Acessamos o 'Writer' para poder salvar o arquivo |
|
| 288 | - $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
| 287 | + // Acessamos o 'Writer' para poder salvar o arquivo |
|
| 288 | + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
| 289 | 289 | |
| 290 | - // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
| 291 | - $objWriter->save('php://output'); |
|
| 290 | + // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
| 291 | + $objWriter->save('php://output'); |
|
| 292 | 292 | |
| 293 | - exit; |
|
| 294 | - } |
|
| 293 | + exit; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - public function importar_produtos_planilha() { |
|
| 297 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 298 | - { |
|
| 296 | + public function importar_produtos_planilha() { |
|
| 297 | + if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 298 | + { |
|
| 299 | 299 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 300 | 300 | $this->redirect("/produto/listar_cadastros"); |
| 301 | - } |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - $typesPermissions = ['application/vnd.ms-excel']; |
|
| 303 | + $typesPermissions = ['application/vnd.ms-excel']; |
|
| 304 | 304 | |
| 305 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 306 | - { |
|
| 305 | + if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 306 | + { |
|
| 307 | 307 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 308 | 308 | $this->redirect("/produto/listar_cadastros"); |
| 309 | - } |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 311 | + $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 312 | 312 | |
| 313 | - $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 313 | + $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 314 | 314 | |
| 315 | - move_uploaded_file($inputFileName, $caminho); |
|
| 315 | + move_uploaded_file($inputFileName, $caminho); |
|
| 316 | 316 | |
| 317 | - $data = [ |
|
| 318 | - 'caminho' => $caminho, |
|
| 319 | - 'usuario_id' => $this->instancia, |
|
| 320 | - 'processado' => 0, |
|
| 321 | - 'ativo' => 1 |
|
| 322 | - ]; |
|
| 317 | + $data = [ |
|
| 318 | + 'caminho' => $caminho, |
|
| 319 | + 'usuario_id' => $this->instancia, |
|
| 320 | + 'processado' => 0, |
|
| 321 | + 'ativo' => 1 |
|
| 322 | + ]; |
|
| 323 | 323 | |
| 324 | - $this->loadModel('QueueProduct'); |
|
| 324 | + $this->loadModel('QueueProduct'); |
|
| 325 | 325 | |
| 326 | - if ($this->QueueProduct->save($data)) |
|
| 327 | - { |
|
| 326 | + if ($this->QueueProduct->save($data)) |
|
| 327 | + { |
|
| 328 | 328 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 329 | 329 | $this->redirect("/produto/listar_cadastros"); |
| 330 | - } |
|
| 331 | - else |
|
| 332 | - { |
|
| 330 | + } |
|
| 331 | + else |
|
| 332 | + { |
|
| 333 | 333 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 334 | 334 | $this->redirect("/produto/listar_cadastros"); |
| 335 | - } |
|
| 336 | - } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | - public function importar_produtos_planilha() { |
|
| 338 | + public function importar_produtos_planilha() { |
|
| 339 | 339 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 340 | 340 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 341 | 341 | |
| 342 | - $objPHPExcel = new PHPExcel(); |
|
| 342 | + $objPHPExcel = new PHPExcel(); |
|
| 343 | 343 | |
| 344 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 345 | - { |
|
| 344 | + if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 345 | + { |
|
| 346 | 346 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 347 | 347 | $this->redirect("/produto/listar_cadastros"); |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - $typesPermissions = ['application/vnd.ms-excel']; |
|
| 350 | + $typesPermissions = ['application/vnd.ms-excel']; |
|
| 351 | 351 | |
| 352 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 353 | - { |
|
| 352 | + if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 353 | + { |
|
| 354 | 354 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 355 | 355 | $this->redirect("/produto/listar_cadastros"); |
| 356 | - } |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 358 | + $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 359 | 359 | |
| 360 | - $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 360 | + $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 361 | 361 | |
| 362 | - move_uploaded_file($inputFileName, $caminho); |
|
| 362 | + move_uploaded_file($inputFileName, $caminho); |
|
| 363 | 363 | |
| 364 | - $data = [ |
|
| 365 | - 'caminho' => $caminho, |
|
| 366 | - 'usuario_id' => $this->instancia, |
|
| 367 | - 'processado' => 0, |
|
| 368 | - 'ativo' => 1 |
|
| 369 | - ]; |
|
| 364 | + $data = [ |
|
| 365 | + 'caminho' => $caminho, |
|
| 366 | + 'usuario_id' => $this->instancia, |
|
| 367 | + 'processado' => 0, |
|
| 368 | + 'ativo' => 1 |
|
| 369 | + ]; |
|
| 370 | 370 | |
| 371 | - if ($this->QueueProducts->save($data)) |
|
| 372 | - { |
|
| 371 | + if ($this->QueueProducts->save($data)) |
|
| 372 | + { |
|
| 373 | 373 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 374 | 374 | $this->redirect("/produto/listar_cadastros"); |
| 375 | - } |
|
| 376 | - else |
|
| 377 | - { |
|
| 375 | + } |
|
| 376 | + else |
|
| 377 | + { |
|
| 378 | 378 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 379 | 379 | $this->redirect("/produto/listar_cadastros"); |
| 380 | - } |
|
| 381 | - } |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - public function processar_planilhas_na_fila() { |
|
| 384 | - $this->loadModel('QueueProduct'); |
|
| 383 | + public function processar_planilhas_na_fila() { |
|
| 384 | + $this->loadModel('QueueProduct'); |
|
| 385 | 385 | |
| 386 | - $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
| 386 | + $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
| 387 | 387 | |
| 388 | - $response = []; |
|
| 389 | - foreach ($planilhas as $planilha) { |
|
| 390 | - $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
| 391 | - } |
|
| 388 | + $response = []; |
|
| 389 | + foreach ($planilhas as $planilha) { |
|
| 390 | + $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
| 391 | + } |
|
| 392 | 392 | |
| 393 | - return $response; |
|
| 394 | - } |
|
| 393 | + return $response; |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
| 396 | + public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
| 397 | 397 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 398 | 398 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 399 | 399 | |
| 400 | - $objPHPExcel = new PHPExcel(); |
|
| 400 | + $objPHPExcel = new PHPExcel(); |
|
| 401 | 401 | |
| 402 | 402 | try { |
| 403 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 404 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 405 | - $objPHPExcel = $objReader->load($inputFileName); |
|
| 403 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 404 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 405 | + $objPHPExcel = $objReader->load($inputFileName); |
|
| 406 | 406 | } catch(Exception $e) { |
| 407 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 407 | + die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | $dados = []; |
@@ -460,40 +460,40 @@ discard block |
||
| 460 | 460 | |
| 461 | 461 | echo json_encode(array('sucess' => true)); |
| 462 | 462 | exit; |
| 463 | - } |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | - public function processar_lista_produtos($dados) { |
|
| 466 | - $errors = []; |
|
| 465 | + public function processar_lista_produtos($dados) { |
|
| 466 | + $errors = []; |
|
| 467 | 467 | |
| 468 | - foreach ($dados as $dado) { |
|
| 469 | - $this->loadModel('Produto'); |
|
| 468 | + foreach ($dados as $dado) { |
|
| 469 | + $this->loadModel('Produto'); |
|
| 470 | 470 | |
| 471 | - $existProduto = $this->Produto->find('all', |
|
| 472 | - array( |
|
| 473 | - 'conditions' => array( |
|
| 474 | - 'Produto.sku' => $dado['sku'], |
|
| 475 | - 'Produto.ativo' => 1 |
|
| 476 | - ) |
|
| 477 | - ) |
|
| 478 | - ); |
|
| 479 | - |
|
| 480 | - if (isset($existProduto) && !empty($existProduto)) |
|
| 481 | - { |
|
| 482 | - $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
| 483 | - $this->Produto->save($dado); |
|
| 484 | - continue; |
|
| 485 | - } |
|
| 471 | + $existProduto = $this->Produto->find('all', |
|
| 472 | + array( |
|
| 473 | + 'conditions' => array( |
|
| 474 | + 'Produto.sku' => $dado['sku'], |
|
| 475 | + 'Produto.ativo' => 1 |
|
| 476 | + ) |
|
| 477 | + ) |
|
| 478 | + ); |
|
| 479 | + |
|
| 480 | + if (isset($existProduto) && !empty($existProduto)) |
|
| 481 | + { |
|
| 482 | + $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
| 483 | + $this->Produto->save($dado); |
|
| 484 | + continue; |
|
| 485 | + } |
|
| 486 | 486 | |
| 487 | 487 | $this->Produto->create(); |
| 488 | 488 | |
| 489 | - if (!$this->Produto->save($dado)) |
|
| 490 | - { |
|
| 491 | - $errors[] = $dado; |
|
| 492 | - } |
|
| 493 | - } |
|
| 489 | + if (!$this->Produto->save($dado)) |
|
| 490 | + { |
|
| 491 | + $errors[] = $dado; |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | - return $errors; |
|
| 495 | + return $errors; |
|
| 496 | 496 | >>>>>>> 36dc74c7f7a4a9679dceb6b9594a56aa51a0ed1a |
| 497 | - } |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | 499 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | ini_set('max_execution_time', 300); |
| 4 | 4 | |
| 5 | -class ProdutoController extends AppController{ |
|
| 5 | +class ProdutoController extends AppController { |
|
| 6 | 6 | |
| 7 | 7 | public function listar_cadastros() { |
| 8 | 8 | $this->layout = 'wadmin'; |
@@ -33,15 +33,15 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function s_adicionar_cadastro() { |
| 36 | - $dados = $this->request->data('dados'); |
|
| 36 | + $dados = $this->request->data('dados'); |
|
| 37 | 37 | |
| 38 | 38 | $variacoes = $this->request->data('variacao'); |
| 39 | 39 | |
| 40 | - $image = $_FILES['imagem']; |
|
| 40 | + $image = $_FILES['imagem']; |
|
| 41 | 41 | |
| 42 | 42 | $retorno = $this->uploadImage($image); |
| 43 | 43 | |
| 44 | - if (!$retorno['status']) |
|
| 44 | + if ( ! $retorno['status']) |
|
| 45 | 45 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
| 46 | 46 | |
| 47 | 47 | $dados['imagem'] = $retorno['nome']; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $dados['ativo'] = 1; |
| 50 | 50 | $dados['id_alias'] = $this->id_alias(); |
| 51 | 51 | |
| 52 | - if($this->Produto->save($dados)) { |
|
| 52 | + if ($this->Produto->save($dados)) { |
|
| 53 | 53 | $produto_id = $this->Produto->getLastInsertId(); |
| 54 | 54 | |
| 55 | 55 | require 'VariacaoController.php'; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $this->loadModel('Variacao'); |
| 75 | 75 | |
| 76 | - $query = array ( |
|
| 76 | + $query = array( |
|
| 77 | 77 | 'joins' => array( |
| 78 | 78 | array( |
| 79 | 79 | 'table' => 'produtos', |
@@ -116,12 +116,12 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | $variacoes = $this->request->data('variacao'); |
| 118 | 118 | |
| 119 | - $image = $_FILES['imagem']; |
|
| 119 | + $image = $_FILES['imagem']; |
|
| 120 | 120 | |
| 121 | - if (!empty($image['name'])) { |
|
| 121 | + if ( ! empty($image['name'])) { |
|
| 122 | 122 | $retorno = $this->uploadImage($image); |
| 123 | 123 | |
| 124 | - if (!$retorno['status']) |
|
| 124 | + if ( ! $retorno['status']) |
|
| 125 | 125 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
| 126 | 126 | |
| 127 | 127 | $dados['imagem'] = $retorno['nome']; |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | $objVariacaoController->desativar_variacoes($id); |
| 142 | 142 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
| 143 | 143 | |
| 144 | - $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
|
| 144 | + $this->Session->setFlash('Produto editado com sucesso!', 'default', 'good'); |
|
| 145 | 145 | return $this->redirect('/produto/listar_cadastros'); |
| 146 | 146 | } else { |
| 147 | - $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
|
| 147 | + $this->Session->setFlash('Ocorreu um erro ao editar o produto!', 'default', 'good'); |
|
| 148 | 148 | return $this->redirect('/produto/listar_cadastros'); |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | ) |
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | - if (!$this->validar_estoque($retorno)) { |
|
| 189 | + if ( ! $this->validar_estoque($retorno)) { |
|
| 190 | 190 | return false; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | public function validar_estoque($produto) { |
| 201 | - if (empty($produto) && !isset($produto)) { |
|
| 201 | + if (empty($produto) && ! isset($produto)) { |
|
| 202 | 202 | return false; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -210,11 +210,11 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | public function calcular_preco_produto_venda($preco, $qnt) { |
| 213 | - if (empty($preco) || !isset($preco)) { |
|
| 213 | + if (empty($preco) || ! isset($preco)) { |
|
| 214 | 214 | return false; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if (!is_numeric($qnt)) { |
|
| 217 | + if ( ! is_numeric($qnt)) { |
|
| 218 | 218 | return false; |
| 219 | 219 | } |
| 220 | 220 | |
@@ -225,12 +225,12 @@ discard block |
||
| 225 | 225 | |
| 226 | 226 | public function uploadImage(&$image) { |
| 227 | 227 | $type = substr($image['name'], -4); |
| 228 | - $nameImage = uniqid() . md5($image['name']) . $type; |
|
| 229 | - $dir = APP . 'webroot/uploads/produto/imagens/'; |
|
| 228 | + $nameImage = uniqid().md5($image['name']).$type; |
|
| 229 | + $dir = APP.'webroot/uploads/produto/imagens/'; |
|
| 230 | 230 | |
| 231 | - $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); |
|
| 231 | + $returnUpload = move_uploaded_file($image['tmp_name'], $dir.$nameImage); |
|
| 232 | 232 | |
| 233 | - if (!$returnUpload) |
|
| 233 | + if ( ! $returnUpload) |
|
| 234 | 234 | return array('nome' => null, 'status' => false); |
| 235 | 235 | |
| 236 | 236 | return array('nome' => $nameImage, 'status' => true); |
@@ -256,8 +256,8 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | public function exportar_excel_exemplo() { |
| 259 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 260 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 259 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 260 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 261 | 261 | |
| 262 | 262 | $objPHPExcel = new PHPExcel(); |
| 263 | 263 | // Definimos o estilo da fonte |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | public function importar_produtos_planilha() { |
| 297 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 297 | + if ( ! isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 298 | 298 | { |
| 299 | 299 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 300 | 300 | $this->redirect("/produto/listar_cadastros"); |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | $typesPermissions = ['application/vnd.ms-excel']; |
| 304 | 304 | |
| 305 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 305 | + if ( ! in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 306 | 306 | { |
| 307 | 307 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 308 | 308 | $this->redirect("/produto/listar_cadastros"); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 311 | + $caminho = APP.'webroot/uploads/produto/planilhas/'.uniqid().'.xls'; |
|
| 312 | 312 | |
| 313 | 313 | $inputFileName = $_FILES['arquivo']['tmp_name']; |
| 314 | 314 | |
@@ -336,12 +336,12 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | public function importar_produtos_planilha() { |
| 339 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 340 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 339 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 340 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 341 | 341 | |
| 342 | 342 | $objPHPExcel = new PHPExcel(); |
| 343 | 343 | |
| 344 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 344 | + if ( ! isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 345 | 345 | { |
| 346 | 346 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 347 | 347 | $this->redirect("/produto/listar_cadastros"); |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | |
| 350 | 350 | $typesPermissions = ['application/vnd.ms-excel']; |
| 351 | 351 | |
| 352 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 352 | + if ( ! in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 353 | 353 | { |
| 354 | 354 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 355 | 355 | $this->redirect("/produto/listar_cadastros"); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 358 | + $caminho = APP.'webroot/uploads/produto/planilhas/'.uniqid().'.xls'; |
|
| 359 | 359 | |
| 360 | 360 | $inputFileName = $_FILES['arquivo']['tmp_name']; |
| 361 | 361 | |
@@ -394,17 +394,17 @@ discard block |
||
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
| 397 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 398 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 397 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 398 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 399 | 399 | |
| 400 | 400 | $objPHPExcel = new PHPExcel(); |
| 401 | 401 | |
| 402 | 402 | try { |
| 403 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 404 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 405 | - $objPHPExcel = $objReader->load($inputFileName); |
|
| 406 | - } catch(Exception $e) { |
|
| 407 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 403 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 404 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 405 | + $objPHPExcel = $objReader->load($inputFileName); |
|
| 406 | + } catch (Exception $e) { |
|
| 407 | + die('Error loading file "'.pathinfo($inputFileName, PATHINFO_BASENAME).'": '.$e->getMessage()); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | $dados = []; |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | |
| 452 | 452 | $errors = $this->processar_lista_produtos($dados); |
| 453 | 453 | |
| 454 | - if (isset($errors) && !empty($errors)) |
|
| 454 | + if (isset($errors) && ! empty($errors)) |
|
| 455 | 455 | { |
| 456 | 456 | $this->QueueProduct->planilhaProcessedIncomplete($planilhaId); |
| 457 | 457 | } |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | ) |
| 478 | 478 | ); |
| 479 | 479 | |
| 480 | - if (isset($existProduto) && !empty($existProduto)) |
|
| 480 | + if (isset($existProduto) && ! empty($existProduto)) |
|
| 481 | 481 | { |
| 482 | 482 | $this->Produto->id = $existProduto[0]['Produto']['id']; |
| 483 | 483 | $this->Produto->save($dado); |
@@ -486,14 +486,14 @@ discard block |
||
| 486 | 486 | |
| 487 | 487 | $this->Produto->create(); |
| 488 | 488 | |
| 489 | - if (!$this->Produto->save($dado)) |
|
| 489 | + if ( ! $this->Produto->save($dado)) |
|
| 490 | 490 | { |
| 491 | 491 | $errors[] = $dado; |
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | return $errors; |
| 496 | ->>>>>>> 36dc74c7f7a4a9679dceb6b9594a56aa51a0ed1a |
|
| 496 | +>> >> >> > 36dc74c7f7a4a9679dceb6b9594a56aa51a0ed1a |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | } |
@@ -41,8 +41,9 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | $retorno = $this->uploadImage($image); |
| 43 | 43 | |
| 44 | - if (!$retorno['status']) |
|
| 45 | - $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 44 | + if (!$retorno['status']) { |
|
| 45 | + $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 46 | + } |
|
| 46 | 47 | |
| 47 | 48 | $dados['imagem'] = $retorno['nome']; |
| 48 | 49 | $dados['id_usuario'] = $this->instancia; |
@@ -121,8 +122,9 @@ discard block |
||
| 121 | 122 | if (!empty($image['name'])) { |
| 122 | 123 | $retorno = $this->uploadImage($image); |
| 123 | 124 | |
| 124 | - if (!$retorno['status']) |
|
| 125 | - $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 125 | + if (!$retorno['status']) { |
|
| 126 | + $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 127 | + } |
|
| 126 | 128 | |
| 127 | 129 | $dados['imagem'] = $retorno['nome']; |
| 128 | 130 | } |
@@ -230,8 +232,9 @@ discard block |
||
| 230 | 232 | |
| 231 | 233 | $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); |
| 232 | 234 | |
| 233 | - if (!$returnUpload) |
|
| 234 | - return array('nome' => null, 'status' => false); |
|
| 235 | + if (!$returnUpload) { |
|
| 236 | + return array('nome' => null, 'status' => false); |
|
| 237 | + } |
|
| 235 | 238 | |
| 236 | 239 | return array('nome' => $nameImage, 'status' => true); |
| 237 | 240 | } |
@@ -327,8 +330,7 @@ discard block |
||
| 327 | 330 | { |
| 328 | 331 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 329 | 332 | $this->redirect("/produto/listar_cadastros"); |
| 330 | - } |
|
| 331 | - else |
|
| 333 | + } else |
|
| 332 | 334 | { |
| 333 | 335 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 334 | 336 | $this->redirect("/produto/listar_cadastros"); |
@@ -372,8 +374,7 @@ discard block |
||
| 372 | 374 | { |
| 373 | 375 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 374 | 376 | $this->redirect("/produto/listar_cadastros"); |
| 375 | - } |
|
| 376 | - else |
|
| 377 | + } else |
|
| 377 | 378 | { |
| 378 | 379 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 379 | 380 | $this->redirect("/produto/listar_cadastros"); |