Completed
Push — master ( 9103a3...e8d6b4 )
by Reginaldo
18:58
created
app/Controller/VendaController.php 1 patch
Spacing   +40 added lines, -40 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(
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
 
131 131
 					$value = (isset($lancamento['LancamentoVenda']['forma_pagamento'])) ? $lancamento['LancamentoVenda']['forma_pagamento'] : array();
132 132
 					
133
-					if (isset($value) && !empty($value))
133
+					if (isset($value) && ! empty($value))
134 134
 						$value = str_replace('_', ' ', $value);
135 135
 					
136
-					if (isset($value) && !empty($value))
136
+					if (isset($value) && ! empty($value))
137 137
 						$value = ucwords($value);
138 138
 				} else if ($aColumns[$i] == "actions") {
139
-		            $value = '<a href="javascript:printNotaNaoFiscal(' . $venda['Venda']['id'] . ');" target="_blank" class="btn btn-info">';
139
+		            $value = '<a href="javascript:printNotaNaoFiscal('.$venda['Venda']['id'].');" target="_blank" class="btn btn-info">';
140 140
 		            $value .= '<i class="fa fa-file-text" aria-hidden="true"></i>';
141 141
 		            $value .= '</a> ';
142 142
 
143
-					$value .= ' <a onclick="remover_venda(' . $venda['Venda']['id'] . ');" id="' . $venda['Venda']['id'] . '" type="button" class="btn btn-danger"><i class="fa fa-times"></i></a>';
143
+					$value .= ' <a onclick="remover_venda('.$venda['Venda']['id'].');" id="'.$venda['Venda']['id'].'" type="button" class="btn btn-danger"><i class="fa fa-times"></i></a>';
144 144
 				} else if ($aColumns[$i] == "valor") { 
145
-					$value = 'R$ ' . number_format($venda['Venda'][$aColumns[$i]], 2, ',', '.');
145
+					$value = 'R$ '.number_format($venda['Venda'][$aColumns[$i]], 2, ',', '.');
146 146
 				} else {
147 147
 					$value = $venda['Venda'][$aColumns[$i]];
148 148
 				}
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 				$row[] = $value;
151 151
 			}
152 152
 
153
-			$btEdit = '<a class="btn btn-info" href="/produto/editar_cadastro/' . $venda['Venda']['id'] . '"><i class="fa fa-pencil"></i></a>';
153
+			$btEdit = '<a class="btn btn-info" href="/produto/editar_cadastro/'.$venda['Venda']['id'].'"><i class="fa fa-pencil"></i></a>';
154 154
 
155 155
 			$row[] = $btEdit;
156 156
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 			if ($produto[0]['Produto']['estoque'] <= 0)
254 254
 			{
255
-				$this->Session->setFlash('O produto (' . $produto[0]['Produto']['nome'] .') não tem mais estoque disponivel!');
255
+				$this->Session->setFlash('O produto ('.$produto[0]['Produto']['nome'].') não tem mais estoque disponivel!');
256 256
 				continue;
257 257
 			}
258 258
 			
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 	}
270 270
 
