Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

gustalevin

Preencher um boleto com dados de uma linha após seleção da mesma

Recommended Posts

Em um site feito em PHP e Javascript, que assumi de outro desenvolvedor, eu possuo uma seção de consulta e impressão de boletos bancários. Já fiz toda a estrutura do boleto e também uma busca SQL que me traz uma lista de boletos.

 

Eu precisaria fazer agora o seguinte: quando eu seleciono uma linha do meu resultado da consulta SQL, que o meu boleto apareça preenchido com os dados dessa linha.

 

Abaixo os prints de como está o site. Primeiro um exemplo de resultado de busca (cobri algumas informações por segurança) e depois como aparece o boleto depois de clicar em Visualizar:

4mater.jpg

I1gN1A.jpg

E abaixo os códigos da página. O desenvolvedor de quem assumi o site utiliza além do arquivo básico PHP e do arquivo básico JS mais dois arquivos: um que fica no diretório Model e outro que fica no diretório Controller.

 

emissaoBoletos.php (lista de boletos no divBoletoLista e tela do boleto no divTelaBoleto)

<div class="pagina">
	<div class="main">
		<div id="conteudo">
			<div class="titulointernas">
				<span class="span_titop"><span class="span_benvindo">{label_emissaoBoletos_emissao}</span>   {label_emissaoBoletos_deboletos}</span>
			</div>
			<div class="imgglossary">
				<a onclick="abrirGlossario('http://www.hotelinvest.com.br/glossario','1000','800','scrollbars=yes');" style="cursor:pointer">
					<br>
					<span class="spbtglossario">{label_emissaoBoletos_acesse}</span>
					<span class="sppglossario">{label_emissaoBoletos_glossario}</span>
					<span class="spbtglossario">{label_emissaoBoletos_hotel}</span>
				</a>
			</div>
			<div id="oportunidadesanunciadasAD">{label_emissaoBoletos_textocab}</div>
			<div class="divFiltros">
				<span class="span_benvindo">{label_emissaoBoletos_textofiltros}</span><br/><br/>
				<span class="filtros" style="margin-left: 0px;">{label_emissaoBoletos_unidade}<select id="comboUnidades"></select></span><br/>
				<span class="filtros">{label_emissaoBoletos_dataentre} <input type="text" id="txtData1"/> {label_emissaoBoletos_datae} <input type="text" id="txtData2"/></span>
				<span class="filtros" style="margin-left: 20px;"><input class="botaoCad" type="button" value="{label_emissaoBoletos_buscar}" style="float:none" onclick="buscaBoletos()"></span>
			</div><br/>
			<div id="divBoletosLista" class="divTabela" style="display:none;width: 98%;overflow: scroll;height: 380px">
				<table id="tableBoletosLista" class="tables" border="1" style="width: 100%;border-collapse: collapse;font-size:11px;text-align: center;">
					<thead>
						<tr>
							<th>#</th>
							<th style="text-align:left; width: 300px">{label_emissaoBoletos_razaosocial}</th>
							<th style="width: 100px">{label_emissaoBoletos_nossonumero}</th>
							<th style="width: 100px">{label_emissaoBoletos_numerodocumento}</th>
							<th style="width: 80px">{label_emissaoBoletos_valor}</th>
							<th style="width: 100px">{label_emissaoBoletos_dataemissao}</th>
							<th style="width: 100px">{label_emissaoBoletos_datavencimento}</th>
							<th></th>
						</tr>	
					</thead>
					<tbody id="bodyBoletosLista">
					</tbody>
				</table>
			</div>
			<div id="divTelaBoleto" style="font-family: Arial;">
				<div>
					<table cellspacing=0 cellpadding=0 width=700px style="border-style: none; border-bottom-style: solid; border-size: 1px; border-color: black;">
						<tbody>
							<tr>
								<td width=200px><div align=left><img src="{raiz}images/layout/logohsbc.jpg" style="width: 72px; height: 15px;"></div></td>
								<td><div align=right style="font-size: 16px; border-left-style: solid; border-right-style: solid;">399    </div></td>
								<td width=700px><div align=right><b>RECIBO DO SACADO</b></div></td>
							</tr>
						</tbody>
					</table>
					<table cellspacing=0 cellpadding=0 width=700px border=0 >
						<tbody>
							<tr>
								<td align=left colspan='6' style="border-style: none; border-color: gray; border-bottom-style: solid; border-right-style: solid; border-size: 1px;"><i>Local de Pagamento</i><br>    Pagável na rede bancária até o vencimento.</td>
								<td rowspan='7' style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px;"></td>
							</tr>
							<tr><td align=left colspan='6' style="border-style: none; border-color: gray; border-right-style: solid; border-size: 1px;" ><i>Cedente</i><br><input type="text" id="cedDoc1" class="valueBoleto" disabled="true" value="NOME DO CEDENTE" /></td></tr>
							<tr>
								<td align=left style="border-style: solid; border-color: gray; border-left-style: none; border-right-style: none; border-bottom-style: none; border-size: 1px"><i>Data do Documento</i><br><input type="text" id="dataDoc1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-bottom-style: none; border-size: 1px" colspan='2'><i>No. do Documento</i><br><input type="text" id="numDoc1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-bottom-style: none; border-size: 1px"><i>Espécie Doc</i><br><input type="text" id="espDoc1" class="valueBoleto" style="width: 50px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-bottom-style: none; border-size: 1px"><i>Aceite</i><br><input type="text" id="aceDoc1" class="valueBoleto" style="width: 50px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-bottom-style: none; border-size: 1px"><i>Data de Processamento</i><br><input type="text" id="dataProc1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
							</tr>
							<tr>
								<td align=left style="border-style: solid; border-color: gray; border-left-style: none; border-right-style: none; border-size: 1px"><i>No. da Conta/Respo</i><br><input type="text" id="numConta1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-size: 1px"><i>Carteira</i><br><input type="text" id="carDoc1" class="valueBoleto" style="width: 50px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-size: 1px"><i>Espécie</i><br><input type="text" id="espDoc1" class="valueBoleto" style="width: 50px" disabled="true" value="R$" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-size: 1px" colspan='2'><i>Quantidade</i><br><input type="text" id="quantDoc1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-size: 1px"><i>Valor</i><br><input type="text" id="valor1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
							</tr>
							<tr>
								<td align=left rowspan='11' colspan='6' style="vertical-align: text-top; border-style: solid; border-color: gray; border-left-style: none; border-top-style: none; border-size: 1px"><i>Instruções (Texto de responsabilidade do cedente)</i><br><input type="text" id="instDoc1" class="valueBoleto" style="width: 400px" disabled="true" /></td>
							</tr>
							<tr><td></td></tr>
							<tr><td></td></tr>
							<tr>
								<td colspan='6'></td>
								<td align=left style="border-style: none; border-color: gray; border-top-style: solid; border-bottom-style: solid; border-size: 1px"><i>Vencimento</i><br><input type="text" id="vencDoc1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
							</tr>
							<tr>
								<td colspan='6'></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>Nosso Número</i><br><input type="text" id="nossoNum1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
							</tr>
							<tr>
								<td colspan='6'></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( = ) Valor do Documento</i><br><input type="text" id="valDoc1" class="valueBoleto" style="width: 100px" disabled="true" /></td>
							</tr>
							<tr>
								<td colspan='6'></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( - ) Desconto</i><br>    </td>
							</tr>
							<tr>
								<td colspan='6'></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( - ) Outras Deduções / Abatimento</i><br>    </td>
							</tr>
							<tr>
								<td colspan='6'></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( + ) Mora / Multa / Juros</i><br>    </td>
							</tr>
							<tr>
								<td colspan='6'></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( + ) Outros Acréscimos</i><br>    </td>
							</tr>
							<tr>
								<td colspan='6'></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( = ) Valor Cobrado</i><br>    </td>
							</tr>
						</tbody>
					</table>
					<table cellspacing=0 cellpadding=0 width=700px border=0 >
						<tbody>
							<tr>
								<td align=left style="border-style: none"><i>Sacado:</i><br><input type="text" id="sacado1" class="valueBoleto" style="height: 24px; width: 400px" disabled="true" /></td>
							</tr>
							<tr>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>Sacador/Avalista:</i></td>
								<td align=right style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>Código de Baixa</i>        5593</td>
							</tr>
							<tr>
								<td></td><td align=right style="text-align: center"><fieldset style="border-bottom-style: none; border-right-style: none; margin-bottom: 5px;"><legend>Autenticação Mecânica</legend></fieldset></td>
							</tr>
							<tr>
								<td style="border-style: dashed; border-width: 1px"></td>
								<td style="border-style: dashed; border-width: 1px"></td>
							</tr>
						</tbody>
					</table>
					<table cellspacing=0 cellpadding=0 width=700px style="margin-top: 5px; border-style: none; border-bottom-style: solid; border-size: 1px; border-color: black;">
						<tbody>
							<tr>
								<td width=200px><div align=left><img src="{raiz}images/layout/logohsbc.jpg" style="width: 72px; height: 15px;"></div></td>
								<td><div align=right style="font-size: 16px; border-left-style: solid; border-right-style: solid;">399    </div></td>
								<td width=700px><input type="text" id="barCode1" class="valueBoleto" style="height: 16px; width: 500px; font-size: 16px" disabled="true" /></td>
							</tr>
						</tbody>
					</table>
					<table cellspacing=0 cellpadding=0 width=700px border=0 >
						<tbody>
							<tr>
								<td align=left colspan='6' style="border-style: none; border-color: gray; border-bottom-style: solid; border-right-style: solid; border-size: 1px;"><i>Local de Pagamento</i><br>    Pagável na rede bancária até o vencimento.</td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>Vencimento</i><br><input type="text" id="vencDoc2" class="valueBoleto" style="width: 100px" disabled="true" /></td>
							</tr>
							<tr><td align=left colspan='6' style="border-style: none; border-color: gray; border-right-style: solid; border-size: 1px;" ><i>Cedente</i><br><input type="text" id="cedDoc2" class="valueBoleto" disabled="true" value="NOME DO CEDENTE" /></td>
							<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>Nosso Número</i><br><input type="text" id="nossoNum2" class="valueBoleto" style="width: 100px" disabled="true" /></td></tr>
							<tr>
								<td align=left style="border-style: solid; border-color: gray; border-left-style: none; border-right-style: none; border-bottom-style: none; border-size: 1px"><i>Data do Documento</i><br><input type="text" id="dataDoc2" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-bottom-style: none; border-size: 1px" colspan='2'><i>No. do Documento</i><br><input type="text" id="numDoc2" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-bottom-style: none; border-size: 1px"><i>Espécie Doc</i><br><input type="text" id="espDoc2" class="valueBoleto" style="width: 50px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-bottom-style: none; border-size: 1px"><i>Aceite</i><br><input type="text" id="aceDoc2" class="valueBoleto" style="width: 50px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-bottom-style: none; border-size: 1px"><i>Data de Processamento</i><br><input type="text" id="dataProc2" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( = ) Valor do Documento</i><br><input type="text" id="valDoc2" class="valueBoleto" style="width: 100px" disabled="true" /></td>
							</tr>
							<tr>
								<td align=left style="border-style: solid; border-color: gray; border-left-style: none; border-right-style: none; border-size: 1px"><i>No. da Conta/Respo</i><br><input type="text" id="numConta2" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-size: 1px"><i>Carteira</i><br><input type="text" id="carDoc2" class="valueBoleto" style="width: 50px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-size: 1px"><i>Espécie</i><br><input type="text" id="espDoc2" class="valueBoleto" style="width: 50px" disabled="true" value="R$" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-right-style: none; border-size: 1px" colspan='2'><i>Quantidade</i><br><input type="text" id="quantDoc2" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: solid; border-color: gray; border-size: 1px"><i>Valor</i><br><input type="text" id="valor2" class="valueBoleto" style="width: 100px" disabled="true" /></td>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( - ) Desconto</i><br>    </td>
							</tr>
							<tr>
								<td align=left rowspan='8' colspan='6' style="vertical-align: text-top; border-style: solid; border-color: gray; border-left-style: none; border-top-style: none; border-size: 1px"><i>Instruções (Texto de responsabilidade do cedente)</i><br><input type="text" id="instDoc2" class="valueBoleto" style="width: 400px" disabled="true" /></td>
							</tr>
							<tr>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( - ) Outras Deduções / Abatimento</i><br>    </td>
							</tr>
							<tr>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( + ) Mora / Multa / Juros</i><br>    </td>
							</tr>
							<tr>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( + ) Outros Acréscimos</i><br>    </td>
							</tr>
							<tr>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>( = ) Valor Cobrado</i><br>    </td>
							</tr>
						</tbody>
					</table>
					<table cellspacing=0 cellpadding=0 width=700px border=0 >
						<tbody>
							<tr>
								<td align=left style="border-style: none"><i>Sacado:</i><br><input type="text" id="sacado2" class="valueBoleto" style="height: 24px; width: 400px" disabled="true" /></td>
							</tr>
							<tr>
								<td align=left style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>Sacador/Avalista:</i></td>
								<td align=right style="border-style: none; border-color: gray; border-bottom-style: solid; border-size: 1px"><i>Código de Baixa</i>        5593</td>
							</tr>
							<tr>
								<td><img src="{raiz}images/layout/codigo_barras.jpg" style="width: 283px; height: 36px; margin-top: 5px;"></td>
								<td align=right style="text-align: center"><fieldset style="border-bottom-style: none; border-right-style: none; margin-bottom: 5px;"><legend>Autenticação Mecânica</legend></fieldset></td>
							</tr>
							<tr>
								<td></td>
								<td align=right style="vertical-align: text-center">FICHA DE COMPENSAÇÃO</td>
							</tr>
						</tbody>
					</table>
				</div>
				<div style="margin-top: 10px"><span class="filtros"><input class="botaoCad" type="button" value="Imprimir" style="float:none"> <input id="btnVoltar" class="botaoCad" type="button" value="Voltar" style="float:none"></span>
				</div>
			</div>
		</div>
	</div>
	<input type='hidden' value='{label_emissaoBoletos_semregistros}' id='lblSemRegistros'/>
