<?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='FP10';
// $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;}

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

// $docu='FC10';

// if(empty($docu)){$docu='FC10';}
$tabla=r_fiel('docu',$docu,'tabla');
$entilabel='CLIENTE';

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

<?php ob_start(); ?>
<resultado>
  
<?php
// PRUEBAS	
$date=date('H:i:s',strtotime('now')) ;
?>
  
<?php  //echo '<rrr><msgalert>*/*/*/'.$_SESSION['screen_height'].'</msgalert></rrr>'?>  
  
<?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=2; $xfontsize=$xfontsize*1.0; }?>

            <?php $pidtxt='detadocu'; $pcaption='Detalle'; $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>
                <td width="1%">
                  <?php $pidtxt='dl_enti'; $ptabla='enti'; include('vrsetlist.php'); ?>
                  <?php $pidtxt='dl_item'; $ptabla='item'; $pwhere='(item_codigo not like "99%")'; include('vrsetlist.php'); ?>
                  <?php //$pidtxt='dl_docu'; $ptabla='docu'; include('vrsetlist.php'); ?>
                  <?php //$pidtxt='dl_iva'; $ptabla='item'; $pcolu='item_iva'; include('vrsetlist.php'); ?>
                  
                </td>
              </tr>
            
              <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).';"';} ?> >
                  <?php if($docu==''){$xtitulo='Registro de DIRECCIONES';}else{$xtitulo='Registro de '.r_fiel('docu',$docu);} ?>
                  <titulo><?php echo $xtitulo; ?></titulo>
                </td>
              </tr>
              <tr>
                <?php $pidtxt='enti'; $pcaption='CED/RUC'; $ptabla='enti';  $psize=$xfontsize; $pdefa=$user_cedula; $pvalue=$user_cedula;
                   if(mb_stristr('invi.clie.prov',$user_tipo) or empty($user_tipo)){$preado=1; $pexact=1;}
                  $pobj=$xobj; include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='email'; $pcaption='E-Mail'; $plong=20; $psize=$xfontsize; $pobj=$xobj; include('vrgettxt.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='wsapp'; $pcaption='WhatsApp'; $plong=15; $psize=$xfontsize; $pobj=$xobj; include('vrgetnum.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='pais'; $pcaption='PAIS'; $ptabla='pais'; $pdefa='ECUA'; $pnotob=0;  $pexact=0; $psize=$xfontsize;  $pobj=$xobj;
//                     $plist='dl_i';
//                     $pwhere='and(item_codigo not like "99%" )';
                    include('vrgetcod.php');
                ?>
              </tr>
             <tr>
               <?php  $pcaption='PROVINCIA'; $ptabla='enti'; $pcolu='enti_provincia'; $pidtxt='provincia'; include('vrgettxt.php') ?>
             </tr>
             <tr>
               <?php  $pcaption='CIUDAD'; $ptabla='enti'; $pcolu='enti_ciudad'; $pidtxt='ciudad';  include('vrgettxt.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='calle1'; $pcaption='Calle1'; $ptabla='adrs'; $pcolu='adrs_calle1'; $plong=20; $psize=$xfontsize; $pobj=$xobj; include('vrgettxt.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='calle2'; $pcaption='Calle2'; $ptabla='adrs'; $pcolu='adrs_calle2'; $plong=20; $psize=$xfontsize; $pobj=$xobj; include('vrgettxt.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='callen'; $pcaption='Numero'; $plong=10; $psize=$xfontsize; $pobj=$xobj; include('vrgettxt.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='calle3'; $pcaption='Referencia'; $plong=20; $psize=$xfontsize; $pobj=$xobj; include('vrgettxt.php'); ?>
              </tr>

<?php if(1==1){ ?>
          </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>
              
<?php } ?>              
              
              
         </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="document.getElementById('item').value='';info_maes('PANT1','ADRS');"; $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_adrs('GRABA');document.getElementById('consul').click();"; $psize=$xfontsize; include('vrbutton.php'); ?>
            </td>
            <?php if($mobile=='true'){?>        
              </tr>
              <tr><td><br></td></tr>
              <tr>
            <?php } ?>              
            </tr>
          </table>
            
           </td>

              	
				</tr>	
			</table>

    <div id="clortlla">
    </div>      
      
		<?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;

     $tabla=r_fiel('docu',$docu,'tabla');
     
      
     if(!empty($enti))
     {

         $sql_enti='update enti0 set enti_razsoc="'.$razsoc.'" where enti_codigo like "'.substr($enti,0,10).'%" and (enti_razsoc="" or enti_razsoc is null)';
         $res_enti=mysql_query($sql_enti,$link_vcrx);
       
        $wsapp='0'.($wsapp*1);
        if(strlen($wsapp)>=10)
        {
   //         $entiwsapp=r_fiel('enti',$enti,'wsapp');
   //         if(!mb_stristr($entiwsapp,$wsapp))
           {
   //           $sql_enti='update enti0 set enti_wsapp=concat("'.$entiwsapp.'",",","'.$wsapp.'") where enti_codigo like "'.substr($enti,0,10).'%"';
             $sql_enti='update enti0 set enti_wsapp="'.$wsapp.'" where enti_codigo like "'.substr($enti,0,10).'%"';
             $res_enti=mysql_query($sql_enti,$link_vcrx);
           }
        }

        if(strlen($email)>7 and mb_stristr($email,'@') and mb_stristr($email,'.'))
        {
           $entiemail=r_fiel('enti',$enti,'emailce');
//            if(!mb_stristr($entiemail,$email))
           {
   //           $sql_enti='update enti0 set enti_emailce=concat("'.$entiemail.'",",","'.$email.'") where enti_codigo like "'.substr($enti,0,10).'%"';
             $sql_enti='update enti0 set enti_email="'.$email.'" where enti_codigo like "'.substr($enti,0,10).'%"';
             $res_enti=mysql_query($sql_enti,$link_vcrx);
           }
        }

     }
     
     
     
     if($ptov==''){$ptov='001101';}
     $ptoe=r_fiel('ptov',$ptov,'ptoe');
//      if($ptov==''){$ptov='001101';}

     if($enti==''){$enti='9999999999';}
     
     if($item==''){$item='9999999999'; $grabaok=0;}
     $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;}
     
     $fecha=date('Y-m-d',strtotime('now'));
     
     if($grabaok==0)
     {
       echo '<msgalert>';
       echo ' ERROR AL GRABAR';
       echo '</msgalert>';
     }
     
      
     if($grabaok==1)
     {
        
        $sql_idnum ='select * from '.$tabla.'0 ';
        $sql_idnum.=' where docu="'.$docu.'"';
        $sql_idnum.=' and ptoe="'.$ptoe.'"';
        $sql_idnum.=' and ptov="'.$ptov.'"';
        $sql_idnum.=' and numero>0';
        $sql_idnum.=' and numero is not null';
        $sql_idnum.=' and enti like "'.substr($enti,0,10).'%"';
        $sql_idnum.=' and fecha="'.$fecha.'"';
         if($tabla=='vtas')
         {$sql_idnum.=' and firmafec is null';}
         if($tabla=='clie')
         {$sql_idnum.=' and status="-"';}
        $sql_idnum.=' and status!="X"';
        $sql_idnum.=' and status!="O"';
        $sql_idnum.=' order by idnum1 desc';
        $res_idnum=mysql_query($sql_idnum,$link_vcrx);

        if(mysql_num_rows($res_idnum)==0)
        {
          $sql_inse ='insert into ';
   //        $sql_inse.=''.$tabla.'1(docu,ptoe,ptov,enti,fecha,status)';
   //        $sql_inse.='value("'.$docu.'","'.$ptoe.'","'.$ptov.'","'.$enti.'","'.$fecha.'","-")';
          $sql_inse.=''.$tabla.'1(docu,ptoe,ptov,enti,fecha,status,iuser,idate)';
          $sql_inse.='value("'.$docu.'","'.$ptoe.'","'.$ptov.'","'.$enti.'","'.$fecha.'","-","'.$user_codigo.'",now())';
          $res_inse=mysql_query($sql_inse,$link_vcrx);
          $idnum=mysql_insert_id($link_vcrx);
           echo '<msgsistemas>';
   //         echo '*/*/*'.$sql_idnum.mysql_error();
   //         echo '*/*/*'.$sql_idnum.mysql_error();
           echo '*/*/*'.$idnum;
           echo '</msgsistemas>';

          if($idnum==0)
          {
             $res_idnum=mysql_query($sql_idnum,$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');
        }  

       
          $sql_updt ='update '.$tabla.'1 set ';
          $sql_updt.=' uuser="'.$user_codigo.'",';
          $sql_updt.=' udate=now(),';
          $sql_updt.=' status=status';
          $sql_updt.=' where idnum1="'.$idnum.'"';
          $res_updt=mysql_query($sql_updt,$link_vcrx);
       
        $iddet=get_iddet($docu,$idnum);

        $sql_inse ='insert into ';
        $sql_inse.=''.$tabla.'2(idnum2,iddet)';
        $sql_inse.='value("'.$idnum.'","'.$iddet.'")';
//         $sql_inse.=''.$tabla.'2(idnum2,iddet,idate2)';
//         $sql_inse.='value("'.$idnum.'","'.$iddet.'",now())';
        $res_inse=mysql_query($sql_inse,$link_vcrx);

        $sql_updt ='update '.$tabla.'2 set ';
        $sql_updt.='item="'.$item.'",';
        $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);
     
        $sql_updt ='update '.$tabla.'2 set ';
        $sql_updt.='idate2=now() ';
        $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;	?>

		