<?php session_start();?>
<?php include('../_cfg/config.php');?>
<?php include('php_gene1.php'); ?>
<?php include('php_session.php');?>
<?php foreach($_POST as $campo => $valor){${$campo}=$valor;} ?>

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

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


<?php
$xenti='';
$xdocu='TFI1';
$xptoe='001001';
// $numero='';
// $xcair='312';
if($idnum=='undefined'){$idnum='';}  
?>

<?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($empr_codigo=='tgck'){$bode='B001';}

// echo '*/*/*'.$docu;
if($docu=='undefined')
{$docu='TFI1';}
else
{
//   $docu.='';
//   $docu=substr($docu,0,4);
}


// $tabla=r_fiel('docu',$docu,'tabla');
$entilabel='ENTIDAD';
$tabla='tfin';
  
if($tabla=='acce'){$user_anul=0;$user_elim=0;$modi_docu=0;}


$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=$docu;  
include('php_useracce.php');
?>


<?php $xobj=3;?>
<?php if($mobile=='true'){$xobj=3; $xfontsize=$xfontsize*1.2; }?>



<?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 $pidtxt='dl_numfac'; $ptabla='empr';  include('vrsetlist.php'); ?>
  
<?php val_usercodigo(); ?>
  
<?php $pidtxt='detadocu'; $pcaption='Detalle'; $ponclick='regi_rpro("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>TOMA FISICA</titulo>
                </td>
              </tr>
              <tr>
                <?php $pidtxt='bode'; $pcaption='BODEGA'; $ptabla='bode';  $psize=$xfontsize; $pdefa=$bode;  $pvalue=$bode;
        if($bode==''){$pvalue='B001';}else{$preado=1;}
        $pobj=$xobj;  include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='docu'; $pcaption='DOCUM.'; $ptabla='docu'; $psize=$xfontsize; $pdefa=$docu; $pvalue='TFI1';  
//                   if($docu==''){$pvalue='FC10';}else{$preado=1;}
                //$ponblur.="list_cxcp();";
                  $phide=1;
                  $pobj=$xobj; $pwhere='and(docu_tabla="'.$tabla.'")'; include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php //$pidtxt='enti'; $pcaption=$entilabel; $ptabla='enti';  $psize=$xfontsize; $pdefa=$xenti;  $pobj=$xobj; if($idnum!=''){$preado=1;} 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='item'; $pcaption='Item'; $ptabla='item'; $pdefa=''; $pnotob=0;  $pexact=0; $psize=$xfontsize;  $pobj=$xobj;
                    $pwhere='and(item_codigo not like "99%" )';
                    include('vrgetcod.php');
                ?>
              </tr>
              <tr> 
								<?php 	$pidtxt='cant'; $pcaption='Cantidad';  $pdefa=1; $psize=$xfontsize;  $pobj=$xobj; include('vrgetval.php'); ?>
              </tr>
              <tr> 
								<?php 	//$pidtxt='puni'; $pcaption='P.Unit.';  $pdefa=1; $psize=$xfontsize;  $pobj=$xobj; include('vrgetval.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='lote'; $pcaption='LOTE'; $ptabla='lote'; $psize=$xfontsize; $pobj=$xobj; include('vrgetcod.php'); ?>
              </tr>            
            
              <tr>
                <?php //$pidtxt='bode2'; $pcaption='BODEGA 2'; $ptabla='bode';  $psize=$xfontsize; $pdefa='';  $pobj=$xobj;  include('vrgetcod.php'); ?>
              </tr>
            
              <tr>
                <?php $fecha1=date('Ymd',strtotime('-30 days')); ?>
                <?php $fecha2=date('Ymd',strtotime('+30 days')); ?>
                <?php
          //$pidtxt='numfac'; $pcaption='NUM.FAC.'; 
