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


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


$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);} 
}


$item='';
$cant=0;
$puni=0;

if(empty($caja) and $tpos==1){$caja=$user0['user_caja'];}
if(empty($modu)){$modu='comp';}
if(empty($ptoe)){$ptoe='001001';}
if(empty($format)){$format=1;}

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

$info_descri='COMPRAS';

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

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

$docu0=data_maes('docu',$docu);
$enti0=data_maes('enti',$enti);
$item0=data_maes('item',$item);
$ctas0=data_maes('ctas',$ctas);
$cair0=data_maes('cair',$cair);
// $lsub0=data_maes('lsub',$lsub);
// $ptov0=data_maes('ptov',$ptov);
$csub0=data_maes('csub',$csub);
$lote0=data_maes('lote',$lote);
$ptoe0=data_maes('ptoe',$ptoe);
$tpro0=data_maes('tpro',$tpro);


// $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_roVENws($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;}

$sql_impo='select * from comp1 where docu="FP15" and ifnull(status,"") not in ("O","X") limit 1';
$res_impo=msql_query($sql_impo,$link_data);
if(msql_num_rows($res_impo)!=0){$impo_ok=1;}


$xtitulo='COMPRAS';
if($modu=='comp'){$xtitulo='COMPRAS';}

$xtitle='REG.COMPRAS';
if($tpos==1){$xtitle='Compras Efectivo';}
$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-01',strtotime('-2 month'));

$fecha_max=date('Y-m-d');

if($tpos==1)
{
     $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==1 and !empty($ptov) and !empty($numero))
