<?php
declare(strict_types=0);

// $brkln_html="&#10;";
$brkln_html="\n";
// $brkln_html='';
// $zgrupo='enti';
// $zgrupo='nombre';

// $err_autor=[2,10,27,37,39,40,46,52,56,57,58,63,80];
// var_dump2($err_autor);

$semana=0;
// if( date('W',strtotime($fecha1)) == date('W',strtotime($fecha2)) ){$semana=1;}
if(date('w',strtotime($fecha1))==1 and date('w',strtotime($fecha2))==0 and days_diff($fecha1,$fecha2)==6){$semana=1;}
if(date('w',strtotime($fecha1))==1 and date('w',strtotime($fecha2))==0 and days_diff($fecha1,$fecha2)>6)
{
     $semana=2;
     $semanas=(days_diff($fecha1,$fecha2)+1)/7;  
}
//                echo '<br>=== '.days_diff($fecha1,$fecha2);


if(mb_stristr2('.ccdeta.cpdeta',$info))
{$zgrupo='docu1_hide';}

if(mb_stristr2('.rprrxm.rprixm.rcrrxm.rcrixm',$info))
if(substr($fecha1,0,4)!=substr($fecha2,0,4))     
{$zgrupo='AÑO';}

// if(substr($info,-4)=='resu')
// {$zgrupo='fecha';}

// echo '==========='.$zblockfield;
// $znolin=1;
//  A4 45 registros por pagina

$date_grid1=date('H:i:s');
$msc_grid=microtime(true);

$eol="\r\n";  
$xbgcolor1='snow';
if($prnt>=1)
{$xbgcolor1='';}     



$href_html_pdf='/-info/'.$xlsf.'.html';
$href_php_xls='/-info/'.$xlsf.'.php';
$href_php_xls_zeus='/-info/'.$xlsf.'_zeus.php';
$href_php_xls_fsoft='/-info/'.$xlsf.'_fsoft.php';
$href_php_xls_sridr='/-info/'.$xlsf.'_sridr.php';
$href_php_xls_sridi='/-info/'.$xlsf.'_sridi.php';



// $href_html_pdf='/info/'.$xlsf.'.html';
// $href_php_xls='/info/'.$xlsf.'.php';
// $href_php_xls_zeus='/info/'.$xlsf.'_zeus.php';
// $href_php_xls_fsoft='/info/'.$xlsf.'_fsoft.php';
// $href_php_xls_sridr='/info/'.$xlsf.'_sridr.php';
// $href_php_xls_sridi='/info/'.$xlsf.'_sridi.php';



$file_html_pdf='../'.$cfg_empr.$href_html_pdf;
$file_php_xls='../'.$cfg_empr.$href_php_xls;
$file_php_xls_zeus='../'.$cfg_empr.$href_php_xls_zeus;
$file_php_xls_fsoft='../'.$cfg_empr.$href_php_xls_fsoft;
$file_php_xls_sridr='../'.$cfg_empr.$href_php_xls_sridr;
$file_php_xls_sridi='../'.$cfg_empr.$href_php_xls_sridi;

$st_count=array();
// echo '======'.$info;
// echo '*/*/*'.$zblockfield;

$fsoft=$empr0['empr_fsoft'];
$zeus=$empr0['empr_zeus'];

if($empr0['empr_codigo']=='demo')
{$srid=1;}


if(!empty($prnt)){$edit=0;}
// if($edit>30 and $user0['user_tipo']!='sist'){$edit=0;}
     
$fecha_edit=date('Y-m-d',strtotime('-'.$edit.' days'));
// $fecha0_edit=date('Y-m-d',strtotime('-3 month'));
// $fecha0_edit=date('Y-m-d',strtotime('-3 month'));

if(date('Y-m-d')<='2024-08-31')
if($empr0['empr_codigo']=='hfre')
{
     $fecha_edit='2024-01-01';
     $fecha0_edit='2024-01-01';
}

// $formacol=1;


if($empr0['empr_codigo']=='jwib')
{
     $trty0=data_maes('trty',$trty);
}

if(substr($info,0,2)=='vt')
{
     if(!empty($ptov))
     {$ptov0=data_maes('ptov',$ptov);}
     else
     {$ptov0=data_maes('ptov',msql_result($zreso,0,'ptov'));}

     if(!empty($zsub))
     {$zsub0=data_maes('zsub',$zsub);}
     else
     {$zsub0=data_maes('zsub',msql_result($zreso,0,'zsub'));}

     if(!empty($vndd))
     {$vndd0=data_maes('vndd',$vndd);}
//      else
//      {$vndd0=data_maes('vndd',msql_result($zreso,0,'vndd'));}
}


     if(!empty($tcel))
     {$tcel0=data_maes('tcel',$tcel);}


if($info=='iikrdx')
{
     $lsub0=data_maes('lsub',msql_result($zreso,0,'item_lsub_hide'));
     $item0=data_maes('item',msql_result($zreso,0,'item_codigo_hide'));
}


if($info=='ttmovi')
{
     $ctas0=data_maes('ctas',msql_result($zreso,0,'ctas_codigo_hide'));
//      var_dump2($ctas0);
//      echo '==='.msql_result($zreso,0,'ctas_codigo_hide');
}

if($info=='bcmovi')
{
     $ctab0=data_maes('ctab',msql_result($zreso,0,'ctab_codigo_hide'));
}

if($info=='cjmovi')
{
     $caja0=data_maes('caja',msql_result($zreso,0,'caja_codigo_hide'));
}

if(mb_stristr2('.enti',$modu))
{
     $zsub0=data_maes('zsub',$zsub);     
     $tpro0=data_maes('tpro',$tpro);     
}

if(mb_stristr2('.item',$modu))
{
     $lsub0=data_maes('lsub',$lsub);     
}


if(empty($zwidthtable)){$zwidthtable='auto';}

if($info=='iikrdx' and $prnt==1){$zwidthtable='99%';}
if($info=='ttmovi' and $prnt==1){$zwidthtable='99%';}

if(mb_stristr2($name,'xls')){$type='xls';}
if(mb_stristr2($name,'xml')){$type='xml';}
if(mb_stristr2($name,'html')){$type='html';}
if(mb_stristr2($name,'json')){$type='xml'; $json_ok=1;}

if($type=='json'){$type='xml'; $json_ok=1;}
if(empty($type)){$type='html';}

if($blog_info==1){$name='blog_info'.'_'.date('Ymd_His');}
if($name==$type or $name=='.'.$type){$name='';}
if(empty($name)){$name=$info.'_'.date('Ymd_His');}
if($info=='iikrdx'){$name=$info.'_'.date('Ymd_His').'_'.$item0['item_codigo'];}
if($info=='iiblog'){$name=$info.'_'.date('Ymd_His').'_'.$bode0['bode_codigo'];}
if($info=='cjdocu'){$name=$info.'_'.date('Ymd_His').'_'.$caja0['caja_codigo'];}
if($type=='xml'){$name=$info;}   

if(($zblockidnum==1 or $zblockdate==1 or $zblockfield==1 or $zblockmonth==1)and empty($zblockrows)){$zblockrows=3;}
if(empty($zblockrows)){$zblockrows=5;}
// if(empty($zblockbott)){$zblockbott='dotted 1px;';}
// if(empty($zblockbott)){$zblockbott='solid 2px;';}
if(empty($zblockbott)){$zblockbott='dashed 1px;';}
if(mb_stristr2('.iiie11',$info)){$zblockrows=2;}
if($info=='iillcc')
{
     $zblockrows=5;
     $zblockbott='solid 2px;';
}



$file_name=$name.'.'.$type;
$trname=substr(uniqid('', true), -3);

$domg = new DOMDocument();
     $domg->encoding = 'utf-8';
     $domg->xmlVersion = '1.0';
     $domg->formatOutput = true;
$ele=$domg;
     
     $ttbl='grid';
     $trow='row';
     $tcol='col';
//      if($json_ok==1){$trow='rows';}
     if($type=='html')
     {
          $ttbl='table';
          $trow='tr';
          $tcol='td';
     }
     
// echo '===='.$name;

     $root=$domg->appendChild($domg->createElement($name));
          $root->setAttribute('date',date('Y-m-d'));
          $root->setAttribute('time1',date('H:i:s'));
          $root->setAttribute('line-h100','');
          if(!empty($zgfsize))
          {$root->setAttribute('style','font-size:'.($zgfsize*100).'%;');}
          $divg=$root;

     if($type=='html')
     {
          $style='';
          $style.='@media screen{tr[name]:hover{background-color:lightblue !important;};}';
//           $style.='@media print{font-size:12px;}';
          if(!empty($zheightrow))
          {$style.='tr{height:'.$zheightrow.'em;}';}
          
          $root->appendChild($domg->createElement('style',$style));
     }

     // botones print xls

//      $btns=$root->appendChild($domg->createElement('span',''));
//           $btns->setAttribute('style','widht:1em;');
//           $btns->setAttribute('id','botones');
//           $btns->setAttribute('align-r','');
//           if($prnt==1)
//           {$btns->setAttribute('hide','');}

     $btns=$root;


