Completed
Push — master ( c55a69...d34eef )
by Reginaldo
32:38
created
app/Controller/ProdutoController.php 3 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 			$objVariacaoController->s_adicionar_variacao($variacoes, $produto_id, $this->instancia);			
56 56
 
57 57
 			$this->Session->setFlash('Produto salvo com sucesso!');
58
-            return $this->redirect('/produto/listar_cadastros');
58
+			return $this->redirect('/produto/listar_cadastros');
59 59
 		} else {
60 60
 			$this->Session->setFlash('Ocorreu um erro ao salva o produto!');
61
-            return $this->redirect('/produto/listar_cadastros');
61
+			return $this->redirect('/produto/listar_cadastros');
62 62
 		}
63 63
 	}
64 64
 
@@ -69,17 +69,17 @@  discard block
 block discarded – undo
69 69
 
70 70
 		$query = array (
71 71
 			'joins' => array(
72
-				    array(
73
-				        'table' => 'produtos',
74
-				        'alias' => 'Produto',
75
-				        'type' => 'LEFT',
76
-				        'conditions' => array(
77
-				            'Variacao.produto_id = Produto.id',
78
-				        ),
79
-				    )
72
+					array(
73
+						'table' => 'produtos',
74
+						'alias' => 'Produto',
75
+						'type' => 'LEFT',
76
+						'conditions' => array(
77
+							'Variacao.produto_id = Produto.id',
78
+						),
79
+					)
80 80
 				),
81
-	        'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1),
82
-	        'fields' => array('Produto.id, Variacao.*'),
81
+			'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1),
82
+			'fields' => array('Produto.id, Variacao.*'),
83 83
 		);
84 84
 
85 85
 		$variacoes = $this->set('variacoes', $this->Variacao->find('all', $query));
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
 			$objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia);	
137 137
 
138 138
 			$this->Session->setFlash('Produto editado com sucesso!','default','good');
139
-            return $this->redirect('/produto/listar_cadastros');
139
+			return $this->redirect('/produto/listar_cadastros');
140 140
 		} else {
141 141
 			$this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good');
142
-            return $this->redirect('/produto/listar_cadastros');
142
+			return $this->redirect('/produto/listar_cadastros');
143 143
 		}
144 144
 	}
145 145
 
@@ -253,108 +253,108 @@  discard block
 block discarded – undo
253 253
 		include(APP . 'Vendor/PHPExcel/PHPExcel.php');
254 254
 		include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php');
255 255
 
256
-        $objPHPExcel = new PHPExcel();
257
-        // Definimos o estilo da fonte
258
-        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
256
+		$objPHPExcel = new PHPExcel();
257
+		// Definimos o estilo da fonte
258
+		$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
259 259
 
260
-        $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);
260
+		$objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);
261 261
 
262
-        // Criamos as colunas
263
-        $objPHPExcel->setActiveSheetIndex(0)
264
-                    ->setCellValue('A1', "Nome do Produto")
265
-                    ->setCellValue('B1', "Preço ")
266
-                    ->setCellValue("C1", "Peso Bruto")
267
-                    ->setCellValue("D1", "Peso Liquido")
268
-                    ->setCellValue("E1", "Estoque")
269
-                    ->setCellValue("F1", "Descrição");
262
+		// Criamos as colunas
263
+		$objPHPExcel->setActiveSheetIndex(0)
264
+					->setCellValue('A1', "Nome do Produto")
265
+					->setCellValue('B1', "Preço ")
266
+					->setCellValue("C1", "Peso Bruto")
267
+					->setCellValue("D1", "Peso Liquido")
268
+					->setCellValue("E1", "Estoque")
269
+					->setCellValue("F1", "Descrição");
270 270
 
271
-        // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas
272
-        $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos');
271
+		// Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas
272
+		$objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos');
273 273
 
274
-        // Cabeçalho do arquivo para ele baixar
275
-        header('Content-Type: application/vnd.ms-excel');
276
-        header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"');
277
-        header('Cache-Control: max-age=0');
278
-        // Se for o IE9, isso talvez seja necessário
279
-        header('Cache-Control: max-age=1');
274
+		// Cabeçalho do arquivo para ele baixar
275
+		header('Content-Type: application/vnd.ms-excel');
276
+		header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"');
277
+		header('Cache-Control: max-age=0');
278
+		// Se for o IE9, isso talvez seja necessário
279
+		header('Cache-Control: max-age=1');
280 280
 
281
-        // Acessamos o 'Writer' para poder salvar o arquivo
282
-        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
281
+		// Acessamos o 'Writer' para poder salvar o arquivo
282
+		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
283 283
 
284
-        // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela
285
-        $objWriter->save('php://output'); 
284
+		// Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela
285
+		$objWriter->save('php://output'); 
286 286
 
