<?php 
declare(strict_types=0);
// session_start();
foreach($_GET  as $key => $value){${$key}=trim($value);} 
foreach($_POST as $key => $value){${$key}=trim($value);} 
include_once('lib_main.php');

if(!empty($empr)){$link_data=msql_connect('','','',$empr); $cfg_empr=$empr;}
$user_codigo=$_SESSION['user_codigo'];
$user0=data_maes('user',$user_codigo);
$empr0=data_maes('empr',$cfg_empr);
$empr_enti0=data_maes('enti',$empr0['empr_ruc']);
if(empty($user_codigo)){include('user_login0.php');return;}

$modu=strtolower($modu);
$tabla=$modu;

// if($docu=='DA16'){$impo_ok=1;}

if(!empty($idnum1))
{
     $sql_docu='select * from '.$tabla.'1 left join '.$tabla.'2 on idnum1=idnum2 where idnum1="'.$idnum1.'" order by iddet desc limit 1';
     $res_docu=msql_query($sql_docu,$link_data);
     $data_docu=msql_fetch_assoc($res_docu);
     foreach($data_docu as $campo => $valor){${$campo}=trim($valor);} 
}


if($tpos>=2)
{
     $item='';
     $cant=0;
     $puni=0;
}

if($tpos==9)
{
     $item='9999999999';
}

if(empty($csub)){$csub = $user0['user_csub'];}
if(empty($csub)){$csub = $_COOKIE['csub'];}

if(empty($modu)){$modu='lpro';}
if(empty($format)){$format=1;}
if(empty($tpos)){$tpos=2;}
if(empty($tpre)){$tpre=2;}

if(empty($enti))
if(substr($docu,0,2)=='PS' or substr($docu,0,2)=='LP')
{$enti=$user0['user_cedula'];}

if($tpos==3 and empty($csub))
{
//      $fecha_vtas=date('Y-m-1',strtotime('-1 month'));
//      $sql_vtas='select distinct ptov from vtas1 where docu like "'.$docu.'%" and status not in("O","X") and fecha>="'.$fecha_vtas.'" order by idnum1 desc';
//      $res_vtas=msql_query($sql_vtas,$link_data);
//      {$xptov=msql_result($res_vtas,0,'ptov');}     
//      if(!empty($xptov))
//      {$ptov=$xptov;}
}

if(empty($csub))
{
     $sql_csub='select * from '.$modu.'1 where iuser="'.$user_codigo.'" order by idnum1 desc limit 1';
     $res_csub=msql_query($sql_csub,$link_data);
     $csub=msql_result($res_csub,0,'csub');
}


if($format==1){$info=substr($modu,0,2).'det2';}
if($format==2){$info=substr($modu,0,2).'deta';}
if($format==3){$info=substr($modu,0,2).'blog';}

// if($tpos==1){$info=substr($modu,0,2).'det1';}
// if($tpos==2){$info=substr($modu,0,2).'det2';}
// if($tpos==3){$info=substr($modu,0,2).'det2';}

$info_descri='LISTA COMPRAS';

if($info=='lpblog'){$info_descri='LISTA DE COMPRAS';}

if(empty($user0['user_tipo'])){$cost='false';}

if(!mb_stristr('sist.supe',$user0['user_tipo']))
{
     $sql_acce='select * from acce1 left join acce2 on idnum1=idnum2 where numero='.$user_codigo.' and docum="COST" and info=1';
     $res_acce=msql_query($sql_acce,$link_data);
     if(msql_num_rows($res_acce)==0){$cost='false';}
}

if(empty($docu)){$docu='PP10';}

$docu0=data_maes('docu',$docu);
$enti0=data_maes('enti',$enti);
$item0=data_maes('item',$item);
$lsub0=data_maes('lsub',$lsub);
$csub0=data_maes('csub',$csub);


$sql_imgi='select * from item0 left join imgi0 on item_codigo=imgi_item where item_status not in ("I","X") and imgi_status not in("I","X") limit 1';
$res_imgi=msql_query($sql_imgi,$link_data);
if(msql_num_rows($res_imgi)!=0){$imgi_ok=1;}

// $sql_mrca='select * from mrca0 where mrca_status not in("I","X") limit 1';
// $res_mrca=msql_query($sql_mrca,$link_data);
// if(msql_num_rows($res_mrca)!=0){$mrca_ok=1;}

// $sql_lote='select * from lote0 where lote_status not in("I","X") limit 1';
// $res_lote=msql_query($sql_lote,$link_data);
// if(msql_num_rows($res_lote)!=0){$lote_ok=1;}



$xtitulo='PROVEEDORES';

$xtitle='REG.'.$xtitulo;
// if($tpos==2){$xtitle='PTO. VENTA';}
$xtopcenter=$xtitle;
if(!empty($docu)){$xtitle.=' /'.$docu;}
if(!empty($numero)){$xtitle.='-'.$numero;}

$fecha0=fecha0($modu);
if(empty($fecha)){$fecha=date('Y-m-d');}

$fecha_min=date('Y-m-d',strtotime('-7 days'));
$fecha_max=date('Y-m-d');
$fecha_max=date('Y-m-d',strtotime('+7 days'));

if($tpos==2)
{
     $fecha_min=date('Y-m-d');
     $fecha_max=date('Y-m-d');
}


// $dom = new DOMDocument();
//      $dom->encoding = 'utf-8';
//      $dom->xmlVersion = '1.0';
//      $dom->formatOutput = true;