</div>

emissaoBoletos.js (atenção pras funções buscaBoletos e verBoleto)

$(document).ready(function(){
	showLoading();
	
	if ($("*").hasClass('menuselected')) {
		$("*").removeClass('menuselected');
		$("#linkhover4").addClass('menuselected');
		$("#linkhover4 a").css('color','#6B6B6B');
		$("#linkhover4 a").css('color','#6B6B6B');
		$('.setamenuprincipal4').css('background', 'url("[:raiz]images/layout/setacinza.png")');
	}
	
	var d = new Date();
	d.setDate(d.getDate());
	$('#txtData1').datepicker({ 
		dateFormat: "dd/mm/yy",
		//maxDate: d
	});
	$("#txtData1").datepicker('setDate',d);
	$('#txtData2').datepicker({ 
		dateFormat: "dd/mm/yy",
		//maxDate: d
	});
	$("#txtData2").datepicker('setDate',d);
	
	$.ajax({
		  async: false,
		  url: '[:raiz]acompanhamentoDiario/getUnidades',
		  dataType: 'json',		  
		  success: function(data) {
			  if (data.length > 0){
				  var retorno = "";
				  for(var i = 0;i < data.length; i++){
					  retorno += "<option value='"+data[i]['id']+"'>"+data[i]['nome']+"</option>";
				  }
				  $('#comboUnidades').html(retorno);
				 
				  if(typeof param != "undefined" ) {
					  $('#comboUnidades option[value='+unidade+']').attr('selected', 'selected');
					  $('#comboUnidades').trigger('change');
				  }
			  } else {
				  
			  }
		  }
	});
	$('#divTelaBoleto').hide();
	
	$('#btnVoltar').click(function(){
		$('#divBoletosLista').show();
		$('#divTelaBoleto').hide();
	});
	
	hideLoading();
});