271 271
 	public function s_adicionar_cadastro() {
272
-		$dados_venda 	  = $this->request->data('venda');
272
+		$dados_venda = $this->request->data('venda');
273 273
 		$dados_lancamento = $this->request->data('lancamento');
274
-		$produtos 	      = $this->request->data('produto');
274
+		$produtos = $this->request->data('produto');
275 275
 
276
-		if (!$this->validar_itens_venda($produtos) && !$dados_venda['orcamento']) {
276
+		if ( ! $this->validar_itens_venda($produtos) && ! $dados_venda['orcamento']) {
277 277
 			$this->Session->setFlash('Algum produto adicionado não possui estoque disponivel');
278 278
 			$this->redirect('/venda/adicionar_cadastro');
279 279
 		}
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 		
284 284
 		$salvar_venda = $this->salvar_venda($produtos, $dados_lancamento, $dados_venda);
285 285
 		
286
-		if (!$salvar_venda) {
286
+		if ( ! $salvar_venda) {
287 287
 			$this->Session->setFlash('Ocorreu um erro ao salvar a venda tente novamento');
288 288
 			$this->redirect('/venda/adicionar_cadastro');
289 289
 		}
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 
342 342
 			$objProdutoEstoqueController = new ProdutoEstoqueController();
343 343
 
344
-			if (!$objProdutoEstoqueController->validar_estoque($produto, $item['quantidade'])) {
344
+			if ( ! $objProdutoEstoqueController->validar_estoque($produto, $item['quantidade'])) {
345 345
 				return false;
346 346
 			}			
347 347
 		}
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 		$informacoes['valor']	   = $informacoes['valor'] - $informacoes['desconto'];
360 360
 		$informacoes['orcamento']  = @$informacoes['orcamento'];
361 361
 
362
-		if (!$this->Venda->save($informacoes)) {
362
+		if ( ! $this->Venda->save($informacoes)) {
363 363
 			$this->Session->setFlash('Ocorreu algum erro ao salvar a venda');
364 364
 			return false;
365 365
 		}
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 	}
383 383
 
384 384
 	public function relatorio_diario() {
385
-		include(APP . 'Vendor/PHPExcel/PHPExcel.php');
386
-		include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php');
385
+		include(APP.'Vendor/PHPExcel/PHPExcel.php');
386
+		include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php');
387 387
 
388 388
         $objPHPExcel = new PHPExcel();
389 389
         // Definimos o estilo da fonte
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
                     ->setCellValue('A1', "Valor Venda")
397 397
                     ->setCellValue('B1', "Custo Médio ")
398 398
                     ->setCellValue("C1", "Valor Lucro")
399
-                    ->setCellValue('D1', "ID Venda" );
399
+                    ->setCellValue('D1', "ID Venda");
400 400
 
401 401
 
402 402
         $vendas = $this->Venda->find('all',
@@ -413,9 +413,9 @@  discard block
 block discarded – undo
413 413
         $i = 2;
414 414
         foreach ($vendas as $key => $venda) {
415 415
         	$objPHPExcel->setActiveSheetIndex(0)
416
-        				->setCellValue('A'.$i, 'R$ ' . $venda['Venda']['valor'])
417
-        				->setCellValue('B'.$i, 'R$ ' . $venda['Venda']['custo'])
418
-        				->setCellValue('C'.$i, 'R$ ' . $venda['Venda']['valor'] - $venda['Venda']['custo'])
416
+        				->setCellValue('A'.$i, 'R$ '.$venda['Venda']['valor'])
417
+        				->setCellValue('B'.$i, 'R$ '.$venda['Venda']['custo'])
418
+        				->setCellValue('C'.$i, 'R$ '.$venda['Venda']['valor'] - $venda['Venda']['custo'])
419 419
         				->setCellValue('D'.$i, $venda['Venda']['id']);
420 420
         	$i++;
421 421
         }
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
         exit;
440 440
 	}
441 441
 
442
-	public function recoverDataToDashboardOneWeek($id_usuario){
442
+	public function recoverDataToDashboardOneWeek($id_usuario) {
443 443
 		$vendas = $this->Venda->find('all',
444 444
 			array('conditions' =>
445 445
 				array(
@@ -536,19 +536,19 @@  discard block
 block discarded – undo
536 536
 			$totalGeral += $total;
537 537
 
538 538
 			$ImpressaoFiscalController->corpoTxt .= ""
539
-						   . "Produto: " . $produto['Produto']['nome']
540
-						   . "\nQuantidade: " . $item['VendaItensProduto']['quantidade_produto'] 
541
-						   . "\nPreço: R$ " . number_format($produto['Produto']['preco'], 2, ',', '.')
542
-						   . "\nTotal: R$ " . number_format($total, 2, ',', '.')
539
+						   . "Produto: ".$produto['Produto']['nome']
540
+						   . "\nQuantidade: ".$item['VendaItensProduto']['quantidade_produto'] 
541
+						   . "\nPreço: R$ ".number_format($produto['Produto']['preco'], 2, ',', '.')
542
+						   . "\nTotal: R$ ".number_format($total, 2, ',', '.')
543 543
 						   . "\n--------------------------\n";
544 544
 		}
545 545
 
546 546
 		$desconto = $totalGeral - $dados_venda['Venda']['valor'];
547 547
 
548
-		$ImpressaoFiscalController->corpoTxt .= "Valor Total: " . number_format($totalGeral, 2, ',', '.') . "\n\n";
549
-		$ImpressaoFiscalController->corpoTxt .= "Valor Pago: R$ " . number_format($dados_venda['Venda']['valor'], 2, ',', '.') . "\n";
550
-		$ImpressaoFiscalController->corpoTxt .= "Desconto: R$ " . number_format($desconto, 2, ',', '.') . "\n\n";
551
-		$ImpressaoFiscalController->corpoTxt .= "Forma de Pagamento: " . $dados_lancamento['LancamentoVenda']['forma_pagamento'] . "\n\n";
548
+		$ImpressaoFiscalController->corpoTxt .= "Valor Total: ".number_format($totalGeral, 2, ',', '.')."\n\n";
549
+		$ImpressaoFiscalController->corpoTxt .= "Valor Pago: R$ ".number_format($dados_venda['Venda']['valor'], 2, ',', '.')."\n";
550
+		$ImpressaoFiscalController->corpoTxt .= "Desconto: R$ ".number_format($desconto, 2, ',', '.')."\n\n";
551
+		$ImpressaoFiscalController->corpoTxt .= "Forma de Pagamento: ".$dados_lancamento['LancamentoVenda']['forma_pagamento']."\n\n";
552 552
 
553 553
 		$file = $ImpressaoFiscalController->gerar_arquivo();
554 554
 		
@@ -590,14 +590,14 @@  discard block
 block discarded – undo
590 590
 		$lancamentos = array();
591 591
 
592 592
 		foreach ($vendas as $i => $venda) {
593
-			$lancamento =  $this->LancamentoVenda->find('first', array(
593
+			$lancamento = $this->LancamentoVenda->find('first', array(
594 594
 					'conditions' => array(
595 595
 						'LancamentoVenda.venda_id' => $venda['Venda']['id']
596 596
 					)
597 597
 				)
598 598
 			);
599 599
 
600
-			if (!empty($lancamento))
600
+			if ( ! empty($lancamento))
601 601
 				$lancamentos[] = $lancamento;
602 602
 		}
603 603
 
Please login to merge, or discard this patch.