287
-        exit;
288
-    }
287
+		exit;
288
+	}
289 289
 
290
-    public function importar_produtos_planilha() {
290
+	public function importar_produtos_planilha() {
291 291
 	include(APP . 'Vendor/PHPExcel/PHPExcel.php');
292 292
 	include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php');
293 293
     	
294
-        $objPHPExcel = new PHPExcel();
294
+		$objPHPExcel = new PHPExcel();
295 295
 
296
-        if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name']))
297
-        {
296
+		if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name']))
297
+		{
298 298
 			$this->Session->setFlash("Erro ao subir a planilha, tente novamente.");
299 299
 			$this->redirect("/produto/listar_cadastros");        	
300
-        }
300
+		}
301 301
 
302
-        $typesPermissions = ['application/vnd.ms-excel'];
302
+		$typesPermissions = ['application/vnd.ms-excel'];
303 303
 
304
-        if (!in_array($_FILES['arquivo']['type'], $typesPermissions))
305
-        {
304
+		if (!in_array($_FILES['arquivo']['type'], $typesPermissions))
305
+		{
306 306
 			$this->Session->setFlash("O arquivo deve ser no formato .xls.");
307 307
 			$this->redirect("/produto/listar_cadastros");                	
308
-        }
308
+		}
309 309
 
310
-        $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls';
310
+		$caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls';
311 311
 
312
-        $inputFileName = $_FILES['arquivo']['tmp_name'];
312
+		$inputFileName = $_FILES['arquivo']['tmp_name'];
313 313
 
314
-        move_uploaded_file($inputFileName, $caminho);
314
+		move_uploaded_file($inputFileName, $caminho);
315 315
 
316
-        $data = [
317
-        	'caminho' => $caminho,
318
-        	'usuario_id' => $this->instancia,
319
-        	'processado' => 0,
320
-        	'ativo' => 1
321
-        ];
316
+		$data = [
317
+			'caminho' => $caminho,
318
+			'usuario_id' => $this->instancia,
319
+			'processado' => 0,
320
+			'ativo' => 1
321
+		];
322 322
 
323
-        if ($this->QueueProducts->save($data))
324
-        {
323
+		if ($this->QueueProducts->save($data))
324
+		{
325 325
 			$this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar.");
326 326
 			$this->redirect("/produto/listar_cadastros");  
327
-        }
328
-        else 
329
-        {
327
+		}
328
+		else 
329
+		{
330 330
 			$this->Session->setFlash("Ocorreu um erro, tente novamente.");
331 331
 			$this->redirect("/produto/listar_cadastros");          	
332
-        }
333
-    }
334
-
335
-    public function processar_planilhas_na_fila() {
336
-    	$planilhas = [
337
-	    	[
338
-	    		'file' => 'teste.xls',
339
-	    		'user_id' => 1
340
-	    	]
341
-    	];
342
-
343
-    	$response = [];
344
-    	foreach ($planilhas as $planilha) {
345
-    		$response[] = $this->processar_planilhas();
346
-    	}
347
-
348
-    	return $response;
349
-    }
350
-
351
-    public function processar_planilhas($inputFileName) {
332
+		}
333
+	}
334
+
335
+	public function processar_planilhas_na_fila() {
336
+		$planilhas = [
337
+			[
338
+				'file' => 'teste.xls',
339
+				'user_id' => 1
340
+			]
341
+		];
342
+
343
+		$response = [];
344
+		foreach ($planilhas as $planilha) {
345
+			$response[] = $this->processar_planilhas();
346
+		}
347
+
348
+		return $response;
349
+	}
350
+
351
+	public function processar_planilhas($inputFileName) {
352 352
 		try {
353
-		    $inputFileType 	= PHPExcel_IOFactory::identify($inputFileName);
354
-		    $objReader 		= PHPExcel_IOFactory::createReader($inputFileType);
355
-		    $objPHPExcel 	= $objReader->load($inputFileName);
353
+			$inputFileType 	= PHPExcel_IOFactory::identify($inputFileName);
354
+			$objReader 		= PHPExcel_IOFactory::createReader($inputFileType);
355
+			$objPHPExcel 	= $objReader->load($inputFileName);
356 356
 		} catch(Exception $e) {
357
-		    die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
357
+			die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
358 358
 		}
359 359
 
360 360
 		$dados = [];
@@ -395,6 +395,6 @@  discard block
 block discarded – undo
395 395
 		}
396 396
 
397 397
 		pr($dados);
398
-    }
398
+	}
399 399
 