function buscaBoletos(){
	$.ajax({
		async: false, cache: false,
		url: '[:raiz]emissaoBoletos/getBoletos',
		data: ({
			unidade: $('#comboUnidades').val(),
			de: $('#txtData1').val(),
			ate: $('#txtData2').val()
		}),
		dataType: 'json',
		success: function(data) {
			$('#divBoletosLista').hide();
			var retorno = "";
			if (data.length > 0){
				for(var i = 0;i< data.length;i++){
					retorno += "<tr id='Linha"+data[i]['row']+"'>";
					retorno += "<td style='text-align:left; width:10px'>"+data[i]['row']+"</td>";
					retorno += "<td style='text-align:left; width:300px'>"+data[i]['razaosocial']+"</td>";
					retorno += "<td style='width: 100px'>"+data[i]['nossonumero']+"</td>";
					retorno += "<td style='width: 80px'>"+data[i]['status']+"</td>";
					retorno += "<td style='width: 80px'>"+data[i]['valor']+"</td>";
					retorno += "<td style='width: 100px'>"+data[i]['dataemissao']+"</td>";
					retorno += "<td style='width: 100px'>"+data[i]['datavencimento']+"</td>";
					retorno += "<td><input class='botaoCad' type='button' value='Visualizar' style='float:none' onclick='verBoleto();'></td>";
					retorno += "</tr>";
				}
			} else {
				retorno = "<tr><td colspan='7' align='center'>"+$('#lblSemRegistros').val()+"</td></tr>";
			}
			$('#bodyBoletosLista').html(retorno);
  			$('#divBoletosLista').show();
			$('#divTelaBoleto').hide();
		}
	});
}

