<?
session_start();
require("../conectar.php");

echo <<<h
<html>

<head>
<title>Buscar</title>
<LINK href="estilo.css" rel=stylesheet>
<script src="funcion.js" type="text/javascript" language="javascript"></script>
<script language="JavaScript" src="calen.js"></script>

<SCRIPT LANGUAGE="JavaScript">
<!--
function tipoopera (f) 
 {
  f.operacion.length=0;
h;

$sql="SELECT id, tipo FROM concepto";
$rc=mysql_query($sql);
while($lc=mysql_fetch_object ($rc)){
echo <<<h
  if (f.tipooperacion.value=='$lc->tipo'){
	f.operacion.options[0]=new Option("","");
h;

	$i=1;

	$sql="SELECT idconcepto, operacion FROM conceptodet WHERE idconcepto='$lc->id' ORDER BY operacion";
	$rcd=mysql_query($sql);
	while($lcd=mysql_fetch_object ($rcd)){
echo <<<h
		f.operacion.options[$i]=new Option("$lcd->operacion","$lcd->operacion");
h;
		$i++;
	}

echo "}";
}

echo <<<h
}

//-->
</SCRIPT>

</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
h;
if ($act == 's')
{
  require ("movbancobuscardet.php");
}


$clas="class=tmed";

require("fecha.php");
$d=$dia; 
$m=$mes;
$a=$año;
$d--;

if ($d==0)
 {
   $d=31;
   $m--;

while (Checkdate($m,$d,$a) !=1)
  {
    $d--;
  }
 }

if ($b!='s')
 {  
  $fechaini="$a-$m-$d";
  $fechafin="$a-$m-$d";
 }


echo <<<h
<form name="forma" method="post" action="movbancobuscar.php?b=s" $tar>
<table border=0 cellspacing=0 cellpadding=4 align=center>
<tr BGCOLOR=WHITE>
	<td nowrap>
		Buscar:
	</td>
	<td nowrap>
		<select name="tipooperacion" class="sel" onChange="tipoopera(this.form);">
			<option value="$tipooperacion">$tipooperacion
h;

		$sql="SELECT id, tipo FROM concepto";
		$rc=mysql_query($sql);
		while($lc=mysql_fetch_object ($rc)){
echo <<<h
			<option value="$lc->tipo">$lc->tipo
h;
		}
echo <<<h
		</select>
	</td>
	<td nowrap>
		<font face="Verdana, Arial, Helvetica, sans-serif" size=2>Del: </font>
		<input type="text" name="fechaini" class="imputbox" size="11" maxlength="10" value="$fechaini"> 
		<a href="javascript:show_calendar('forma.fechaini');" onmouseover="window.status='Calendario';return true;" onmouseout="window.status='';return true;"><img src="show-calendar.gif"  border=0></a>
		al
		<input type="text" name="fechafin" class="imputbox" size="11" maxlength="10" value="$fechafin" > <a href="javascript:show_calendar('forma.fechafin');" onmouseover="window.status='Calendario';return true;" onmouseout="window.status='';return true;"><img src="show-calendar.gif"  border=0></a>

		<input type="checkbox" name="xconciliado" size="11" maxlength="10" value="s" >Conciliados &nbsp;&nbsp;
	</td>
	<td nowrap>
		Monto:		 	
		<input type="text" name="monto" class="imputbox" size="11" maxlength="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue=false;" value="$monto">
	      <input type="submit" name="bus" value=" Buscar " class="botones">
	</td>
</tr>
<tr BGCOLOR=WHITE>
	<td nowrap>
	</td>
	<td nowrap>
		<select name="operacion" class="sel">
			<option value="$operacion">$operacion
		</select>
	</td>
	<td nowrap colspan=2>
		<B>Sin fecha:</B> Monto: <input type="text" name="montolibre" class="imputbox" size="11" maxlength="10" onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnValue=false;" value="$montolibre">
		ó Beneficiario: <input type="text" name="beneficiario" class="imputbox" size="40" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();" value="$beneficiario">
	</td>
</tr>
<tr BGCOLOR=WHITE>
	<td nowrap>
	</td>
	<td nowrap>
		NO. CUENTA
	</td>
	<td nowrap>
		<select name="cuenta" class="sel">
			<option value="$cuenta">$cuenta
h;

		$sql="SELECT id, grupo, cuenta FROM cuentas";
		$rc=mysql_query($sql);
		while($lc=mysql_fetch_object ($rc)){
echo <<<h
			<option value="$lc->id">$lc->cuenta --- $lc->grupo
h;
		}
echo <<<h
		</select>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Oficina:
	</td>
    <td width="225">
		<select name="oficina" class=imputbox  onchange="">
			<option value="$idoficina">$lt->sucursal
h;
			$sql="SELECT id, sucursal FROM oficina ORDER BY sucursal";
			$rt=mysql_query($sql);
			while ($lt=mysql_fetch_object ($rt)){
echo <<<h
			<option value='$lt->id'>$lt->sucursal
h;
			}
			mysql_free_result($rt);
echo <<<h
			<option value=''>
		</select>
	</td>
</tr>
</table>
</form>
h;


if ($b=='s'){
	if ($montolibre == '' && $beneficiario==''){
		if ($tipooperacion!=''){
			$cond.=" AND tipooperacion='$tipooperacion'";
		}
		if ($operacion!=''){
			$cond.=" AND operacion='$operacion'";
		}
		if ($monto!=''){
			$cond.=" AND total=$monto";
		}
//***para buscar por numero de cuenta
		if ($cuenta!=''){
			$cond.=" AND idcuenta='$cuenta'";
		}
//***para buscar por oficina
		if ($oficina!=''){
			$cond.=" AND idoficina='$oficina'";
		}
//***para buscar por oficina
		if ($xconciliado=='s')
			$sql="SELECT * FROM movbanco where fechaconciliado >= '$fechaini' and  fechaconciliado <= '$fechafin' $cond order by fecha, tipooperacion, operacion, total";
		else
			$sql="SELECT * FROM movbanco where fecha >= '$fechaini' and  fecha <= '$fechafin' $cond order by fecha, tipooperacion, operacion, total";
		
		$r=mysql_query($sql);
		$cant=mysql_num_rows($r);
	}
	else{
		if ($beneficiario!=''){
			$cond.=" AND beneficiario LIKE '%$beneficiario%'";
		}
		if ($montolibre!=''){
			$cond.=" AND total=$montolibre";
		}	

		$sql="SELECT * FROM movbanco where no<>0 $cond order by fecha, tipooperacion, operacion, total";
		$r=mysql_query($sql);
		$cant=mysql_num_rows($r);
	}

	if($cant == 0){
		echo "<center><B>No existe ningún movimiento de banco</B></center>";
	}
	else{
echo <<<h
<form name="f" method="post" action="movbancobuscar.php?act=s">
<table align=center cellspacing=0 cellpadding=3 border=0 $clas>
<tr>
	<td align=center bgcolor="#F0F0F0"><B></B></td>
	<td align=center bgcolor="#F0F0F0"></td>
	<td align=center bgcolor="#F0F0F0"><B>No</B></td>
	<td align=center bgcolor="#F0F0F0"><B>T.OPERACION</B></td>
	<td align=center bgcolor="#F0F0F0"><B>OPERACION</B></td>
	<td align=center bgcolor="#F0F0F0"><B>FECHA</B></td>
	<td align=center bgcolor="#F0F0F0"><B>CHEQUE</B></td>
	<td align=center bgcolor="#F0F0F0"><B>SUCURSAL</B></td>
	<td align=center bgcolor="#F0F0F0"><B>TOTAL</B></td>
	<td align=center bgcolor="#F0F0F0"><B>CLIENTE</B></td>
	<td align=center bgcolor="#F0F0F0"><B>ASIGNADO</B></td>
h;
$i=0;
		while ($l=mysql_fetch_object ($r)){
echo <<<h
<tr onmouseover="setPointer(this, $i, 'over', '#FFFFFF', '#CCFFCC', '#FFCC99');" onmouseout="setPointer(this, $i, 'out', '#FFFFFF', '#CCFFCC', '#FFCC99');" onmousedown="setPointer(this, $i, 'click', '#FFFFFF', '#CCFFCC', '#FFCC99');">
h;
			$i++;

			if ($l->operacion=='INSCRIPCIONES'){
				$sql="SELECT no, apat, amat, nom from prospectos where nobandepins='$l->no' or nobandepins2='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='DIFERENCIAS'){
				$sql="SELECT no, apat, amat, nom from prospectos where noband1=$l->no or noband2=$l->no or noband3=$l->no  or noband4=$l->no or noband5=$l->no or noband6=$l->no or noband7=$l->no or noband8=$l->no or noband9=$l->no or noband10=$l->no or noband11=$l->no or noband12=$l->no  or noband13=$l->no or noband14=$l->no";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='AHORRO VOLUNTARIO'){
				$sql="SELECT no, apat, amat, nom from prospectos where nobanavold1=$l->no or nobanavold2=$l->no or nobanavold3=$l->no";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='MULTIDEPOSITO'){
				$sql="SELECT no, apat, amat, nom from prospectos where nobandepins='$l->no' or nobandepins2='$l->no' OR noband1=$l->no or noband2=$l->no or noband3=$l->no  or noband4=$l->no or noband5=$l->no or noband6=$l->no or noband7=$l->no or noband8=$l->no or noband9=$l->no or noband10=$l->no or noband11=$l->no or noband12=$l->no  or noband13=$l->no or noband14=$l->no OR nobanavold1=$l->no or nobanavold2=$l->no or nobanavold3=$l->no";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='PAGO NOTARIA'){
				$sql="SELECT no, apat, amat, nom from prospectos where nobannotariad1=$l->no";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='REEMBOLSO INSCRIPCION' || $l->operacion=='REEMBOLSO INSCRIPCION X CANC'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchreembins='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='REEMBOLSO DIFERENCIA X CANC'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchreembdifxcanc='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='REEMBOLSO DIFERENCIA A FAVOR'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchreembdiffavor='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='REEMBOLSO AHORRO VOLUNTARIO'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchreembahorrovol='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='MULTIREEMBOLSO'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchreembmulti='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='TRANSFERENCIA DIFERENCIA APROVI'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchtrdifapv='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='TRANSFERENCIA DIFERENCIA CLIENTE'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchtrdifcli='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='TRANSFERENCIA INSCRIPCION'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchtrins='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='MULTITRANSFERENCIA'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchtrmulti='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='R.POOL DIF. CLIENTE'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchreembpooldifcli='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='R.POOL INSC.'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchreembpoolins='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else if ($l->operacion=='MULTIREEMBOLSOPULL'){
				$sql="SELECT no, apat, amat, nom from prospectos where idchreembpoolmulti='$l->no'";
				$rp=mysql_query($sql);
				$lp=mysql_fetch_object ($rp);
				mysql_free_result ($rp);
			}
			else{
				$lp->apat="";
				$lp->amat="";
				$lp->nom="";
			}


echo <<<h
	<td>$i</td>
	<td>
		<a href="#x" onclick="window.open('movbancos.php?mod=s&no=$l->no','','toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,top=0,left=0');">Modificar</a> 	
    </td>
    <td align=center>
		$l->no <INPUT TYPE="hidden" name="no$i" value="$l->no">
	</td>
	<td>
		$l->tipooperacion
	</td>
    <td>
		$l->operacion
	</td>
	<td>
		$l->fecha
	</td>
	<td>
h;

if ($l->nocheque!=0)
	echo $l->nocheque;
else
	echo $l->notransferencia;

echo <<<h
	</td>
	<td>
		<input type="text" name="sucursal$i" class="imputbox" size="10" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();" value="$l->sucursal">
	</td>
	<td>
		$l->total
	</td>
h;


	if ($lp->apat=='' and $lp->amat=='' and $lp->nom=='')
echo<<<h
	<td>
		$l->beneficiario
	</td>
h;
else
echo <<<h
	<td><a href="#x" onclick="window.open('prospectos.php?mod=s&cual=$lp->no','','toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,top=0,left=0');">
		$lp->apat $lp->amat $lp->nom</a>
	</td>
h;

echo <<<h
	<td>
		$l->asignado
	</td>
</tr>
h;

		}
		mysql_free_result ($r);
echo <<<h
	<td align="center" colspan="7">
		<input type="submit" name="Submit" value="  Actualizar  " class="botones">
	</td>
</table>
</form>
h;

	}
}
mysql_close();	
?>
</body>
</html>