// echo $dom->saveXML();


$idnum1='';
//  SELECT DB
// if($tpos==2 and !empty($ptov) and !empty($numero))
// if($tpos!=0 and !empty($ptov) and !empty($numero))
//           echo '*/*/*'.$info;
//           echo '*/*/*'.$sql_info;

if($tpos!=0 and !empty($docu)  and !empty($csub) and !empty($numero))
{
//      $vndd='';
     include('sele_info.php');
     if($user_codigo==2)
     {
//           echo '*/*/*'.$sql_info;
//           echo '*/*/*'.$info;
     }
}


// if($format==2 and !empty($docu) and !empty($bode) and !empty($numero))
// {include('sele_info.php');}



if($format==3 and !empty($enti) )
{include('sele_info.php');}



// echo '*/*/*/*'.$modu;
// echo '*/*/*/*'.$info;

if(!empty($sql_info))
{
     $sql_info1=$sql_info;
     $sql_info1=str_replace('group by idnum1,iddet','group by idnum1',$sql_info1);
     $sql_info1=str_replace('group by idnum1,iddet','group by idnum1',$sql_info1);
     $res_info1=msql_query($sql_info1,$link_data);
     
     $total=msql_result($res_info1,0,'total');
     $tiva=msql_result($res_info1,0,'iva');
     $subt_iva=msql_result($res_info1,0,'subt_iva_hide');
     $subt_iva0=msql_result($res_info1,0,'subt_iva0_hide');
     
     $claveacc=msql_result($res_info1,0,'claveacc_hide');
     $iuser=msql_result($res_info1,0,'iuser_hide');
     
     if(msql_num_rows($res_info1)!=0)
     {
          $subt_iva0=number_format($subt_iva0,2);
          $subt_iva=number_format($subt_iva,2);
          $tiva=number_format($tiva,2);
          $total=number_format($total,2);
          
     }
     
//      echo '========'.$info;
     
     $res_info=msql_query($sql_info,$link_data);
     if(!empty($numero))
     {
          $idnum1=msql_result($res_info,0,'idnum1_hide');
          $edit=msql_result($res_info,0,'b_o');

          $data_head=data_docu($docu,$idnum1);
          foreach($data_head as $key => $value){${$key}=trim($value);} 
          
          $nombre='';
          $email='';
          $wsapp='';
          
     }
}


if(empty($numero))
{
     $dcto=0;
     $total=0;
     $efectivo=0;
     $tarjeta=0;
     $credito=0;
     $cambio=0;

     $nombre='';
     $email='';
     $wsapp='';
     
}



// $zid='dlimpo';     
// $zdocu='FP15';     
// $zcolu='impor';   
// if($docu=='DA16')
// {$zwhere='(fecha>="'.date('Y-m-01',strtotime('-12 month')).'")';}
// include('ele_datalist.php');



if(!empty($enti))
{

$ztabla='umdd';
include('ele_datalist.php');
     
     
// $zid='dliva';     
// $ztabla='item';
// $zcolu='item_iva';     
// $zcolu2='item_iva';     
// include('ele_datalist.php');


$ztabla='enti';
$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from comp1) or left(enti_codigo,10) in(select distinct left(enti,10) from prov1))';
if(substr($docu,0,2)=='PS')
{$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from prov1 where docu like "PS%"))';}
include('ele_datalist.php');

              
$ztabla='item';
$zlpre='ppro1';     
$zstockv=1;     
// $zwhere='(left(item_codigo,2)!="99")';
include('ele_datalist.php');

// $ztabla='cair';
// include('ele_datalist.php');
     
$ztabla='csub';
include('ele_datalist.php');
     
$ztabla='docu';
$zwhere='(docu_tabla="'.$modu.'")';
include('ele_datalist.php');

echo '<datalist id="dlpuni"></datalist>';
echo '<datalist id="dlpvp"></datalist>';
echo '<datalist id="dldcto"></datalist>';

}