if(!empty($docu) and !empty($ptoe) and !empty($numero) and !empty($enti))
{
     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');
     if(msql_num_rows($res_info1)!=0){$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');
          
//           $info=substr($modu,0,2).'resu';
//           include('sele_info.php');
//           $res_info1=msql_query($sql_info,$link_data);
//           $data_head=msql_fetch_assoc($res_info1);

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


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

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


// datalist
{

     
     
$zid='dliva';     
$ztabla='item';
$zcolu='item_iva';     
$zcolu2='item_iva';     
if(!empty($enti))
{$zwhere='(item_codigo in (select distinct item from comp1 left join comp2 on idnum1=idnum2 and status not in("O","X") and enti like "'.substr($enti,0,10).'%"))';}
include('ele_datalist.php');

$zid='dlice';     
$ztabla='item';
$zcolu='item_ice';     
$zcolu2='item_ice';     
if(!empty($enti))
{$zwhere='(item_codigo in (select distinct item from comp1 left join comp2 on idnum1=idnum2 and status not in("O","X") and enti like "'.substr($enti,0,10).'%"))';}
include('ele_datalist.php');

$zid='dlirbp';     
$ztabla='item';
$zcolu='item_irbp';     
$zcolu2='item_irbp';     
if(!empty($enti))
{$zwhere='(item_codigo in (select distinct item from comp1 left join comp2 on idnum1=idnum2 and status not in("O","X") and enti like "'.substr($enti,0,10).'%"))';}
include('ele_datalist.php');

$zid='dlptoe';     
$ztabla='comp';
$zcolu='ptoe';     
$zcolu2='ptoe';    
if(!empty($enti))
{$zwhere='(enti like "'.substr($enti,0,10).'%")';}
// {$zwhere='(enti like "'.substr($enti,0,10).'%" and ifnull(claveacc,"")="")';}
include('ele_datalist.php');

     
$zid='dlnumero';     
$ztabla='comp';
$zcolu='numero';     
$zcolu2='numero';    
if(!empty($enti))
{$zwhere='(enti like "'.substr($enti,0,10).'%" and ptoe like "'.$ptoe.'%")';}
if($tpos==1)
{$zwhere='(enti like "'.substr($enti,0,10).'%" and ptoe like "'.$ptoe.'%" and ifnull(caja,"")!="")';}
include('ele_datalist.php');


$zid='dlimpo';     
$zdocu='FP15';     
$zcolu='impor';   
// $zcolu='nume_impo';   
// $zwhere='(fecha>="2000-01-01")';     
include('ele_datalist.php');


     
     
$zid='dlatrz';     
$ztabla='comp';
$zcolu='atrz';     
$zcolu2='atrz';    
if(!empty($enti))
{$zwhere='(enti like "'.substr($enti,0,10).'%" and ptoe like "'.$ptoe.'%" and ifnull(atrz,"")!="")';}
include('ele_datalist.php');

     
$ztabla='ctas';
include('ele_datalist.php');

$ztabla='cair';
include('ele_datalist.php');

$ztabla='csub';
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($tpos==1)
{$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from comp1 where ifnull(caja,"")!=""))'; }
include('ele_datalist.php');

$ztabla='fpag';
{$zwhere='(fpag_codigo in (select distinct fpag from comp1))';}
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.'"))';
// include('ele_datalist.php');

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

     
     
     
$ztabla='lote';
include('ele_datalist.php');
     
$ztabla='vhcl';
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"  >';
{
     
// 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');
     

     
$zid='btn_print'; 
$zlabel='Imprimir';
$href='?scri=info_docu3&prnt=1&docu='.$docu.'&idnum='.$idnum1.'&formato=';  
$zalign='right';
//$href='?prnt=1&docu='.$docu.'&idnum='.$idnum1.'&formato=';  
$zonclick='{print_url("'.$href.'");}';
if(empty($idnum1)){$zhide=1;}     
$zsize=1.5;     
include('ele_button.php');
     

// echo '/*/*'.$tpos;     
     
$zid='fecha';
$ztype='date';
$zlabel='Fecha';
$zvalue=$fecha;
$zmin=$fecha_min;     
$zmax=$fecha_max;     
include('ele_input.php');  
     
         
     
$zid='enti';
$zlabel='Proveedor';
$zvalue=$enti;
// if(empty($zvalue)){$zvalue='9999999999999';}
$ztabla='enti';
// $zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&enti="+document.getElementById("enti").value+"&docu="+document.getElementById("docu").value+"&ptoe="+document.getElementById("ptoe").value;}';
$zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&enti="+document.getElementById("enti").value+"&docu="+document.getElementById("docu").value+"&ptoe="+document.getElementById("ptoe").value+"&tpos="+document.getElementById("tpos").value+"&fecha="+document.getElementById("fecha").value;}';
$zonchange=$zonblur;
     
// $zonblur='{if(document.getElementById("'.$zid.'").getAttribute("disabled")!=""){document.getElementById("idnum1").value="";}}';
// $zonchange='{fn_consulta(event);}';
     
     
if(!empty($enti)){$zreado=2;}
include('ele_input.php');
     

$zobj=1;     
include('ele_break.php');
     
     
$zid='docu';
$zlabel='Docum.';
$zvalue=$docu;
$ztabla='docu';
// $zonblur='{document.getElementById("enti").onblur();}';
$zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&enti="+document.getElementById("enti").value+"&docu="+document.getElementById("docu").value+"&ptoe="+document.getElementById("ptoe").value+"&tpos="+document.getElementById("tpos").value;}';
// $zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&enti="+document.getElementById("enti").value+"&docu="+document.getElementById("docu").value+"&ptoe="+document.getElementById("ptoe").value+"&tpos="+document.getElementById("tpos").value;}';
$zonchange=$zonblur;
$zwhere='(docu_tabla="'.$modu.'")';
if($tpos==1)     
{$zwhere='(docu_codigo in("FP10","FP90"))';}
$zexact=1;     
include('ele_select.php');
     
     
$zid='ptoe';
$zlabel='Pto.Emisión';
$zvalue=$ptoe; 
$zlist='dlptoe';
$zmaxlen=6; 
$zwidth=6;
$zdefa='001001';
// $zonblur='{fn_consulta();}';
// $zonblur='{document.getElementById("enti").onblur();}';
$zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&enti="+document.getElementById("enti").value+"&docu="+document.getElementById("docu").value+"&ptoe="+document.getElementById("ptoe").value+"&tpos="+document.getElementById("tpos").value;}';
$zonchange=$zonblur;
if(mb_stristr2('.FP90',$docu)){$zdefa='001001'; $zreado=1; }     
if(mb_stristr2('.FP15',$docu)){$zdefa='001001'; $zhide=1;}     
include('ele_input.php');

     
$zid='numero';
$zlabel='№';
$zvalue=$numero;
$zvalue=(int)$numero;
$zclass='numeric-int';
$zondblclick='{document.getElementById("'.$zid.'").style.width="'.round(7*2/3,2).'em";}';     
$zonblur='{if(document.getElementById("'.$zid.'").getAttribute("disabled")!=""){document.getElementById("idnum1").value="";}}';
$zonchange='{fn_consulta(event);}';
$zbackcolor='grey';
$zfontcolor='white';
$zmaxlen=9;
$zmin=0;     
if(mb_stristr2('FP03.FP90',$docu)){$zreado=1;}
if(substr($docu,0,2)=='FP'){$zlist='dlnumero';}
if($tpos==1){$zlist='';}
include('ele_input.php');

// if cpntabilidad    
// if($empr_enti0['enti_obcon']==1)
// if($empr0['enti_cont']==1)
{
     if(mb_stristr2('FP10.FP02.FPX03.FP14',$docu) or substr($docu,0,2)=='NP')
     {
          $zid='atrz';
          $zlabel='Autoriza';
          $zvalue=$atrz;
          $zlist='dlatrz';
          $zwidth=10;
          $zmax=9999999999;
          if(!empty($claveacc))
          {
               $zvalue='E : '.substr($claveacc,-10);
               $zreado=1;
               $ztitle=$claveacc;
          }
          include('ele_input.php');
     }
}
     

     
// if($impo_ok==1 or (mb_stristr2('.FP15.FP10.FP90.FP03',$docu)))
     
if($docu=='FP15' or $impo_ok==1)
{
//      $zid='nume_impo';
     $zid='impor';
     $zlabel='#Import.';
//      $zvalue=$nume_impo;
     $zvalue=$impor;
     $zlist='dlimpo';
     if($docu=='FP15')
     {include('ele_input.php');}
     else
     {
          $zdocu='FP15';     
          $zcolu='impor';   
          $zcolu2='impor';
          $zwhere='(fecha>="'.date('Ymd',strtotime('-12 month')).'")';
          include('ele_select.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($ptoe))
     
$zobj=1;     
include('ele_break.php');

     
     
     
     
// if( (!empty($docu) and !empty($ptoe) and !empty($numero) and !empty($enti)) or ($docu=='FP03' and !empty($ptoe)  and !empty($enti)) )
if( (!empty($docu) and !empty($ptoe) and !empty($numero) and !empty($enti)) or (mb_stristr2('FP03.FP90',$docu) and !empty($ptoe)  and !empty($enti)) )
{
//     $zobj=1;
//     include('ele_break.php');
     
     
     if($docu=='FP03')
     {
     $zobj=1;
     include('ele_break.php');
          
     $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');
     
     $zid='wsapp';
     $zlabel='wsapp';
     $zvalue=$wsapp;
     $ztype='number';
//      $zreado=2;
//      $zwidth=10;
     $zsize=0.9;
     include('ele_input.php');
          
     }

     if($empr_enti0['enti_obcon']==1)
     {
          if(substr($docu,0,2)=='FP')
          {
               $zobj=1;
               include('ele_break.php');

               $zid='fpag';
               $zlabel='F.Pago';
               $zvalue=$fpag;
               $ztabla='fpag';
               $zdefa='01';
          //      include('ele_input.php');
               include('ele_select.php');

               $zid='suco';
               $zlabel='Sust.Comp.';
               $zvalue=$suco;
               $ztabla='suco';
               $zdefa='01';
          //      include('ele_input.php');
               include('ele_select.php');
               
          }
          
          
     }

     if(substr($docu,0,2)=='NP')
     {
          
     $zid='dl_docum';     
     $ztabla='docu';
     $zwhere='(docu_tabla="comp" 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='comp';
     $zcolu='numero';
     $zcolu2='numero';
     $fecha1=date('Y-m-1',strtotime('-12 month'));
     $zwhere='(fecha>="'.$fecha1.'")';
     include('ele_datalist.php');
          
          
     $zobj=2;     
     $zid='todocu';
     $zlabel='Modifica';
     $zdefa='FP10';          
     $zvalue=$docum;
     $ztabla='docu';
     $zlist='dl_docum';     
     $zwhere='(docu_tabla="comp" 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;
     $zlist='dl_numer';     
     $zclass='numeric-int';
     include('ele_input.php');
          
     }

     
     
     
     
     {
     $zobj=1;
     include('ele_break.php');
          
          
//      echo '*/*/*'.$tpos;     
     $zid='concepto';
     $zlabel='Concepto';
     $zvalue=$concepto;
//      $zreado=2;
//      $zsize=0.9;
     $zwidth=25;
     $zrows=2;
     if($tpos==1){$zhide=1;}          
     include('ele_input.php');
                    
     }
          

     
     $zalign='right';
     $zid='total';
     $zwidth=7;
     $zsize=1.5;
     $zreado=1;
     $zlabel='Total 💲';
     $zvalue=$total;
//      $zvalue='💲 '.number_format($total,2);
     $zclass='numeric-dec';
     include('ele_input.php');
     
     
     
     
     $zobj=2;
     include('ele_break.php');
     
     $zobj=4;
     $zid='item';
     $zlabel='Item';
//      $zvalue=$item;
     $ztabla='item';
     $zopen=0;
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
//      $zdefa='9999999999';
//      if($docu=='FP90'){$zvalue='9999999999';}
//      if($docu=='FP15'){$zvalue='9999999999';}
//      if($docu=='FP90'){$zreado=1;}
     if($tpos==1){$zvalue='9999999999';}
     if($tpos==1){$zvalue='9999999999';}
     include('ele_input.php');
     
//      $zobj=4;
//      $zid='producto';
//      $zlabel='Prod/Serv';
//      $zvalue=$producto;
// //      $zwidth=15;
//      include('ele_input.php');

     
     if($empr0['empr_automotriz'])
     {
          $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');
     
          
     }
     
     
     
     $cant=1;
     $zobj=4;
     $zid='cant';
     $zlabel='Cant.';
     $zvalue=(float)$cant;
     $zdefa=1;
     $zmin=0;
     $zmax=9999;
     $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;
     $zmin=0;
     $zmax=9999.99;
     $zmax=99999.99;
     if($max_puni>=1000){$zmax=9999.99;}
     if($max_puni>=10000){$zmax=99999.99;}
     if($docu=='FP15'){$zmax=99999.99;}
     if($docu=='FP16'){$zmax=99999.99;}
     if($empr0['empr_codigo']=='pec1'){$zmax=99999.99;}
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     $zlist='dlpuni';
     if($tpre==1){$zreado=1;}
     include('ele_input.php');
     }
     
//      if(1==2)
     if($empr0['empr_codigo']=='mhec')
     if($docu=='FP15')     
     {
//           $zobj=4;
//           $zid='puni1';
//           $zlabel='P.Unit_1';
//           $zvalue=(float)$puni1;
//           $zmin=0;
//           $zmax=9999.99;
//           $zmax=99999.99;
//           if($max_puni>=1000){$zmax=9999.99;}
//           if($max_puni>=10000){$zmax=99999.99;}
//           if($docu=='FP15'){$zmax=99999.99;}
//           if($docu=='FP16'){$zmax=99999.99;}
//           if($empr0['empr_codigo']=='pec1'){$zmax=99999.99;}
//           $zclass='numeric-dec';
//           $zonchange='calc_subtot();';
//           $zonblur='calc_subtot();';
//           $zlist='dlpuni';
//           $zhide=1;
//           include('ele_input.php');
          
          $zobj=4;
          $zid='puni2';
          $zlabel='P.Unit_R';
          $zvalue=(float)$puni2;
          $zmin=0;
          $zmax=9999.99;
          $zmax=99999.99;
          if($max_puni>=1000){$zmax=9999.99;}
          if($max_puni>=10000){$zmax=99999.99;}
          if($docu=='FP15'){$zmax=99999.99;}
          if($docu=='FP16'){$zmax=99999.99;}
          if($empr0['empr_codigo']=='pec1'){$zmax=99999.99;}
          $zclass='numeric-dec';
          $zonchange='calc_subtot();';
          $zonblur='calc_subtot();';
          $zlist='dlpuni';
//           if($tpre==1){$zreado=1;}
          include('ele_input.php');
     }
     
     

     if(empty($numero)){$dcto=0;}

     
     if(!mb_stristr2('FP03.FP90.FP15',$docu))
     {
          $zobj=4;
          $zid='ice';
          $zlabel='% ICE';
          $zvalue=round($ice,2);
          $zmin=0;
          $zmax=99.99;
          $zclass='numeric-dec';
          $zonchange='calc_subtot();';
          $zonblur='calc_subtot();';
          $zlist='dlice';
          $zsize=0.8;
          include('ele_input.php');
     }
     
     
     if(!mb_stristr2('FP03.FP90.FP15',$docu))
     {
          $zobj=4;
          $zid='dcto';
          $zlabel='% Dcto.';
          $zvalue=$dcto;
          $zmin=0;
          $zmax=99.99;
          $zclass='numeric-dec';
          $zonchange='calc_subtot();';
          $zonblur='calc_subtot();';
          include('ele_input.php');
     }

     
     if(!mb_stristr2('FP90.FP15',$docu))
     {
          $zobj=4;
          $zid='iva';
          $zlabel='% IVA';
          $zvalue=round($iva,2);
          $zmin=0;
          $zmax=$_SESSION['porc_iva'];
          if(empty($zmax)){$zmax=15;}
          $zclass='numeric-dec';
          $zonchange='calc_subtot();';
          $zonblur='calc_subtot();';
          $zlist='dliva';
          $zsize=0.8;
          include('ele_input.php');
     }
     
     
     if(!mb_stristr2('FP03.FP90',$docu))
     {
     $zobj=4;
     $zid='irbp';
     $zlabel='IRBP';
     $zvalue=$irbp;
     $zmin=0;
     $zmax=9999;
     $zclass='numeric-dec';
     $zonchange='calc_subtot();';
     $zonblur='calc_subtot();';
     $zlist='dlirbp';
     $zsize=0.8;
     if($tpos==1){$zhide=1;}
     $zhide=1;
     include('ele_input.php');
     }
     
     
     
//      echo '===='.$docu;
     if(substr($docu,2,2)!='15')
     {
     $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($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');

     
     if(!mb_stristr2('FP90',$docu))
     {
     $zobj=4;
     $zid='cair';
     $zlabel='CAIR';
     $zvalue=$cair;
     $ztabla='cair';
     $zsize=0.8;
     include('ele_input.php');
     }
     
     $zobj=4;
     $zid='ctas';
     $zlabel='Cta.Cont.';
     $zvalue=$ctas;
     $ztabla='ctas';
     include('ele_input.php');
     
     $zobj=4;
     $zid='csub';
     $zlabel='C.Costo';
     $zvalue=$csub;
     $ztabla='csub';
     include('ele_input.php');
     
     
     
     
     
     $zobj=4;
     $zid='detalle';
     $zlabel='Notas';
     $zwidth=25;    
     $zrows=2;     
     $zvalue=$detalle;
     // $zhide=1;     
     // $zvalue=$data_docu[$zid];

     include('ele_input.php');


     
$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;}
$zhide=1;     
include('ele_button.php');
     
     
$zid='btn_grabar'; 
$zlabel='Grabar';
$zalign='right';
$zonclick='{save_docu(event);}';
$zsize=1.5;
if(!mb_stristr2('FP03.FP90',$docu)){}
if($stfin==1){$zhide=1;}     
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(mb_stristr2('demo.anml',$cfg_empr))
if(1==2)     
{
     $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='Paciente';
     $zvalue=$pcnt;
     $zlist='dl_pcnt';
     include('ele_input.php');
}
     
if(mb_stristr2('deXmo.tgck',$cfg_empr))
{
     $zobj=4;
     $zid='vhcl';
     $ztabla='vhcl';
     $zlabel='Vehiculo';
     $zvalue=$vhcl;
     include('ele_input.php');
}
     
// $zobj=1;     
// include('ele_break.php');
    
     

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

}
     
// TITULO     
     
     

}     
// echo '</div>';
// include('ele_break.php');

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



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





// COBRO
$sty_pago='float:right;';
if(!empty($numero) and empty($edit)){$sty_pago.='display:none;';}  
if(mb_stristr2('.FP15',$docu)){$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();';
     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;
     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='Cheque';
//      $zlabel='✍ Cheque $';
//      $zvalue=$cheque;
//      $zmin=0;
//      $zmax=99999;
//      $zwidth=5;
//      $zclass='numeric-dec';
//      $zonchange='{calc_subtot();}';
//      $zonblur='{save_docu(event);}';
//      if($tpos==1){$zhide=1;}
//      include('ele_input.php');
     

//      $zobj=1;
//      $zalign='right';
//      $zid='numche';
//      $zlabel='# Cheque';
//      $zvalue=$nume_vouc;
//      $zmin=0;
//      $zmax=999999999;     
//      $zclass='numeric-int';
//      $zonblur='{save_docu(event);}';
//      if($tpos==1){$zhide=1;}
//      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();}';
     $zonblur='{save_docu(event);}';
     if($tpos==1){$zhide=1;}
     include('ele_input.php');
     

     $zobj=1;
     $zalign='right';
     $zid='numvou';
     $zlabel='# Voucher';
     $zvalue=$nume_vouc;
     $zmin=0;
     $zmax=999999999;     
     $zclass='numeric-int';
     $zonblur='{save_docu(event);}';
     if($tpos==1){$zhide=1;}
     include('ele_input.php');
     
     $zobj=1;     
     include('ele_break.php');
     

     
$doca='AP';     
$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();';
     $zonblur='{save_docu(event);}';
     $zhide=1;
     include('ele_input.php');
     
     $zobj=1;     
     include('ele_break.php');

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


}
echo '</span>';


// filtros
echo '</div>';


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


// $zobj=1;
// $zid='cstock';
// $zlabel='Consulta Stock';
// $zwidth=25;         
// $zvalue='';
// $zonenter='{fn_stock();}';
// $zonblur='{fn_stock();}';
// include('ele_input.php');

echo '<div align="center" height="auto" id="divstock">';
echo '</div>';
     

echo '<div style="clear:both;">&#127380; : '.$idnum1.'</div>';

?>

<script>
function fn_stock(event)
{
     var busca,xsrc='?';
     busca=document.getElementById('cstock').value;
     document.getElementById('divstock').innerHTML='';
     if(busca.length>3)
     {
//           xsrc='?scri=info_modu3&modu=inve&info=iibode&tsaldo=69&prnt=1&prec=pvp&item='+busca;
//           document.getElementById('fr_stock').setAttribute('src',xsrc);
     
          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('item',busca);
          dato=exe_ajax(datapost,'divstock','',true);
     
     }
     
}
</script>

<script>
function fn_consulta(event)
{
     var xhref='',dataget;
     xhref=xhref+'?scri=<?php echo basename(__FILE__,'.php');?>';

     if(parseInt(document.getElementById('numero').value)>0)
     {
          dataget=new_FormData('filtros','get');
          xhref=xhref+dataget;
          
//           console.log(dataget);

          document.getElementById("main2").innerHTML='Espere...';
          location.href=xhref;
     }
}
</script>



<script>
function fn_nuevo(event)
{
     var enti;
     var xhref='';
// $zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&enti="+document.getElementById("enti").value+"&docu="+document.getElementById("docu").value+"&ptoe="+document.getElementById("ptoe").value+"&tpos="+document.getElementById("tpos").value;}';
     xhref=xhref+'?scri=<?php echo basename(__FILE__,'.php');?>';
     xhref=xhref+'&tpos='+document.getElementById("tpos").value;
     
     alert(xhref);
     
     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("idnum1").value="";
                    document.getElementById("fecha").value="";
                    document.getElementById("numero").value="";
                    enti=document.getElementById("enti").value;
     //                if(enti.indexOf("9999999999")<0)
                    {document.getElementById("enti").value="";}
                    document.getElementById("ptoe").value="";
//                     document.getElementById("tpos").value="";
//                     document.getElementById("").value="";
//                     fn_consulta(event);
                    location.href=xhref;
               }
          })
}     
     
</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,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;}
     
     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;}
     
//      console.log('-+-+-');
//      console.log(efectivo>total);
//      console.log(efectivo);
//      console.log(total);
//      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';
          if(cambio>0)
          {document.getElementById('cambio').style.color='darkred';}
   }
     
}
</script>


<script>document.title="<?php echo $xtitle;?>"</script>
<script>document.getElementById('topcenter').innerHTML="<?php echo $xtopcenter;?>"</script>
<script>calc_subtot()</script>
<!-- <script>set_noback();</script> -->
<!-- <script>window.onbeforeunload = function(){return 'Are you sure you want to leave?';};</script> -->

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