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

<?php ob_start(); ?>
<resultado>
  
<?php
// PRUEBAS	
$date=date('H:i:s',strtotime('now')) ;
?>
  
<?php // echo '<rrr><msgalert>*/*/*/'.$pant.'</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=3; $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>
                <?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 VENTAS</titulo>
                </td>
              </tr>
              <tr>
                <?php $pidtxt='ptov'; $pcaption='PTO.VENTA'; $ptabla='ptov';  $psize=$xfontsize; $pdefa='001101'; if($cfg_empr=='demo'){$pdefa='001001';} $pobj=$xobj; include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='docu'; $pcaption='DOCUMENTO'; $ptabla='docu';  $psize=$xfontsize; $pdefa=''; $pvalue='FC10'; $pwhere='(docu_tabla like "vtas")'; $pobj=$xobj; $phide=1; include('vrgetcod.php'); ?>
              </tr>
              <tr>
                <?php $pidtxt='enti'; $pcaption=$entilabel; $ptabla='enti';  $psize=$xfontsize; $pdefa=$xenti;  $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=10; $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='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; $plong=6;  $pobj=$xobj; include('vrgetval.php'); ?>
              </tr>
              <tr> 
								<?php 	$pidtxt='puni'; $pcaption='P.Unit.';  $pdefa=1; $psize=$xfontsize;  $pobj=$xobj;  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';  $psize=$xfontsize;  $pobj=$xobj; 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','FCXX');"; $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_fact("GRABA");info_docu("PANT3","FCXX");'; $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;

     
     $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).'%"';
          $res_enti=msql_query($sql_enti,$link_vcrx);
        }
     }
     
     if(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).'%"';
          $res_enti=msql_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';}
     $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;}

     $sql_item='update item0 set item_puni="'.$puni.'") where item_codigo like "'.$item.'" and (item_puni=0 or item_puni is null)';
     $res_item=msql_query($sql_item,$link_vcrx);
     
     $fecha=date('Y-m-d',strtotime('now'));
     
     $sql_idnum ='select * from vtas1 ';
     $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 firmafec is null';
     $sql_idnum.=' and status!="X"';
     $sql_idnum.=' and status!="O"';
     $sql_idnum.=' order by idnum1 desc';
     $res_idnum=msql_query($sql_idnum,$link_vcrx);
     
     if(msql_num_rows($res_idnum)==0)
     {
       $sql_inse ='insert into ';
       $sql_inse.='vtas1(docu,ptoe,ptov,enti,fecha,status)';
       $sql_inse.='value("'.$docu.'","'.$ptoe.'","'.$ptov.'","'.$enti.'","'.$fecha.'","-")';
       $res_inse=msql_query($sql_inse,$link_vcrx);

       $res_idnum=msql_query($sql_idnum,$link_vcrx);
       $idnum=msql_result($res_idnum,0,'idnum1');
       $numero=nume_docu($docu,$ptoe);

       $sql_updt='update vtas1 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.='vtas2(idnum2,iddet)';
     $sql_inse.='value("'.$idnum.'","'.$iddet.'")';
     $res_inse=msql_query($sql_inse,$link_vcrx);

     $sql_updt ='update vtas2 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=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;	?>

		