function verBoleto(){
	$('#divBoletosLista').hide();
	$('#divTelaBoleto').show();
	
	var d = new Date();
	d.setDate(d.getDate());
	$('#dataProc1').datepicker({ 
		dateFormat: "dd/mm/yy",
	});
	// Data de processamento é a data atual.
	$("#dataProc1").datepicker('setDate',d);
	$("#dataProc2").val($("#dataProc1").val());
}

emissaoBoletosController.php (atenção na função getBoletos, chamada no arquivo JS e que depois chama a função no arquivo Model):

<?php
class emissaoBoletosController extends PaginaAplicacao{
	
	public function index(){
		$this->inicializa('emissaoBoletos.index');
		Loader::js("emissaoBoletos",'',array('raiz'=>System::raiz(),'aba' => $aba));
		Loader::js("maskJquery",'',array('raiz'=>System::raiz()));
		$this->exibe('emissaoBoletos');
    }
    
    public function getUnidades() {
    	$emissao = new EmissaoBoletos();
    	$retorno = $emissao->getUnidadesUsuario();
    	echo json_encode($retorno);
    }
    
    public function getBoletos() {
    	$de = (($_REQUEST['de'] == "" or $_REQUEST['de'] == null) ? "null" : $_REQUEST['de']);
    	$deAux = explode("/",$de);
    	$de = str_replace("/", "-", $de);
    	 
    	$ate = (($_REQUEST['ate'] == "" or $_REQUEST['ate'] == null) ? "null" : $_REQUEST['ate']);
    	$ateAux = explode("/",$ate);
    	$ate = str_replace("/", "-", $ate);
    	
    	$unidade = (($_REQUEST['unidade'] == "-1" or $_REQUEST['unidade'] == null) ? "null" : Unidade::getCodBiBytIdUnidade($_REQUEST['unidade']));
    	
    	$diaDe  = $deAux[0];
    	$mesDe  = $deAux[1];
    	$anoDe  = $deAux[2];
    	 
    	$diaAte = $ateAux[0];
    	$mesAte = $ateAux[1];
    	$anoAte = $ateAux[2];
    	
    	$usuario = new UsuarioModel();
		$login = Login::retornaNomeUser();
		$usuario->login = $login;
		$nome = $usuario->selectUsuarioByLogin();
    	
    	$relatorio = new EmissaoBoletos();
    	$retorno = $relatorio->getBoletos($nome,$unidade,$diaDe,$mesDe,$anoDe,$diaAte,$mesAte,$anoAte);
    	echo json_encode ($retorno);
    }
}
?> 

