<?php 
session_start();

require('../cfg/res.php');
require('../cfg/cfg.php');

include('php_gene1.php');
include('php_session.php');

// $empr_impo=r_fiel('empr',$cfg_empr,'impo');

$xacceso=0;
$sql_acce='select * from usrdoc1 where docu like "FP%" and info="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 ($xacceso==0){echo '<font size="8" color="red"><b>';die('No tiene acceso a Informe de Compras ' );}	


$fecha1 = date('Y-m-j');
$nuevafecha = strtotime ( '-1 month' , strtotime ( $fecha1 ) ) ;
$xfecha1 = date ( 'Y/m/j' , $nuevafecha );
$xfecha1= date('Y/m/'.'1');
$xfecha2= date('Y/m/d');

$sql_datesp='SET lc_time_names = "es_UY"';
$res_datesp=mysql_query($sql_datesp,$link_vcrx);

$xmodi='0';
if(isset($_POST['xmodi']) && !empty($_POST['xmodi']))
{$xmodi=$_POST['xmodi'];}

$xfgrou='D';
if(isset($_POST['fgrou']) && !empty($_POST['fgrou']))
{$xfgrou=$_POST['fgrou'];}

if(isset($_POST['fcodi']) && !empty($_POST['fcodi']))
{$xfcodi=$_POST['fcodi'];}

switch ($xfcodi)
{
	case '1': $item_codi='item';break;
	case '2': $item_codi='item_codigov';break;
	case '3': $item_codi='item_ean';break;
	default : $item_codi='item';break;
}


$sql_compt='select *,
	max(dcto) as pdcto,
	max(ice) as pice,
	max(iva) as piva,
	max(irbp) as pirbp,
	sum(tcant) as ttcant,
	sum(tsubt) as ttsubt,
	sum(tdcto*-1) as ttdcto,
	sum(tsubtice) as ttsubtice,
	sum(tprop) as ttprop,
	sum(tice) as ttice,
	sum(tsubtiva0) as ttsubtiva0,
	sum(tsubtiva) as ttsubtiva,
	sum(tiva) as ttiva,
	sum(tirbp) as ttirbp,
	sum(total) as ttotal';

$sql_compt.='	from comp12 where ';

if ($_POST['opt']=='celet1'){
	$sql_compt=str_replace('comp1','cele1',$sql_compt);
}

// echo $sql_compt;

$sql_compt.='(';

if(isset($_POST['fecha_ini']) && !empty($_POST['fecha_ini']) && isset($_POST['fecha_fin']) && !empty($_POST['fecha_fin']))
{
	$xfecha1=$_POST['fecha_ini'];
	$xfecha2=$_POST['fecha_fin'];
}

$sql_compf='select min(fecha) as fecha from comp1 where status!="X" and status!="O" and fecha>="'.$xfecha1.'"';
if ($_POST['opt']=='celet1'){
	$sql_compf=str_replace('comp1','cele1',$sql_compf);
}
$res_compf=mysql_query($sql_compf,$link_vcrx);
$xfecha1b=mysql_result($res_compf,0,'fecha');

$sql_compf='select max(fecha) as fecha from comp1 where status!="X" and status!="O" and fecha<="'.$xfecha2.'"';
if ($_POST['opt']=='celet1'){
	$sql_compf=str_replace('comp1','cele1',$sql_compf);
}
$res_compf=mysql_query($sql_compf,$link_vcrx);
$xfecha2b=mysql_result($res_compf,0,'fecha');

	$xanios=date('Y',strtotime($xfecha2b))-date('Y',strtotime($xfecha1b))+1;
	$xanio1=date('Y',strtotime($xfecha1b));
	$xanio2=date('Y',strtotime($xfecha2b));

	$dias=intval(strtotime($xfecha2b) - strtotime($xfecha1b))/60/60/24;
    $anios=date('Y',strtotime($xfecha2))-date('Y',strtotime($xfecha1));

	switch ($xfgrou)
	{
	case 'M':
		$xfecha1=date('Y/m/'.'1',strtotime($xfecha1));

		if($dias<=31)
		{$xfecha1=date('Y/m/'.'1',strtotime('-2 month',strtotime($xfecha1)));}

		$xfecha2=date('Y/m/t',strtotime($xfecha2));
		break;

	case 'S':
		if($dias<=7)
		{$xfecha1=date('Y/m/d',strtotime('-1 month',strtotime($xfecha1)));}
		
		$xfecha1=date('Y/m/d',strtotime('-'.date('w',strtotime($xfecha1)).' day',strtotime($xfecha1)));
		$xfecha2=date('Y/m/d',strtotime('+'.(6-date('w',strtotime($xfecha2))).' day',strtotime($xfecha2)));
		break;
	}

	$sql_compt.='fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"';
//}
//else
//{
//	$sql_compt.=' fecha BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"' ;
//}

$sql_compt.=')';
$sql_compt=str_replace(')(',')||(',$sql_compt);

