<?php
session_start();
// require('../cfg/res.php');

// zeus para HSHE

include('../_cfg/config.php');
include ('php_gene1.php');
include ('php_session.php');

// echo 'RIDE1';

$docu=$_GET['docu'];
$fecha1=$_GET['fecha1'];
$fecha2=$_GET['fecha2'];
$enti=$_GET['enti'];
$order=$_GET['order'];

if($docu==''){$docu=$_POST['docu'];}
if($fecha1==''){$fecha1=$_POST['fecha1'];}
if($fecha2==''){$fecha2=$_POST['fecha2'];}
if($enti==''){$enti=$_POST['enti'];}
if($order==''){$order=$_POST['order'];}

if($fecha1==''){$fecha1=date('Y-m-1');}
if($fecha2==''){$fecha2=date('Y-m-d');}


$sql_docu='select * from docu0 where docu_codigo like "'.substr($docu,0,2).'%" order by docu_codigo';
$res_docu=msql_query($sql_docu,$link_vcrx);
$tabla =msql_result($res_docu,0,'docu_tabla');


$sql_docu ='select * from '.$tabla.'12 ';
$sql_docu.=' where docu like "'.substr($docu,0,2).'%"';
$sql_docu.=' and fecha>="'.$fecha1.'"';
$sql_docu.=' and fecha<="'.$fecha2.'"';
$sql_docu.=' and tcant!=0';
// $sql_docu.=' and hshe=1';
// $sql_docu.=' and (hshe=1 or zeus=1)';
$sql_docu.=' and zeus=1';
// $sql_docu.=' and enti="1791739477001"';
$sql_docu.=' and status!="O" ';
$sql_docu.=' order by fecha,enti,numero ';
// $sql_docu.=' limit 20 ';
// if($order=='E'){$sql_docu.=' order by enti_descri,numero';}
// if($order=='F'){$sql_docu.=' order by fecha,enti_descri,numero';}
// if($order=='N'){$sql_docu.=' order by numero,idnum1';}
$res_docu=msql_query($sql_docu,$link_vcrx);

?>

<?php ob_start(); ?>

<?php // explain_sql($sql_docu); ?>

  

<table width="300%" style="font-family:arial;font-size:10px;border-collapse:collapse;">
  <thead>
    <tr style="background:#d3d3d3;" border="1">
    <th>Año y Mes</th>
    <th>Fuente</th>
    <th>Documento</th>
    <th>Fecha</th>
    <th>Cuenta</th>
    <th>Nit</th>
    <th>Auxiliar</th>
    <th>Centro de Costo</th>
    <th>Item</th>
    <th>Descripción</th>
    <th>Valor</th>
    <th>Ind. Tipo de Cuenta</th>
    <th>Conciliado</th>
    <th>Banco</th>
    <th>Vendedor</th>
    <th>Plaza</th>
    <th>Tipo de Factura</th>
<!--      en cuenta de cartera 1 debe ser 01 -->
    <th>No. Factura</th>
<!--       completar 9 caracteres con ceros -->
    <th>Vencimiento</th>
<!--       fecha del dia "2018/08/15" solo en 130502 -->
    <th>Referencia</th>
    <th>Usuario</th>
    <th>Fecha de Grabación</th>
    <th>Zona</th>
    <th>Cliente/Proveedor</th>
<!--       completar con 09 solo en 130502 -->
    <th>% de Retención</th>
    <th>Base de Retención</th>
    <th>Código de Presupuesto</th>
    <th>Número de la Reserva Presupuestal</th>
    <th>Valor en Otra Moneda</th>
    <th>Estado</th>
    <th>Consecutivo de Reversión</th>
    <th>Aplicación</th>
    <th>Unidad 1</th>
    <th>Unidad 2</th>
    <th>Unidad 3</th>
    <th>Valor Unid 1</th>
    <th>Valor Unid 2</th>
    <th>Valor Unid 3</th>
    <th>Serie del Proveedor</th>
    <th>Autorizacion del Proveedor</th>
    <th>Tasa de Cambio</th>
    <th>Unidad de Negocio</th>
    </tr>
  </thead>
  <tbody>