// PANTALLA FILTROS
// echo '<div id="filtros" noprint >';
echo '<div id="filtros"  >';
{
     
// $ptoe='001001';     
     
// OCULTOS
echo '<div hide>';   
{
echo '<input id="modu" value="'.$modu.'">';
echo '<input id="info" value="'.$info.'">';
echo '<input id="tpos" value="'.$tpos.'">';
echo '<input id="tpre" value="'.$tpre.'">';
echo '<input id="idnum1" value="'.$idnum1.'">';
echo '<input id="stfin" value="'.$stfin.'">';
echo '<input id="format" value="'.$format.'">';
// echo '<input id="ptoe" value="'.$ptoe.'">';
}     
echo '</div>';     
     
     
$zobj=2;     
include('ele_break.php');
     
$zid='btn_nuevo'; 
$zlabel='Nuevo';
$zalign='right';
$zonclick='{fn_nuevo();}';
$zsize=1.5;     
include('ele_button.php');
     
     
         
$zid='fecha';
$ztype='date';
$zlabel='Fecha';
$zvalue=$fecha;
// $zvalue=$data_docu[$zid];
$zmin=$fecha_min;     
$zmax=$fecha_max;     
// if($tpos==1){$zhide=1;}
// if($tpos==2){$zhide=1;}
$zreado=2;     
// if(substr($docu,0,2)=='LP'){$zhide=1;}     
if(substr($docu,0,2)=='LP'){$zvalue=date('Y-m-d');}     
include('ele_input.php');  
     
 
//      echo '*/*/*/*'.$modu;
//      echo '*/*/*/*'.$info;
     
$zid='docu';
$zlabel='Docum.';
$zvalue=$docu;
$ztabla='docu';
$zwhere='(docu_tabla="'.$modu.'")';
if(!empty($docu)){$zreado=2;}
$zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&tpos="+document.getElementById("tpos").value+"&docu="+document.getElementById("docu").value+"&ptov="+document.getElementById("ptov").value;}';
$zonchange=$zonblur;
if($tpos<=2){$zobj=1;}     
if($tpos<=2){$zreado=1;}     
if($tpos<=2){$zlist='nolist';}     
include('ele_select.php');
     
     
$zid='ptoe';
$ztabla='ptoe';
$zlabel='Pto.Emi.';
$zvalue=$ptoe; 
$zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&tpos="+document.getElementById("tpos").value+"&docu="+document.getElementById("docu").value+"&ptoe="+document.getElementById("ptoe").value;}';
$zonchange=$zonblur;
if($impo_ok==1)
{
     $ptoe='001001';
     $zhide=1;
}
// if(substr($docu,0,2)=='LP'){$ptoe='001001';}
if(substr($docu,0,2)=='PS'){$zvalue='001001';}
if(substr($docu,0,2)=='PS'){$zhide=1;}     
if(substr($docu,0,2)=='LP'){$zvalue='001001';}
if(substr($docu,0,2)=='LP'){$zhide=1;}     
// // if($format==3){$zvalue='001001';}     
// if($format==3){$zhide=1;}     
include('ele_select.php');
     

if($tpos==1){$zobj=1;}     
$zid='numero';
$zlabel='№';
$zvalue=$numero;
$zvalue=(int)$numero;
$zmin=1;
$zmax=9999999;     
$zclass='numeric-int';
$zreado=2;     
$zondblclick='{document.getElementById("'.$zid.'").style.width="'.round(7*2/3,2).'em";}';     
$zonblur='{if(document.getElementById("'.$zid.'").getAttribute("disabled")!=""){document.getElementById("idnum1").value="";fn_consulta();}}';
$zbackcolor='grey';
$zfontcolor='white';
$zsize=1.2;     
if($format==3){$zhide=1;}     
include('ele_input.php');
     
$zid='btn_envia'; 
$zsize=1.5;
$zalign='right';
$zlabel='✆';     
$ztitle='Enviar WhatsApp';     
$zbackcolor='lightgreen';
if(!empty($numero))
{
     if($tpos!=3)
     {$zonclick='{send_wsapp(document.getElementById("wsapp").value);}';}
     if($tpos==3)
     {$zonclick='{send_wsapp();}';}
}
if(empty($claveacc)){$zonclick='{location.reload();';}
if(empty($numero)){$zhide=1;}  
if($format==3){$zhide=1;}     
include('ele_button.php');
     
     
$zid='btn_print'; 
$zsize=1.5;     
$zalign='right';
$zlabel='Imprimir';
$href='?scri=info_docu3&prnt=1&docu='.$docu.'&idnum='.$idnum1.'&formato=';  
$zonclick='{print_url("'.$href.'");}';
if(mb_stristr('hg01',$cfg_empr)){$href.='&destino=txt';}
if(mb_stristr('anml',$cfg_empr)){$href.='&pgsize=P';}
if(empty($idnum1)){$zhide=1;}     
include('ele_button.php');

     
$zid='btn_final'; 
$zlabel='Finalizar';
$zalign='right';
$zonclick='{fn_finalizar();}';
if(!empty($numero) and empty($edit)){$zhide=1;}     
if(empty($numero)){$zhide=1;}     
if($stfin==1){$zhide=1;}    
$zhide=1;     
$zsize=0.8;     
include('ele_button.php');
     
$zid='btn_consul'; 
$zlabel='Consultar';
$zalign='right';
$zonclick='{fn_consulta(event);}';
$zhide=1;     
include('ele_button.php');

echo '<span style="float:right; white-space:nowrap;">';     
// echo $msgres;
echo '</span>';     

     
     
// if(!empty($csub))
// if(!empty($ptoe))
{
     
$zobj=1;     
include('ele_break.php');

     
//if(@mb_stristr('vtas',$modu))
{
     if(1==2)
     {
     $zid='csub';
     $ztabla='csub';
     $zlabel='Centro/Dpto.';
     $zvalue=$csub; 
//      $zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&tpos="+document.getElementById("tpos").value+"&docu="+document.getElementById("docu").value+"&csub="+document.getElementById("csub").value;}';
     $zonblur='fn_consulta();';
     $zonchange=$zonblur;
     if(substr($docu,0,2)=='PP'){$zhide=1;}     
     if($impo_ok==1)
     {$zhide=1;}
     include('ele_select.php');
     }

     
     
     $zid='enti';
     $ztabla='enti';
     $zlabel='Proveedor';
//      if(substr($docu,0,2)=='LP'){$enti=$user0['user_cedula'];}
     $zvalue=$enti;
     if(empty($zvalue)){$zvalue='9999999999999';}
     
     
     if(substr($docu,0,2)=='LP'){$zvalue=$empr0['empr_ruc'];}
     if(substr($docu,0,2)=='LP'){$zlabel='Solicita';}
     if(substr($docu,0,2)=='LP'){$zreado=1;}
//      $zonblur='fn_consulta();';
     if($format==3)
     {$zonchange='fn_consulta();';}
     include('ele_input.php');

     
     if(substr($docu,0,2)=='LP')
     {
          
     }
     
     
     
     
if($impo_ok==1)
{
//      $zid='nume_impo';
     $zid='impor';
     $zlabel='#Import.';
//      $zvalue=$nume_impo;
     $zvalue=$impor;
     $zlist='dlimpo';
     include('ele_input.php');

     
     $zobj=1;
     include('ele_break.php');
     
     
//      $zalign='right';
     $zid='costoe';
     $zlabel='Cost.Exterior';
     $zvalue=$costoe;
     $zclass='numeric-dec';
     $zwidth=7;
     $zmax=999999.99;
//      $zsize=0.8;
//      $zreado=1;
//      if($subt_iva==0 or $tarjeta==0){$zhide=1;}
     include('ele_input.php');
     
     
     
     
}
     
     
     
//      $zid='lpre'; 
//      $zvalue=$lpre;
//      $zlabel='Lista'; 
//      $zonchange='{buscar_item(event);}';
//      $zoptions='puni1,Precio 1;puni2,Precio 2;puni3,Precio 3;puni4,Precio 4;puni5,Precio 5;';
//      $zhide=1;
//      include('ele_select.php');
     
     $zobj=1;
     include('ele_break.php');
     
     if(1==2)
     if($tpos==2)
     {
     $zid='nombre';
     $zlabel='Nombre';
     $zvalue=$nombre;
     $zsize=0.9;
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if($impo_ok==1){$zhide=1;}
     include('ele_input.php');
     
     $zid='email';
     $zlabel='e-mail';
     $zvalue=$email;
     $zsize=0.9;
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if($impo_ok==1){$zhide=1;}
     include('ele_input.php');
     }

     if(1==2)
     if($tpos!=3)
     {
     $zid='wsapp';
     $zlabel='wsapp';
     $zvalue=$wsapp;
     $ztype='number';
     $zsize=0.9;
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if(!empty($numero))
     {$zonclick='{send_wsapp(document.getElementById("wsapp").value);}';}
     if($impo_ok==1){$zhide=1;}
     include('ele_input.php');
     }          
          
     if($tpos==3)
     {
          
     $zid='concepto';
     $zlabel='Concepto';
     $zvalue=$concepto;
//      $zreado=2;
//      $zsize=0.9;
     $zwidth=25;
     $zrows=2;
     include('ele_input.php');

     if(mb_stristr('demo.sawo',$cfg_empr))
     {
          $zid='numoc';
          $zlabel='# Orden';
          $zvalue=$numoc;
          include('ele_input.php');
     }
          
          

                    
     }
          

     $zalign='right';
     $zid='total';
     $zlabel='Total';
     $zvalue='💲 '.$total;
     $zwidth=7;
     $zsize=1.5;
     $zreado=1;
     if($format==3){$zhide=1;}     
     include('ele_input.php');
     
//      $zobj=4;
     $zalign='right';
     $zid='tiva';
     $zlabel='IVA';
     $zvalue=$tiva;
     $zclass='numeric-dec';
     $zwidth=7;
     $zmax=999.99;
     $zsize=0.8;
     $zreado=1;
     if($tiva==0 or $tarjeta==0){$zhide=1;}
     include('ele_input.php');
     
//      $zobj=4;
     $zalign='right';
     $zid='subt_iva';
     $zlabel='Sub IVA';
     $zvalue=$subt_iva;
     $zclass='numeric-dec';
     $zwidth=7;
     $zmax=99999.99;
     $zsize=0.8;
     $zreado=1;
     if($subt_iva==0 or $tarjeta==0){$zhide=1;}
     include('ele_input.php');
     
     
//      $zobj=4;
     $zalign='right';
     $zid='subt_iva0';
     $zlabel='Sub IVA 0';
     $zvalue=$subt_iva0;
     $zclass='numeric-dec';
     $zwidth=7;
     $zmax=99999.99;
     $zsize=0.8;
     $zreado=1;
     if($subt_iva0==0 or $tarjeta==0){$zhide=1;}
     include('ele_input.php');
     
          

     $zobj=2;
     include('ele_break.php');

     
// echo '*/*/*'.$ptoe;
     //820
// if(!empty($csub))
{
     
     $zobj=4;
     $zid='item';
     $zlabel='Item';
     $zvalue=$item;
     $ztabla='item';
     $zopen=0;
//      $zonchange='calc_subtot();';
//      $zonblur=$zonchange;
     if(substr($docu,0,2)=='LP')
     {
          $zonenter='{fn_lp10(event,this.value);}';
          $zonblur='{fn_lp10(event,this.value);}';
     }
     
     if($tpos==1){$zvalue='';}
     if($tpos==1)
     {$zonchange='if(this.value.length==13){document.getElementById("puni").value=0;save_docu(event);};';}
//      {$zonchange='if(this.value.length==13){save_docu(event);};';}
     if($tpos==9){$zhide=1;}
     include('ele_input.php');
     
//      $zobj=4;
//      $zid='producto';
//      $zlabel='Prod/Serv';
//      $zvalue=$producto;
// //      $zwidth=15;
//      include('ele_input.php');
     
     
     $cant=1;
     $zobj=4;
     $zid='cant';
     $zlabel='Cant.';
     $zvalue=$cant;
     $zdefa=1;
     $zmin=0;
     $zmax=9999;
     $zwidth=5;
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     include('ele_input.php');


//      if($cost=='true')
     {
     $zobj=4;
     $zid='puni';
     $zlabel='P.Unit';
     $zvalue=$puni;
//      $zwidth=6 ;
     $zmin=0;
     $zmax=9999.99;
     $zmin=$zmax*(-1);     
//      $max_puni=max_puni();
     if($max_puni>=1000){$zmax=9999.99;}
     if($max_puni>=10000){$zmax=99999.99;}
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
//      $zlist='dlpuni';
//      if($tpre==1){$zreado=1;}
//      if($tpos==1){$zhide=1;}
//      if(substr($docu,0,2)=='PS'){$zreado=1;}
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if(substr($docu,0,2)=='LP'){$zhide=1;}

     include('ele_input.php');
     }

     
     if(empty($numero)){$dcto=0;}
     $zobj=4;
     $zid='dcto';
     $zlabel='% Dcto.';
     $zvalue=$dcto;
//      $zwidth=6;
     $zmin=0;
     $zmax=99.99;
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     if($tpos==1){$zhide=1;}
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if(substr($docu,0,2)=='LP'){$zhide=1;}
//      $zhide=1;
     include('ele_input.php');
     
     $zobj=4;
     $zid='iva';
     $zlabel='% IVA';
     $zvalue=$iva;
     $zmin=0;
     $zmax=9999;
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
//      $zoptions='0;12';
//      include('ele_select.php');
     $zlist='dliva';
     $zsize=0.9;
     if($tpos==1){$zhide=1;}
     if($tpos==2){$zmax=999;$zreado=1;}
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if(substr($docu,0,2)=='LP'){$zhide=1;}
     include('ele_input.php');
     
     $zobj=4;
     $zid='ice';
     $zlabel='ICE';
     $zvalue=$ice;
     $zwidth=6;
//      $zoptions='0;12';
     $zhide=1;
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     if($tpos==1){$zhide=1;}
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if(substr($docu,0,2)=='LP'){$zhide=1;}
     include('ele_select.php');
     
     $zobj=4;
     $zid='irbp';
     $zlabel='IRBP';
     $zvalue=$irbp;
     $zwidth=6;
//      $zoptions='0;12';
     $zhide=1;
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if(substr($docu,0,2)=='LP'){$zhide=1;}
     include('ele_select.php');
     
     $zobj=4;
     $zid='pvp';
     $zlabel='P.V.P.';
     $zvalue=$pvp;
     $zclass='numeric-dec';
     $zwidth=6;
     $zmax=99999;
     $zreado=1;
     if($tpos!=1){$zhide=1;}
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if(substr($docu,0,2)=='LP'){$zhide=1;}
     include('ele_input.php');
     
     
     $zobj=4;
     $zid='subtot';
     $zlabel='Sub-Total';
     $zvalue=$subtot;
     $zclass='numeric-dec';
     $zwidth=7;
     $zmax=99999.99;
     $zreado=1;
     if(substr($docu,0,2)=='PS'){$zhide=1;}
     if(substr($docu,0,2)=='LP'){$zhide=1;}
     include('ele_input.php');

     
     $zobj=4;
     $zid='umdd';
     $ztabla='umdd';
     $zlabel='U.Medida';
     $zvalue=$umdd; 
//      if(substr($docu,0,2)=='PP'){$zhide=1;}     
     if($impo_ok==1){$zhide=1;}
     include('ele_input.php');

//      $cant=1;
     $zobj=4;
     $zid='uxpre';
     $zlabel='U.X Pres.';
     $zvalue=$uxpre;
     $zdefa=1;
     $zmin=1;
     $zmax=9999;
     $zwidth=5;
     $zclass='numeric-int';
     if(substr($docu,0,2)=='PP'){$zhide=1;}
     if(substr($docu,0,2)=='PS'){$zhide=1;}
//      if(substr($docu,0,2)=='LP'){$zhide=1;}
//      $zonchange='calc_subtot();';
//      $zonblur='calc_subtot();';
     include('ele_input.php');
     
     
     
     $zobj=4;
     $zid='presenta';
     $zlabel='Presentación';
     $zlist='dl_presenta';
     $zwidth=10;    
     $zvalue=$presenta;
     $zhide=1;
     include('ele_input.php');
     
     
     
     $zobj=4;
     $zid='csub';
     $ztabla='csub';
     $zlabel='Centro/Dpto.';
     $zvalue=$csub;
     if(empty($zvalue)){$zvalue='GENE-GENE';}
     if(substr($docu,0,2)=='PP'){$zhide=1;}     
     if($impo_ok==1)
     {$zhide=1;}
     include('ele_select.php');

     
     $dias=15;
     $zobj=4;
     $zid='dias';
     $zlabel='Días';
     $zvalue=$dias;
     $zdefa=15;
     $zmin=0;
     $zmax=90;
     $zwidth=5;
     $zclass='numeric-dec';
     $zhide=1;
     if(substr($docu,0,2)=='PS'){$zhide=0;}
     if(substr($docu,0,2)=='LP'){$zhide=0;}
     include('ele_input.php');
     
     

     
     
     
     
}


     

     
     
          

$zid='btn_grabar'; 
$zlabel='Grabar';
$zalign='right';
$zonclick='{save_docu(event);}';
// $zonclick='{save_docu(event);vali_docu(event);}';
$zsize=1.5;
if(!empty($numero) and empty($edit)){$zhide=1;}  
if($format==3){$zhide=0;}
include('ele_button.php');
     

// $zid='btn_envia'; 
// $zlabel='Enviar WA';
// $zalign='right';
// $zonclick='{send_wsapp(document.getElementById("wsapp").value);}';
// if(empty($claveacc))
// {$zonclick='{location.reload();';}
// // $zsize=1.5;
// if(empty($numero)){$zhide=1;}  
// if($tpos>=3){$zhide=1;}  
// // $zsize=2;
// include('ele_button.php');
     
     
     
// $zobj=1;     
// include('ele_break.php');

     
$zid='btn_deleall'; 
$zlabel='Borrar';
$zalign='right';
$zonclick='{fn_deledeta(event);}';
//$zsize=1.5;
$zbackcolor='darkred';
$zfontcolor='white';     
if(!empty($numero) and empty($edit)){$zhide=1;}       
$zhide=1;     
include('ele_button.php');
     
     
     
     

     
if($tpos==9)
{
     $zid='dl_detalle';
     $zdocu=$docu;
     $zcolu='detalle';
     include('ele_datalist.php');
}
     
     
$zobj=4;
$zid='detalle';
$zlabel='Notas';
$zwidth=25;    
$zrows=2;     
$zvalue=$detalle;
if($tpos==9){$zlist='dl_detalle'; $zrows=1;}          
include('ele_input.php');
     
     
}

     
     
     

$zobj=2;     
include('ele_break.php');

}
     
// TITULO     
     
     

}     
// include('ele_break.php');

