<?php
 
session_start();
$com = "C"; 
include("DMMYSQLG.php");
include("DF30000.inc");
include("DMMYSQLG.php");
require_once("DF80000.php");
?>
<?php

$idBascps="";
$tipDocs="";
$tipMov='P';
$pag_reg2 = 'DW21000_AG2.php';//A DONDE VA SI ES TODO OK
$pag_reg1 = 'DW21000_PR-PRO.php';//A DONDE VA SI ES ERROR

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{
		$ArgsPag_reg="&solDocs=solDocs&botPR=$_REQUEST['botPR']&idpas=".date("H:i:s").date('d').date('m').date("Y");
		$tipDocs="solDocs";
		$idBascps=$_REQUEST['botPR'];	
	}
}
elseif(isset($_REQUEST['todDocs'])){
	$tipDocs="todDocs";
	$ArgsPag_reg="&todDocs=todDocs&idpas=".date("H:i:s").date('d').date('m').date("Y");
	
}

if($_POST['bot']==''){
	echo '<h2>!!! SELECCIONA UN REGISTRO... ACTUALIZANDO !!!</h2>';
	echo '<meta content="1; url='.$pag_reg1.'?ids=none'.$ArgsPag_reg.'"  HTTP-EQUIV="REFRESH">';
	exit();
}
	
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>

<body>
<?php
 
$sql = mysqli_query($con ,"select * from dvredocl where n_reg = '".$_REQUEST['bot']."'");
$res=mysqli_fetch_array($sql); 
?>
<form name="frm1" id="frm1" method="post" >

<?php

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="756"  align="center">
  <tr>
    <td colspan="9" class="mentab"><div align="left">Documento Numero: <?php
 echo $_REQUEST['bot'] ?> </div></td>
  </tr>
  <tr>
    <th colspan="9">Consulta Documento X Pagar </th>
  </tr>
  <tr>
    <td>Proveedor:</td>
    <td><?php
 
	  $sqlx = mysqli_query($con ,"select * from dxbascps where codigo = '".$res['codigo']."'");
	  $resx=mysqli_fetch_array($sqlx); 
	  echo $resx['nombre']. ' ' . $resx['ap_paterno']. ' ' . $resx['ap_materno']; 
	  ?>
      &nbsp;</td>
    <td>Fecha:</td>
    <td><?php
 
	  $fec1 = $res['fec_doc'];
	  include('DF20000.php');
	  echo $f_f; 
	  ?>
      &nbsp;</td>
    <td>Documento</td>
    <td colspan="3"><?php
 
	  echo $res['num_doc']; 
	  ?>    </td>
    </tr>
  
  <tr>
    <td>Cuenta Contable :</td>
    <td><?php
 
	  @$sql=mysqli_query($con ,"select * from dycatcta where cta_con = '".$res['cve_mto']."'");
	  @$reg = mysqli_fetch_array($sql);
	  if(mysqli_num_rows($sql)>0)
	  	echo $reg['descripcion'];
	  else
	  	echo $res['cve_mto'];
	  ?></td>
    <td>Sub-Total:</td>
    <td><?php
 echo '$' . number_format($res['sub_tot'], 2, '.', ',');?></td>
    <td>Iva:</td>
    <td><?php
 echo '$' . number_format($res['iva_tot'], 2, '.', ',');?></td> 
    <td>Total:</td>
    <td><?php
 echo '$' . number_format($res['total'], 2, '.', ',');?></td>
  </tr>
   <tr>
     <td nowrap>Tipo Moneda :</td>
     <td nowrap><?php
$tipMon=array("1"=>"NACIONAL","2"=>"EXTRANJERA"); echo $tipMon[$res['moneda']];?>&nbsp;</td>
     <td nowrap>Pais:</td>
     <td nowrap><?php
$dt_paises=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM geoyos_jc.dxpaises WHERE cve_pais='".$res['cve_pai']."'")); echo $dt_paises['des_pais'];?>&nbsp;</td>
     <td nowrap>Moneda:</td>
     <td nowrap><?php
$dt_paimon=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM geoyos_jc.dxpaimon WHERE cve_mon='".$res['cve_mon']."'")); echo $dt_paimon['des_moneda'];?>&nbsp;</td>
     <td nowrap>Tipo Cambio: </td>
     <td nowrap><?php
echo $res['tip_cam'];?>&nbsp;</td>
   </tr>
   <tr style="#FFCC00">
      <td colspan="8" nowrap><div align="center" class="Estilo2 Estilo3 Estilo2">&nbsp;&nbsp;Tot. Pagos: <?php