//                 $plist='dl_numfac';
//                   $pdocu='FC'; $pcolu='numero'; $plong=9;
//                   $pwhere='(fecha between "'.$fecha1.'" and "'.$fecha2.'" )';
               // $psize=$xfontsize; $pdefa='';  $pobj=$xobj;  include('vrgetnum.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 width="25%"></td>
              </tr>
              
              
              
              
               <tr>
								<?php 	$pidtxt='detalle'; $pcaption='NOTAS'; $psize=$xfontsize;  $pobj=$xobj; if($mobile=='true'){$pobj=2;}; $plong=20; $prows=2; 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','TFIX');"; $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_tfin("GRABA");document.getElementById("item").value="";info_docu("PANT3","TFIX");'; $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;
     if(!mb_stristr('IF',substr($docu,0,2)) or $bode=='' or $item=='')
     {$grabaok=0;}     
      
     if(!empty($lote))
     {
        $sql_lote='select * from tfin12 where status!="O" and docu like "IF%" and item="'.$item.'" and lote="'.$lote.'" order by fecha desc';
        $res_lote=mysql_query($sql_lote,$link_vcrx);
        if(mysql_num_rows($res_lote)==0)
        {
           $grabaok=0;
           echo '<msgbox>';
           echo 'LOTE NO CORRESPONDE';
           echo '</msgbox>';
        }
     }

     $itemdesc=r_fiel('item',$item);
     if(mb_stristr($itemdesc,'NUEVO EAN')){r_fiel('item',$item,'descri',$detalle);$detalle='';}  
     if($cant==0){$cant=1;}
     if($puni==0){$puni=1/100;}
     
     if($enti=='' and substr($docu,0,3)=='TFI'){$enti=$cfg_ruc;}
//      if($enti=='' and substr($docu,0,1)=='E'){$enti=$cfg_ruc;}
     $fecha=date('Y-m-d',strtotime('now'));
     $ptoe=r_fiel('bode',$bode,'ptoe');
     if($ptoe==''){$ptoe='001001';}
     
     $sql_idnum ='select * from '.$tabla.'1 ';
     $sql_idnum.=' where docu="'.$docu.'"';
     $sql_idnum.=' and ptoe="'.$ptoe.'"';
     $sql_idnum.=' and bode="'.$bode.'"';
     $sql_idnum.=' and enti like "'.substr($enti,0,10).'%"';
     $sql_idnum.=' and fecha="'.$fecha.'"';
     $sql_idnum.=' and status!="X"';
     $sql_idnum.=' and status!="O"';
     $sql_idnum.=' order by idnum1 desc';
     $res_idnum=mysql_query($sql_idnum,$link_vcrx);
     
//      echo 'AQUIIIIIIxxxxxxxxxxxxxxxxxxxxI'.$pant;
//   echo mysql_error($link_vcrx);
     if(mysql_num_rows($res_idnum)==0)
     {
       $sql_inse ='insert into ';
//        $sql_inse.=''.$tabla.'1(docu,ptoe,bode,enti,fecha,status)';
//        $sql_inse.='value("'.$docu.'","'.$ptoe.'","'.$bode.'","'.$enti.'","'.$fecha.'","-")';
       $sql_inse.=''.$tabla.'1(docu,ptoe,bode,enti,fecha,status,iuser,idate)';
       $sql_inse.='value("'.$docu.'","'.$ptoe.'","'.$bode.'","'.$enti.'","'.$fecha.'","-","'.$user_codigo.'",now())';
       $res_inse=mysql_query($sql_inse,$link_vcrx);
//   echo mysql_error($link_vcrx);
         
//        echo $sql_idnum;
       $res_idnum=mysql_query($sql_idnum,$link_vcrx);
//   echo mysql_error($link_vcrx);
       $idnum=mysql_result($res_idnum,0,'idnum1');
       $numero=nume_docu($docu,$ptoe);

       $sql_updt='update '.$tabla.'1 set numero="'.$numero.'" where idnum1="'.$idnum.'"';
       $res_updt=mysql_query($sql_updt,$link_vcrx);
     }
     else
     {
       $idnum=mysql_result($res_idnum,0,'idnum1');
       $numero=mysql_result($res_idnum,0,'numero');
     }  
     
     $iddet=get_iddet($docu,$idnum);
     
     $sql_inse ='insert into ';
     $sql_inse.=''.$tabla.'2(idnum2,iddet)';
     $sql_inse.='value("'.$idnum.'","'.$iddet.'")';
     $res_inse=mysql_query($sql_inse,$link_vcrx);

     $sql_updt ='update '.$tabla.'2 set ';
     $sql_updt.='item="'.$item.'",';
     $sql_updt.='lote="'.$lote.'",';
     $sql_updt.='cant="'.$cant.'",';
     $sql_updt.='puni="'.$puni.'",';
     $sql_updt.='detalle="'.$detalle.'"';
     $sql_updt.=' where idnum2="'.$idnum.'"';
     $sql_updt.=' and iddet="'.$iddet.'"';
     $res_updt=mysql_query($sql_updt,$link_vcrx);
     
     
   }   
    
    
  ?>

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

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

		