emissaoBoletos.php (diretório Model, nesse arquivo está a função getBoletos com a devida consulta SQL)

<?php

ini_set('display_errors',1); 
error_reporting(E_ALL);

class EmissaoBoletos extends ModeloBanco{
	static $_tabela = 'dre_linha';

	public function getUnidadesUsuario() {
		$idUser = Login::retornaIdUser();	
		$perfilAcesso =  Login::retornaPerfilAcesso();		
		
		if($perfilAcesso == 1) {
			/* se perfil de usuairo = 1*/
			$sql = "SELECT u.*";
			$sql .= " FROM unidade u";
			$sql .= " join usuario_unidade uu on (uu.id_unidade = u.id)";
			$sql .= " WHERE u.ind_unidade_ativa = 1 AND u.ind_predio_novo = 0";
			$sql .= " and uu.id_usuario = $idUser and lower(uu.ind_tipo_investidor) != 'c' ORDER BY nome ASC";
		} elseif($perfilAcesso == 2) {
			/* se perfil de usuairo = 2*/
			$sql = "SELECT u.* ";
			$sql .= " FROM unidade u";
			$sql .= " join administrador adm on (adm.id_unidade = u.id)";
			$sql .= " WHERE u.ind_unidade_ativa = 1 AND u.ind_predio_novo = 0";
			$sql .= " and adm.id_usuario = $idUser";
			$sql .= " ORDER BY nome ASC";
		} else {
			/* se perfil de usuario = 3*/
			$sql = "SELECT u.*";
			$sql .= " FROM unidade u";
			$sql .= " WHERE u.ind_unidade_ativa = 1 AND u.ind_predio_novo = 0 ORDER BY nome ASC";
		}
		$res = parent::executaQuery($sql);
		return $res;
	}
	
