Completed
Push — master ( 17c1a3...d21531 )
by Reginaldo
18:10
created
app/Controller/VendaController.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
 					$value = str_replace('_', ' ', $value);
133 133
 					$value = ucwords($value);
134 134
 				} else if ($aColumns[$i] == "actions") {
135
-		            $value = '<a href="javascript:printNotaNaoFiscal(' . $venda['Venda']['id'] . ');" target="_blank" class="btn btn-info">';
136
-		            $value .= '<i class="fa fa-file-text" aria-hidden="true"></i>';
137
-		            $value .= '</a> ';
135
+					$value = '<a href="javascript:printNotaNaoFiscal(' . $venda['Venda']['id'] . ');" target="_blank" class="btn btn-info">';
136
+					$value .= '<i class="fa fa-file-text" aria-hidden="true"></i>';
137
+					$value .= '</a> ';
138 138
 
139 139
 					$value .= ' <button onclick="remover_venda(' . $venda['Venda']['id'] . ');" type="button" class="btn btn-danger"><i class="fa fa-times"></i></button>';
140 140
 				} else if ($aColumns[$i] == "valor") { 
@@ -380,58 +380,58 @@  discard block
 block discarded – undo
380 380
 		include(APP . 'Vendor/PHPExcel/PHPExcel.php');
381 381
 		include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php');
382 382
 
383
-        $objPHPExcel = new PHPExcel();
384
-        // Definimos o estilo da fonte
385
-        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
386
-
387
-        $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);
388
-
389
-        // Criamos as colunas
390
-        $objPHPExcel->setActiveSheetIndex(0)
391
-                    ->setCellValue('A1', "Valor Venda")
392
-                    ->setCellValue('B1', "Custo Médio ")
393
-                    ->setCellValue("C1", "Valor Lucro")
394
-                    ->setCellValue('D1', "ID Venda" );
395
-
396
-
397
-        $vendas = $this->Venda->find('all',
398
-        	array('conditions' => array(
399
-        			'AND' => array(
400
-        				'Venda.ativo' => 1,
401
-        				'Venda.id_usuario' => $this->instancia,
402
-        				'Venda.data_venda' => date('Y-m-d')
403
-        			)
404
-        		)
405
-        	)
406
-        );
407
-
408
-        $i = 2;
409
-        foreach ($vendas as $key => $venda) {
410
-        	$objPHPExcel->setActiveSheetIndex(0)
411
-        				->setCellValue('A'.$i, 'R$ ' . $venda['Venda']['valor'])
412
-        				->setCellValue('B'.$i, 'R$ ' . $venda['Venda']['custo'])
413
-        				->setCellValue('C'.$i, 'R$ ' . $venda['Venda']['valor'] - $venda['Venda']['custo'])
414
-        				->setCellValue('D'.$i, $venda['Venda']['id']);
415
-        	$i++;
416
-        }
417
-
418
-        // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas
419
-        $objPHPExcel->getActiveSheet()->setTitle('Listagem de vendas');
420
-
421
-        // Cabeçalho do arquivo para ele baixar
422
-        header('Content-Type: application/vnd.ms-excel');
423
-        header('Content-Disposition: attachment;filename="relatorio_vendas_'.date('d-m-Y').'.xls"');
424
-        header('Cache-Control: max-age=0');
425
-        // Se for o IE9, isso talvez seja necessário
426
-        header('Cache-Control: max-age=1');
427
-
428
-        // Acessamos o 'Writer' para poder salvar o arquivo
429
-        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
430
-
431
-        // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela
432
-        $objWriter->save('php://output'); 
433
-
434
-        exit;
383
+		$objPHPExcel = new PHPExcel();
384
+		// Definimos o estilo da fonte
385
+		$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
386
+
387
+		$objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40);
388
+
389
+		// Criamos as colunas
390
+		$objPHPExcel->setActiveSheetIndex(0)
391
+					->setCellValue('A1', "Valor Venda")
392
+					->setCellValue('B1', "Custo Médio ")
393
+					->setCellValue("C1", "Valor Lucro")
394
+					->setCellValue('D1', "ID Venda" );
395
+
396
+
397
+		$vendas = $this->Venda->find('all',
398
+			array('conditions' => array(
399
+					'AND' => array(
400
+						'Venda.ativo' => 1,
401
+						'Venda.id_usuario' => $this->instancia,
402
+						'Venda.data_venda' => date('Y-m-d')
403
+					)
404
+				)
405
+			)
406
+		);
407
+
408
+		$i = 2;
409
+		foreach ($vendas as $key => $venda) {
410
+			$objPHPExcel->setActiveSheetIndex(0)
411
+						->setCellValue('A'.$i, 'R$ ' . $venda['Venda']['valor'])
412
+						->setCellValue('B'.$i, 'R$ ' . $venda['Venda']['custo'])
413
+						->setCellValue('C'.$i, 'R$ ' . $venda['Venda']['valor'] - $venda['Venda']['custo'])
414
+						->setCellValue('D'.$i, $venda['Venda']['id']);
415
+			$i++;
416
+		}
417
+
418
+		// Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas
419
+		$objPHPExcel->getActiveSheet()->setTitle('Listagem de vendas');
420
+
421
+		// Cabeçalho do arquivo para ele baixar
422
+		header('Content-Type: application/vnd.ms-excel');
423
+		header('Content-Disposition: attachment;filename="relatorio_vendas_'.date('d-m-Y').'.xls"');
424
+		header('Cache-Control: max-age=0');
425
+		// Se for o IE9, isso talvez seja necessário
426
+		header('Cache-Control: max-age=1');
427
+
428
+		// Acessamos o 'Writer' para poder salvar o arquivo
429
+		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
430
+
431
+		// Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela
432
+		$objWriter->save('php://output'); 
433
+
434
+		exit;
435 435
 	}
