<?php 
declare(strict_types=0);
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);
if(empty($user_codigo)){include('user_login0.php');return;}

$porc_iva=$_SESSION['porc_iva'];
if(empty($porc_iva)){$porc_iva=15;}

// $tpos
// 1= prod o servicio unico     
// 2= punto/venta fecha auto enti nombre wsapp
// 3= registro venta fecha limites     
// 9= item varios

// if(empty($modu) and !empty($docu))
if(!empty($docu))
{
     $docux=data_maes('docu',$docu);
     $modu=$docux['docu_tabla'];
}

if(!empty($docu) and !empty($idnum1))
{vali_docu($docu,$idnum1);}

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

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($ptov)){$ptov = $user0['user_ptov'];}
if(empty($ptov)){$ptov = $_COOKIE['ptov'];}

if(empty($vndd)){$vndd=$user0['user_cedula'];}
if(empty($modu)){$modu='vtas';}
if(empty($format)){$format=1;}
if(empty($tpos)){$tpos=2;}
if(empty($tpre)){$tpre=1;}

if(empty($lpre))
{
     $lpre='puni1';
     if($cfg_empr=='imcp'){$lpre='puni3';}
}

if($tpos==3 and empty($ptov))
{
     $fecha_vtas=date('Y-m-1',strtotime('-1 month'));
     $sql_vtas='select distinct ptov from '.$modu.'1 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($ptov))
{
     $sql_ptov='select * from '.$modu.'1 where iuser="'.$user_codigo.'" order by idnum1 desc limit 1';
     $res_ptov=msql_query($sql_ptov,$link_data);
     $ptov=msql_result($res_ptov,0,'ptov');
}


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';}

// if(empty($info)){$info='vtblog';}
// else{$info='vtdeta';}

$info_descri='VENTAS';

if($info=='vtblog'){$info_descri='PTO.EMISION';}

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

if(!mb_stristr2('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) and $modu=='vtas'){$docu='FC10';}
if(empty($docu) and $modu=='clie'){$docu='PF10';}
if(empty($docu)){$docu='FC10';}

$docu0=data_maes('docu',$docu);
$enti0=data_maes('enti',$enti);
$item0=data_maes('item',$item);
$lsub0=data_maes('lsub',$lsub);
$ptov0=data_maes('ptov',$ptov);
$lote0=data_maes('lote',$lote);


$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='VENTAS';
if($modu=='vtas'){$xtitulo='VENTAS';}
if($modu=='clie'){$xtitulo='CLIENTES';}

$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(date('Y-m-d')<="2025-01-15")
{$fecha_min=date('Y-m-d',strtotime('-15 days'));}



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


// if(date('Y-m-d')<="2025-01-07"){$fecha_min="2024-12-31";}

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

// echo $dom->saveXML();

//if ($cfg_empr=='span')
//   {
//     $fecha_min=date('Y-m-d',strtotime('-150 days'));
//   }

$idnum1='';
//  SELECT DB
if($tpos!=0 and !empty($docu)  and !empty($ptov) and !empty($numero))
{
     include('sele_info.php');
}

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);
     }
     
     $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;
     $transf=0;
     $anticipo=0;
     $credito=0;
     $cambio=0;

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

// datalist
// echo '*/*/*'.$ptov;
// $ptov='';
if(!empty($ptov))
{

     
     
     
$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 vtas1) or left(enti_codigo,10) in(select distinct left(enti,10) from clie1))';}
include('ele_datalist.php');

$ztabla='fpag';
// {$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from vtas1) or left(enti_codigo,10) in(select distinct left(enti,10) from clie1))';}
include('ele_datalist.php');

     
$fec_vndd=date('Y-m-01',strtotime('-3 month'));
$zid='dlvndd';     
$ztabla='enti';
// $zwhere='(  (left(enti_codigo,10) in(select distinct left(vndd,10) from vtas1 where fecha>="'.$fec_vndd.'") or left(enti_codigo,10) in(select distinct left(vndd,10) from clie1  where fecha>="'.$fec_vndd.'") ) )';
$zwhere='( length(trim(enti_codigo))=10 and  (left(enti_codigo,10) in(select distinct left(vndd,10) from vtas1 where fecha>="'.$fec_vndd.'") or left(enti_codigo,10) in(select distinct left(vndd,10) from clie1  where fecha>="'.$fec_vndd.'") ) )';
include('ele_datalist.php');
    
              
$ztabla='item';
$zlpre='pvp1';     
$zstockv=1;     
$zwhere='(left(item_codigo,2)!="99")';
// $zwhere='(left(item_codigo,2)!="99" and left(item_codigo,1)!="0")';     
include('ele_datalist.php');

     
     
     
if($empr0['empr_inve']==1 or $empr0['empr_pduc']==1 or $empr0['empr_prod']==1)
{
     $ztabla='lote';
     include('ele_datalist.php');
}
     