if(isset($_POST['fdocu']) && !empty($_POST['fdocu']))
{
	$sql_compt.=' and  (docu like "'.$_POST['fdocu'].'%"  ) ';
	$xfdocu=$_POST['docu'];
}

if(isset($_POST['fenti']) && !empty($_POST['fenti']))
{
	$sql_compt.=' and  (enti like "'.$_POST['fenti'].'%" or enti_descri like "%'.$_POST['fenti'].'%" ) ';
	$xfenti=$_POST['fenti'];
}

if(isset($_POST['ftoenti']) && !empty($_POST['ftoenti']))
{
// 	$sql_compt.=' and  (enti like "'.$_POST['fenti'].'%" or enti_descri like "%'.$_POST['fenti'].'%" ) ';
	$sql_compt.=' and  (toenti like "'.$_POST['ftoenti'].'%" ) ';
	$xftoenti=$_POST['ftoenti'];
}

if(isset($_POST['fitem']) && !empty($_POST['fitem']))
{
// 	$sql_compt.=' and  (item like "'.$_POST['fitem'].'%" or item_descri like "%'.$_POST['fitem'].'%" ) ';
	$sql_compt.=' and  (item like "'.$_POST['fitem'].'%" or item_descri like "%'.$_POST['fitem'].'%" or detalle like "%'.$_POST['fitem'].'%" ) ';
	$xfitem=$_POST['fitem'];
}

if(isset($_POST['ftpro']) && !empty($_POST['ftpro']))
{
	$sql_compt.=' and  (tpro like "'.$_POST['ftpro'].'%" or tpro_descri like "%'.$_POST['ftpro'].'%" ) ';
	$xftpro=$_POST['ftpro'];
}

if(isset($_POST['fcair']) && !empty($_POST['fcair']))
{
	$sql_compt.=' and  (cair like "'.$_POST['fcair'].'%" or cair_descri like "%'.$_POST['fcair'].'%" ) ';
	$xfcair=$_POST['fcair'];
}




if(isset($_POST['fctas']) && !empty($_POST['fctas']))
{
	$sql_compt.=' and  (ctas like "'.$_POST['fctas'].'%" or ctas_descri like "%'.$_POST['fctas'].'%" ) ';
	$xfctas=$_POST['fctas'];
}

if(isset($_POST['fnocta']) && !empty($_POST['fnocta']))
{
  if($_POST['fnocta']=='true' and $xfctas=='')
	$sql_compt.=' and  (ctas="" or ctas is null) ';
	$xfnocta=$_POST['fnocta'];
}



if(isset($_POST['fcdad']) && !empty($_POST['fcdad']))
{
	$sql_compt.=' and  (prvc_descri like "%'.$_POST['fcdad'].'%" or enti_cdad like "'.$_POST['fcdad'].'%" or cdad_descri like "%'.$_POST['fcdad'].'%"  ) ';
	$xfcdad=$_POST['fcdad'];
}

if(isset($_POST['flsub']) && !empty($_POST['flsub']))
{
	$sql_compt.=' and  (item_lsub like "'.$_POST['flsub'].'%" or lsub_descri like "%'.$_POST['flsub'].'%" ) ';
	$xflsub=$_POST['flsub'];
}

if(isset($_POST['fzsub']) && !empty($_POST['fzsub']))
{
	$sql_compt.=' and  (enti_zsub like "'.$_POST['fzsub'].'%" or zsub_descri like "%'.$_POST['fzsub'].'%" ) ';
	$xfzsub=$_POST['fzsub'];
}

if(isset($_POST['ftpro']) && !empty($_POST['ftpro']))
{
	$sql_compt.=' and  (enti_tpro like "'.$_POST['ftpro'].'%" or tpro_descri like "%'.$_POST['ftpro'].'%" ) ';
	$xftpro=$_POST['ftpro'];
}


if(isset($_POST['fvndd']) && !empty($_POST['fvndd']))
{
	$sql_compt.=' and  (vndd like "'.$_POST['fvndd'].'%" ) ';
	$xfvndd=$_POST['fvndd'];
}


if(isset($_POST['frcdd']) && !empty($_POST['frcdd']))
{
	//$sql_compt.=' and  (enti like "%'.$_POST['frcdd'].'%" ) ';
	$xfrcdd=$_POST['frcdd'];
}


if(isset($_POST['fctlg']) && !empty($_POST['fctlg']))
{$xfctlg=$_POST['fctlg'];}


	$sql_compt.=' and(status!="X") ';
	$sql_compt.=' and(status!="O") ';

// if (mb_stristr('gnya',$_SESSION['user_vcrx_empr']))
// {$sql_compt.=' and(docu!="NV13") ';}

$xforde='D';
if(isset($_POST['forde']) && !empty($_POST['forde']))
{$xforde=$_POST['forde'];}

