<?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='LCL1';
if($docu==''){$docu='LCL';}
$xptoe='001001';
$ptov="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='';}
else
{
  $docu.='10';
  $docu=substr($docu,0,4);
}


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

$tabla='carr';
  
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 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(); ?>

  
		<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="25%"></td>
              </tr>
              <tr>
                <?php $pidtxt='docu'; $pcaption='DOCUM.'; $ptabla='docu';  $psize=$xfontsize; $pdefa=$docu;  $pobj=3; $preado=1; $pwhere='and(docu_tabla="carr")'; include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php //$pidtxt='bode'; $pcaption='BODEGA'; $ptabla='bode';  $psize=$xfontsize; $pdefa='B001';  $pobj=3;  include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='enti'; $pcaption=$entilabel; $ptabla='enti';  $psize=$xfontsize; $pdefa=$xenti;  $pobj=3; if($idnum!=''){$preado=1;} include('vrgetcod.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='item'; $pcaption='Item'; $ptabla='item'; $pdefa=''; $pnotob=0;  $pexact=0; $psize=$xfontsize;
                    $pwhere='and(item_codigo not like "99%" )';
                    include('vrgetcod.php');
                ?>
              </tr>
              <tr> 
								<?php 	$pidtxt='cant'; $pcaption='Cantidad'; $pdefa=1; $psize=$xfontsize; include('vrgetval.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='puni'; $pcaption='P.Unit.'; $psize=$xfontsize; include('vrgetval.php'); ?>
              </tr>
              <tr> 
								<?php 	$pidtxt='dcto'; $pcaption='Dcto.'; $psize=$xfontsize; include('vrgetval.php'); ?>
              </tr>
              <tr> 
								<?php 	$pidtxt='iva'; $pcaption='IVA';  $psize=$xfontsize; include('vrgetval.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'; $plong=30; $psize=$xfontsize; if($mobile=='true'){$pobj=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><br></td></tr>
           <tr>
           <td>
          <?php 
            $pidtxt='consul'; $pcaption='Consultar ';
            $ponclick='';                                                                 
            $ponclick.='info_docu("PANT3",'.'document.getElementById("docu").value'.')';              
            $psize=$xfontsize; include('vrbutton2.php'); 
          ?>
            </td>  
            </tr>
            <tr><td><br></td></tr>
            <tr>
            <td>
                <?php $pidtxt='graba'; $pcaption='Grabar'; 
                $ponclick='regi_carr("GRABA");'.'info_docu("PANT3",'.'document.getElementById("docu").value'.')'.';';
                $psize=$xfontsize; include('vrbutton2.php'); ?>
            </td>
            <td align="center" >
            <?php $pidtxt='detadocu'; $pcaption='Detalle'; $ponclick='regi_carr("DETA")'; $psize=$xfontsize; $pdefa=0; $phide=1; include('vrchkbox.php'); ?>
            </td>
            </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('LCL.CARR',substr($docu,0,3)) or $item=='')
     {$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=r_fiel('item',$pitem,'puni');}
     if($puni==0){$puni=999999;}
     
     if($enti=='' and substr($docu,0,1)=='I'){$enti='9999999999';}
     if($enti=='' and substr($docu,0,1)=='E'){$enti=$cfg_ruc;}
     $fecha=date('Y-m-d',strtotime('now'));
     $ptoe=r_fiel('ptov',$ptov,'ptoe');
     if($ptoe==''){$ptoe='001001';}
     
     $sql_idnum ='select * from carr1 ';
     $sql_idnum.=' where docu="'.$docu.'"';
     $sql_idnum.=' and ptoe="'.$ptoe.'"';
     $sql_idnum.=' and ptov="'.$ptov.'"';
     $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=msql_query($sql_idnum,$link_vcrx);
     
//      echo 'AQUIIIIIIxxxxxxxxxxxxxxxxxxxxI'.$pant;
//   echo msql_error($link_vcrx);
     if(msql_num_rows($res_idnum)==0)
     {
       $sql_inse ='insert into ';
       $sql_inse.='carr1(docu,ptoe,ptov,enti,fecha,status)';
       $sql_inse.='value("'.$docu.'","'.$ptoe.'","'.$ptov.'","'.$enti.'","'.$fecha.'","-")';
       $res_inse=msql_query($sql_inse,$link_vcrx);
//   echo msql_error($link_vcrx);
         
//        echo $sql_idnum;
       $res_idnum=msql_query($sql_idnum,$link_vcrx);
//   echo msql_error($link_vcrx);
       $idnum=msql_result($res_idnum,0,'idnum1');
       $numero=nume_docu($docu,$ptoe);

       $sql_updt='update carr1 set numero="'.$numero.'" where idnum1="'.$idnum.'"';
       $res_updt=msql_query($sql_updt,$link_vcrx);
     }
     else
     {
       $idnum=msql_result($res_idnum,0,'idnum1');
       $numero=msql_result($res_idnum,0,'numero');
     }  
     
     $iddet=get_iddet($docu,$idnum);
     
     $sql_inse ='insert into ';
     $sql_inse.='carr2(idnum2,iddet)';
     $sql_inse.='value("'.$idnum.'","'.$iddet.'")';
     $res_inse=msql_query($sql_inse,$link_vcrx);

     $sql_updt ='update carr2 set ';
     $sql_updt.='item="'.$item.'",';
     $sql_updt.='cant="'.$cant.'",';
     $sql_updt.='puni="'.$puni.'",';
     $sql_updt.='dcto="'.$dcto.'",';
     $sql_updt.='iva="'.$iva.'",';
     $sql_updt.='detalle="'.$detalle.'"';
     $sql_updt.=' where idnum2="'.$idnum.'"';
     $sql_updt.=' and iddet="'.$iddet.'"';
     $res_updt=msql_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;	?>

		