if($empr0['empr_guia']==1 or $empr0['empr_garage']==1 or $empr0['empr_automotriz']==1)
{
     $ztabla='plvh';
     include('ele_datalist.php');
}     
     
$ztabla='cntn';
include('ele_datalist.php');
     
$ztabla='docu';
$zwhere='(docu_tabla="'.$modu.'")';
include('ele_datalist.php');

     
// if(mb_stristr2('icvs.demo',$empr0['empr_codigo']))
if($empr0['empr_inmobil']==1)     
{
     $zid='dlproyecto';     
     $zdocu='FC%';
     $zcolu='proyecto';     
     $zcolu2='proyecto';     
     include('ele_datalist.php');
     
     $zid='dlpisomz';     
     $zdocu='FC%';
     $zcolu='pisomz';     
     $zcolu2='pisomz';     
     include('ele_datalist.php');

     $zid='dldptovi';     
     $zdocu='FC%';
     $zcolu='dptovi';     
     $zcolu2='dptovi';     
     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 >';
$bgcolor=$ptov0['ptov_color'];
echo '<div id="filtros" noprint >';
// echo '<div id="filtros" style="background-color:'.$bgcolor.';" noprint >';
{
     
// OCULTOS
echo '<div hide>';   
{
// echo '<input id="ipip" value="'.$ipip.'">';
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 '</div>';     
     
     
$zobj=2;     
include('ele_break.php');
     
$zid='btn_nuevo'; 
$zlabel='Nuevo';
$zalign='right';
$zonclick='{fn_nuevo();}';
$zsize=1.5;     
include('ele_button.php');
     
     
// $zobj=1;         
$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($empr0['empr_codigo']=='icvs' and date('Y-m-d')<='2024-10-31')
{$zmin='2024-01-01';}
include('ele_input.php');  
     
     
     
$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;}';
// $zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&tpos="+document.getElementById("tpos").value+"&docu="+document.getElementById("docu").value+"&ptov="+document.getElementById("ptov").value+"&modu="+document.getElementById("modu").value;}';
$zonblur='{fn_consulta(event);}';
$zonchange=$zonblur;
if($tpos<=2){$zobj=1;}     
if($tpos<=2){$zreado=1;}     
if($tpos<=2){$zlist='nolist';}     
if($cfg_empr=='icvs'){$zvalue='FC50';}
include('ele_select.php');
     

// $zobj=1;     
$zid='ptov';
$ztabla='ptov';
$zwhere='(ptov_ptoe in (select ptoe_codigo from ptoe0))';     
$zlabel='Pto.Vta.';
$zvalue=$ptov; 
if(!empty($ptov)){$zreado=2;}
if($tpos<=1){$zobj=1;}     
if($tpos<=1){$zreado=1;}     
if($tpos<=1){$zlist='nolist';}     
$zonblur='{fn_consulta(event);}';
$zonchange=$zonblur;
if($cfg_empr=='icvs'){$zvalue='001102';}
include('ele_select.php');


if($tpos==1){$zobj=1;}     
$zid='numero';
// $zlabel='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();}}';
$zonblur='{if(document.getElementById("'.$zid.'").getAttribute("disabled")!=""){document.getElementById("idnum1").value="";}}';
$zonchange='{fn_consulta(event);}';
$zbackcolor='grey';
$zfontcolor='white';
$zsize=1.2;     
include('ele_input.php');
     
$zid='btn_wsapp'; 
$zsize=1.5;
$zalign='right';
$zlabel='✆';
// $zlabel='📞';     
$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;}  
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=';  
if(mb_stristr2('hg01',$cfg_empr)){$href.='&destino=txt';}
if(mb_stristr2('anml',$cfg_empr)){$href.='&pgsize=P';}
$zonclick='{print_url("'.$href.'");}';
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($ptov))
{

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

     
//if(@mb_stristr2('vtas',$modu))
{
//     $zobj=1;
//     include('ele_break.php');

//      echo '==='.$vndd;
     $zid='vndd';
     $ztabla='vndd';
     $zlabel='Vendedor';
     $zvalue=$vndd;
     $zlist='dlvndd';
     $zalign='right';
     if($tpos==1){$zobj=1;$zreado=1;$zhide=0;}
     if($tpos==2){$zreado=2;$zobj=6;}
     if($tpos==3){$zreado=0;$zobj=6;}
     if($tpos!=1){$zdefa=$vndd;}
     if($cfg_empr=='icvs'){$zvalue='9924100028';}
//      if($empr0['empr_codigo']=='facx'){$zhide=1;}
     if($empr0['empr_ceuser']==1)
     {
          $vndd=$user0['user_cedula'];
          $zhide=1;
     }
     
     include('ele_input.php');
     
     $zid='fpag';
     $ztabla='fpag';
     $zwhere='(fpag_codigo*1=1 or fpag_codigo*1>=15)';
     $zlabel='F.Pago';
     $zvalue=$fpag;
     $zalign='right';
     $zexact=1;
     $zdefa='01';
     if($tpos==1){$zobj=1;$zhide=0; }
     if($tpos==2){$zreado=0;$zobj=4;}
     if($tpos==3){$zreado=0;$zobj=4; $zdefa='20';}
     $zsize=0.9;
     if(substr($docu,0,2)=='NC'){$zvalue='';$zhide=1;}
     if($empr0['empr_codigo']=='facx'){$zhide=1;}
     if($empr0['empr_ceuser']==1){$zhide=1;}
     include('ele_select.php');
     

     
     
     
     
     $zid='plazo';
     $zlabel='Plazo';
     $zvalue=$plazo;
     $zalign='right';
     $zsize=0.9;
     $zmin=0;
     $zmax=30*3;
     $zclass='numeric-int';
     if($tpos==1){$zobj=1;$zhide=1; }
     if($tpos==2){$zobj=1;$zhide=1; }
     if($tpos==3){$zreado=0;$zobj=4;}
     if($modu=='clie'){$zmax=30;}
     if(substr($docu,0,2)=='NC'){$zvalue=0;$zhide=1;}
     if($empr0['empr_codigo']=='facx'){$zhide=1;}
     if($empr0['empr_ceuser']==1){$zhide=1;}
     include('ele_input.php');
     
     
     
     
     $zid='enti';
     $zlabel='Cliente';
     $zvalue=$enti;
     if(empty($zvalue)){$zvalue='9999999999999';}
     $ztabla='enti';
     if(substr($docu,0,2)=='NC')
     {
          $zonenter='{fn_cxcob();}';
          $zonblur='{fn_cxcob();}';
     }     
//      $zopen=1;
     include('ele_input.php');

     if(substr($docu,0,2)=='NC')
     {
          
     $zid='dl_docum';     
     $ztabla='docu';
     $zwhere='(docu_tabla="vtas" and left(docu_codigo,1)="F" and docu_status not in ("I","X"))';
     include('ele_datalist.php');
         
     $zid='dl_ptoem';     
     $ztabla='ptov';
     $zwhere='(ptov_status not in ("I","X"))';
     include('ele_datalist.php');
         
     $zid='dl_numer';     
     $ztabla='vtas';
     $zcolu='numero';
     $zcolu2='numero';
     $fecha1=date('Y-m-1',strtotime('-12 month'));
     $zwhere='(fecha>="'.$fecha1.'")';
     include('ele_datalist.php');

          
$zobj=1;     
include('ele_break.php');
          
     $zobj=2;     
     $zid='todocu';
     $zlabel='Modifica';
     $zdefa='FC10';          
     $zvalue=$docum;
     $ztabla='docu';
     $zlist='dl_docum';     
     $zwhere='(docu_tabla="vtas" and left(docu_codigo,1)="F" and docu_status not in ("I","X"))';
     include('ele_select.php');
          
     $zobj=1;     
     $zid='toptoe';
     $zlabel='Pto.Emi';
     $zdefa='';     
     $zvalue=$toptoe;
     $ztabla='ptov';
     $zlist='dl_ptoem';     
     $zwhere='(ptov_status not in ("I","X"))';
     include('ele_select.php');
          
     $zobj=1;     
     $zid='tonume';
     $zlabel='Número';
     $zvalue=$tonume;
     $zmax=999999999;
     $zlist='dl_numer';     
     $zclass='numeric-int';
     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($tpos==2)
     {
     $zid='nombre';
     $zlabel='Nombre';
     $zvalue=$nombre;
     $zsize=0.9;
     include('ele_input.php');
     
     $zid='email';
     $zlabel='e-mail';
     $zvalue=$email;
     $zsize=0.9;
     include('ele_input.php');
     }

     if($tpos!=3)
     {
     $zid='wsapp';
     $zlabel='wsapp';
     $zvalue=$wsapp;
     $ztype='number';
     $zsize=0.9;
     if(!empty($numero))
     {$zonclick='{send_wsapp(document.getElementById("wsapp").value);}';}
     if($user0['user_hide_wsapp']==1)
     {$zhide=1;}
     include('ele_input.php');
     }          
     

// if(mb_stristr2('icvs.demo',$empr0['empr_codigo']))
if($empr0['empr_inmobil']==1)          
{
     
     $zid='proyecto';
     $zlabel='🏗️ Proyecto';
     $zvalue=$proyecto;
     $zwidth=10;
     $zlist='dlproyecto';
     include('ele_input.php');

     $zid='pisomz';
     $zlabel='🏘️ Ps.Mz.';
     $zvalue=$pisomz;
//      $zmin=1;
//      $zmax=9999;
     $zwidth=5;
     $zlist='dlpisomz';
     include('ele_input.php');

     $zid='dptovi';
     $zlabel='🏠 Dp.Villa';
     $zvalue=$dptovi;
     $zmin=1;
     $zmax=999;
//      $zlist='dptovi';
     include('ele_input.php');

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

     
     
     
}     
     
     
     
     
     
     if($tpos==3)
     {
     $zid='concepto';
     $zlabel='Concepto';
     $zvalue=$concepto;
     $zwidth=25;
     $zrows=2;
     include('ele_input.php');

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

     $zalign='right';
     $zid='total';
     $zlabel='Total 💲';
     $zvalue=$total;
//      $zvalue='💲 '.number_format($total,2);
     $zwidth=7;
     $zsize=1.5;
     $zreado=1;
     $zclass='numeric-dec';
     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
     
// and !empty($edit)
     
if(!empty($ptov) )
{
     
     $zobj=4;
     $zid='item';
     $zlabel='Item';
//      $zvalue=$item;
     $ztabla='item';
     $zopen=0;
     $zonchange='calc_subtot();';
     $zonblur=$zonchange;
     if($tpos==1){$zvalue='';}
     if($tpos==1)
     {$zonchange='if(this.value.length==13){document.getElementById("puni").value=0;save_docu(event);};';}
//      if($tpos==1)
//      {$zonkeyup="{if(isValidBarcode(this.value)){btn_grabar.onclick(); this.value=null;};}";}
     if($tpos==9){$zhide=1;}
     if($empr0['empr_ceuser']==1)
     {
          $zvalue='9999999999';
          $zreado=1;
     }
     include('ele_input.php');
     
     
     
     
//      if($empr0['empr_automotriz']==1 and $empr0['empr_impo']==1 and substr($docu,0,2)=='PF')
     if($empr0['empr_automotriz']==1 and $empr0['empr_impo']==1 and mb_stristr2('.PF10.PC10',$docu))
     {
          $ztabla='mdvh';
          include('ele_datalist.php');     

          $zobj=4;
          $zid='mdvh';
          $zlabel='Mod.Vehic.';
          $ztabla='mdvh';
          $zvalue=$mdvh;
     //      if(empty($zvalue)){$zvalue='9999999999999';}
          $zopen=0;
          $zonchange='calc_subtot();';
          $zonblur=$zonchange;
          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');
          
          
          if($docu=='PC10')
          {
               $zid='dlvclor';     
               $ztabla='vinn';
               $zcolu='vinn_clor';     
               $zcolu2='vinn_clor';
//                $zwhere='(vinn)';
               include('ele_datalist.php');

               $zobj=4;
               $zid='clor';
               $zlabel='Color';
               $ztabla='clor';
               $zvalue=$clor;
               $zlist='dlvclor';
          //      if(empty($zvalue)){$zvalue='9999999999999';}
               $zopen=0;
//                $zonchange='calc_subtot();';
//                $zonblur=$zonchange;
               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');
          }
          
     }
     
     if(1==2)
     if($empr0['empr_automotriz']==1 and $empr0['empr_impo']==1 and substr($docu,0,2)=='PC')
     {
          $ztabla='vinn';
          include('ele_datalist.php');     

          $zobj=4;
          $zid='vinn';
          $zlabel='VIN';
          $ztabla='vinn';
          $zvalue=$vinn;
     //      if(empty($zvalue)){$zvalue='9999999999999';}
          $zopen=0;
          $zonchange='calc_subtot();';
          $zonblur=$zonchange;
          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=(float)$cant;
     $zdefa=1;
     $zmin=0;
     $zmax=9999;
     if(mb_stristr2('imcp',$cfg_empr))
     {$zmax=999999;}
//      $zmaxlen=7;
     $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=(float)$puni;
//      $zwidth=6 ;
     $zmin=0;
     $zmax=99999.99;
     $zmin=$zmax*(-1);     
     if($max_puni>=1000){$zmax=9999.99;}
     if($max_puni>=10000){$zmax=99999.99;}
          
     if(mb_stristr2('pcs1.',$empr0['empr_codigo']))
     {$zmax=99999.99;}
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     $zlist='dlpuni';
//      if($tpre==1){$zreado=1;}
     if($tpos==1){$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)=='NC'){$zhide=1;}
     include('ele_input.php');
     
     
     $zobj=4;
     $zid='iva';
     $zlabel='% IVA';
     $zvalue=$iva;
     $zmin=0;
//      $zmax=$_SESSION['porc_iva'];
//      if(empty($zmax)){$zmax=15;}
     $zmax=$porc_iva;
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     $zlist='dliva';
     $zsize=0.9;
     if($tpos==1){$zhide=1;}
     if($tpos==2){$zmax=999;$zreado=1;}
     include('ele_input.php');
     
     $zobj=4;
     $zid='ice';
     $zlabel='ICE';
     $zvalue=$ice;
     $zwidth=6;
     $zhide=1;
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     if($tpos==1){$zhide=1;}
     include('ele_select.php');
     
     $zobj=4;
     $zid='irbp';
     $zlabel='IRBP';
     $zvalue=$irbp;
     $zwidth=6;
     $zhide=1;
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     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;}
     include('ele_input.php');
     
     
     $zobj=4;
     $zid='subtot';
     $zlabel='Sub-Total';
     $zvalue=$subtot;
     $zclass='numeric-dec';
     $zwidth=7;
     $zmax=99999.99;
     $zreado=1;
     include('ele_input.php');

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

     
     
$zid='btn_autor'; 
$zlabel='AUTORIZADO';
$zalign='right';
$zsize=1.5;
$zbackcolor='royalblue';
$zfontcolor='white';
if(empty($numero) or !empty($edit)){$zhide=1;}  
if($format==3){$zhide=0;}
include('ele_button.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_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(mb_stristr2('demo.anml',$cfg_empr))
if($empr0['empr_veterinaria']==1)     
{
     $zid='dl_pcnt';     
     $ztabla='enti';
//      {$zwhere='(left(enti_codigo,10) in(select distinct left(pcnt,10) from vtas2) or left(enti_codigo,10) in(select distinct left(pcnt,10) from clie2))';}
     if(mb_stristr2('anml',$cfg_empr))
     {$zwhere='(left(enti_codigo,2)="99")';}
     include('ele_datalist.php');
     
     $zobj=4;
     $zid='pcnt';
     $ztabla='enti';
     $zlabel='Mascota';
     $zvalue=$pcnt;
     $zlist='dl_pcnt';
     include('ele_input.php');
}
     
// if(mb_stristr2('deXmo.tgck.sawo.ztej',$cfg_empr))
if($empr0['empr_automotriz']==1)     
{
     $zobj=4;
     $zid='plvh';
     $ztabla='plvh';
     $zlabel='Vehículo';
     $zvalue=$plvh;
     include('ele_input.php');
}
     
     
// $zobj=1;     
// include('ele_break.php');

if($empr0['empr_codigo']=='pcs1')
{
     $zobj=4;
     $zid='cntn';
     $ztabla='cntn';
     $zlabel='Contenedor';
     $zvalue=$cntn;
     include('ele_input.php');    
     
     $zobj=4;
     $zid='cntnf1';
     $ztype='date';
     $zlabel='Desde';
     $zvalue=$cntnf1;
     $zmin=date('Y-m-01',strtotime('-1 month'));
     $zmax=date('Y-m-t',strtotime('+1 month'));
     include('ele_input.php');    
     
     $zobj=4;
     $zid='cntnf2';
     $ztype='date';
     $zlabel='Hasta';
     $zvalue=$cntnf2;
     $zmin=date('Y-m-01',strtotime('-1 month'));
     $zmax=date('Y-m-t',strtotime('+1 month'));
     include('ele_input.php');    
     
     $cant=1;
     $zobj=4;
     $zid='envio';
     $zlabel='Envio';
     $zvalue=$envio;
     $zdefa=0;
     $zmin=0;
     $zmax=99;
//      $zmaxlen=7;
     $zwidth=5;
     $zclass='numeric-dec';
//      $zonchange='calc_subtot();';
//      $zonblur='calc_subtot();';
     include('ele_input.php');
     
}
     
     
     
     
if($tpos==9)
{
     $zid='dl_detalle';
     $zdocu=$docu;
     $zcolu='detalle';
     include('ele_datalist.php');
}
     
     
     
if($empr0['empr_ceuser']==1)
{
     $zid='dlnotas';     
     $zdocu='FC%';     
     $zcolu='detalle';   
//      $zwhere='(fecha>="'.date('Y-m-d',strtotime('-1 month')).'")';     
     $zwhere='(iuser="'.$user0['user_codigo'].'" and  fecha>="'.date('Y-m-d',strtotime('-1 month')).'")';     
     include('ele_datalist.php');
}
     
$zobj=4;
$zid='detalle';
$zlabel='Notas';
$zwidth=25;    
$zrows=2;     
$zlist='dlnotas';     
$zvalue=$detalle;
if($tpos==1){$zhide=1;}
if($tpos==2){$zhide=1;}
if($tpos==9){$zlist='dl_detalle'; $zrows=1;}     
if($empr0['empr_ceuser']==1){$zlist='dlnotas'; $zrows=1;}     
include('ele_input.php');
     
     
}

     
    
     

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

}
     
// TITULO     
     
     

}     
// echo '</div>';


     $p12_caduca=$empr0['empr_p12caduca'];
     if($empr0['empr_ceuser']==1)
     {$p12_caduca=$user0['user_p12caduca'];}
     $dias_caduca=days_diff($p12_caduca);  
     if($dias_caduca>=(-15) and $dias_caduca<=(5))
     {
          
          $zid='';
          $zalign='right';
          $zlabel='Fir.Caduca';
          $zvalue=$p12_caduca;
          $zwidth=6;
          $zreado=1;
          if($dias_caduca<=(7))
          {
               $zbackcolor='darkred';
               $zfontcolor='white';
          }
          if($dias_caduca<=(0))
          {
               $zbackcolor='darkred';
               $zfontcolor='white';
          }
          if($dias_caduca<=(-8))
          {
               $zbackcolor='gold';
               $zfontcolor='black';
          }
          include('ele_input.php');
          
          $zobj=2;     
          include('ele_break.php');
     }




// COBRO
$sty_pago='float:right;';
// if($tpos==3){$sty_pago.='display:none;';}
if($empr0['empr_codigo']=='facx'){$sty_pago.='display:none;';}
if($empr0['empr_ceuser']==1){$sty_pago.='display:none;';}
if($tpos==9){$sty_pago.='display:none;';}
echo '<span id="pagos" noprint style="'.$sty_pago.'"  >';
{
     
     $zalign='right';
     $zid='efectivo';
     $zlabel='💵 Efectivo';
     $zvalue=$efectivo;
     $zmin=0;
     $zmax=99999;
     $zwidth=5;
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
//      $zplace='$';
     if(!empty($numero))
     {
          $zsave=1;
          $zsavet=$modu;
          $zsavei=$idnum1;
          $zsavef=$zid;
     }
     include('ele_input.php');
     
     $zobj=1;
     $zalign='right';
     $zid='caja';
     $zlabel='Caja';
     $ztabla='caja';
     $zvalue=$caja;
     $zdefa=$caja;
     $zexact=1;
     if($tpos==2){$zvalue=$ptov; $zhide=1;}
     include('ele_select.php');

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

     
     
     $zobj=1;
     $zalign='right';
     $zid='ctab';
     $zlabel='Cta.Banc.';
     $ztabla='ctab';
     $zvalue=$ctab;
     $zdefa=$ctab;
     $zexact=1;
     if($tpos==1){$zhide=1;}
     include('ele_select.php');
     
     $zobj=1;     
     include('ele_break.php');
     
//      🏦💸
     $zalign='right';
     $zid='transf';
     $zlabel='🏦 Transf.';
     $zvalue=$transf;
     $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='numtra';
     $zlabel='# Transf.';
     $zvalue=$nume_tra;
     $zmin=0;
     $zmax=999999999;     
     $zclass='numeric-int';
     if(!empty($numero))
     {
          $zsave=1;
          $zsavet=$modu;
          $zsavei=$idnum1;
          $zsavef=$zid;
     }
     include('ele_input.php');
     
     $zobj=2;     
     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=2;     
     include('ele_break.php');

$doca='AC';     
$val_anticipo=0;
if(!empty($enti))     
if(substr($enti,0,4)!='9999')     
{$val_anticipo=calc_anticipo($doca,$enti,$fecha2);}
$val_anticipo=number_format($val_anticipo,2);     
     
//      👛
     $zalign='right';
     $zid='anticipo';
     $zlabel='💰Liq.Antic.';
     $zvalue=$anticipo;
     $zplace=$val_anticipo;
     $zmin=0;
     $zmax=99999;
     $zwidth=5;
     $zclass='numeric-dec';
     if($val_anticipo<=0.01){$zhide=1;}
//      $zonchange='{calc_subtot();}';
     if(!empty($numero))
     {
          $zsave=1;
          $zsavet=$modu;
          $zsavei=$idnum1;
          $zsavef=$zid;
     }
     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);}';
     }
     $zhide=1;
     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;
     $zhide=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>';     


