<?php
 
session_start();
if($_SESSION['tipven']==""){
	$_SESSION['tipven'] = $_POST['tip_ven'];
}
$com = "A";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
include("DF30000.inc");
include("DF80000.php");
include("DFJQUERY.inc");
include("DFSETDIV.inc");
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<body>
<script language="javascript">
$(document).ready(function(){
	setActions();
});
function setActions(){

	 SetDisplayDiv.setup({
	 	radioName : 'r1',
		radioValue: 'todDoc',
		radioEvent: 'click',
		divId     : 'busFec'
	 });
	 
	SetDisplayDiv.setup({
	 	radioName : 'r1',
		radioValue: 'porDoc',
		radioEvent: 'click',
		divId     : 'idBus'
	 });
 	SetDisplayDiv.setup({
	 	radioName : 'r1',
		radioValue: 'porCli',
		radioEvent: 'click',
		divId     : 'idBus'
	 });
	 
	 SetDisplayDiv.setup({
	 	radioName : 'r1',
		radioValue: 'porCli',
		radioEvent: 'click',
		divId     : 'busFec'
	 });

	 SetDisplayDiv.setup({
	 	radioName : 'r1',
		radioValue: 'porFec',
		radioEvent: 'click',
		divId     : 'busFec'
	 });
	 SetDisplayDiv.Start();
}
</script>
<form id="frm1" name="frm1" method="post" action="" >
<?php

$idBascps="";
$tipDocs="";
$tipMov='P';
if(isset($_REQUEST['solDocs'])){
	if($_REQUEST['botPR']==""){
		echo '<h2>!!! SELECCIONA UN REGISTRO... ACTUALIZANDO !!!</h2>';
		echo '<meta content="1; url=DW21000_PR.php"  HTTP-EQUIV="REFRESH">';
		exit();	
	}
	else{
		echo '<input type="hidden" name="solDocs" id="solDocs" value="">';
		echo '<input type="hidden" name="botPR" id="botPR" value="'.$_REQUEST['botPR'].'">';
		$tipDocs="solDocs";
		$idBascps=$_REQUEST['botPR'];	
	}
}
elseif(isset($_REQUEST['todDocs'])){
	$tipDocs="todDocs";
	echo '<input type="hidden" name="todDocs" id="todDocs" value="">';
}
?>
<table width="714" border="0" align="center">
	<tr>
		<th width="100%">DOCUMENTOS X PAGAR </th>
	</tr>
	<tr>
          <td>
            <div align="center">
              <input name="r1" type="radio" tabindex="1"  value="todDoc"/>
              Todos/Documentos
              &nbsp;&nbsp;&nbsp;
              <input name="r1" type="radio" tabindex="2" onClick="arriba(this.value)" value="porSal" checked/>