switch ($xfgrou)
{
// 	case 'D':$xgroup='enti_tpro,enti_descri,enti,docu,ptoe,numero,idnum1 ';break;
	case 'D':$xgroup='docu,fecha,ptoe,numero,idnum1 ';break;
	case 'E':$xgroup='enti_tpro,enti_descri,enti ';break;
	case 'I':$xgroup='item_lsub,item_descri,item ';break;

	case 'P':$xgroup='ptoe ';break;
// 	case 'V':$xgroup='vndd ';break;
// 	case 'Z':$xgroup='zsub ';break;
	case 'T':$xgroup='enti_tpro ';break;
	case 'L':$xgroup='item_lsub ';break;
// 	case 'R':$xgroup='item_at10 ';break;
	case 'R':$xgroup='cair ';break;
	case 'C':$xgroup='ctas ';break;

	case 'A':$xgroup='fanio ';break;
	case 'M':$xgroup='fanio,fmes ';$xforde='S'; break;
	case 'S':$xgroup='fanio,fsema '; $xforde='M'; break;
	case 'F':$xgroup='fecha ';break;

	default :$xgroup='';break;
}

// echo $xforde;
switch ($xforde)
{
// 	case 'D':$xorder=$xgroup;break;
	case 'D':$xorder=str_replace('_descri','',$xgroup);
			$xorder=str_replace(',enti',',enti_descri,enti',$xorder);break;
	case 'C':$xorder=str_replace('_descri','',$xgroup);
			$xorder=str_replace(',item',','.$item_codi.',item_descri,item',$xorder);break;
	case 'T':$xorder='ttotal desc, '.str_replace('_descri','',$xgroup);break;
	case 'S':$xorder='fecha';break;
	case 'M':$xorder='fecha';break;
	default :$xorder='enti_descri,fecha desc,'.$xgroup;break;
}
//$item_codi
//echo $xorder;
//$xorder=str_replace('_codigo','',$xorder)

// explain_sql($sql_compt);

upl_claves2('04',$xfecha1,$xfecha2);
upl_claves2('01',$xfecha1,$xfecha2);

$res_comptt=mysql_query($sql_compt,$link_vcrx);

if (mysql_result($res_comptt,0,'ttcant')==0)
{
// 	$sql_compt=str_replace($xfecha1,'2000-01-01',$sql_compt);
// 	$res_comptt=mysql_query($sql_compt,$link_vcrx);
// 	$xfecha1='2000-01-01';
}

$xttdcto=mysql_result($res_comptt,0,'ttdcto');
$xttprop=mysql_result($res_comptt,0,'ttprop');
$xttice=mysql_result($res_comptt,0,'ttice');
$xttiva=mysql_result($res_comptt,0,'ttiva');
$xttirbp=mysql_result($res_comptt,0,'ttirbp');


$sql_compt.=' group by '.$xgroup;
// if ($xmodi=='0')
// {$sql_compt.=' group by '.$xgroup;}


if ($xmodi=='1')
{
	$xfgrou=$xmodi;
}

if ($xmodi=='2')
{
	$sql_compt=str_replace('sum','',$sql_compt);
	$sql_compt=str_replace('group by ','group by idnum1,iddet,',$sql_compt);
	$sql_compt.=',iddet';
	$xfgrou=$xmodi;
}

$sql_compt.=' order by '.$xorder;

//  echo $sql_compt;
// explain_sql($sql_compt);

$res_compt=mysql_query($sql_compt,$link_vcrx);
$totreg = mysql_num_rows($res_compt);
// echo str_repeat('-',date('s')*2).'';

?>
<table id="tabla_cxccli" width="100%" border="0" cellspacing="0" cellpadding="2" style="border-collapse:collapse;font-size:12px; border:#000000 solid 1px;">