// echo '*/*/*/'.$_COOKIE['oscreen'];

// COBRO
$sty_pago='float:right;';
if($tpos==3){$sty_pago.='display:none;';}
if($tpos==9){$sty_pago.='display:none;';}
echo '<span noprint style="'.$sty_pago.'"  >';
if(1==2)
{
     $zalign='right';
     $zid='efectivo';
     $zlabel='💵 Efectivo';
     $zvalue=$efectivo;
     $zmin=0;
     $zmax=99999;
     $zwidth=5;
     $zclass='numeric-dec';
//      $zonchange='calc_subtot();';
     if(!empty($numero))
     {
          $zsave=1;
          $zsavet=$modu;
          $zsavei=$idnum1;
          $zsavef=$zid;
//           $zonblur='{save_data(event,this.id);}';
//           $zonblur='{document.getElementById("item").value=""; save_docu(event);}';
     }
     include('ele_input.php');
     
     $zobj=1;
     $zalign='right';
     $zid='caja';
     $zlabel='Caja';
     $ztabla='caja';
     $zvalue=$caja;
     $zdefa=$caja;
//      if(empty($zvalue)){$zvalue=$ptov;$zdefa=$ptov;}
     if($tpos==2){$zvalue=$ptov; $zhide=1;}
     include('ele_select.php');

     $zobj=1;     
     include('ele_break.php');

     $zalign='right';
     $zid='tarjeta';
     $zlabel='💳 Tarjeta';
     $zvalue=$tarjeta;
     $zmin=0;
     $zmax=99999;
     $zwidth=5;
     $zclass='numeric-dec';
//      $zonchange='{calc_subtot();}';
     if(!empty($numero))
     {
          $zsave=1;
          $zsavet=$modu;
          $zsavei=$idnum1;
          $zsavef=$zid;
     }
     include('ele_input.php');
     

     $zobj=1;
     $zalign='right';
     $zid='numvou';
     $zlabel='# Voucher';
     $zvalue=$nume_vouc;
     $zmin=0;
     $zmax=999999999;     
     $zclass='numeric-int';
     if(!empty($numero))
     {
          $zsave=1;
          $zsavet=$modu;
          $zsavei=$idnum1;
          $zsavef=$zid;
//           $zonblur='{save_data(event,this.id);}';
//           $zonblur='{document.getElementById("item").value=""; save_docu(event);}';
     }
     include('ele_input.php');
     
     $zobj=1;     
     include('ele_break.php');
     
     
//      $zobj=4;
     $zalign='right';
     $zid='credito';
     $zlabel='✍ Crédito ';
     $zvalue=$credito;
     $zmin=0;
     $zmax=99999;
     $zwidth=5;
     $zclass='numeric-dec';
     $zonchange='{calc_subtot();}';
//      $zonblur='calc_subtot();';
     if(!empty($numero))
     {
          $zsave=1;
          $zsavet=$modu;
          $zsavei=$idnum1;
          $zsavef=$zid;
//           $zonblur='{save_data(event,this.id);}';
//           $zonblur='{document.getElementById("item").value=""; save_docu(event);}';
     }
     include('ele_input.php');
     
     $zobj=1;     
     include('ele_break.php');

//      $zlabel='💲🪙🔂 Cambio ';
     $zalign='right';
     $zid='cambio';
     $zlabel='🪙  Cambio ';
     $zmin=0;
     $zmax=99999;
     $zwidth=8;
     $zclass='numeric-dec';
     $zreado=1;
     include('ele_input.php');


}
echo '</span>';