<?php
// echo $sql_docu;
$xride='';
$lidnum='';
$xidnum='';
$total=0;    
$crow=0;
    
    
    
    
while($aso_docu=msql_fetch_assoc($res_docu))
{
?>
    <?php $crow++; ?>
    <?php $xidnum=$aso_docu['idnum1']; ?>

    <?php    
      if(($lidnum!=$xidnum and $crow>1))
      {
    ?>
        <tr style="background:#d3d3d3;">
<!--         <td><?php echo date('Ym',strtotime($aso_docu['fecha'])); ?></td> -->
        <td><?php echo date('Ym',strtotime($fecha2)); ?></td>
        <td>10</td>
        <td>15NUEVO</td>
        <td><?php echo $aso_docu['fecha']; ?></td>
        <td><?php echo '13050502'; ?></td>
        <td>'<?php echo $xenti; ?></td>
        <td></td>
        <td></td>
        <td></td>
        <td>FACTURA : <?php echo $xaplica; ?></td>
        <td><?php echo round($total*(-1),2); ?></td>
        <td>2</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>'01</td>
        <td>'<?php echo $xaplica; ?></td>
        <td><?php echo $fecha2; ?></td>
        <td></td>
        <td>Excel</td>
        <td><?php echo $aso_docu['fecha']; ?></td>
        <td>'02</td>
        <td>'<?php echo substr($xenti,0,10); ?></td>
        <td>0.00</td>
        <td>0.00</td>
        <th></th>
        <th></th>
        <th>0.00</th>
        <th></th>
        <th>0.00</th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th>0.00</th>
        <th>0.00</th>
        <th>0.00</th>
        <td><?php echo $aso_docu['ptoe']; ?></td>
        <td><?php echo $aso_docu['autornum']; ?></td>
        <td>0.00</td>
<!--         <td>ZeusLibroPrincipal</td> -->
        <td>Local</td>
        </tr>

    <?php  $total=0;?>
    <?php  } 
    ?>  
    
    <?php $xenti=$aso_docu['enti']; ?>
    <?php
    $xaplica=$aso_docu['numer'];
    $xcta='13351';
    if(abs($aso_docu['puni'])==1)   {$xcta='13551501';} 
    if(abs($aso_docu['puni'])==2)   {$xcta='13551502';} 
    if(abs($aso_docu['puni'])==2.75){$xcta='13551503';} 
 
    if(abs($aso_docu['puni'])==10){$xcta='13551703';} 
    if(abs($aso_docu['puni'])==20){$xcta='13551702';} 
    if(abs($aso_docu['puni'])==30){$xcta='13551704';} 
    if(abs($aso_docu['puni'])==70){$xcta='13551701';} 
    if(abs($aso_docu['puni'])==100){$xcta='13551705';} 
    ?>
    <?php { ?>    
    <tr>
<!--     <td><?php echo date('Ym',strtotime($aso_docu['fecha'])); ?></td> -->
    <td><?php echo date('Ym',strtotime($fecha2)); ?></td>
    <td>10</td>
    <td>15NUEVO</td>
    <td><?php echo $aso_docu['fecha']; ?></td>
    <td><?php echo $xcta; ?></td>
    <td>'<?php echo $aso_docu['enti']; ?></td>
    <td></td>
    <td></td>
    <td></td>
    <td>FACTURA : <?php echo $xaplica; ?></td>
    <td><?php echo round(abs($aso_docu['tcant']),2); ?></td>
    <td>1</td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>CR</td>
    <td>'<?php echo $aso_docu['numero']; ?></td>
    <td></td>
    <td></td>
    <td>Excel</td>
    <td><?php echo $aso_docu['fecha']; ?></td>
    <td>'02</td>
    <td></td>
    <td><?php echo round(abs($aso_docu['puni']),2); ?></td>
    <td><?php echo round(abs($aso_docu['cant']),2); ?></td>
    <th></th>
    <th></th>
    <th>0.00</th>
    <th></th>
    <th>0.00</th>
    <th></th>
    <th></th>
    <th></th>
    <th></th>
    <th>0.00</th>
    <th>0.00</th>
    <th>0.00</th>
    <td><?php echo $aso_docu['ptoe']; ?></td>
    <td><?php echo $aso_docu['autornum']; ?></td>
    <td>0.00</td>
<!--         <td>ZeusLibroPrincipal</td> -->
        <td>Local</td>
    </tr>
    <?php } ?>    
    <?php //$total=$total+abs($aso_docu['tcant']); ?>
    <?php $total=$total+round(abs($aso_docu['tcant']),2); ?>
    
    <?php    
      if( $crow==msql_num_rows($res_docu))
      {
    ?>
        <tr style="background:#d3d3d3;">
        <td><?php echo date('Ym',strtotime($aso_docu['fecha'])); ?></td>
        <td>10</td>
        <td>15NUEVO</td>
        <td><?php echo $aso_docu['fecha']; ?></td>
        <td><?php echo '13050502'; ?></td>
        <td>'<?php echo $xenti; ?></td>
        <td></td>
        <td></td>
        <td></td>
        <td>FACTURA : <?php echo $xaplica; ?></td>
        <td><?php echo round($total*(-1),2); ?></td>
        <td>2</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>'01</td>
        <td>'<?php echo $xaplica; ?></td>
        <td><?php echo $fecha2; ?></td>
        <td></td>
        <td>Excel</td>
        <td><?php echo $aso_docu['fecha']; ?></td>
        <td>'02</td>
        <td>'<?php echo substr($xenti,0,10); ?></td>
        <td>0.00</td>
        <td>0.00</td>
        <th></th>
        <th></th>
        <th>0.00</th>
        <th></th>
        <th>0.00</th>
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th>0.00</th>
        <th>0.00</th>
        <th>0.00</th>
        <td><?php echo $aso_docu['ptoe']; ?></td>
        <td><?php echo $aso_docu['autornum']; ?></td>
        <td>0.00</td>
<!--         <td>ZeusLibroPrincipal</td> -->
        <td>Local</td>
        </tr>

    <?php  $total=0;?>
    <?php  } 
    ?>  
    
    <?php $lidnum=$aso_docu['idnum1']; ?>
    

<?php    
}
?>
</tbody>
</table>

  
<?php
$docuhtml = ob_get_clean(); 
$docuhtml=alltrim($docuhtml);
// echo '<html>';
echo $docuhtml;	
// echo '</html>';
 die(); 
return;  
?>