echo number_format($res['tot_pag'],2,'.',',');?> &nbsp;&nbsp;Tot. Notas: <?php
echo number_format($res['tot_not'],2,'.',',');?> Tot.Cargos:<?php
echo number_format($res['tot_car'],2,'.',',');?> &nbsp;&nbsp;Tot. Abonos: <?php
echo number_format($res['tot_abo'],2,'.',',');?>&nbsp;&nbsp;Tot. Saldo: <?php
echo number_format($res['tot_sal'],2,'.',',');?></div></td>
    </tr>
  <tr>
    <td>Descripcion:</td>
    <td colspan="7"><?php
echo $res['des'];?>&nbsp;</td>
    </tr>
</table>
<table width="756"  align="center">
    <tr>
      <th colspan="5">Detalle  de Documentos </th>
    </tr>
    <tr>
      <th colspan="5" class="inputcodigo"><div align="left"></div></th>
    </tr>
    <tr>
      <td width="130"><div align="center">Con</div></td>
      <td width="183"><div align="center">Fol_mov</div></td>
      <td width="126"><div align="center">Total </div></td>
      <td width="236"><div align="center">Cuenta Contable </div></td>
    </tr>
	<?php
 
	
	@$sqlx = mysqli_query($con ,"select * from dvredocl where n_reg = '".$_REQUEST['bot']."'");
	@$resx=mysqli_fetch_array($sqlx);
	
	@$sql = mysqli_query($con ,"select * from dvredocd where codigo='".$resx['codigo']."' AND num_doc = '".$resx['num_doc']."'");
	$j=0;
	$totDoc=0;
	while(@$res=mysqli_fetch_array($sql)){
	$j += 1;
	$totDoc+=$res['sub_tot'];
	echo '<tr>';
		echo '<td><div align="center">'.$j.'&nbsp;</div></td>';
		echo '<td><div align="center">'.$res['num_doc'].'&nbsp;</div></td>';
		$nd = $res['num_doc'];
		echo '<td><div align="center">'.'$' . number_format($res['sub_tot'], 2, '.', ',').'&nbsp;</div></td>';
		@$sqly=mysqli_query($con ,"select * from dycatcta where  cta_con = '".$res['cve_mto']."'");
	    @$regy = mysqli_fetch_array($sqly);
		if(mysqli_num_rows($sqly)>0)
			echo '<td><div align="center">'.$res['cve_mto'].' '.$regy['descripcion'].'&nbsp;</div></td>';
		else
			echo '<td><div align="center">'.$res['cve_mto'].'&nbsp;</div></td>';
	echo '</tr>';
	}	
	echo '<tr class="inputcodigo">
		<td colspan="2"><div align="right">&nbsp;Total:</div></td>
		<td><div align="right">'.number_format($totDoc,2,'.',',').'&nbsp;</div></td>
		<td colspan="2"><div align="right">&nbsp;</div></td>
	</tr>'; 
	?>
  </table>
  <div align="center">
<?php
 
	if(isset($_REQUEST['Submit3'])){
		echo '<input name="Submit4" type="submit" value = "Guardar Modificacion">';
	}
?>
<table  >
      <tr>
        <th>Cheque/Transferencia</th>
        <th>Fecha</th>
        <th>Importe de Pago </th>
		<th>Tipo Movimiento </th>
      </tr>
	  <?php
 
		$result = mysqli_query($con ,"SELECT * FROM dvcobdoc WHERE codigo='".$resx['codigo']."' AND num_doc = '".$resx['num_doc']."' and cli_pro ='P'");
		//echo "SELECT * FROM dvcobdoc WHERE codigo='".$resx['codigo']."' AND num_doc = '".$resx['num_doc']."' and cli_pro ='P'";
		 
	 while(@$reg = mysqli_fetch_array($result)){
	  	echo "<tr>";
		echo '<td><div align="center">'.$reg["fol_cob"].'</div></td>';
		$fec1 = chfecha($reg['fec_cob'],'Y-m-d','d/m/Y');
		echo '<td><div align="center">' . $fec1 . '&nbsp</div></td>';
		echo '<td><div align="center">' . '$' . number_format($reg['tot_cob'], 2, '.', ',') . '&nbsp</div></td>';
		$tipo = $reg['tip_mto'];
		if ($tipo == 1)
		    $tipo= "cobro/pago";
		else if ($tipo ==2)
		   	$tipo= "cargo";
		else if	($tipo ==3)
		    $tipo= "abono";
		echo '<td><div align="center">'.$tipo.'</div></td>';
		$totPag +=$reg['tot_cob'];
	}
	echo '<tr>
			<td colspan="2"><div align="right">TOTAL:</div></td>
			<td colspan="1"><div align="right">'.number_format($totPag,2,'.',',').'</div></td>
			<td colspan="2"><div align="right">&nbsp;</div></td>
		</tr>';
	  ?>
    </table>

  </div>
  <p>
    <input name="Submit2" type="button" id="Submit2" value="Regresar" onClick="openpage('DW21000_PR-PRO.php','_self')">
  </p>
</form>
</body>
</html>