// RESULTADO
$sty_resu='float:right;';
$sty_resu='margin:0 auto;';
echo '<span id="main2" style="'.$sty_resu.'"  >';
if(gettype($res_info)!='NULL')
{
     $zreso=$res_info;
     $zinfo=$info;
     $zname=$zname;
     $zhead=0;
     $zgfsize=0.9;
//           $zblockrows=3;
     $zheightrow='2';
     $zblockidnum=1;
     $zhidebtns=1;
//           $zwidthtable='80%';
     include('ele_grid.php');     

//           if($info=='vtblog')
//           {if($idx<msql_num_rows($res_krdx)){echo '<div id="pgbreak" style="height:2em;"></div>';}}

}
echo '</span>';     


echo '</div>';


echo '<div style="height:1em;"></div>';     


$zobj=2;     
include('ele_break.php');

$zobj=1;
$zid='clp10';
$zlabel='Consulta Compras';
$zwidth=25;         
$zvalue='';
$zonenter='{fn_lp10();}';
$zonblur='{fn_lp10();}';
if($tpos==1){$zhide=1;}
if($tpos==9){$zhide=1;}
// if(substr($docu,0,2)=='NC'){$zhide=1;}
include('ele_input.php');



echo '<div align="center" height="auto" id="divextra1" unselectable="on" onmousedown="return false;" onselectstart="return false;">';
echo '</div>';