//filtros
echo '</div>';


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


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

$zobj=1;
$zid='cstock';
$zlabel='Consulta Stock';
$zwidth=25;         
$zvalue='';
$zonenter='{fn_stock();}';
$zonblur='{fn_stock();}';
if($tpos==1){$zhide=1;}
if($tpos==9){$zhide=1;}
if(substr($docu,0,2)=='NC'){$zhide=1;}
if($empr0['empr_codigo']=='facx'){$zhide=1;}
include('ele_input.php');

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

     $div=$dom_div->appendChild($dom_div->createElement("div",""));
          $div->setAttribute("id","divextra1");
          $div->setAttribute("align","center");
          $div->setAttribute("height","auto");
          $div->setAttribute("unselectable","on");
          $div->setAttribute("onmousedown","return false;");
          $div->setAttribute("onselecstart","return false;");
          $div->setAttribute("style","margin-top:0em;");
echo $dom_div->saveHTML();



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


?>

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

<script>
function fn_cxcob(event)
{
     var enti,busca,xsrc='?';
     busca=document.getElementById('cstock').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 Xcalc_subtot(event)
{
     var tpre;
     var cant,puni,dcto,iva,ice,irbp,pvp;
     var subtot,tdcto,tice,tiva,tirbp,subtot,total;
     var efectivo,tarjeta,anticipo,transf,cambio;
     
     if(document.getElementById("tpre")){tpre=document.getElementById("tpre").value ||0;}
     
     if(document.getElementById("cant")){cant=document.getElementById("cant").value ||0;}
     if(document.getElementById("pvp")){pvp=document.getElementById("pvp").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(tpre==2)
     {
          puni=pvp/(1+iva/100);
          if(document.getElementById("puni")){document.getElementById("puni").value=parseFloat(puni);}
     }
     if(document.getElementById("puni")){puni=document.getElementById("puni").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("anticipo")){tarjeta=document.getElementById("anticipo").value ||0;}
     if(document.getElementById("efectivo")){efectivo=document.getElementById("efectivo").value ||0;}
     if(document.getElementById("tarjeta")){tarjeta=document.getElementById("tarjeta").value ||0;}
     if(document.getElementById("transf")){tarjeta=document.getElementById("transf").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=parseFloat(subtot);}

     console.log(total);
     console.log(efectivo);
     console.log(cambio);
     
     
     if(document.getElementById("cambio"))
     {
          document.getElementById("cambio").value=cambio.toFixed(2);
          document.getElementById('cambio').style.color='navy';
          document.getElementById('cambio').style.fontSize='1.2em';
          document.getElementById('cambio_ele').setAttribute("hide","");
          if(cambio>0)
          {
               document.getElementById('cambio').style.color='darkred';
               document.getElementById('cambio_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/?scri=info_docu3&prnt=1';
     link=link+'&clave='+'<?php echo $claveacc; ?>';
     
     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<9)
          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> -->