//      echo '<br>===='.$_SESSION['screenw'];
//      echo '<br>===='.$_SESSION['screenh'];
//      echo '<br>===='.$_SESSION['screeno'];
               
     if($type=='html' and empty($zhidebtns))
     {
          
          $zdom=$domg;
          $zele=$root;
          $zele=$btns;
          $zid='prnt_'.$info.'_'.$idx; 
          $zlabel='Impri';
          $zalign='right';
          $zonclick='{nwo=window.open(xhref+"&prnt=1","_blank");nwo.print();}';
          $znoprint=1;
          $zsize=1.2;
          if($prnt==1){$zhide=1;}
          include('ele_button.php');

//           if($type=='xls')
//           if($type=='xml')

               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zobj=1;     
               include('ele_break.php');
          
          
          {
          $zdom=$domg;
          $zele=$root;
          $zele=$btns;
          $zid='xls_'.$info; 
          $zlabel='𝕏ls';
          $zalign='right';
          $zhref=$href_php_xls;
          $zdownload=1;
          $znoprint=1;
          $zsize=0.8;
          if($prnt==1){$zhide=1;}
          include('ele_button.php');
          }
          

//           if($fsoft==1 and $info=='iiddcc')
          if($fsoft==1 and $info=='iieclb')
          {
               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zobj=1;     
               include('ele_break.php');
               
               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zid='fsoft_'.$info; 
               $zlabel='FSOFT';
               $zalign='right';
               $znoprint=1;
               $zhref=$href_php_xls_fsoft;
               $zdownload=1;
               include('ele_button.php');
               
          }
          else{$fsoft=0;}
               
          if($zeus==1 and $info=='rcresu')
          {
               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zobj=1;     
               include('ele_break.php');
               
               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zid='zeus_'.$info; 
               $zlabel='ZEUS 2';
               $zalign='right';
               $znoprint=1;
               $zhref=$href_php_xls_zeus;
               $zdownload=1;
               include('ele_button.php');
               
               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zid='zeus_'.$info; 
               $zlabel='ZEUS 1';
               $zalign='right';
               $znoprint=1;
               $zhref=$href_php_xls_zeus;
               $zdownload=1;
               $zhref='https://'.$empr0['empr_codigo'].'.'.$domain.'/index2.php?scri=down_zeus&print=1&docu=RCLI&fecha1='.$fecha1.'&fecha2='.$fecha2;
               $zdownload=0;
               $zhide=1;
               include('ele_button.php');
               
               
          }
          else{$zeus=0;}
          
//           if($srid==1)
          if($srid==1 and $info=='rcresu')
          {
               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zobj=1;     
               include('ele_break.php');
               
               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zid='sridr_'.$info; 
               $zlabel='Dev.Rta.'; //rta
               $zalign='right';
               $zhref=$href_php_xls_sridr;
               $zdownload=1;
               $znoprint=1;
               include('ele_button.php');
               
               
               $zdom=$domg;
               $zele=$root;
               $zele=$btns;
               $zid='sridi_'.$info; 
               $zlabel='Dev.IVA'; //rta
               $zalign='right';
               $zhref=$href_php_xls_sridi;
               $zdownload=1;
               $znoprint=1;
               include('ele_button.php');
               
               
          }
          else{$srid=0;}
          
          if($info=='vtrpm1')
          {
          $zdom=$domg;
          $zele=$root;
          $zele=$btns;
          $zid='csv_'.$info; 
          $zlabel='CSV';
          $zalign='right';
          $zhref=substr($zfile,strpos($zfile,'/-info/'));
          $zdownload=1;
          $znoprint=1;
          $zsize=0.8;
          include('ele_button.php');
          }
     }

     // cabecera y filtros para imprimir
     if($type=='html' and $zhead==1)
     {
          $grid_main=$root->appendChild($domg->createElement($ttbl));
          $grid_main->setAttribute('id',$name.'_main');
          $grid_main->setAttribute('name',$name.'_main');
          $grid_main->setAttribute('width',$zwidthtable);
          $grid_main->setAttribute('align','center');
          $grid_main->setAttribute('hora_ini',date('H:i:s'));
          $style='';
          $style.='border-collapse:collapse;';
          $style.='background-color:'.$xbgcolor1.';';
          $style.='font-family:arial;';
          $style.='min-width:60%;';
          $grid_main->setAttribute('style',$style);
          $headg=$grid_main->appendChild($domg->createElement('thead'));
          if($zhidehead==1)
          {$headg->setAttribute("hide","");}
          $row=$headg->appendChild($domg->createElement($trow));
                    $style='border-top:solid 2px; border-bottom:solid 2px;';
                    $style.='background-color:gainsboro;';
                    $row->setAttribute("style",$style);

               $col=$row->appendChild($domg->createElement('th'));       
                    $col->setAttribute("colspan","30");
                    $col->setAttribute("bold","");
                    $col->setAttribute("valign-m","");
                    $col->setAttribute("width","100%");

               $div0=$col;  


          // TITULOS
          if(1==1)
          {

               $div1=$div0->appendChild($domg->createElement('div',""));   
                    $div1->setAttribute("style","float:left;width:30%;");
                    $div1->setAttribute("align-l","");
                    $div1->setAttribute("rel-left","");
               $div=$div1->appendChild($domg->createElement('div',htmlspecialchars($modu_descri)));   
               $div=$div1->appendChild($domg->createElement('br',''));   
               $div=$div1->appendChild($domg->createElement('div',htmlspecialchars($info_descri)));   

               $div2=$div0->appendChild($domg->createElement('div',""));   
                    $div2->setAttribute("style","float:center;display:inline-block;width:40%;");
               $dive=$div2->appendChild($domg->createElement('div',htmlspecialchars($_SESSION['empr_descri'])));   
                    $dive->setAttribute("size120","");

               $div=$div2->appendChild($domg->createElement('div',"RUC : ".$_SESSION['empr_ruc']));   
                    $div->setAttribute("size80","");
               
               
               if($empr0['empr_codigo']=='jwib')
               {
                    $dive->setAttribute("hide","");
                    $div->setAttribute("hide","");
                    
//                $div=$div2->appendChild($domg->createElement('div',"CONGREGACION : ".$cong0['cong_descri'].' ('.$cong0['cong_codigo'].')'));   
               $div=$div2->appendChild($domg->createElement('div'," ".$cong0['cong_descri']));   
                    $div->setAttribute("size120","");
               $div=$div2->appendChild($domg->createElement('div'," ".' ('.$cong0['cong_codigo'].')'));   
                    $div->setAttribute("size80","");
                    
               }
               

               $div3=$div0->appendChild($domg->createElement('div',""));   
                    $div3->setAttribute("style","float:right;top:0;width:30%;");
//                     $div3->setAttribute("style","float:right;top:0;width:;");
                    $div3->setAttribute("align-r","");
                    $div3->setAttribute("rel-right","");
                    $div3->setAttribute("size60","");

               $div=$div3->appendChild($domg->createElement('div',"USUARIO :".$user0['user_descri']));   
               $div=$div3->appendChild($domg->createElement('div',"FECHA :".date('Y-m-d')));   
               $div=$div3->appendChild($domg->createElement('div',"HORA :".date('H:i:s')));   

          $colx=3;


          $row=$headg->appendChild($domg->createElement($trow));
               $row->setAttribute('valign','top');
               $col1=$row->appendChild($domg->createElement($tcol));
                    $col1->setAttribute('style','max-width:35%');
//                     $col1->setAttribute('width',intdiv(100,$colx).'%');
               $col2=$row->appendChild($domg->createElement($tcol));
                    $col2->setAttribute('style','max-width:35%');
//                     $col2->setAttribute('width',intdiv(100,$colx).'%');
               $col3=$row->appendChild($domg->createElement($tcol));
                    $col3->setAttribute('style','max-width:35%');
//                     $col3->setAttribute('width',intdiv(100,$colx).'%');
//                     $col3->setAttribute('width',intdiv(100,8).'%');

//                if($modu=='inve' and $cost=='true'){$colx=4;}
               if($modu=='inve' and ($cost=='true' or !empty($prec))){$colx=4;}
               if($modu=='cont'){$colx=4;}
               if($info=='hchcli'){$colx=4;}
               
               if($colx>=4)
               {
               $col4=$row->appendChild($domg->createElement($tcol));
                    $col4->setAttribute('style','max-width:35%');
               }     
               

          ///////////////////////////////////
               $grid21=$col1->appendChild($domg->createElement($ttbl));
               $grid21->setAttribute("border","1");
               $grid21->setAttribute('cellpadding',"3px");
               {
                    $grid21->setAttribute('width','100%');
                    $grid21->setAttribute('align','left');
                    $style='';
                    $style.='border-collapse:collapse;';
                    $style.='background-color:'.$xbgcolor1.';';
//                     $style.='max-width:40%;';
                    $grid21->setAttribute('style',$style);
               }

               $grid22=$col2->appendChild($domg->createElement($ttbl));
               $grid22->setAttribute("border","1");
               $grid22->setAttribute('cellpadding',"3px");
               {
                    $grid22->setAttribute('width','100%');
                    $grid22->setAttribute('align','center');
                    $style='';
                    $style.='border-collapse:collapse;';
                    $style.='background-color:'.$xbgcolor1.';';
                    $grid22->setAttribute('style',$style);
               }

               $grid23=$col3->appendChild($domg->createElement($ttbl));
               $grid23->setAttribute("border","1");
               $grid23->setAttribute('cellpadding',"3px");
               {
                    $grid23->setAttribute('width','100%');
                    $grid23->setAttribute('align','right');
                    $style='';
                    $style.='border-collapse:collapse;';
                    $style.='background-color:'.$xbgcolor1.';';
//                     $style.='max-width:50%;';
                    $grid23->setAttribute('style',$style);
               }

               if($col4)
               {
               $grid24=$col4->appendChild($domg->createElement($ttbl));
               $grid24->setAttribute("border","1");
               $grid24->setAttribute('cellpadding',"3px");
               {
     //                $grid->setAttribute('id',$name);
                    $grid24->setAttribute('width','100%');
                    $grid24->setAttribute('align','right');
                    $style='';
                    $style.='border-collapse:collapse;';
                    $style.='background-color:'.$xbgcolor1.';';
//                     $style.='max-width:35%;';
//                          $style.='font-family:arial;';
                    $grid24->setAttribute('style',$style);
               }
               }


          ///// llena filtros 
               $info_desde='';
               $info_desde.='sriats.';
               $info_desde.='sriats.';
               $info_desde.='mtclac.';
               $info_desde.='atresu.atblog.atenti.';
               $info_desde.='iikrdx.iiblog.iiiiee.iiddcc.iidocu.iiddbb.iievta.iiecon..iiecxb.iidcdd.iicuxc';
               $info_desde.='ccddcc.ccmovi.cpddcc.cpmovi.ccdcdd.cpdcdd.ccdcmm.cpdcmm.ccanti.cpanti.cccred';
               $info_desde.='ttssss.ttmovi.ttresu.ttdeta.ttsscc.ttssnn.ttssdd.ttssmm.ttrrii.ttricc.ttsfcc';
               $info_desde.='cjresu.cjmovi.cjdocu.';
               $info_desde.='bcresu.bcmovi.bcdocu.';
               $info_desde.='mmdeta';
               
               if(substr($info,2,4)=='resu' and !mb_stristr2('.ccresu.cpresu',$info)){$info_desde.=$info;}
               
//                echo '==='.
               if($empr0['empr_codigo']=='jwib'){$info_desde.=$info;}
               
               
//                echo '<br>=== '.date('W',strtotime($fecha1));
//                echo '<br>=== '.date('W',strtotime($fecha2));
//                echo '<br>=== '.days_diff($fecha1,$fecha2);

              $xfechas12=1; 
              
              if(substr($fecha1,0,7)==substr($fecha2,0,7))
              {
                   if(date('d',strtotime($fecha1))==1 and date('d',strtotime($fecha2))==date('t',strtotime($fecha2)))
                   {
                    $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $col->setAttribute('bold',"");
                         $div=$col->appendChild($domg->createElement('div',strtoupper( strftime('%B / %Y',strtotime($fecha1)) ) ));
                         $col->setAttribute('colspan',"2");
                         $col->setAttribute('align-c',"");
                        $xfechas12=0;
                   }
              }
               
//               if(days_diff($fecha1,$fecha2)==6)
              {
                   if($semana>0)     
                   {
                    $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $col->setAttribute('bold',"");
                         if($semana==1)
                         {$div=$col->appendChild($domg->createElement('div',strtoupper('SEMANA '.strftime('%W / %Y',strtotime($fecha1)) ) ));}
                         if($semana==2)
                         {$div=$col->appendChild($domg->createElement('div',$semanas.' '.strtoupper('SEMANAS' ) ));}
                         $col->setAttribute('colspan',"2");
                         $col->setAttribute('align-c',"");
                        $xfechas12=0;
                   }
              }
               
               
              if(substr($fecha1,5,5)=='01-01' and substr($fecha2,5,5)=='12-31')
              {
                   if(date('Y',strtotime($fecha1))==date('Y',strtotime($fecha2)))
                   {
                    $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $col->setAttribute('bold',"");
                         $div=$col->appendChild($domg->createElement('div',strtoupper('AÑO '.strftime('%Y',strtotime($fecha1)) ) ));
                         $col->setAttribute('colspan',"2");
                         $col->setAttribute('align-c',"");
                        $xfechas12=0;
                   }
              }
               
               
              if(mb_stristr2($info_desde,$info) or $blog_info==1 or mb_stristr2('.vt.co.cl.pr..rp.rc..cj.bc..op.hc',substr($info,0,2)))
              if($xfechas12==1)
              {
                    $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $col->setAttribute('bold',"");
                         $div=$col->appendChild($domg->createElement('div','FECHAS' ) );
                         $col->setAttribute('colspan',"2");
                         $col->setAttribute('align-c',"");
                         $col->setAttribute('max-width',"50%");
                   
                   
              }
               
               if(mb_stristr2($info_desde,$info) or $blog_info==1 or mb_stristr2('.vt.co.cl.pr..rp.rc..cj.bc..op.hc',substr($info,0,2)))
               {
                    $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                         $div=$col->appendChild($domg->createElement('div','DESDE'));
                    $col=$row->appendChild($domg->createElement($tcol));
//                          $div=$col->appendChild($domg->createElement('span',strftime2('%A %e/%B/%Y',strtotime($fecha1))));
                         $div=$col->appendChild($domg->createElement('span',$fecha1));
                         if($semana==2)
                         {$div=$col->appendChild($domg->createElement('span',' (S'.date('W',strtotime($fecha1)).') '));}
                         $div=$col->appendChild($domg->createElement('span',' / '.strftime2('%A',strtotime($fecha1))));
                    
                         $div->setAttribute('nowrap',"");
               }

//                echo '===='.$semana;
               // grid 21
{
               if(!empty($fecha2))
               {
               $row=$grid21->appendChild($domg->createElement($trow));
               $col=$row->appendChild($domg->createElement($tcol));
                    //$col->setAttribute('width',"20%");
                    $col->setAttribute('bold',"");
                    $div=$col->appendChild($domg->createElement('div','HASTA'));
               $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('span',$fecha2));
                         if($semana==2)
                         {$div=$col->appendChild($domg->createElement('span',' (S'.date('W',strtotime($fecha2)).') '));}
                         $div=$col->appendChild($domg->createElement('span',' / '.strftime2('%A',strtotime($fecha2))));
                    $div->setAttribute('nowrap',"");
               }

               if(!empty($stat))
               {
                    $stat0=data_maes('stat',$stat);
                    $xfilter='STATUS';
                    $stat_box=$stat.' - '.$stat0['stat_descri'];
                    $xvalue=$stat_box;

                    $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    
               }

     
               if(!empty($nivel))
               {
               $row=$grid21->appendChild($domg->createElement($trow));
                    if(mb_stristr2('.ttresu.ttdeta.ttmovi',$info))
                    {$row->setAttribute('hide',' ');}
               $col=$row->appendChild($domg->createElement($tcol));
                    $col->setAttribute('bold',"");
                    $div=$col->appendChild($domg->createElement('div','NIVEL'));
               $col=$row->appendChild($domg->createElement($tcol));
                    $div=$col->appendChild($domg->createElement('div',$nivel));
               }
     
               if(!empty($impor))
               {
               $row=$grid21->appendChild($domg->createElement($trow));
               $col=$row->appendChild($domg->createElement($tcol));
                    //$col->setAttribute('width',"20%");
                    $col->setAttribute('bold',"");
                    $div=$col->appendChild($domg->createElement('div','IMPORTACION'));
               $col=$row->appendChild($domg->createElement($tcol));
                    $div=$col->appendChild($domg->createElement('div',$impor));
               }

     
               if(!empty($caja) or $info=='cjmovi')
               {
                    $xfilter='CAJA';
                    $caja_box=$caja;
//                     if((int)$ctab!=0)
                    {$caja_box=$caja.' - '.$caja0['caja_descri'];}
                    if($info=='cjmovi')
                    {$caja_box=$caja0['caja_codigo'].' - '.$caja0['caja_descri'];}
                    $xvalue=$caja_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

               }

     
               if(!empty($ctab) or $info=='bcmovi')
               {
                    
                    $xfilter='CTA. BANCARIA';
                    $ctab_box=$ctab;
                    {$ctab_box=$ctab.' - '.$ctab0['ctab_descri'];}
                    if($info=='bcmovi')
                    {$ctab_box=$ctab0['ctab_codigo'].' - '.$ctab0['ctab_descri'];}
                    $xvalue=$ctab_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

               }

     
     


               $xfilter='';
               $xvalue='';                         
//                $row=$grid21->appendChild($domg->createElement($trow));
               if(!empty($docu))
               {
                    $xfilter='DOCUMENTO';
                    $xvalue=$docu.' - '.$docu0['docu_descri'];
               }
               if(!empty($xfilter) and !empty($xvalue))
               {
                    $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }



               $xfilter='';
               $xvalue='';                         
               if($tbod_ok==1)
               {
                    $xfilter='T.BODEGA';                         
                    $xvalue=$tbod;
               }
               if(!empty($xfilter) and !empty($xvalue))
               {
                    $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }


               $xfilter='';
               $xvalue='';                         
               if(!empty($bode))
               {
                    $xfilter='BODEGA';
                    $xvalue=$bode.' - '.$bode0['bode_descri'];
               }
               if(!empty($ptov))
               {
                    $xfilter='PTO.VTA';
                    $xvalue=$ptov.' - '.$ptov0['ptov_descri'];
               }
               if(!empty($caja))
               {
                    $xfilter='CAJA';
                    $xvalue=$caja.' - '.$caja0['caja_descri'];
               }
     
               if(!empty($xfilter) and !empty($xvalue))
               {
                    
               $row=$grid21->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }
}               


              // grid 22
{                    
               if(!empty($tcel))
               {
                    $xfilter='T.CEle';
                    $tcel_box=$tice.' - '.$tcel0['tcel_descri'];
                    $xvalue=$tcel_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }
     
               if(!empty($zsub))
               {
                    $xfilter='ZONA';
                    $zsub_box=$zsub.' - '.$zsub0['zsub_descri'];
                    if($info=='ccmovi'){$zsub_box=$zsub0['zsub_codigo'].' - '.$zsub0['zsub_descri'];}
                    $xvalue=$zsub_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }
     
               if(!empty($tpro))
               {
                    $xfilter='T.PROV.';
                    $tpro_box=$tpro.' - '.$tpro0['tpro_descri'];
                    if($info=='cpmovi'){$tpro_box=$tpro0['tpro_codigo'].' - '.$tpro0['tpro_descri'];}
                    $xvalue=$tpro_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }
     
               if(!empty($enti))
               {
                    $xfilter='ENTIDAD';
                    if(mb_stristr2('.cxco.vtas.clie',$modu)){$xfilter='CLIENTE';}
                    if(mb_stristr2('.cxpa.comp.prov',$modu)){$xfilter='PROVEEDOR';}
                    $enti_box=$enti;
                    if((int)$enti!=0){$enti_box=$enti.' - '.$enti0['enti_descri'];}
                    if($info=='ccmovi'){$enti_box=$enti0['enti_codigo'].' - '.$enti0['enti_descri'];}
                    $xvalue=$enti_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('a',htmlspecialchars($xvalue)));
                    
                         if(mb_stristr2('.ccresu.cpresu.ccsald.cpsald.ccmovi.cpmovi.ccanti.cpanti.ccdeta.cpdeta',$info))
                         {
                              if($info=='ccanti'){$xinfo='ccresu';}
                              if($info=='ccmovi'){$xinfo='ccresu';}
                              if($info=='ccresu'){$xinfo='ccmovi';}
                              if($info=='ccdeta'){$xinfo='ccmovi';}
                              if($info=='ccsald'){$xinfo='ccmovi';}
                              
                              if($info=='cpanti'){$xinfo='cpresu';}
                              if($info=='cpmovi'){$xinfo='cpresu';}
                              if($info=='cpresu'){$xinfo='cpmovi';}
                              if($info=='cpdeta'){$xinfo='cpmovi';}
                              if($info=='cpsald'){$xinfo='cpmovi';}
                              
                              
//                               $fecha1x=$fecha1;
                              $fecha1x=date('Y-m-01',strtotime('-11 month'));
                              if($fecha1<$fecha1x){$fecha1x=$fecha1;}
//                               echo '<br>==='.$fecha1;
//                               echo '<br>==='.$fecha1x;
                              $href='';
                              $href.='?scri=info_modu3';
                              $href.='&modu='.$modu;
                              $href.='&fecha1='.$fecha1x;
                              $href.='&fecha2='.$fecha2x;
                              $href.='&enti='.$enti;
                              $href.='&tsaldo=9';
                              $href.='&info='.$xinfo;
                              $div->setAttribute("href",$href);
//                               $div->setAttribute("target",'_blank');
                         }
                    
                    if($modu=='cxco')
                    {
                         $xfilter='CONTACTOS';
                         $xcontacto=$enti0['enti_contacto'];
                         $xtelefono=$enti0['enti_telefono'];
                         $xcelular=$enti0['enti_celular'];
                         $xwsapp=$enti0['enti_wsapp'];
                         $xemail=$enti0['enti_email'];
                         
                         if(!empty($xcontacto.$xwsapp.$xemail))
                         {
                              $row=$grid22->appendChild($domg->createElement($trow));
                              $col=$row->appendChild($domg->createElement($tcol));
                                   $div=$col->appendChild($domg->createElement('div',$xfilter));
                                   $col->setAttribute('bold',"");
                              $col=$row->appendChild($domg->createElement($tcol));
//                                    $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                                   $div=$col->appendChild($domg->createElement('div',' '));
                                   if(!empty($xcontacto))
                                   {$span=$div->appendChild($domg->createElement('span',$xcontacto));}
                              
//                                    if(!empty($xcelular))
//                                    {$span=$div->appendChild($domg->createElement('span','|'.$xcelular));}
                              
                                   if(!empty($xwsapp))
                                   {
                                        $xvalue=$xwsapp;
                                        $xvalue=$xvalue*1;
                                        $xvalue=str_pad($xvalue,10,'0',STR_PAD_LEFT);
                                        $span=$div->appendChild($domg->createElement('span',' | '));
                                        $span=$div->appendChild($domg->createElement('a',$xvalue));
                                             $span->setAttribute('href','https://api.whatsapp.com/send/?phone=593'.$xvalue);
                                             $span->setAttribute('target','_blank');
                                   }
                              
                                   if(!empty($xemail))
                                   {
                                        $xvalue=$xemail;
//                                         $xvalue=strtolower($xvalue);
                                        $span=$div->appendChild($domg->createElement('span',' | '));
                                        $span=$div->appendChild($domg->createElement('a',$xvalue));
                                             $span->setAttribute('href','mailto:'.$xvalue);
                                        
                                             $onclick='{navigator.clipboard.writeText("'.$xvalue.'")}';
                                             $onclick.='{swal_fire("<msg><icon>info</icon><title>Se copió al PortaPapeles</title><text>'.$xvalue.'</text><timer>3000</timer></msg>")}';
                                             $span->setAttribute('onclick',$onclick);
                                        
                                   }
                              
                         }
                         
                    }
                    
                    
                    if(empty($vndd))
                    if(mb_stristr2('.vtas.cxco',$modu))
                    {
                         $sql_vndd2='select vndd from vtas1 where enti like "'.$enti.'%" order by fecha desc limit 1';
                         $res_vndd2=msql_query($sql_vndd2,$link_data);
                         {
                              $vndd0=data_maes('vndd',msql_result($res_vndd2,0,'vndd'));
                              $vndd_descri=$vndd0['vndd_descri'];

                              $row=$grid22->appendChild($domg->createElement($trow));
                                   $row->setAttribute('size80',"");
                              $col=$row->appendChild($domg->createElement($tcol));
                                   $div=$col->appendChild($domg->createElement('div','VENDEDOR'));
                                   $col->setAttribute('bold',"");
                              $col=$row->appendChild($domg->createElement($tcol));
                                   $div=$col->appendChild($domg->createElement('span',htmlspecialchars($vndd_descri)));
                         }
                         
                    }

                    if(1==2)
                    if(empty($rcdd))
                    if(mb_stristr2('.vtas.cxco',$modu))
                    {
                         $sql_rcdd2='select enti_rcdd from enti0 where enti like "'.$enti.'%" order by enti_codigo desc ';
                         $res_rcdd2=msql_query($sql_rcdd2,$link_data);
                         {
                              $rcdd0=data_maes('rcdd',msql_result($res_rcdd2,0,'enti_rcdd'));
                              $rcdd_descri=$rcdd0['rcdd_descri'];

                              $row=$grid22->appendChild($domg->createElement($trow));
                                   $row->setAttribute('size80',"");
                              $col=$row->appendChild($domg->createElement($tcol));
                                   $div=$col->appendChild($domg->createElement('div','RECAUDAOR'));
                                   $col->setAttribute('bold',"");
                              $col=$row->appendChild($domg->createElement($tcol));
                                   $div=$col->appendChild($domg->createElement('span',htmlspecialchars($rcdd_descri)));
                         }
                         
                    }

               }               

               if(!empty($stce))
               {
//                     $toenti0=data_maes('enti',$toenti);
//                     $xfilter='ENTIDAD';
//                     if(mb_stristr2('.cxco.vtas.clie',$modu)){$xfilter='CLIENTE';}
//                     if(mb_stristr2('.comp',$modu)){$xfilter='ADQUIRIENTE';}
//                     if(mb_stristr2('.retc',$modu)){$xfilter='SUJ.RETENIDO';}
                    $xfilter='SRI';
//                     $toenti_box=$toenti;
//                     if((int)$toenti!=0){$enti_box=$toenti.' - '.$toenti0['enti_descri'];}
//                     if($info=='ccmovi'){$enti_box=$enti0['enti_codigo'].' - '.$enti0['enti_descri'];}
//                     $xvalue=$enti_box;
                    if($stce==1){$xvalue='AUTORIZADOS';}
                    if($stce==2){$xvalue='NO AUTORIZADOS';}
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }               

     
               if(!empty($toenti))
               {
                    $toenti0=data_maes('enti',$toenti);
                    $xfilter='ENTIDAD';
//                     if(mb_stristr2('.cxco.vtas.clie',$modu)){$xfilter='CLIENTE';}
                    if(mb_stristr2('.comp',$modu)){$xfilter='ADQUIRIENTE';}
                    if(mb_stristr2('.retc',$modu)){$xfilter='SUJ.RETENIDO';}
                    $toenti_box=$toenti;
                    if((int)$toenti!=0){$enti_box=$toenti.' - '.$toenti0['enti_descri'];}
//                     if($info=='ccmovi'){$enti_box=$enti0['enti_codigo'].' - '.$enti0['enti_descri'];}
                    $xvalue=$enti_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }               

     
               
               if(!empty($tsaldo))
               {
                    $xfilter='SALDOS';
                    if($tsaldo==0){$tsaldo_descri='TODOS';}
                    if($tsaldo==6){$tsaldo_descri='Menor a 0';}
                    if($tsaldo==8){$tsaldo_descri='Igual a 0';}
                    if($tsaldo==9){$tsaldo_descri='Mayor a 0';}
                    if($tsaldo==68){$tsaldo_descri='Menor o Igual a 0';}
                    if($tsaldo==69){$tsaldo_descri='Diferente a 0';}
                    if($tsaldo==98){$tsaldo_descri='Mayor o Igual a 0';}
                    
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($tsaldo_descri)));
               }               

     
               if(!empty($pcnt))
               {
                    $xfilter='PACIENTE';
                    if($empr0['empr_veterinaria']==1)
                    {$xfilter='MASCOTA';}
                         
                    $pcnt_box=$pcnt;
                    if((int)$pcnt!=0){$pcnt_box=$pcnt.' - '.$pcnt0['pcnt_descri'];}
                    $xvalue=$pcnt_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
//                          $div=$col->appendChild($domg->createElement('div',htmlspecialchars($pcnt0['pcnt_descri'])));
                    
                    
                    $xfilter='NOMBRE';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_nom1'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

                    
                    
                    
                    
                    $xfilter='FACTURA A  ';
                    if($empr0['empr_veterinaria']==1)
                    {$xfilter='DUEÑO';}
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_factura'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    
                    
                    
               }               

     
     
               if(!empty($vndd))
               {
                    $xfilter='VENDEDOR';
                    $vndd_box=$vndd;
                    $vndd0=data_maes('vndd',$vndd);
                    if((int)$vndd!=0){$vndd_box=$vndd.' - '.$vndd0['vndd_descri'];}
                    if($info=='ccmovi'){$vndd_box=$vndd0['vndd_codigo'].' - '.$vndd0['vndd_descri'];}
                    $xvalue=$vndd_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                         $row->setAttribute('size80',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }


               if(!empty($rcdd))
               {
                    $xfilter='RECAUDADOR';
                    $rcdd_box=$rcdd;
                    $rcdd0=data_maes('rcdd',$rcdd);
                    if((int)$rcdd!=0){$rcdd_box=$rcdd.' - '.$rcdd0['rcdd_descri'];}
                    if($info=='ccmovi'){$rcdd_box=$rcdd0['rcdd_codigo'].' - '.$rcdd0['rcdd_descri'];}
                    $xvalue=$rcdd_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                         $row->setAttribute('size80',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }


               if(!empty($lsub))
               {
                    $lsub_box=$lsub.' - '.$lsub0['lsub_descri'];
                    if($info=='iikrdx'){$lsub_box=$lsub0['lsub_codigo'].' - '.$lsub0['lsub_descri'];}
                    $xfilter='LINEA';                         
                    $xvalue=$lsub_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }

               if(!empty($plvh))
               {
                    $plvh0=data_maes('plvh',$plvh);
                    
                    $plvh_box='*'.$plvh.'*';
                    $xfilter='VEHICULOS';
                    if($plvh==$plvh0['plvh_codigo'])
                    {
                         $plvh_box=$plvh.' - '.$plvh0['plvh_descri'];
                         $xfilter='VEHICULO';
                    }
                    
                    $xvalue=$plvh_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }

               if(!empty($clvh))
               {
                    $clvh0=data_maes('clvh',$clvh);
                    
                    if((int)$clvh!=0){$clvh_box=$clvh.' - '.$clvh0['clvh_descri'];}
                    
//                     $clvh_box='*'.$clvh.'*';
                    $xfilter='CLASE';
                    if($clvh==$clvh0['clvh_codigo'])
                    {
                         $clvh_box=$clvh.' - '.$clvh0['clvh_descri'];
                         $xfilter='CLASE';
                    }
                    
                    $xvalue=$clvh_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }

               if(!empty($mdvh))
               {
                    $mdvh0=data_maes('mdvh',$mdvh);
                    
                    if((int)$mdvh!=0){$mdvh_box=$mdvh.' - '.$mdvh0['mdvh_descri'];}
                    
//                     $mdvh_box='*'.$mdvh.'*';
                    $xfilter='MODELO';
                    if($mdvh==$mdvh0['mdvh_codigo'])
                    {
                         $mdvh_box=$mdvh.' - '.$mdvh0['mdvh_descri'];
                         $xfilter='MODELO';
                    }
                    
                    $xvalue=$mdvh_box;

                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }

     
               if(!empty($ctas) or $info=='ttmovi')
               {
                    
                    $ctas_box=$ctas;
//                     if($info=='ttmovi'){$ctas_box=$ctas0['ctas_codigo'].' - '.$ctas0['ctas_descri'];}
//                     if($ctas0['ctas_status']=="I"){$ctas_box.=' (INACTIVO)';}
                    
//                     if((int)$ctas!=0){$ctas_box=$ctas.' - '.$ctas0['ctas_descri'];}
//                     if($info=='ttmovi'){$ctas_box=$ctas0['ctas_codigo'].' - '.$ctas0['ctas_descri'];}
                    
                    $xfilter='GRUPO';
                    $ctan0=data_maes('ctas',$ctas0['ctas_codi1']); 
                    $xvalue=$ctan0['ctas_codigo'].' - '.$ctan0['ctas_descri'];
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    
//                     var_dump($ctas0);
                    
                    if($ctas0['ctas_codigo']>$ctan0['ctas_codigo'])
                    {
                         $xfilter='SUB-GRUPO';
                         $ctan0=data_maes('ctas',$ctas0['ctas_codi2']); 
                         $xvalue=$ctan0['ctas_codigo'].' - '.$ctan0['ctas_descri'];
                         $row=$grid22->appendChild($domg->createElement($trow));
                         $col=$row->appendChild($domg->createElement($tcol));
                              $div=$col->appendChild($domg->createElement('div',$xfilter));
                              $col->setAttribute('bold',"");
                         $col=$row->appendChild($domg->createElement($tcol));
                              $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    }

                    if($ctas0['ctas_codigo']>$ctan0['ctas_codigo'])
                    {
                         $xfilter='CUENTA';
                         $ctan0=data_maes('ctas',$ctas0['ctas_codi3']); 
                         $xvalue=$ctan0['ctas_codigo'].' - '.$ctan0['ctas_descri'];
                         $row=$grid22->appendChild($domg->createElement($trow));
                         $col=$row->appendChild($domg->createElement($tcol));
                              $div=$col->appendChild($domg->createElement('div',$xfilter));
                              $col->setAttribute('bold',"");
                         $col=$row->appendChild($domg->createElement($tcol));
                              $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    }

                    if($ctas0['ctas_codigo']>$ctan0['ctas_codigo'])
                    {
                         $xfilter='SUB-CUENTA';
                         $ctan0=data_maes('ctas',$ctas0['ctas_codi4']); 
                         $xvalue=$ctan0['ctas_codigo'].' - '.$ctan0['ctas_descri'];
                         $row=$grid22->appendChild($domg->createElement($trow));
                         $col=$row->appendChild($domg->createElement($tcol));
                              $div=$col->appendChild($domg->createElement('div',$xfilter));
                              $col->setAttribute('bold',"");
                         $col=$row->appendChild($domg->createElement($tcol));
                              $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    }

                    if($ctas0['ctas_codigo']>$ctan0['ctas_codigo'])
                    {
                         $xfilter='AUXILIAR';
                         $ctan0=data_maes('ctas',$ctas0['ctas_codi5']); 
                         $xvalue=$ctan0['ctas_codigo'].' - '.$ctan0['ctas_descri'];
                         $row=$grid22->appendChild($domg->createElement($trow));
                         $col=$row->appendChild($domg->createElement($tcol));
                              $div=$col->appendChild($domg->createElement('div',$xfilter));
                              $col->setAttribute('bold',"");
                         $col=$row->appendChild($domg->createElement($tcol));
                              $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    }



//                     if($info=='ttmovi'){$ctas_box=$ctas0['ctas_codigo'].' - '.$ctas0['ctas_descri'];}
//                     if($ctas0['ctas_status']=="I"){$ctas_box.=' (INACTIVO)';}
                    
//                     if((int)$ctas!=0){$ctas_box=$ctas.' - '.$ctas0['ctas_descri'];}
//                     if($info=='ttmovi'){$ctas_box=$ctas0['ctas_codigo'].' - '.$ctas0['ctas_descri'];}
                    
                    
//                     $xfilter='CUENTA';
// //                     $xfilter='AUXILIAR';
//                     $xvalue=$ctas_box;
//                     $row=$grid22->appendChild($domg->createElement($trow));
//                     $col=$row->appendChild($domg->createElement($tcol));
//                          $div=$col->appendChild($domg->createElement('div',$xfilter));
//                          $col->setAttribute('bold',"");
//                     $col=$row->appendChild($domg->createElement($tcol));
//                          $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }
     
               if(!empty($bode))
               {
                    $xfilter='BODEGA';
                    $bode_box=$bode.' - '.$bode0['bode_descri'];
//                     if($info=='ttmovi'){$csub_box=$csub0['csub_codigo'].' - '.$csub0['csub_descri'];}
                    $xvalue=$bode_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

               }
     
     
     
               if(!empty($item) or $info=='iikrdx')
               {
                    $item_box=$item;
                    if(empty($item0['item_descri'])){$item0=data_maes('item',$item);}
                    if((int)$item!=0 and strlen($item)>=8){$item_box=$item.' - '.$item0['item_descri'];}
                    if($info=='iikrdx'){$item_box=$item0['item_codigo'].' - '.$item0['item_descri'];}
                    $item_box.=' - '.$item0['item_umdd'];
                    
                    
                    if($item0['item_status']=="I"){$item_box.=' (INACTIVO)';}
                    
                    $xfilter='ITEM';                         
                    $xvalue=$item_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                         if($item0['item_status']=="I"){$col->setAttribute('bgc-ulyellow',' ');}

               }

               if(!empty($lote))
               {
                    $lote_box=$lote;
//                          if((int)$item!=0){$item_box=$item.' - '.$item0['item_descri'];}
//                          if($info=='iikrdx'){$item_box=$item0['item_codigo'].' - '.$item0['item_descri'];}
                    $xfilter='LOTE';                         
                    $xvalue=$lote_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

               }

               if(!empty($csub))
               {
                    $xfilter='CENTRO-S';
                    $csub_box=$csub.' - '.$csub0['csub_descri'];
                    if($info=='ttmovi'){$csub_box=$csub0['csub_codigo'].' - '.$csub0['csub_descri'];}
                    $xvalue=$csub_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

               }
     
               if(!empty($trty))
               {
                    $xfilter='TERRITORIO';
                    $trty_box=$trty.' - '.$trty0['trty_descri'];
//                     if($info=='ttmovi'){$trty_box=$trty0['csub_codigo'].' - '.$trty0['trty_descri'];}
                    $xvalue=$trty_box;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

               }
     
               if(!empty($bloq))
               {
                    $xfilter='BL.MZ.';
                    $xvalue=$bloq;
                    $row=$grid22->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

               }
     



               $xfilter='';
               $xvalue='';      
               $row=$grid22->appendChild($domg->createElement($trow));
                    $row->setAttribute('style',"height:0em;");
               if(!empty($xfilter) and !empty($xvalue))
               {
//                          $row=$grid22->appendChild($domg->createElement($trow));
//                          $col=$row->appendChild($domg->createElement($tcol));
//                               $div=$col->appendChild($domg->createElement('div',$xfilter));
//                               $col->setAttribute('width',"20%");
//                               $col->setAttribute('bold',"");
//                          $col=$row->appendChild($domg->createElement($tcol));
//                               $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
               }
}


               $xfilter='';
               $xvalue='';                         



               if($col3)
               {
               $row=$grid23->appendChild($domg->createElement($trow));
                    $row->setAttribute('style',"height:0em;");
                    
                    if(!empty($pcnt))
                    {
                    $xfilter='SEXO';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_sexod'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid23->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                         
                    $xfilter='ESPECIE';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_especie'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid23->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                         
                    $xfilter='RAZA';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_raza'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid23->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                         
                    $xfilter='COLOR';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_color'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid23->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));

                         
                         
                         
                    }
                    
                    
               }
               
               if($col4)
               {
               $row=$grid24->appendChild($domg->createElement($trow));
                    $row->setAttribute('style',"height:0em;");
                    
                    
                    if($info=='hchcli')
                    {
                    $xfilter='F.NAC.';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_fechanac'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid24->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    
                    $xfilter='EDAD';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_edad'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid24->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                    
                         
                         
                    $xfilter='ESTERIL';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_esterild'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid24->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                         
                         
                    $xfilter='VENENO';
                    if((int)$pcnt!=0){$pcnt_box=$pcnt0['pcnt_venenod'];}
                    $xvalue=strtoupper($pcnt_box);
                    $row=$grid24->appendChild($domg->createElement($trow));
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',$xfilter));
                         //$col->setAttribute('width',"20%");
                         $col->setAttribute('bold',"");
                    $col=$row->appendChild($domg->createElement($tcol));
                         $div=$col->appendChild($domg->createElement('div',htmlspecialchars($xvalue)));
                         
                    }
                         
                         
                    
                    
               }

          }

///////////////////////////////////

     $rowsg=$grid_main->appendChild($domg->createElement('tbody'));
          $row=$rowsg->appendChild($domg->createElement($trow));
               $col=$row->appendChild($domg->createElement($tcol));       
                    $col->setAttribute("style","padding:0;");
                    $col->setAttribute("colspan","99");
               $divg=$col->appendChild($domg->createElement('div'," "));                           

     }

//      if($zblockidnum==1 and empty($zblockrows)){$zblockrows=3;}
//      if(empty($zblockrows)){$zblockrows=5;}
//      if(empty($zblockbott)){$zblockbott='dotted 1px;';}
//      if(mb_stristr2('.iiie11',$info)){$zblockrows=2;}
//      if($info=='iillcc')
//      {
//           $zblockrows=5;
//           $zblockbott='solid 2px;';
//      }

     $thead=array();     
     $tfoot=array();
     $tfootcc=array();
     $tsuma=array();
     $tsumad=array();
     $tdeci=array();

     $field_name=array();
     $field_type=array();
     $field_leng=array();
     $head_name=array();

     $grid=$divg->appendChild($domg->createElement($ttbl));
          $grid->setAttribute('id',$name.'');     
          $grid->setAttribute('class','tbl_info ');
          $grid->setAttribute('name',$name);
          $grid->setAttribute('border','0');

          if($type=='html')
          {
               $grid->setAttribute('blockrows',$zblockrows);
               $grid->setAttribute('blockbott',$zblockbott);
               $grid->setAttribute('heightrow',$zheightrow);
               if($info=='iillcc')
               {$grid->setAttribute("border","1");}
          }              

     if($type=='html')
     {
          $grid->setAttribute('id',$name);
          $grid->setAttribute('align','center');
          $grid->setAttribute('width',$zwidthtable);
          $style='';
          $style.='border-collapse:collapse;';
          $style.='background-color:'.$xbgcolor1.';';
          $style.='min-width:60%;';
          if($formacol==1)
          {$style.='min-width:90%;';}
          
          $grid->setAttribute('style',$style);
     }

     if($type=='xml')
     {
          $rowsg=$grid->appendChild($domg->createElement('tbody'));
          $footg=$grid->appendChild($domg->createElement('tfoot'));
     }

     if($type=='html')
     {
          $caption='';
          $grid->appendChild($domg->createElement('caption',$caption));
          $colg=$grid->appendChild($domg->createElement('colgroup'));
          

          
          
          $headg=$grid->appendChild($domg->createElement('thead'));
               $style='';
               $style.='background-color:silver;';
               $style.='border-top:2px solid;border-bottom:2px solid;';
               $style.='z-index:9999;';
          
               $style.='top:0px;';
               if(empty($prnt)){$style.='top:100px;';}
               $headg->setAttribute('style',$style);
          
//                if(msql_num_rows($zreso)>=5)
               if(mb_stristr2($scri,'info'))
               {$headg->setAttribute('sticky','');}

          $rowsg=$grid->appendChild($domg->createElement('tbody'));
               $rowsg->setAttribute('valign','top');
               $rowsg->setAttribute('style','overflow-y:auto;');
          
          $footg=$grid->appendChild($domg->createElement('tfoot'));
               $style.='bottom:10px;';
               $footg->setAttribute('style',$style);
          
//                if(mb_stristr2($scri,'info'))
               if(msql_num_rows($zreso)>=5)
               {$footg->setAttribute('sticky','');}
     }

     // verifica columna en blanco y longitud de columna
//      $ncol=0;
     msql_data_seek($zreso);
     for($xcol=0; $xcol<msql_num_fields($zreso); $xcol++)
     {
          $field_name[$xcol]=msql_field_name($zreso,$xcol);
          $field_type[$xcol]=msql_field_type($zreso,$xcol);
          
          $head_name[$xcol]=$field_name[$xcol];
          $head_name[$xcol]=str_replace('_hide','',$head_name[$xcol]);
          $head_name[$xcol]=str_replace('_edit','',$head_name[$xcol]);
          $head_name[$xcol]=str_replace('_check','',$head_name[$xcol]);
          
          if(mb_stristr2($field_name[$xcol],'__')){$field_name[$xcol]=str_replace('__','-',$field_name[$xcol]);}
          
          for($xrow=0; $xrow<msql_num_rows($zreso); $xrow++)
          {
               $value=msql_result($zreso,$xrow,$xcol);
               if(mb_stristr2('.numero.numer.num.',$field_name[$xcol])){$value=(int)$value; }
               $value_leng=strlen($value);
               if($value_leng>$field_leng[$xcol]){$field_leng[$xcol]=$value_leng;}
          }

          
//           var_dump2($field_name);
          
          $tdeci[$xcol]=0;
          for($xrow=0; $xrow<msql_num_rows($zreso); $xrow++)
          {
               $value=msql_result($zreso,$xrow,$xcol);
               $tsuma[$xcol]+=(float)$value;
               
               $value_dec=(floatval($value)-intval($value))*100;
               if(!empty($value_dec))
               if(strlen($value_dec)>$tdeci[$xcol])
               {$tdeci[$xcol]=strlen($value_dec);}
               
               if(mb_stristr2($field_name[$xcol],'porc_') and $tdeci[$xcol]>2)
               {$tdeci[$xcol]=2;}
               
               if(mb_stristr2($field_name[$xcol],'porc_'))
               {$tsuma[$xcol]=0;}
               
//                if(substr($field_name[$xcol],0,4)=='prom')
//                {$tsuma[$xcol]=0;}
               
//                if(mb_stristr2($field_name[$xcol],'idnum'))
//                {$tsuma[$xcol]=0;}
               
          }
          

          for($xrow=0; $xrow<msql_num_rows($zreso); $xrow++)
          {
               $value=msql_result($zreso,$xrow,$xcol);
               $value_leng=strlen($value);

               if(mb_stristr2('.int',$field_type[$xcol])){$value=(int)$value;}
               if(mb_stristr2('.real',$field_type[$xcol])){$value=(float)$value;}
               if(mb_stristr2('.int.real',$field_type[$xcol]) and $type=='xml'){$value=1;}
               if(mb_stristr2('.inicial_$.stock.saldo.saldo_$.total.total_$.neto.',$field_name[$xcol])){$value=1;}
               if(mb_stristr2('.ingreso.egreso.debito_$.credito_$',$field_name[$xcol])){$value=1;}
               if($empr0['empr_rete']==1 and $modu=='cxpa')
               {if(mb_stristr2('.reten',$field_name[$xcol])){$value=1;}}                    
               
               if(mb_stristr2($field_name[$xcol],'_hide')){$value=0;}
               if(mb_stristr2('.b_e.b_o.b_x.b_a.u_f',$field_name[$xcol]) and !empty($prnt)){$value=0;}
   
               // 2023-07-23 comentariado para mostrar diferenci inventrio
//                if(mb_stristr2('.int.real',$field_type[$xcol]) and $value<0.01){$value=0;}
               
               
//                if($field_type[$xcol]=='int'){$tsuma[$xcol]+=$value;}
//                if($field_type[$xcol]=='real'){$tsuma[$xcol]+=$value;}
//                $tsuma[$xcol]+=$value;
               
               if(!empty($value)){$thead[$xcol]=1;break;}
               if(substr($field_name[$xcol],-5)=='_edit'){$thead[$xcol]=1;break;}
               if(substr($field_name[$xcol],-6)=='_check'){$thead[$xcol]=1;break;}
               if($edit>0)
               {
                    if($field_name[$xcol]=='atrz'){$thead[$xcol]=1;break;}
                    
               }
          }
     }

     $num_col=array_sum($thead);

// var_dump2($tsuma);


     $l_idn=@msql_result($zreso,0,'idnum1_hide');
     $l_date=@msql_result($zreso,0,'fecha');
     $l_field=@msql_result($zreso,0,$zblockfield);

// echo '*/*/*'.$zblockfield;
// echo '*/*/*/'.$l_field;
     $ssnega=0;
     $sum_stock=0;
     $sum_saldo=0;
     $xcountrow=0;


     if(msql_num_rows($zreso)==0)
     {
          $row=$rowsg->appendChild($domg->createElement($trow));
          $col=$row->appendChild($domg->createElement($tcol));
          $col->setAttribute('align-c','');
          if(!empty($zhidehead))
          {$div=$col->appendChild($domg->createElement('div',$modu_descri));}
//           $div=$col->appendChild($domg->createElement('div',$info_descri ));
          $div=$col->appendChild($domg->createElement('div',"NO HAY DATOS"));
     }


     $l_year='';
     $l_month='';
     $l_ctas='';
     $l_item='';
     $sum_saldo=0;

     $lnivel=0;
     $lgrupo='';
     $llongi=0;

     // diascob
     if(1==2)
     if($info=='ccresu')
     {
//           echo '<br> ==> '.date('H:i:s');
          $cdias=0;
          msql_data_seek($zreso,0);
          while ($asoc=msql_fetch_assoc($zreso))
          {
               if($asoc['vence']>='2000-01-01' and $asoc['u_movi']>='2000-01-01')
               {
                    $xdiascob=days_diff($asoc['vence'], $asoc['u_movi']);
                    $sql_updt='update vtas1 set diascob="'.$xdiascob.'" where idnum1="'.$asoc['idnum1_hide'].'"';
                    $res_updt=msql_query($sql_updt,$link_data);
               }
          }
//           echo '<br> ==> '.date('H:i:s');
     }

//      if($anticipo>0)
     if($zhidecols==1)
     if($info=='ccresu' or $info=='cpresu')
     {
//           echo '====='.$tsuma['saldo'];
//           var_dump2($tsuma);
          
          if($modu=='cxco'){$doca='AC';}
          if($modu=='cxpa'){$doca='AP';}
          $anticipo=calc_anticipo($doca,$enti,$fecha2);
          
          $divanti=$grid->appendChild($domg->createElement('div'," "));
               $divanti->appendChild($domg->createElement('span','ANTICIPOS : '));
               $divanti->appendChild($domg->createElement('span',number_format($anticipo,2)));
               $divanti->setAttribute('align-r',' ');
               $divanti->setAttribute('size120',' ');
               $divanti->setAttribute('bold',' ');
               if($anticipo==0)
               {$divanti->setAttribute('hide',' ');}
     }

     // llena detalle
     if($show_timei>=1)
     {echo '<br>=== ele_grid detalle ==== '.date('H:i:s');}

     msql_data_seek($zreso,0);
     for($xrow=0; $xrow<msql_num_rows($zreso); $xrow++)
     {
          
          if($show_timei>=2)
          {echo '<br>=== ele_grid linea ==== '.date('H:i:s');}
          
          {
          $col_sticky==0;
               
          $tabla_link=$modu;     
          $asoc=msql_fetch_assoc($zreso);
          $num_deci0=0;
          $num_deci=2;
          $item_duni=$asoc['item_duni_hide'];
          $item_dval=$asoc['item_dval_hide'];
          $item_dpre=$asoc['item_dpre_hide'];
          $item_dcos=$asoc['item_dcos_hide'];
          $status=$asoc['status'];
          $stat=$asoc['stat'];
          $st=$asoc['st'];
          if($item_dval<2){$item_dval=2;}
          if($item_dpre<2){$item_dpre=2;}
          if($item_dcos<2){$item_dcos=2;}
          if($modu!='inve'){$item_duni=2;}
          }

          if(1==2)
          if($info=='ccresu')
          {
               $xdiascob=days_diff($asoc['u_movi'], $asoc['vence']);
               
//                last_error();               
               
//                $sql_updt='update vtas1 set diascob="'.$xdiascob.'" where idnum1="'.$asoc['idnum1_hide'].'"';
//                $res_updt=msql_query($sql_updt,$link_data);
          }
          
          
          if($empr0['empr_codigo']=='jwib'){$item_duni=0;}
          
          if(mb_stristr2($info,'ddbb') or $type!='html')
          {
               $num_deci=6;
               $item_duni=6;
               $item_dval=6;
               $item_dpre=6;
               $item_dcos=6;
          }
          
          if($modu=='cont' and $asoc['ctas_hide']!=$l_ctas)
          {$sum_saldo=0; $l_ctas=$asoc['ctas_hide'];}

          if($modu=='inve' and $asoc['item_hide']!=$l_item)
          {$sum_saldo=0; $sum_stock=0; $l_item=$asoc['item_hide'];}

          $sum_stock=$sum_stock+$asoc['stock'];
          $sum_saldo=$sum_saldo+$asoc['saldo_$'];
          $sum_saldo=$sum_saldo+$asoc['saldo'];
          
//           if(mb_stristr2('.1.2.3',substr($asoc['ctas'],0,1)) and strlen($asoc['ctas'])<=2)
          if($modu=='cont')
          if(strlen($asoc['ctas'])<=2)
          {
               if(substr($asoc['ctas'],0,1)==1){$sum_1activo+=$asoc['saldo']+$asoc['saldo_hide'];}
               if(substr($asoc['ctas'],0,1)==2){$sum_2pasivo+=$asoc['saldo']+$asoc['saldo_hide'];}
               if(substr($asoc['ctas'],0,1)==3){$sum_3patrim+=$asoc['saldo']+$asoc['saldo_hide'];}
               if(substr($asoc['ctas'],0,1)==4){$sum_4ingres+=$asoc['saldo']+$asoc['saldo_hide'];}
               

               if($empr0['empr_ctasuper']==1)
               {
                    if(substr($asoc['ctas'],0,1)==5 and substr($asoc['ctas'],0,2)==51){$sum_51costos+=$asoc['saldo']+$asoc['saldo_hide'];}
                    if(substr($asoc['ctas'],0,1)==5 and substr($asoc['ctas'],0,2)>=52){$sum_52gastos+=$asoc['saldo']+$asoc['saldo_hide'];}
//                     if(substr($asoc['ctas'],0,1)==5 and substr($asoc['ctas'],0,2)>=5){$sum_52gastos+=$asoc['saldo']+$asoc['saldo_hide'];}
                    if(substr($asoc['ctas'],0,1)>=7){$sum_7otrosg+=$asoc['saldo']+$asoc['saldo_hide'];}
                    $sum_8otrosg=0;
                    
                    $sum_situacion=$sum_1activo +$sum_2pasivo +$sum_3patrim;
                    $sum_resultado=$sum_4ingres +$sum_51costos +$sum_52gastos +$sum_8otrosg;
               }
               
                              
               if($empr0['empr_ctasuper']!=1)
               {
                    if(substr($asoc['ctas'],0,1)==5){$sum_5costos+=$asoc['saldo']+$asoc['saldo_hide'];}
                    if(substr($asoc['ctas'],0,1)==6){$sum_6gastos+=$asoc['saldo']+$asoc['saldo_hide'];}
                    if(substr($asoc['ctas'],0,1)==7){$sum_7otrosi+=$asoc['saldo']+$asoc['saldo_hide'];}
                    if(substr($asoc['ctas'],0,1)==8){$sum_8otrosg+=$asoc['saldo']+$asoc['saldo_hide'];}

                    $sum_situacion=$sum_1activo +$sum_2pasivo +$sum_3patrim;
                    $sum_resultado=$sum_4ingres +$sum_5costos +$sum_6gastos +$sum_7otrosi +$sum_7otrosg +$sum_8otrosg;
               }
               
               

               
               
               if($sum_situacion!=0 or $sum_resultado!=0)
               {$nofoot=1;}
          }

          if(mb_stristr2('.ttssff.ttrrii',$info))
          {$nohead=1; $znolin=1; }

          if(mb_stristr2('.ttsscc.ttsfcc.ttricc',$info))
          {$nofoot=0;}
          
          if($info=='sudet2')
          {$nofoot=1;}

          $class='';
          $style=''; 
//           if(($xcountrow+1)%$zblockrows==0){$style.='border-bottom:'.$zblockbott; } 
          if($xrow+1==msql_num_rows($zreso)){$style.='border-bottom:solid 2px;'; } 
          

          
          $xcountrow++;
          
          if(mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc.ttsscc.ttssaa.',$info) and $asoc['nivel_hide']==1 )
          {
//                     $style.='background-color:gainsboro !important;';
                    $style.='background-color:#E8E8E8!important;';
//                     $style.='background-color:#F0F0F0;';
                    $style.='border-top:solid 2px;';
                    $style.='border-bottom:solid 2px;';
                    $xcountrow=0;
          }
          
          if(mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc.ttsscc.ttssaa.',$info) and $asoc['nivel_hide']==3 )
          {
//                     $style.='border-top:solid 1px;';
//                     $style.='border-bottom:solid 1px;';
//                     $xcountrow=0;
          }
          
          if(mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc..ttsscc.ttssaa.',$info) and $asoc['nivel_hide']<=3 )
          {
//                     $style.='border-top:;';
//                     $style.='border-bottom:;';
//                     $xcountrow=0;
          }
          
          if($zblockidnum==1)
          {
               $n_idn=@msql_result($zreso,$xrow+1,'idnum1_hide');
               if($n_idn!=$l_idn)
               {
                    $style.='border-bottom:solid 2px;';
                    $l_idn=$n_idn;
                    $xcountrow=0;
               }
          }      
          
          if($zblockdate==1)
          {
               $n_date=@msql_result($zreso,$xrow+1,'fecha');
               if($n_date!=$l_date)
               {
                    $style.='border-bottom:solid 2px;';
                    $l_date=$n_date;
                    $xcountrow=0;
               }
          }          
          
          if(!empty($zblockfield))
          {
               $n_field =@msql_result($zreso,$xrow+1,$zblockfield);
               if($n_field!=$l_field)
               {
                    $style.='border-bottom:solid 2px;';
                    $l_field=$n_field;
                    $xcountrow=0;
               }
          }
          

          if($zblockmonth==1)
          {
               $n_month=substr(@msql_result($zreso,$xrow+1,'fecha'),0,7);
               if($n_month!=$l_month)
               {
                    $style.='border-bottom:solid 2px;';
                    $l_month=$n_month;
                    $xcountrow=0;
               }
          }
          
          if(mb_stristr2('.ttssff.ttrrii',$info) and $nivel>=2)
          {
               
          }
          

          
//           if($lgrupo!=$asoc[$zgrupo] or ($xrow-1)>=msql_num_rows($zreso) )
//           or !msql_fetch_assoc($zreso)
          
//           echo '==='.msql_num_rows($zreso);
//           echo '==='.$xrow;
          
          
          if(!empty($zgrupo))
          {
               if($lgrupo!=$asoc[$zgrupo] or msql_num_rows($zreso)==($xrow+1))
               {
                    $agrupo=$asoc[$zgrupo];
                    if(msql_num_rows($zreso)==($xrow+1))
                    {
                         foreach($array_grupo as $key=>$valor)
                         {$array_grupo[$key]+=$asoc[$key];}
                    }

                    if($lgrupo!='')
                    {
                         foreach($array_grupo as $key=>$valor)
                         {
                              if($valor< abs($saldo0))
                              {
                                   $cgtot=${'cg_'.$key}->appendChild($domg->createElement('span','-'));                                   
                              }
                              
                              if($valor>= abs($saldo0))
                              {
                                   $cgtot=${'cg_'.$key}->appendChild($domg->createElement('span',''.number_format($valor,2)));

                                   if($valor< ($saldo0*-1))
                                   {
                                        $cgtot->setAttribute('red','');
                                        $cgtot->setAttribute('bgc-ulyellow','');
                                   }
                                   
                              }
                                   
                         }
                    }

                    
                    if($lgrupo!=$asoc[$zgrupo])
                    {
                         $rowgrupo=$rowsg->appendChild($domg->createElement('tr','')); 
                              $rgstyle='height:2.5em; border-top:2px solid; border-bottom:1px solid;';
                              $rowgrupo->setAttribute('bold','');
                              $rowgrupo->setAttribute('align-m','');
                              $rowgrupo->setAttribute('style',$rgstyle);

                              $rowgrupo->setAttribute('bgc-ulblue',' ');                         
                              $rowgrupo->setAttribute('size120',' ');
                    }
                    
                    $colgrupo=$rowgrupo->appendChild($domg->createElement('td',""));
                              if(msql_num_rows($zreso)==($xrow+1))
                              {$colgrupo->setAttribute('hide',' ');}

                    for($xcol=0; $xcol<msql_num_fields($zreso); $xcol++)
                    {
                         $descrigru='';
                         if($zgrupo==msql_field_name($zreso,$xcol))
                         {
                              $descrigru=$asoc[$zgrupo];
                         }
                         
                         if($info=='ccdeta' or $info=='cpdeta')
                         {
                              if(mb_stristr2('.fecXha.docu.numero.',msql_field_name($zreso,$xcol)))
                              {$descrigru=$asoc[msql_field_name($zreso,$xcol)];}
                         }

                         
                         if(substr($info,-4)=='resu')
                         {
                              if(msql_field_name($zreso,$xcol)==$zgrupo)
                              {$descrigru=$asoc[msql_field_name($zreso,$xcol)];}
                         }
                         
                         $colgrupo=$rowgrupo->appendChild($domg->createElement('td',htmlspecialchars($descrigru)));
                              if(msql_num_rows($zreso)==($xrow+1))
                              {$colgrupo->setAttribute('hide',' ');}

                         if(substr(msql_field_name($zreso,$xcol),-4)=='hide')
                         {$colgrupo->setAttribute('hide','');}

//                          if(mb_stristr2('.int.real',$field_type[$xcol]))
//                          if($tsuma[$xcol]==0)
//                          {$colgrupo->setAttribute('hide','');}

                         if(mb_stristr2('.total.saldo.costo.valor.debito.credito',msql_field_name($zreso,$xcol)))
                         {
                              if(mb_stristr2('.total.saldo.costo.valor',msql_field_name($zreso,$xcol)))
                              {
                                   $colgrupo->setAttribute('td_total','');
                              }

                              $colgrupo->setAttribute('align-r','');
                              ${'cg_'.msql_field_name($zreso,$xcol)}=$colgrupo;
                              $array_grupo[msql_field_name($zreso,$xcol)]=0;
                         }

                    }

                    $lgrupo=$asoc[$zgrupo];
               }
               
               foreach($array_grupo as $key=>$valor)
               {$array_grupo[$key]+=$asoc[$key];}
          }

          
          
          
          
          $row=$rowsg->appendChild($domg->createElement($trow));
//                $row->setAttribute('class','prueba1');
               $classr='ctas ';
               if($modu=='cont')
               {
                    for($idxn=1; $idxn<=$asoc['nivel_hide']; $idxn++)
                    {$classr.='n'.$idxn.' ';}

                    
                    if($empr0['empr_ctasuper']==1)
                    {
                         if(mb_stristr2('.1.2.3',substr($asoc['ctas'],0,1)))
                         {
                              if($asoc['nivel_hide']>=2){$classr.='g'.substr($asoc['ctas'],0,1).' ';}
                              if($asoc['nivel_hide']>=3){$classr.='g'.substr($asoc['ctas'],0,3).' ';}
                              if($asoc['nivel_hide']>=4){$classr.='g'.substr($asoc['ctas'],0,5).' ';}
                              if($asoc['nivel_hide']>=5){$classr.='g'.substr($asoc['ctas'],0,7).' ';}
                         }
                         if(!mb_stristr2('.1.2.3',substr($asoc['ctas'],0,1)))
                         {
                              if($asoc['nivel_hide']>=2){$classr.='g'.substr($asoc['ctas'],0,2).' ';}
                              if($asoc['nivel_hide']>=3){$classr.='g'.substr($asoc['ctas'],0,4).' ';}
                              if($asoc['nivel_hide']>=4){$classr.='g'.substr($asoc['ctas'],0,6).' ';}
                              if($asoc['nivel_hide']>=5){$classr.='g'.substr($asoc['ctas'],0,8).' ';}
                         }
                    }
                    else
                    {
                         if($asoc['nivel_hide']>=2){$classr.='g'.substr($asoc['ctas'],0,1).' ';}
                         if($asoc['nivel_hide']>=3){$classr.='g'.substr($asoc['ctas'],0,3).' ';}
                         if($asoc['nivel_hide']>=4){$classr.='g'.substr($asoc['ctas'],0,5).' ';}
                         if($asoc['nivel_hide']>=5){$classr.='g'.substr($asoc['ctas'],0,7).' ';}
                    }
                         
               }
               $row->setAttribute('class',$classr);
               
//           if(($xcountrow+1)%$zblockrows==0){$row->setAttribute('bb-do1',''); } 
          if(($xcountrow)%$zblockrows==0){$row->setAttribute('bb-do1',''); } 

          
          
          // formato vertical
          if($formacol==1)
          {
               $headg->setAttribute('style','display:none;');
               $footg->setAttribute('style','display:none;');

               $colcol=$row->appendChild($domg->createElement('td'));
               $tabcol=$colcol->appendChild($domg->createElement('table'));
                    $tabcol->setAttribute('style','width:100%; border:2px solid; text-align:right; font-size:1.4em;');
               $rowcol=$tabcol->appendChild($domg->createElement('tr'));
               $row=$rowcol->appendChild($domg->createElement('td'));
                    $row->setAttribute('style','text-align:center;');
               $tcol='span';
               $tcol='div';
          }
          
          if($type=='html')
          {
               $zhrefok=1;
//                if(!empty($zheightrow))
//                {$style.='height:'.$zheightrow.'em;';}
               
               if($zblockidnum==1)
               {
//                     $c_idn=@msql_result($zreso,$xrow,'idnum1_hide');
//                     if($c_idn!=$l_idn)
//                     {$style.='border-top:solid 2px;'; $l_idn=$c_idn;}
               }
               $tr_id=$trname.'_'.($xrow+1);
               $row->setAttribute('id',$tr_id);
               $row->setAttribute('name',"");
//                $row->setAttribute('timer',date('H:i:s'));
               
               // asigna valores en id(pantalla)
               $xondblclick='';
               if(substr($info,0,2)=='ii' and substr($info,2,4)!='det2' and substr($info,2,4)!='krdx' )
               {
                    $xondblclick ="{";
                    $xondblclick.="set_idvalue('item','".msql_result($zreso,$xrow,'item')."');";
                    $xondblclick.="set_idvalue('puni','".msql_result($zreso,$xrow,'puni1_hide')."');";
                    $xondblclick.="set_idvalue('pvp','".msql_result($zreso,$xrow,'pvp_1')."');";
                    $xondblclick.="set_idvalue('iva','".msql_result($zreso,$xrow,'iva_hide')."');";
                    $xondblclick.="}";
                    $row->setAttribute('ondblclick',htmlspecialchars($xondblclick));
               }

               if(substr($info,0,2)=='cc' or substr($info,0,2)=='cp')
               {
                    $xondblclick ="{";

                    // caja/bcos
                    $xondblclick.="set_idvalue('docum','".msql_result($zreso,$xrow,'docu')."');";
                    $xondblclick.="set_idvalue('ptoem','".msql_result($zreso,$xrow,'ptoe')."');";
                    $xondblclick.="set_idvalue('numer','".msql_result($zreso,$xrow,'numero')."');";
                    $xondblclick.="set_idvalue('cant','".msql_result($zreso,$xrow,'saldo')."');";
                    
                    
                    //n.cre
                    $iva_fact=msql_result($zreso,$xrow,'iva_hide');
                    if(mb_stristr2($scri,'regi_vtas'))
                    {
                    $xondblclick.="set_idvalue('todocu','".msql_result($zreso,$xrow,'docu')."');";
                    $xondblclick.="set_idvalue('toptoe','".msql_result($zreso,$xrow,'ptoe')."');";
                    $xondblclick.="set_idvalue('tonume','".msql_result($zreso,$xrow,'numero')."');";
                    $xondblclick.="set_idvalue('item','9999999999');";
                    {$xondblclick.="set_idvalue('cant','1');";}
                    $xondblclick.="set_idvalue('puni','".msql_result($zreso,$xrow,'saldo')/(1+($iva_fact/100))."');";
                    $xondblclick.="set_idvalue('iva','".$iva_fact."');";
                    $xondblclick.="set_idvalue('subtot','".msql_result($zreso,$xrow,'saldo')."');";
                    }
                    
                    $xondblclick.="}";
                    $row->setAttribute('ondblclick',htmlspecialchars($xondblclick));
               }

               if($status=='O' or $stat=='O' or $st=='O'){$row->setAttribute('linethr',"");}
               if(!empty($style)){$row->setAttribute('style',$style);}
               if(!empty($class)){$row->setAttribute('class',$class);}

               // COLUMNA #linea
               $col=$row->appendChild($domg->createElement($tcol,str_pad($xrow+1,strlen(msql_num_rows($zreso)),'0',STR_PAD_LEFT)));
//                $style='background-color:white;';
//                $style='';
               $class='';
               
//                if(mb_stristr2('.ttssff.ttrrii',$info))
               if($znolin==1)     
               {$col->setAttribute('hide',"");}

               $col->setAttribute('sticky-left',"");
               $col->setAttribute('align-c',"");
               $col->setAttribute('size80',"");
//                $col->setAttribute('border-lr',"");
               if(!empty($class)){$col->setAttribute('class',$class);}
               if(!empty($style)){$col->setAttribute('style',$style);}
          }
          
          // llena fila
//           if(1==2)
          for($xcol=0; $xcol<msql_num_fields($zreso); $xcol++)
          {
               $num_deci=2;
               if(substr($field_name[$xcol],0,4)=='porc')
               {$num_deci=$tdeci[$xcol];}
               
               
               if($field_name[$xcol]=='s_min')
               {$num_deci=0;}
               if($field_name[$xcol]=='s_max')
               {$num_deci=0;}
               
               
               if($empr0['empr_codigo']=='jwib')
               if(mb_stristr2('.lb.m1.m2.m3.m4.vi.nc.nt.',$field_name[$xcol]))
               {$num_deci=0;}
               
               
               // formato vertical
               if($formacol==1)
               {
                    $nomcol=msql_field_name($zreso,$xcol);
                    if(substr($nomcol,-5)!='_hide')
                    {
                         $nomcol=strtoupper($nomcol);
                         if(mb_stristr2('b_o',$nomcol)){$nomcol='';}
                         $colname=$row->appendChild($domg->createElement('div',' '));
                              $xstylec="clear:both; height:5px;";
                              if($nomcol=='CANT' or $nomcol=='ENTRA')
                              {$xstylec.='border-top:1px solid;';}
                              $colname->setAttribute("style",$xstylec);
                         if(!empty($nomcol)){$nomcol.=' : ';}
                         $colname=$row->appendChild($domg->createElement('span',$nomcol.'  '));
                              $colname->setAttribute('float-l','');
                              $colname->setAttribute('bold','');
                              $colname->setAttribute('size80','');
                    }
               }                    
               
               $value=msql_result($zreso,$xrow,$xcol);
//                if(substr($value,0,2)=='&#'){$value=html_entity_decode($value);}
               if(mb_stristr2($value,'&#')){$value=html_entity_decode($value);}
               
               $value1='';
               $value2='';
               if($type=='xml'){$tcol=$field_name[$xcol];}
               if($field_type[$xcol]=='int'){$tfoot[$xcol]=(int)$tfoot[$xcol]+(int)$value;}
               if($field_type[$xcol]=='real'){$tfoot[$xcol]+=$value;}
               
               
               // aqui resultados
               if(mb_stristr2('.ttsscc.ttsfcc.ttricc',$info))
               {
                    if($field_type[$xcol]=='int' or $field_type[$xcol]=='real') 
                    if($info=='ttricc'){$value=$value*(-1);}
                    
                    if($field_type[$xcol]=='int' or $field_type[$xcol]=='real') 
                    if(strlen($asoc['ctas'])<=2)
                    {
//                          $tfootcc[$xcol]+=(real)$value;
                         $tfootcc[$xcol]+=(float)$value;
                         $tfoot[$xcol]=$tfootcc[$xcol];
                         if($tfootcc[$xcol]==0){$tfootcc[$xcol]='';}
                    }
                    
               }
               
               
               if(substr($field_name[$xcol],0,4)=='prom'){$tfoot[$xcol]='';}
//                if(substr($field_name[$xcol],0,4)=='prom'){$tfoot[$xcol]=$tfoot[$xcol]/msql_num_rows($zreso);}
               if(mb_stristr2($field_name[$xcol],'porc_')){$tfoot[$xcol]=0;}
               if(mb_stristr2($field_name[$xcol],'idnum')){$tfoot[$xcol]='';}
               if($empr0['empr_codigo']=='jwib')
               if(mb_stristr2('.lb.m1.m2.m3.m4.grupo',$field_name[$xcol])){$tfoot[$xcol]='';}
               
               if($field_type[$xcol]=='string'){$value=alltrim($value);}

               if($info=='iikrdx' and $field_name[$xcol]=='stock'){$value=$sum_stock;}
               if($info=='iikrdx' and $field_name[$xcol]=='saldo_$'){$value=$sum_saldo;}
               if($info=='ccmovi' and $field_name[$xcol]=='saldo'){$value=$sum_saldo;}
               if($info=='cpmovi' and $field_name[$xcol]=='saldo'){$value=$sum_saldo;}
               if($info=='ccanti' and $field_name[$xcol]=='saldo'){$value=$sum_saldo;}
               if($info=='cpanti' and $field_name[$xcol]=='saldo'){$value=$sum_saldo;}
               if($info=='ttmovi' and $field_name[$xcol]=='saldo'){$value=$sum_saldo;}
               if($info=='cjmovi' and $field_name[$xcol]=='saldo'){$value=$sum_saldo;}
               if($info=='bcmovi' and $field_name[$xcol]=='saldo'){$value=$sum_saldo;}
               
               
               
//                $value9=(real)$value;
               $value9=(float)$value;
               
//                if($value!=0 and abs($value)<$saldo0)
               if($value!=0 and abs((float)$value)<$saldo0)
               {
                    if($field_name[$xcol]=='saldo')
                    {$value=0; $value9=0;}
               }
               
               
               
               
               if(!mb_stristr2('.nombre.cliente.proveedor.empleado.producto.vendedor.persona',$field_name[$xcol]))
               {$value=abrevia($value);}
               
               
               
//                if($field_name[$xcol]=='bode' and msql_result($zreso,$xrow,'docu')=='EB13'){$value.='►'.msql_result($zreso,$xrow,'bode2_hide');}
//                if($field_name[$xcol]=='bode' and msql_result($zreso,$xrow,'docu')=='IB13'){$value.='◄'.msql_result($zreso,$xrow,'bode2_hide');}
//                if($field_name[$xcol]=='bode' and msql_result($zreso,$xrow,'docu')=='EB13'){$value.=' ►';}
//                if($field_name[$xcol]=='bode' and msql_result($zreso,$xrow,'docu')=='IB13'){$value.=' ◄';}

               if($type=='xml' and !empty($thead[$xcol]))
               {
//                     if(empty($value)){$value=' ';}
                    $col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));
               }

               if($type=='html' and !empty($thead[$xcol]))
               {
                
                    if(mb_stristr2('.int.real',$field_type[$xcol]))
                    {$value=number_format($value9,$num_deci);}
                    
                    
                    if($field_name[$xcol]=='st')
                    {$st_count[$value]++;}
                    
                    if(mb_stristr2($field_name[$xcol],'u_') and mb_stristr2('.int.real',$field_type[$xcol]))
                    {$value=number_format(trunc_real($value9,$item_dval),$item_duni);}
                    if(mb_stristr2($field_name[$xcol],'$_') and mb_stristr2('.int.real',$field_type[$xcol]))
                    {$value=number_format(trunc_real($value9,$item_dval),$item_dval);}
                    if(mb_stristr2($field_name[$xcol],'_u') and mb_stristr2('.int.real',$field_type[$xcol]))
                    {$value=number_format(trunc_real($value9,$item_dval),$item_duni);}
                    if(mb_stristr2($field_name[$xcol],'_$') and mb_stristr2('.int.real',$field_type[$xcol]))
                    {$value=number_format(trunc_real($value9,$item_dval),$item_dval);}

                    if(mb_stristr2('._c_.dias_v.diasv',$field_name[$xcol]) and mb_stristr2('.int.real',$field_type[$xcol]))
                    {$value=number_format((float)$value9,$num_deci0);}
                    
                    if(mb_stristr2('.inicial',$field_name[$xcol]) and mb_stristr2('.int.real',$field_type[$xcol]))
                    {$value=number_format((float)$value9,$item_duni);}

                    if(mb_stristr2('.puni.p_unit.p-unit.unit.punit.pvp',$field_name[$xcol]))
                    {$value=number_format(trunc_real($value9,$item_dval),$item_dpre);}
                    
                    if(mb_stristr2($field_name[$xcol],'antig'))
                    {$value=number_format($value9,$num_deci0);}
                    
                    if(mb_stristr2($field_name[$xcol],'p_uni'))
                    {$value=number_format(trunc_real($value9,$item_dval),$item_dpre);}
                    
                    if(mb_stristr2('.stock.stock_ini.stock_fin',$field_name[$xcol])and mb_stristr2('.int.real',$field_type[$xcol]))
                    {$value=number_format((float)$value9,$item_duni);}
                    
                    if(mb_stristr2('.cant.ingreso.egreso',$field_name[$xcol]))
                    {$value=number_format((float)$value9,$item_duni);}

                    
//                     if()
                    if(mb_stristr2('.iidcdd.iidcmm',$info) and mb_stristr2($field_name[$xcol],'$'))
                    {$value=number_format((float)$value9,2);}


                    if(mb_stristr2('.valor',$field_name[$xcol]))
                    {$value=number_format((float)$value9,$item_dcos);}

                    if(mb_stristr2('.contable',$field_name[$xcol]) and mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc.ttsscc.ttssaa.',$info) and $asoc['nivel_hide']==$nivel)
                    {$value=ucwords2($value);}

                    if(mb_stristr2('.contable',$field_name[$xcol]) and mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc.ttsscc.ttssaa.',$info))
                    {
                         $value=str_repeat('. ',(int)$asoc['nivel_hide']-1).($value);
                    }

//                     if(mb_stristr2('.contable',$field_name[$xcol]) and mb_stristr2('.ttssff.ttrrii',$info))
//                     {$value='<p>'.str_repeat('   ',(int)$asoc['nivel_hide']-1).($value).'</p>';}

//                     if($field_name[$xcol]=='documento' and $value=='* I N I C I A L *')
                    if($fkrdx==1)
                    {
                         if($value=='* I N I C I A L *')
                         {
                              $row->setAttribute("bgc-lsblue","");
                              $row->setAttribute("bold","");
                         }
                    }
                    
                    
                    
                    
                    if($field_name[$xcol]=='c_pro_$')
                    {$value=number_format((float)$value9,$item_dcos);}

                    if(mb_stristr2('.cost.cost_prom',$field_name[$xcol]) and mb_stristr2('.int.real',$field_type[$xcol]))
                    {
                         $item_dcos2=$item_dcos;
                         if($value9>=1)
                         {
//                               $sql_updt='update item0 set item_dcos=2 where item_codigo like "'.$asoc['item'].'%"';
//                               $res_updt=msql_query($sql_updt,$link_data);
                         }
                         if($value9>=1){$item_dcos2=2;}
                         if($value9<1 and $item_dcos2<=4){$item_dcos2=4;}
                         $value=number_format(trunc_real($value9,$item_dval),$item_dcos2);
                    }

                    if(mb_stristr2('.int',$field_type[$xcol]))
                    {$value=number_format(trunc_real($value9,$item_dval),0);}


//                    if($value=='0.00'){$value='▬';}
                    
                    
                    if(substr($field_name[$xcol],-6)=='_check')
                    {}
                    else
                    {
                         if(mb_stristr2('.ttssff.ttrrii',$info))
                         {if($value=='0.00'){$value='';}}
                         else
                         {if($value=='0.00'){$value='--';}}
                    }
                    
                    
                    
                    if(mb_stristr2('.img',$field_name[$xcol]))
                    {
//                               if(file_exists($value))
//                               {$value_img=$value;$value="";}
                         if(empty($value)){$value="SIN FOTO";}
                         else{$value_img=$value;$value="";}
                    }

                    $crea_value=true;
//                     echo '/*/*'.$info;
                    
                    if($field_name[$xcol]=='u_f')
                    {
                         
                         $fdoc_docu=$asoc['docu'].$asoc['docu_hide'];
                         $fdoc_idnum=$asoc['idnum1_hide'];
                         $fdoc_iddet=$asoc['iddet_hide'];
                         
                         $sql_fdoc='';
                         $sql_fdoc.='select * from fdoc0 ';
                         $sql_fdoc.='where ifnull(fdoc_status,"") not in ("I","X") ';
                         $sql_fdoc.='and fdoc_docu="'.$fdoc_docu.'"';
                         $sql_fdoc.='and fdoc_idnum="'.$fdoc_idnum.'"';
                         $sql_fdoc.='and fdoc_iddet="'.$fdoc_iddet.'"';
                         $res_fdoc=msql_query($sql_fdoc,$link_data);
                         
                         $value='';
//                          $value=msql_num_rows($res_fdoc);
//                          echo '<br>===='.$sql_fdoc;
//                          echo '<br>===='.$value;
                         
                         if($asoc['u_f']=='u_f')
                         {
                              $sticon='📁';
                              
                              
                                   $col=$row->appendChild($domg->createElement($tcol,''));
                                   $crea_value=false;
                              
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zid='fdoc_'.$fdoc_docu.'_'.$fdoc_idnum.'_'.$fdoc_iddet;
                              $zlabel='Subir Archivos';
                              $ztype='file';
                              $zmulti=1;
//                               $zaccept='.xml,.txt,.pdf';
                              $zaccept='.pdf,.doc,.png,.jpg,.jpeg';
                              $zlabel2='';
                              $zsize=0.8;
                              $zalign='right';
                              $zonclick2="{upld_filedocu('".$fdoc_docu."','".$fdoc_idnum."','".$fdoc_iddet."','".$zid."');}";
//                               $zhide=1;
//                               $zlabel2='🔼';
//                               $zlabel2='📁';
                              include('ele_input.php');
                              
                              
                              
                              
                              
                         }
                    }
                    
//                          echo '====='.$asoc['b_o'];
                    if($field_name[$xcol]=='b_o')
                    {
                         $value='';
                         if(($asoc['b_o']!=0) and !empty($user0['user_tipo']))
                         {
                              $stvalue=''; $stdescri=''; $stattrib='';
                              
                              $idnum_link=$asoc['idnum1_hide'];
                              $iddet_link=$asoc['iddet_hide'];
                              $docu_link=$asoc['docu_hide'];
                              $numero_link=$asoc['numero_hide'];
                              
//                               if(mb_stristr2($info,'resu')){$iddet_link='';}
                                                            
//                                    ⛔🚫🅾❌
                              if($asoc['b_o']==1)
                              {
                                   if(mb_stristr2('.sist.supe.admi',$user0['user_tipo']) or $asoc['usr']==$user0['user_codigo'])
                                   {$stvalue='--'; $st_anul=$iddet_link; $stdescri='Remover'; $stattrib='bt_-'; $sticon='⛔';}
                                   else{$idnum_link='';}
                              }
                              
                              if($asoc['b_o']==2)
                              {
//                                    echo '<br>=='.$asoc['usr'];
//                                    echo '<br>=='.$user0['user_codigo'];
                                   if(mb_stristr2('.sist.supe',$user0['user_tipo']) or $asoc['usr']==$user0['user_codigo'])
                                   {$stvalue='O'; $st_anul=$stvalue; $stdescri='Anular'; $stattrib='bt_o'; $sticon='🚫'; $iddet_link='';}
                                   else{$idnum_link='';}
//                                    ⟲
//                                    nota de credito
//                                    if($empr0['empr_codigo']=='demo')
                                   {
//                                         if(substr($asoc['docu'],0,2)=='FC' and $asoc['autorfec_hide']!='')
//                                         {$stvalue='N'; $st_anul=$stvalue; $stdescri='N.Crédito'; $stattrib='bt_o'; $sticon='⭕'; $iddet_link='';}
                                   }
                              }
                              
                              if($asoc['b_o']==3)
                              {
                                   if(mb_stristr2('.sist.supe',$user0['user_tipo']))
                                   {$stvalue='X'; $st_anul=$stvalue; $stdescri='Eliminar'; $stattrib='bt_x'; $sticon='X'; $iddet_link='';}
                                   else{$idnum_link='';}
                              }
                              
                              if(!empty($idnum_link))
                              {
                                   $col=$row->appendChild($domg->createElement($tcol,''));
//                                    $ref=$col->appendChild($domg->createElement('button',$stvalue));                           
                                   $ref=$col->appendChild($domg->createElement('button',$sticon));                           
                                   $ref->setAttribute('title',$stdescri.' /'.$docu_link.'-'.(int)$numero_link.' /'.$iddet_link);
                                   
                                   $tconfirm=$docu_link.'-'.(int)$numero_link.' /'.$iddet_link;
                                   if(($asoc['b_o']==1)){$st_anul=$iddet_link;}
                                   else{$st_anul=$stvalue;}
                                   $ref->setAttribute('onclick','{anul_docu("'.$docu_link.'","'.$idnum_link.'","'.$st_anul.'","'.$tconfirm.'","'.$tr_id.'");}');
                                   $ref->setAttribute($stattrib,'');
//                                    $ref->setAttribute('noprinter','');
                                   $crea_value=false;
                              }
                         }

                    }

                    if($field_name[$xcol]=='b_a')
                    {
//      ☑✅⍻
                         $value='';
                         if(($asoc['b_a']!=0) and !empty($user0['user_tipo']))
                         {
                              $stvalue='';$stdescri='';$stattrib='';
                              
                              $idnum_link=$asoc['idnum1_hide'];
                              $iddet_link=$asoc['iddet_hide'];
                              $docu_link=$asoc['docu_hide'];
                              $numero_link=$asoc['numero_hide'];
                              
//                               echo '*/*'.$asoc['b_a'];
                              if($asoc['b_a']==1)
                              {
                                   if(mb_stristr2('.sist.supe.admi',$user0['user_tipo']) or $asoc['usr']==$user0['user_codigo'])
                                   {$stvalue='A'; $st_anul=$iddet_link; $stdescri='Aprobar'; $stattrib='bt_-'; $sticon='✅';}
                                   else{$idnum_link='';}
                              }
                              
                              if($asoc['b_a']==2)
                              {
                                   if(mb_stristr2('.sist.supe.admi',$user0['user_tipo']) or $asoc['usr']==$user0['user_codigo'])
                                   {$stvalue='R'; $st_anul=$iddet_link; $stdescri='Procesar'; $stattrib='bt_-'; $sticon='✍';}
                                   else{$idnum_link='';}
                              }
                              
                              if(!empty($idnum_link))
                              {
                                   $col=$row->appendChild($domg->createElement($tcol,''));
                                   $ref=$col->appendChild($domg->createElement('button',$sticon));                           
                                   $ref->setAttribute('title',$stdescri.' /'.$docu_link.'-'.$numero_link*(1).' /'.$iddet_link);
                                   
                                   $tconfirm=$docu_link.'-'.$numero_link*(1).' /'.$iddet_link;
                                   if(($asoc['b_a']==1)){$st_anul=$iddet_link;}
                                   else{$st_anul=$stvalue;}
                                   $ref->setAttribute('onclick','{prcs_docu("'.$docu_link.'","'.$idnum_link.'","'.$stvalue.'","'.$tconfirm.'","'.$tr_id.'");}');
                                   $ref->setAttribute($stattrib,'');
//                                    $ref->setAttribute('noprinter','');
                                   $crea_value=false;
                              }
                         }

                    }
                    
                    
                    if($field_name[$xcol]=='fecha')
                    {
//                          $col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));       
//                               $col->setAttribute('title',$asoc['dia_hide']);
//                          $crea_value=false;
                    }

                    
                    
                    if($field_name[$xcol]=='u_movi')
                    {
//                          $value=date_diff(date('Y-m-d'), $value);
//                          $col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));       
//                               $col->setAttribute('title',$asoc['dia_hide']);
//                          $crea_value=false;
                    }

                    
                    if($field_name[$xcol]=='iess_cober')
                    {
                         $rpis_file='rpis/RPIS_'.$asoc['fecha'].'_'.$asoc['cedula'].'.pdf';
                         $href='';

                         if(file_exists($rpis_file))
                         {
//                               $href='https://'.$cfg_empr.'.vcrxol.com/'.$rpis_file;
                              $href='https://'.$cfg_empr.'.'.$domain.'/'.$rpis_file;
                              $onclick.="down_url('".$rpis_file."')";
                         }
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
//                          $ref->setAttribute('onclick',$onclick);
                         $ref->setAttribute('href',$href);
                         $ref->setAttribute('target','_blank');
                         $crea_value=false;
                         
                    }
                    
                    
                    
                    if($field_name[$xcol]=='ats')
                    {
//                          echo '==='.$toenti;
                         $xanio=substr($asoc['a_mes_hide'],0,4);
                         $xmes=substr($asoc['a_mes_hide'],5,2);
//                          $onclick="gen_ats('".$xanio."','".$xmes."');";
                         
                        $xmes1=$xmes; 
                        $xmes2=$xmes; 
                         
                        $empr_seme=[];
                        $empr_seme[]='0993391288001'; 
                         
                         
                        if($empr0['empr_sriats']==6 or in_array($toenti,$empr_seme))
                        {
                             if($xmes>=1 and $xmes<=6) {$xmes1='01';$xmes2='06';}
                             if($xmes>=7 and $xmes<=12){$xmes1='07';$xmes2='12';}
//                              $psixm=1;
//                              $sriiva=6;
                        }
                         
                         
                         $onclick="gen_ats('".$xanio."','".$xmes."','".$toenti."');";
//                          $onclick.="down_url('info/ATS_".$xanio.$xmes."_".$empr0['empr_codigo'].".xml')";
                         $onclick.="down_url('-info/ATS_".$xanio.$xmes2."_".$empr0['empr_codigo'].'_'.$toenti.".xml')";
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                         $ref->setAttribute('onclick',$onclick);
                         $ref->setAttribute('target','_blank');
                         $ref->setAttribute('nowrap','');
                         $crea_value=false;
                    }
                    
                    if($field_name[$xcol]=='idn')
                    {

                         $tabla_modu=$modu;
                         if(mb_stristr2('.cxco.cxpa',$modu))
                         {$tabla_modu='';}
                         
                         if(mb_stristr2('.vtas.clie',$modu))
                         {$tabla_modu='vtas';}
                         
                         $href='';
                         $alert='';
                         
                         
//                          if(substr($asoc['st_ce'],0,2)!=25)
                         {
                              $href='';
                              $href.='?scri=regi_'.$tabla_modu.'3';
                              $href.='&docu='.substr($asoc['docu'].$asoc['docu_hide'],0,4);
                              $href.='&idnum1='.$idnum_link;
                              $href.='&modu='.$tabla_modu;
                              $href.='&ptoe='.$asoc['ptoe'];
                              $href.='&ptov='.$asoc['ptov'];
                              $href.='&caja='.$asoc['caja'];
                              $href.='&ctab='.$asoc['ctab'];
                              
                              if(!empty($asoc['bode']))
                              {$href.='&bode='.$asoc['bode'];}
                              
                              if(!empty($asoc['placa']))
                              {$href.='&plvh='.$asoc['placa'];}
                              
                              if(!empty($asoc['plvh']))
                              {$href.='&plvh='.$asoc['plvh'];}
                              
                              if(!empty($asoc['vinn']))
                              {$href.='&vinn='.$asoc['vinn'];}
                              
                              $href.='&numero='.$asoc['numero'];
     //                          $href.='&tpos=3';
                              if($tabla_link=='vtas'){$href.='&tpos=3';}
                              if($tabla_link=='inve'){$href.='&tpos=3';}
                         }
                         
                         if(substr($asoc['st_ce'],0,2)==25)
                         {
                              if(mb_stristr2('.comp',$modu))
                              {
                                   $href='';
                                   $href.='?scri=info_modu3';
                                   $href.='&docu='.substr($asoc['docu'].$asoc['docu_hide'],0,4);
                                   $href.='&idnum1='.$idnum_link;
                                   $href.='&modu='.$tabla_modu;
                                   $href.='&info='.substr($modu,0,2).'deta';
                                   $href.='&fecha1='.$asoc['fecha'];
                                   $href.='&fecha2='.$asoc['fecha'];
                                   $href.='&numero='.$asoc['numero'];
                                   $href.='&enti='.$asoc['enti'];
                                   $href.='&edit=90';
                              }
                         }
                         
                         
                         
                         if($modu=='cont' and substr($asoc['docu'],0,2)!='DD')
                         {$href='';}
                         
//                          if(1==1)
                         if(!empty($href))
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
//                               if(substr($asoc['st_ce'],0,2)!=25)
                              {
                                   $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('target','_blank');
                                   
//                                    if(substr($asoc['st_ce'],0,2)==25)
//                                    {$ref->setAttribute('onclick',"swal_fire('<msg><icon>info</icon><title>Aviso</title><text>DOCUMENTO YA ESTA AUTORIZADO</text></msg>')");}
                              }

//                               if(substr($asoc['st_ce'],0,2)==25)
//                               {
//                                    $ref=$col->appendChild($domg->createElement('span',htmlspecialchars($value)));
//                                    $ref->setAttribute('onclick',"swal_fire('<msg><icon>info</icon><title>Aviso</title><text>DOCUMENTO YA ESTA AUTORIZADO</text></msg>')");
//                               }
                              
                              $crea_value=false;
                         }
                         

                         if(1==2)
                         if(!empty($href))
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
//                               if(substr($asoc['st_ce'],0,2)!=25)
                              {
                                   $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('target','_blank');
                              }

//                               if(substr($asoc['st_ce'],0,2)==25)
//                               {
//                                    $ref=$col->appendChild($domg->createElement('span',htmlspecialchars($value)));
//                                    $ref->setAttribute('onclick',"swal_fire('<msg><icon>info</icon><title>Aviso</title><text>DOCUMENTO YA ESTA AUTORIZADO</text></msg>')");
//                               }
                              $crea_value=false;
                         }
                         
                         
                         
                         
                    }

                    
//                     if($field_name[$xcol]=='wsapp' )
                    if(mb_stristr2($field_name[$xcol],'wsapp') and strlen(trim($asoc['wsapp']))>=9)
                    {
//                          $xwsapp=trim($asoc['wsapp']);
//                          $xwsapp=substr($xwsapp,-10);     
//                          $xwsapp=str_pad($xwsapp,10,'0',STR_PAD_LEFT);     

                         $wsappme=$value;
                         $wsappme=substr($wsappme,-10);     
                         $wsappme=str_pad($wsappme,10,'0',STR_PAD_LEFT);     
                         if(strlen($wsappme)==9 or strlen($wsappme)==10)
                         {$wsappme='593'.$value;}
                         
                         $href='';
                         $href='https://wa.me/'.$wsappme;
                         
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                         $ref->setAttribute('num',$value);
                         $ref->setAttribute('href',$href);
                         $ref->setAttribute('target','_blank');

                         $crea_value=false;
                    }                    
                    

                    if($field_name[$xcol]=='territorio')
                    {
//                                    https://jwib.vcrxol.com/?scri=regi_jwrt3
                                   if($empr0['empr_codigo']=='jwib')
                                   {
                                        if($info=='rtttff')
                                        {
                                        $href='https://'.$_SERVER['SERVER_NAME'].'/';
                                        $href.='?scri=regi_jwrt3';
//                                         $href.='&prnt=1';
//                                         $href.='&info='.$asoc['docu_hide'];
                                        $href.='&cong='.$cong0['cong_codigo'];
                                        $href.='&trty='.$asoc['trty_hide'];
//                                         $href.='&idnum='.$asoc['idnum1_hide'];
                                        }
                                   }
                                    
                                    
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                    
                                   $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('num',$value);
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('target','_blank');

                                   $crea_value=false;
                    }
                    
                    
                    
                    if($field_name[$xcol]=='asignado')
                    {
                                   if($empr0['empr_codigo']=='jwib')
                                   {
                                        $href='https://'.$_SERVER['SERVER_NAME'].'/';
                                        $href.='?scri=jwib_asig4';
                                        $href.='&prnt=1';
                                        $href.='&info='.$asoc['docu_hide'];
                                        $href.='&cong='.$cong0['cong_codigo'];
                                        $href.='&idnum='.$asoc['idnum1_hide'];
                                   }
                                    
                                    
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                    
                                   $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('num',$value);
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('target','_blank');

                                   $crea_value=false;
                    }
                    
                    
//                     if(1==2)
                    $col_names=[];
                    $col_names[]='numero';
                    $col_names[]='idc';
                    $col_names[]='total';
                    $col_names[]='debito';
                    $col_names[]='credito';
//                     if($field_name[$xcol]=='numero' or $field_name[$xcol]=='idc' or $field_name[$xcol]=='total'  or $field_name[$xcol]=='debito'  or $field_name[$xcol]=='credito' )
                    if(in_array($field_name[$xcol],$col_names))
                    {
                         if(!empty($asoc['docu'].$asoc['docu_hide']) and (int)$asoc['numero']>0 )
                            {
                              {
//                                    echo '<br>==>'.$asoc['tabla1'];
                                   
                                   $tabla_link=$asoc['tabla1'];
                                   if(empty($tabla_link)){$tabla_link=$asoc['tabla1_hide'];}
                                   
                                   $idnum_link=$asoc['idn'];
                                   if(empty($idnum_link))$idnum_link=$asoc['idnum1_hide'];
                                   
//                                    if($asoc['mdfrom']!='cont')
                                   if($modu=='cont')
                                   if(!empty($asoc['idfrom_hide']))
                                   {
                                        $idnum_link=$asoc['idfrom_hide'];
                                        if(substr($asoc['docu'],0,2)=='DD')
                                        {$idnum_link=$asoc['idn'];}
                                   }
                                   
                                   if(empty($idnum_link))
                                   {
                                    $sql_getid ='select idnum1 from '.$tabla_link.'1 where status!="X" ';
                                    $sql_getid.='and docu="'.substr($asoc['docu'].$asoc['docu_hide'],0,4).'"  ';
                                    $sql_getid.='and numero*1="'.(int)$asoc['numero'].'" ';
                                    $sql_getid.='and ifnull(ptoe,"")="'.substr($asoc['ptoe'].$asoc['ptoe_hide'],0,6).'"  ';
                                   
                                   if($tabla_link=='vtas' and $empr0['empr_ceuser']==1)
                                   {$sql_getid.='and idnum1 = "'.$asoc['idnum1_hide'].'" ';}

                                   if($tabla_link=='comp')
                                   {$sql_getid.='and left(enti,10) like "'.substr($asoc['enti'].$asoc['enti_hide'],0,10).'%" ';}
                                   
                                   if($tabla_link=='retc')
                                   {$sql_getid.='and left(enti,10) like "'.substr($asoc['enti'].$asoc['enti_hide'],0,10).'%" ';}
                                   
                                   if($tabla_link=='inve')
                                   {$sql_getid.='and bode = "'.$asoc['bode'].'" ';}
                                   
                                   if($tabla_link=='caja')
                                   {
                                        $sql_getid.='and caja like "'.substr($asoc['caja'].$asoc['caja_hide'],0,6).'%" ';
                                        $sql_getid.='and enti like "'.substr($asoc['enti_hide'],0,10).'%" ';
                                   }
                                   
                                   if($tabla_link=='bcos')
                                   {$sql_getid.='and ctab like "'.substr($asoc['ctab'].$asoc['ctab_hide'],0,6).'%" ';}
                                   
                                   if($tabla_link=='rmed')
                                   {$sql_getid.='and (mdco like "'.$asoc['mdco'].'%" )';}
                                   
//                                    echo '<br>=== '.$tabla_link;
//                                    echo '<br>=== '.$sql_getid;
                                   
                                    $res_getid=msql_query($sql_getid,$link_data);
                                    $idnum_link=msql_result($res_getid,0,'idnum1');
                                        
                                   }

//                                if($field_name[$xcol]!='total')
                                    if(!mb_stristr2('.total.debito.credito',$field_name[$xcol]))     
                                    if((int)$value>0)
                                    {$value=str_pad((int)$value,$field_leng[$xcol],'0',STR_PAD_LEFT);}
                                   
                              }
                              
                              if(substr($asoc['docu'],0,2)!='DD')
                              if($info=='ttdeta'){$tabla_link=$asoc['mdfrom_hide']; $idnum_link=$asoc['idfrom_hide'];}
                              

                              
                               if(!empty($idnum_link))
                                 {
                                   $xptoe=$asoc['ptoe'];
                                   if(empty($xptoe)){$xptoe=$asoc['ptoe_hide'];}
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                    
                                   $href='https://'.$cfg_empr.'.'.$domain.'/index2.php?';
                                   $href.='prnt=1&docu='.substr($asoc['docu'].$asoc['docu_hide'],0,4).'&idnum='.$idnum_link.'&formato=';
                                   if($field_name[$xcol]=='idc'){$href.='3';}
                                    
                                   if(mb_stristr2('.ttmovi.ttresu',$info) and !empty($asoc['mdfrom_hide']))
                                   {$href.='?prnt=1&docu='.substr($asoc['docu'].$asoc['docu_hide'],0,4).'&idnum='.$idnum_link.'&formato=3';}
                                    
//                                    if(mb_stristr2('.vtas.clie.comp.inve.infi.retc.retp.guia.opro.hcli.prov.lpro.cont.caja.bcos.jwrt.rmed.',$tabla_link))
//                                    if(mb_stristr2('.vtas.clie.comp.inve.infi.retc.retp.guia.opro.hcli.prov.lpro.cont.caja.bcos.jwrt.rmed.dxco.dxpa.',$tabla_link))
                                   {
                                        $href='https://'.$_SERVER['SERVER_NAME'].'/';
//                                         if(mb_stristr2($_SERVER['REQUEST_URI'],'index3.php'))
//                                         {$href.='index3.php';}
                                        $href.='?scri=info_docu3';
                                        $href.='&prnt=1';
                                        $href.='&docu='.substr($asoc['docu'].$asoc['docu_hide'],0,4);
                                        $href.='&idnum='.$idnum_link.'';
                                        if(mb_stristr2('.cxco.cxcpa',$modu))
                                        {$href.='&abon=1';}
//                          echo '==== ';
                                   }
                                    
                                   
//                                    if($field_name[$xcol]=='numero' and $modu!='cont' and mb_stristr2('.vtas.comp.inve',$tabla_link))
//                                    {$href.='&abon=1';}
                                    
                                   if($field_name[$xcol]=='numero' and $modu=='cont')
                                   {$href.='&cont=1';}
                                    
                                   if(substr($info,-4)=='resu' and mb_stristr2('.total.debito.credito',$field_name[$xcol])) 
                                   {
                                        if(substr($info,0,2)=='tt'){$href.='&cont=1';}
                                        else{$href.='&cont=2';}
                                   }
                                         
                                   if($info=='ttdeta' and mb_stristr2('.toXtal.debito.credito',$field_name[$xcol])) 
                                   {$href.='&cont=2';}
                                         
                                    
                                   if($tabla_link=='vtas' and $cfg_empr=='anml'){$href.='&pgsize=P';} 
                                    
                                    
//                                    if($empr0['empr_codigo']=='jwib')
//                                    {
//                                         $href='https://'.$_SERVER['SERVER_NAME'].'/';
//                                         $href.='?scri=jwib_asig4';
//                                         $href.='&prnt=1';
//                                         $href.='&info='.$asoc['docu_hide'];
//                                         $href.='&cong='.$cong0['cong_codigo'];
//                                         $href.='&idnum='.$asoc['idnum1_hide'];
//                                    }
                                    
                                    
                                    
                                   $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('num',$value);
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('target','_blank');

                                   $crea_value=false;
                                 }
                            }

                    }

                    // aplica
//                     if(1==2)
                    if($field_name[$xcol]=='numer' and !empty($asoc['numer']))
                    {
                         $xdocum=$asoc['docum'];
                         if(empty($xdocum)){$xdocum=$asoc['docum_hide'];}
                         $xptoem=$asoc['ptoem'];
                         if(empty($xptoem)){$xptoem=$asoc['ptoem_hide'];}
                         if(!empty($xdocum) and !empty($asoc['numer']))
                         {
//                          echo '<br>====>';
                              $sql_getab='select docu_tabla from docu0 where docu_codigo="'.$xdocum.'"';
                              $res_getab=msql_query($sql_getab,$link_data);
                              $tabla_link=strtolower(msql_result($res_getab,0,'docu_tabla'));
                              $idnum_link='';
                              
                              if(!empty($tabla_link))
                              {
                                   $sql_getid='select idnum1 from '.$tabla_link.'1 ';
                                   $sql_getid.='where ifnull(status,"")not in ("O","X") ';
                                   $sql_getid.='and docu="'.$xdocum.'" ';
                                   $sql_getid.='and ptoe="'.$xptoem.'"  ';
                                   $sql_getid.='and (numero*1)="'.$asoc['numer'].'" ';
                                   $sql_getid.='and enti like "'.substr($asoc['enti_hide'],0,10).'%" ';
                                   $sql_getid.='order by status, fecha desc ';
                                   $res_getid=msql_query($sql_getid,$link_data);
                                   $idnum_link=msql_result($res_getid,0,'idnum1');
                                   $value=str_pad((int)$value,$field_leng[$xcol],'0',STR_PAD_LEFT);
                                   
//                                    if($asoc['numer']*1==16)
//                                    {echo '<br>==>'.$sql_getid;}
                                   
                              }

                              if(empty($idnum_link))
                              {
//                                    $row->setAttribute("bgc-ulyellow","");
                              }
//                               echo '===='.$idnum_link;

                              if(!empty($idnum_link))
                              {
                                   $xptoe=$asoc['ptoem'];
                                   $col=$row->appendChild($domg->createElement($tcol));       

                                   $href='https://'.$_SERVER['SERVER_NAME'].'/';

                                   if(mb_stristr2($_SERVER['REQUEST_URI'],'index3.php'))
                                   {$href.='index3.php';}

                                   $href.='?scri=info_docu3';
                                   $href.='&prnt=1&docu='.$xdocum.'&idnum='.$idnum_link.'&formato=';
                                   $href.='&abon=1';
                                   $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                        $ref->setAttribute('href',$href);
                                        $ref->setAttribute('target','_blank');

                                   $crea_value=false;
                              }
                         }
                              
                    }

                    if(($field_name[$xcol]=='nume_fact' or $field_name[$xcol]=='nume_opro' or $field_name[$xcol]=='orden') and empty($edit))
                    {
                         
//                     if(!empty($asoc['numfac']) or !empty($asoc['numord']))
//                          if(!empty($asoc[$field_name[$xcol]]) )
                         {
                              $tabla_link2='';
                              $tabla_link2=$tabla_link;
                              if(substr($asoc['docu'],0,4)=='EB10'){$tabla_link2='vtas';}
                              if(substr($asoc['docu'],0,4)=='IB12'){$tabla_link2='vtas';}
                              if(substr($asoc['docu'],0,4)=='IB10'){$tabla_link2='comp';}
                              if(substr($asoc['docu'],0,4)=='EB12'){$tabla_link2='comp';}
                              if(substr($asoc['docu'],0,4)=='IB13'){$tabla_link2='inve';}
                              if(substr($asoc['docu'],0,4)=='EB19'){$tabla_link2='opro';}
                              if(substr($asoc['docu'],0,4)=='IB15'){$tabla_link2='comp';}
                              
//                               echo '**/*/'.$tabla_link2;

//                               if(!empty($tabla_link2))
                              {
     //                          $sql_getid='select idnum1,docu from '.$tabla_link.'1 where enti like "'.substr($asoc['enti'],0,10).'%" and numero='.$asoc['numfac'].' ';
//                               $sql_getid='select idnum1,docu,numero,fecha from '.$tabla_link2.'1 where enti like "'.substr($asoc['enti'],0,10).'%" and numero='.$asoc[$field_name[$xcol]].' ';
                              $sql_getid='select idnum1,docu,numero,fecha from '.$tabla_link2.'1 ';
                              $sql_getid.='where enti like "'.substr($asoc['enti'],0,10).'%" and numero*1="'.$asoc[$field_name[$xcol]].'" ';
                              $res_getid=msql_query($sql_getid,$link_data);
                              $idnum_link=msql_result($res_getid,0,'idnum1');
                              $docum_link=msql_result($res_getid,0,'docu');
                              $numer_link=msql_result($res_getid,0,'numero');
                              $fecha_link=msql_result($res_getid,0,'fecha');

                              $numer_link=str_pad($value, 9, "0", STR_PAD_LEFT);
                                   
//                               if(!empty($idnum_link))
                              {
                              $xptoe=$asoc['ptoem'];
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $href='';
                              $href='?scri=info_docu3&prnt=1';
                              $href.='&docu='.$docum_link.'&idnum='.$idnum_link.'&formato=';
                              $taga='a';     
                              if(empty($idnum_link)){$href='';$taga='span';}
                              if(empty($fecha_link)){$value.=' '; }
                                   
                              $ref=$col->appendChild($domg->createElement($taga,htmlspecialchars($value)));                           
                                   $ref->setAttribute('num',$numer_link);
                                   if(!empty($href))
                                   {
                                        $ref->setAttribute('href',$href);
                                        $ref->setAttribute('target','_blank');
                                   }
                                   if(empty($fecha_link))
                                   {
                                        $ref->setAttribute('bold','');
                                        $ref->setAttribute('red','');
                                   }

                              $crea_value=false;
                              }
                                   
                              }

                         }
                    }

                    if($field_name[$xcol]=='wsapp' and strlen(trim($asoc['wsapp']))>=9 and 1==2)
                    {
//                          if(!empty($idnum_link))
                         {
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $xwsapp=trim($asoc['wsapp']);
                         $xwsapp=substr($xwsapp,-10);     
                         $xwsapp=str_pad($xwsapp,10,'0',STR_PAD_LEFT);     
                         $href='';
                         $href='https://wa.me/';
                         $href.='593';
                         $href.=$xwsapp;
                              
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                              $ref->setAttribute('href',$href);
                              $ref->setAttribute('target','_blank');

                         $crea_value=false;
                         }
                    }

                    
                    
                    if($field_name[$xcol]=='st_ce')
                    {
                         
                    }


                    if($field_name[$xcol]=='nume_rete' and mb_stristr2('.vtresu.coresu',$info))
                    {
                       {
                         $col=$row->appendChild($domg->createElement($tcol));       
                          {
                              $href='https://'.$_SERVER['SERVER_NAME'].'/';
                              if(mb_stristr2($_SERVER['REQUEST_URI'],'index3.php'))
                              {$href.='index3.php';}
                              $href.='?scri=info_docu3';
                              $href.='&prnt=1';
                              if($info=='vtresu'){$href.='&docu=RCLI';}
                              if($info=='coresu'){$href.='&docu=RPRO';}
                              $href.='&idnum='.$asoc['idn_rete_hide'];
                          }
                            
                         $value=$value*1;
                         if(empty($value)){$value='';}
                            
                          
                          if($empr0['empr_rete']==1)  
                          if(empty($value) and $info=='coresu' and mb_stristr2('.FP10.FP03',$asoc['docu']) )
                          {
                              $href=''; 
                              $value='';
                               
//                               if(days_diff(date('Y-m-t',strtotime($asoc['fecha'])), date('Y-m-d'))<=5)
                              if($asoc['fecha']>=date('Y-m-01',strtotime('-28 days')))
                              {
                                   $href='https://'.$_SERVER['SERVER_NAME'].'/';

                                   if(mb_stristr2($_SERVER['REQUEST_URI'],'index3.php'))
                                   {$href.='index3.php';}

                                   $href.='?scri=regi_rete4';
                                   $href.='&docu=RPRO';
                                   $href.='&modu=retp';
                                   $href.='&fecha='.$asoc['fecha'];
                                   $rete4enti=$asoc['enti'];
                                   if(empty($rete4enti)){$rete4enti=$enti;}  
                                   $rete4enti=substr($rete4enti,0,10);  
                                   $href.='&enti='.$rete4enti.'001';
                                   $href.='&docum='.$asoc['docu_hide'];
                                   $href.='&ptoem='.$asoc['ptoe'];
                                   $href.='&numer='.$asoc['numero'];
                                   $value='Ret.';
//                                    $value='000';
                              
                              }
                               
                          }
                            
                          $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                               $ref->setAttribute('onclick',$onclick);
                               $ref->setAttribute('href',$href);
                               $ref->setAttribute('target','_blank');
                          $crea_value=false;
                       }
                         
                    }


                    if($field_name[$xcol]=='saldo' and mb_stristr2('.vtresu.coresu',$info))
                    {
                       {
                         $col=$row->appendChild($domg->createElement($tcol));       
//                           {
// //                               $href='https://'.$_SERVER['SERVER_NAME'].'/';
// //                               if(mb_stristr2($_SERVER['REQUEST_URI'],'index3.php'))
// //                               {$href.='index3.php';}
// //                               $href.='?scri=info_docu3';
// //                               $href.='&prnt=1';
// //                               if($info=='vtresu')
// //                               {$href.='&docu=RCLI';}
// //                               if($info=='coresu')
// //                               {$href.='&docu=RPRO';}
// //                               $href.='&idnum='.$asoc['idn_rete_hide'];
//                           }
                            
//                          $value=$value*1;
//                          if(empty($value)){$value='';}
                            
                          
//                           if($empr0['empr_rete']==1)  
//                           if(empty($value) and $info=='coresu' and mb_stristr2('.FP10.FP03',$asoc['docu']) )
//                           {
//                               $href=''; 
//                               $value='';
                               
// //                               if(days_diff(date('Y-m-t',strtotime($asoc['fecha'])), date('Y-m-d'))<=5)
//                               if($asoc['fecha']>=date('Y-m-01',strtotime('-28 days')))
//                               {
//                                    $href='https://'.$_SERVER['SERVER_NAME'].'/';

//                                    if(mb_stristr2($_SERVER['REQUEST_URI'],'index3.php'))
//                                    {$href.='index3.php';}

//                                    $href.='?scri=regi_rete4';
//                                    $href.='&docu=RPRO';
//                                    $href.='&modu=retp';
//                                    $href.='&fecha='.$asoc['fecha'];
//                                    $rete4enti=$asoc['enti'];
//                                    if(empty($rete4enti)){$rete4enti=$enti;}  
//                                    $rete4enti=substr($rete4enti,0,10);  
//                                    $href.='&enti='.$rete4enti.'001';
//                                    $href.='&docum='.$asoc['docu_hide'];
//                                    $href.='&ptoem='.$asoc['ptoe'];
//                                    $href.='&numer='.$asoc['numero'];
//                                    $value='Ret.';
// //                                    $value='000';
                              
//                               }
                               
//                           }
                          
                          $value=0;  
                          $value=sal_docu($asoc['docu'],$asoc['idnum1_hide']); 
                          $value=number_format($value,2);
                          $ref=$col->appendChild($domg->createElement('span',htmlspecialchars($value)));                           
//                                $ref->setAttribute('onclick',$onclick);
//                                $ref->setAttribute('href',$href);
//                                $ref->setAttribute('target','_blank');
                          $crea_value=false;
                       }
                         
                    }

                    
                    
                    if($field_name[$xcol]=='reten' and mb_stristr2('.cpresu.ccresu',$info))
                    {
//                        if(abs($asoc['saldo'])>$saldo0)
                       {
                         $col=$row->appendChild($domg->createElement($tcol));       

                         $href='https://'.$_SERVER['SERVER_NAME'].'/';

                         if(mb_stristr2($_SERVER['REQUEST_URI'],'index3.php'))
                         {$href.='index3.php';}

                         $href.='?scri=regi_rete4';
                         $href.='&docu=RPRO';
                         $href.='&modu=retp';
                         $href.='&fecha='.$asoc['fecha'];
                         $rete4enti=$asoc['enti'];
                         if(empty($rete4enti)){$rete4enti=$enti;}  
                         $rete4enti=substr($rete4enti,0,10);  
                         $href.='&enti='.$rete4enti.'001';
                         $href.='&docum='.$asoc['docu_hide'];
                         $href.='&ptoem='.$asoc['ptoe'];
                         $href.='&numer='.$asoc['numero'];
                            
                          if($value>0)
                          {
                              $href='https://'.$_SERVER['SERVER_NAME'].'/';
                              if(mb_stristr2($_SERVER['REQUEST_URI'],'index3.php'))
                              {$href.='index3.php';}
                              $href.='?scri=info_docu3';
                              $href.='&prnt=1';
                              if($info=='ccresu')
                              {$href.='&docu=RCLI';}
                              if($info=='cpresu')
                              {$href.='&docu=RPRO';}
                              $href.='&idnum='.$asoc['idreten_hide'];
                          }
                            
                            
                          $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                               $ref->setAttribute('onclick',$onclick);
                               $ref->setAttribute('href',$href);
                               $ref->setAttribute('target','_blank');
                          $crea_value=false;
                       }

                    }

//                     echo '====='.$field_name[$xcol];

                    if($field_name[$xcol]=='trf' and mb_stristr2('.otdet2',$info))
                    {
                       if(empty($value)){$value='A';}

                       if($value!='T')
                       {
                          $col=$row->appendChild($domg->createElement($tcol));       
                          $href='';
                          $href.='https://'.$cfg_empr.'.'.$domain.'/?scri=regi_maes3';
                          $href.='&modu=item';
                          $href.='&codigo='.$asoc['item_hide'].'';
                            
                          $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                          $ref->setAttribute('onclick',$onclick);
                          $ref->setAttribute('href',$href);
                          $ref->setAttribute('target','_blank');
                          $crea_value=false;
                       }

                       if($value=='T')
                       {
                          $col=$row->appendChild($domg->createElement($tcol));       
                          $href='';
                          $href.='https://'.$cfg_empr.'.'.$domain.'/?scri=info_maes3';
                          $href.='&modu=tmpr';
                          $href.='&info=mttmpr';
                          $href.='&edit=1';
                          $href.='&item='.$asoc['item_hide'].'';
                            
                          $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                          $ref->setAttribute('onclick',$onclick);
                          $ref->setAttribute('href',$href);
                          $ref->setAttribute('target','_blank');
                          $crea_value=false;
                       }

                    }

                    
                    
                    if($field_name[$xcol]=='asigna')
                    {
                       if($info=='rvresu')
                       {
//                           $xptoe=$asoc['ptoe'];
                          $passkey='';
                          $passkey.=$asoc['cong_hide'];  
                          $passkey.=$asoc['trty_hide'];  
                          $passkey.=$asoc['bloq_hide'];  
                          $passkey.=date('Y-m-d');
                            
                          $passkey=md5($passkey);
                            
                          $col=$row->appendChild($domg->createElement($tcol));       
                          $href='';
                          $href.='https://'.$cfg_empr.'.'.$domain.'/?scri=regi_jwrv3';
                          $href.='&cong='.$asoc['cong_hide'];
                          $href.='&trty='.$asoc['trty_hide'];
                          $href.='&bloq='.$asoc['bloq_hide'];
                          $href.='&passkey='.$passkey;
                            
                          $onclick='{send_trty("'.$cong0['cong_descri'].'","'.$asoc['territorio'].'","'.$asoc['bl_mz'].'","'.$href.'");}';  
                          $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                          $ref->setAttribute('onclick',$onclick);
//                           $ref->setAttribute('href',$href);
//                           $ref->setAttribute('target','_blank');
                          $crea_value=false;
                       }

                    }

                    if($field_name[$xcol]=='color')
                    {
                       if(substr($value,0,1)=='#')
                       {
                         $col=$row->appendChild($domg->createElement($tcol));
                         $col->setAttribute("style","background-color:".$value."; ");
                         $crea_value=false;
                       }
                    }
                    
                    
                //  Softball
                {
                   if($field_name[$xcol]=='line1' or $field_name[$xcol]=='line2')
                       {
                          $sql_getab='select docu_tabla from docu0 where docu_codigo="soft"';
                          $res_getab=msql_query($sql_getab,$link_data);
                          $tabla_link=strtolower(msql_result($res_getab,0,'docu_tabla'));
                          $idnum_link=$asoc['line1'];
                          $value=str_pad((int)$value,$field_leng[$xcol],'0',STR_PAD_LEFT);

                          $sql_getIn = 'select * from '.$tabla_link.'1 where status!="X" and idnum1= '.$asoc['line1'];
                          $res_getIn = msql_query($sql_getIn,$link_data);
                          $liga = msql_result($res_getIn,0,'liga');
                          $torn = msql_result($res_getIn,0,'torn');
                          $jornada = msql_result($res_getIn,0,'jornada');
                          $tipo = msql_result($res_getIn,0,'tipo');
                          if ($field_name[$xcol]=='line1')
                              $team1 = msql_result($res_getIn,0,'team1');
                          else
                              $team1 = msql_result($res_getIn,0,'team2');
                     
                          if(!empty($idnum_link))
                              {
                                  $xptoe=$asoc['ptoe'];
                                  $col=$row->appendChild($domg->createElement($tcol));       
                                  $href='';
//                                   $href='https://'.$cfg_empr.'.vcrxol.com/?scri=regi_liup3.php&modu=LIUP&idsoft='.$idnum_link.'&team='.$team1;
                                  $href='https://'.$cfg_empr.'.'.$domain.'/?scri=regi_liup3.php&modu=LIUP&idsoft='.$idnum_link.'&team='.$team1;
                                   
                                  $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                  $ref->setAttribute('href',$href);
                                  $ref->setAttribute('target','_blank');

                                  $crea_value=false;
                              }

                       }

                   if($field_name[$xcol]=='juego')
                      {
                         $sql_getab='select docu_tabla from docu0 where docu_codigo="soft"';
                         $res_getab=msql_query($sql_getab,$link_data);
                         $tabla_link=strtolower(msql_result($res_getab,0,'docu_tabla'));
                         $idnum_link=$asoc['juego'];
                         $value=str_pad((int)$value,$field_leng[$xcol],'0',STR_PAD_LEFT);

                         if(!empty($idnum_link))
                            {
                               $xptoe=$asoc['ptoe'];
                               $col=$row->appendChild($domg->createElement($tcol));       
                               $href='';
//                                $href='https://'.$cfg_empr.'.vcrxol.com/?scri=regi_soft3.php&modu=SOFT&idnum='.$idnum_link;
                               $href='https://'.$cfg_empr.'.'.$domain.'/?scri=regi_soft3.php&modu=SOFT&idnum='.$idnum_link;
                                   
                               $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                               $ref->setAttribute('href',$href);
                               $ref->setAttribute('target','_blank');

                               $crea_value=false;
                            }

                      }
                    
                }

                    
                    
                    
//                     if($field_name[$xcol]=='idate')
                    if(mb_stristr2('.idate.udate',$field_name[$xcol]))
                    {    
                         $value1=substr($value,0,8);
                         $value2=substr($value,9,8);
                         $value=$value1;
                    }

                    if($field_name[$xcol]=='descripcion' and $modu=='pcnt')
                    {$value=ucwords2(strtolower($value));}

                    if(mb_stristr2('.nombre.raza.especie.vendedor.vndd.recaudador.rcdd.propietario.usuario.actividad.persona.enti',$field_name[$xcol]))
                    {$value=ucwords2(strtolower($value));}
                    
                    if(mb_stristr2('.cliente.proveedor',$field_name[$xcol]) and substr($asoc['enti'],2,1)<='5')
                    {$value=ucwords2(strtolower($value));}
                    if(mb_stristr2('.cliente.proveedor',$field_name[$xcol]) and substr($asoc['enti'],2,1)>'5')
                    {$value=strtoupper($value);}
                    
                    if(mb_stristr2('.enti_descri',$field_name[$xcol]))
                    {
                         if(substr($asoc['enti'],1)!='9'){$value=ucwords2($value);}
                    }
                    

                    if(mb_stristr2('.descripcion',$field_name[$xcol]) and substr($asoc['codigo'],2,1)<='5' and mb_stristr2('.enti.clie.prov.pcnt.vndd.rcdd',$modu))
                    {$value=ucwords2(strtolower($value));}
                    if(mb_stristr2('.descripcion',$field_name[$xcol]) and substr($asoc['codigo'],2,1)>'5' and mb_stristr2('.enti.clie.prov.pcnt.vndd.rcdd',$modu))
                    {$value=strtoupper($value);}
                    
                    if(mb_stristr2('.nom_comercial',$field_name[$xcol]))
                    {$value=strtoupper($value);}
                    
                    $value=siglas($value);
                    
                    if($field_name[$xcol]=='ptoe' or $field_name[$xcol]=='ptoem' or $field_name[$xcol]=='pto_emi')
                    {$value=substr($value,0,3).'.'.substr($value,3,3);}
//                     {$value=substr($value,0,3).'-'.substr($value,3,3);}

                    // filtro x enlace
                    $href2='';
                    $openinfo='';
                    
                    // enlaces
                    
//                     if($edit==0)
                    if($edit!=1)
                    {
                    if(mb_stristr2('.enti.pcnt',$modu))
                    {
                         
                         if($field_name[$xcol]=='nombre' and ($empr0['empr_clinica'] or $empr0['empr_veterinaria']) )
                         {
                              $href='';
                              $href.='?scri=regi_hcli3';
                              $href.='&modu=hcli';
                              $href.='&docu=hc10';
                              $href.='&enti='.$asoc['codigo'];

                              $col=$row->appendChild($domg->createElement($tcol));       

                              $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
                                  $ref->setAttribute('target','_blank');
                              $crea_value=false;
                         }
                         
                    }
                         
                    if($blog_info==1)
                    {
                         if(mb_stristr2('.file',$field_name[$xcol]))
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $href='';
                              $href='info/'.$value;
                              $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('target','_blank');
                              $crea_value=false;
                              
                         }
                    }
                         
                    if(mb_stristr2('.vtas.comp.clie.prov.guia.cont',$modu))
                    {
                         
                         // 2024-11-07 ttssss
//                          if(mb_stristr2('.docu.enti.item.ctas.vndd.zsub.lsub.csub.cair..plvh.codt.cntn..pcnt.',$field_name[$xcol]))
                         if(mb_stristr2('.docu.enti.item.ctXas.vndd.rcdd.zsub.lsub.csub.cair..plvh.codt.cntn..pcnt.',$field_name[$xcol]))
                         {$href2='&'.$field_name[$xcol].'='.$asoc[$field_name[$xcol]];}
                         
                         if(!empty($href2)){$openinfo=substr($modu,0,2).'resu';}

                         if(substr($info,2,4)==$field_name[$xcol] and $edit==0)
                         {$openinfo=substr($modu,0,2).'deta';}
                         
                         if($field_name[$xcol]=='fecha' and $edit==0)
                         {$openinfo=substr($modu,0,2).'resu'; $href2='&fecha1='.$asoc['fecha'].'&fecha2='.$asoc['fecha'];}

                         if($field_name[$xcol]=='mXes')
                         {$openinfo=substr($modu,0,2).'xfec'; $href2='&fecha1='.$asoc['mes'].'-01'.'&fecha2='.$asoc['mes'].'-31';}
                         
                         if($field_name[$xcol]=='plvh' and $asoc['st']!='O' and substr($info,-4)=='res1' )
                         {
                              
                              $href2='';
                              $href2.='';
                              $href2.='&scri='.'regi_grge3';
                              $href2.='&docu='.$asoc['docu'];
                              $href2.='&idnum1='.$asoc['idnum1_hide'];
                              $href2.='&xorden='.$asoc['plvh'];
                         }
                         
                         if(substr($info,-4)=='det2'){$openinfo='';}
                         
//                          echo '===='.$openinfo;
                         if(!empty($openinfo))
                         {
                              if($modu=='cont'){$openinfo='tt'.substr($openinfo,2);}

                              $col=$row->appendChild($domg->createElement($tcol));       
                              $href='';
                              $href='?scri=info_modu3&modu='.$modu.'&info='.$openinfo.'&fecha1='.$fecha1.'&fecha2='.$fecha2;
//                               if(!empty($ctas)){$href.='&ctas='.$ctas;}
                              if(!empty($enti)){$href.='&enti='.$enti;}
                              if(!empty($item)){$href.='&item='.$item;}
                              if(!empty($zsub)){$href.='&zsub='.$zsub;}
                              if(!empty($lsub)){$href.='&lsub='.$lsub;}
                              if(!empty($vndd)){$href.='&vndd='.$vndd;}
                              if(!empty($rcdd)){$href.='&rcdd='.$rcdd;}
                              if(!empty($ptov)){$href.='&ptov='.$ptov;}
                              $href.=$href2;
                              $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
                                  $ref->setAttribute('target','_blank');
                              $crea_value=false;
                         }
                         
                    }

                    if(mb_stristr2('.cxco.cxpa',$modu))
                    if(mb_stristr2('.enti.nombre.vndd.rcdd.salXdo.anticipo.fecha.mes',$field_name[$xcol]))
                    {
                         $fecha11=$fecha1;
                         if(!empty($asoc['u_movi']) and $asoc['u_movi']<$fecha11){$fecha11=date('Y-m-01',strtotime($asoc['u_movi']));}
                         
                         if($info=='ccsald' and $field_name[$xcol]=='enti'){$openinfo='ccmovi'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpsald' and $field_name[$xcol]=='enti'){$openinfo='cpmovi'; $href2='&enti='.$asoc['enti'];}
                         
                         if($info=='ccsald' and $field_name[$xcol]=='nombre'){$openinfo='ccresu'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpsald' and $field_name[$xcol]=='nombre'){$openinfo='cpresu'; $href2='&enti='.$asoc['enti'];}
                         
                         if($info=='ccsald' and $field_name[$xcol]=='saldo'){$openinfo='ccmovi'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpsald' and $field_name[$xcol]=='saldo'){$openinfo='cpmovi'; $href2='&enti='.$asoc['enti'];}
                         
                         if($info=='ccsald' and $field_name[$xcol]=='anticipo'){$openinfo='ccanti'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpsald' and $field_name[$xcol]=='anticipo'){$openinfo='cpanti'; $href2='&enti='.$asoc['enti'];}
                         
                         ///////////////////
                         if($info=='ccddcc' and $field_name[$xcol]=='enti'){$openinfo='ccmovi'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpddcc' and $field_name[$xcol]=='enti'){$openinfo='cpmovi'; $href2='&enti='.$asoc['enti'];}

                         if($info=='ccddcc' and $field_name[$xcol]=='nombre'){$openinfo='ccresu'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpddcc' and $field_name[$xcol]=='nombre'){$openinfo='cpresu'; $href2='&enti='.$asoc['enti'];}
                         
                         if($info=='ccddcc' and $field_name[$xcol]=='saldo'){$openinfo='ccmovi'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpddcc' and $field_name[$xcol]=='saldo'){$openinfo='cpmovi'; $href2='&enti='.$asoc['enti'];}
                         
                         if($info=='ccddcc' and $field_name[$xcol]=='anticipo'){$openinfo='ccanti'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpddcc' and $field_name[$xcol]=='anticipo'){$openinfo='cpanti'; $href2='&enti='.$asoc['enti'];}

                         ///////////////////
                         if($info=='ccdcdd' and $field_name[$xcol]=='fecha'){$openinfo='ccddcc'; $href2='&fecha1='.$asoc['fecha'].''.'&fecha2='.$asoc['fecha'].'';}
                         if($info=='cpdcdd' and $field_name[$xcol]=='fecha'){$openinfo='cpddcc'; $href2='&fecha1='.$asoc['fecha'].''.'&fecha2='.$asoc['fecha'].'';}
                         
                         if($info=='ccdcmm' and $field_name[$xcol]=='mes'){$openinfo='ccdcdd'; $href2='&fecha1='.$asoc['mes'].'-01'.'&fecha2='.$asoc['mes'].'-31';}
                         if($info=='cpdcmm' and $field_name[$xcol]=='mes'){$openinfo='cpdcdd'; $href2='&fecha1='.$asoc['mes'].'-01'.'&fecha2='.$asoc['mes'].'-31';}
                         
                         ///////////////////
                         if($info=='ccresu' and $field_name[$xcol]=='enti'){$openinfo='ccresu'; $href2='&enti='.$asoc['enti'];}
                         if($info=='cpresu' and $field_name[$xcol]=='enti'){$openinfo='cpresu'; $href2='&enti='.$asoc['enti'];}
                         
                         if($info=='ccresu' and $field_name[$xcol]=='vndd'){$openinfo='ccresu'; $href2='&vndd='.$asoc['vndd'];}
                         if($info=='ccresu' and $field_name[$xcol]=='rcdd'){$openinfo='ccresu'; $href2='&rcdd='.$asoc['rcdd'];}
                         
                         if(!empty($openinfo))
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $href='';
                              $href='?scri=info_modu3&modu='.$modu.'&info='.$openinfo.'&fecha1='.$fecha11.'&fecha2='.$fecha2.'&tsaldo=69';
                              if(!empty($enti)){$href.='&enti='.$enti;}
                              if(!empty($vndd)){$href.='&vndd='.$vndd;}
                              if(!empty($rcdd)){$href.='&rcdd='.$rcdd;}
                              if(!empty($zsub)){$href.='&zsub='.$zsub;}
                              if(!empty($tpro)){$href.='&tpro='.$tpro;}
                              $href.=$href2;
                              $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('title','Movimiento');
                                   if($openinfo=='ccresu' or $openinfo=='cpresu')
                                   $ref->setAttribute('title','Resumen');
                                        
                                   $ref->setAttribute('target','_blank');
                                   if(mb_stristr2('.saldo.anticipo',$field_name[$xcol]) and abs($value)<$saldo0)
                                   {
                                        $ref->setAttribute('red',"");
                                        if($value<0)
                                        {$ref->setAttribute('hide',"");}
                                   }
                              $crea_value=false;
                         }
                    }
                         
                    if(mb_stristr2('.inve',$modu) and 1==2)
                    if(mb_stristr2('.item.lote.',$field_name[$xcol]) and empty($zhidehref))
                    {
                         $openinfo='iikrdx';
                         $fecha11=$fecha1;
                         if(!empty($asoc['u_movi']) and $asoc['u_movi']<$fecha11){$fecha11=date('Y-m-01',strtotime($asoc['u_movi'])); }
                         
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $href='';
                         $href='?scri=info_modu3&modu='.$modu.'&info='.$openinfo.'&fecha1='.$fecha11.'&fecha2='.$fecha2.'&cost='.$cost;
                         $href.='&item='.$asoc['item'];
                         $href.='&bode='.$bode;
                         if($field_name[$xcol]=='lote')
                         {$href.='&lote='.$asoc['lote'];}
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                              $ref->setAttribute('href',$href);
                              $ref->setAttribute('target','_blank');

                         $crea_value=false;
                    }

                    if(mb_stristr2('.inve',$modu) and 1==2)
                    if(mb_stristr2('.bode',$field_name[$xcol]) and $info!='iiblog')
                    {
                         $openinfo='iiblog';
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $href='';
                         $href='?scri=info_modu3&modu='.$modu.'&info='.$openinfo.'&fecha1='.$fecha1.'&fecha2='.$fecha2.'&cost='.$cost;
                         $href.='&item='.$asoc['bode'];
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                              $ref->setAttribute('href',$href);
                              $ref->setAttribute('target','_blank');

                         $crea_value=false;
                    }

                    if(mb_stristr2('.inve',$modu))
                    if(mb_stristr2('.item.lote.bode.fecha.mes.',$field_name[$xcol]))
                    {
                         $fecha11=$fecha1;
                         if(!empty($asoc['u_movi']) and $asoc['u_movi']<$fecha11){$fecha11=date('Y-m-01',strtotime($asoc['u_movi']));}

                         if($field_name[$xcol]=='bode' and $info=='iiblog'){$openinfo='iiblog'; $href2='&fecha1='.$fecha1.'&fecha2='.$fecha2;}
                         if($field_name[$xcol]=='mes' and $info=='iidcmm'){$openinfo='iidcdd'; $href2='&fecha1='.$asoc['mes'].'-01'.'&fecha2='.$asoc['mes'].'-31';}
                         if($field_name[$xcol]=='item'){$openinfo='iikrdx'; $href2='&fecha1='.$fecha11.'&fecha2='.$fecha2.'&item='.$asoc['item'];}
                         if($field_name[$xcol]=='lote'){$openinfo='iikrdx'; $href2='&fecha1='.$fecha11.'&fecha2='.$fecha2.'&lote='.$asoc['lote'];}
                         if($field_name[$xcol]=='bode'){$openinfo='iikrdx'; $href2='&fecha1='.$fecha11.'&fecha2='.$fecha2.'&bode='.$asoc['bode'];}
                         
                         if(!empty($openinfo))
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $href='';
                              $href='?scri=info_modu3&modu='.$modu.'&info='.$openinfo.'&cost='.$cost.'&tsaldo=69';
                              if(!empty($lsub)){$href.='&lsub='.$lsub;}
                              if(!empty($item)){$href.='&item='.$item;}
                              if(!empty($bode)){$href.='&bode='.$bode;}
                              if(!empty($lote)){$href.='&lote='.$lote;}
                              $href.=$href2;
                              $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
//                                    $ref->setAttribute('title','Movimiento');
//                                    if($openinfo=='ccresu' or $openinfo=='cpresu')
//                                    $ref->setAttribute('title','Resumen');
                                        
                                   $ref->setAttribute('target','_blank');
                              $crea_value=false;
                         }
                    }
                    
                         
                         
                         
                    if($modu=='cont')
                    if($field_name[$xcol]=='ctas' or $field_name[$xcol]=='mes')
                    {
                         $openinfo='';
                         $href='';
                         $col=$row->appendChild($domg->createElement($tcol));       
                         if($field_name[$xcol]=='ctas'){$openinfo='ttmovi'; $href2='&fecha1='.$fecha1.'&fecha2='.$fecha2.'&ctas='.$asoc['ctas'];}
                         if($info=='ttssdd' and $field_name[$xcol]=='ctas'){$openinfo='ttmovi'; $href2='&fecha1='.$asoc['fecha'].'&fecha2='.$asoc['fecha'].'&ctas='.$asoc['ctas'];}
                         if($info=='ttssdd' and $field_name[$xcol]=='fecha'){$openinfo='ttmovi'; $href2='&fecha1='.$asoc['fecha'].'&fecha2='.$asoc['fecha'].'&ctas='.$asoc['ctas'];}
                         if($info=='ttssmm' and $field_name[$xcol]=='ctas'){$openinfo='ttmovi'; $href2='&fecha1='.$asoc['mes'].'-01'.'&fecha2='.$asoc['mes'].'-31'.'&ctas='.$asoc['ctas'];}
                         if($info=='ttssmm' and $field_name[$xcol]=='mes'){$openinfo='ttssdd'; $href2='&fecha1='.$asoc['mes'].'-01'.'&fecha2='.$asoc['mes'].'-31'.'&ctas='.$asoc['ctas'];}
                         
                         if(!empty($openinfo))
                         {
                              $href='';
                              $href='?scri=info_modu3&modu='.$modu.'&info='.$openinfo;
//                               if(!empty($ctas)){$href.='&ctas='.$ctas;}
                              if(!empty($csub)){$href.='&csub='.$csub;}
                              if(!empty($nivel)){$href.='&nivel='.$nivel;}
                              $href.=$href2;
                              $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('target','_blank');
                              $crea_value=false;
                         }
                    }
                    
                    if($field_name[$xcol]=='codigo')     
                    {
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $href='';
                         $href='?scri=regi_maes3&modu='.$modu.'&codigo='.$asoc['codigo'].'';
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                              $ref->setAttribute('href',$href);
                              $ref->setAttribute('target','_blank');
                         $crea_value=false;
                    }
                    
                    if($field_name[$xcol]=='item' and $info=='vtrpm1')
                    {
//                          $col=$row->appendChild($domg->createElement($tcol));       
//                          $href='';
//                          $href='?scri=regi_maes3&modu='.$field_name[$xcol].'&codigo='.$asoc[$field_name[$xcol]].'';
//                          $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
//                               $ref->setAttribute('href',$href);
//                               $ref->setAttribute('target','_blank');
//                          $crea_value=false;
                    }
                    
                    if($field_name[$xcol]=='producto' and empty($xondblclick))     
                    {
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $href='';
                         $href='?scri=regi_maes3&modu=item&codigo='.$asoc['item'].$asoc['item_hide'].'';
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                              $ref->setAttribute('href',$href);
                              $ref->setAttribute('target','_blank');
                         $crea_value=false;
                    }
                    
                    if(substr($field_name[$xcol],-2)=='_U' and $modu=='inve')
                    {
                         $openinfo='iikrdx';
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $href='';
                         $href='?scri=info_modu3&modu='.$modu.'&info='.$openinfo.'&fecha1='.$fecha1.'&fecha2='.$fecha2;
                         $href.='&item='.$asoc['item'].'&bode='.substr($field_name[$xcol],0,strpos($field_name[$xcol],'_')).'&cost='.$cost.'&lote='.$asoc['lote'];
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                              $ref->setAttribute('href',$href);
                              $ref->setAttribute('target','_blank');

                         $crea_value=false;
                    }

                    if($field_name[$xcol]=='pin')     
                    {
//                          https://orel.vcrxol.com/index3.php?scri=usrt_confirm0&usrt=109&email=ventas@orellanaelec.com&pin=674415
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $href='';
                         $href='?scri=usrt_confirm0'.'&usrt='.$asoc['codigo'].'&email='.$asoc['e_mail'].'&pin='.$asoc['pin'];
                         $ref=$col->appendChild($domg->createElement('a',htmlspecialchars($value)));                           
                              $ref->setAttribute('href',$href);
                              $ref->setAttribute('target','_blank');
                         $crea_value=false;
                    }
                         
                    }
                    
                    
                    // calculados
                    {
                    
                    if($field_name[$xcol]=='e_bode')
                    {
                         foreach ($ebode as $key1=>$val1)
                         {
                              foreach($val1 as $key2=>$val2)
                              if($key2=='numfac' and $val2==$asoc['numero']){$value=$val1['ebode']; break 2;}
                         }
                         if($value<1){$value='--';}
                         if($value>=1){$value=number_format($value,$item_duni);}
                         
                         $col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));       
                         $crea_value=false;
                    }
                    
                    if($field_name[$xcol]=='pedido')
                    {
                         foreach ($pclie as $key1=>$val1)
                         {
                              foreach($val1 as $key2=>$val2)
                              if($key2=='item' and $val2==$asoc['item']){$value=$val1['pcli']; break;}
                         }
                         if($value<1){$value='--';}
                         if($value>=1){$value=number_format($value,$item_duni);}
                         
                         $col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));       
                         $crea_value=false;
                    }

                    
                    if($field_name[$xcol]=='vcp' and 1==1)
                    {
                         $value=0;
                         if(count($sal_inve)>0)
                         {
                              foreach ($sal_inve as $key1=>$val1)
                              {
                                   foreach($val1 as $key2=>$val2)
                                   if($key2=='item' and $val2==$asoc['item']){$value=$val1['c_pro_$']; break;}
                              }
                              $value=porc_varia($value,$asoc['c_pro_$']);
                              if(abs($value)<0.01){$value='--';}
                              $value=(int)$value;
                              if(abs($value)<1){$value='--';}
                              else{$value=number_format($value,0);}
                         }
                         
                         $col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));       
                         $crea_value=false;
                    }
                    
                    if($field_name[$xcol]=='r_saldo')
                    {
                         
                         $value=$asoc['saldo']/$tsuma[$xcol-1]*100;
                         $value=number_format($value,2);
                         
                         $col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));       
                         $crea_value=false;
                    }
                         
                    }
                    
                    
//                          echo '<br>*/*/*'.$asoc['st_ce'];
//                          echo '<br>*/*/*'.$asoc['autornum_hide'];
                    $atrz_ok=0;
                    if(mb_stristr2($asoc['st_ce'],'AUT')){$atrz_ok=1;}

                    
                    // editables
//                     if($edit>=1)
                    {
                    
                      
                    if(mb_stristr2('.resu.',substr($info,2,4)) and $edit>=1 and date('Y-m-d')<=date('Y-m-d',strtotime($asoc['f_cobro'].'+30 days')))
                    {
                         if(($head_name[$xcol]=='f_cobro' and $asoc['docu']=='ICH1'))
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                                   $zvalue=$value;
//                                    $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                                   $ztype='date';
                                   $zmin=date('Y-m-d',strtotime($value.'-7 days'));
                                   $zmax=date('Y-m-d',strtotime($value.'+7 days'));
                              
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
//                                    $zsaved=$asoc['iddet_hide'];
                              
                                   if($head_name[$xcol]=='f_cobro')
                                   {
                                        $zmin=$asoc['fecha'];
                                        $zmax=date('Y-m-t',strtotime($value.'+2 month'));
                                        $zsavef='fcobro';
                                   }
                              
                              
                                   include('ele_input.php');
                              $crea_value=false;
                         }

                         
                    }
                         
//                         echo '===='.$edit; 
                    if(mb_stristr2('.resu.cuxc',substr($info,2,4)) and $edit>=1 and $asoc['idate']>=$fecha_edit)
                    {
                         if($atrz_ok==0)
                         if($head_name[$xcol]=='fecha' )
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                                   $zvalue=$value;
//                                    $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                                   $ztype='date';
                                   $zmin=date('Y-m-d',strtotime($value.'-7 days'));
                                   $zmax=date('Y-m-d',strtotime($value.'+7 days'));
                              
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
//                                    $zsaved=$asoc['iddet_hide'];
                              
                                   if($head_name[$xcol]=='f_cobro')
                                   {
                                        $zmin=$asoc['fecha'];
                                        $zmax=date('Y-m-t',strtotime($value.'+2 month'));
                                        $zsavef='fcobro';
                                   }
                              
                              
                                   include('ele_input.php');
                              $crea_value=false;
                         }

                         if($head_name[$xcol]=='placa' and $atrz_ok==0)
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                              $ztabla='plvh';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
//                                    $zsaved=$asoc['iddet_hide'];
                                   include('ele_input.php');
                              $crea_value=false;
                         }

                         if($head_name[$xcol]=='codt' and $atrz_ok==0)
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                              $ztabla='enti';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
//                                    $zsaved=$asoc['iddet_hide'];
                                   include('ele_input.php');
                              $crea_value=false;
                         }

                         if($head_name[$xcol]=='vndd' )
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
//                                    $zvalue=$value;
                                   $zvalue=$asoc['vndd_hide'];
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $ztabla=$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu;
                                   $zsavef=$head_name[$xcol];
//                                    $zsavef='vndd';
                                   $zsavei=$asoc['idnum1_hide'];
                                   include('ele_input.php');
                              $crea_value=false;
                         }
                         
                         
                         
                         if($head_name[$xcol]=='fpag' or $head_name[$xcol]=='suco')
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $ztabla=$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
//                                    $zsaved=$asoc['iddet_hide'];
                                   include('ele_input.php');
                              $crea_value=false;
                         }
                         
                         if($head_name[$xcol]=='nume_impor')
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                              $zlist='dlimpo';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef='impor';
                                   $zsavei=$asoc['idnum1_hide'];
                                   include('ele_input.php');
                              $crea_value=false;
                         }
                         
                         if($head_name[$xcol]=='fp')
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $ztabla='fpag';
                              $zlist='dl_fpag';
                              $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef='fpag';
                                   $zsavei=$asoc['idnum1_hide'];
                                   include('ele_input.php');
                              $crea_value=false;
                         }
                         
                         
                         if($head_name[$xcol]=='sc')
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $ztabla='suco';
                              $zlist='dl_suco';
                              $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef='suco';
                                   $zsavei=$asoc['idnum1_hide'];
                                   include('ele_input.php');
                              $crea_value=false;
                         }
                         
                         if($asoc['autornum_hide'] =='')
                         if($head_name[$xcol]=='atrz')
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
//                               $ztabla='atrz';
                              $zlist='dlatrz';
                              $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef='atrz';
                                   $zsavei=$asoc['idnum1_hide'];
                                   include('ele_input.php');
                              $crea_value=false;
                         }

                         
                         if($head_name[$xcol]=='c_ext' or $head_name[$xcol]=='seguro' or $head_name[$xcol]=='flete' or $head_name[$xcol]=='d_clX')
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                              
                              $zclass='numeric-dec';
                              $zmin=0.00;
                              $zmax=9999.99;
                              
                                   $zvalue=$value;
                                   $zvalue=str_replace(',','',$zvalue);
//                                    $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu;
                                   if($head_name[$xcol]=='c_ext'){$zsavef='costoe1';}
                                   if($head_name[$xcol]=='seguro'){$zsavef='seguro1';}
                                   if($head_name[$xcol]=='flete'){$zsavef='flete1';}
                                   if($head_name[$xcol]=='d_clX'){$zsavef='costol1dX';}
                                        
                                   $zsavei=$asoc['idnum1_hide'];
//                                    $zoptions='1,Uni.;2,Val.;3,Kg.;';
//                                    $zexact=1;
                                   include('ele_input.php');
                              $crea_value=false;
                         }
                         
                         
                         
                         if($head_name[$xcol]=='d_ce' or $head_name[$xcol]=='d_sg' or $head_name[$xcol]=='d_fl' or $head_name[$xcol]=='d_cl')
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                                   $zvalue=$value;
//                                    $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu;
                                   if($head_name[$xcol]=='d_ce'){$zsavef='costoe1d';}
                                   if($head_name[$xcol]=='d_sg'){$zsavef='seguro1d';}
                                   if($head_name[$xcol]=='d_fl'){$zsavef='flete1d';}
                                   if($head_name[$xcol]=='d_cl'){$zsavef='costol1d';}
                                        
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zoptions='1,Uni.;2,Val.;3,Kg.;';
                                   $zexact=1;
                                   include('ele_select.php');
                              $crea_value=false;
                         }
                         
//                          if($head_name[$xcol]=='factu' or $head_name[$xcol]=='orden' or $head_name[$xcol]=='impor')
//                          echo ' === '.$head_name[$xcol];
                         if(
                              ($head_name[$xcol]=='factu' and ($asoc['docu']=='EB10' or $asoc['docu']=='IB10'))
                            or($head_name[$xcol]=='numfac' and ($asoc['docu']=='EB10' or $asoc['docu']=='IB10'))
                            or($head_name[$xcol]=='numfac' and ($asoc['docu']=='EB10' or $asoc['docu']=='IB15'))
                            or($head_name[$xcol]=='nume_fact' and ($asoc['docu']=='EB10' or $asoc['docu']=='IB10'))
                            or($head_name[$xcol]=='nume_fact' and ($asoc['docu']=='EB10' or $asoc['docu']=='IB15'))
                            or($head_name[$xcol]=='nume_opro' and ($asoc['docu']=='EB19') )
                            or($head_name[$xcol]=='orden' and ($asoc['docu']=='EB19') )
                            or($head_name[$xcol]=='nume_impo' )
                         )
                         {
                              $col=$row->appendChild($domg->createElement($tcol));       
                              $zdom=$domg;
                              $zele=$col;
                              $zobj=1;
                              $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                                   $zclass='numeric';
                                   $zmin=0;
                                   $zmax=999999999;
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsavef=$head_name[$xcol];
                                   if($head_name[$xcol]=='factu'){$zsavef='numfac';}
                                   if($head_name[$xcol]=='orden'){$zsavef='numfac';}
                                   if($head_name[$xcol]=='nume_fact'){$zsavef='numfac';}
                                   if($head_name[$xcol]=='nume_opro'){$zsavef='numfac';}
                              
                                   if($head_name[$xcol]=='nume_impo'){$zsavef='impor';}
                                   if($head_name[$xcol]=='nume_impo')
                                   {
                                        $zclass='';
                                        $zmin='';
                                        $zmax='';
                                        
                                        $zdocu='FP15';
                                        $zcolu='impor';
                                        $zcolu2='impor';
                                        $zlist='dlimpo';
                                   }
//                                    if($head_name[$xcol]=='orden'){$zsavef='orden';}
//                                    if($head_name[$xcol]=='impor'){$zsavef='impor';}
                                   include('ele_input.php');
                              $crea_value=false;
                         }
                         
                         
                    }
                         
                         
                    if(substr($field_name[$xcol],-6)=='_check')
                    {
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $zdom=$domg;
                         $zele=$col;
                         $zobj=1;
                         
                         if($head_name[$xcol]=='zeus')
                         {
                              $zvalue=$value;
                              $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                              $zsave=1;
                              $zsavet=$modu  ;
                              $zsavef=$head_name[$xcol];
                              $zsavei=$asoc['idnum1_hide'];
                              $ztype='check';
                              $zsize=0.9;
                              if($prnt==1){$zreado=1;}
                              if($prnt==1){$zsize=0.7;}
                              include('ele_input.php');
                         }

                         if($head_name[$xcol]=='cchk')
                         {
                              $zvalue=$value;
                              $zid=$asoc['idnum1_hide'].'_'.$head_name[$xcol];
                              $zsave=1;
                              $zsavet=$modu  ;
                              $zsavef=$head_name[$xcol];
                              $zsavei=$asoc['idnum1_hide'];
                              $ztype='check';
                              $zsize=0.9;
                              if($prnt==1){$zreado=1;}
                              if($prnt==1){$zsize=0.7;}
                              include('ele_input.php');
                         }

//                          if($head_name[$xcol]=='nuev')
                         if(mb_stristr2('.nuev.modi.cons.info.apro.anul.elim',$head_name[$xcol]))     
                         {
                              $zvalue=$value;
//                               $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                              $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].'_'.$head_name[$xcol];
                              $zsave=1;
                              $zsavet=$modu ;
                              $zsavef=$head_name[$xcol];
                              $zsavei=$asoc['idnum1_hide'];
                              $zsaved=$asoc['iddet_hide'];
                              $ztype='check';
                              $zsize=0.9;
                              if($prnt==1){$zreado=1;}
                              if($prnt==1){$zsize=0.7;}
                              include('ele_input.php');
                         }

                         $crea_value=false;
                    }
                         
                    if(substr($field_name[$xcol],-5)=='_edit')
                    {
//                     echo '*/*/*';
                         $col=$row->appendChild($domg->createElement($tcol));       
                         $zdom=$domg;
                         $zele=$col;
                         $zobj=1;
                         $zplace='.';

                         if($head_name[$xcol]=='cant')
                         {
                              $zvalue=$value;
                              $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                              $zclass='numeric-dec';
                              $zmin=0.00;
                              $zmax=9999.99;
                              $zmax=9999999.99;
//                               $zmax=$asoc['cant0_hide'];
                              $zsave=1;
                              $zsavet=$modu  ;
                              $zsavef='cant';
                              $zsavei=$asoc['idnum1_hide'];
                              $zsaved=$asoc['iddet_hide'];
                              if(substr($asoc['docu'],0,2)=='PS' and $asoc['st']=='A'){$zreado=1;$zsave=0;}
                              include('ele_input.php');
                         }
                         
                         if($head_name[$xcol]=='pcp')
                         {
//                               $zvalue=$value;
                              $zvalue=$asoc['p_uni'];
                              $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                              $zclass='numeric-dec';
                              $zmin=0.00;
                              $zmax=99999.99;
//                               $zmax=999999.99;
                              $zsave=1;
                              $zsavet=$modu  ;
//                               $zsavef='cuni';
                              $zsavef='puni';
                              $zsavei=$asoc['idnum1_hide'];
                              $zsaved=$asoc['iddet_hide'];
                              include('ele_input.php');
                         }
                         
                         if($head_name[$xcol]=='prov')
                         {
                              
                              $zvalue=$value;
                              $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                              $ztabla='enti';
//                               $zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from comp1 left join comp2 on idnum1=idnum2 and item="'.$asoc['item'].'" ))';
//                               $zlist='dlenti'.$asoc['item'];
                              $zsave=1;
                              $zsavet=$modu  ;
                              $zsavef='enti2';
                              $zsavei=$asoc['idnum1_hide'];
                              $zsaved=$asoc['iddet_hide'];
     //                          if($aso_jwib['docuc_'.$cas10]=='AS11'){$zreado=1;}
                              include('ele_input.php');
                         }

                         if($head_name[$xcol]=='item')
                         {
                              $zvalue=$value;
                              $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                              $ztabla='item';
                              $zsave=1;
                              $zsavet=$modu  ;
                              $zsavef='item';
                              $zsavei=$asoc['idnum1_hide'];
                              $zsaved=$asoc['iddet_hide'];
                              if(substr($asoc['itemce_hide'],0,4)!='9999'){$zreado=2;}
                              if(substr($asoc['docu'],0,2)=='PS' and $asoc['st']=='A'){$zreado=1;$zsave=0;}
//                               $zreado=1;
                              include('ele_input.php');
                         }
                         
//                          if(1==2)
                         if($head_name[$xcol]=='horas')
                         {
                              $zvalue=$value;
                              $zid=$asoc['codigo'].$head_name[$xcol];
                              $zclass='numeric-dec';
                              $zmin=0.00;
                              $zmax=999.99;
                              $zsave=1;
                              $zsavet=$modu  ;
                              $zsavef='horas';
                              $zsavec=$asoc['codigo'];
//                               $zsaved=$asoc['iddet_hide'];
//                               if(substr($asoc['docu'],0,2)=='PS' and $asoc['st']=='A'){$zreado=1;$zsave=0;}
                              include('ele_input.php');
                         }
                         
                         
                         

                         $crea_value=false;
                    }

                    if(substr($info,2,4)=='mdc0' )
                    {
                              if($head_name[$xcol]=='lugar' and $edit>=1)
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
//                                    $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zid=$asoc['idnum1_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
//                                    $zsaved=$asoc['iddet_hide'];
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                         
                    }

                         
                         
                         
                         
                         
                         
//                     if(substr($info,2,4)=='det2' or substr($info,2,4)=='rein')
                         
                    if(!empty($edit) and $info=='iiresu')
                    {
                         if(substr($asoc['idate'],0,8)>=date('y-m-d',strtotime('-'.$edit.' days')))
                         {
                              if($head_name[$xcol]=='enti' )
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $ztabla='enti';
                                   $zreado=1;
                                   if(mb_stristr2('.IB10.IB15',$asoc['docu']))
                                   {$zreado=0;}
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                              if($head_name[$xcol]=='bode_t' )
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu;
                                   $zsavef='bode2';
                                   $zsavei=$asoc['idnum1_hide'];
                                   $ztabla='bode';
                                   $zreado=1;
                                   if(mb_stristr2('.EB13',$asoc['docu']))
                                   {$zreado=0;}
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                         }
                    }
                         
                    if(!empty($edit) and mb_stristr2('.cjresu.bcresu.rcresu',$info) )
                    {
                         if(substr($asoc['idate'],0,8)>=date('y-m-d',strtotime('-'.$edit.' days')))
                         {
                              if($head_name[$xcol]=='ctab' )
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $ztabla='ctab';
                                   $zreado=1;
                                   if(mb_stristr2('.ND17.',$asoc['docu']))
                                   {$zreado=0;}
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                         }
                    }
                         
                         
                         
                    if(!empty($edit))
                    if(substr($info,2,4)=='deta' or substr($info,2,4)=='det1' or substr($info,2,4)=='det2' or substr($info,2,4)=='det3' or substr($info,2,4)=='dein')
                    {
//                                    echo '===='.$value;
//                               echo '*/*'.$info;
//                          echo '*/*/* '.substr($asoc['idate_hide'],0,10);
//                          echo '*/*/*'.$atrz_ok;
//                          echo '*/*/*'.$asoc['idate_hide'];
//                          echo '*/*/*'.date('Y-m-d');
//                          echo ' */*/* '.substr($asoc['idate_hide'],0,10)>=date('Y-m-d');
                         
                         if(substr($asoc['idate_hide'],0,10)>=date('Y-m-d'))
                         {
                              if($head_name[$xcol]=='cant' and $atrz_ok==0)
                              {
//                               echo '<br>';     
//                               echo '==='.$value9;
//                               echo '==='.$value;
                                   
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value9;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zclass='numeric-dec';
                                   $zmin=0.01;
                                   $zmax=9999.99;
                                   $zmax=999999.99;
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
     //                               $zonblur='{location.reload();}';
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                              if(mb_stristr2('.peso.volu.ad_valor.especial.dumping.fodinfa',$head_name[$xcol]))
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value9;
                                   $xheadname=$head_name[$xcol];
                                   if($head_name[$xcol]=='peso'){$xheadname='peso';}
                                   if($head_name[$xcol]=='volu'){$xheadname='volu';}
                                   if($head_name[$xcol]=='ad_valor'){$xheadname='adva';}
                                   if($head_name[$xcol]=='ad-valor'){$xheadname='adva';}
                                   if($head_name[$xcol]=='especial'){$xheadname='espe';}
                                   if($head_name[$xcol]=='dumping'){$xheadname='dump';}
                                   if($head_name[$xcol]=='fodinfa'){$xheadname='fodi';}
                                   
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$xheadname;
                                   $zclass='numeric-dec';
                                   $zmin=0.00;
                                   $zmax=9999.999;
                                   $zsave=1;
                                   $zsavet=$modu  ;
//                                    $zsavef=$head_name[$xcol];
                                   $zsavef=$xheadname;
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
     //                               $zonblur='{location.reload();}';
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                              
                              if($head_name[$xcol]=='puni' and $modu=='prov')
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
//                                    $zvalue=$value;
                                   $zvalue=$value9;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zclass='numeric-dec';
                                   $zmin=0.01;
                                   $zmax=99999.99;
//                                    $zmax=999999.99;
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
     //                               $zonblur='{location.reload();}';
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                              if($head_name[$xcol]=='lote')
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
     //                               $ztabla='enti';
          //                          $zlist='dlenti';
     //                               $zclass='numeric-dec';
     //                               $zmin=0.01;
     //                               $zmax=9999.99;
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
     //                               $zonblur='{location.reload();}';
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                              if($head_name[$xcol]=='numserie')
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                              if($head_name[$xcol]=='detalle')
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                              if($modu=='rmed')
                              if(
                                   $head_name[$xcol]=='---'
                                   or $head_name[$xcol]=='farmaco' 
                                   or $head_name[$xcol]=='medicamento' 
                                   or $head_name[$xcol]=='prescripcion' 
                                   or $head_name[$xcol]=='via' 
                                   or $head_name[$xcol]=='dosis' 
                                   or $head_name[$xcol]=='frecuencia' 
                                   or $head_name[$xcol]=='duracion' 
                                   or $head_name[$xcol]=='indicaciones' 
                              )
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
//                                    echo '==='.$zid;
//                                    echo '==='.$modu;
                                   $zsave=1;
                                   $zsavet=$modu  ;
                                   $zsavef=$head_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
                                   $zwidth=10;

                                   {$zlist='dl'.$head_name[$xcol];}
                                   if($head_name[$xcol]=='farmaco')
                                   {$zlist='dl_fmco';}
                                   if($head_name[$xcol]=='medicamento')
                                   {$zlist='dl_mdcn';}

                                   if($head_name[$xcol]=='duracion')
                                   {
                                        $zclass='numeric-int';
                                        $zmin=1;
                                        $zmax=90;
                                   }                                   
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                              
                         }
                         
   
//                          echo '=== '.$fecha0_edit;
                         
//                          if(substr($asoc['idate_hide'],0,10)>=date('Y-m-01',strtotime('-3 month')))
                         if(substr($asoc['idate_hide'],0,10)>=$fecha0_edit)
                         {
                              $numerete=0;
                              if($head_name[$xcol]=='cair')
                              {
                                   $sql_retp='select * from retp1 left join retp2 on idnum1=idnum2 ';
                                   $sql_retp.='where ifnull(status,"-") not in("O","X") and enti like "'.$asoc['enti'].'%" and docum="'.$asoc['docu'].'" and numer="'.$asoc['numero'].'" ';
                                   $sql_retp.='order by cair desc ';
                                   $res_retp=msql_query($sql_retp,$link_data);
                                   $aso_retp=msql_fetch_assoc($res_retp);
                                   $numerete=$aso_retp['numero'];
                                   $cairrete=$aso_retp['cair'];
//                                    echo '<br>==='.$sql_retp;
//                                    echo '<br>==='.$numerete;
                              }
                             
                              
//                               echo '<br>'.$modu;
                              if(
                                   $head_name[$xcol]=='cuenta'  or $head_name[$xcol]=='ctas'  or $head_name[$xcol]=='cair'  or $head_name[$xcol]=='csub' 
                                   or ($head_name[$xcol]=='item' and $modu=='comp') 
                                   or ($head_name[$xcol]=='item' and $modu=='lpro' and substr($value,0,4)=='9999')
                              )
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
//                                    $zvalue.='**';
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $ztabla=$head_name[$xcol];
                                   if($head_name[$xcol]=='cuenta'){$ztabla='ctas';}
//                                    echo '<br>=== '.$ztabla;
                                   $zsave=1;
                                   $zsavet=$modu;
                                   $zsavef=$head_name[$xcol];
                                   if($head_name[$xcol]=='cuenta'){$zsavef='ctas';}
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
                                   
                                   if($head_name[$xcol]=='cair' and !empty($numerete)){$zreado=1; }
                                   
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
//                                    echo '*/*/*'.$head_name[$xcol];
                              if($head_name[$xcol]=='uxpre' or $head_name[$xcol]=='facon')
                              {
                                   $col=$row->appendChild($domg->createElement($tcol));       
                                   $zdom=$domg;
                                   $zele=$col;
                                   $zobj=1;
                                   $zplace='.';
                                   $zvalue=$value;
                                   $zid=$asoc['idnum1_hide'].'_'.$asoc['iddet_hide'].$head_name[$xcol];
                                   $zclass='numeric-dec';
                                   $zmin=0.00;
                                   $zmax=9999.99;
                                   $zsave=1;
                                   $zsavet=$modu;
//                                    $zsavef=$head_name[$xcol];
                                   $zsavef=$field_name[$xcol];
                                   $zsavei=$asoc['idnum1_hide'];
                                   $zsaved=$asoc['iddet_hide'];
     //                               $zonblur='{location.reload();}';
                                   include('ele_input.php');
                                   $crea_value=false;
                              }
                              
                         }
                         
                    }

                         
                    }
                    
                    
                    // llena valor
                    if($crea_value)
                    {$col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));}
                    
                    
                    if($anti=='true' and  substr($field_name[$xcol],0,2)=='A_')
                    {
                         $styledv='';
                         $styledv.=color_cxcp(substr($field_name[$xcol],2,5)*1);
                         $styledv=substr($styledv,0,strpos($styledv,';'));
                         $styledv=str_replace('background-color:','border-right:2px solid ',$styledv);
                         $col->setAttribute('style',$styledv);
                    }
                    
                    
                    
                    if($formacol==1)
                    {
                         $col->setAttribute('align-r',' ');
                         if(mb_stristr2('int.real.float',$field_type[$xcol]))
                         if($value9==0)
                         {
                              $colname->setAttribute('hide',' ');
                              $col->setAttribute('hide',' ');
                              
                         }
                    }
                    
                    $col_sticky=0;
                    if(substr($info,2,4)=='resu' and $field_name[$xcol]=='numero'){$col_sticky=1;}
                    if($modu=='inve' and $field_name[$xcol]=='item'){$col_sticky=1;}
                    if($modu=='cxco' and $field_name[$xcol]=='enti'){$col_sticky=1;}
                    if($modu=='cxpa' and $field_name[$xcol]=='enti'){$col_sticky=1;}
                    if($modu=='cont' and $field_name[$xcol]=='ctas'){$col_sticky=1;}
                    if($modu=='btcr' and $field_name[$xcol]=='_d_'){$col_sticky=1;}
                    if($info=='vtenxm' and $field_name[$xcol]=='cliente'){$col_sticky=1;}
                    
                    if($field_name[$xcol]=='iva')
                    {
                         $col->setAttribute('title',number_format($asoc['piva_hide'],1).'%');
                    }
                    if($col_sticky==1)
                    {$col->setAttribute('sticky-left2',"");}                    

                    

//                     $styledv='';
                    
                    if($field_name[$xcol]=='dias_v' or $field_name[$xcol]=='diasv')
                    {
                         $styledv='';
                         $styledv.=color_cxcp($value9);
                         $col->setAttribute('style',$styledv);
                    }
                    
                    
                    
                    

                    if(!empty($value1) and !empty($value2))
                    {
                         $col->appendChild($domg->createElement("br",""));
                         $col->appendChild($domg->createElement("span",$value2));
                    }
                    
                    $class='';
                    $style='';
                    
                    
                    if($value=='▼'){$style.="color:green; border-color:green; border-right:solid 3px;"; $col->setAttribute("bold",""); $col->setAttribute("size140","");}
                    if($value=='▲'){$style.="color:gold; border-color:gold; border-right:solid 3px;"; $col->setAttribute("bold",""); $col->setAttribute("size140","");}
                    
                    
                    if(empty($value_img))
                    {}
                    else
                    {
                         $col->setAttribute("align-c","");
                         $img=$col->appendChild($domg->createElement("img",""));
                         $img->setAttribute("src",$value_img);
                         $img->setAttribute("width","50");
                         $img->setAttribute("heigth","50");
                         $value_img="";
                    }
                    
                    if($field_name[$xcol]=='bode' and substr(msql_result($zreso,$xrow,'docu'),-2)=='13' and msql_result($zreso,$xrow,'bode2')!='')
                    {
                         $col->appendChild($domg->createElement('br',''));
                         if(msql_result($zreso,$xrow,'docu')=='IB13')
                         {$bode2=$col->appendChild($domg->createElement('span',' ◄'.msql_result($zreso,$xrow,'bode2_hide')));}
                         if(msql_result($zreso,$xrow,'docu')=='EB13')
                         {$bode2=$col->appendChild($domg->createElement('span',' ►'.msql_result($zreso,$xrow,'bode2_hide')));}
                         
                         $bode2->setAttribute('size80','');
                    }
                    
                    if(mb_stristr2('.ttssff.ttrrii',$info)) 
                    {
//                          if(strlen($value)>40){$col->setAttribute('size80',"");}
//                          elseif(strlen($value)>40){$col->setAttribute('size80',"");}
                    }
                 
                    if(!mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc.',$info)) 
                    if($modu!='hcli')
                    {
                         if(strlen($value)>80){$col->setAttribute('size60',"");}
                         elseif(strlen($value)>40){$col->setAttribute('size80',"");}
                    }
                 
                    if(mb_stristr2('.idnum1.idnum2.iddet.st_ce',$field_name[$xcol])){$col->setAttribute('size60',"");}
                    if(mb_stristr2('.idn.usr.idc.idd',$field_name[$xcol])){$col->setAttribute('size60',"");}
                    if(mb_stristr2('.tdcto.tprop.tiva.tice.tirbp',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if(mb_stristr2('.tiva.tice.tirbp',$field_name[$xcol])){$col->setAttribute('italic',"");}
                    if(mb_stristr2('.vndd.rcdd',$field_name[$xcol])){$col->setAttribute('size80',"");}
//                     if(mb_stristr2('.r_saldo',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if($field_name[$xcol]=='r_saldo'){$col->setAttribute('size80',"");}
                    if(mb_stristr2('.nega.c_pro.v_pro.vcp',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if(mb_stristr2('.u_movi',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if(mb_stristr2('.i_rot.d_rot',$field_name[$xcol])){$col->setAttribute('size80',"");}
//                     if(mb_stristr2('.d_rot.d_rot',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if(mb_stristr2('.umdd.cpd.cpm.cps.',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if(mb_stristr2($field_name[$xcol],'comi_')){$col->setAttribute('italic',"");}
                    if(mb_stristr2($field_name[$xcol],'comi_')){$col->setAttribute('size80',"");}
                    if(mb_stristr2($field_name[$xcol],'_comi')){$col->setAttribute('italic',"");}
                    if(mb_stristr2($field_name[$xcol],'_comi')){$col->setAttribute('size80',"");}
                    if(mb_stristr2($field_name[$xcol],'_rta')){$col->setAttribute('italic',"");}
                    if(mb_stristr2($field_name[$xcol],'_rta')){$col->setAttribute('size80',"");}
                    if(mb_stristr2($field_name[$xcol],'_iva')){$col->setAttribute('italic',"");}
                    if(mb_stristr2($field_name[$xcol],'_iva')){$col->setAttribute('size80',"");}
                    if(mb_stristr2($field_name[$xcol],'iva_')){$col->setAttribute('italic',"");}
                    if(mb_stristr2($field_name[$xcol],'iva_')){$col->setAttribute('size80',"");}
                    if(mb_stristr2($field_name[$xcol],'_ice')){$col->setAttribute('size80',"");}
                    if(mb_stristr2($field_name[$xcol],'_icon')){$col->setAttribute('align-c',"");}
                    if(mb_stristr2($field_name[$xcol],'hora')){$col->setAttribute('align-c',"");}

                    if(mb_stristr2('.st_ce',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                    if(mb_stristr2($field_name[$xcol],'AÑO')){$col->setAttribute('align-c',"");}
                    
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,0,1)=='1'){$col->setAttribute('italic',"");}
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,0,1)=='1'){$col->setAttribute('bold',"");}
//                     if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,0,1)=='1'){$col->setAttribute('dred',"");}
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='2'){$col->setAttribute('bgc-lgreen',"");}
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='3'){$col->setAttribute('bgc-gold',"");}
                    
//                     if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='4'){$col->setAttribute('bgc-orange',"");}
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='4')
                    {
                         if(empty(err_autor($asoc['autormsj_hide']))){$col->setAttribute('bgc-dorange',"");}
                         else{$col->setAttribute('bgc-dred',"");}
                    }
                    
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='5'){$col->setAttribute('bgc-lblue',"");}
                    
                    $stce_title='';
                    $stce_title.='F: '.$asoc['firmafec_hide'].$brkln_html;
                    if(!empty($asoc['recepmsj_hide'])){$stce_title.='R: '.$asoc['recepfec_hide'].' = '.$asoc['recepmsj_hide'].$brkln_html;}
                    if(!empty($asoc['autormsj_hide'])){$stce_title.='A: '.$asoc['autormsj_hide'];}
                    if(!empty($asoc['autorfec_hide'])){$stce_title='A: '.$asoc['autorfec_hide'].$brkln_html;}
                    if(!empty($asoc['emailfec_hide'])){$stce_title.='@: '.$asoc['emailfec_hide'];}
                    
                    
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='2'){$col->setAttribute('title',$stce_title);}
//                     if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='3'){$col->setAttribute('title',$asoc['recepmsj_hide'].' | '.$asoc['recepfec_hide']);}
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='3'){$col->setAttribute('title',$stce_title);}
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='4'){$col->setAttribute('title',$stce_title);}
//                     if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='5'){$col->setAttribute('title','A: '.$asoc['autorfec_hide']);}
                    if(mb_stristr2('.st_ce',$field_name[$xcol]) and substr($value,1,1)=='5'){$col->setAttribute('title',$stce_title);}
// 
                    if(mb_stristr2('.docu.cair.suco.fpag',$field_name[$xcol]))
                    {
                         $maes_descri_hide=$asoc[$field_name[$xcol].'_descri_hide'];
                         if(!empty($maes_descri_hide))
                         $col->setAttribute('title',$maes_descri_hide);
                    }
                    
                    if(mb_stristr2('.ptoe.ptoem.pto_emi.bode.caja.ctab.numero.status.st',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                    
                    if(mb_stristr2('.ptoe.ptoem',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if(mb_stristr2('.tdcto.',$field_name[$xcol])){$col->setAttribute('italic',"");}
                    if(mb_stristr2('.tdcto.',$field_name[$xcol]) and $value!=0){$col->setAttribute('underline',"");}
                    
                    if(mb_stristr2('.entra.sale.tiempo.',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                    if(mb_stristr2('.color.talla.',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                    if(mb_stristr2('.color.talla',$field_name[$xcol])){$col->setAttribute('size80',"");}
//                     if(substr(htmlentities($value),0,2)=='&#'){$col->setAttribute('align-c',"");}
                    
                    
                    if(mb_stristr2('.cant.uxpre.facon',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    
                    if(mb_stristr2('.codigo',$field_name[$xcol])){$col->setAttribute('nowrap',"");}
                    if(mb_stristr2('.idate',$field_name[$xcol])){$col->setAttribute('nowrap',"");}
                    
                    if(mb_stristr2('.nume_impor',$field_name[$xcol])){$col->setAttribute('nowrap',"");}
                    if(mb_stristr2('.vence',$field_name[$xcol])){$col->setAttribute('nowrap',"");}
                    if(mb_stristr2('.vence',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if(mb_stristr2('.vence',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                    
                    if(mb_stristr2('.cair',$field_name[$xcol])){$col->setAttribute('border-lr',"");}
                    if(mb_stristr2('.iva',$field_name[$xcol])){$col->setAttribute('border-lr',"");}
                    
                    if(mb_stristr2('.empr',$field_name[$xcol])){$col->setAttribute('border-lr',"");}
                    if(mb_stristr2('.empr',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    
                    if(mb_stristr2($field_name[$xcol],'porc_')){$col->setAttribute('italic',"");}
                    if(mb_stristr2($field_name[$xcol],'porc_')){$col->setAttribute('size80',"");}
                    if(mb_stristr2($field_name[$xcol],'tot_')){$col->setAttribute('bold',"");}
                    if(mb_stristr2($field_name[$xcol],'base_')){$col->setAttribute('border-l',"");}
                    if(mb_stristr2('.docum',$field_name[$xcol])){$col->setAttribute('border-l',"");}
                    if(mb_stristr2('.bode',$field_name[$xcol])){$col->setAttribute('border-l',"");}
                    if(mb_stristr2('.asub',$field_name[$xcol])){$col->setAttribute('border-l',"");}
                    if(mb_stristr2('.peso_kg.dato.fase',$field_name[$xcol])){$col->setAttribute('border-l',"");}
                    if(mb_stristr2('.temp_°c',$field_name[$xcol])){$col->setAttribute('border-l',"");}
                    if(mb_stristr2('.reg_san.cod_pre',$field_name[$xcol])){$col->setAttribute('border-l',"");}
                    if(mb_stristr2('.cambio',$field_name[$xcol])){$col->setAttribute('border-lr',"");}
                    if(mb_stristr2('.tipo',$field_name[$xcol])){$col->setAttribute('border-lr',"");}
                    if(mb_stristr2('.reg_san',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    if(mb_stristr2('.anticipo.abono.reten.egreso.credito',$field_name[$xcol])){$col->setAttribute('italic',"");}

//                     echo '=='.$field_leng[$xcol];
                    if($field_type[$xcol]=='date' and $field_leng[$xcol]<=10){$col->setAttribute('td_date',"");}
                    if($field_type[$xcol]=='date' and $field_leng[$xcol]>10){$col->setAttribute('td_datime',"");}
                    if(mb_stristr2('.ultimo',$field_name[$xcol])){$col->setAttribute('size80',"");}
                    
                    if($field_type[$xcol]=='string' and $field_leng[$xcol]<=9 and mb_stristr2($value,'-')){$col->setAttribute('size80',"");}
                    if($field_type[$xcol]=='string' and $field_leng[$xcol]<=9 and mb_stristr2($value,' ')){$col->setAttribute('nowrap',"");}
//                     if($field_type[$xcol]=='string' and $field_leng[$xcol]<=4){$col->setAttribute('align-c',"");}
                    if($field_type[$xcol]=='string' and $field_leng[$xcol]<=4 and $field_name[$xcol]!='ctas'){$col->setAttribute('align-c',"");}
                    if($field_type[$xcol]=='string' and $field_leng[$xcol]==7 and substr($value,4,1)=='-'){$col->setAttribute('align-c',"");}

                    if(!mb_stristr2('.numero',$field_name[$xcol]))
                    {
                    if($field_type[$xcol]=='int' and $field_leng[$xcol]<=2){$col->setAttribute('align-c',"");}
                    if($field_type[$xcol]=='int' and $field_leng[$xcol]>2){$col->setAttribute('align-r',""); $col->setAttribute('padd-lr05',"");}
                    if($field_type[$xcol]=='real'){$col->setAttribute('align-r',""); $col->setAttribute('padd-lr05',"");}
                    if($field_type[$xcol]=='float'){$col->setAttribute('align-r',""); $col->setAttribute('padd-lr05',"");}
                    }
                    
                    
//                     if(mb_stristr2('.ctas.enti.item.plvh.codt',$field_name[$xcol])){$col->setAttribute('td_codigo',"");}
                    if(mb_stristr2('.ctas.enti.item.plvh.codt.pcnt.empl.nvdd..csub.c_sub.cedula.clvh.mdvh.vinn',$field_name[$xcol])){$col->setAttribute('td_codigo',"");}
                    if(mb_stristr2('.codigo',$field_name[$xcol])){$col->setAttribute('padd-lr05',"");}
                    if(mb_stristr2('.nume_',substr($field_name[$xcol],0,5))){$col->setAttribute('align-c',"");}
                    if(mb_stristr2('.cedula.orden',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                    if(mb_stristr2('.idn.idc',$field_name[$xcol])){$col->setAttribute('align-c',"");}
//                     if(mb_stristr2('.idc',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                    if(mb_stristr2('.idate.udate.fecha_up',$field_name[$xcol]) and $field_leng[$xcol]>10){$col->setAttribute('td_datime',"");}
                    
                    if(!mb_stristr2('.ttssff.ttrrii.ttsfcc.ttricc.',$info))
                    {if(mb_stristr2('.inicial_$.total.total_$.saldo.saldo_$.costo_$.valor_$.stock.neto.',$field_name[$xcol])){$col->setAttribute('td_total',"");}}
                    
                    if(mb_stristr2('.ccresu.cpresu.',$info))
                    {if(mb_stristr2('.numero.',$field_name[$xcol])){$col->setAttribute('td_total',"");}}
                    
                    if(mb_stristr2('.liga',$field_name[$xcol])){$col->setAttribute('td_total',"");}
                    
                    if(mb_stristr2('.ccmovi.cpmovi.ccddcc.cpddcc.ccsald.cpsald.ccresu.cpresu',$info) and mb_stristr2('.saldo.stock.saldo_$',$field_name[$xcol]) and $value<0)
                    {
                         $row->setAttribute('red',""); $ssnega=1;
//                          if(abs($value)<=0.5){$value=0;}
                         
//                          if(abs($value)==7.50)
//                          if(1==2)
//                          if(mb_stristr2('.ccresu.cpresu',$info)
//                          if($value<0)
//                               if($asoc['docu_hide']=='EE10')
//                               {
// //                                    $xenti=$enti;
// //                                    if(empty($xenti)){$xenti=$asoc['enti'];}
// //                                    $sql_fact='select * from comp1 where ifnull(status,"")not in("O","X") ';
// //                                    $sql_fact.='and enti like"'.substr($xenti,0,10).'%" and docu="'.$asoc['docu'].'" and numero="'.$asoc['numero'].'"';
// //                                    $res_fact=msql_query($sql_fact,$link_data);
// //                                    echo 
// //                                    echo '==> '.$asoc['idnum_hide'];
// //                                    echo '==> '.$asoc['docu'];
// //                                    echo '==> '.$asoc['enti_hide'];
// //                                    echo '==> '.$asoc['enti'];
// //                                    echo '==> '.$enti;
// //                                    echo '==> '.$asoc['ptoe'];
// //                                    echo '==> '.$asoc['numero'];
//                               }
                    }
                    
//                     if(mb_stristr2('.iiiiee.iibode.iikrdx.iisxlt.',$info) and mb_stristr2('.saldo.stock.saldo_$.',$field_name[$xcol]) and $value< (-0.0;1))
                    if(mb_stristr2('.iiiiee.iibode.iikrdx.iisxlt.',$info) and mb_stristr2('.saldo.stock.saldo_$.',$field_name[$xcol]) and $value<0)
                    {
                         $row->setAttribute('red',""); $ssnega=1;
//                          if($field_name[$xcol]=='saldo_$' and $value>(-0.01))
                         {
//                               $row->removeAttribute('red',"");
//                               $ssnega=0;
                         }
                    }
                    
                    
                    
                    if(mb_stristr2('.iiiiee.iibode.iikrdx.iisxlt.',$info)
                       and mb_stristr2('.stock',$field_name[$xcol]) 
                       and $asoc['stock']<$asoc['s_min']
                       and days_diff($asoc['u_movi'],$fecha2)<30
                      )
                    {
                         $row->setAttribute('orange',"");
                    }
                    
                    if($asoc['st']!='O')
                    if(substr($field_name[$xcol],0,3)=='err')
                    {
                         if($asoc[$field_name[$xcol]]>=4){$row->setAttribute('dred',"");}
                         if($asoc[$field_name[$xcol]]>=1){$row->setAttribute('orange',"");}
                    }
                    
                    
//                          echo '==='.$asoc['st'];
                    
                    if(mb_stristr2('.iicuxc',$info) and mb_stristr2('.puni.factu.nume_fact',$field_name[$xcol]) and $value<=0)
                    {$row->setAttribute('red',""); $ssnega=1;}
                    
                    if(mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc.',$info))
                    {
                         if($asoc['nivel_hide']==1)
                         {$row->setAttribute('bold',"");}
                         
//                          if($asoc['nivel_hide']==2)
                         if($asoc['nivel_hide']==2 and $nivel>3)
                         {
                              $row->setAttribute('bold',"");
                              $row->setAttribute('italic',"");
                         }

                         if($asoc['nivel_hide']==3)
                         {$row->setAttribute('italic',"");}
                         
                         
                    }
                    
                    
                    if(mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc.',$info) and ($asoc['nivel_hide']==$nivel or $asoc['nivel_hide']==$nivel-1) )
                    {
//                          $row->setAttribute('bold',"");
//                          $row->setAttribute('size80',"");
                    }
                    
                    if(mb_stristr2('.ttssff.ttrrii.ttssnn.ttsfcc.ttricc.',$info) and $asoc['nivel_hide']==$nivel and abs($asoc['saldo'])<=0.01)
                    {
//                          $row->setAttribute('hide',"");
//                          $row->setAttribute('size80',"");
                    }

                    
                    if(mb_stristr2('.btblog',$info))
                    {
//                          if($asoc['docu_hide']=='BTC1'){$row->setAttribute('bgc-ulgreen',"");}
//                          if($asoc['docu_hide']=='BTC2'){$row->setAttribute('bgc-lred',"");}
                    }

                    
                    if(!($status=='O' or $stat=='O' or $st=='O'))
                    if(mb_stristr2('.caja.ctab.bode.ptov.vndd',$field_name[$xcol]))
                    {
//                          echo '*/'.$field_name[$xcol];
//                          {$col->setAttribute('bgc-beige',"");}
                         {$col->setAttribute('style',"background-color:".$asoc[$field_name[$xcol].'_color_hide'].";");}
                    }

                    if($info=='ccdeta' or $info=='cpdeta')
                    {
                         if($asoc['headet_hide']==1)
                         {
//                               $col->setAttribute('bgc-ulblue',' ');
//                               $col->setAttribute('size120',' ');
//                               if(mb_stristr2('.numero',$field_name[$xcol]))
//                               {$col->setAttribute('bold',' ');}
                         }

                    }

                    
                    if(!($status=='O' or $stat=='O' or $st=='O'))
                    if(mb_stristr2('.bcresu',$info) and mb_stristr2('.doxcu.debito.credito',$field_name[$xcol]))
                    {
                         if($asoc['debito']>0)
                         {$col->setAttribute('bgc-lcyan',"");}
                         
                         if(mb_stristr2('.CH10.DP10',$asoc['docu']))
                         {$col->setAttribute('bgc-beige',"");}
                         
//                          if($asoc['credito']>0)
//                          {$col->setAttribute('bgc-beige',"");}
                         
                         if(substr($asoc['docu'],2,2)=='13')
                         {
//                               if($asoc['debito']>0)
//                               {$col->setAttribute('bgc-beige',"");}
//                               if($asoc['credito']>0)
//                               {$col->setAttribute('bgc-beige',"");}
                         }
                         
                         
                         
                    }
                    
                    
                    
//                     if($info=='iikrdx' and mb_stristr2('.docu.ingreso.egreso',$field_name[$xcol]))
//                     echo '<br>===='.$empr0['empr_codigo'].$field_name[$xcol];
//                     if($empr0['empr_codigo']=='jwib' and mb_stristr2($field_name[$xcol],'tipo'))
                    if(!($status=='O' or $stat=='O' or $st=='O'))
                    if($empr0['empr_codigo']=='jwib' and $field_name[$xcol]=='tipo')
                    {
//                          echo '<br>=='.$value;
                         if(mb_stristr2('.😀',$value)){$row->setAttribute('bgc-ulblue',"");}
                         if(mb_stristr2('.🤐',$value)){$row->setAttribute('bgc-ulyellow',"");}
                         if(mb_stristr2('.😡',$value)){$row->setAttribute('bgc-ulred',"");}
                         if(mb_stristr2('.😶',$value)){$row->setAttribute('',"");}
//                          if(mb_stristr2('.DH',$value)){$row->setAttribute('bgc-ulgreen',"");}
                         
                         if(mb_stristr2('.OK',$value)){$row->setAttribute('bgc-ulblue',"");}
                         if(mb_stristr2('.OC',$value)){$row->setAttribute('bgc-ulyellow',"");}
                         if(mb_stristr2('.NT',$value)){$row->setAttribute('bgc-ulred',"");}
                         if(mb_stristr2('.NC',$value)){$row->setAttribute('',"");}
//                          if(mb_stristr2('.DH',$value)){$row->setAttribute('bgc-ulgreen',"");}
                    }
                    
                    if(!($status=='O' or $stat=='O' or $st=='O'))
                    if($info=='iikrdx' and mb_stristr2('.docu.iXngreso.eXgreso',$field_name[$xcol]))
                    {
                         if(mb_stristr2('.IB10.IB14.IB15',$value))
                         {$row->setAttribute('bgc-ulblue',"");}
                    }
                    
                    if(!($status=='O' or $stat=='O' or $st=='O'))
                    if(mb_stristr2('.ccmovi.cpmovi',$info) and mb_stristr2('.doXcum.debito.credito',$field_name[$xcol]))
                    {
                         if(mb_stristr2('.AC10.AC11.AP10.AP11',$asoc['docu']))
                         {$col->setAttribute('bgc-ulyellow',"");}
                         if(mb_stristr2('.PR10.PR11',$asoc['docu']))
                         {$col->setAttribute('bgc-lpink',"");}
                         if(mb_stristr2('.PR10.PR11',$asoc['docum']))
                         {$col->setAttribute('bgc-lpink',"");}
//                          {$col->setAttribute('bgc-ulblue',"");}
                    }
                    
                    
                    
                    if(!($status=='O' or $stat=='O' or $st=='O'))
                    if($empr0['empr_codigo']=='jwib' and mb_stristr2('.tipo',$field_name[$xcol]))
                    {
                         if($value=='OK'){$row->setAttribute('bgc-lblue',"");}
                         if($value=='OC'){$row->setAttribute('bgc-ulyellow',"");}
                         if($value=='NT'){$row->setAttribute('bgc-lred',"");}
                         if($value=='DH'){$row->setAttribute('bgc-lgreen',"");}
//                          if($value=='OK'){$row->setAttribute('bgc-lblue',"");}
                    }
                    
                    
                    
                    
                    if(!($status=='O' or $stat=='O' or $st=='O'))
                    if($info=='iikrdx' and mb_stristr2('.doXcu.ingreso.egreso',$field_name[$xcol]))
                    {
                         if(substr($asoc['docu'],2,2)=='13')
                         {
//                               if($asoc['ingreso']>0)
                              {$col->setAttribute('bgc-beige',"");}
//                               if($asoc['egreso']>0)
//                               {$col->setAttribute('bgc-beige',"");}
                         }
                    }
                    
                    if(mb_stristr2('.e_bode',$field_name[$xcol]))
                    {
                         $col->setAttribute('size80',"");
                         if($value!=number_format($asoc['cant'],$item_duni))
                         {$col->setAttribute('red',"");$col->setAttribute('bold',"");}
                    }

                    if($modu=='cxco')
                    if($field_name[$xcol]=='f_cobro' and $value>$fecha2)
                    {$row->setAttribute('orange',"");}
                    
                    if(mb_stristr2('.difer',$field_name[$xcol]) and abs($value)>=0.01 ){$row->setAttribute('red',"");}
                    if($field_name[$xcol]=='nega'){$col->setAttribute('align-c',"");}
                    if($field_name[$xcol]=='nega' and $value>0){$row->setAttribute('red',"");}
                    if($field_name[$xcol]=='nega_hide' and $value>1){$row->setAttribute('red',"");}
                    
                    if(mb_stristr2('.linea.zona.',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                    if(mb_stristr2('.linea.zona.',$field_name[$xcol])){$col->setAttribute('nowrap',"");}
                    if(mb_stristr2('.anio.mes.a_mes',$field_name[$xcol])){$col->setAttribute('td_date',"");}
                    if(mb_stristr2($field_name[$xcol],'documento')){$col->setAttribute('nowrap',"");}
                    if(!empty($class)){$col->setAttribute('class',$class);}
                    if(!empty($style)){$col->setAttribute('style',$style);}

               }
          }
          
          
          
          
          
     }

     if($show_timei>=1)
     {echo '<br>=== ele_grid detalle ==== '.date('H:i:s');}

     if($type=='xml')
     {
          $rowf=$footg->appendChild($domg->createElement($trow));
          for($xcol=0; $xcol<msql_num_fields($zreso); $xcol++)
          {
               if(!empty($thead[$xcol]))
               {$col=$rowf->appendChild($domg->createElement($field_name[$xcol],$tfoot[$xcol]));}
          }
     }


     // colgroup head foot
     $xsort=0;
     if($type=='html')
     {
          $rowh=$headg->appendChild($domg->createElement($trow));
          $rowf=$footg->appendChild($domg->createElement($trow));
          if(msql_num_rows($zreso)==0){$rowf->setAttribute('hide','');}
          if($nofoot==1){$rowf->setAttribute('hide','');}
          if($nohead==1){$rowh->setAttribute('hide','');}
//           if(mb_stristr2('.ttssff.ttrrii',$info)){$rowf->setAttribute('hide','');}
          

          //summary
          $ccolg=$colg->appendChild($domg->createElement('col',""));
               $ccolg->setAttribute('colu','L');
//                $ccolg->setAttribute('style',"background-color:white;");
               $ccolg->setAttribute('border-lr'," ");
//                $ccolg->setAttribute('style','background-color:red;');
          $crowh=$rowh->appendChild($domg->createElement('th','L'));
          
          $tot_row=$xrow;
          if($st_count['-']>0){$tot_row=$st_count['-'];}
          
          $crowf=$rowf->appendChild($domg->createElement('th',$tot_row));
//           $crowf=$rowf->appendChild($domg->createElement('th',$st_count['-']));
//                $crowh->setAttribute('sticky-left','');
//                $crowf->setAttribute('sticky-left','');
               if($znolin==1)
               {
                    $crowh->setAttribute('hide'," ");
                    $crowf->setAttribute('hide'," ");
               }
          

          
          $onclick='sortTable(this,'.$xsort++.'';
          if(@mb_stristr2('.int.real.float',$field_type[$xcol])){$onclick.=',"N"';}
          $onclick.=');';
          
          $onclick.='dottedTable('.$name.');';
          $crowh->setAttribute('onclick',$onclick);
          $crowh->setAttribute('size80',"");
          
          
          
          for($xcol=0; $xcol<msql_num_fields($zreso); $xcol++)
          {
//                echo '<br> | '.$field_name[$xcol];
               
               $num_deci0=0;
               $num_deci=2;

               if($empr0['empr_codigo']=='jwib')
               if(mb_stristr2('.lb.m1.m2.m3.m4.vi.nc.nt.',$field_name[$xcol]))
               {$num_deci=0;}
               
               $item_duni=$asoc['item_duni_hide'];
               $item_dval=$asoc['item_dval_hide'];
               $item_dpre=$asoc['item_dpre_hide'];
               $item_dcos=$asoc['item_dcos_hide'];
               
               if(!empty($thead[$xcol]))
               {
                    // group col
                    $style='';
                    $class='';
                    if(mb_stristr2($field_name[$xcol],'conteo') and $info=='iillcc'){$style.='background-color:whitesmoke;';}
                    if(mb_stristr2($field_name[$xcol],'idn')){$style.='background-color:whitesmoke;';}
                    if(mb_stristr2($field_name[$xcol],'idc')){$style.='background-color:whitesmoke;';}
                    if(mb_stristr2($field_name[$xcol],'nega')){$style.='background-color:gold;';}
                    
                    if(mb_stristr2($field_name[$xcol],'dias_v')){$style.='background-color:whitesmoke;';}
                    
                    
                    
                    
//                     if($field_name[$xcol]=='docu'){$class.='colg_docu ';}
                    
                    if($field_name[$xcol]=='cant'){$style.='background-color:whitesmoke;';}
                    if($field_name[$xcol]=='umdd'){$style.='border:solid 1px;';}
                    if(mb_stristr2('._01._03._05._07._09._11',substr($field_name[$xcol],-3))){$style.='background-color:whitesmoke;';}
                    if(mb_stristr2('.2_U.4_U.6_U.8_U.0_U.',substr($field_name[$xcol],-3))){$style.='background-color:whitesmoke;';}
                    if(mb_stristr2('.2_$.4_$.6_$.8_$.0_$.',substr($field_name[$xcol],-3))){$style.='background-color:whitesmoke;';}
                    if(mb_stristr2('.lun.mie.vie.dom.',substr($field_name[$xcol],-3))){$style.='background-color:whitesmoke;';}
                    

                    $col=$colg->appendChild($domg->createElement('col',""));
                         $col->setAttribute('colu',$field_name[$xcol]);
                         $col->setAttribute('type',$field_type[$xcol]);
                         $col->setAttribute('length',$field_leng[$xcol]);
                         if(!empty($class)){$col->setAttribute('class',$class);}
                         if(!empty($style)){$col->setAttribute('style',$style);}

                    $style='';
                    $class='';
                    $onclick='';
                         if(mb_stristr2('.idate',$field_name[$xcol])){$class.='size80';}
                         if(mb_stristr2('.tdcto.tprop.tiva.tice.tirbp.r_rta.r_iva',$field_name[$xcol])){$class.='italic size80 ';}
                         if(mb_stristr2($field_name[$xcol],'comi_')){$class.='italic size80 ';}
                         if(mb_stristr2($field_name[$xcol],'_comi')){$class.='italic size80 ';}
                         if(mb_stristr2($field_name[$xcol],'_rta')){$class.='italic size80 ';}
                         if(mb_stristr2($field_name[$xcol],'_iva')){$class.='italic size80 ';}
                         if(mb_stristr2($field_name[$xcol],'iva_')){$class.='italic size80 ';}
                         if(mb_stristr2($field_name[$xcol],'_ice')){$class.='italic size80 ';}
                         if(mb_stristr2('.tdcto',$field_name[$xcol])){$class.='underline ';}
                         if(mb_stristr2($field_name[$xcol],'a_mes')){$class.='size80 ';}
                         if($field_type[$xcol]=='date'){$class.='date';}
                    
                    
                    
                         $onclick.='sortTable(this,'.$xsort++.'';
                         if(mb_stristr2('.int.real.float',$field_type[$xcol])){$onclick.=',"N"';}
                         $onclick.=');';
                         $onclick.='dottedTable('.$name.');';
//                               $onclick.='dottedTable('.$name.');';
//                               $onclick.='dottedTable('.$name.');';
                    
//      table = document.getElementById(micelda.parentElement.parentElement.parentElement.id);
                    

                    // group head
                    $val_fieldname=$field_name[$xcol];
                    $val_fieldname=strtoupper($val_fieldname);
                    $val_fieldname=str_replace('_','-',$val_fieldname);
                    $val_fieldname=str_replace('PORC-','%',$val_fieldname);
                    $val_fieldname=str_replace('NUM-','# ',$val_fieldname);
                    $val_fieldname=str_replace('NUME-','# ',$val_fieldname);
                    $val_fieldname=str_replace('ANIO','AÑO',$val_fieldname);
                    
                    
                    if(mb_stristr2('.b_e.b_o.b_x.b_a.',$field_name[$xcol])){$val_fieldname='_';}
                    if(mb_stristr2('.u_f',$field_name[$xcol])){$val_fieldname='Archivos';}
                    if(mb_stristr2('.numero',$field_name[$xcol]) and $field_leng[$xcol]<=4){$val_fieldname='NUM';}
                    if(mb_stristr2('.documento',$field_name[$xcol]) and $field_leng[$xcol]<=4){$val_fieldname='DOCUM';}
                    if(mb_stristr2('.nega',$field_name[$xcol]) ){$val_fieldname='.N.';}
                    if(mb_stristr2('.i_rot',$field_name[$xcol]) ){$val_fieldname='I.R.';}
                    if(mb_stristr2('.d_rot',$field_name[$xcol]) ){$val_fieldname='D.R.';}
                    if($field_name[$xcol]=='r_saldo'){$val_fieldname='%';}
                    if(substr($field_name[$xcol],-5)=='_icon'){$val_fieldname=strtoupper(substr($field_name[$xcol],0,1));}
//                     if(mb_stristr2('.v_pro',$field_name[$xcol]) and $field_leng[$xcol]<=4){$val_fieldname='%v_pro';}
                    if(substr($field_name[$xcol],-5)=='_edit'){$val_fieldname=strtoupper(str_replace('_edit','',$field_name[$xcol]));}
                    if(substr($field_name[$xcol],-6)=='_check'){$val_fieldname=strtoupper(str_replace('_check','',$field_name[$xcol]));}
//                     if(mb_stristr2('.notas.',$field_name[$xcol])){$style.='max-width:50%;'; }
                    
                    if(substr($field_name[$xcol],0,2)=='A_'){$style.=color_cxcp(substr($field_name[$xcol],2));}
                    

                    $col=$rowh->appendChild($domg->createElement('th',$val_fieldname));
                         $col->setAttribute('name',$field_name[$xcol]);
                         if(!empty($onclick)){$col->setAttribute('onclick',$onclick);}
                         if(!empty($class)){$col->setAttribute('class',$class);}
                         if(!empty($style)){$col->setAttribute('style',$style);}

                         if($field_leng[$xcol]<=5){$col->setAttribute('size80',"");}
                         if(mb_stristr2('.idn.usr.idc.idate.st_ce',$field_name[$xcol])){$col->setAttribute('size80',"");}
                         if(mb_stristr2('.idate',$field_name[$xcol])){$col->setAttribute('nowrap',"");}
//                          if(mb_stristr2('.notas.',$field_name[$xcol])){$col->setAttribute('width',"50%");}
                         if(mb_stristr2('.notas.',$field_name[$xcol])){$col->setAttribute('max-width',"50%");}
                    

                         if($field_name[$xcol]=='vcp'){$col->setAttribute('title',"Variac.Costo.Prom.");}
                         if($field_name[$xcol]=='i_rot'){$col->setAttribute('title',"Indice de Rotación");}
                         if($field_name[$xcol]=='d_rot'){$col->setAttribute('title',"Días de Rotación");}
                         if($field_name[$xcol]=='cpd'){$col->setAttribute('title',"Cons.Prom.Diario");}
                         if($field_name[$xcol]=='cpm'){$col->setAttribute('title',"Cons.Prom.Mensual");}
                         if($field_name[$xcol]=='cps'){$col->setAttribute('title',"Cons.Prom.Semanal");}
                         if($field_name[$xcol]=='u_movi'){$col->setAttribute('title',"Ultimo Movimiento");}
                    
                         if($field_name[$xcol]=='obser'){$col->setAttribute('style',"min-width:10em;");}
                         if($field_name[$xcol]=='observac'){$col->setAttribute('style',"min-width:20em;");}
                         if($field_name[$xcol]=='observaciones'){$col->setAttribute('style',"min-width:30em;");}
                         if(mb_stristr2('.concepto.detalle',$field_name[$xcol])){$col->setAttribute('style',"max-width:10em;");}                         
                         if(mb_stristr2('.anticipo.abono.reten.credito',$field_name[$xcol])){$col->setAttribute('italic'," ");}                         
                         if(mb_stristr2('.ptoem',$field_name[$xcol])){$col->setAttribute('size80'," ");}                         
                    
                    
                    $tfoot_val=$tfoot[$xcol];
                    if($field_name[$xcol]=='dias_v'){$tfoot_val='';}
                    if($field_name[$xcol]=='idn'){$tfoot_val='';}
                    if($field_name[$xcol]=='idc'){$tfoot_val='';}
                    
                    if($field_type[$xcol]=='real'){$tfoot_val=number_format($tfoot_val,$num_deci);}
                    if($field_name[$xcol]=='_c_'){$tfoot_val=number_format($tfoot_val,$num_deci0);}
                    
                    if($field_name[$xcol]=='cost'){$tfoot_val='';}
                    if($field_name[$xcol]=='cpd'){$tfoot_val='';}
                    if($field_name[$xcol]=='cpm'){$tfoot_val='';}
                    if($field_name[$xcol]=='cps'){$tfoot_val='';}
                    if($field_name[$xcol]=='i_rot'){$tfoot_val='';}
                    if($field_name[$xcol]=='d_rot'){$tfoot_val='';}
                    if($field_name[$xcol]=='c_pro'){$tfoot_val='';}
                    if($field_name[$xcol]=='v_pro'){$tfoot_val='';}
                    if($field_name[$xcol]=='s_min'){$tfoot_val='';}
                    if($field_name[$xcol]=='s_max'){$tfoot_val='';}
                    if($field_name[$xcol]=='vcp'){$tfoot_val='';}
                    if($field_name[$xcol]=='r_saldo'){$tfoot_val='';}
//                     if($field_name[$xcol]=='uxpre'){$tfoot_val='';}
//                     if($field_name[$xcol]=='facon'){$tfoot_val='';}

                    if(mb_stristr2('.codigo.p_unit.pvp',$field_name[$xcol])){$tfoot_val='';}
                    if(mb_stristr2('.b_e.b_o.b_x.b_a.u_f',$field_name[$xcol])){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'p_uni')){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'p_comi')){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'pvp')){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'cost_pro')){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'cpd')){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'cpm')){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'cps')){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'c_pro')){$tfoot_val='';}
                    if(mb_stristr2($field_name[$xcol],'antig')){$tfoot_val='';}
//                     if(substr($field_name[$xcol],-5)=='_edit'){$tfoot_val=1; $tfoot[$xcol]=1;}
                    
                    if(mb_stristr2('.iva.ice.irbp.dcto.prop',$field_name[$xcol]) and substr($info,0,2)=='mt'){$tfoot_val='';}
                    if(mb_stristr2('.c_uni.uxpre.facon',$field_name[$xcol])){$tfoot_val='';}
                    $col=$rowf->appendChild($domg->createElement('th',$tfoot_val));
                         $col->setAttribute('name',$field_name[$xcol]);
                         if(mb_stristr2('.anticipo.abono.reten.credito',$field_name[$xcol])){$col->setAttribute('italic'," ");}                         
                         if($field_type[$xcol]=='real'){$col->setAttribute('align-r',""); $col->setAttribute('padd-lr05',"");}
//                               if($field_type[$xcol]=='real'){$style.='padding-right:0.5em;';}
                         if(!empty($class)){$col->setAttribute('class',$class);}
                         if(!empty($style)){$col->setAttribute('style',$style);}
//                     echo '*/*/*'.$tfoot_val;
                    
                    
               }
               
               // totales arriba
               if($zhead==1)
               {
                    if($type=='html')
                    {                    
//                          echo '<br>*/*/*'.$field_name[$xcol];
                         $xdatosarriba='';
                         $xdatosarriba.='vtas_iva0.comp_iva0';
                         $xdatosarriba.='rete_rta.rete_iva.';
                         $xdatosarriba.='cant.subt.dcto.prop.iva.ice.';
//                          $xdatosarriba.='cant.subt.dcto.iva.ice.';
                         $xdatosarriba.='subt_iva0.';
//                          $xdatosarriba.='inicial_$.debito_$.credito_$.saldo_$.';
                         $xdatosarriba.='inicial.ingreso.egreso.stock.';
                         $xdatosarriba.='inicial_$.debito_$.credito_$.saldo_$.';
                         $xdatosarriba.='costo_$.valor_$';
                         $xdatosarriba.='total_$.valor.abono.reten.';
                         $xdatosarriba.='efectiv.transf.';
                         $xdatosarriba.='inicial_hide.inicial_$_hide';
                         
                         if($scri=='info_maes3'){$xdatosarriba='';}
                         if($info=='sriats'){$xdatosarriba='';}
                         if(mb_stristr2('.ttssff.ttrrii.ttsfcc.ttricc.ttsscc.',$info)){$xdatosarriba='';}
//                          if(mb_stristr2('.ttsfcc.ttricc',$info)){$xdatosarriba='';}
                         
//                          if(mb_stristr2('.int.real',$field_type[$xcol]))
                         if(mb_stristr2($xdatosarriba,$field_name[$xcol]) and mb_stristr2('.int.real',$field_type[$xcol]))
                         {
                                   if(!mb_stristr2($field_name[$xcol],'_$'))
                                   {$row=$grid23->appendChild($domg->createElement($trow));}
                                   if(mb_stristr2($field_name[$xcol],'_$'))
                                   {$row=$grid24->appendChild($domg->createElement($trow));}
                                        $row->setAttribute('align-r',"");
                                        if($tsuma[$xcol]==0 and mb_stristr2('.vtas.clie.comp.prov.retc.retp',$modu))
                                        $row->setAttribute('hide',"");
                              
                                   $field_namet=strtoupper($field_name[$xcol]);
                                   $field_namet=str_replace('_HIDE','',$field_namet);
                                   $col=$row->appendChild($domg->createElement($tcol));
//                                         $col->setAttribute('width',"20%");
                                        $col->setAttribute('bold',"");
//                                         $col->setAttribute('align-r',"");
                                        $div=$col->appendChild($domg->createElement('div',$field_namet));
                                   $col=$row->appendChild($domg->createElement($tcol));
//                                         $col->setAttribute('align-r',"");
//                                         $div=$col->appendChild($domg->createElement('div',number_format($tfoot[$xcol],2)));
                                        $div=$col->appendChild($domg->createElement('div',number_format($tsuma[$xcol],2)));
                                   
                         }
                         
                         
                         
//                          $xdatosarriba='';
                    }
               }
          }
          
//                          echo '<br>=======';
               if(!mb_stristr2('.cccred',$info))
               if($modu=='cxco' or $modu=='cxpa')
               {
                    if($modu=='cxco'){$doca='AC';}
                    if($modu=='cxpa'){$doca='AP';}
                    $anticipo=calc_anticipo($doca,$enti,$fecha2);
                    
                    if($anticipo!=0)
                    {
                    $row=$grid23->appendChild($domg->createElement($trow));
                    $row->setAttribute('align-r',"");
                         $col=$row->appendChild($domg->createElement($tcol,'ANTICIPO'));
                         $col->setAttribute('bold',"");
                         $col=$row->appendChild($domg->createElement($tcol,''));
                         $div=$col->appendChild($domg->createElement("a",number_format($anticipo,2)));
                         
                              $href='';
                              $href.='?scri=info_modu3';
                              $href.='&modu='.$modu;
                              $href.='&fecha1='.$fecha1x;
                              $href.='&fecha2='.$fecha2x;
                              $href.='&enti='.$enti;
//                               $href.='&tsaldo=9';
                              $href.='&info='.'ccanti';
                              $div->setAttribute("href",$href);
                         
                         
//                          $col->setAttribute('bold',"");
                    }
               }
                    
          
          
          
     }



     if(mb_stristr2('.ttssff.ttssaa.ttsfcc.ttsscc',$info))
     {
          $xdatosarriba='';
          $row=$grid23->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','ACTIVOS'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_1activo,2)));
          
          $row=$grid23->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','PASIVOS'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_2pasivo,2)));
          
          $row=$grid23->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','PATRIMONIO'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_3patrim,2)));
          
          $row=$grid23->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','TOTAL'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_situacion,2)));
               $col->setAttribute('bold',"");
          
     }

     if(mb_stristr2('.ttrrii.ttssaa.ttricc.ttsscc',$info))
     {
          $xdatosarriba='';
          $row=$grid24->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','INGRESOS'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_4ingres*(1),2)));
          
          $row=$grid24->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','COSTOS'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               if($empr0['empr_ctasuper']==1)
               {$div=$col->appendChild($domg->createElement('div',number_format($sum_51costos*(1),2)));}
               if($empr0['empr_ctasuper']!=1)
               {$div=$col->appendChild($domg->createElement('div',number_format($sum_5costos*(1),2)));}
          
          $row=$grid24->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','GASTOS'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               if($empr0['empr_ctasuper']==1)
               {$div=$col->appendChild($domg->createElement('div',number_format($sum_52gastos*(1),2)));}
               if($empr0['empr_ctasuper']!=1)
               {$div=$col->appendChild($domg->createElement('div',number_format($sum_6gastos*(1),2)));}
          
          
          if($sum_7otrosi !=0)
          {
          $row=$grid24->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','OTROS INGRESOS'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_7otrosi*(1),2)));
          }
          
          if($sum_7otrosg !=0)
          {
          $row=$grid24->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','OTROS GASTOS'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_7otrosg*(1),2)));
          }
          
          if($sum_8otrosg !=0)
          {
          $row=$grid24->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','OTROS GASTOS'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_8otrosg*(1),2)));
          }
          
          $row=$grid24->appendChild($domg->createElement($trow));
               $row->setAttribute('align-r',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div','RESULTADO'));
               $col->setAttribute('bold',"");
          $col=$row->appendChild($domg->createElement($tcol));
               $div=$col->appendChild($domg->createElement('div',number_format($sum_resultado*(1),2)));
               $col->setAttribute('bold',"");
          
     }



     if($info=='iikrdx' and $tsaldo==6 and $ssnega==0){$domg = new DOMDocument();}
     if($info=='ccmovi' and $tsaldo==6 and $ssnega==0){$domg = new DOMDocument();}
     if($info=='cpmovi' and $tsaldo==6 and $ssnega==0){$domg = new DOMDocument();}


     $root->setAttribute('time2',date('H:i:s'));


     if($info=='vtrpm1')
     {
          msql_data_seek($zreso,0);
          $file_content='';

          for($xrow=0; $xrow < msql_num_rows($zreso); $xrow++)
          {
               $asoc=msql_fetch_assoc($zreso);
               if(!empty($asoc['reg_san']))
               {
                    $file_content.=trim($asoc['reg_san']).'!';
                    $file_content.=trim($asoc['nom_com']).'!';
                    $file_content.='!!!';
                    $file_content.=trim($asoc['cod_pre']).'!';
                    $file_content.=trim($asoc['pre_com']).'!';
                    $file_content.='SI!';
                    $file_content.=number_format($asoc['pre_fac'],2,'.','').'!';
                    $file_content.=number_format($asoc['pre_vta'],2,'.','').'!';
                    $file_content.=number_format($asoc['undds'],0,'.','').'!';
                    $file_content.=number_format($asoc['fracc'],0,'.','').'!';
//                     $file_content.='NA!';
                    $file_content.=$eol;
               }
          }
          if(!empty($zfile))
          {file_put_contents($zfile,$file_content);}
     }

//           $grid_main->setAttribute('hora_fin',date('H:i:s'));

//           $serializado = serialize($domg);
//           $tamanoEnBytes = strlen($serializado);
//           $grid_main->setAttribute('bytes',$tamanoEnBytes);


$html=$domg->saveXML();

if($json_ok==1)
{
     $xml = simplexml_load_string($html);
     $json = json_encode($xml);
     $type='json';
     echo $json;
}



// if(empty($blog_info))
{
     $msc_xls = microtime(true);
     
     if(!empty($xlsf))
     {include('ele_down_xls.php');}

     if(!empty($xlsf) and $zeus==1)
     {include('ele_down_zeus.php');}

     if(!empty($xlsf) and $fsoft==1)
     {include('ele_down_fsoft.php');}

     if(!empty($xlsf) and $srid==1)
     {
          include('ele_down_sridr.php');
          include('ele_down_sridi.php');
     }
     
     $msc_xls = microtime(true)-$msc_xls;
     $msc_xls=round($msc_xls,2);
     
}


// var_dump2($st_count);

if($modu=='hcli')
{
//      $html=str_replace('size60','',$html);
//      $html=str_replace('size80','',$html);
//      $html=str_replace('nowrap','',$html);
}
if(empty($blog_info))
{if($type=='html'){file_put_contents($file_html_pdf,$html);}}

if($type=='html' or $type=='xml'){echo $html;}

$msc_grid = microtime(true)-$msc_grid;
$msc_grid=round($msc_grid,2);

$date_grid2=date('H:i:s');

echo '<div hide>';
echo '<br>==> t1 : '.$date_grid1;
echo '<br>==> t2 : '.$date_grid2;
echo '<br>==> xls : '.$msc_xls;
echo '<br>==> grid : '.$msc_grid;
echo '</div>';
// var_dump($tfootcc);
// $array = json_decode($json,TRUE);

// var_dump($GLOBALS);

?>