<tr style="border-bottom:#000000 solid 2px; ">
<?php
switch ($xfgrou)
{
	case '1':
?>

	<th></th>
	<th>DOCU</th>
	<th>NUMERO</th>
	<th>FECHA</th>
	<th>PROVEEDOR</th>
	<th>CONCEPTO</th>
	<th>VALOR</th>
  
	<th style="<?php if($empr_impo==0){ echo 'display:none;';} ?>" >IMPOR</th>
	<th>SU.CO.</th>
	<th>F.PAG</th>
	<th>AUTORIZA</th>
	<th></th>
	<th></th>



<?php	
	break;
	case '2':
?>

	<th></th>
	<th>DOCU</th>
	<th>NUMERO</th>
	<th>FECHA</th>
	<th>PROVEEDOR</th>
	<th>ITEM</th>
	<th>DETALLE</th>
	<th>CANT.</th>
	<th>P.UNI</th>
	<th>ITEM</th>
	<th>CAIR</th>
	<th>CUENTA</th>
	<th></th>
	<th></th>
	<th></th>



<?php	
	break;
	case 'D':
?>

	<th></th>
	<th>DOCU</th>
	<th>PTO/NUMERO</th>
	<th>FECHA</th>
	<th>NOMBRE</th>



<?php	
	break;
	case 'E':
?>
	<th></th>
	<th>TIPO</th>
	<th>PROVEEDOR</th>
	<th>NOMBRE</th>
	<th></th>



<?php	
	break;
	case 'I':
?>
	<th></th>
	<th>LINEA</th>
	<th>ITEM</th>
	<th>NOMBRE</th>
	<th>CANT</th>


<?php	
	break;
	case 'M':
?>
	<th></th>
	<th>ANIO</th>
	<th>MES</th>
	<th>NOMBRE</th>
	<th></th>
<?php	
	break;
	case 'S':
?>
	<th></th>
	<th>ANIO</th>
	<th>SEMA</th>
	<th></th>
	<th></th>
<?php	
	break;
	case 'F':
?>
	<th></th>
	<th>ANIO</th>
	<th>MES</th>
	<th>FECHA</th>
	<th></th>

<?php	
	break;
	case 'P':
?>
	<th></th>
	<th>PTO/EMI</th>
	<th></th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'V':
?>
	<th></th>
	<th>VNDD</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'Z':
?>
	<th></th>
	<th>ZONA</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'T':
?>
	<th></th>
	<th>T.PROV.</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'L':
?>
	<th></th>
	<th>LINEA</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'C':
?>
	<th></th>
	<th>CODIGO</th>
	<th>CUENTA</th>
	<th></th>
	<th></th>

<?php	
	break;
	case 'R':
?>
	<th></th>
	<th>COD.RET.</th>
	<th>NOMBRE</th>
	<th></th>
	<th></th>
<?php } ?>

<?php	if ($xmodi=='0')	{	?>

	<th>SUBT</th>
<?php if($xttdcto!=0){ ?>	
	<th>DCTO</th>
<?php } ?>

<?php if ($xttprop!=0){ ?>	
	<th>PROP</th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th>ICE</th>
<?php } ?>

	<th>ST-IVA 0</th>

<?php if ($xttiva!=0){ ?>	
	<th>ST-IVA</th>
	<th>IVA</th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th>IRBP</th>
<?php } ?>

	<th>TOTAL</th>

<?php
switch ($xfgrou)
{
	case 'D':
?>
	<th>CRE</th>
    <?php
//     if(mb_stristr('comp',$tabla))
    {
    ?>
    <th><span title="SUSTENTO DEL COMPROBANTE">SC</span></th>
    <th><span title="FORMA DE PAGO">FP</span></th>
    <th><span title="AUTORIZACION">AUT</span></th>
    <?php } ?>
  
<!-- 
	<th>PROVINCIA /CIUDAD</th>
	<th>VENDEDOR</th>
 -->
<?php	
	break;
	case 'E':
?>
	<th>PROVINCIA /CIUDAD</th>
	<th>VENDEDOR</th>

<?php	
	break;
	case 'I':
?>
	<th>MARCA/MODELO</th>
	<th></th>
<?php } ?>

<?php } ?>

<?php if($xmodi=='2'){ ?>
	
<?php } ?>




</tr>

<?php 
$filax=0;

$cregi=0;  
//$urcdd='';

