<?php session_start();?>

<!-- GS=Gerente o socio  -->
<!-- S=Supervisor  -->
<!-- Ss=Semi Senior  -->
<!-- As=Asistente -->

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

<?php foreach($_POST as $campo => $valor){${$campo}=$valor;} ?>
<?php // $enti2=$_POST['enti']; ?>

<?php if($pant==''){$pant='PANT0';}?>

<?php if(!mb_stristr('PANT.GRAB',substr($pant,0,4))) {return;} ?>


<?php

$xenti='';
$xdocu='ATV1';
$xptoe='001001';
// $numero='';
?>


<?php	

$user_anul=0;
$user_elim=0;

$modi_docu=1;

if($user_tipo=='sist'){$user_anul=1;$user_elim=1;}
if($user_tipo=='supe'){$user_anul=1;$user_elim=1;}
// if($user_tipo=='clie' and substr($docu,0,2)=='OP'){$user_anul=1;}
if($user_tipo=='clie' and substr($docu,0,2)=='PC'){$user_anul=1;}

if($docu=='undefined')
{$docu='';}
else
{
  $docu.='10';
  $docu=substr($docu,0,4);
}


$tabla=r_fiel('docu',$docu,'tabla');
$entilabel='ENTIDAD';

$tabla='retp';
  
if(@mb_stristr('vtas.clie.carr.retc.guia.',$tabla)){$entilabel='CLIENTE';}
if(@mb_stristr('comp.prov.retp.',$tabla)){$entilabel='PROVEEDOR';}
if(@mb_stristr('RC.',substr($docu,0,2))){$entilabel='CLIENTE';}
if(@mb_stristr('RP.',substr($docu,0,2))){$entilabel='PROVEEDOR';}

$entilabel='CLIENTE';

if($tabla=='acce'){$user_anul=0;$user_elim=0;$modi_docu=0;}


$xfontsize=12;
// if($mobile=='true' and $orient=='V'){$xfontsize=40;}
// if($mobile=='true' and $orient=='H'){$xfontsize=12;}
if($orient=='V'){$xfontsize=40;}
if($orient=='H'){$xfontsize=12;}

$hpant1 =ceil($screenh*0.30);
$hpant11=ceil($screenh*0.10);
$hpant2 =ceil($screenh*0.30);

$wpant1 =$screenw*.9;
	
if ($orient=='V')
{
	$hpant1 =ceil($screenh*0.90);
	$hpant11=ceil($screenh*0.40);
	$hpant2 =ceil($screenh*0.90);
  $wpant1 =$screenw-20;
}

?>

<?php
$docuacce='ATV1';  
// $user_codigo='119';
include('php_useracce.php');
?>


<?php ob_start(); ?>
<resultado>
<?php
// PRUEBAS	
$date=date('H:i:s',strtotime('now')) ;
  
