<?php session_start();?>
//require('../cfg/cfg.php');
// --> require('../cfg/res.php');
//include('../../_lib/php_gene1.php');

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

$ahora=date('Y-m-d');
$ahorita=date('G:i');

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<style>
body{font-family:Arial, Helvetica, sans-serif; font-size:14px;}
</style>
</head>

<body>
<?php
//include('php_session.php');
$fini=$_GET['fini'];
$ffin=$_GET['ffin'];
$clie=$_GET['clie'];
$recu=$_GET['recu'];

   
tfle_costatvd($fini,$ffin);

   
$valo=0;
if(isset($_GET['valo']) && !empty($_GET['valo'])){$valo=1;}
$tipo=$_GET['tipo'];
$tcant=0;
$tpuni=0;
$ttotal=0;
echo $recu;
echo r_fiel('enti',$recu,$campo="descri",$valor="");
//solo sera temporal para corregir el checkbox


$atv_sql ='select *,';
  
if($tipo=='actclie'){$atv_sql.='enti2 as qbreak ';}
if($tipo=='actrecu'){$atv_sql.='enti as qbreak ';}
if($tipo=='actcsub'){$atv_sql.='csub1 as qbreak ';}
  
$atv_sql.='from atvd12 where status!="O" ';
$atv_sql.=' and enti not like "9999%" ';
$atv_sql.=' and enti2 not like "9999%" ';

if(isset($fini) && !empty($fini)){ $atv_sql.=' and fecha>="'.$fini.'" ';}	 
if(isset($ffin) && !empty($ffin)){ $atv_sql.=' and fecha<="'.$ffin.'" ';}	 
if(isset($recu) && !empty($recu)){ $atv_sql.=' and enti="'.$recu.'" ';}
if(isset($clie) && !empty($clie)){ $atv_sql.=' and enti2="'.$clie.'" ';}
//if($tipo=='actclie'){$recu='';}
//if($tipo=='actrecu'){$clie='';}

//if($recu!=''){ $atv_sql.=' and enti="'.$recu.'" ';}
//if($clie!=''){ $atv_sql.=' and enti2="'.$clie.'" ';}

if($tipo=='actclie')  
{$atv_sql.=' order by enti2,fecha,asub'; $consulta=' Actividades X Clienete';}
  
if($tipo=='actrecu')  
{$atv_sql.=' order by enti,fecha,asub';$consulta=' Actividades X Recurso';}
  
if($tipo=='actcsub')  
{$atv_sql.=' order by csub1,fecha,asub';$consulta=' Actividades X C.Costo';}
  
// echo $atv_sql;	 
//	qbreak="'.$_POST['idnum'].'"';
?>
   
<table cellpadding="2" width="100%" border="1" style="border-collapse:collapse;">
<tr align="center" style="font-weight:bolder;font-size:18px;"><td colspan="5">Consulta de<?php echo $consulta; ?></td></tr>
<tr align="center" style="background: #F0F0F0; font-weight:bolder;"><td colspan="6">FILTROS</td></tr>
<tr>
	<td style="font-weight:bolder;" width="10%">DESDE</td><td width="10%"><?php echo $fini;?></td>
    <td style="font-weight:bolder;"  width="10%">CLIENTE</td><td><?php if(empty($clie)){echo 'TODOS';}else{echo r_fiel('enti',$clie,$campo="descri",$valor="");} ?></td>
    <td colspan="2" rowspan="2" style="font-weight:bolder;" width="50%">
    <div>usuario</div>
    <div>fecha:  <?php echo $ahora;?></div>
    <div>hora:  <?php echo $ahorita;?></div>
    </td>
</tr>
<tr style="border-bottom:#CCC solid 1px;">
	<td style="font-weight:bolder;">HASTA</td><td><?php echo $ffin;?></td>
    <td style="font-weight:bolder;">RECURSO</td><td><?php if(empty($recu)){echo 'TODOS';}else{echo r_fiel('enti',$recu,$campo="descri",$valor="");} ?></td>
</tr>