while($r_compt=mysql_fetch_assoc($res_compt))
{
$cregi++;  
$duni=$r_compt['item_duni'];
?>
<?php
    $enti_descri=$r_compt['enti_descri'];
    $enti_razsoc=$r_compt['enti_razsoc'];
    if($enti_descri=='' and $enti_razsoc=='')    
    {
      get_ruc0($r_compt['enti']);
//       get_ced0($r_compt['enti']);
    }
?>

<?php	
//if ($r_compt['enti_modelo']==$urcdd)
//{if($urcdd==$prcdd){$filax=1;}}
//else
//{if($urcdd!=$prcdd){}else{$filax=4;}}

//$prcdd=$urcdd;
//$urcdd=$r_compt['enti_modelo'];
?>
	
	<tr class="filax" id="<?php echo $r_ped['idnum1']; ?>" valign="top" align="center" style=" <?php if($filax>=4){echo 'border-top:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >
<?php
switch ($xfgrou)
{
	case '1':
?>
<td>
		<a href="../print1.php?prnt=1&docu=<?php echo $r_compt['docu']; ?>&idnum=<?php echo $r_compt['idnum1']; ?>&formato=3" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_compt['docu'];?>-<?php echo $r_compt['numero'];?>"  /></a>
<!--     <a href="../lib/celectop1.php?docu=<?php echo $r_compt['docu']; ?>&idnum=<?php echo $r_compt['idnum1']; ?>&formato=1" target="_blank" tabindex="-1"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_compt['docu'];?>-<?php echo $r_compt['numero'];?>"  /></a> -->
</td>
  <td align="center"><?php echo'<span title="'.$r_compt['docu'].'">'.$r_compt['docu'].'</span>';?></td>
	<td align="center"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['idnum1']; ?>',this);" tabindex="-1"><?php echo '<span title="'.$r_compt['ptonumero'].'">'.$r_compt['numero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_compt['fechadmy'].'">'.$r_compt['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_compt['enti'].'">'.$r_compt['enti_descri'].'</span>';?></td>
		<td align="left"><?php echo'<span title="'.$r_compt['concepto'].'">'.$r_compt['concepto'].'</span>';?></td>
   <td align="right"><?php echo number_format($r_compt['ttotal'],2);?></td>
    
		<?php $pcaption='Impor.';  $pidtxt='impo_'.$r_compt['idnum1']; $pdefa=$r_compt['impor']; $pobj=1; $plist='dl_impor'; $plong=5; if($empr_impo==0){$phide=1;} include('vrgettxt.php'); ?>
    
<!-- <td> -->
		<?php //$pidtxt='impor'; $pcaption='Import.';  $pdocu='FP10'; $pcolu='impor'; $psize=$xfontsize; $plong=12; $plist='dl_impor'; $ptitle='Importación'; include('vrgettxt.php'); ?>
		
    <?php $pcaption=$r_compt['suco_descri'];  $ptabla='suco'; $pidtxt='suco_'.$r_compt['idnum1']; $pdefa=$r_compt['suco']; $pobj=1; $plist='dl_suco'; include('vrgetcod.php'); ?>
<!-- </td> -->
<!-- <td> -->
		<?php $pcaption=$r_compt['fpag_descri'];  $ptabla='fpag'; $pidtxt='fpag_'.$r_compt['idnum1']; $pdefa=$r_compt['fpag']; $pobj=1; $plist='dl_fpag'; include('vrgetcod.php'); ?>
<!-- </td> -->
<!-- <td> -->
		<?php 
    $atrznume=$r_compt['claveacc'];
    if($atrznume!='')
    {
      echo '<td>';
      echo '<span style="font-size:12px;">'.substr($atrznume,24).'</span>';
      echo '<span style="display:none">';
      $pcaption=''; $pidtxt='atrz_'.$r_compt['idnum1']; $pdefa=$r_compt['atrz']; $pobj=1; $plong=10; $phide=1; include('vrgetnum.php');      
      echo '</span>';
      echo '</td>';
    }
    else
    {$pcaption=''; $pidtxt='atrz_'.$r_compt['idnum1']; $pdefa=$r_compt['atrz']; $pobj=1; $plong=10; include('vrgetnum.php');}
    ?>
<!-- </td> -->
		<td>
		<?php $pcaption='Modif';  $ponclick='_modi1('.$r_compt['idnum1'].');'; include('vrbutton.php'); ?>
		</td>
		<td style="font-size:10px;"><div id="error_<?php echo $r_compt['idnum1'];?>"></div></td>

		
	<th></th>

<?php	
	break;
	case '2':
?>
<td>
		<a href="../print1.php?prnt=1&docu=<?php echo $r_compt['docu']; ?>&idnum=<?php echo $r_compt['idnum1']; ?>&formato=3" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_compt['docu'];?>-<?php echo $r_compt['numero'];?>"  /></a>
<!--     <a href="../lib/celectop1.php?docu=<?php echo $r_compt['docu']; ?>&idnum=<?php echo $r_compt['idnum1']; ?>&formato=1" target="_blank" tabindex="-1"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_compt['docu'];?>-<?php echo $r_compt['numero'];?>" /></a> -->
</td>
        <td align="center"><?php echo'<span title="'.$r_compt['docu'].'">'.$r_compt['docu'].'</span>';?></td>
	<td align="center"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['idnum1']; ?>',this);" tabindex="-1"><?php echo '<span title="'.$r_compt['ptonumero'].'">'.$r_compt['numero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_compt['fechadmy'].'">'.$r_compt['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_compt['enti'].'">'.$r_compt['enti_descri'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_compt['item'].'">'.$r_compt['item_descri'].'</span>';?></td>

		<td align="left">
      <?php 
        echo '<span >';
        echo $r_compt['detalle'];
        echo ' /'.$r_compt['itemce'];
        echo ' /'.$r_compt['itemce2'];
        echo '</span>';
      ?>
    </td>
   	<td align="right"><?php echo number_format($r_compt['cant'],2);?></td>
   	<td align="right"><?php echo number_format($r_compt['puni'],2);?></td>

<td>
		<?php $pcaption=$r_compt['item_descri'];  $ptabla='item'; $pidtxt='item_'.$r_compt['idnum1'].'_'.$r_compt['iddet']; $pdefa=$r_compt['item']; $pobj=1; $plist='dl_item'; include('vrgetcod.php'); ?>
</td>
<td>
		<?php $pcaption=$r_compt['cair_descri'];  $ptabla='cair'; $pidtxt='cair_'.$r_compt['idnum1'].'_'.$r_compt['iddet']; $pdefa=$r_compt['cair']; $pobj=1; $plist='dl_cair'; include('vrgetcod.php'); ?>
</td>
<td>
		<?php $pcaption=$r_compt['ctas_descri'];  $ptabla='ctas'; $pidtxt='ctas_'.$r_compt['idnum1'].'_'.$r_compt['iddet']; $pdefa=$r_compt['ctas']; $pobj=1; $plist='dl_ctas'; include('vrgetcod.php'); ?>
</td>
<!-- 		<td><input type="text" value="<?php echo $r_compt['item'];?>" style="width:130px;" id="item_<?php echo $r_compt['idnum1'];?>_<?php echo $r_compt['iddet'];?>"/></td> -->
<!-- 		<td><input type="text" value="<?php echo $r_compt['cair'];?>" style="width:40px;" id="cair_<?php echo $r_compt['idnum1'];?>_<?php echo $r_compt['iddet'];?>"/></td> -->
<!-- 		<td><input type="text" value="<?php echo $r_compt['ctas'];?>" style="width:100px;" id="ctas_<?php echo $r_compt['idnum1'];?>_<?php echo $r_compt['iddet'];?>"/></td> -->
		<td>
			<?php $pcaption='Modif';  $ponclick='_modi2('.$r_compt['idnum1'].','.$r_compt['iddet'].'); '; include('vrbutton.php'); ?>
<!-- 			<input type="button" value="<Modif>" onclick="_modi2('<?php echo $r_compt['idnum1'];?>','<?php echo $r_compt['iddet'];?>');" /> -->
		</td>

		<td style="font-size:10px;"><div id="error_<?php echo $r_compt['idnum1'];?>_<?php echo $r_compt['iddet'];?>"></div></td>

		
	<th></th>

<?php	
	break;
	case 'D':
?>
<td>
	<a href="../print1.php?prnt=1&docu=<?php echo $r_compt['docu']; ?>&idnum=<?php echo $r_compt['idnum1']; ?>&formato=3" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_compt['docu'];?>-<?php echo $r_compt['numero'];?>"  /></a>
<!--     <a href="../lib/celectop1.php?docu=<?php echo $r_compt['docu']; ?>&idnum=<?php echo $r_compt['idnum1']; ?>&formato=1" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_compt['docu'];?>-<?php echo $r_compt['numero'];?>"  /></a> -->
</td>
        <td align="center"><?php echo'<span title="'.$r_compt['docu'].'">'.$r_compt['docu'].'</span>';?></td>
	<td align="center"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['idnum1']; ?>',this);"><?php echo '<span title="'.$r_compt['ptonumero'].'">'.$r_compt['ptonumero'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_compt['fechadmy'].'">'.$r_compt['fechadmy'].'</span>';?></td>
	<td align="left"><?php echo'<span title="'.$r_compt['enti'].'">'.$r_compt['enti_descri'].'</span>';?></td>

<?php	
	break;
	case 'E':
?>
	<td>
    	<a href="../lib/impr_compt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_compt['enti']; ?>&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_compt['enti'];?>"  /></a>
	</td>
        <td align="center"><?php echo'<span title="'.$r_compt['enti_tpro'].'">'.$r_compt['tpro_descri'].'</span>';?></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['enti']; ?>',this);"><?php echo '<span title="'.$r_compt['enti'].'">'.$r_compt['enti'].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_compt['enti_direccion'].'">'.$r_compt['enti_descri'].'</span>';?></td>
	<td></td>

<?php	
	break;
	case 'I':
?>
	<td>
    	<a href="../lib/impr_compt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_compt['item']; ?>&fecha_ini=<?php echo $xfecha1; ?>&fecha_fin=<?php echo $xfecha2; ?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_compt['item'];?>"  /></a>
	</td>
        <td align="center"><?php echo'<span title="'.$r_compt['item_lsub'].'">'.$r_compt['lsub_descri'].'</span>';?></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['item']; ?>',this);"><?php echo '<span title="'.$r_compt['item'].'">'.$r_compt[$item_codi].'</span>';?></a> </td>
	<td align="left"><?php echo'<span title="'.$r_compt['item_mrca'].'">'.$r_compt['item_descri'].'</span>';?></td>
   	<td align="right"><?php echo number_format($r_compt['ttcant'],$duni);?></td>


<?php	
	break;
	case 'M':
?>
		
	<td>
   	<a href="../lib/impr_compt1d.php?grupo=<?php echo $xfgrou; ?>&idnum=<?php echo $r_vtast['fanio'].$r_vtast['fmes']; ?>&fecha_ini=<?php echo  $r_vtast['fanio'].'/'.$r_vtast['fmes'].'/01';?>&fecha_fin=<?php echo $r_vtast['fanio'].'/'.$r_vtast['fmes'].'/'.cal_days_in_month(CAL_GREGORIAN, $r_vtast['fmes'], $r_vtast['fanio']);?>" target="_blank"><img src="http://vcrxol.com/_img/print2.png" width="20"  title="Imprimir  <?php echo $r_vtast['fmesn'];?>"  /></a>
	</td>
  <td align="center"><?php echo'<span title="'.$r_compt['fanio'].'">'.$r_compt['fanio'].'</span>';?></td>
	<td align="center"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['fanio'].$r_compt['fmes']; ?>',this);"><?php echo '<span title="'.$r_compt['fmes'].'">'.$r_compt['fmes'].'</span>';?></a> </td>
	<td align="center"><?php echo'<span title="'.$r_compt['fmesn'].'">'.$r_compt['fmesn'].' /'.$r_compt['fanio'].'</span>';?></td>
	<td></td>

<?php	
	break;
	case 'S':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['item'];?>','<?php echo $r_compt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_compt['fanio'].'">'.$r_compt['fanio'].'</span>';?></td>
	<td align="center"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['fanio'].$r_compt['fsema']; ?>',this);"><?php echo '<span title="'.$r_compt['fsema'].'">'.$r_compt['fsema'].'</span>';?></a> </td>
	<td align="center">
    <?php 
      $week_start = date('d/M',strtotime(sema_ini($r_compt['fecha'])));
      $week_end = date('d/M',strtotime(sema_fin($r_compt['fecha'])));
      echo $week_start.' - '.$week_end;
    ?>
  </td>
<!-- echo date("Y-m-d", strtotime('monday this week'))     -->
	<td></td>

<?php	
	break;
	case 'F':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['item'];?>','<?php echo $r_compt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_compt['fanio'].'">'.$r_compt['fanio'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_compt['fmesn'].'">'.$r_compt['fmesn'].'</span>';?></td>
	<td align="center"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['fecha']; ?>',this);?>',this);"><?php echo '<span title="'.$r_compt['fechadmy'].'">'.$r_compt['fdian'].'-'.$r_compt['fdia'].'</span>';?></a> </td>
	<td></td>

<?php	
	break;
	case 'P':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['item'];?>','<?php echo $r_compt['item_descri'];?>');" type="image" width="20"></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['ptoe']; ?>',this);"><?php echo '<span title="'.$r_compt['ptoe'].'">'.$r_compt['ptoe'].'</span>';?></a> </td>
	<td align="left"></td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'V':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['item'];?>','<?php echo $r_compt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_compt['vndd'].'">'.$r_compt['vndd'].'</span>';?></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['vndd']; ?>',this);"><?php echo '<span title="'.$r_compt['vndd_descri'].'">'.$r_compt['vndd_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'Z':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['item'];?>','<?php echo $r_compt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_compt['zsub'].'">'.$r_compt['zsub'].'</span>';?></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['zsub']; ?>',this);"><?php echo '<span title="'.$r_compt['zsub_descri'].'">'.$r_compt['zsub_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>
<?php	
	break;
	case 'T':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['item'];?>','<?php echo $r_compt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_compt['tpro'].'">'.$r_compt['tpro'].'</span>';?></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['tpro']; ?>',this);"><?php echo '<span title="'.$r_compt['tpro_descri'].'">'.$r_compt['tpro_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>
<?php	
	break;
	case 'L':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['item_lsub'];?>','<?php echo $r_compt['item_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_compt['item_lsub'].'">'.$r_compt['item_lsub'].'</span>';?></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['lsub']; ?>',this);"><?php echo '<span title="'.$r_compt['lsub_descri'].'">'.$r_compt['lsub_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'C':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['ctas'];?>','<?php echo $r_compt['ctas_descri'];?>');" type="image" width="20"></td>
        <td align="left"><?php echo'<span title="'.$r_compt['ctas'].'">'.'</span>';?><?php echo $r_compt['ctas'];?></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['ctas']; ?>',this);"><?php echo '<span title="'.$r_compt['ctas_descri'].'">'.$r_compt['ctas_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>

<?php	
	break;
	case 'R':
?>
	<td><input src="http://vcrxol.com/_img/print2.png" title="Imprimir" onclick="imprimirlista('<?php echo $r_compt['cair'];?>','<?php echo $r_compt['cair_descri'];?>');" type="image" width="20"></td>
        <td align="center"><?php echo'<span title="'.$r_compt['cair'].'">'.'</span>';?><?php echo $r_compt['cair'];?></td>
	<td align="left"><a href="#" onClick="compt1d('<?php echo $xfgrou; ?>','<?php echo $r_compt['cair']; ?>',this);"><?php echo '<span title="'.$r_compt['cair_descri'].'">'.$r_compt['cair_descri'].'</span>';?></a> </td>
	<td align="left"></td>
	<td></td>


<?php }?>

		
<?php
	if ($xmodi=='0')
	{
	?>
   	<td align="right"><?php echo number_format($r_compt['ttsubt'],2);?></td>


<?php if($xttdcto!=0){ ?>	
   	<td align="right" title="<?php echo number_format($r_compt['pdcto'],2).'%';?>"><?php echo '<i>'.number_format($r_compt['ttdcto'],2);?></td>
<?php } ?>


<?php if ($xttprop!=0){ ?>	
   	<td align="right" title="<?php echo number_format($r_compt['pprop'],2).'%';?>"><?php echo number_format($r_compt['ttprop'],2);?></td>
<?php } ?>

<?php if ($xttice!=0){ ?>	
   	<td align="right" title="<?php echo number_format($r_compt['pice'],2).'%';?>"><?php echo number_format($r_compt['ttice'],2);?></td>
<?php } ?>
   	<td align="right"><?php echo number_format($r_compt['ttsubtiva0'],2);?></td>

<?php if ($xttiva!=0){ ?>	
   	<td align="right"><?php echo number_format($r_compt['ttsubtiva'],2);?></td>
   	<td align="right" title="<?php echo number_format($r_compt['piva'],2).'%';?>"><?php echo number_format($r_compt['ttiva'],2);?></td>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
   	<td align="right" title="<?php echo number_format($r_compt['pirbp'],2);?>"><?php echo number_format($r_compt['ttirbp'],2);?></td>
<?php } ?>

   	<td align="right"><?php echo '<b>'.number_format($r_compt['ttotal'],2);?></td>

<?php	
switch ($xfgrou)
{
	case 'D':
?>
        <td align="center"><?php if($r_compt['plazo']>0){echo "S";}else{echo "N";};?></td>
        <td align="center"><span title="<?php echo $r_compt['suco_descri']; ?>"><?php echo $r_compt['suco'];?></span></td>
        <td align="center"><span title="<?php echo $r_compt['fpag_descri']; ?>"><?php echo $r_compt['fpag'];?></span></td>
        <td align="center"><span title="<?php echo $r_compt['atrz'].$r_compt['autornum']; ?>">
          <?php
            if($r_compt['autornum']!=""){echo 'E';}
            else{if($r_compt['atrz']!=""){echo 'I';}else{echo '_';}}
          ?>
          </span></td>
<!-- 
		<td align="center"><?php echo'<span title="'.$r_compt['cdad_descri'].'">'.$r_compt['cdad_descri'].'</span>';?></td>
				<td align="center"><?php echo'<span title="'.$r_compt['vndd'].'">'.$r_compt['vndd'].'</span>';?></td>
 -->
<?php	
	break;
	case 'E':
?>
	<td align="center"><?php echo'<span title="'.$r_compt['enti_telefono'].'">'.$r_compt['prvc_descri'].' /'.$r_compt['cdad_descri'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_compt['vndd'].'">'.$r_compt['vndd'].'</span>';?></td>


<?php	
	break;
	case 'I':
?>
	<td align="center"><?php echo'<span title="'.$r_compt['item_mrca'].'">'.$r_compt['item_mrca'].' /'.$r_compt['item_modelo'].'</span>';?></td>
	<td align="center"></td>


	
<?php }?>


<?php }?>





</tr>
<?php }?>


<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000; <?php if($xmodi!='0'){echo 'display:none;';}?>"</tr>
	<th></th>
	<th></th>
	<th><?php echo $xfgrou.' : '.$cregi; ?></th>
	<th>TOTALES</th>
	<th></th>
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttsubt'),2);?></th>

<?php if($xttdcto!=0){ ?>	
	<th align="right"><?php echo '<i>'.number_format(mysql_result($res_comptt,0,'ttdcto'),2);?></th>
<?php } ?>

<?php if ($xttprop!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttprop'),2);?></th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttice'),2);?></th>
<?php } ?>

	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttsubtiva0'),2);?></th>

<?php if ($xttiva!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttsubtiva'),2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttiva'),2);?></th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttirbp'),2);?></th>
<?php } ?>

	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttotal'),2);?></th>


	</tr>

<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000; <?php if($xmodi!='0'){echo 'display:none;';}?>"</tr>
	<th></th>
	<th></th>
	<th></th>
	<th>PROMEDIOS</th>
	<th></th>
<?php if ($totreg!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttsubt')/$totreg,2);?></th>
<?php } ?>

<?php if($xttdcto!=0){ ?>	
	<th align="right"><?php echo '<i>'.number_format(mysql_result($res_comptt,0,'ttdcto')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttprop!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttprop')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttice!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttice')/$totreg,2);?></th>
<?php } ?>

<?php if ($totreg!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttsubtiva0')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttiva!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttsubtiva')/$totreg,2);?></th>
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttiva')/$totreg,2);?></th>
<?php } ?>

<?php if ($xttirbp!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttirbp')/$totreg,2);?></th>
<?php } ?>

<?php if ($totreg!=0){ ?>	
	<th align="right"><?php echo number_format(mysql_result($res_comptt,0,'ttotal')/$totreg,2);?></th>
<?php } ?>


	</tr>


</table>
</div>