436 436
 
437 437
 	public function recoverDataToDashboardOneWeek($id_usuario){
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
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
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	public function listar_cadastros_ajax() {
68 68
 		$this->layout = 'ajax';
69 69
 
70
-		$aColumns = array( 'id', 'valor', 'forma_pagamento', 'data_venda', 'actions' );
70
+		$aColumns = array('id', 'valor', 'forma_pagamento', 'data_venda', 'actions');
71 71
 
72 72
 		$this->loadModel('LancamentoVenda');
73 73
 
@@ -84,26 +84,26 @@  discard block
 block discarded – undo
84 84
 			array('order' => array('Venda.id DESC'))
85 85
 		);
86 86
 		
87
-		if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
87
+		if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1')
88 88
 		{
89 89
 			$conditions['offset'] = $_GET['iDisplayStart'];
90 90
 			$conditions['limit'] = $_GET['iDisplayLength'];
91 91
 		}
92 92
 
93
-		if ( isset( $_GET['iSortCol_0'] ) )
93
+		if (isset($_GET['iSortCol_0']))
94 94
 		{
95
-			for ( $i=0 ; $i < intval( $_GET['iSortingCols'] ) ; $i++ )
95
+			for ($i = 0; $i < intval($_GET['iSortingCols']); $i++)
96 96
 			{
97
-				if ( $_GET[ 'bSortable_' . intval($_GET['iSortCol_' . $i]) ] == "true" )
97
+				if ($_GET['bSortable_'.intval($_GET['iSortCol_'.$i])] == "true")
98 98
 				{
99
-					$conditions['order'] = array('Venda.' . $aColumns[intval($_GET['iSortCol_' . $i])] => $_GET['sSortDir_'.$i]);
99
+					$conditions['order'] = array('Venda.'.$aColumns[intval($_GET['iSortCol_'.$i])] => $_GET['sSortDir_'.$i]);
100 100
 				}
101 101
 			}
102 102
 		}
103 103
 
104
-		if ( isset( $_GET['sSearch'] ) && !empty( $_GET['sSearch'] ) )
104
+		if (isset($_GET['sSearch']) && ! empty($_GET['sSearch']))
105 105
 		{
106
-			$conditions['conditions']['Venda.id LIKE '] = '%' . $_GET['sSearch'] . '%';
106
+			$conditions['conditions']['Venda.id LIKE '] = '%'.$_GET['sSearch'].'%';
107 107
 		}
108 108
 		
109 109
 		$vendas = $this->Venda->find('all', $conditions);
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		foreach ($vendas as $venda) {
119 119
 			$row = array();
120 120
 
121
-			for ( $i=0 ; $i < count($aColumns) ; $i++ )
121
+			for ($i = 0; $i < count($aColumns); $i++)
122 122
 			{
123 123
 				if ($aColumns[$i] == "forma_pagamento") {
124 124
 					$lancamento = $this->LancamentoVenda->find('first', array(
@@ -132,13 +132,13 @@  discard block
 block discarded – undo
132 132
 					$value = str_replace('_', ' ', $value);
133 133
 					$value = ucwords($value);
134 134
 				} else if ($aColumns[$i] == "actions") {
135
-		            $value = '<a href="javascript:printNotaNaoFiscal(' . $venda['Venda']['id'] . ');" target="_blank" class="btn btn-info">';
135
+		            $value = '<a href="javascript:printNotaNaoFiscal('.$venda['Venda']['id'].');" target="_blank" class="btn btn-info">';
136 136
 		            $value .= '<i class="fa fa-file-text" aria-hidden="true"></i>';
137 137
 		            $value .= '</a> ';
138 138
 
139
-					$value .= ' <button onclick="remover_venda(' . $venda['Venda']['id'] . ');" type="button" class="btn btn-danger"><i class="fa fa-times"></i></button>';
139
+					$value .= ' <button onclick="remover_venda('.$venda['Venda']['id'].');" type="button" class="btn btn-danger"><i class="fa fa-times"></i></button>';
140 140
 				} else if ($aColumns[$i] == "valor") { 
141
-					$value = 'R$ ' . number_format($venda['Venda'][$aColumns[$i]], 2, ',', '.');
141
+					$value = 'R$ '.number_format($venda['Venda'][$aColumns[$i]], 2, ',', '.');
142 142
 				} else {
143 143
 					$value = $venda['Venda'][$aColumns[$i]];
144 144
 				}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 				$row[] = $value;
147 147
 			}
148 148
 
149
-			$btEdit = '<a class="btn btn-info" href="/produto/editar_cadastro/' . $venda['Venda']['id'] . '"><i class="fa fa-pencil"></i></a>';
149
+			$btEdit = '<a class="btn btn-info" href="/produto/editar_cadastro/'.$venda['Venda']['id'].'"><i class="fa fa-pencil"></i></a>';
150 150
 
151 151
 			$row[] = $btEdit;
152 152
 
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
 			if ($produto[0]['Produto']['estoque'] <= 0)
250 250
 			{
251
-				$this->Session->setFlash('O produto (' . $produto[0]['Produto']['nome'] .') não tem mais estoque disponivel!');
251
+				$this->Session->setFlash('O produto ('.$produto[0]['Produto']['nome'].') não tem mais estoque disponivel!');
252 252
 				continue;
253 253
 			}
254 254
 			
@@ -265,11 +265,11 @@  discard block
 block discarded – undo
265 265
 	}
266 266
 
267 267
 	public function s_adicionar_cadastro() {
268
-		$dados_venda 	  = $this->request->data('venda');
268
+		$dados_venda = $this->request->data('venda');
269 269
 		$dados_lancamento = $this->request->data('lancamento');
270
-		$produtos 	      = $this->request->data('produto');
270
+		$produtos = $this->request->data('produto');
271 271
 
272
-		if (!$this->validar_itens_venda($produtos) && !$dados_venda['orcamento']) {
272
+		if ( ! $this->validar_itens_venda($produtos) && ! $dados_venda['orcamento']) {
273 273
 			$this->Session->setFlash('Algum produto adicionado não possui estoque disponivel');
274 274
 			$this->redirect('/venda/adicionar_cadastro');
275 275
 		}
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		
280 280
 		$salvar_venda = $this->salvar_venda($produtos, $dados_lancamento, $dados_venda);
281 281
 		
282
-		if (!$salvar_venda) {
282
+		if ( ! $salvar_venda) {
283 283
 			$this->Session->setFlash('Ocorreu um erro ao salvar a venda tente novamento');
284 284
 			$this->redirect('/venda/adicionar_cadastro');
285 285
 		}
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 
337 337
 			$objProdutoEstoqueController = new ProdutoEstoqueController();
338 338
 
339
-			if (!$objProdutoEstoqueController->validar_estoque($produto, $item['quantidade'])) {
339
+			if ( ! $objProdutoEstoqueController->validar_estoque($produto, $item['quantidade'])) {
340 340
 				return false;
341 341
 			}			
342 342
 		}
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 		$informacoes['valor']	   = $informacoes['valor'] - $informacoes['desconto'];
355 355
 		$informacoes['orcamento']  = @$informacoes['orcamento'];
356 356
 
357
-		if (!$this->Venda->save($informacoes)) {
357
+		if ( ! $this->Venda->save($informacoes)) {
358 358
 			$this->Session->setFlash('Ocorreu algum erro ao salvar a venda');
359 359
 			return false;
360 360
 		}
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	}
378 378
 
379 379
 	public function relatorio_diario() {
380
-		include(APP . 'Vendor/PHPExcel/PHPExcel.php');
381
-		include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php');
380
+		include(APP.'Vendor/PHPExcel/PHPExcel.php');
381
+		include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php');
382 382
 
383 383
         $objPHPExcel = new PHPExcel();
384 384
         // Definimos o estilo da fonte
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
                     ->setCellValue('A1', "Valor Venda")
392 392
                     ->setCellValue('B1', "Custo Médio ")
393 393
                     ->setCellValue("C1", "Valor Lucro")
394
-                    ->setCellValue('D1', "ID Venda" );
394
+                    ->setCellValue('D1', "ID Venda");
395 395
 
396 396
 
397 397
         $vendas = $this->Venda->find('all',
@@ -408,9 +408,9 @@  discard block
 block discarded – undo
408 408
         $i = 2;
409 409
         foreach ($vendas as $key => $venda) {
410 410
         	$objPHPExcel->setActiveSheetIndex(0)
411
-        				->setCellValue('A'.$i, 'R$ ' . $venda['Venda']['valor'])
412
-        				->setCellValue('B'.$i, 'R$ ' . $venda['Venda']['custo'])
413
-        				->setCellValue('C'.$i, 'R$ ' . $venda['Venda']['valor'] - $venda['Venda']['custo'])
411
+        				->setCellValue('A'.$i, 'R$ '.$venda['Venda']['valor'])
412
+        				->setCellValue('B'.$i, 'R$ '.$venda['Venda']['custo'])
413
+        				->setCellValue('C'.$i, 'R$ '.$venda['Venda']['valor'] - $venda['Venda']['custo'])
414 414
         				->setCellValue('D'.$i, $venda['Venda']['id']);
415 415
         	$i++;
416 416
         }
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
         exit;
435 435
 	}
436 436
 
437
-	public function recoverDataToDashboardOneWeek($id_usuario){
437
+	public function recoverDataToDashboardOneWeek($id_usuario) {
438 438
 		$vendas = $this->Venda->find('all',
439 439
 			array('conditions' =>
440 440
 				array(
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
 		
501 501
 		$ImpressaoFiscalController->userName = $usuario['Usuario']['nome'];
502 502
 
503
-		$ImpressaoFiscalController->corpoTxt .= "Valor: R$ " . number_format($dados_venda['Venda']['valor'], 2, ',', '.') . "\n\n";
503
+		$ImpressaoFiscalController->corpoTxt .= "Valor: R$ ".number_format($dados_venda['Venda']['valor'], 2, ',', '.')."\n\n";
504 504
 		
505 505
 		$dados_lancamento = $this->LancamentoVenda->find('first',
506 506
 			array('conditions' => 
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 			)
512 512
 		);
513 513
 
514
-		$ImpressaoFiscalController->corpoTxt .= "Forma de Pagamento: " . $dados_lancamento['LancamentoVenda']['forma_pagamento'] . "\n\n";
514
+		$ImpressaoFiscalController->corpoTxt .= "Forma de Pagamento: ".$dados_lancamento['LancamentoVenda']['forma_pagamento']."\n\n";
515 515
 		
516 516
 		$produtos = $this->VendaItensProduto->find('all', 
517 517
 			array('conditions' =>
@@ -532,10 +532,10 @@  discard block
 block discarded – undo
532 532
 			$total = $produto['Produto']['preco'] * $item['VendaItensProduto']['quantidade_produto'];
533 533
 
534 534
 			$ImpressaoFiscalController->corpoTxt .= ""
535
-						   . "Produto: " . $produto['Produto']['nome']
536
-						   . "\nQuantidade: " . $item['VendaItensProduto']['quantidade_produto'] 
537
-						   . "\nPreço: R$ " . number_format($produto['Produto']['preco'], 2, ',', '.')
538
-						   . "\nTotal: R$ " . number_format($total, 2, ',', '.')
535
+						   . "Produto: ".$produto['Produto']['nome']
536
+						   . "\nQuantidade: ".$item['VendaItensProduto']['quantidade_produto'] 
537
+						   . "\nPreço: R$ ".number_format($produto['Produto']['preco'], 2, ',', '.')
538
+						   . "\nTotal: R$ ".number_format($total, 2, ',', '.')
539 539
 						   . "\n--------------------------\n";
540 540
 		}
541 541
 
@@ -579,14 +579,14 @@  discard block
 block discarded – undo
579 579
 		$lancamentos = array();
580 580
 
581 581
 		foreach ($vendas as $i => $venda) {
582
-			$lancamento =  $this->LancamentoVenda->find('first', array(
582
+			$lancamento = $this->LancamentoVenda->find('first', array(
583 583
 					'conditions' => array(
584 584
 						'LancamentoVenda.venda_id' => $venda['Venda']['id']
585 585
 					)
586 586
 				)
587 587
 			);
588 588
 
589
-			if (!empty($lancamento))
589
+			if ( ! empty($lancamento))
590 590
 				$lancamentos[] = $lancamento;
591 591
 		}
592 592
 
Please login to merge, or discard this patch.