X Saldo
&nbsp;&nbsp;&nbsp;&nbsp;
<input name="r1" type="radio" value="porDoc" tabindex="3" onClick="arriba(this.value)"/>
X Documento
&nbsp;&nbsp;&nbsp;
<input name="r1" type="radio" value="porCli" tabindex="4" onClick="arriba(this.value)"/>
X Cliente
&nbsp;&nbsp;&nbsp;
<input name="r1" type="radio" value="porFec" tabindex="5" onClick="arriba(this.value)"/>
X Fecha </div></td>
    </tr>
        <tr>
          <td> <div align="center"><span id="idBus">Buscar:
            <input name="tbus" type="text" id="tbus" onKeyUp="may(this)"/>
          </span><span id="busFec">De:
              
            <input name="fec_ini" type="text" class="emplea" id="fec_ini" size="10" maxlength="20"
			<?php

				if(isset($_POST['fec'])){ //este es el truco
					echo 'value="' . $_POST['fec'] .  '"';
				}
				else{
					echo 'value="' . date('d/m/Y') .  '"';
				}
			?>onkeypress="return soloNumeros(event)"//solo fechas
		/>
            <input name="botFecIni" id="botFecIni" type="image" value="Cal" src="logos/cal4.jpg" />
            <script type="text/javascript">
		  Calendar.setup(
			{
			  inputField  : "fec_ini",       // ID of the input field
			  ifFormat    : "%d/%m/%Y",  // the date format
			  button      : "botFecIni"        // ID of the button
			}
		  );
            </script>
              
            A:
              
            <input name="fec_fin" type="text" class="emplea" id="fec_fin" size="10" maxlength="20"
			<?php

				if(isset($_POST['fec2'])){ //este es el truco
					echo 'value="' . $_POST['fec2'] .  '"';
				}
				else{
					echo 'value="' . date('d/m/Y') .  '"';
				}
			?>onkeypress="return soloNumeros(event)"//solo fechas
		/>
            <input name="botFecFin" id="botFecFin" type="image" value="Cal" src="logos/cal4.jpg"/>
            <script type="text/javascript">
		  Calendar.setup(
			{
			  inputField  : "fec_fin",       // ID of the input field
			  ifFormat    : "%d/%m/%Y",  // the date format
			  button      : "botFecFin"        // ID of the button
			}
		  );
            </script>
            </span>
            <input name="buscarPRO" type="submit" id="buscarPRO" value="Buscar" onClick="sendForm('frm1','DW21000_PR-PRO.php','_self',false)"/>          
          </div></td>
        </tr>
  </table>
       
	<p>&nbsp;</p>
	<div align="center">
    <table width="750" border='1'>
      <tr>
        <th colspan="12"><div align="left">
          <input type="button" name="Submit6" value="Agregar" onClick="openpage('DW21000_AG1.php','_self')">
          <input name="consultarPRO" type="button" id="consultarPRO"  onClick="openpage('DW21000_DE.php','_self')" value="Consultar"/>
          <input name="eliminarPRO" type="button" id="eliminarPRO" onClick="openpage('DW21000_EL.php','_self')" value="Eliminar"/>
		  <input name="modificarPRO" type="button" id="modificarPRO" onClick="openpage('DW21000_MO.php','_self')" value="Modificar"/>
          <label></label>
          <input name="regresarPRO" type="button" id="regresarPRO" onClick="openpage('DW21000_PR.php','_self')" value="Regresar"/>
        </div></th>
      </tr>
      <tr>
        <th colspan="12">
		<?php

		$strTit='';
		switch($tipDocs){
			case 'solDocs':
				$dt_bascps=mysqli_fetch_array(mysqli_query($con ,"select dxbascps.codigo,CONCAT(dxbascps.ap_paterno,' ',dxbascps.ap_materno,' ',dxbascps.nombre) as nom from dxbascps where codigo='$idBascps'"));
				$strTit.="DOCUMENTOS ".$dt_bascps['codigo'].'-'.$dt_bascps['nom'];
			break;
			case 'todDocs':
				$strTit.="TODOS LOS DOCUMENTOS";
			break;
		 }			
		echo $strTit;
		?>&nbsp;</th>
      </tr>
      <tr>
        <th width="24"><div align="center">Sel</div></th>
        <th width="40"><div align="center">Fecha</div></th>
		<th width="52"><div align="center">Cliente</div></th>
		<th width="77"><div align="center"> Documento</div></th>
        <th width="50"><div align="center">Tipo Moneda </div></th>
        <th width="50">Cuenta</th>
        <th width="67">Sub Total</th>
        <th width="26">IVA</th>
        <th width="40"><div align="center">Total </div></th>
        <th width="52"><div align="center">Pagos</div></th>
        <th width="99"><div align="center">Notas de Credito</div></th>
        <th width="97"><div align="center">Saldo</div></th>
      </tr>
      <?php

	switch($tipDocs){
		case 'solDocs':
			$andCli=" && dvredocl.codigo='$idBascps'";
		break;
		case 'todDocs':
			$andCli="";
		break;
	}
	$strBus="SELECT dvredocl.*,dvredocl.cve_mto as id_cta,CONCAT(dxbascps.ap_paterno,' ',dxbascps.ap_materno,' ',dxbascps.nombre) as nom FROM dvredocl LEFT JOIN dxbascps ON(dxbascps.codigo=dvredocl.codigo) WHERE dvredocl.tip_mov='$tipMov' $andCli";
	if(isset($_POST['buscarPRO'])){
		 $tipBusq=$_POST['r1'];
		 $fecIni=chfecha($_POST['fec_ini'],'d/m/Y','Y-m-d');
		 $fecFin=chfecha($_POST['fec_fin'],'d/m/Y','Y-m-d');
		 $tBus=$_POST['tbus'];
		 switch($tipBusq){
		 	case 'todDoc':
				$strBus.=" AND dvredocl.tot_sal>0 AND fec_doc between '$fecIni' AND '$fecFin' ";
			break;
			
			case 'porSal':
				$strBus.=" AND dvredocl.tot_sal>0";
			break;
			
			case 'porDoc':
				$strBus.=" AND dvredocl.num_doc='$tBus'";
			break;
			
			case 'porCli';
				$strBus.=" AND CONCAT(dxbascps.ap_paterno,' ',dxbascps.ap_materno,' ',dxbascps.nombre) like '%$tBus%'  AND dvredocl.fec_doc between '$fecIni' AND '$fecFin'";
			break;
			
			case 'porFec':
				$strBus.=" && dvredocl.fec_doc between '$fecIni' && '$fecFin' ";
			break;
			
		 }
	}
	else{
		$strBus.=" && dvredocl.tot_sal>0";
	}
	$strBus.=" order by nom";
	//echo $strBus.'<br>';
	$result=mysqli_query($con ,$strBus);	 
	while($row = mysqli_fetch_array($result)){
	  	if($row['moneda']==1){
			$mon = "N";
		}else{
			$mon = "E";
		}
		echo '<tr>';
		echo '<td> <div align="center"><input name="bot" type="radio" value="'. $row["n_reg"].'"></div></td>';
		echo '<td> <div align="center">' . chfecha($row['fec_doc'],'Y-m-d','d/m/Y'). "&nbsp;</div></td>";
		echo '<td> <div align="left">'.$row['nom'].'&nbsp;</div></td>';
		echo '<td> <div align="right">' . $row['num_doc'] . "&nbsp;</div></td>";
		echo '<td> <div align="center">' . $mon . "&nbsp;</div></td>";
		echo '<td> <div align="right">' . $row['id_cta'] . "&nbsp;</div></td>";
		echo "<td> <div align='right'>" . '$' . number_format($row['sub_tot'], 2, '.', ',') . "&nbsp;</div></td>";
		echo "<td> <div align='right'>" . '$' . number_format($row['iva_tot'], 2, '.', ',') . "&nbsp;</div></td>";
		echo "<td> <div align='right'>" . '$' . number_format($row['total'], 2, '.', ',') . "&nbsp;</div></td>";
		echo "<td> <div align='right'>" . '$' . number_format($row['tot_pag'], 2, '.', ',') . "&nbsp;</div></td>";
		echo "<td> <div align='right'>" . '$' . number_format($row['tot_not'], 2, '.', ',') . "&nbsp;</div></td>";
		echo "<td> <div align='right'>" . '$' . number_format($row['tot_sal'], 2, '.', ',') . "&nbsp;</div></td>";
		echo "</tr>";
	}
	mysqli_close($con);

	?>
    </table>
	</div>
</form>

</body>
</html>
