<?php 
declare(strict_types=0);
// session_start();
foreach($_GET as $campo => $valor){${$campo}=trim($valor);} 
foreach($_POST as $campo => $valor){${$campo}=trim($valor);} 
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);
if(empty($user_codigo)){include('user_login0.php');return;}

// echo '<meta http-equiv="refresh" content="5">';
if(empty($modu)){$modu='retp';}
// $docu=strtoupper($docu);
// $info='cjblog';
$info_descri='RETENCIONES';

// if($format==2){$info='bcdet2';}
if($info=='bcblog'){$info_descri='RETENCIONES';}
if($info=='bcdet2'){$info_descri='DOC.RETENCIONES';}
if(empty($user0['user_tipo'])){$cost='false';}

$info='rpdet2';

// $enti=substr($enti,0,10).'001';
// if(mb_stristr2('sist.supe',$user0['user_tipo'])){$cost='true';}

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($bcos)){$bcos=$user0['user_bcos'];}

// if(empty($bcos))
// {
//      $fecha_bcos=date('Y-m-1',strtotime('-1 month'));
//      $sql_bcos='select distinct bode from bcos1 where status not in("O","X") and fecha>="'.$fecha_bcos.'"';
//      $res_bcos=msql_query($sql_bcos,$link_data);
//      if(msql_num_rows($res_bcos)==1)
//      {$bcos=msql_result($res_bcos,0,'bcos');}
// }     

if($format==2)
{
// $docum='';
// $cant=0;
// $puni=0;
}

$docu0=data_maes('docu',$docu);
$enti0=data_maes('enti',$enti);
$bcos0=data_maes('bcos',$bcos);
$ctas0=data_maes('ctas',$ctas);
$docum0=data_maes('docu',$docum);

// $sql_tbod='select distinct bode_tipo from bode0 where bode_status not in("I","X") and bode_tipo!="" and bode_tipo is not null';
// $res_tbod=msql_query($sql_tbod,$link_data);
// if(msql_num_rows($res_tbod)>1){$tbod_ok=1;}

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

// if(@mb_stristr2('clie.prov.empl',$modu)){$tabla='enti';}
// if(@mb_stristr2('inve.prec.teki',$modu)){$tabla='item';}

$xtitulo='RETENCIONES';
if($modu=='bcos'){$xtitulo='RETENCIONES';}
if($modu=='bcos'){$xtitulo='RETENCIONESS';}

$xtitle='REG.'.$xtitulo;
$xtopcenter=$xtitle;
if(!empty($docu)){$xtitle.=' /'.$docu;}
if(!empty($numero)){$xtitle.='-'.$numero;}
if(empty($numero)){$total=0;}

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

// $fecha_min=date('Y-m-d',strtotime('-7 days'));
if(empty($fecha1)){$fecha1=date('Y-m-d',strtotime('-7 days'));}
if(empty($fecha2)){$fecha2=date('Y-m-d');}
if($cfg_empr=='span'){$fecha1=date('Y-m-d',strtotime('-60 days'));}

// if($empr=='imcp' and date('Y-m-d')<='2024-06-30'){$fecha_min='2024-05-01';}

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

// echo '*/*/*/*/';
// echo sal_item2('20109837');
     
//  SELECT DB
// if(!empty($bcos))
// {include('sele_info.php');}


if(!empty($enti) and !empty($docum) and !empty($ptoem) and !empty($numer))
{
     $sql_fact ='select * from comp1 ';
     $sql_fact.='left join comp2 on idnum1=idnum2 ';
     $sql_fact.='left join item0 on item=item_codigo ';
//      $sql_fact.='left join cair0 on item_cair=cair_codigo ';
     $sql_fact.='left join cair0 on cair=cair_codigo ';
     $sql_fact=calc_fields('comp',$sql_fact);
     $sql_fact.='where ifnull(status,"") not in("O","X") ';
     $sql_fact.='and enti like "'.substr($enti,0,10).'%" ';
     $sql_fact.='and docu = "'.$docum.'" ';
     $sql_fact.='and ptoe = "'.$ptoem.'" ';
     $sql_fact.='and numero*1 = "'.$numer.'" ';
     
     $sql_fair=$sql_fact;
     $sql_fair.='group by cair ';
     $sql_fair.='order by cair ';
     $res_fair=msql_query($sql_fair,$link_data);
     
     $sql_fiva=$sql_fact;
     $sql_fiva.='and iva>0 ';
//      $sql_fiva.='group by iva ';
//      $sql_fiva.='order by iva ';
     $sql_fiva.='group by cair ';
     $sql_fiva.='order by cair ';
     $res_fiva=msql_query($sql_fiva,$link_data);
     
     $res_fact=msql_query($sql_fact,$link_data);
     $fact1=msql_fetch_assoc($res_fact);
     
     $sql_fact.='group by idnum2,iddet ';
     $sql_fact.='order by idnum2,iddet ';
     $res_fact=msql_query($sql_fact,$link_data);

     
     // verifica retenciones de factura
     $sql_retp ='select * from retp1 ';
     $sql_retp.='left join retp2 on idnum1=idnum2 ';
//      $sql_retp=calc_fields('retp',$sql_retp);
     $sql_retp.='where ifnull(status,"") not in("O","X") ';
     $sql_retp.='and enti like "'.substr($enti,0,10).'%" ';
     $sql_retp.='and docum="'.$docum.'" ';
     $sql_retp.='and ptoem="'.$ptoem.'" ';
     $sql_retp.='and numer*1='.$numer.' ';
     $sql_retp.='and ifnull(autornum,"")!="" ';
//      $sql_retp.='order by fecha desc, idnum1 desc ';
     $res_retp=msql_query($sql_retp,$link_data);
     $idreta=msql_result($res_retp,0,'idnum1');
//      if(!empty($idreta))
//      {$numero=msql_result($res_retp,0,'numero');}
     
     
     $fecha1=$fact1['fecha'];
     $fecha2=date('Y-m-d',strtotime($fact1['fecha'].' +5 days'));
//      if(!empty($idreta))
//      {$fecha2=date('Y-m-d');}

     // retenciones anteriores
     $sql_retp ='select * from retp1 ';
     $sql_retp.='left join retp2 on idnum1=idnum2 ';
     $sql_retp=calc_fields('retp',$sql_retp);
     $sql_retp.='where ifnull(status,"") not in("O","X") ';
     $sql_retp.='and enti like "'.substr($enti,0,10).'%" ';
     $sql_retp.='and cair*1<300 ';
     $sql_retp.='and cair*1<300 ';
     $sql_retp.='group by idnum1 ';
     $sql_retp.='order by fecha desc, idnum1 desc ';
     $sql_retp.='limit 10 ';
     $res_retp=msql_query($sql_retp,$link_data);
     $porc_iva=msql_result($res_retp,0,'puni');
     
     
     $sql_retp ='select * from retp1 ';
     $sql_retp.='left join retp2 on idnum1=idnum2 ';
     $sql_retp=calc_fields('retp',$sql_retp);
     $sql_retp.='where ifnull(status,"") not in("O","X") ';
     $sql_retp.='and enti like "'.substr($enti,0,10).'%" ';
     $sql_retp.='and cair*1>=300 ';
     $sql_retp.='group by idnum1 ';
     $sql_retp.='order by fecha desc, idnum1 desc ';
     $sql_retp.='limit 10 ';
     $res_retp=msql_query($sql_retp,$link_data);
     $lcair0=data_maes('cair',msql_result($res_retp,0,'cair'));
     
     
     
     $sql_retp ='select * from retp1 ';
     $sql_retp.='left join retp2 on idnum1=idnum2 ';
//      $sql_retp=calc_fields('retp',$sql_retp);
     $sql_retp.='where ifnull(status,"") not in("O","X") ';
     $sql_retp.='and cair*1>=300 ';
     $sql_retp.='group by idnum1 ';
     $sql_retp.='order by fecha desc, idnum1 desc ';
     $sql_retp.='limit 10 ';
     $res_retp=msql_query($sql_retp,$link_data);
     $ptoemi=msql_result($res_retp,0,'ptoe');
//      echo '*/*/*'.$sql_retp;
     
}

// else
{
     $sql_retp='select * from retp1 where ifnull(status,"")!="X" order by idnum1 desc limit 1';
     $res_retp=msql_query($sql_retp,$link_data);
//      if(empty($ptoe)){$ptoe=msql_result($res_retp,0,'ptoe');}
     if(empty($ptoemi)){$ptoemi=msql_result($res_retp,0,'ptoe');}
}

//      echo '<br>/*/*/*'.$docu;
//      echo '<br>/*/*/*'.$ptoe;
//      echo '<br>/*/*/*'.$ptoemi;
//      echo '<br>/*/*/*'.$numero;


if(!empty($docu) and !empty($ptoe) and !empty($numero))
{include('sele_info.php');}

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


if(!empty($sql_info))
{
//      echo '/*/*/*';
     
     $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);
     
     $cantidad=msql_result($res_info1,0,'total_hide');
     
     $sql_info=str_replace('order by ','order by fecha desc, idnum1 desc, iddet desc, ',$sql_info);
     $sql_info.=' limit 100';
     $res_info=msql_query($sql_info,$link_data);
     if(msql_num_rows($res_info)==0)
     {
          if($fecha1!=$fecha2)
          {
               $sql_info=str_replace($fecha1,$fecha0,$sql_info);
               $res_info=msql_query($sql_info,$link_data);
          }
     }
     
     $msgres=number_format(msql_num_rows($res_info)).' Resultado(s)...';
     
//           echo '*/*/*/*'.$sql_info;
//           echo '*/*/*/*'.$numero;
//           echo '*/*/*/*'.$idnum1;

     if(!empty($numero))
     {
          $idnum1=msql_result($res_info,0,'idnum1');
          if(empty($idnum1))
          {$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);} 
     }
     
     if(empty($idnum1)){$edit=1;}
     
}

// echo '*/*/*'.$format;

// PANTALLA FILTROS
echo '<div id="filtros" noprint >';
{
// OCULTOS
echo '<div hide>';     
echo '<input id="format" hide value="'.$format.'">';
// echo '<input id="limit" hide value="'.$limit.'">';
echo '<input id="modu" value="'.$modu.'">';
echo '<input id="info" value="'.$info.'">';
echo '<input id="idnum1" value="'.$idnum1.'">';
echo '<input id="fecha1" value="'.$fecha1.'">';
echo '<input id="fecha2" value="'.$fecha2.'">';
echo '<input id="stfin" value="'.$stfin.'">';
echo '</div>';     
     
// {$ztitulo='FILTROS'; include('ele_title.php');}
// {$ztitulo='INVENTARIOS'; include('ele_title.php');}

$ztabla='cair';
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 comp1))';}
include('ele_datalist.php');
     
$ztabla='docu';
$zwhere='(docu_tabla="'.$modu.'")';
include('ele_datalist.php');

$zid='dldocum';     
$ztabla='docu';
// $zwhere='(docu_tabla="'.$modu.'")';
$zwhere='(docu_tabla in("bcos","bcos","vtas","comp","dxco","dxpa"))';
include('ele_datalist.php');

$zobj=2;     
include('ele_break.php');
 
if($format==2) 
{
$zid='btn_nuevo'; 
$zlabel='Nuevo';
$zalign='right';
$zonclick='{fn_nuevo();}';
$zsize=1.5;     
include('ele_button.php');
}
               
     
// if($empr0['emrp_codigo']=='imcp' and date('Y-m-d')<='2024-06-30')
// if($empr0['empr_codigo']and date('Y-m-d')<='2024-06-30')
// {$fecha1='2024-05-01';}
     
    //  echo '=='.$fecha1;
$zid='fecha';
$ztype='date';
$zlabel='Fecha';
$zvalue=date('Y-m-d');
$zmin=$fecha1;
$zmax=$fecha2;
if($zvalue>$zmax){$zvalue=$zmax;}     
if(substr($zvalue,0,7)>substr($fecha1,0,7)){$zvalue=date('Y-m-t',strtotime($fecha1));}
// $zsize=2;
include('ele_input.php');  



     
$zid='docu';
$zlabel='Docum.';
// $zvalue=$docu;
// $zvalue='RETP';     
$zvalue='RPRO';     
$ztabla='docu';
$zwhere='(docu_tabla="'.$modu.'")';
$zexact=1;
$zreado=1;     
// include('ele_input.php');
include('ele_select.php');

     
     
$zid='ptoe';
$ztabla='ptoe';
$zlabel='Pto.Emi.';
$zvalue=$ptoemi; 
$zdefa=$ptoemi;
// if(!empty($bode)){$zreado=1;}
$zondblclick='{document.getElementById("'.$zid.'").removeAttribute("disabled");}';     
$zonchange='{fn_consulta(event);}';
$zonblur=$zonchange;
$zexact=1;
$zreado=2;     
include('ele_select.php');
     
     
if($format==2)
{
// $zid='ctab';
// $ztabla='ctab';
// $zlabel='Banco';
// $zvalue=$ctab; 
// // if(!empty($bode)){$zreado=1;}
// $zondblclick='{document.getElementById("'.$zid.'").removeAttribute("disabled");}';     
// $zonchange='{fn_consulta(event);}';
// $zonblur=$zonchange;
// $zexact=1;     
// include('ele_select.php');
}

// if($format==2) 
{
     
$zid='numero';
$zlabel='Numero';
$zlabel='№';
$zvalue=$numero;
$zvalue=(int)$numero;
$zmin=1;
$zmax=999999999;     
$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="";fn_consulta();}}';
$zreado=2;     
$zsize=1.2;     
include('ele_input.php');
     
}

     
if(@mb_stristr2('DB10.EE13.CH10.ND13',$docu))
{
     $zid='caba2';
     $zlabel='Caja/Bco.2';
//      if($docu=='DB10'){$zlabel='C.Origen';}
//      if($docu=='CH10'){$zlabel='C.Destino';}
//      if($docu=='ND13'){$zlabel='C.Destino';}
     $zvalue=$caba2;
     $ztabla='caba';
     $zwhere='(caba_codigo!="'.$caba2.'")';
     //      $zmaxlen=20;
     include('ele_select.php');
}     
     
     
     
     
// if($format==2)
{
$zid='btn_print'; 
$zlabel='Imprimir';
$zalign='right';
// $href='?prnt=1&docu='.$docu.'&idnum='.$idnum1.'&formato=';  
$href='?scri=info_docu3&prnt=1&docu='.$docu.'&idnum='.$idnum1.'&formato=';  
     
$zonclick='{print_url("'.$href.'");}';
// $zonclick='{save_docu(event);print_url("'.$href.'");}';
if(empty($idnum1)){$zhide=1;}     
$zsize=1.5;     
include('ele_button.php');
}
               
if($format==3)
{
     $zid='btn_consul'; 
     $zlabel='Consultar';
     $zalign='right';
     // $zonclick='{fn_consulta(event);}';
     $zonclick='{document.getElementById("fecha1").value="";document.getElementById("fecha2").value="";fn_consulta(event);}';
     include('ele_button.php');
}     

echo '<span style="float:right; white-space:nowrap;">';     
// echo $msgres;
echo '</span>';     
     
$zid='total';
$zlabel='Total 💲';
// $zvalue=$total;
$zvalue=number_format($total,2);
$zwidth=5;
$zclass='numeric-dec';
$zalign='right';     
$zsize=1.5;
if($total>0){$zreado=2;}
$zhide=1;     
include('ele_input.php');
     
     
     
// if(!empty($ctab) and !empty($docu))
// if(!empty($ctab) and !empty($docu) and !empty($numero))
// if(!empty($docu) and !empty($ptoe))
{
//      if($format==2)
     {
     $zobj=1;     
     include('ele_break.php');

//      $zobj=4;
     $zid='enti';
     $zlabel='Entidad';
     if(@mb_stristr2('DC10.ICH1',$docu))
     {$zlabel='Cliente';}
     if(@mb_stristr2('DP10.CH10',$docu))
     {$zlabel='Proveedor';}
     $zvalue=$enti;
     $ztabla='enti';
//      $zonenter='{fn_cxcp(event);fn_cxcp(event,"cxpa");}';
//      $zonblur ='{fn_cxcp(event);fn_cxcp(event,"cxpa");}';
//      if($modu=='retc'){$zonenter='{fn_cxcp(event,"cxco");}';}
//      if($modu=='retp')
     {$zonenter='{fn_rete(event);}';}
     $zonblur=$zonenter;

     include('ele_input.php');

     }     

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

//      $zid='concepto';
//      $zlabel='Concepto';
//      $zwidth=25;    
//      $zrows=2;     
//      $zvalue=$concepto;
//      include('ele_input.php');

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

     if(@mb_stristr2('retc.retp',$modu))
     {

          $zobj=4;
          $zid='docum';
          $zlabel='Docum.';
          $zvalue=$docum;
          $ztabla='docu';
          $zlist='dldocum';
          $zonchange='{fn_consulta();}';
          include('ele_input.php');

          $zobj=4;
          $zid='ptoem';
          $zlabel='Pto.Emi.';
          $zvalue=$ptoem;
          $zdefa='001001';
          $zwidth=4;
          $zonchange='{fn_consulta();}';
          include('ele_input.php');

          $zobj=4;
          $zid='numer';
          $zlabel='Número';
          $zvalue=$numer;
          $zclass='numeric-int';
          $zonchange='{fn_consulta();}';

          include('ele_input.php');

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

          $zobj=4;
          $zid='subtiva0';
          $zlabel='S-Tot IVA 0%';
          $zvalue=trim_rzero($fact1['subtiva0'],2);
          $zclass='numeric-dec';
          if($fact1['total']>0){$zreado=1;}
          include('ele_input.php');


          $xiva=trim_rzero($fact1['iva']);
          if(empty($xiva)){$xiva=$_SESSION['porc_iva'];}
          $zobj=4;
          $zid='subtiva';
          $zlabel='S-Tot IVA '.$xiva.'%';
          $zvalue=round($fact1['subtiva'],2);
          $zclass='numeric-dec';
          if($fact1['total']>0){$zreado=1;}
          include('ele_input.php');

          $zobj=4;
          $zid='iva';
          $zlabel='I.V.A.';
//           $zvalue=trim_rzero($fact1['tiva'],2);
          $zvalue=round($fact1['tiva'],2);
          $zclass='numeric-dec';
          if($fact1['total']>0){$zreado=1;}
          include('ele_input.php');


          
          $zobj=4;
          $zid='total';
          $zlabel='Total';
//           $zvalue=trim_rzero($fact1['total'],2);
//           $zvalue=number_format($fact1['total'],2);
          $zvalue=round($fact1['total'],2);
          $zclass='numeric-dec';
          if($fact1['total']>0){$zreado=1;}
          include('ele_input.php');


          $zid='verfact'; 
          $zlabel='Ver FACT.';
          $href='?scri=info_docu3&prnt=1&docu='.$docum.'&idnum='.$fact1['idnum1'].'&edit=';  
          $zonclick='{window.open("'.$href.'","_blank");}';
          {$zcolor='cyan';}
//           if(empty($idreta))
//           {$zcolor='green';}
//           $zsize=1.5;
          include('ele_button.php');

          if(empty($idreta))
          {
          $zid='modfact'; 
          $zlabel='Mod.CAIR';
          $href='?scri=info_modu3&modu=COMP&info=codeta&edit=30&docu='.$docum.'&enti='.$enti.'&numero='.$numer.'&fecha1='.$fact1['fecha'].'&fecha2='.$fact1['fecha'].'&formato=';  
          $zonclick='{window.open("'.$href.'","_blank");}';
          $zcolor='lightgreen';
//           $zsize=1.5;
          include('ele_button.php');
          }

          if(!empty($idreta))
          {
          $zid='verrete'; 
          $zlabel='Ver Rete.';
          $href='?scri=info_docu3&prnt=1&docu='.$docu.'&idnum='.$idreta.'&edit=';  
          $zonclick='{window.open("'.$href.'","_blank");}';
          $zcolor='darkred';
//           $zsize=1.5;
          include('ele_button.php');
          }          
          



     }

     
//                while($aso_clac=msql_fetch_assoc($res_clac))

     $zid='btn_grabar'; 
     $zlabel='Grabar';
     $zalign='right';
     $zonclick='{save_docu(event);}';
     $zsize=1.5;
     if(!empty($idreta)){$zhide=1;}
     include('ele_button.php');

     
     if(!empty($idreta))
     {
//           $idnum=$idreta;
//           include('ele_docu');
          $numer='';
     }
     

     if(!empty($enti) and !empty($docum) and !empty($ptoem) and !empty($numer))
     {     
     $zlabel='Retencion Renta';
     $zobj=2;     
     include('ele_break.php');
     
     $xconta=0;
     msql_data_seek($res_fair);
     while($aso_fair=msql_fetch_assoc($res_fair))
     {
          $xconta++;
          
          $zobj=4;
          $zid='cair_codi_'.$xconta;
          $zlabel='CAIR';
          $zvalue=$aso_fair['cair'];
          if(empty($zvalue))
          {
               $zplace=$lcair0['cair_codigo'];
//                $zvalue=$lcair0['cair_codigo'];
          }
          
          $ztabla='cair';
          include('ele_input.php');
          $acair0=data_maes('cair',$aso_fair['cair']);

          
//           $zobj=1;     
//           include('ele_break.php');
          
          
          $zobj=4;
          $zid='cair_base_'.$xconta;
          $zlabel='Base';
//           $zvalue=trim_rzero($aso_fair['subt'],2);
          $zvalue=round($aso_fair['tsubt']-$aso_fair['tdcto'],2);
          $zclass='numeric-dec';
          include('ele_input.php');
          
//           echo '*/*/* '.$sql_fair;
          
          
          
          
          $zobj=4;
          $zid='cair_porc_'.$xconta;
          $zlabel='Porc.%';
          $zvalue=number_format($aso_fair['cair_porc'],2);
          if((int)$zvalue==0)
          {
               $zvalue='';
               $zplace=$acair0['cair_porc'];
          }
//           if((int)$zvalue!=0)
//           {
//                $zvalue=$aso_fair['cair_porc'];
//           }
          $zclass='numeric-dec';
          $zmin=0;
          $zmax=30;
          include('ele_input.php');

          
//           $rete4deta=$aso_fair['concepto'].' /';
          $rete4deta='';
          
          if(!empty($aso_fair['concepto']))
          {$rete4deta.=''.$aso_fair['concepto'].' /';}
          
          if(!empty($aso_fair['detalle']))
          {$rete4deta.=''.$aso_fair['detalle'].' /';}
          
          if(!empty($aso_fair['item_descri']))
          {$rete4deta.=''.$aso_fair['item_descri'].' /';}
          
          $zobj=4;
          $zid='cair_deta_'.$xconta;
          $zlabel='Detalle';
          $zvalue=$rete4deta;
          $zreado=1;
          $zwidth=strlen($rete4deta)*(.6);
          $maxwidth=30;
          $zrows=intdiv($zwidth,$maxwidth);
          if($zrows>1){$zwidth=$maxwidth;}
          if(($zwidth % $maxwidth)!=0){$zrows++;}
          
          include('ele_input.php');
          
          $zobj=1;     
          include('ele_break.php');
          
//           echo $aso_fair['cair_porc'];
     }
     
     $zlabel='Retencion I.V.A.';
     $zobj=2;     
     include('ele_break.php');
     
     $xconta=0;
     msql_data_seek($res_fiva);
     while($aso_fiva=msql_fetch_assoc($res_fiva))
     {
          $xconta++;
          $zobj=4;
          $zid='iva_codi_'.$xconta;
          $zlabel='IVA';
          $zvalue=$aso_fiva['iva'];
          $zclass='numeric-dec';
          $zmin=0;
          $zmax=30;
          $zreado=1;
          include('ele_input.php');
          
          $zobj=4;
          $zid='iva_base_'.$xconta;
          $zlabel='Base';
//           $zvalue=number_format($aso_fair['subt'],6);
//           $zvalue=number_format($aso_fiva['tiva'],6);
//           $zvalue=trim_rzero($aso_fiva['tiva'],2);
          $zvalue=round($aso_fiva['tiva'],2);
          $zclass='numeric-dec';
          include('ele_input.php');
          
          $zobj=4;
          $zid='iva_porc_'.$xconta;
          $zlabel='Porc.%';
//           $zvalue=round($aso_fiva['iva_porc'],2); 
          $zvalue=round($porc_iva,0);
          if((int)$zvalue=0) 
          {
               $zvalue=''; 
               $zplace=round($porc_iva,2);
          }
          if((int)$zvalue!=0)
          {
               $zvalue=round($porc_iva,0); 
          }

          
          $zclass='numeric-dec';
          $zmin=0;
          $zmax=100;
          include('ele_input.php');
          
          $zobj=1;     
          include('ele_break.php');
          
//           echo $aso_fair['cair_porc'];
     }
     
     }     

//      $zobj=4;
//      $zid='ctas';
//      $zlabel='Cta. Contable';
//      $zvalue=$ctas;
//      $ztabla='ctas';
//      include('ele_input.php');

     $zobj=4;     
     $zid='detalle';
     $zlabel='Notas';
     $zwidth=25;    
     $zrows=2;     
     $zvalue=$detalle;
     $zhide=1;
     include('ele_input.php');

}


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

     
     

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


// RESULTADO
echo '<div id="main2" >';
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');  
     
//      $zalign='right';
//      $zid='difer';
//      $zlabel='Difer.';
//      $zvalue=number_format($total-$cantidad,2);
//      $zwidth=8;
//      $zclass='numeric-dec';
//      $zreado=1;
//      if($total<=0){$zhide=1;}
//      include('ele_input.php');

}
echo '</div>';     



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


$zid='btn_reten'; 
$zlabel='🔎 Retenciones';
$zonclick='{fn_rete();}';
// $zonclick.='{document.getElementById("divcxpa").innerHTML="";}';
include('ele_button.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();



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

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


?>

<script>
function fn_rete(event)
{
     var enti,docu,modu,info,xdiv,fecha1,fecha2,xsrc='?';
     enti=document.getElementById('enti').value;
     if(enti===''){return;}
     
     modu='retp';
     info='rpresu';
     xdiv='divextra1';
     fecha1="<?php echo date('Y-m-01',strtotime($fact1['fecha'].' -12 month')); ?>";
     fecha2="<?php echo date('Y-m-d',strtotime($fact1['fecha'].' -1 day')); ?>";
     <?php if(!empty($idreta)){ ?>
     fecha2="<?php echo date('Y-m-d'); ?>";     
     <?php } ?>
     
     if(enti.length>=10)
     {
          var datapost,dato;
          datapost=new FormData();
          datapost.append('script','info_modu3');
          datapost.append('modu',modu);
          datapost.append('info',info);
          datapost.append('fecha1',fecha1);
          datapost.append('fecha2',fecha2);
//           datapost.append('prec','pvp');
          datapost.append('prnt','1');
          datapost.append('sortdesc','1');
          datapost.append('zhidebtns','1');
          datapost.append('zhidehead','1');
          datapost.append('enti',enti);
          dato=exe_ajax(datapost,xdiv,'',true);
     
     }
     
}
</script>


<script>
function fn_consulta(event)
{
     var xhref='',dataget;
     
     var enti,docum,ptoem,numer;
     enti=document.getElementById('enti').value;
     docum=document.getElementById('docum').value;
     ptoem=document.getElementById('ptoem').value;
     numer=document.getElementById('numer').value;
     
     if(enti===''){return;}
     if(docum===''){return;}
     if(ptoem===''){return;}
     if(numer===''){return;}
     
     xhref=xhref+'?scri=<?php echo basename(__FILE__,'.php');?>';
     
     document.getElementById("main2").innerHTML='Espere...';
     dataget=new_FormData('filtros','get');
     xhref=xhref+dataget;

     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="";
                    document.getElementById("total").value="0";
                    enti=document.getElementById("enti").value;
     //                if(enti.indexOf("9999999999")<0)
                    {document.getElementById("enti").value="";}
                    fn_consulta(event);
               }
          })
}     
     
</script>





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

