<?php
////  ******************  NO UTILIZAR ***********************
require('../cfg/res.php');
require('../../_lib/vrdocu0.php');
session_start();


$xacceso=0;
$sql_acce='select * from usrdoc1 where docu like "'.$_POST['docu'].'%" and modi="1" and user="'.$_SESSION['user_vcrx_id'].'" ';
$res_acce=mysql_query($sql_acce,$link_vcrx);
if (mysql_num_rows($res_acce)!=0){$xacceso=1;}
if (mb_stristr('sist.supe',$_SESSION['user_vcrx_tipo'])){$xacceso=1;}
//if (mb_stristr('clie',$_SESSION['user_vcrx_tipo']) and mb_stristr('OP.',substr($_POST['docu'],1,2))){$xacceso=1;}
//if ($xacceso==0){die('No tiene acceso a modificar :'.$docu_tipo );}	

$docur=new vrdocu0('../cfg/res.php',$_POST['docu']);

$sql_tota='select * from '.$docur->tabla.'11 where idnum2='.$_POST['idnumx'].' order by iddet desc';
$res_tota=mysql_query($sql_tota,$link_vcrx);

$sql_deta='select * from '.$docur->tabla.'12 where idnum2='.$_POST['idnumx'].' order by iddet ';
if($_SESSION['user_vcrx_empr']=='ecgl' and mb_stristr('clie.vtas',$docur->tabla))
{$sql_deta='select * from '.$docur->tabla.'12 where idnum2='.$_POST['idnumx'].' order by itnum, iddet ';}

$res_deta=mysql_query($sql_deta,$link_vcrx);

//echo $sql_tota;
$sql_error='';
$sql_error= mysql_error($link_vcrx);
$sql_error=trim($sql_error);


$filax=1;

