Created
March 20, 2013 16:41
-
-
Save dodopok/5206179 to your computer and use it in GitHub Desktop.
Filtro CakePHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--VIEW--> | |
<div class="notas all"> | |
<?php | |
echo $this->Html->script(array('mask')); | |
echo $this->Html->script(array('jquery.contextMenu')); | |
echo $this->Html->css(array('jquery.contextMenu')); | |
?> | |
<script> | |
function Mask(){ | |
$(".CPF").mask("999.999.999-99"); | |
$(".data").mask("99/99/9999"); | |
$(".CNPJ").mask("99.999.999/9999-99"); | |
$(".CEP").mask("99999-999"); | |
$(".telefone").mask("(99) 9999-9999"); | |
$('#chave').mask('99999999999999999999999999999999999999999999'); | |
} | |
</script> | |
<style> | |
table tr td { | |
padding-top: 10px; | |
} | |
</style> | |
<div class="search" style="width:900px;float:left;"> | |
<?php echo $this->Form->create(array('action' => '../nfes/', 'type' => 'GET')); ?> | |
<h4 style="display:inline;">Filtros:</h4> | |
<br/><br/> | |
<?php | |
$options = array('' => 'Todas','1' => 'Entrada', '0' => 'Saída', '2' => 'Reentrada'); | |
echo $this->Form->input('tipoNF', array('options' => $options,'name' => 'tipoNF','label' => 'Tipo de Nota:','default' => '')); | |
echo $this->Form->input('ide_serie', array('type' => 'text','size' => 5,'name' => 'ide_serie','label' => 'Série:')); | |
echo $this->Form->input('ide_nNF', array('name' => 'ide_nNF_de','size' => 5,'label' => 'Número de:', 'type' => 'text')); | |
echo $this->Form->input('ide_nNF', array('name' => 'ide_nNF_ate','size' => 5,'label' => 'Número até:', 'type' => 'text')); | |
echo $this->Form->input('ide_dEmi', array('class' => 'data','name' => 'ide_dEmi_fromdate','size' => 15,'label' => 'Emissão de:', 'type' => 'text')); | |
echo $this->Form->input('ide_dEmi', array('class' => 'data','name' => 'ide_dEmi_todate','size' => 15,'label' => 'Emissão até:', 'type' => 'text')); | |
echo $this->Form->input('infNFe_Id', array('size' => 44,'name' => 'infNFe_Id','id' => 'chave','label' => 'Chave da nota:')); | |
echo '<br/><br/><br/><br/>'; | |
echo $this->Form->input('emit_xNome', array('size' => 74,'name' => 'emit_xNome','label' => 'Nome do Emitente:')); | |
echo $this->Form->input('emit_CNPJ', array('size' => 15,'name' => 'emit_CNPJ','class' => 'CNPJ','label' => 'CNPJ do Emitente:')); | |
echo $this->Form->input('enderEmit_xMun', array('size' => 15,'name' => 'enderEmit_xMun','label' => 'Município do Emitente:')); | |
echo $this->Form->input('estados', array('label' => 'UF do Destinatário:', 'name' => 'enderEmit_UF')); | |
echo '<br/><br/><br/><br/>'; | |
echo $this->Form->input('dest_xNome', array('size' => 74,'name' => 'dest_xNome','label' => 'Nome do Destinatário:')); | |
echo $this->Form->input('dest_CNPJ', array('size' => 25,'name' => 'dest_CNPJ','class' => 'CNPJ','label' => 'CNPJ do Destinatário:')); | |
echo $this->Form->input('dest_CPF', array('size' => 15,'name' => 'dest_CPF','class' => 'CPF','label' => 'CPF do Destinatário:')); | |
echo $this->Form->input('enderDest_xMun', array('size' => 15,'name' => 'enderDest_xMun','label' => 'Município do Destinatário:')); | |
echo $this->Form->input('estados', array('label' => 'UF do Destinatário:', 'name' => 'enderDest_UF')); | |
echo '<br/><br/><br/><br/>'; | |
$options = array('' => 'Selecione:','Autorizado' => 'Autorizada','Carta' => 'Carta de Correção', 'Cancelamento' => 'Cancelada', 'Denegada' => 'Denegada', 'Lote' => 'Lote em processamento', 'Verificada' => 'Não Verificada'); | |
echo $this->Form->input('infProt_xMotivo', array('options' => $options,'name' => 'infProt_xMotivo','label' => 'Situação:','default' => '1')); | |
$options = array('' => 'Selecione:','1' => 'Sim','0' => 'Não'); | |
echo $this->Form->input('baixada', array('options' => $options,'name' => 'baixada','label' => 'Baixada:','default' => '')); | |
?> | |
<br/><br/><br/><br/> | |
<input type="submit" name="submit" value="Pesquisar"/> | |
<?php echo $this->Form->end(); ?> | |
</div> | |
<div class="upload" style="width:300px;float:left;"> | |
<h4><?php echo __('Enviar Notas'); ?></h4> | |
<?php | |
echo $this->Form->create('Nfe', array('type' => 'file', 'action' => '/../nfes/importar', 'id' => 'importarForm')); | |
echo $this->Form->input('files.', array('type' => 'file', 'multiple','onChange' => '$("#importarForm").submit();')); | |
echo $this->Form->end(); | |
echo '<br/><br/><br/>'; | |
if(!empty($retorno)){ | |
echo $retorno; | |
} | |
?> | |
</div> | |
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> | |
<h2><?php echo __('Notas'); ?></h2> | |
<table cellpadding="0" cellspacing="0"> | |
<tr> | |
<th><?php echo $this->Paginator->sort('ide_serie', 'Série'); ?></th> | |
<th><?php echo $this->Paginator->sort('ide_nNF', 'Número'); ?></th> | |
<th><?php echo $this->Paginator->sort('ide_dEmi', 'Data Emissão'); ?></th> | |
<th><?php echo $this->Paginator->sort('enderDest_UF', 'UF Destino'); ?></th> | |
<th><?php echo $this->Paginator->sort('emit_xNome', 'Emitente'); ?></th> | |
<th><?php echo $this->Paginator->sort('dest_xNome', 'Destinatário'); ?></th> | |
<th><?php echo $this->Paginator->sort('ICMSTot_vNF', 'Valor'); ?></th> | |
<th><?php echo $this->Paginator->sort('infProt_xMotivo', 'Status'); ?></th> | |
<th><?php echo $this->Paginator->sort('tipoNF', 'Tipo de Nota'); ?></th> | |
<th><?php echo $this->Paginator->sort('tipoNF', 'Baixada'); ?></th> | |
<th class="actions"></th> | |
</tr> | |
<?php | |
$cStat = array(100, 103, 104, 105); | |
foreach ($notas as $nota): | |
if($nota['Nfe']['infProt_tpAmb']==2){ | |
$nota['Nfe']['infProt_tpAmb'] = 'Homologação'; | |
}elseif($nota['Nfe']['infProt_tpAmb']==1){ | |
$nota['Nfe']['infProt_tpAmb'] = 'Produção'; | |
} | |
?> | |
<tr> | |
<td><?php echo h($nota['Nfe']['ide_serie']);?></td> | |
<td><?php echo h($nota['Nfe']['ide_nNF']); ?></td> | |
<td><?php echo h(implode('/', array_reverse(explode('-', $nota['Nfe']['ide_dEmi'])))); ?></td> | |
<td><?php echo h($nota['Nfe']['enderDest_UF']); ?></td> | |
<td><?php echo h($nota['Nfe']['emit_xNome']); ?></td> | |
<td><?php echo h($nota['Nfe']['dest_xNome']); ?></td> | |
<td><?php echo 'R$ '.number_format($nota['Nfe']['ICMSTot_vNF'], 2, ',', '.'); ?></td> | |
<td><?php if(!empty($nota['Nfe']['infCanc_xEvento'])){echo h($nota['Nfe']['infCanc_xEvento']);}elseif(!empty($nota['Nfe']['infCCe_xEvento'])){echo h($nota['Nfe']['infCCe_xEvento']);}else{echo h($nota['Nfe']['infProt_xMotivo']);} ?></td> | |
<td><?php | |
switch ($nota['Nfe']['tipoNF']) { | |
case 0: | |
$tipoNF = 'Saída'; | |
break; | |
case 1: | |
$tipoNF = 'Entrada'; | |
break; | |
case 2: | |
$tipoNF = 'Reentrada'; | |
break; | |
} | |
echo $tipoNF; | |
?></td> | |
<td><?php | |
switch ($nota['Nfe']['baixada']) { | |
case 0: | |
$baixada = 'Não'; | |
break; | |
case 1: | |
$baixada = 'Sim'; | |
break; | |
} | |
echo $baixada; | |
?></td> | |
<td class="actions"> | |
<div class="btn-group"> | |
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> | |
Ações | |
<span class="caret"></span> | |
</a> | |
<ul class="dropdown-menu"> | |
<?php if(in_array($nota['Nfe']['infProt_cStat'], $cStat)){ ?> | |
<li class="xml"><a href="/sistema/emissor/notas/consulta/<?php echo $nota['Nfe']['id'] ?>" class="context">Atualizar</a></li> | |
<?php } ?> | |
<li class="danfe"><a href="/sistema/emissor/notas/danfe/<?php echo $nota['Nfe']['id'] ?>" class="context">DANFE</a></li> | |
<?php if($nota['Nfe']['infCCe_cStat'] == '135'){ ?> | |
<li class="dacce"><a href="/sistema/emissor/notas/dacce/<?php echo $nota['Nfe']['id'] ?>" class="context">DACCE</a></li> | |
<?php } ?> | |
<li class="duplicata"><a href="/sistema/emissor/notas/duplicata/<?php echo $nota['Nfe']['id'] ?>" class="context">Duplicatas</a></li> | |
<?php if($nota['Nfe']['infProt_cStat'] == '100'){ ?> | |
<li class="xml"><a href="/sistema/emissor/notas/baixa/<?php echo $nota['Nfe']['id'] ?>" class="context">XML</a></li> | |
<li class="email"><a href="/sistema/emissor/notas/envia/<?php echo $nota['Nfe']['id'] ?>" class="context">Enviar por E-mail</a></li> | |
<?php } ?> | |
<?php if(!in_array($nota['Nfe']['infProt_cStat'], $cStat)){ ?> | |
<li class="exclui"><a href="/sistema/emissor/notas/exclui/<?php echo $nota['Nfe']['id'] ?>" class="context">Excluir</a></li> | |
<?php } ?> | |
</ul> | |
</div> | |
</td> | |
</tr> | |
<?php endforeach; ?> | |
<script> | |
Mask(); | |
</script> | |
</table> | |
<?php echo $this->Form->end(); ?> | |
<br/> | |
<p> | |
<?php | |
echo $this->Paginator->counter(array( | |
'format' => __('Página {:page} de {:pages}, mostrando {:current} cadastros de {:count}, começando no {:start}, até o {:end}') | |
)); | |
?> </p> | |
<div class="paging"> | |
<?php | |
echo $this->Paginator->prev('< ' . __('Anterior'), array(), null, array('class' => 'prev disabled')); | |
echo $this->Paginator->numbers(array('separator' => '')); | |
echo $this->Paginator->next(__('Próxima') . ' >', array(), null, array('class' => 'next disabled')); | |
?> | |
</div> | |
</div> | |
<!--FUNCTION DO CONTROLLER--> | |
<?php | |
public function index(){ | |
$this->set('title_for_layout', 'NFe'); | |
$this->Nfe->recursive = -1; | |
$arraycerta = array(); | |
$pi = false; | |
$conditions = array(); | |
$this->request->data = $this->request->query; | |
unset($this->request->data['submit']); | |
foreach($this->request->data as $key => $value){ | |
//Para filtrar campos de data | |
if($key == 'ide_dEmi_todate' || $key == 'ide_dEmi_fromdate'){ | |
if(!$pi){ | |
if(!empty($value)){ | |
$this->request->data['ide_dEmi_fromdate'] = implode('-', array_reverse(explode('/', $this->request->data['ide_dEmi_fromdate']))); | |
$this->request->data['ide_dEmi_todate'] = implode('-', array_reverse(explode('/', $this->request->data['ide_dEmi_todate']))); | |
$key = str_replace('_fromdate', '', $key); | |
$key = str_replace('_todate', '', $key); | |
$arraycerta[$key.' >= '] = $this->request->data['ide_dEmi_fromdate']; | |
$arraycerta[$key.' <= '] = $this->request->data['ide_dEmi_todate']; | |
unset($this->request->data['ide_dEmi_todate']); | |
unset($this->request->data['ide_dEmi_fromdate']); | |
$pi = true; | |
} | |
} | |
}elseif($key == 'ide_nNF_de' || $key == 'ide_nNF_ate'){ | |
if(!$pi){ | |
if(!empty($value)){ | |
$this->request->data['ide_nNF_de'] = implode('-', array_reverse(explode('/', $this->request->data['ide_nNF_de']))); | |
$this->request->data['ide_nNF_ate'] = implode('-', array_reverse(explode('/', $this->request->data['ide_nNF_ate']))); | |
$key = str_replace('_de', '', $key); | |
$key = str_replace('_ate', '', $key); | |
$arraycerta[$key.' >= '] = $this->request->data['ide_nNF_de']; | |
$arraycerta[$key.' <= '] = $this->request->data['ide_nNF_ate']; | |
unset($this->request->data['ide_nNF_de']); | |
unset($this->request->data['ide_nNF_ate']); | |
$pi = true; | |
} | |
} | |
}else{ | |
if($key == 'tipoNF'){ | |
if($value === '0'){ | |
$value = '10'; | |
} | |
} | |
if(!empty($value)){ | |
if($key == 'tipoNF' && $value == '10'){ | |
$value = '0'; | |
} | |
$value = str_replace('-', '', $value); | |
$value = str_replace('/', '', $value); | |
$value = str_replace('.', '', $value); | |
} | |
} | |
} | |
$this->request->data = $arraycerta; | |
$conditions = array_merge($this->request->data,$conditions); | |
$conditions['Nfe.group_id = '] = $this->Session->read('choosed'); | |
$this->paginate = array('limit' => 30, 'order' => array('Nfe.ide_dEmi' => 'desc', 'ide_nNF' => 'desc')); | |
$this->set('notas', $this->paginate(null,$conditions)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment