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

// 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=='imcp' and date('Y-m-d')<='2025-05-10'){$fecha_min='2025-04-25';}
if($cfg_empr=='span'){$fecha_min=date('Y-m-d',strtotime('-60 days'));}


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

// echo '====='.$format;

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

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

// echo '==== '.$docu.$ptoe.$numero;

if(!empty($docu) and !empty($ptoe) 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);
     
     $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)...';

     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);} 
     }
     
     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($format==3)
{
$caba1=$ctab;     
     
$zid='ctab';
$ztabla='ctab';
$zlabel='Banco';
$zvalue=$ctab; 
$zexact=1;     
if(!empty($ctab)){$zreado=1;}
$zondblclick='{document.getElementById("'.$zid.'").removeAttribute("disabled");}';     
$zonchange='{fn_consulta(event);}';
$zonblur=$zonchange;
include('ele_select.php');
}
     
$zid='fecha';
$ztype='date';
$zlabel='Fecha';
$zvalue=$fecha;
$zmin=$fecha_min;     
$zmax=$fecha2;     
// $zdefa=$fecha0;     
include('ele_input.php');  
     
$zid='docu';
$zlabel='Docum.';
$zvalue=$docu;
$ztabla='docu';
$zwhere='(docu_tabla="'.$modu.'")';
// $zondblclick='{document.getElementById("'.$zid.'").removeAttribute("disabled");}';     
// $zonblur='{location.href="?scri='.basename(__FILE__,'.php').'&'.$zid.'="+document.getElementById("'.$zid.'").value;}';
// $zonchange=$zonblur;
//      include('ele_input.php');
// $zonchange='{fn_consulta(event);}';
// include('ele_input.php');
$zexact=1;
$zreado=2;     
include('ele_select.php');

     
$zid='ptoe';
$ztabla='ptoe';
$zlabel='Pto.Emi.';
$zvalue=$ptoe; 
// 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='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")!=""){location.href="?scri='.basename(__FILE__,'.php').'&tpos="+document.getElementById("tpos").value+"&docu="+document.getElementById("docu").value+"&ptov="+document.getElementById("ptov").value+"&numero="+document.getElementById("numero").value;}}';
$zonblur='{if(document.getElementById("'.$zid.'").getAttribute("disabled")!=""){document.getElementById("idnum1").value="";fn_consulta();}}';
// $zbackcolor='black';
// $zfontcolor='white';
$zreado=2;     
// $zbackcolor='grey';
// $zfontcolor='white';
$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=';  
     
if(mb_stristr2('hg01',$cfg_empr))
{$href.='&destino=txt';}
$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($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';
     if($modu=='retc'){$zonenter='{fn_cxcp(event,"cxco");}';}
     if($modu=='retp'){$zonenter='{fn_cxcp(event,"cxpa");}';}
     $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';
          $zhide=1;
          include('ele_input.php');

          $zobj=4;
          $zid='ptoem';
          $zlabel='Pto.Emi.';
          $zvalue=$ptoem;
          $zwidth=4;
          $zhide=1;
          include('ele_input.php');

          $zobj=4;
          $zid='numer';
          $zlabel='Número';
          $zvalue=$numer;
          $zclass='numeric-int';
          $zhide=1;
          include('ele_input.php');


          $zobj=4;
          $zid='cair';
          $zlabel='CAIR';
          $zvalue=$cair;
//           $zwidth=4;
          $ztabla='cair';
          include('ele_input.php');

          
          

          $zobj=4;
          $zid='cant';
          $zlabel='Base';
          $zvalue=(float)$cant;
     //      $zmaxlen=7;
          $zwidth=5;
          $zclass='numeric-dec';
          $zmin=0;
          $zmax=999999;
          include('ele_input.php');


//           if(1==2)
          {
          $zobj=4;
          $zid='puni';
          $zlabel='% Ret.';
          $zvalue=(float)$puni;
          $zwidth=6 ;
          $zclass='numeric-dec';
          $zmin=0;
          $zmax=100;
          include('ele_input.php');
          }

          if(1==2)
          {
               $zid='lote';
               $zlabel='Lote';
               $zvalue=$lote;
               $ztabla='lote';
               $zmaxlen=20;
               include('ele_input.php');
          }

          if(1==2)
          {
               $zid='serie';
               $zlabel='Serie';
               $zvalue=$serie;
     //           $ztabla='lot';
               include('ele_input.php');
          }


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


     //      $zid='enti';
     //      $zlabel='Clie/Prov';
     //      $zvalue=$enti;
     //      $ztabla='enti';
     //      include('ele_input.php');


          if(1==2)
          {
          $zid='numfac';
          $zlabel='# FC/NC';
          $zvalue=$numfac;
          $zwidth=6;
          $zclass='numeric-int';
          include('ele_input.php');
          }


     }

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

//      $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_cxcob'; 
$zlabel='🔎 CXCob';
$zonclick='{document.getElementById("divcxpa").innerHTML="";}';
$zonclick.='{fn_cxcp(event,"cxco");}';
if($modu!='retc'){$zhide=1;}
include('ele_button.php'); 
echo '<div align="center" height="auto" id="divcxco" unselectable="on" onmousedown="return false;" onselectstart="return false;" style="margin-top:0em;">'.'</div>';

$zobj=1;     
include('ele_break.php');
$zid='btn_cxpag'; 
$zlabel='🔎 CXPag';
$zonclick='{document.getElementById("divcxco").innerHTML=""}';
$zonclick.='{fn_cxcp(event,"cxpa");}';
if($modu!='retp'){$zhide=1;}
include('ele_button.php');
echo '<div align="center" height="auto" id="divcxpa" unselectable="on" onmousedown="return false;" onselectstart="return false;" style="margin-top:0em;">'.'</div>';

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

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


?>

<script>
function fn_cxcp(event,modu='cxco')
{
     var enti,docu,modu,info,xdiv,xsrc='?';
     enti=document.getElementById('enti').value;
     docu=document.getElementById('docu').value;
//      document.getElementById('ccxcp').innerHTML='';
     if(enti===''){return;}
     if(docu===''){return;}
     
//      modu='cxco';
//      info='ccresu';
//      xdiv='divcxco';
//      if('EE.CH.DP.EV'.indexOf(docu.substr(0,2))>=0)
//      {modu='cxpa';info='cpresu';}
     
     info='ccresu';
     xdiv='div'+modu;
     if(modu=='cxpa'){info='cpresu';}     
     
     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('prec','pvp');
          datapost.append('prnt','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;
     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> -->