	public function getBoletos($nome,$unidade,$diaDe,$mesDe,$anoDe,$diaAte,$mesAte,$anoAte){
		$diaDe--;
		$diaDe++;
		$diaAte--;
		$diaAte++;
		
		$mesDe--;
		$mesDe++;
		$mesAte--;
		$mesAte++;
		
		$anoDe--;
		$anoDe++;
		$anoAte--;
		$anoAte++;
		
		$idUser = Login::retornaIdUser();	
		$perfilAcesso =  Login::retornaPerfilAcesso();
		
		if($perfilAcesso == 1) {		
		$sqlLista = "SELECT ROW_NUMBER() OVER (ORDER BY IDHOTEL) AS row, IDHOTEL AS idhotel, RAZAOSOCIAL AS razaosocial, NOSSONUMERO AS nossonumero,
		NUMERODOCUMENTO AS numerodocumento, REPLACE(CAST(VALOR AS NUMERIC(15,2)),'.',',') AS valor,
		replace(convert(NVARCHAR, DATAEMISSAO, 103), '-', '/') AS dataemissao, replace(convert(NVARCHAR, DATAPROGRAMADA, 103), '-', '/') AS datavencimento,
		HISTORICOCOMPL AS historico, NUMEROBOLETO AS numeroboleto, DESCRICAO AS descricao, NOSSONUMERO AS nossonumero, STATUS AS status FROM BOLETOS WHERE IDHOTEL = $unidade  AND RAZAOSOCIAL = '$nome' AND DATAPROGRAMADA
		BETWEEN (cast($anoDe as varchar(4))  + '-' + cast($mesDe as varchar(2))  + '-' + cast($diaDe as varchar(2))) 
		AND (cast($anoAte as varchar(4)) + '-' + cast($mesAte as varchar(2)) + '-' + cast($diaAte as varchar(2)))"; }
		else {
		$sqlLista = "SELECT ROW_NUMBER() OVER (ORDER BY IDHOTEL) AS row, IDHOTEL AS idhotel, RAZAOSOCIAL AS razaosocial, NOSSONUMERO AS nossonumero,
		NUMERODOCUMENTO AS numerodocumento, REPLACE(CAST(VALOR AS NUMERIC(15,2)),'.',',') AS valor,
		replace(convert(NVARCHAR, DATAEMISSAO, 103), '-', '/') AS dataemissao, replace(convert(NVARCHAR, DATAPROGRAMADA, 103), '-', '/') AS datavencimento,
		HISTORICOCOMPL AS historico, NUMEROBOLETO AS numeroboleto, DESCRICAO AS descricao, NOSSONUMERO AS nossonumero, STATUS AS status FROM BOLETOS WHERE IDHOTEL = $unidade AND DATAPROGRAMADA
		BETWEEN (cast($anoDe as varchar(4))  + '-' + cast($mesDe as varchar(2))  + '-' + cast($diaDe as varchar(2))) 
		AND (cast($anoAte as varchar(4)) + '-' + cast($mesAte as varchar(2)) + '-' + cast($diaAte as varchar(2)))"; }
		$res = System::element('mssqldb')->select($sqlLista);
		$retorno =  array();
		foreach ($res as $r){
			$obj = array();
			$obj['row'] = $r['row'];
			$obj['razaosocial'] = $r['razaosocial'];
			$obj['nossonumero'] = $r['nossonumero'];
			$obj['status'] = $r['status'];
			$obj['valor'] = $r['valor'];
			$obj['dataemissao'] = $r['dataemissao'];
			$obj['datavencimento'] = $r['datavencimento'];
			$retorno[] = $obj;
		}
		return($retorno);
	}
}

Como eu poderia melhorar isso?

Acredito que o ajuste deveria ser feito no JS. Em outro site de dúvidas, uma solução encontrada foi mudar a função verBoleto para:

onclick="verBoleto("+ data[i]['row'] +");"

Aí parece que na função verBoleto se faz uma consulta pelo ID (row) e retorna o boleto montado somente com essas informações referente ao ID. Isso eu tô penando, por enquanto... tentei, por exemplo, no campo que recebe a data de emissão:

$('#dataDoc1').val() = $data[row]['dataemissao'];

Quem tiver ideias, pode falar.

Obrigado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Se o problema é apenas que o boleto tenha o conteúdo da linha que você escolheu é só no botão Visualizar Boleto você colocar url com a informação do ID que você obteve na consulta.

exemplo se a linha tem a id 10, você monta a url do botão com o id 10, exemplo

emissaoBoletos.php?id=10

Na página emissaoBoletos.php você faz uma nova consulta no banco, dessa vez você "puxa" o id que está sendo consultado pela url através de um GET, no caso que eu citei acima você poderia colocar assim:

$id_boleto = $_GET['id'];

aí você faz uma consulta no banco de dados onde a ID pesquisada será = $id_boleto.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Se o problema é apenas que o boleto tenha o conteúdo da linha que você escolheu é só no botão Visualizar Boleto você colocar url com a informação do ID que você obteve na consulta.

exemplo se a linha tem a id 10, você monta a url do botão com o id 10, exemplo

emissaoBoletos.php?id=10

Na página emissaoBoletos.php você faz uma nova consulta no banco, dessa vez você "puxa" o id que está sendo consultado pela url através de um GET, no caso que eu citei acima você poderia colocar assim:

$id_boleto = $_GET['id'];

aí você faz uma consulta no banco de dados onde a ID pesquisada será = $id_boleto.

 

OK, eu tentei fazer assim, pra início de conversa:

function verBoleto(){
   location.href = 'emissaoBoletos?row=1';
}
E no início da página emissaoBoletos.php:
<?php
if($_GET['row']){
   echo "<script type='text/javascript'>$('#divTelaBoleto').show();</script>"
   echo "<script type='text/javascript'>$('#divBoletosLista').hide();</script>";
}
?>

Mas não deu certo!!! Isso ia ser substituto à parte do código que tem no JS. E nem botei ainda a busca SQL pra testar. O que mais dá pra fazer?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Descobri a solução. No onclick da botão Visualizar:

onclick='verBoleto("+ data[i]['nossonumero'] +","+ data[i]['valor'] +","+ data[i]['dataemissao'] +","+ data[i]['datavencimento'] +","+ data[i]['razaosocial'] +");'

E na função em si, dentro do js:

 

function verBoleto(nossonumero,valor,dataemissao,datavencimento,razaosocial){
   $('#divBoletosLista').hide();
   $('#divTelaBoleto').show();

   var d = new Date();
   d.setDate(d.getDate());
   $('#dataProc1').datepicker({ 
      dateFormat: "dd/mm/yy",
   });
   // Data de processamento é a data atual.
   $("#dataProc1").datepicker('setDate',d);
   $("#dataProc2").val($("#dataProc1").val());

   $('#dataDoc1').val(dataemissao);
   $('#vencDoc1').val(datavencimento);
   $('#sacado1').val(razaosocial);
   $('#nossoNum1').val(nossonumero);
   $('#valDoc1').val(valor);
}

Por enquanto, consigo preencher pra NossoNumero. Pra Valor eu preencho, mas não pega o número com vírgula direito (170,90 fica só 170). Datas ele transforma num número. E Razão Social nem funciona o Visualizar.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.