?>	
	
  
<?php if(mb_stristr('PANT0',$pant)){ ?>
<?php $fecha1=date('Y-m-01',strtotime ('today')); ?>
<?php //$fecha2=date('Y-m-01',strtotime ('+1 month')); ?>
<?php //$fecha2=date('Y-m-d',strtotime ($fecha2.' -1 day')); ?>
<?php $fecha2=$fechaa; ?>
  
<?php //val_usercodigo(); ?>
  
<?php $xobj=3;?>
<?php if($mobile=='true'){$xobj=3; $xfontsize=$xfontsize*1.0; }?>

<?php $pidtxt='detadocu'; $pcaption='Detalle'; $ponclick='regi_atvd("DETA")'; $psize=$xfontsize; $pdefa=0; $phide=1; include('vrchkbox.php'); ?>
  
		<div id="pant0" style="border:solid 2px; overflow:auto;">
		<?php { ?>
			<table id="tpant0" cellpadding="2" width="99%" border="0"
					 style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse; background-color:white;">
				<tr>
          <td valign="top">
          <table width="100%" cellpadding="2" border="0"
                style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse; background-color:white;">
              <tr>
                <?php if($mobile!='true'){?>        
                <td width="25%">
                </td>
                <?php } ?>
                <td colspan="2" align="center" <?php if($mobile=='false'){echo 'style="display:none;"';}else{echo 'style="text-transform:uppercase;font-weight:bold;font-family:arial;font-size:'.($xfontsize*1.2).';"';} ?> >
                  <titulo>Registro de Actividades</titulo>
                </td>
              </tr>
              <tr>
                <?php $pidtxt='docu'; $pcaption='docu';  $psize=$xfontsize; $pdefa='ATXX'; $phide=1; $preado=1;   include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='fecha'; $pcaption='Fecha';  $psize=$xfontsize; $pdefa=$xfecha;  $pobj=$xobj; include('vrgetfec.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='user'; $pcaption='USUARIO'; $ptabla='user';  $psize=$xfontsize; $pdefa=$user_codigo;
                $preado=1;
//                 $cargo=get_nomi($user_cedula,'cargo');
//                 if(mb_stristr('SUPE.ENCA',substr($cargo,0,4)) or mb_stristr('sist',$user_tipo)){$preado=0;}
                include('vrgetcod.php'); ?>
              </tr>

          <?php if($mobile!='true'){?>        
          </table>

          </td>
          <td valign="top">
            
            <table width="100%" cellpadding="2" border="0"
                  style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse; background-color:white;">
              <tr>
                <td width="25%"></td>
              </tr>
          <?php } ?>
          
              <tr>
                  <?php $pidtxt='dl_plan'; $ptabla='empr';  include('vrsetlist.php'); ?>
                  <?php $pidtxt='dl_atvd'; $ptabla='empr';  include('vrsetlist.php'); ?>
                 
                <?php $pidtxt='enti'; $pcaption=$entilabel; $ptabla='enti';  $psize=$xfontsize; $pdefa=$xenti; $ponblur="list_atvd();list_plan();"; include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='asub'; $pcaption='ACTIVIDAD'; $ptabla='asub';  $psize=$xfontsize; $pdefa=''; $plist='dl_atvd';   include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='horas'; $pcaption='Horas';  $psize=$xfontsize; $pdefa=1.00;   include('vrgetval.php'); ?>
              </tr>

              
          </table>

          <?php if($mobile!='true'){?>        
          </td>
          <td valign="top">
            
            <table width="100%" cellpadding="2" border="0"
                  style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse; background-color:white;">
              <tr>
                <td width="25%"></td>
              </tr>
          <?php } ?>

							<tr style="display:none;" class="tran cxco dxco">
							<?php //$pidtxt='cxco'; $pcaption='C.X COB.'; $plist='dl_cxco'; $pdefa=''; $ponblur="sele_cxcp('".$pidtxt."');"; $psize=$xfontsize; $plong=30; include('vrgettxt.php'); ?>
							</tr>
               
               
                <?php //$pidtxt='dl_plan1'; $pdocu='PLA1'; $pcolu='idnum1,numero,fecha,enti_descri';    include('vrsetlist.php'); ?>
              <tr>
                <?php //$pidtxt='plan'; $pcaption='PROYECTO';  $psize=$xfontsize; $plong=30; $pdocu='PLA1'; $pcolu='docu,numero,fecha,enti_descri,asub';  $pwhere='(asub like "%0000")';  include('vrgettxt.php'); ?>
                <?php $pidtxt='plan'; $pcaption='PROYECTO';  $plist='dl_plan'; $psize=$xfontsize; $plong=15;  $ponblur="list_atvd();"; include('vrgettxt.php'); ?>
              </tr>
              
              <tr>
                <?php $pidtxt='obser'; $pcaption='Observaciones';  $psize=$xfontsize; $pdefa=''; if($mobile=='true'){$pobj=2;};
                    $plong=40; $prows=3; 
                    include('vrgettxt.php'); ?>
              </tr>

          </table>

          <?php if($mobile!='true'){?>        
          </td>
          <td valign="top">
          <?php } ?>
            
          <table width="100%" cellpadding="2" border="0"
                  style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse; background-color:white;">
           <tr>
           <td style="display:;">
            <?php $pidtxt='consul'; $pcaption='Consultar '; $ponclick="info_docu('PANT3','ATXX');"; $psize=$xfontsize; include('vrbutton.php'); ?>
            </td>  
            <?php if($mobile!='true'){?>        
            </tr>
            <tr><td><br></td></tr>
            <tr>
            <?php } ?>              
            <td>
            <?php $pidtxt='graba'; $pcaption='Grabar'; $ponclick='regi_atvd("GRABA");info_docu("PANT3","ATXX");'; $psize=$xfontsize; include('vrbutton.php'); ?>
            </td>  
            <?php if($mobile!='true'){?>        
              </tr>
              <tr><td><br></td></tr>
              <tr>
            <?php } ?>              
            <td>
            <?php $pidtxt='imprim'; $pcaption='Imprimir '; $ponclick="info_docu('IMPR3','ATXX');"; $psize=$xfontsize; include('vrbutton.php'); ?>
            </td>
            <?php if($mobile=='true'){?>        
              </tr>
              <tr><td><br></td></tr>
              <tr>
            <?php } ?>              
            </tr>
        </table>
        </td>
				</tr>	
			</table>
		<?php } ?>
		</div>	
		<div id="pant1" style="border:solid 1px; overflow:auto; font-family:arial;">
		<div id="tpant1b"></div>
    </div>
		<hr>
		<div id="pant11" style="border:solid 1px; overflow:auto; font-family:arial; display:none;"></div>
		<div id="pant2"  style="border:solid 1px; overflow:auto; font-family:arial; display:none;
					<?php if($orient=='V'){echo'min-height:'.($hpant2-75).'px;';}else{echo'min-height:'.($hpant2-90).'px;';}  ?> 
					<?php if($orient=='V'){echo'height:'.($hpant2-75).'px;';}else{echo'height:'.($hpant2-30).'px;';}  ?> 
           "></div>
		<div id="pant9"></div>
<?php } ?>			


<?php if(mb_stristr('GRABA',$pant)){ ?>

	<?php $crow=0; ?>
	<?php $ccol=0; ?>
	<?php $tnumero=0; ?>
	<?php //echo '***'.date('H:i:s') .'<br>';?>
	<pant1>
	<?php	//val_usercodigo(); ?>
	<?php 	
   if(mb_stristr('GRABA',$pant))  
   {
     $grabaok=1;
     $docu='ATV1';
     $ptoe='001001';
     
     if($enti=='' or $asub=='' or $horas==0)
     {$grabaok=0;}     
     
     if($fecha==''){$fecha=date('Y-m-d');}
     if($user==''){$user=$user_codigo;}
     $user_cedula=r_fiel('user',$user,'user_cedula');
     
        
     $sql_fact ='select * ';
     $sql_fact.=' from atvd1 ';
     $sql_fact.=' where status!="O" ';
     $sql_fact.=' and status !="X" ';
     $sql_fact.=' and docu = "'.$docu.'" ';
     $sql_fact.=' and fecha = "'.$fecha.'" ';
     $sql_fact.=' and enti like "'.substr($user_cedula,0,10).'%" ';
     $sql_fact.=' and length("'.trim($user_cedula).'")>=10 ';
//      $sql_fact.=' and numero = "'.$numero.'" ';
     $sql_fact.=' order by idnum1 desc';
     $res_fact=msql_query($sql_fact,$link_vcrx);
//      echo $sql_fact;
     $idnum=msql_result($res_fact,0,'idnum1');

//      $fecha2=date('Y-m-d',strtotime($fecha.' -2 days'));
     $fecha2=date('Y-m-d',strtotime($fecha.' -360 days'));

     if($fecha>$fechaa){$grabaok=0;}
//      if(days_diff($fecha2,$fecha)>2){$grabaok=0;}
     if(days_diff($fecha2,$fecha)>360){$grabaok=0;}
     
      
     if(mb_stristr($asub,'0000')){$grabaok=0;}
      
     if(empty($plan)){$grabaok=0;}
      
    $numer=$plan*1;
    if($grabaok==1)
    {
       $numer=fillzero($numer);
       
       $sql_plan='select * from plan12 where status not in ("O","X") and enti like "'.substr($enti,0,10).'%" and numero ="'.$numer.'" and asub like "%0000"';
       $res_plan=msql_query($sql_plan,$link_vcrx);
       
       $docum=@msql_result($res_plan,0,'docu');
       $asub0000=@msql_result($res_plan,0,'asub');
       $asub0000d=@msql_result($res_plan,0,'asub_descri');
       $asub0000=substr($asub0000,0,4);
       
       msql_data_seek($res_plan,0);
       while($aso_plan=msql_fetch_assoc($res_plan))
       {$asub0000full.=substr($aso_plan['asub'],0,4);}
       
//        if($asub0000!=substr($asub,0,4))
       if(!mb_stristr($asub0000full,substr($asub,0,4)))
       {
          echo '<msgalert>';
          echo ' Actividad '.$asub .' *** NO CORRESPONDE A '.$asub0000d;
          echo '</msgalert>';
          $grabaok=0;
       }
    }

    
     
     if($grabaok==1)
     {
       if($idnum==0)
       {
         $xdocu=$docu;
         $xptoe=$ptoe;
         $xnumero=nume_docu($xdocu,$xptoe);
         $sql_iret ='insert into atvd1(docu,ptoe,numero,enti,status,fecha,iuser,idate)';
         $sql_iret.='value("'.$xdocu.'","'.$xptoe.'","'.$xnumero.'","'.$user_cedula.'","-","'.$fecha.'","'.$user_codigo.'",now())';
         $res_iret=msql_query($sql_iret,$link_vcrx);

         $res_fact=msql_query($sql_fact,$link_vcrx);
         $idnum=msql_result($res_fact,0,'idnum1');
         
       }
//        echo '*/*/'.$sql_fact;
//        echo '*/*/'.$idnum;
          

       $maxhoras=8;
       $sql_suma='select sum(cant) as tothoras from atvd2 where idnum2="'.$idnum.'"';
       $res_suma=msql_query($sql_suma,$link_vcrx);
       $tothoras=msql_result($res_suma,0,'tothoras');
          
       if($tothoras>$maxhoras)
       {
          echo '<msgalert>';
          echo ' REGISTRO MAXIMO DE HORAS X DIA = '.$maxhoras;
          echo '</msgalert>';
          $grabaok=0;
       }
          
          
       $puni=1;
//        if($sbrta==0 and $base_rta!=0 and $cair!='-' and $stfin!=1)
          if($grabaok==1)
       {
         $iddet=get_iddet($xdocu,$idnum);
         $sql_iatvd ='insert into atvd2(idnum2,iddet,enti2,asub,cant,puni,detalle,idate2)';
         $sql_iatvd.='value("'.$idnum.'","'.$iddet.'","'.$enti.'","'.$asub.'","'.$horas.'","'.$puni.'","'.$obser.'",now())';
         $res_iatvd=msql_query($sql_iatvd,$link_vcrx);
          
//          $docum=substr($plan,0,4);
//          $numer=substr($plan,strpos($plan,'-')+1,9);
         $sql_updt='update atvd2 set docum="'.$docum.'",numer="'.$numer.'" where idnum2="'.$idnum.'" and iddet="'.$iddet.'"';
         $res_updt=msql_query($sql_updt,$link_vcrx);
         $sql_updt='update atvd2 set numerpla="'.$numer.'" where idnum2="'.$idnum.'" and iddet="'.$iddet.'"';
         $res_updt=msql_query($sql_updt,$link_vcrx);
          
//          echo '*/*/*/*/'. $sql_iatvd;
       }

     }
   }   
    
    
  ?>
  </pant1>
	<?php //echo '***'.date('H:i:s') .'<br>';?>
				
<?php } ?>			
    
</resultado>

<?php $obstart = ob_get_clean(); ?>
<?php $obstart = alltrim($obstart) ?>
<?php echo $obstart;	?>

		