</table>
<hr />
<?php $atv_res=msql_query($atv_sql,$link_vcrx);?>
<?php if(msql_num_rows($atv_res)==0){echo 'No se encontraron datos';}
if(msql_num_rows($atv_res)!=0){?>
<table border="0" cellpadding="2" style="border-collapse:collapse;">
<?php $aux_qbreak='';?>
<?php while($atv_r=msql_fetch_assoc($atv_res)){?>
	
  <?php if($aux_qbreak!=$atv_r['qbreak']&& !empty($aux_qbreak)){$linea=0;?>
        <tr style="border-top:2px solid #000;">
        	<td></td>
            <td align="center"><?php echo number_format($tcant,2);?></td>
            <td align="left"><?php //echo $atv_r['asub_descri'];?></td>
            <td align="left"><?php  //if($tipo=='actclie'){echo $atv_r['enti_descri'];}else{echo $atv_r['enti2'];}?></td>
            <?php if($valo=='1'){?><td align="right"></td><?php }?>
            <?php if($valo=='1'){?><td align="right"><?php echo number_format($ttotal,2);?></td><?php }?>
            <td align="left"><?php //echo $atv_r['detalle'];?></td>
        </tr>
        <tr>
        	<td></td>
            <td></td>
            <td></td>
            <td></td>
            <?php if($valo=='1'){?><td></td><?php }?>
            <?php if($valo=='1'){?><td></td><?php }?>
            <td></td>
        </tr>
		<?php 	$tcant=0;		$tpuni=0;		$ttotal=0;		?>
		<?php }?>

	<?php if($aux_qbreak!=$atv_r['qbreak']){$aux_qbreak=$atv_r['qbreak'];?>
	<?php
   $tipodes='';
   if($tipo=='actclie'){$tipodes='CLIENTE';}
   if($tipo=='actrecu'){$tipodes='RECURSO';}
   if($tipo=='actcsub'){$tipodes='C.COSTO';}
   ?>
   
    <tr><td colspan="8">
    <table width="100%">
        <tr>
            <td style="font-weight:bolder;"><?php  echo $tipodes; ?></td>
            <td>
               <?php
                 if($tipo=='actclie'){echo $atv_r['enti2'].' - '.r_fiel('enti',$atv_r['enti2'],$campo="descri",$valor="");}
                 if($tipo=='actrecu'){echo r_fiel('enti',$atv_r['enti'],$campo="descri",$valor="");}
                 if($tipo=='actcsub'){echo $atv_r['csub1'];}
               ?>
           </td>
            <td style="font-weight:bolder;">CONCEPTO</td>
            <td><?php echo $atv_r['concepto'];?></td>
        </tr>
        <!--<tr>
            <td style="font-weight:bolder;">SERVICIO</td>
            <td><?php echo $atv_r['asub_descri'];?></td>
        </tr>-->
	</table>
    </td>
	</tr>
   
   
    <tr  style="background: #F0F0F0;border-top:2px solid #000;border-bottom:2px solid #000; ">
		    <th style="font-weight:bolder;">FECHA</th>
            <th style="font-weight:bolder;">HORAS</th>
            <th style="font-weight:bolder;width:20%;">ACTIVIDAD</th>
            <th style="font-weight:bolder;">
               <?php  if($tipo=='actclie'){echo 'RECURSO';}?>
               <?php  if($tipo=='actrecu'){echo 'CLIENTE';}?>
               <?php  if($tipo=='actcsub'){echo 'CLIENTE';}?>
            </th>
            <th style="font-weight:bolder;">
               <?php  if($tipo=='actclie'){echo 'C-SUB';}?>
               <?php  if($tipo=='actrecu'){echo 'EMPR.';}?>
               <?php  if($tipo=='actcsub'){echo 'RECU.';}?>
            </th>
            <?php if($valo=='1'){?><th style="font-weight:bolder;">VALOR</th><?php }?>
            <?php if($valo=='1'){?><th style="font-weight:bolder;">TOTAL</th><?php }?>
            <th style="font-weight:bolder;width:30%;">OBSERVACION</th>
        </tr>
    <?php }?>
  
<tr style=" <?php $linea++;if($linea==3){echo 'border-bottom:1px  dotted #000;';$linea=0;}?>" valign="top">
	<td><?php echo $atv_r['fechadmy']?></td>
	<td align="center"><?php echo number_format($atv_r['cant'],2);$tcant+=$atv_r['cant'];?></td>
    <td align="left"><?php echo $atv_r['asub_descri'];?></td>
    <td align="left">
       <?php  if($tipo=='actclie'){echo r_fiel('enti',$atv_r['enti'],"descri");}?>
       <?php  if($tipo=='actrecu'){echo r_fiel('enti',$atv_r['enti2'],"descri");}?>
       <?php  if($tipo=='actcsub'){echo r_fiel('enti',$atv_r['enti2'],"descri");}?>
   </td>
    <td align="left">
       <?php  if($tipo=='actclie'){echo $atv_r['csub1'];}?>
       <?php  if($tipo=='actrecu'){echo $atv_r['empr1'];}?>
       <?php  if($tipo=='actcsub'){echo r_fiel('enti',$atv_r['enti'],"descri");}?>
   </td>
    <?php if($valo=='1'){?><td align="right"><?php echo number_format($atv_r['puni'],2);$tpuni+=$atv_r['puni'];?></td><?php }?>
    <?php if($valo=='1'){?><td align="right"><?php echo number_format($atv_r['total'],2);$ttotal+=$atv_r['total'];?></td><?php }?>
    <td align="left"><?php echo $atv_r['detalle'];?></td>
</tr>
<?php }?>

        <tr style="border-top:2px solid #000;">
	        <td></td>
            <td align="center"><?php echo number_format($tcant,2);?></td>
            <td align="left"><?php //echo $atv_r['asub_descri'];?></td>
            <td align="left"><?php //echo $atv_r['asub_descri'];?></td>
            <td align="left"><?php  //if($tipo=='actclie'){echo $atv_r['enti_descri'];}else{echo $atv_r['enti2'];}?></td>
            <?php if($valo=='1'){?><td align="right"></td><?php }?>
            <?php if($valo=='1'){?><td align="right"><?php echo number_format($ttotal,2);?></td><?php }?>
            <td align="left"><?php //echo $atv_r['detalle'];?></td>
        </tr>

</table>	

<?php }?>
</body>
</html>