400 400
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class ProdutoController extends AppController{		
3
+class ProdutoController extends AppController {		
4 4
 
5 5
 	public function listar_cadastros() {
6 6
 		$this->layout = 'wadmin';
@@ -31,15 +31,15 @@  discard block
 block discarded – undo
31 31
 	}
32 32
 
33 33
 	public function s_adicionar_cadastro() {
34
-		$dados  = $this->request->data('dados');
34
+		$dados = $this->request->data('dados');
35 35
 
36 36
 		$variacoes = $this->request->data('variacao');
37 37
 
38
-		$image  = $_FILES['imagem'];
38
+		$image = $_FILES['imagem'];
39 39
 
40 40
 		$retorno = $this->uploadImage($image);
41 41
 
42
-		if (!$retorno['status']) 
42
+		if ( ! $retorno['status']) 
43 43
 			$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente');
44 44
 
45 45
 		$dados['imagem'] = $retorno['nome'];
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		$dados['ativo'] = 1;
48 48
 		$dados['id_alias'] = $this->id_alias();
49 49
 
50
-		if($this->Produto->save($dados)) {
50
+		if ($this->Produto->save($dados)) {
51 51
 			$produto_id = $this->Produto->getLastInsertId();
52 52
 			require 'VariacaoController.php';
53 53
 			$objVariacaoController = new VariacaoController();
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 
68 68
 		$this->loadModel('Variacao');
69 69
 
70
-		$query = array (
70
+		$query = array(
71 71
 			'joins' => array(
72 72
 				    array(
73 73
 				        'table' => 'produtos',
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 
111 111
 		$variacoes = $this->request->data('variacao');
112 112
 
113
-		$image  = $_FILES['imagem'];
113
+		$image = $_FILES['imagem'];
114 114
 		
115
-		if (!empty($image['name'])) {
115
+		if ( ! empty($image['name'])) {
116 116
 			$retorno = $this->uploadImage($image);
117 117
 			
118
-			if (!$retorno['status']) 
118
+			if ( ! $retorno['status']) 
119 119
 				$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente');
120 120
 			
121 121
 			$dados['imagem'] = $retorno['nome'];
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
 			$objVariacaoController->desativar_variacoes($id);
136 136
 			$objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia);	
137 137
 
138
-			$this->Session->setFlash('Produto editado com sucesso!','default','good');
138
+			$this->Session->setFlash('Produto editado com sucesso!', 'default', 'good');
139 139
             return $this->redirect('/produto/listar_cadastros');
140 140
 		} else {
141
-			$this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good');
141
+			$this->Session->setFlash('Ocorreu um erro ao editar o produto!', 'default', 'good');
142 142
             return $this->redirect('/produto/listar_cadastros');
143 143
 		}
144 144
 	}
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
 
149 149
 		$id = $this->request->data('id');
150 150
 
151
-		$dados = array ('ativo' => '0');
152
-		$parametros = array ('id' => $id);
151
+		$dados = array('ativo' => '0');
152
+		$parametros = array('id' => $id);
153 153
 
154
-		if ($this->Produto->updateAll($dados,$parametros)) {
154
+		if ($this->Produto->updateAll($dados, $parametros)) {
155 155
 			echo json_encode(true);
156 156
 		} else {
157 157
 			echo json_encode(false);
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 			)
181 181
 		);
182 182
 
183
-		if (!$this->validar_estoque($retorno)) {
183
+		if ( ! $this->validar_estoque($retorno)) {
184 184
 			return false;
185 185
 		}
186 186
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	}
193 193
 
194 194
 	public function validar_estoque($produto) {
195
-		if (empty($produto) && !isset($produto)) {
195
+		if (empty($produto) && ! isset($produto)) {
196 196
 			return false;
197 197
 		}
198 198
 		
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
 	}
205 205
 
206 206
 	public function calcular_preco_produto_venda($preco, $qnt) {
207
-		if (empty($preco) || !isset($preco)) {
207
+		if (empty($preco) || ! isset($preco)) {
208 208
 			return false;
209 209
 		}
210 210
 
211
-		if (!is_numeric($qnt)) {
211
+		if ( ! is_numeric($qnt)) {
212 212
 			return false;
213 213
 		}
214 214
 
@@ -219,12 +219,12 @@  discard block
 block discarded – undo
219 219
 
220 220
 	public function uploadImage(&$image) {
221 221
 		$type = substr($image['name'], -4);
222
-		$nameImage = uniqid() . md5($image['name']) . $type;
223
-		$dir = APP . 'webroot/uploads/produto/imagens/';
222
+		$nameImage = uniqid().md5($image['name']).$type;
223
+		$dir = APP.'webroot/uploads/produto/imagens/';
224 224
 		
225
-		$returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage);
225
+		$returnUpload = move_uploaded_file($image['tmp_name'], $dir.$nameImage);
226 226
 
227
-		if (!$returnUpload)
227
+		if ( ! $returnUpload)
228 228
 			return array('nome' => null, 'status' => false);
229 229
 
230 230
 		return array('nome' => $nameImage, 'status' => true);
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 	}
251 251
 
252 252
 	public function exportar_excel_exemplo() {
253
-		include(APP . 'Vendor/PHPExcel/PHPExcel.php');
254
-		include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php');
253
+		include(APP.'Vendor/PHPExcel/PHPExcel.php');
254
+		include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php');
255 255
 
256 256
         $objPHPExcel = new PHPExcel();
257 257
         // Definimos o estilo da fonte
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
     }
289 289
 
290 290
     public function importar_produtos_planilha() {
291
-	include(APP . 'Vendor/PHPExcel/PHPExcel.php');
292
-	include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php');
291
+	include(APP.'Vendor/PHPExcel/PHPExcel.php');
292
+	include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php');
293 293
     	
294 294
         $objPHPExcel = new PHPExcel();
295 295
 
296
-        if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name']))
296
+        if ( ! isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name']))
297 297
         {
298 298
 			$this->Session->setFlash("Erro ao subir a planilha, tente novamente.");
299 299
 			$this->redirect("/produto/listar_cadastros");        	
@@ -301,13 +301,13 @@  discard block
 block discarded – undo
301 301
 
302 302
         $typesPermissions = ['application/vnd.ms-excel'];
303 303
 
304
-        if (!in_array($_FILES['arquivo']['type'], $typesPermissions))
304
+        if ( ! in_array($_FILES['arquivo']['type'], $typesPermissions))
305 305
         {
306 306
 			$this->Session->setFlash("O arquivo deve ser no formato .xls.");
307 307
 			$this->redirect("/produto/listar_cadastros");                	
308 308
         }
309 309
 
310
-        $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls';
310
+        $caminho = APP.'webroot/uploads/produto/planilhas/'.uniqid().'.xls';
311 311
 
312 312
         $inputFileName = $_FILES['arquivo']['tmp_name'];
313 313
 
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 
351 351
     public function processar_planilhas($inputFileName) {
352 352
 		try {
353
-		    $inputFileType 	= PHPExcel_IOFactory::identify($inputFileName);
354
-		    $objReader 		= PHPExcel_IOFactory::createReader($inputFileType);
355
-		    $objPHPExcel 	= $objReader->load($inputFileName);
356
-		} catch(Exception $e) {
357
-		    die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
353
+		    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
354
+		    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
355
+		    $objPHPExcel = $objReader->load($inputFileName);
356
+		} catch (Exception $e) {
357
+		    die('Error loading file "'.pathinfo($inputFileName, PATHINFO_BASENAME).'": '.$e->getMessage());
358 358
 		}
359 359
 
360 360
 		$dados = [];
Please login to merge, or discard this patch.
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -39,8 +39,9 @@  discard block
 block discarded – undo
39 39
 
40 40
 		$retorno = $this->uploadImage($image);
41 41
 
42
-		if (!$retorno['status']) 
43
-			$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente');
42
+		if (!$retorno['status']) {
43
+					$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente');
44
+		}
44 45
 
45 46
 		$dados['imagem'] = $retorno['nome'];
46 47
 		$dados['id_usuario'] = $this->instancia;
@@ -115,8 +116,9 @@  discard block
 block discarded – undo
115 116
 		if (!empty($image['name'])) {
116 117
 			$retorno = $this->uploadImage($image);
117 118
 			
118
-			if (!$retorno['status']) 
119
-				$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente');
119
+			if (!$retorno['status']) {
120
+							$this->Session->setFlash('Não foi possivel salvar a imagem tente novamente');
121
+			}
120 122
 			
121 123
 			$dados['imagem'] = $retorno['nome'];
122 124
 		}
@@ -224,8 +226,9 @@  discard block
 block discarded – undo
224 226
 		
225 227
 		$returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage);
226 228
 
227
-		if (!$returnUpload)
228
-			return array('nome' => null, 'status' => false);
229
+		if (!$returnUpload) {
230
+					return array('nome' => null, 'status' => false);
231
+		}
229 232
 
230 233
 		return array('nome' => $nameImage, 'status' => true);
231 234
 	}
@@ -324,8 +327,7 @@  discard block
 block discarded – undo
324 327
         {
325 328
 			$this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar.");
326 329
 			$this->redirect("/produto/listar_cadastros");  
327
-        }
328
-        else 
330
+        } else 
329 331
         {
330 332
 			$this->Session->setFlash("Ocorreu um erro, tente novamente.");
331 333
 			$this->redirect("/produto/listar_cadastros");          	
Please login to merge, or discard this patch.