echo '<div style="clear:both;">&#127380; : '.$idnum1.'</div>';
// echo 'CA:'.$data_head['claveacc'];
     


?>

<script>
function fn_lp10(event,item='')
{
     
     var busca,item,xsrc='?';
     busca=item;
     
     if(busca==='')
     {busca=document.getElementById('clp10').value;}
//      item=document.getElementById('item').value;
     document.getElementById('divextra1').innerHTML='';
     if(busca.length>3)
     {
          var datapost,dato;
          datapost=new FormData();
          datapost.append('script','info_modu3');
//           datapost.append('modu','prov');
          datapost.append('modu','lpro');
          datapost.append('docu','LP10');
//           datapost.append('info','prdeta');
          datapost.append('info','lpdeta');
//           datapost.append('prec','pvp');
          datapost.append('prnt','1');
          datapost.append('zhidebtns','1');
          datapost.append('zhidehead','1');
          datapost.append('item',busca);
          datapost.append('fecha1','2020-01-01');
          datapost.append('cost','true');
          datapost.append('xxfecha1','<?php echo date('Y-01-01');?>');
          datapost.append('xxfecha2','<?php echo date('Y-m-d');?>');
          
          dato=exe_ajax(datapost,'divextra1','',true);
     
//           alert(busca);
     }
     
}
</script>