if(empty($sql_error))
{
if(mysql_num_rows($res_deta)!=0  )
{

	$tcant=mysql_result($res_tota,0,'tcant');

	if(mb_stristr('vtas.clie.comp.dxco.dxpa.prov', strtolower($docur->tabla)))
	{
//	$tsubt=mysql_result($res_tota,0,'tsubt');
	$tdcto=mysql_result($res_tota,0,'tdcto');
//	$tsubtice=mysql_result($res_tota,0,'tsubtice');
	$tice=mysql_result($res_tota,0,'tice');
//	$tsubtiva=mysql_result($res_tota,0,'tsubtiva');
//	$tsubtiva0=mysql_result($res_tota,0,'tsubtiva0');
	$tiva=mysql_result($res_tota,0,'tiva');
	$tirbp=mysql_result($res_tota,0,'tirbp');
	$total=mysql_result($res_tota,0,'total');
	}

	$xstat=mysql_result($res_tota,0,'status');



$xfec1 = date('Y-m-j');
$xfec1 = strtotime ( '-10 day' , strtotime ( $xfec1 ) ) ;
$xfec1 = date ( 'Y-m-j' , $xfec1 );

$xfec2 = mysql_result($res_tota,0,'fecha');
$xfec2 = mysql_result($res_tota,0,'idate');
$xstat = mysql_result($res_tota,0,'status');

$xmodif = 0;
if ($xfec2>=$xfec1 && $xstat=="-")
{$xmodif=1;}

$xmodif = 1;



?>
<div align=left>
<?php
echo '<b>'.mysql_result($res_tota,0,'docu').'-'.mysql_result($res_tota,0,'numero').'  -  '.mysql_result($res_tota,0,'enti_descri').'</b>';
?>
</div>


<?php
	if(mb_stristr('cont', strtolower($docur->tabla)))
	{
?>
<table border="1" cellpadding="2" cellspacing="0"  style="border-collapse:collapse;">
   <tr style="border-bottom:solid 2px;" align="center">
   <th>#</th>
   <th>Cuenta</th>
   <th>Contable</th>
   <th>Debito</th>
   <th>Credito</th>
   <th>Detalle</th>
   </tr>

<?php	
   while($row_deta=mysql_fetch_assoc($res_deta))
   {
   $duni=2;
   $dval=2;
   ?>
   
		
   <tr style=" <?php if($filax==3){echo 'border-bottom:solid 1px #000;';$filax=1;}else{echo'border-bottom:thin dotted  #000;';$filax++;} ?>" >
	    <td align="center"><small><div id="num_id_<?php echo $row_deta['iddet'];?>"> <?php echo $row_deta['iddet'];?></div></small></td>
	    <td><?php echo $row_deta['ctas'];?></td>
    	    <td><?php echo $row_deta['ctas_descri'];?></td>
	    <td align="right"><?php echo number_format($row_deta['debito'],$dval);?></td>
	    <td align="right"><?php echo number_format($row_deta['credito'],$dval);?></td>
   	    <td><?php echo $row_deta['detalle'];?></td>
    </tr>

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



<?php
	if(mb_stristr('guia', strtolower($docur->tabla)))
	{
?>
<table width="100%" border="1" cellpadding="2" cellspacing="0"  style="border-collapse:collapse;">
   <tr style="border-bottom:solid 2px;" align="center">
   <th>#</th>
   <th>Item</th>
   <th>Descrip.</th>
		 
	<?php if($_SESSION['user_vcrx_empr']=='ecgl'){ ?>
		<th>Laminas</th>
		<th>Largo</th>
		<th>Ancho</th>
	<?php } ?>
		 
   <th>Cant</th>
   <th>P.Unit.</th>

   <?php if ($tdcto>0){ ?>
   <th>Dcto</th>
   <?php }?>
   <?php if ($tice>0){ ?>
   <th>ICE</th>
   <?php }?>
   <?php if ($tiva>0){ ?>
   <th>IVA</th>
   <?php }?>
   <?php if ($tirbp>0){ ?>
   <th>IRBP</th>
   <?php }?>
   <th>SubTot</th>
   <th>Detalle</th>
	<?php if($_SESSION['user_vcrx_empr']=='pcs1'){ ?>
		<th>Contenedor</th>
		<th>Desde</th>
		<th>Hasta</th>
	<?php } ?>
     
   <th></th>
   </tr>

<?php	
   $num_fila=0;
   while($row_deta=mysql_fetch_assoc($res_deta))
   {
   $duni=$row_deta['item_duni'];
   $dval=$row_deta['item_dval'];
   $dval=2;

   ?>
   <tr id="numrow_<?php echo $num_fila;?>" style=" <?php if($filax==3){echo 'border-bottom:solid 1px #000;';$filax=1;}else{echo'border-bottom:thin dotted  #000;';$filax++;} ?>" >
	    <td align="center"><small><div id="num_id_<?php echo $row_deta['iddet'];?>">
        <?php echo '*/*/'.$_SESSION['user_vcrx_empr']; ?> 
      	<?php if($_SESSION['user_vcrx_empr']=='ecgl'){ ?>
        <?php echo $row_deta['itnum'];?>
        <?php}else{?>
        <?php echo $row_deta['iddet'];?>
        <?php}?>
      </div></small></td>
	    <td><?php echo $row_deta['item'];?></td>
    	    <td><?php echo $row_deta['item_descri'];?></td>
	    <td align="right"><?php echo number_format($row_deta['cant'],$duni);?></td>
	    <td align="right"><?php echo '<span title="'.$row_deta['puni'].'">'.number_format($row_deta['tsubt'],$dval).'</span>';?></td>
	    <?php if ($tdcto>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['dcto'].'%">'.number_format($row_deta['tdcto'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tice>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['ice'].'%">'.number_format($row_deta['tice'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tiva>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['iva'].'%">'.number_format($row_deta['tiva'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tirbp>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['irbp'].'">'.number_format($row_deta['tirbp'],2).'</span>';?></td>
	    <?php }?>
	    <td align="right"><?php echo number_format($row_deta['total'],2);?></td>
   	  <td><?php echo $row_deta['detalle'].'';?></td>

      <?php if($_SESSION['user_vcrx_empr']=='pcs1'){ ?>
        <th align="center"><?php echo $row_deta['cntn'];?></th>
        <th align="center"><?php echo date('d/M/y',strtotime($row_deta['cntnf1']));?></th>
        <th align="center"><?php echo date('d/M/y',strtotime($row_deta['cntnf2']));?></th>
      <?php } ?>

      <?php if($_SESSION['user_vcrx_empr']=='tgck'){ ?>
        <th align="center"><?php echo $row_deta['vhcl'];?></th>
      <?php } ?>

     <?php
	    if ($xmodif==1)
	    {
	    ?>
	    <td>ABC
	       	<input type="image" id="e_deta" src="http://vcrxol.com/_img/ico_minus.png" width="25" title="Eliminar linea #<?php echo $row_deta['iddet'];?>-<?php echo $row_deta['cant'];?>"  onclick="deledeta('<?php echo strtolower($docur->tabla);?>','<?php echo $row_deta['idnum1'];?>','<?php echo $row_deta['iddet'];?>','numrow_<?php echo $num_fila;?>');"  />
	    </td>
	    <?php	    
	    }
	    ?>

     
     
    </tr>
<?php $num_fila++; }?>
</table>
<?php } ?>


<?php
	if(mb_stristr('vtas.clie', strtolower($docur->tabla)))
	{
?>
<table width="100%" border="1" cellpadding="2" cellspacing="0"  style="border-collapse:collapse;">
   <tr style="border-bottom:solid 2px;" align="center">
   <th>#</th>
   <th>Item</th>
   <th>Descrip.</th>
		 
	<?php if($_SESSION['user_vcrx_empr']=='ecgl'){ ?>
		<th>Laminas</th>
		<th>Largo</th>
		<th>Ancho</th>
	<?php } ?>
		 
   <th>Cant</th>
   <th>P.Unit.</th>

   <?php if ($tdcto>0){ ?>
   <th>Dcto</th>
   <?php }?>
   <?php if ($tice>0){ ?>
   <th>ICE</th>
   <?php }?>
   <?php if ($tiva>0){ ?>
   <th>IVA</th>
   <?php }?>
   <?php if ($tirbp>0){ ?>
   <th>IRBP</th>
   <?php }?>
   <th>SubTot</th>
   <th>Detalle</th>
	<?php if($_SESSION['user_vcrx_empr']=='pcs1'){ ?>
		<th>Contenedor</th>
		<th>Desde</th>
		<th>Hasta</th>
	<?php } ?>
     
   <th></th>
   </tr>

<?php	
   $num_fila=0;
   while($row_deta=mysql_fetch_assoc($res_deta))
   {
   $duni=$row_deta['item_duni'];
   $dval=$row_deta['item_dval'];
   $dval=2;

   ?>
   <tr id="numrow_<?php echo $num_fila;?>" style=" <?php if($filax==3){echo 'border-bottom:solid 1px #000;';$filax=1;}else{echo'border-bottom:thin dotted  #000;';$filax++;} ?>" >
	    <td align="center"><small><div id="num_id_<?php echo $row_deta['iddet'];?>">
        <?php echo '*/*/'.$_SESSION['user_vcrx_empr']; ?> 
      	<?php if($_SESSION['user_vcrx_empr']=='ecgl'){ ?>
        <?php echo $row_deta['itnum'];?>
        <?php}else{?>
        <?php echo $row_deta['iddet'];?>
        <?php}?>
      </div></small></td>
	    <td><?php echo $row_deta['item'];?></td>
    	    <td><?php echo $row_deta['item_descri'];?></td>
	    <td align="right"><?php echo number_format($row_deta['cant'],$duni);?></td>
	    <td align="right"><?php echo '<span title="'.$row_deta['puni'].'">'.number_format($row_deta['tsubt'],$dval).'</span>';?></td>
	    <?php if ($tdcto>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['dcto'].'%">'.number_format($row_deta['tdcto'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tice>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['ice'].'%">'.number_format($row_deta['tice'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tiva>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['iva'].'%">'.number_format($row_deta['tiva'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tirbp>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['irbp'].'">'.number_format($row_deta['tirbp'],2).'</span>';?></td>
	    <?php }?>
	    <td align="right"><?php echo number_format($row_deta['total'],2);?></td>
   	  <td><?php echo $row_deta['detalle'].'';?></td>

      <?php if($_SESSION['user_vcrx_empr']=='pcs1'){ ?>
        <th align="center"><?php echo $row_deta['cntn'];?></th>
        <th align="center"><?php echo date('d/M/y',strtotime($row_deta['cntnf1']));?></th>
        <th align="center"><?php echo date('d/M/y',strtotime($row_deta['cntnf2']));?></th>
      <?php } ?>

      <?php if($_SESSION['user_vcrx_empr']=='tgck'){ ?>
        <th align="center"><?php echo $row_deta['vhcl'];?></th>
      <?php } ?>

     <?php
	    if ($xmodif==1)
	    {
	    ?>
	    <td>ABC
	       	<input type="image" id="e_deta" src="http://vcrxol.com/_img/ico_minus.png" width="25" title="Eliminar linea #<?php echo $row_deta['iddet'];?>-<?php echo $row_deta['cant'];?>"  onclick="deledeta('<?php echo strtolower($docur->tabla);?>','<?php echo $row_deta['idnum1'];?>','<?php echo $row_deta['iddet'];?>','numrow_<?php echo $num_fila;?>');"  />
	    </td>
	    <?php	    
	    }
	    ?>

     
     
    </tr>
<?php $num_fila++; }?>
</table>
<?php } ?>




<?php
	if(mb_stristr('comp.prov', strtolower($docur->tabla)))
	{
?>
<table width="100%" border="1" cellpadding="2" cellspacing="0"  style="border-collapse:collapse;">
   <tr style="border-bottom:solid 2px;" align="center">
   <th>#</th>
   <th>Item</th>
   <th>Descrip</th>
   <th>Cant</th>
   <th>P.Unit.</th>
   <?php if ($tdcto>0){ ?>
   <th>Dcto</th>
   <?php }?>
   <?php if ($tice>0){ ?>
   <th>ICE</th>
   <?php }?>
   <?php if ($tiva>0){ ?>
   <th>IVA</th>
   <?php }?>
   <?php if ($tirbp>0){ ?>
   <th>IRBP</th>
   <?php }?>
   <th>SubTot</th>
   <th>Cuenta</th>
   <th>CAIR</th>
   <th>Detalle</th>
   <th></th>
   </tr>

<?php	
   $num_fila=0;
   while($row_deta=mysql_fetch_assoc($res_deta))
   {
   $duni=$row_deta['item_duni'];
   $dval=$row_deta['item_dval'];
   $dval=2;
   ?>
   <tr id="numrow_<?php echo $num_fila;?>" style=" <?php if($filax==3){echo 'border-bottom:solid 1px #000;';$filax=1;}else{echo'border-bottom:thin dotted  #000;';$filax++;} ?>" >
	    <td align="center"><small><div id="num_id_<?php echo $row_deta['iddet'];?>"> <?php echo $row_deta['iddet'];?></div></small></td>
	    <td><?php echo $row_deta['item'];?></td>
    	    <td><?php echo $row_deta['item_descri'];?></td>
	    <td align="right"><?php echo number_format($row_deta['cant'],$duni);?></td>
	    <td align="right"><?php echo '<span title="'.$row_deta['puni'].'">'.number_format($row_deta['tsubt'],$dval).'</span>';?></td>
	    <?php if ($tdcto>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['dcto'].'%">'.number_format($row_deta['tdcto'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tice>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['ice'].'%">'.number_format($row_deta['tice'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tiva>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['iva'].'%">'.number_format($row_deta['tiva'],2).'</span>';?></td>
	    <?php }?>
	    <?php if ($tirbp>0){ ?>
	    <td align="right"><?php echo '<span title="'.$row_deta['irbp'].'">'.number_format($row_deta['tirbp'],2).'</span>';?></td>
	    <?php }?>
	    <td align="right"><?php echo number_format($row_deta['total'],2);?></td>
	    <td align="left"><?php $row_deta['ctas'];?></td>
	    <td align="center"><?php $row_deta['cair'];?></td>
   	  <td><?php echo $row_deta['detalle'];?></td>

	    <?php
	    if ($xmodif==1)
	    {
	    ?>
	    <td>
	       	<input type="image" id="e_deta" src="http://vcrxol.com/_img/ico_minus.png" width="25" title="Eliminar linea #<?php echo $row_deta['iddet'];?>-<?php echo $row_deta['cant'];?>"  onclick="deledeta('<?php echo strtolower($docur->tabla);?>','<?php echo $row_deta['idnum1'];?>','<?php echo $row_deta['iddet'];?>','numrow_<?php echo $num_fila;?>');"  />
	    </td>
	    <?php	    
	    }
	    ?>
    </tr>
<?php $num_fila++; }?>
</table>
<?php } ?>





<?php
	if(mb_stristr('inve.prod', strtolower($docur->tabla)))
	{
?>
<table width="100%" border="1" cellpadding="2" cellspacing="0"  style="border-collapse:collapse;">
   <tr style="border-bottom:solid 2px;" align="center">
   <th>#</th>
   <th>Item</th>
   <th>Descri</th>
   <th>Cant</th>
   <th>P.Unit.</th>
   <th>SubTot</th>
   <th>NumSerie</th>
   <th>Detalle</th>
   </tr>

<?php	
   while($row_deta=mysql_fetch_assoc($res_deta))
   {
   $duni=$row_deta['item_duni'];
   $dval=$row_deta['item_dval'];
   $dval=2;
		 
   ?>
	
   
		
   <tr style=" <?php if($filax==3){echo 'border-bottom:solid 1px #000;';$filax=1;}else{echo'border-bottom:thin dotted  #000;';$filax++;} ?>" >
    
	    <td align="center"><small><div id="num_id_<?php echo $row_deta['iddet'];?>"> <?php echo $row_deta['iddet'];?></div></small></td>
			
	    <td><?php echo $row_deta['item'];?></td>
    	    <td><?php echo $row_deta['item_descri'];?></td>
	    <td align="right"><?php echo number_format($row_deta['cant'],$duni);?></td>
	    <td align="right"><?php echo '<span title="'.$row_deta['puni'].'">'.number_format($row_deta['puni'],$dval).'</span>';?></td>
	    <td align="right"><?php echo number_format($row_deta['total'],2);?></td>
        <td align="left"><?php echo $row_deta['numserie'];//numero de serie ?></td>
   	    <td><?php echo $row_deta['detalle'];?></td>

   
   
	
    </tr>

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



<?php
	if(mb_stristr('rolp.nvdd', strtolower($docur->tabla)))
	{
?>
<table width="100%" border="1" cellpadding="2" cellspacing="0"  style="border-collapse:collapse;">
   <tr style="border-bottom:solid 2px;" align="center">
   <th>#</th>
   <th>Entidad</th>
   <th>Nombre</th>
   <th>Item</th>
   <th>Descri</th>
   <th>Cant</th>
   <th>V.Unit</th>
   <th>SubTot</th>
   <th>Centro.Sub.</th>
   <th>Detalle</th>
   </tr>

<?php	
   while($row_deta=mysql_fetch_assoc($res_deta))
   {
   $duni=$row_deta['item_duni'];
   $dval=$row_deta['item_dval'];
   $dval=2;
   ?>
   
		
   <tr style=" <?php if($filax==3){echo 'border-bottom:solid 1px #000;';$filax=1;}else{echo'border-bottom:thin dotted  #000;';$filax++;} ?>" >
    
	    <td align="center"><small><div id="num_id_<?php echo $row_deta['iddet'];?>"> <?php echo $row_deta['iddet'];?></div></small></td>
			
	    <td><?php echo $row_deta['enti2'];?></td>
 	    <td><?php echo $row_deta['enti2_descri'];?></td>
	    <td><?php echo $row_deta['item'];?></td>
 	    <td><?php echo $row_deta['item_descri'];?></td>
	    <td align="right"><?php echo number_format($row_deta['cant'],$duni);?></td>
	    <td align="right"><?php echo '<span title="'.$row_deta['puni'].'">'.number_format($row_deta['puni'],$dval).'</span>';?></td>
	    <td align="right"><?php echo number_format($row_deta['total'],2);?></td>
        <td align="center"><?php echo $row_deta['csub_descri']; ?></td>
   	    <td><?php echo $row_deta['detalle'];?></td>

   
   
	
    </tr>

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





<?php
// 		$echo $sql_deta;
	if(mb_stristr('caja.bcos.retc.retp.cjte', strtolower($docur->tabla)))
	{
?>
<table width="100%" border="1" cellpadding="2" cellspacing="0"  style="border-collapse:collapse;">
   <tr style="border-bottom:solid 2px;" align="center">
   <th>#</th>
   <th>Docum</th>
   <th>Descrip</th>
   <th>Numer</th>
   <th>Cant</th>
   <th>Detalle</th>


   
   </tr>

<?php	
		
   $num_fila=0;
   while($row_deta=mysql_fetch_assoc($res_deta))
   {
   $duni=2;
   $dval=2;
  
   ?>
   
		
   <tr id="numrow_<?php echo $num_fila;?>" style=" <?php if($filax==3){echo 'border-bottom:solid 1px #000;';$filax=1;}else{echo'border-bottom:thin dotted  #000;';$filax++;} ?>" >
    
	    <td align="center"><small><div id="num_id_<?php echo $row_deta['iddet'];?>"> <?php echo $row_deta['iddet'];?></div></small></td>
			
	    <td><?php echo $row_deta['docum'];?></td>
    	    <td><?php echo $row_deta['docum_descri'];?></td>
    	    <td><?php echo $row_deta['ptoemi'];?></td>
	    <td align="right"><?php echo number_format($row_deta['cant'],$dval);?></td>
   	    <td><?php echo $row_deta['detalle'];?></td>

	    <?php
	    if ($xmodif==1)
	    {
	    ?>
	    <td>
	       	<input type="image" id="e_deta" src="http://vcrxol.com/_img/ico_minus.png" width="25" title="Eliminar linea #<?php echo $row_deta['iddet'];?>-<?php echo $row_deta['cant'];?>"  onclick="deledeta('<?php echo strtolower($docur->tabla);?>','<?php echo $row_deta['idnum1'];?>','<?php echo $row_deta['iddet'];?>','numrow_<?php echo $num_fila;?>');"  />
	    </td>
	    <?php	    
	    }
	    ?>
   
   
	
    </tr>

<?php $num_fila++;}?>
</table>
<?php
	}
?>




	
	
<?php
}
else
{echo 'NO HAY DETALLE --> ';}

}
?>
<input type="hidden" id="hdd_car_det_err" value="<?php echo $sql_error;?>" />