<script>
function fn_cxcob(event)
{
     var enti,busca,xsrc='?';
     busca=document.getElementById('cib10').value;
     enti=document.getElementById('enti').value;
     
     document.getElementById('divextra1').innerHTML='';
     
//      if(busca.length>3)
     {
          var datapost,dato;
          datapost=new FormData();
          datapost.append('script','info_modu3');
          datapost.append('modu','cxco');
          datapost.append('info','ccresu');
//           datapost.append('prec','pvp');
          datapost.append('prnt','1');
          datapost.append('zhidebtns','1');
          datapost.append('zhidehead','1');
          datapost.append('enti',enti);
          dato=exe_ajax(datapost,'divextra1','',true);
     
     }
     
}
</script>


<script>
function fn_consulta(event)
{
     var xhref='',dataget;
     xhref=xhref+'?scri=<?php echo basename(__FILE__,'.php');?>';
     
     dataget=new_FormData('filtros','get');
     xhref=xhref+dataget;
     
     document.getElementById("main2").innerHTML='Espere...';
     location.href=xhref;
}
</script>

<script>
function fn_nuevo(event)
{
     var enti;
     swal.fire({
          icon:'warning',
          title:'Nuevo Documento',
          text:'Continuar ?',
          confirmButtonText:'Nuevo',
          confirmButtonColor:color1,
          focusCancel:true,
          showCancelButton:true,
          cancelButtonColor: 'darkred',
          timer:60000
     }).then((result) => 
          {
               if(result.isConfirmed)
               {
                    document.getElementById("fecha").value="";
                    document.getElementById("numero").value="";
                    document.getElementById("idnum1").value="";
                    enti=document.getElementById("enti").value;
     //                if(enti.indexOf("9999999999")<0)
                    {document.getElementById("enti").value="";}
                    fn_consulta(event);
               }
          })
}     
     
</script>


<script>
function fn_deledeta(event)
{
     anul_docu(document.getElementById('docu').value,document.getElementById('idnum1').value,'ALL');
     //fn_consulta(event);
     return;
}          
</script>

<script>
function fn_finalizar(event)
{
     swal.fire({
          icon:'warning',
          title:'Finalizar Documento',
          text:'Continuar ?',
          confirmButtonText:'Finalizar',
          confirmButtonColor:color1,
          focusCancel:true,
          showCancelButton:true,
          cancelButtonColor: 'darkred',
          timer:10000
     }).then((result) => 
          {
               if(result.isConfirmed)
               {
               document.getElementById("stfin").value="1";
               save_docu(event);
               }
          })
}
</script>

<script>
function calc_subtot(event)
{
     var cant,puni,dcto,iva,ice,irbp,pvp;
     var subtot,tdcto,tice,tiva,tirbp,subtot,total;
     var efectivo,tarjeta,cambio;
     
     if(document.getElementById("cant")){cant=document.getElementById("cant").value ||0;}
     if(document.getElementById("puni")){puni=document.getElementById("puni").value ||0;}
     if(document.getElementById("dcto")){dcto=document.getElementById("dcto").value ||0;}
     if(document.getElementById("iva")){iva=document.getElementById("iva").value ||0;}
     if(document.getElementById("ice")){ice=document.getElementById("ice").value ||0;}
     if(document.getElementById("irbp")){irbp=document.getElementById("irbp").value ||0;}
     
     if(document.getElementById("subtot")){subtot=document.getElementById("subtot").value ||0;}
     if(document.getElementById("total")){total=document.getElementById("total").value ||0;}
     if(document.getElementById("efectivo")){efectivo=document.getElementById("efectivo").value ||0;}
     if(document.getElementById("tarjeta")){tarjeta=document.getElementById("tarjeta").value ||0;}
     
     subtot=puni;
     tdcto=subtot*dcto/100;
     tice=subtot*ice/100;
     subtot=subtot-tdcto+tice;
     tiva=subtot*iva/100;
     tirbp=cant*irbp;
     subtot=subtot+tiva;
     
     pvp=subtot;
     pvp=pvp.toFixed(2);
     
     subtot=subtot*cant;
     subtot=subtot.toFixed(2);
     
     if(total==0){total=subtot;}
     
     cambio=0;
//      if(efectivo>total && total>0)
     if(parseFloat(efectivo)>parseFloat(total) && parseFloat(total)>0)
     {cambio=efectivo-total;}
     
     if(document.getElementById("pvp")){document.getElementById("pvp").value=parseFloat(pvp);}
     if(document.getElementById("subtot")){document.getElementById("subtot").value=subtot;}
     
     
     if(document.getElementById("cambio"))
     {
          document.getElementById("cambio").value=cambio.toFixed(2);
          document.getElementById('cambio').style.color='navy';
          document.getElementById('cambio').style.fontSize='1.2em';
          if(cambio>0)
          {document.getElementById('cambio').style.color='darkred';}
     }

     
//      document.getElementById('subt_iva0_ele').setAttribute("hide","");
//      document.getElementById('subt_iva_ele').setAttribute("hide","");
//      document.getElementById('tiva_ele').setAttribute("hide","");
//      if(tarjeta>0)
//      {
//           document.getElementById('subt_iva0_ele').removeAttribute("hide");
//           document.getElementById('subt_iva_ele').removeAttribute("hide");
//           document.getElementById('tiva_ele').removeAttribute("hide");
//      }

}
</script>

<script>document.title="<?php echo $xtitle;?>"</script>
<script>document.getElementById('topcenter').innerHTML="<?php echo $xtopcenter;?>"</script>
<script>calc_subtot()</script>

<script>
function send_wsapp(wsapp='')
{
     var url='',texto='',phone='',link='';
//      link='https://<?php //echo strtolower($empr0['empr_codigo']); ?>.vcrxol.com/index3.php?scri=info_docu3&prnt=1&pgsize=P&clave='+'<?php //echo $claveacc; ?>';
     link='https://<?php echo strtolower($empr0['empr_codigo']); ?>.vcrxol.com/index3.php?scri=info_docu3&prnt=1';
     link=link+'&pgsize='+'P';
     link=link+'&clave='+'<?php echo $claveacc; ?>';
//      link=encodeURIComponent(link);
     
     if(document.getElementById('wsapp'))
     {
          wsapp=document.getElementById('wsapp').value;
          if(wsapp==='')
          {
               var mensaje='';
               mensaje=mensaje+'<result>';
               mensaje=mensaje+'<text>Digite Número</text>';
               mensaje=mensaje+'</result>';
               swal_fire(mensaje);
               return;
          }

          if(wsapp.length<10)
          {
               var mensaje='';
               mensaje=mensaje+'<result>';
               mensaje=mensaje+'<text>Número Incompleto</text>';
               mensaje=mensaje+'</result>';
               swal_fire(mensaje);
               return;
          }
          
          wsapp.substring(wsapp.length-10);
          wsapp=String(wsapp).padStart(10, '0');

          phone='593';
          phone='593'+wsapp;
          
          
     }
     
     
     
     {
//      var eol='%0A';
     var eol='\r\n';
     texto ='*= COMPROBANTE ELECTRONICO =*';
     texto+=eol;
     texto+=eol;
     texto+='📃 Tipo  : '+'<?php echo $docu0['docu_descri']; ?>'+' ';
     texto+=eol;
     texto+='🏢 Emisor : '+'<?php echo $empr0['empr_ruc'].' - '.$empr0['empr_descri']; ?>'+' ';
     texto+=eol;
     texto+='👤 Cliente : '+'<?php echo $enti.' - '.ucwords($enti0['enti_descri']) ; ?>'+' ';
     texto+=eol;
     texto+='📆 Fecha : '+'<?php echo $fecha; ?>'+' ';
     texto+=eol;
     texto+='№ : *'+'<?php echo $ptoe.'-'.$numero; ?>'+'* ';
     texto+=eol;
     texto+='💲 Valor : '+'<?php echo number_format($total,2); ?>'+' ';
     texto+=eol;
     texto+='🔑 Clave : '+'<?php echo $claveacc; ?>'+' ';
     texto+=eol;
     texto+='🔗 Link : '+link;
          
     texto=encodeURIComponent(texto);
//      texto=encodeURI(texto);
     }
     
     url=url+'https://api.whatsapp.com/send/';
     url=url+'?phone='+phone;
     url=url+'&text='+texto;
     window.open(url,'_blank');
}
     
     
     
     
</script>



<script>document.getElementById('enti').focus();</script>

<?php if(!empty($idnum1)){ ?>
<script>document.getElementById('item').focus();</script>
<?php } ?>
<?php if($tpos==1){ ?>
<!-- <script>document.getElementById('item').value='';</script> -->
<?php } ?>


<!-- <script>set_noback();</script> -->
<!-- <script>window.onbeforeunload = function(){return 'Are you sure you want to leave?';};</script> -->

