<?php
// SQL_INFO FIELDS     
// FIELDS     
//      $fields='*, ';

$char_unibod='_u';
if($cost=='true'){$char_unibod='_u';}

     // JWIB
     {
          if($info=='rvblog')
          {
               $fields='';
               $fields.='fecha,';
//                $fields.='trty as territ,';
               $fields.='trty_descri as territorio,';
               $fields.='bloq as bl_mz,';
//                $fields.='ndpto as num_dpto,';
               $fields.='ndptoA as num_dpto,';
//                $fields.='lpad(ndpto*1,3,"0") as num_dptob,';
//                $fields.='visita as tipo,';
               $fields.='visita as visita_hide,';
               
               $fields.='visita_icon as tipo,';
               $fields.='persona,';
               $fields.='etario,';
               $fields.='tema,';
               $fields.='pregunta,';
               $fields.='publicacion,';
               $fields.='observacion,';
               $fields.='publicador,';
               $fields.='status as st,';
               
          }
          
          if($info=='rvresu')
          {
               $fields='';
               $fields.='trty_descri as territorio,';
               $fields.='bloq as bl_mz,';
               $fields.='max(fecha) as fecha,';
               $fields.='sum(nc) as nc,';
               $fields.='sum(vi) as vi,';
               $fields.='sum(nt) as nt,';
               $fields.='"Asigna" as asigna,';
               $fields.='status as st,';
               $fields.='cong as cong_hide,';
               $fields.='trty as trty_hide,';
               $fields.='bloq as bloq_hide,';
               
          }
          
          if($info=='rvdeta')
          {
               $fields='';
               $fields.='fecha,';
               $fields.='trty_descri as territorio,';
               $fields.='bloq as bl_mz,';
               $fields.='ndpto as n_dpto,';
//                $fields.='visita,';
               $fields.='visita as visita_hide,';
               
               $fields.='visita_icon as tipo,';
               
               $fields.='persona,';
               $fields.='etario_icon as etario,';
               $fields.='tema,';
//                $fields.='concepto,';
               $fields.='pregunta,';
               $fields.='public,';
               $fields.='publicador,';
//                $fields.='(vi) as vi,';
//                $fields.='(nc) as nc,';
//                $fields.='(nt) as nt,';
//                $fields.='"Asigna" as asigna,';
               $fields.='status as st,';
               $fields.='cong as cong_hide,';
               $fields.='trty as trty_hide,';
               $fields.='bloq as bloq_hide,';
               
          }
          

          if($info=='rtblog')
          {
               $fields='';
               $fields.='fecha,';
//                $fields.='docu,';
//                $fields.='ptoe,';
               $fields.='numero,';
//                $fields.='trty as num_territ,';
               $fields.='trty_descri as territorio,';
               $fields.='trty_referencia as referencia,';
               $fields.='vence,';
               $fields.='asignado,';
//                $fields.='"enviar" as wsapp,';
               $fields.='b_o,';
               $fields.='status as st,';
               $fields.='cong as cong_hide,';
               $fields.='trty as trty_hide,';
               $fields.='ptoe as ptoe_hide,';
               
               
          }
          
          if($info=='rtresu')
          {
               $fields='';
               $fields.='(fecha) as fecha,';
//                $fields.='numero,';
               $fields.='trty_grupo as grupo,';
               $fields.='trty_descri as territorio,';
               $fields.='vence,';
               $fields.='asignado,';
//                $fields.='concat(b_e,"-",b_o) as aa,';
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
               $fields.='status as st,';
               $fields.='cong as cong_hide,';
               $fields.='trty as trty_hide,';
               
          }
          
          if($info=='rtdeta')
          {
               $fields='';
               $fields.='docu,';
               $fields.='fecha,';
               $fields.='numero,';
               $fields.='trty_descri as territorio,';
               $fields.='vence,';
               $fields.='asignado,';
               $fields.='status as st,';
               $fields.='cong as cong_hide,';
               $fields.='trty as trty_hide,';
//                $fields.='docu as docu_hide,';
//                $fields.='ptoe as ptoe_hide,';
               
          }
          
          
          if($info=='rtttff')
          {
               $fields='';
//                $fields.='docu,';
//                $fields.='numero,';
               $fields.='trty_descri as territorio,';
               $fields.='asignado,';
               $fields.='fecha as inicio,';
               $fields.='vence as final,';
               
               $fechaw1=date('Y-m-d',strtotime($fecha1.''));
               if(date('w',strtotime($fechaw1))!=1)
               {$fechaw1=date('Y-m-d',strtotime($fechaw1.' last monday'));}
               while($fechaw1<$fecha2)
               {
                    $fechaw2=date('Y-m-d',strtotime($fechaw1.'+6 days'));
                    $fields.='case when "'.$fechaw1.'">=fecha and "'.$fechaw1.'"<=vence then "&#'.mb_ord('🏁').';" else " _" end as s_'.date('W',strtotime($fechaw1)).', ';
                    $fechaw1=date('Y-m-d',strtotime($fechaw1.'+7 days'));
               }
               
//                $fechaw1=$fecha1;
//                while($fechaw1<$fecha2)
//                {
//                     $fields.='case when "'.$fechaw1.'">=fecha and "'.$fechaw1.'"<=vence then "&#'.mb_ord(🏁).';" else " _" end as d_'.date('d',strtotime($fechaw1)).', ';
//                     $fechaw1=date('Y-m-d',strtotime($fechaw1.'+1 days'));
//                }
               
               
               
               $fields.='status as st,';
               $fields.='cong as cong_hide,';
               $fields.='trty as trty_hide,';
               
          }
          
          
          
          
          if($info=='mmresu')
          {
               $fields='';
               $fields.='nombre1 as nombre,';
               $fields.='substring(max(fecha),1,7) as fecha,';
//                $fields.='fsema as fecha,';
               $fields.='sum(lb) as lb,';
               $fields.='max(f_lb) as f_lb,';
               $fields.='sum(m1) as m1,';
               $fields.='max(f_m1) as f_m1,';
               $fields.='sum(m2) as m2,';
               $fields.='max(f_m2) as f_m2,';
               $fields.='sum(m3) as m3,';
               $fields.='max(f_m3) as f_m3,';
               $fields.='sum(m4) as m4,';
               $fields.='max(f_m4) as f_m4,';
               $fields.='status as st,';
               
          }
          
          if($info=='mmdeta')
          {
               $fields='';
               $fields.='nombre1 as nombre,';
               $fields.='fecha,';
               $fields.='docu_descri,';
               $fields.='status as st,';
               
          }
          
          if($info=='asresu')
          {
               $fields='';
               $fields.='nombre1 as nombre,';
               $fields.='substring(max(fecha),1,7) as fecha,';
               $fields.='sum(lb) as lb,';
               $fields.='max(f_lb) as f_lb,';
               $fields.='sum(a1) as a1,';
               $fields.='max(f_a1) as f_a1,';
               $fields.='sum(a2) as a2,';
               $fields.='max(f_a2) as f_a2,';
               $fields.='sum(a3) as a3,';
               $fields.='max(f_a3) as f_a3,';
               $fields.='sum(a4) as a4,';
               $fields.='max(f_a4) as f_a4,';
               $fields.='status as st,';
               
          }
          
          if($info=='asdeta')
          {
               $fields='';
               $fields.='nombre1 as nombre,';
               $fields.='fecha,';
               $fields.='status as st,';
               
          }
          
          if($info=='vcresu')
          {
               $fields='';
               $fields.='nombre1 as nombre,';
               $fields.='substring(max(fecha),1,7) as fecha,';
               $fields.='sum(lb) as lb,';
               $fields.='max(f_lb) as f_lb,';
               $fields.='sum(a1) as a1,';
               $fields.='max(f_a1) as f_a1,';
               $fields.='sum(a2) as a2,';
               $fields.='max(f_a2) as f_a2,';
               $fields.='sum(a3) as a3,';
               $fields.='max(f_a3) as f_a3,';
               $fields.='sum(a4) as a4,';
               $fields.='max(f_a4) as f_a4,';
               $fields.='status as st,';
               
          }
          
          if($info=='vcdeta')
          {
               $fields='';
               $fields.='nombre1 as nombre,';
               $fields.='fecha,';
               $fields.='status as st,';
               
          }
          
          if($info=='jwmdc0')
          {
               $fields='';
     //           $fields.='fecha,';
               $fields.='fecha1 as desde,';
               $fields.='fecha2 as hasta,';
               $fields.='ndia_descri as dia,';
               $fields.='left(hora,5) as hora,';
     //           $fields.='modo,';
               $fields.='modo_icon,';
               $fields.='lreu,';
               $fields.='nombre1 as conductor,';
               $fields.='nombre2 as auxiliar,';
               $fields.='dia_des as dia_hide,';
     //           $fields.='concepto as notas,';
               $fields.='concepto_t as notas,';
               $fields.='status as st,';
               $fields.='b_o,';
     //           $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
     //           $fields.='convert(idnum1,char) as idn,';
     //           $fields.='ifnull(iuser,0) as usr,';
     //           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          

          }

          if($info=='jwmdc1')
          {
               $fields='';
               $fields.='fecha,';
     //           $fields.='ndia_descri as dia,';
               $fields.='dia_des as dia,';
               $fields.='left(hora,5) as hora,';
     //           $fields.='modo,';
               $fields.='modo_icon,';
               $fields.='lreu,';
               $fields.='nombre1 as conductor,';
               $fields.='nombre2 as auxiliar,';
               $fields.='fecha1 as desde,';
               $fields.='fecha2 as hasta,';
               $fields.='dia_des as dia_hide,';
     //           $fields.='concepto as notas,';
               $fields.='concepto_t as notas,';
               $fields.='status as st,';
               $fields.='b_o,';
     //           $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
     //           $fields.='convert(idnum1,char) as idn,';
     //           $fields.='ifnull(iuser,0) as usr,';
     //           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          

          }


          
//           echo '===='.$info;
          if($info=='mcprog')
          {
//                $sql_lreu='select distinct lreu,lreu_descri from jwmc1 ';
//                $sql_lreu.='left join lreu0 on lreu=lreu_codigo ';
//                $sql_lreu.='where cong="'.$cong.'" ';
// //                if(!empty($docu))
// //                {$sql_lreu.='and docu="'.$docu.'" ';
//                $sql_lreu.='order by lreu ';
//                $res_lreu=msql_query($sql_lreu,$link_data);
               
//                echo '<br>===-----'.$sql_lreu;
          
               $fields='';
//                $fields.='concat(dia,"/",left(mes_des,3)) as dia,';
               $fields.='sema as semana,';
//                $fields.='sema as semana,';
               
               
//                $fields.='ndia_descri as dia,';
               $fields.='left(hora,5) as hora,';
               $fields.='lugar,';
//                $fields.='trty_descri as territorio,';
               $fields.='trty_sector as territorio,';
               $fields.='dia_des as dia_hide,';
//                $fields.='concepto_t as notas,';
               
               
               $fields.='max(case when dia_n=1 then concat(nombre1," / ",nombre2) end) as LUNES, ';
               $fields.='max(case when dia_n=2 then concat(nombre1," / ",nombre2) end) as MARTES, ';
               $fields.='max(case when dia_n=3 then concat(nombre1," / ",nombre2) end) as MIERCOLES, ';
               $fields.='max(case when dia_n=4 then concat(nombre1," / ",nombre2) end) as JUEVES, ';
               $fields.='max(case when dia_n=5 then concat(nombre1," / ",nombre2) end) as VIERNES, ';
               $fields.='max(case when dia_n=6 then concat(nombre1," / ",nombre2) end) as SABADO, ';
               $fields.='max(case when dia_n=7 then concat(nombre1," / ",nombre2) end) as DOMINGO, ';
               
               if(1==2)
               if(msql_num_rows($res_lreu)!=0)
               while($aso_lreu=msql_fetch_assoc($res_lreu))
               {
                    $xlreu=trim($aso_lreu['lreu']);
                    $xlreu_descri=trim($aso_lreu['lreu_descri']);
                    $xlreu_descri=str_replace('.','_',$xlreu_descri);
                    $xlreu_descri=str_replace(' ','_',$xlreu_descri);
                    
                    $fields.='(case when docu="MDC5" and  lreu="'.$xlreu.'" then concat(nombre1," / ",nombre2) end) as '.$xlreu_descri.', ';
                    $fields.='(case when docu!="MDC5" and  lreu="'.$xlreu.'" then nombre1 end) as '.$xlreu_descri.', ';
               }
               
               $fields.='status as st,';
               $fields.='b_o,';
               
          }
          
          
     }


     // PLANIFICACION
     {
          

          
          
     if($info=='plresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          $fields.='dia_des as dia_hide,';
//           $fields.='csub1 as csub,';
          $fields.='user_descri as usuario,';
          $fields.='left(enti,10) as enti,';
          $fields.='left(enti_descri,30) as cliente,';
          $fields.='asub,';
          $fields.='asub_descri as servicio,';
          $fields.='horas,';
          $fields.='empr1 as empresa,';
          $fields.='valorpla as valor,';
          $fields.='concepto_t as concepto,';
          $fields.='status as st,';
          $fields.='b_o,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
          
     }

     if($info=='pldet2')
     {
          $fields='';
          $fields.='asub,';
          $fields.='asub_descri as actividad,';
          
          $fields.='cant as horas,';
//           $fields.='item_umdd as U_Mdd,';
          $fields.='puni as costo,';
          $fields.='empl,';
          $fields.='empl_descri as empleado,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
//           $fields.='b_o,';
     }
          
          
          
          
     }
     
     // BITACORA / AVISOS
     {
          if($info=='btresu')
          {
               $fields='';
               $fields.='case when docu="BTC1" then "&#129001;" when docu="BTC2" then "&#128998;" else "" end as _d_,';
               $fields.='docu as docu_hide,';
               $fields.='dia_d as dia,';
               $fields.='fecha as fecha,';
               $fields.='hora as hora,';
               
               $fields.='enti,';
               $fields.='enti_descri as nombre,';
               
               $fields.='plvh,';
               $fields.='plvh_mrca as mrca,';
               $fields.='plvh_clor1 as color,';
               
               $fields.='concepto as motivo,';
               $fields.='ppdd_descri as destino,';
               $fields.='detalle as notas,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
               $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
               $fields.='convert(idnum1,char) as idn,';
               
          }
          
          if($info=='bthist')
          {
               $fields='';
               $fields.='case when docu="BTC1" then "&#129001;" when docu="BTC2" then "&#128998;" else "" end as _d_,';
               $fields.='docu as docu_hide,';
               $fields.='dia_d as dia,';
               $fields.='fecha as fecha,';
               $fields.='hora as hora,';
               
               $fields.='enti,';
               $fields.='enti_descri as nombre,';
               
               $fields.='plvh,';
               $fields.='plvh_mrca as mrca,';
               $fields.='plvh_clor1 as color,';
               
               
               $fields.='concepto as motivo,';
               $fields.='ppdd_descri as destino,';
//                $fields.='ppdd_wsapp1 as wsapp1,';
//                $fields.='ppdd_wsapp2 as wsapp2,';
               $fields.='detalle as notas,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
               $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
               $fields.='convert(idnum1,char) as idn,';
               
          }
          
          if($info=='btblog')
          {
               $fields='';
               
//                $fields.='case when docu="BTC1" then "&#9660;" when docu="BTC2" then "&#9650;" else "" end as _d_,';
//                $fields.='case when docu="BTC1" then "&#129001;" when docu="BTC2" then "&#129000;" else "" end as _d_,';
               $fields.='case when docu="BTC1" then "&#129001;" when docu="BTC2" then "&#128998;" else "" end as _d_,';
               $fields.='docu as docu_hide,';
               $fields.='dia_d as dia,';
               $fields.='fecha as fecha,';
               $fields.='hora as hora,';

               $fields.='enti as cedula,';
               $fields.='enti_descri as nombre,';
               
               $fields.='plvh,';
               $fields.='plvh_mrca as mrca,';
               $fields.='plvh_clor1 as color,';
//                $fields.='plvh_propietario as dueÑo,';
//                $fields.='ppdd as destino,';
               $fields.='concepto as motivo,';
               $fields.='ppdd_descri as destino,';
//                $fields.='ppdd_wsapp1 as wsapp1,';
//                $fields.='ppdd_wsapp2 as wsapp2,';
               $fields.='detalle as notas,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
               $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
               $fields.='convert(idnum1,char) as idn,';
               
          }
          
          if($info=='btdet2')
          {
               $fields='';
               $fields.='docu as docu_hide,';
               $fields.='dia_d as dia,';
               $fields.='fecha as fecha,';
               $fields.='hora as hora,';
               $fields.='plvh,';
               $fields.='plvh_mrca as mrca,';
               $fields.='plvh_clor1 as color,';
//                $fields.='plvh_propietario as dueÑo,';
               $fields.='enti,';
               $fields.='enti_descri as nombre,';
//                $fields.='ppdd as destino,';
               $fields.='ppdd_descri as destino,';
               $fields.='concepto as motivo,';
               $fields.='detalle as notas,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
               $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
               $fields.='convert(idnum1,char) as idn,';
               
          }

          
          if($info=='btinve')
          {
               $fields='';
               $fields.='case when docu="BTC1" then "&#129001;" when docu="BTC2" then "&#128998;" else "" end as _d_,';
               $fields.='docu as docu_hide,';
               $fields.='dia_d as dia,';
               $fields.='fecha as fecha,';
               $fields.='hora as hora,';
               
               $fields.='enti,';
               $fields.='enti_descri as nombre,';
               
               $fields.='plvh,';
               $fields.='plvh_mrca as mrca,';
               $fields.='plvh_clor1 as color,';
               
               
               $fields.='concepto as motivo,';
               $fields.='ppdd_descri as destino,';
//                $fields.='ppdd_wsapp1 as wsapp1,';
//                $fields.='ppdd_wsapp2 as wsapp2,';
               $fields.='detalle as notas,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
               $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
               $fields.='convert(idnum1,char) as idn,';
               
          }
          
          
          
     }     
     
     // ACCESOS
     {
     if($info=='acdeta')
     {
          $fields='';
//           $fields.='fecha,';
          $fields.='docd_tipo as tipo,';
          $fields.='upper(docd_tabla) as modulo,';
          $fields.='docum,';
          $fields.='docd_descri as documento,';
//           $fields.='convert(user_codigo,char) as codigo,';
          $fields.='numero,';
          $fields.='user_tipo as tipo,';
//           $fields.='user_email as email,';
          $fields.='user_descri as usuario,';
//           $fields.='ptoe as ptoe_hide,';
          $fields.='ifnull(nuev,0) as nuev_check,';
          $fields.='ifnull(modi,0) as modi_check,';
          
          $fields.='ifnull(cons,0) as cons_check,';
          $fields.='ifnull(info,0) as info_check,';
          
          $fields.='ifnull(apro,0) as apro_check,';
          
          $fields.='ifnull(anul,0) as anul_check,';
          $fields.='ifnull(elim,0) as elim_check,';
//           if(is_numeric($enti)==0 or strlen($enti)<10)
          $fields.='status as st,';
//           $fields.='b_o,';
//           $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
//           $fields.='convert(idnum1,char) as idn,';
//           $fields.='ifnull(iuser,0) as usr,';
          
     }

          
          
     }
     
     // NOMINAS
     {
          if($info=='suresu')
          {
               $fields.='fecha2 as fecha,';
               $fields.='docu,';
//                $fields.='docu_descri,';
               $fields.='numero,';
               $fields.='enti,';
//                $fields.='left(enti_descri,30) as empleado,';
               $fields.='left(empl_descri,30) as empleado,';
               $fields.='ptoe as ptoe_hide,';
               $fields.='sueldo,';
               $fields.='poranti as porc_anti,';
               $fields.='case when ifnull(poranti,0)>0 then sueldo*poranti/100 else valanti end as anticipo,';
//                $fields.='valanti,';
               $fields.='alimentacion as alime,';
               $fields.='movilizacion as movil,';
               $fields.='comision as     comis,';
               $fields.='otros,';
               $fields.='total,';
               $fields.='de13,';
               $fields.='de14,';
               $fields.='fres,';
//                $fields.='dia_des as dia_hide,';
               $fields.='csub as csub,';
               $fields.='cargo,';
               $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';
               
          }
          
//           if($info=='sublog')
          if($info=='sudeta' or $info=='sublog')
          {
               $fields='';
               $fields.='fecha2 as fecha,';
               $fields.='docu,';
//                $fields.='docu_descri,';
               $fields.='numero,';
               $fields.='enti,';
//                $fields.='left(enti_descri,30) as empleado,';
               $fields.='left(empl_descri,30) as empleado,';
               $fields.='ptoe as ptoe_hide,';
               $fields.='sueldo,';
//                $fields.='poranti as porc_anti,';
//                $fields.='valanti as anticipo,';
               $fields.='poranti as porc_anti,';
               $fields.='case when ifnull(poranti,0)>0 then sueldo*poranti/100 else valanti end as anticipo,';
               $fields.='alimentacion as alime,';
               $fields.='movilizacion as movil,';
               $fields.='comision as     comis,';
               $fields.='otros,';
               $fields.='total,';
               $fields.='de13,';
               $fields.='de14,';
               $fields.='fres,';
//                $fields.='dia_des as dia_hide,';
               $fields.='csub as csub,';
               $fields.='cargo,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
               $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';

          }

          if($info=='sudet2')
          {
               $fields='';
               $fields.='fecha2 as fecha,';
//                $fields.='docu,';
//                $fields.='docu_descri,';
               $fields.='numero,';
               $fields.='enti,';
//                $fields.='left(enti_descri,30) as empleado,';
               $fields.='left(empl_descri,30) as empleado,';
               $fields.='ptoe as ptoe_hide,';
               $fields.='sueldo,';
//                $fields.='poranti as porc_anti,';
//                $fields.='valanti as anticipo,';
               $fields.='poranti as porc_anti,';
               $fields.='case when ifnull(poranti,0)>0 then sueldo*poranti/100 else valanti end as anticipo,';
               $fields.='alimentacion as alime,';
               $fields.='movilizacion as movil,';
               $fields.='comision as     comis,';
               $fields.='otros,';
               $fields.='total,';
               $fields.='de13,';
               $fields.='de14,';
               $fields.='fres,';
//                $fields.='dia_des as dia_hide,';
               $fields.='csub as csub,';
               $fields.='cargo,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';

          }

          
          if($info=='nodeta')
          {
               $fields='';
               $fields.='fecha,';
               $fields.='numero,';
               $fields.='empl,';
               $fields.='left(empl_descri,30) as empleado,';
               $fields.='ptoe as ptoe_hide,';
               $fields.='cant,';
               $fields.='puni,';
               $fields.='total,';
               $fields.='if(nvdd_tipo=1,total,0) as ingresos,';
               $fields.='csub as csub,';
//                $fields.='cargo,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';

          }
          
          if($info=='nodet2')
          {
               $fields='';
               $fields.='fecha,';
               $fields.='numero,';
               $fields.='empl,';
               $fields.='left(empl_descri,30) as empleado,';
               $fields.='ptoe as ptoe_hide,';
               $fields.='nvdd,';
               $fields.='nvdd_descri as novedad,';
               $fields.='cant,';
               $fields.='puni as valor,';
               $fields.='total,';
               $fields.='if(nvdd_tipo=1,total,0) as ingresos,';
               $fields.='if(nvdd_tipo=2,total,0) as descntos,';
               $fields.='if(nvdd_tipo=3,total,0) as provisio,';
               $fields.='csub as csub,';
//                $fields.='cargo,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';

          }
          
          
          if($info=='noblog')
          {
               $fields='';
               $fields.='fecha,';
               $fields.='numero,';
               $fields.='empl,';
               $fields.='left(empl_descri,30) as empleado,';
               $fields.='ptoe as ptoe_hide,';
               $fields.='nvdd,';
               $fields.='nvdd_descri as novedad,';
               $fields.='cant,';
               $fields.='puni as valor,';
               $fields.='total,';
               $fields.='if(nvdd_tipo=1,total,0) as ingresos,';
               $fields.='if(nvdd_tipo=2,total,0) as descntos,';
               $fields.='if(nvdd_tipo=3,total,0) as provisio,';
               $fields.='csub as csub,';
//                $fields.='cargo,';
               
               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
               $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';

          }
          
          
          
     }
     
     // ACTIVIDADES
     {
          
     if($info=='atblog')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          $fields.='dia_des as dia_hide,';
          $fields.='csub1 as csub,';
          $fields.='user_descri as usuario,';
//           $fields.='empr2 as empr,';
          $fields.='left(enti_descri,30) as cliente,';
          $fields.='docum as docum_hide,';
          $fields.='ptoem as ptoem_hide,';
          $fields.='numer*1 as numer,';
          $fields.='concat(ifnull(atvd_descri,"")," /",ifnull(asub_descri,"")) as actividad, ';
          $fields.='detalle_t as concepto,';
          $fields.='horas,';
          $fields.='puni as valor,';
          $fields.='total,';
          $fields.='status as st,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
          
     }

     if($info=='atresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          $fields.='dia_des as dia_hide,';
          $fields.='csub1 as csub,';
          $fields.='user_descri as usuario,';
//           $fields.='left(enti_descri,30) as cliente,';
//           $fields.='lsub_descri as linea,';
//           $fields.='concat(ifnull(atvd_descri,"")," /",ifnull(asub_descri,"")) as actividad, ';
          $fields.='horas,';
          $fields.='total,';
          $fields.='detalle_t as concepto,';
          $fields.='status as st,';
//           $fields.='if(b_o>0,1,0) as b_o,';
          $fields.='b_o,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
          
     }
          
          
     if($info=='atxsem')
     {
          $fields='';
//           $fields.='fecha,';
//           $fields.='docu,';
//           $fields.='ptoe as ptoe_hide,';
//           $fields.='numero,';
//           $fields.='dia_des as dia_hide,';
//           $fields.='csub1 as csub,';
//           $fields.='user_descri as usuario,';
//           $fields.='horas,';
//           $fields.='total,';
//           $fields.='detalle as concepto,';
//           $fields.='status as st,';
//           $fields.='b_o,';
//           $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          

          $fields.='sum(idnum_c) as _c_,';
          $fields.='asema as A_sem,';
          $fields.='min(fecha) as desde,';
          $fields.='max(fecha) as hasta,';
          $fields.='sema,';
          $fields.='user_descri as usuario,';
          
          
          
     }
          
     if(mb_stristr2('.atxsem',$info))
     { 
//           $xround=6;
          $fields.='sum(case when dia_n=1 then total end) as LUN,';
          $fields.='sum(case when dia_n=2 then total end) as MAR,';
          $fields.='sum(case when dia_n=3 then total end) as MIE,';
          $fields.='sum(case when dia_n=4 then total end) as JUE,';
          $fields.='sum(case when dia_n=5 then total end) as VIE,';
          $fields.='sum(case when dia_n=6 then total end) as SAB,';
          $fields.='sum(case when dia_n=0 then total end) as DOM,';
          $fields.='sum(total) as total,';
     }
          
          
     }
     



     // HISTORIA CLINICA
     {
          
     if($info=='hcblog')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
//           $fields.='fecha,';
          $fields.='dia_des as dia_hide,';
          if(is_numeric($enti)==0 or strlen($enti)<10)
          {$fields.='left(enti_descri,30) as cliente,';}
          $fields.='upper(fase) as fase,';
//           $fields.='tempo,';
          $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='status as st,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          
          $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser2,0) as usr,';
          
     }

     if($info=='hcresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          
          if(is_numeric($pcnt)==0 or strlen($pcnt)<10)
          {
               $fields.='left(enti,10) as enti,';
               $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as paciente,';
          }
          
          if($empr0['empr_veterinaria']==1)
          {
               $fields.='enti_nom1 as nombre,';
               $fields.='enti_especie as especie,';
               $fields.='enti_raza as raza,';
               $fields.='enti_color as color,';
          }
          $fields.='upper(fase) as fase,';
//           $fields.='concat(upper(ifnull(fase,""))," : ",ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='dia_des as dia_hide,';
          $fields.='status as st,';
          $fields.='b_o,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
          
     }
          
     if($info=='hcdeta')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
//           if(is_numeric($enti)==0 or strlen($enti)<10)
          if(is_numeric($pcnt)==0 or strlen($pcnt)<10)
          {
               $fields.='left(enti,10) as pcnt,';
               $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as paciente,';
          }
          if($empr0['empr_veterinaria']==1)
          {
               $fields.='enti_nom1 as nombre,';
               $fields.='enti_especie as especie,';
               $fields.='enti_raza as raza,';
               $fields.='enti_color as color,';
          }
          $fields.='upper(fase) as fase,';
//           $fields.='concat(upper(ifnull(fase,""))," : ",ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='dia_des as dia_hide,';
          $fields.='status as st,';
          $fields.='b_o,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
          
     }

     if($info=='hchcli')
     {
          $fields='';
          $fields.='fecha,';
//           $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
//           $fields.='pcnt_edad as pcnt_edad_hide,';
//           if(is_numeric($enti)==0 or strlen($enti)<10)
//           if(is_numeric($pcnt)==0 or strlen($pcnt)<10)
//           {
//                $fields.='left(enti,10) as pcnt,';
//                $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as paciente,';
//           }
          if($empr0['empr_veterinaria']==1)
          {
//                $fields.='enti_nom1 as nombre_hide,';
//                $fields.='enti_especie as especie_hide,';
//                $fields.='enti_raza as raza_hide,';
//                $fields.='enti_color as color_hide,';
          }
          $fields.='upper(fase) as fase,';
//           $fields.='concat(upper(ifnull(fase,""))," : ",ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='dia_des as dia_hide,';
          $fields.='status as st,';
//           $fields.='b_o,';
          $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';          
//           $fields.='convert(idnum1,char) as idn,';
//           $fields.='ifnull(iuser,0) as usr,';
          
     }
          
          

     }
     
     // ORDEN TRABAJO
     {
          
//           echo '====='.$info;
     if($info=='otblog')
     {
          $fields='';
          $fields.='fecha1,';
          $fields.='hora1,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
//           $fields.='fecha,';
          $fields.='dia_des as dia_hide,';
//           if(is_numeric($enti)==0 or strlen($enti)<10)
//           {$fields.='left(enti_descri,30) as paciente,';}
          $fields.='plvh as placa,';
          
          
          $fields.='upper(fase) as fase,';
          $fields.='datos,';
          $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='if(docu like "OT%","u_f","") as u_f,';
          $fields.='status as st,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          
          $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser2,0) as usr,';
          
     }

//           echo '==='.$info;
          
     if($info=='otdeta')
     {
          $fields='';
          $fields.='fecha1 as fecha,';
          $fields.='hora1 as hora,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
//           $fields.='fecha,';
          $fields.='dia_des as dia_hide,';
//           if(is_numeric($enti)==0 or strlen($enti)<10)
//           {$fields.='left(enti_descri,30) as paciente,';}
          $fields.='plvh as placa,';
          
          
          $fields.='upper(fase) as fase,';
          $fields.='datos,';
          $fields.='detalle as notas,';
//           $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='left(mcnc_descri, locate(" ",mcnc_descri)+10) as mecanico,';
          $fields.='if(docu like "OT%","u_f","") as u_f,';
          $fields.='status as st,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          
          $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser2,0) as usr,';
          
     }

     if($info=='otdet2')
     {
          $fields='';
          $fields.='fecha1 as fecha,';
          $fields.='hora1 as hora,';
//           $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
//           $fields.='numero,';
//           $fields.='fecha,';
          $fields.='dia_des as dia_hide,';
//           if(is_numeric($enti)==0 or strlen($enti)<10)
//           {$fields.='left(enti_descri,30) as paciente,';}
//           $fields.='plvh as placa,';
          
          
          $fields.='upper(fase) as fase,';
          $fields.='item as item_hide,';
          $fields.='detalles,';
//           $fields.='subtot+1 as subtotal,';
//           $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          
          
          $fields.='cant,';
//           $fields.='puni,';
//           $fields.='dcto,';
//           $fields.='tiva,';
//           $fields.='comi,';
          $fields.='item_ttrf as trf,';
          $fields.='total,';
          
          $fields.='detalle as notas,';
          
          $fields.='left(mcnc_descri, locate(" ",mcnc_descri)+10) as mecanico,';
          $fields.='if(docu like "OT%","u_f","") as u_f,';
//           $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
//           TIMESTAMPDIFF(HOUR, mi_campo_datetime, NOW()) AS horas_diferencia
          $fields.='if(timestampdiff(HOUR,idate2,now())<(24*2),1,0) as b_o,';
          $fields.='status as st,';
          
          $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser2,0) as usr,';
          
     }

     if($info=='otresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='fecha1 as fecha1_hide,';
          $fields.='hora1 as hora1_hide,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          
//           if(is_numeric($pcnt)==0 or strlen($pcnt)<10)
          {
               $fields.='left(enti,10) as enti,';
               $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
          }
          
          if($empr0['empr_automotriz']==1)
          {
               $fields.='plvh as placa,';
               $fields.='vinn,';
          }
          
          $fields.='upper(fase) as fase,';
//           $fields.='concat(upper(ifnull(fase,""))," : ",ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
          $fields.='dia_des as dia_hide,';
          $fields.='status as st,';
          $fields.='b_o,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
          
     }
          
     if($info=='othtec')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          $fields.='upper(fase) as fase,';
          $fields.='concat(ifnull(item_descri,""),ifnull(notas,"")) as notas,';
//           $fields.='dia_des as dia_hide,';
          $fields.='status as st,';
//           $fields.='b_o,';
          $fields.='substr(ifnull(idate2,"2000-01-01 00:00:00"),3) as idate,';          
//           $fields.='convert(idnum1,char) as idn,';
//           $fields.='ifnull(iuser,0) as usr,';
          
     }
          
     }
     
     // VENTAS
     {
     
//      if($info=='vtenti')
     if(mb_stristr2('.vtenti.clenti',$info))
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='zsub as zona,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
     }

     if($info=='vtxiva')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='iva as p_iva,';
     }

     if($info=='vtptov')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='ptov as ptov,';
     }

     if($info=='vtvndd')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='zsub as zona,';
          if(is_numeric($vndd)==0 or strlen($vndd)<10)
          {$fields.='left(vndd,10) as vndd,';}               
          
          $fields.='vndd_descri as vendedor,';
//           $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
     }

//      if($info=='vtitem')
     if(mb_stristr2('.vtitem.clitem',$info))
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='item,';
          $fields.='item_descri as descripcion,';
     }

     if($info=='vtrpm1')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          $fields.='ifnull(item_pvp1,0) as pvp1,';
//           $fields.='item_umdd,';
          $fields.='case when ifnull(item_umdd,"")="" then "UNID" else item_umdd end as umdd,';
     }

     if($info=='vtlsub')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='lsub_descri as lineas,';
     }

     if($info=='vtxano')
     {
//           $xround=6;
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='left(fecha,4) as anio,';
     }


     if($info=='vtxmes')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='left(fecha,7) as mes,';
     }

     if($info=='vtxsem')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='asema as A_sem,';
          $fields.='min(fecha) as desde,';
          $fields.='max(fecha) as hasta,';
          $fields.='sema,';
          
     }

     if($info=='vtxfec')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='fecha,';
          $fields.='dia_d as dia,';
          
     }

     if($info=='vtenxm')
     {
//           $xround=6;
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='zsub as zona,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
          
     }

     if($info=='vtvnxm')
     {
//           $xround=6;
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='zsub as zona,';
          $fields.='left(vndd,10) as vndd,';
          $fields.='vndd_descri as vendedor,';
//           $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
          
     }
     
     
     if($info=='vtanxm')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='zsub as zona,';
          $fields.='left(fecha,4) as anio,';
     }
     
                   
     if($info=='vtitxm')
     {
//           $xround=6;
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
     }
     
     if($info=='vtlsxm')
     {
//           $xround=6;
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='lsub_descri as lineas,';
          
     }
     
     if(mb_stristr2('.vtenxm.vtitxm.vtvnxm.vtlsxm.',$info))
     { 
          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               $fields.='sum(case when left(fecha,7)="'.$xames.'" then tsubt-tdcto end) as '.$xanio.'_'.$xmes.',';
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
          }
          $fields.='sum(tsubt-tdcto) as total,';
     }
          

     if(mb_stristr2('.vtanxm',$info))
     { 
          for($idx=1; $idx<=12; $idx++)
          {
//                $xround=2;
               $xmes=str_pad($idx,2,'0',STR_PAD_LEFT);
               $fields.='sum(case when substring(fecha,6,2)="'.$xmes.'" then tsubt-tdcto end) as m$_'.$xmes.',';
          }
          $fields.='sum(tsubt-tdcto) as total,';
          $fields.='sum(tsubt-tdcto)/12 as prom,';
     }

          

          
     if(mb_stristr2('.vtxsem',$info))
     { 
//           $xround=6;
          $fields.='sum(case when dia_n=1 then tsubt-tdcto end) as LUN,';
          $fields.='sum(case when dia_n=2 then tsubt-tdcto end) as MAR,';
          $fields.='sum(case when dia_n=3 then tsubt-tdcto end) as MIE,';
          $fields.='sum(case when dia_n=4 then tsubt-tdcto end) as JUE,';
          $fields.='sum(case when dia_n=5 then tsubt-tdcto end) as VIE,';
          $fields.='sum(case when dia_n=6 then tsubt-tdcto end) as SAB,';
          $fields.='sum(case when dia_n=0 then tsubt-tdcto end) as DOM,';
          $fields.='sum(tsubt-tdcto) as total,';
          $fields.='sum(tsubt-tdcto)/7 as prom,';
     }

     if($info=='vtres1' or $info=='clres1')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu as docu_hide,';
          $fields.='ptoe as ptoe_hide,';
          if(empty($ptov))
          {$fields.='ptoe,';}
//           $fields.='ptoe_descri as ptoe,';
          $fields.='numero*1 as numero,';
          $fields.='left(enti,10) as enti,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
     }
          
     // garage inventario post
          
          
     if($info=='vtresu' or $info=='clresu' or $info=='vtcomi')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          if(is_numeric($enti)==0 or strlen($enti)<10)
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
          
     }
          
     if($info=='caresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='left(enti,10) as user,';
          $fields.='user_descri as cliente,';
     }

          
     if($info=='vtdeta' or $info=='cldeta')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
          $fields.='piva as piva_hide,';

          if($empr0['empr_automotriz']==1)
          {
               $fields.='upper(plvh) as plvh,';
               
          }
               
          if($empr0['empr_garage']==1)
          {
               $fields.='upper(plvh) as plvh,';
//                $fields.='plvh_descri as vehiculo,';
//                $fields.='plvh_mrca as marca,';
//                $fields.='plvh_mdlo as modelo,';
//                $fields.='case when plvh_modelo like "% %" then substring(plvh_modelo,1,locate(" ",plvh_modelo,locate(" ",plvh_modelo)+1)) else plvh_modelo end as modelo,';
//                $fields.='case when substring(plvh_modelo,1,locate(" ",plvh_modelo,locate(" ",plvh_modelo)+1))!="" then substring(plvh_modelo,1,locate(" ",plvh_modelo,locate(" ",plvh_modelo)+1)) else plvh_modelo end as modelo,';
               $fields.='substring_index(plvh_modelo," ",2) as modelo, ';
               
//                $fields.='convert(plvh_anio,char) as año,';
               $fields.='plvh_clor as color,';
               $fields.='hora1 as entra,';
//                $fields.='hora2 as sale,';
               $fields.='case when ifnull(stfin,0)=1 then hora2 else "--:--" end as sale,';
//                $fields.='substring(timediff(hora2,hora1),1,5) as tiempo,';
               $fields.='hora12 as tiempo,';
          }
          
          
          
          $fields.='tcant as cant,';
          $fields.='puni as p_uni,';
          $fields.='tsubt as subt,';
          $fields.='tdcto as dcto,';
//          $fields.='subtiva0 as subt_iva0,';
//          $fields.='subtiva as subt_iva,';
          $fields.='tiva as iva,';
//          $fields.='subtice as subt_ice,';
          $fields.='tice as ice,';
          $fields.='saldo as total,';
          
          $fields.='vndd_descri as vendedor,';
          
          
          if($cost=='true')
          {
               $fields.='cuni as c_uni,';
               $fields.='costo,';
               $fields.='renta,';
               $fields.='renta/tsubt*100 as porc_rta,';
          }
          
//           $fields.='claveacc as claveacc_hide,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
     }

          
          
     if($info=='vtdet1' or $info=='cldet1')
     {
          $fields='';
          $fields.='item as item_hide,';
          $fields.='item_descri as producto,';
          
//           $fields.='cant,';
          $fields.='cant as cant_edit,';
//           $fields.='item_umdd as U_Mdd,';
          $fields.='puni as p_unit,';
          $fields.='tiva as iva,';
          $fields.='tice as ice,';
          $fields.='saldo as total,';
          
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
     }
          
          
     if($info=='vtdet2' or $info=='cldet2')
     {
          $fields='';
          $fields.='item,';
          $fields.='item_descri as producto,';

          if($empr0['empr_garage']==1)
          {
               $fields.='upper(plvh) as plvh,';
               $fields.='substring_index(plvh_modelo," ",2) as modelo, ';
               $fields.='plvh_clor as color,';
               $fields.='hora1 as entra,';
               $fields.='case when ifnull(stfin,0)=1 then hora2 else "--:--" end as sale,';
               $fields.='hora12 as tiempo,';
          }
          
          $fields.='cant,';
          $fields.='item_umdd as U_Mdd,';
          $fields.='puni as p_unit,';
          $fields.='tsubt as subt,';
          $fields.='tdcto as dcto,';
          $fields.='subtiva0 as subt_iva0_hide,';
//           $fields.='subtiva as subt_iva_hide,';
          $fields.='subtiva as subt_iva,';
          $fields.='piva as piva_hide,';
          $fields.='pice as pice_hide,';
          $fields.='tiva as iva,';
          $fields.='tice as ice,';
          $fields.='saldo as total,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          $fields.='claveacc as claveacc_hide,';
          $fields.='claveacc2 as claveacc2_hide,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
     }
          
     if($info=='vtdet3' or $info=='cldet3')
     {
          $fields='';
//           $fields.='item,';
//           $fields.='item_descri as producto,';

          if($empr0['empr_garage']==1)
          {
//                $fields.='upper(plvh) as plvh,';
//                $fields.='substring_index(plvh_modelo," ",2) as modelo, ';
//                $fields.='plvh_clor as color,';
//                $fields.='hora1 as entra,';
//                $fields.='case when ifnull(stfin,0)=1 then hora2 else "--:--" end as sale,';
//                $fields.='hora12 as tiempo,';
          }
          
          $fields.='cant,';
//           $fields.='item_umdd as U_Mdd,';
          $fields.='puni as p_unit,';
          $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
          $fields.='subtiva0 as subt_iva0_hide,';
//           $fields.='subtiva as subt_iva_hide,';
//           $fields.='subtiva as subt_iva,';
          $fields.='piva as piva_hide,';
          $fields.='pice as pice_hide,';
          $fields.='tiva as iva,';
          $fields.='tice as ice,';
          $fields.='saldo as total,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          $fields.='claveacc as claveacc_hide,';
          $fields.='claveacc2 as claveacc2_hide,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
     }
          
          
          
     if($info=='vtblog' or $info=='clblog')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
          $fields.='item,';
          $fields.='item_descri as producto,';

          
          if($empr0['empr_garage']==1)
          {
               $fields.='upper(plvh) as plvh,';
//                $fields.='plvh_descri as vehiculo,';
//                $fields.='plvh_mrca as marca,';
//                $fields.='plvh_mdlo as modelo,';
//                $fields.='case when plvh_modelo like "% %" then substring(plvh_modelo,1,locate(" ",plvh_modelo,locate(" ",plvh_modelo)+1)) else plvh_modelo end as modelo,';
//                $fields.='case when substring(plvh_modelo,1,locate(" ",plvh_modelo,locate(" ",plvh_modelo)+1))!="" then substring(plvh_modelo,1,locate(" ",plvh_modelo,locate(" ",plvh_modelo)+1)) else plvh_modelo end as modelo,';
               $fields.='substring_index(plvh_modelo," ",2) as modelo, ';
                              
//                $fields.='convert(plvh_anio,char) as año,';
               $fields.='plvh_clor as color,';
               $fields.='hora1 as entra,';
//                $fields.='hora2 as sale,';
               $fields.='case when ifnull(stfin,0)=1 then hora2 else "--:--" end as sale,';
//                $fields.='substring(timediff(hora2,hora1),1,5) as tiempo,';
               $fields.='hora12 as tiempo,';
          }
          
          
          
          $fields.='tcant as cant,';
          $fields.='tsubt as subt,';
          $fields.='tdcto as dcto,';
//          $fields.='subtiva0 as subt_iva0,';
//          $fields.='subtiva as subt_iva,';
          $fields.='tiva as iva,';
//          $fields.='subtice as subt_ice,';
          $fields.='tice as ice,';
          $fields.='saldo as total,';
          $fields.='detalle_t as detalle,';
//           $fields.='status as st,';
          
          if($info=='vtblog')
          {$fields.='if(b_o>0 and ifnull(autornum,"")="",1,0) as b_o,';}
          
          if($info=='clblog')
          {$fields.='if(b_o>0,1,0) as b_o,';}
          
//           $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          
     }

          
          
     if(mb_stristr2('.vtres1.clres1',$info))
     {
          if($empr0['empr_garage']==1)
          {
               $fields.='plvh,';
               $fields.='plvh_mrca as marca,';
//                $fields.='plvh_clase as clase,';
               $fields.='plvh_icon as i_,';
               $fields.='substring_index(plvh_modelo," ",2) as modelo, ';
//                $fields.='plvh_model1 as modelo, ';
               $fields.='plvh_clor as color,';
               $fields.='plvh_wsapp as wsapp,';
               
               $fields.='hora1 as entra,';
               $fields.='case when ifnull(stfin,0)=1 then hora2 else "--:--" end as sale,';
               $fields.='hora12 as tiempo,';
               $fields.='cant as hr,';
//                $fields.='plvh_clase as clase,';
//                $fields.='pvp,';
          }
          $fields.='saldo as total,';
     }
          
          
          
     if(mb_stristr2('.vtenti.vtitem.vtptov.vtvndd.vtlsub.vtresu.vtxmes.vtxfec.clresu.vtxano.caresu.vtxiva.clenti.clitem',$info))
     {
          $fields.='sum(tcant) as cant,';
          $fields.='sum(tsubt) as subt,';
          $fields.='sum(tdcto) as dcto,';
          
          $fields.='case when subtiva0!=subtiva then subtiva0 else 0 end as subt_iva0, ';
          $fields.='case when subtiva0!=subtiva then subtiva else 0 end as subt_iva, ';
          $fields.='sum(subtot) as sub_tot,';
          
          $fields.='sum(tiva) as iva,';
          
          $fields.='sum(subtice) as subt_ice,';
          $fields.='sum(tice) as ice,';
          
          $fields.='sum(saldo) as total,';
          
//           if(mb_stristr2('.vtenti.vtitem.vtptov.vtvndd.vtlsub..vtxmes.vtxfec..vtxano...clenti.',$info))
//           {$fields.='(sum(saldo) / sum(idnum_c)) as c_prom,';}
          

          $fields.='piva as piva_hide,';
          $fields.='pice as pice_hide,';
          
          if($cost=='true')
          {
               $fields.='sum(costo) as costo,';
               $fields.='sum(renta) as renta,';
//                $fields.='round(renta/tsubt*100,1) as porc_rta,';
               $fields.='round(sum(renta)/sum(costo)*100,1) as porc_rta,';
          }
          
//           $fields.='status as st,';
     }


     if(mb_stristr2('.vtenti.vtitem.vtptov.vtvndd.',$info))
     {$fields.='max(fecha) as ult_vta,';}
          
     if(mb_stristr2('.clenti.clitem.clptov.clvndd.',$info))
     {$fields.='max(fecha) as ult_pro,';}
          
     if(mb_stristr2('.vtcomi.clcomi',$info))
     {
          $fields.='subtot as sub_total,';
          $fields.='saldo as total,';
          $fields.='comi as porc_comi,';
          $fields.='tcomi as comi$,';
          $fields.='left(vndd,10) as vndd,';
          $fields.='vndd_descri as vendedor,';
          
          $fields.='status as st,';
//           $fields.='if(b_o>0,1,0) as b_o,';
//           $fields.='b_o,';
          
     }

          
          
     if($info=='vtrpm1')
     {
          $fields.='sum(cant) as cant,';
//           $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
          $fields.='tiva as iva,';
//           $fields.='min(puni*(1-ifnull(dcto,0)/100)) as min_puni,';
//           $fields.='avg(puni*(1-ifnull(dcto,0)/100)) as avg_puni,';
//           $fields.='max(puni*(1-ifnull(dcto,0)/100)) as max_puni,';

//           $fields.='min(puni*(1-ifnull(dcto,0)/100)) as pre_fact,';
//           $fields.='max(puni) as pre_vta,';

//           $fields.='item_rgsn as regi_sani,';
//                     $fields.=$modu.'_rgsn as regi_sani,';
          if($rgsn_ok==1)
          {
               $fields.='item_rgsn as regi_sani,';
          }
          if($rgsn_ok==2)
          {
               $fields.='rgsn_codreg as regi_sani,';
               $fields.='rgsn_nomcom as nom_com,';
               $fields.='rgsn_codpre as cod_pre,';
               $fields.='rgsn_precom as pre_com,';
          }
          

          $fields.='min(puni*(1-ifnull(dcto,0)/100)) as pre_fac, ';
          $fields.='max(puni) as pre_vta, ';
          
          
          $fields.='0 as Obs,';
          
          // cajas
          $fields.='case ';
          $fields.='when substring(trim(item_descri),-2,1)="x" and substring(trim(item_descri),-1,1) in("1","2","3","4","5","6","7","8","9","0") then sum(cant)div(substring(trim(item_descri),-1,1)*1) ';
          $fields.='when substring(trim(item_descri),-3,1)="x" and substring(trim(item_descri),-1,1) in("1","2","3","4","5","6","7","8","9","0") then sum(cant)div(substring(trim(item_descri),-2,2)*1) ';
          $fields.='when substring(trim(item_descri),-4,1)="x" and substring(trim(item_descri),-1,1) in("1","2","3","4","5","6","7","8","9","0") then sum(cant)div(substring(trim(item_descri),-3,3)*1) ';
          $fields.='else "" end ';
          $fields.='as undds, ';
          
          // fracciones
          $fields.='case ';
          $fields.='when substring(trim(item_descri),-2,1)="x" and substring(trim(item_descri),-1,1) in("1","2","3","4","5","6","7","8","9","0") then mod(sum(cant),(substring(trim(item_descri),-1,1)*1)) ';
          $fields.='when substring(trim(item_descri),-3,1)="x" and substring(trim(item_descri),-1,1) in("1","2","3","4","5","6","7","8","9","0") then mod(sum(cant),(substring(trim(item_descri),-2,2)*1)) ';
          $fields.='when substring(trim(item_descri),-4,1)="x" and substring(trim(item_descri),-1,1) in("1","2","3","4","5","6","7","8","9","0") then mod(sum(cant),(substring(trim(item_descri),-3,3)*1)) ';
          $fields.='else sum(cant) end ';
          $fields.='as fracc, ';
          
          
          
     }

     if(mb_stristr2('.vtresu.vtXvndd.vtXptov',$info))
     {
          if($empr0['empr_codigo']=='icvs')
          {
          $fields.='convert(ifnull(proyecto,0),char) as proyecto,';
          $fields.='convert(ifnull(pisomz,0),char) as P_M,';
          $fields.='convert(ifnull(dptovi,0),char) as D_V,';
          $fields.='left(infoadic,1) as _t_,';
          }
          
          $fields.='convert(ifnull(plazo,0),char) as plazo,';
          
          if($empr0['empr_ptovta']==1)
          {
          $fields.='case ';
//           $fields.='when status="X" or status="O" then 0 ';
          $fields.='when ifnull(status,"")in("X","O") then 0 ';
          $fields.='when ifnull(efectivo,0)+ifnull(tarjeta,0)+ifnull(credito,0)=0 then saldo ';
          $fields.='when ifnull(efectivo,0)+ifnull(tarjeta,0)+ifnull(credito,0)>saldo and ifnull(efectivo,0)>0 then saldo-ifnull(tarjeta,0)-ifnull(credito,0) ';
          $fields.='else efectivo end as _efe_,';
          }
                    
          $fields.='case ';
//           $fields.='when status="X" or status="O" then 0 ';
          $fields.='when ifnull(status,"")in("X","O") then 0 ';
          $fields.='else tarjeta end as _tar_,';
          
          $fields.='case ';
//           $fields.='when status="X" or status="O" then 0 ';
          $fields.='when ifnull(status,"")in("X","O") then 0 ';
          $fields.='else credito end as _cre_,';
          
     }

     if($info=='vtcomi' )
     {
          
     }
          
          
     if($info=='vtresu' and $cfg_empr=='msg1')
     {
//           $fields.='prrta as p_Rta,';
//           $fields.='priva as p_IVA,';
          $fields.='tsubt*prrta/100 as R_Rta,';
          $fields.='tiva*priva/100 as R_IVA,';
//           $fields.='comi as p_comi,';
          $fields.='round (tsubt*comi/100,2) as Comi_Fir,';
          $fields.='round (saldo-(tsubt*prrta/100)-(tiva*priva/100)-(tsubt*comi/100),2) as Reemb,';
          $fields.='Tercero as Comi_3ro,';
          $fields.='round (saldo-(tsubt*prrta/100)-(tiva*priva/100)-(tsubt*comi/100)-tercero,2) as Neto,';
          
     }
          
     }

     
     // GUIAS
     {
          
     if($info=='guresu' )
     {
          $fields='';
          $fields.='fecha,';
//           $fields.='dia_d as dia,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          if(is_numeric($enti)==0 or strlen($enti)<10)
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as entidad,';
     }
          

          
     if($info=='gudet2')
     {
          $fields='';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
          $fields.='cant,';
          $fields.='item_umdd as U_Mdd,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
     }

          
          
          
          
     if(mb_stristr2('.guresu',$info))
     {
          $fields.='tcant as cant,';
          $fields.='concepto_t as concepto,';
          if($empr0['empr_impo']==1 or $empr0['empr_expo']==1)
          {$fields.='cntn,';}
          
          $fields.='plvh,';
//           $fields.='placa,';
          $fields.='plvh_descri,';
          $fields.='substr(cedula1,1,10) as codt,';
          $fields.='codt_descri as conductor,';
          $fields.='status as st,';
//           $fields.='if(b_o>0,1,0) as b_o,';
          $fields.='b_o,';
          
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
          
     }

          

          
     }     
     

// RECETAS MEDICAS
     {
          
     if($info=='rmresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          if(is_numeric($enti)==0 or strlen($enti)<10)
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as paciente,';
          
          $fields.='ciex as cie,';
          $fields.='ciex_descri as cie_10,';
          $fields.='iddet_c as c_med,';
          $fields.='ciex2 as cie2,';
          $fields.='ciex3 as cie3,';
          $fields.='mdco,';
//           $fields.='mdco as medico,';
          
          
//           $fields.='item_umdd as U_Mdd,';
//           $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
//           $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
     }

          
          
     if($info=='rmdet2')
     {
          $fields='';
//           $fields.='convert(round(cant,0),char) as cant,';
          $fields.='cant,';
//           $fields.='convert(round(cant,0),CHAR)as cant,';
//           $fields.='cast(round(cant,0) as CHAR)as cant,';
          $fields.='farmaco,';
          $fields.='medicamento,';
//           $fields.='prescripcion,';
          $fields.='via,';
          $fields.='dosis,';
          $fields.='frecuencia,';
          $fields.='duracion,';
          $fields.='if(ifnull(indicaciones,"")="",".",indicaciones) as indicaciones,';
//           $fields.='indicaciones,';
          
//           $fields.='item_umdd as U_Mdd,';
//           $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
     }

          

     }


     // ORDENES
     {
     if($info=='opresu' )
     {
          $fields='';
          $fields.='fecha,';
//           $fields.='dia_d as dia,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          if(is_numeric($enti)==0 or strlen($enti)<10)
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as entidad,';
          $fields.='csub1 as c_costo,';
     }
          
     if($info=='opdeta')
     {
          $fields='';
          $fields.='fecha,';
//           $fields.='dia_d as dia,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
          $fields.='csub1 as c_costo,';
//           $fields.='enti_descri as cliente,';
          if(is_numeric($enti)==0 or strlen($enti)<10)
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as entidad,';
          
          $fields.='item_lsub as linea,';
          $fields.='item,';
          $fields.='item_descri as descripcion,';
     }

     if($info=='opdet2' )
     {
          $fields='';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
          
//           $fields.='round(sum(case ';
//           $fields.='when item_descri like "%KG%" and item_descri like "%25%" then saco*25 ';
//           $fields.='when item_descri like "%KG%" and item_descri like "%45%" then saco*45 ';
//           $fields.='when item_descri like "%KG%" and item_descri like "%50%" then saco*50 ';
//           $fields.='else 0 end),2) as Kg, ';
          
          $fields.='cant,';
          $fields.='item_umdd as u_mdd,';
          
          if($_SESSION['empr_codigo']=='hfre')
          {
          $fields.='saco,';
          }

          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
     }
          
     if($info=='opdein' )
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
          $fields.='enti_descri as entidad,';
//           echo '*/*/*'.$docu;
          $fields.='item,';
          $fields.='case when item like "99%" and detalle is not null then detalle_t else item_descri end as producto,';

          $fields.='tcant as cant,';
          
          if($_SESSION['empr_codigo']=='hfre')
          {$fields.='tsaco as saco,';}
//           $fields.='puni as p_uni,';
//           $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
//           $fields.='tiva as iva,';
//           $fields.='tice as ice,';
//           $fields.='total as total,';
          $fields.='detalle_t as detalle,';
          
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
          
     }
          
          
     if($info=='opitem')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='item,';
          $fields.='item_descri as descripcion,';
     }
          
     if(mb_stristr2('.opresu.opitem.opdeta',$info))
     {
          $fields.='tcant as cant,';
          $fields.='item_umdd as umdd,';
          if($empr0['empr_codigo']=='hfre')
          {$fields.='sum(tsaco) as saco,';}
          
          $fields.='inve_cant as c_inve,';
          $fields.='ifnull(tcant,0)-ifnull(inve_cant,0) as c_dife,';
          $fields.='inve_numero as nume_inve,';
          
          $fields.='detalle_t as detalle,';
          $fields.='status as st,';
          $fields.='b_o,';
          $fields.='ifnull(iuser,0) as usr,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
     }
          
     }     
     
     // COMPRAS
     {
          
     if($info=='coenti')
     {
          $fields='';
          $fields.='idnum_c as _c_,';
          $fields.='enti_tpro as t_pro,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as proveedor,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as proveedor,';
          $fields.='tcant as cant,';
     }

     if($info=='coitem')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='item,';
//           $fields.='item_descri as item,';
          $fields.='item_descri as producto,';
     }
     
     if($info=='coctas')
     {
          $fields='';
          $fields.='idnum_c as _c_,';
//           $fields.='item_lsub as linea,';
          $fields.='ctas,';
          $fields.='ctas_descri as Contable,';
     }
     
     if($info=='cocair')
     {
          $fields='';
          $fields.='idnum_c as _c_,';
//           $fields.='item_lsub as linea,';
          $fields.='cair,';
          $fields.='cair_descri,';
     }
                   
     if($info=='cociva')
     {
          $fields='';
          $fields.='idnum_c as _c_,';
//           $fields.='item_lsub as linea,';
          $fields.='concat(round(iva,1)," %") as iva,';
//           $fields.='cair_descri,';
     }
                   
     if($info=='cocaxm')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='cair,';
          $fields.='cair_descri,';
          
     }
     
     if($info=='coenxm')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='enti,';
          $fields.='enti_descri,';
          
     }
     
     if($info=='coitxm')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item,';
          $fields.='item_descri,';
          
     }
     
     if($info=='coctxm')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='ctas,';
          $fields.='ctas_descri,';
          
     }
     
     if($info=='coxmes')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='left(fecha,7) as mes,';
     }

     if($info=='coresu' or $info=='prresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as proveedor,';
          if(is_numeric($enti)==0 or strlen($enti)<10)
          {$fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as proveedor,';}

          if(is_numeric($toenti)!=0 and strlen($toenti)>=10)
          {$fields.='toenti as adqui,';}
     }

     if($info=='codeta' or $info=='prdeta')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
//           echo '*/*/*'.$docu;
          if(substr($docu,0,2)=='PS')
          {
          $fields.='csub1 as c_sub,';
          }
          if(substr($docu,0,2)!='PS')
          {
          $fields.='left(enti,10) as enti,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as proveedor,';
          }
          $fields.='item,';
          $fields.='case when item like "99%" and detalle is not null then detalle_t else item_descri end as producto,';

          $fields.='tcant as cant,';
          $fields.='puni as p_uni,';
          $fields.='tsubt as subt,';
          $fields.='tdcto as dcto,';
//          $fields.='subtiva0 as subt_iva0,';
//          $fields.='subtiva as subt_iva,';
          $fields.='tiva as iva,';
//          $fields.='subtice as subt_ice,';
          $fields.='tice as ice,';
          $fields.='saldo as total,';
     }


     if($info=='cores1' or $info=='prres1')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu as docu_hide,';
          $fields.='ptoe as ptoe_hide,';
          if(empty($ptov))
          {$fields.='ptoe,';}
//           $fields.='ptoe_descri as ptoe,';
          $fields.='numero*1 as numero,';
          $fields.='left(enti,10) as enti,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as proveedor,';
     }
          


     if($info=='coanxm')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='enti_tpro as tpro,';
          $fields.='left(fecha,4) as anio,';
     }
          
          
     if($info=='codet2')
     {
          $fields='';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
          $fields.='cant,';
          $fields.='umdd as U_Mdd,';
//           $fields.='item_umdd as U_Mdd,';
          
          if(substr($docu,0,2)=='FP'){$xcost=1;}
          if(substr($docu,0,2)=='NP'){$xcost=1;}
          
          if($xcost==1)
          {
          $fields.='puni,';
          $fields.='tsubt as subt,';
          $fields.='tdcto as dcto,';
          $fields.='subtiva0 as subt_iva0_hide,';
          $fields.='subtiva as subt_iva_hide,';
          $fields.='piva as piva_hide,';
          $fields.='pice as pice_hide,';
          $fields.='tiva as iva,';
          $fields.='tice as ice,';
          $fields.='tirbp as irbp,';
          $fields.='saldo as total,';
          }

          

          
          if($empr0['empr_cont']==1)
          {
               $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(csub,"")="",".",csub) end as csub,';
               $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
               $fields.='if(docu like "PS%","u_f","") as u_f,';
               $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(cair,"")="",".",cair) end as cair,';
               $fields.='cair_descri as cair_descri_hide,';
               $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(ctas,"")="",".",ctas) end as ctas,';
               $fields.='ctas_descri as contable,';
          }
          
          
          if($info=='codet2')
          {
               $fields.='itemce as cod_prov,';
               $fields.='if(left(item,2)!="99",uxpre,"") as uxpre,';
//                $fields.='if(left(item,2)!="99",ifnull(uxpre,1),"") as uxpre,';
               $fields.='if(left(item,2)!="99",facon,"") as facon,';
          }
          
//           $fields.='if(b_o>0,1,0) as b_o,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
//           $fields.='b_o,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
          
     }

     if($info=='prdet2')
     {
          $fields='';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
          
          if($empr0['empr_automotriz']==1 and $empr0['empr_impo']==1)
          {$fields.='mdvh_descri as modelo_vh,';}
          
          $fields.='cant,';
          $fields.='umdd as U_Mdd,';
//           $fields.='item_umdd as U_Mdd,';
          
          if(substr($docu,0,2)=='PP'){$xcost=1;}
          if(substr($docu,0,2)=='PT'){$xcost=1;}
          
          if($xcost==1)
          {
//           $fields.='puni as p_unit,';
          $fields.='puni,';
          $fields.='tsubt as subt,';
          $fields.='tdcto as dcto,';
          $fields.='subtiva0 as subt_iva0_hide,';
          $fields.='subtiva as subt_iva_hide,';
          $fields.='tiva as iva,';
//          $fields.='subtice as subt_ice,';
          $fields.='tice as ice,';
          $fields.='tirbp as irbp,';
          $fields.='saldo as total,';
          }

//           if(!mb_stristr2('.PT',substr($docu,0,2)))

          
          $fields.='if(docu like "DA%",ifnull(peso,0.01),0) as peso,';
//           $fields.='if(docu like "DA%",ifnull(cm3,0.01),0) as cm3,';
//           $fields.='if(docu like "DA%",ifnull(volu,0.01),0) as volu,';
          $fields.='if(docu like "DA%",arcl,"") as arancel,';
          $fields.='if(docu like "DA%",ifnull(adva,0.01),0) as ad_valor,';
          $fields.='if(docu like "DA%",ifnull(espe,0.01),0) as especial,';
          $fields.='if(docu like "DA%",ifnull(dump,0.01),0) as dumping,';
          $fields.='if(docu like "DA%",ifnull(fodi,0.01),0) as fodinfa,';
               
          if($empr0['empr_codigo']=='mhec')
          {
               $fields.='if(docu like "DA%",ifnull(l_comp,0.01),0) as l_comp,';
          }
          
          
          if($empr0['empr_cont']==1)
          {
          
     //           if($docu!='DA16')
               {$fields.='case when substring(docu,1,2)in("PT","DA") then "" else if(ifnull(csub,"")="",".",csub) end as csub,';}

               $fields.='convert(dias,char) as dias,';
               $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
               $fields.='if(docu like "PS%","u_f","") as u_f,';

     //           if($docu!='DA16')
               {
                    $fields.='case when substring(docu,1,2)in("PT","DA") then "" else if(ifnull(cair,"")="",".",cair) end as cair,';
                    $fields.='cair_descri as cair_descri_hide,';

                    $fields.='case when substring(docu,1,2)in("PT","DA") then "" else if(ifnull(ctas,"")="",".",ctas) end as ctas,';
                    $fields.='ctas_descri as contable,';
               }
               
          }
          
          if($info=='codet2')
          {
               $fields.='itemce as cod_prov,';
               $fields.='if(left(item,2)!="99",uxpre,"") as uxpre,';
//                $fields.='if(left(item,2)!="99",ifnull(uxpre,1),"") as uxpre,';
               $fields.='if(left(item,2)!="99",facon,"") as facon,';
               
          }
//           $fields.='if(b_o>0,1,0) as b_o,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
//           $fields.='b_o,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
          
     }

          
          
          
     if($info=='prrsol' or $info=='lprsol')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
//           $fields.='ptoe,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
//           echo '*/*/*'.$docu;
//           if(substr($docu,0,2)=='PS')
          {
          $fields.='csub as c_sub,';
          $fields.='csub_descri as centro,';
          }
          if(substr($docu,0,2)!='PS')
          {
//           $fields.='left(enti,10) as enti,';
//           $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as proveedor,';
          }
          
          $fields.='itemce as itemce_hide,';
          $fields.='item,';
          $fields.='case when item like "99%" and detalle is not null then detalle_t else item_descri end as producto,';

//           $fields.='cant as cant,';
          $fields.='cant as cant_edit,';
          $fields.='item_umdd as ummd,';
          $fields.='item as item_edit,';
          $fields.='idate as idate_hide,';
          $fields.='status as st,';
          
//           $fields.='puni as p_uni,';
//           $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
//          $fields.='subtiva0 as subt_iva0,';
//          $fields.='subtiva as subt_iva,';
//           $fields.='tiva as iva,';
//          $fields.='subtice as subt_ice,';
//           $fields.='tice as ice,';
//           $fields.='saldo as total,';
     }

     if($info=='prosol' or $info=='lposol')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
//           $fields.='ptoe,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
//           echo '*/*/*'.$docu;
//           if(substr($docu,0,2)=='PS')
          {
          $fields.='csub as c_sub,';
          $fields.='csub_descri as centro,';
          }
          if(substr($docu,0,2)!='PS')
          {
//           $fields.='left(enti,10) as enti,';
//           $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as proveedor,';
          }
          
          $fields.='itemce as itemce_hide,';
          $fields.='item,';
          $fields.='case when item like "99%" and detalle is not null then detalle_t else item_descri end as producto,';

          $fields.='cant as cant,';
          $fields.='item_umdd as umdd,';
          $fields.='enti2 as enti2_edit,';
          $fields.='enti2 as prov_edit,';
          $fields.='idate as idate_hide,';
          $fields.='status as st,';
          
//           $fields.='puni as p_uni,';
//           $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
//          $fields.='subtiva0 as subt_iva0,';
//          $fields.='subtiva as subt_iva,';
//           $fields.='tiva as iva,';
//          $fields.='subtice as subt_ice,';
//           $fields.='tice as ice,';
//           $fields.='saldo as total,';
     }
          
          
     if($info=='codein' )
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
          $fields.='enti_descri as proveedor,';
//           echo '*/*/*'.$docu;
          $fields.='item,';
          $fields.='case when item like "99%" and detalle is not null then detalle_t else item_descri end as producto,';

          $fields.='tcant as cant,';
          
          
//           $fields.='puni as p_uni,';
// //           $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
//           $fields.='tiva as iva,';
//           $fields.='tice as ice,';
//           $fields.='saldo as total,';
          $fields.='detalle_t as detalle,';
          
          
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
          
     }
          
          
          
     if($info=='prdeta')
     {
          if(substr($docu,0,2)=='PS')
          {
//           $fields.='cant0 as cant0_hide,';
//           $fields.='cant1 as cant_edit,';
//           $fields.='cant2 as orden,';
//           $fields.='cuni as pcp_edit,';
//           $fields.='enti2 as prov_edit,';
          }
     }          

     if($info=='prdet1')
     {
          $fields='';
//           $fields.='idnum1,iddet,';
          $fields.='docu,numero,fecha,';
          $fields.='ptoe as ptoe_hide,';
//           $fields.='lsub_codigo, lsub_descri,';
//           $fields.='bode,bode_descri,';
          $fields.='item,item_descri,';
          $fields.='cant as cant,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='item_umdd as umdd,';
//           $fields.='lote,';
          
          if($cost=='true')
          {
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='puni as cost,';
          }
          $fields.='enti,enti_descri,';
//           $fields.='numfac,';
          
//           $fields.='status as st,';
     }
          
          
     if($info=='prblog')
     {
          $fields='';
          $fields.='fecha,';
//           $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
                    
//           $fields.='left(enti,10) as enti,';
//           $fields.='left(enti_descri,15) as enti_descri,';
          
          $fields.='item, item_descri as producto,';
          
          $fields.='cant,';
          $fields.='umdd,';
          $fields.='dias as dias_hide,';
          $fields.='limite,';
          
          $fields.='csub as c_sub,';
          $fields.='csub_descri as c_costo,';
          $fields.='case when concat(concepto_t,detalle_t)!="" then concat(concepto_t," /",detalle_t) else "" end as concepto,';
          $fields.='if(b_o>0,1,0) as b_o,';
          
          $fields.='substring(idate2,3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
          
//           $fields.='item_status as st,';
//           $fields.='status as st,';
     }

          
     if($info=='lpdeta')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
//           $fields.='ptoe,';
          $fields.='numero,';
//           echo '*/*/*'.$docu;
//           if(substr($docu,0,2)=='PS')
          {
          $fields.='csub as c_sub,';
          $fields.='csub_descri as c_costo,';
          }
          
          $fields.='item,';
          $fields.='case when item like "99%" and detalle is not null then detalle_t else item_descri end as producto,';

          $fields.='tcant as cant,';
//           $fields.='puni as p_uni,';
//           $fields.='tsubt as subt,';
//           $fields.='saldo as total,';
          
          $fields.='dias as dias_hide,';
          $fields.='limite,';
          
//           $fields.='cant as cant_edit,';
          $fields.='puni as pcp_edit,';
          $fields.='enti as prov_edit,';
          $fields.='detalle,';
//           $fields.='ifnull(enti,"9999999999999") as enti_edit,';
          
     }

          
          
     if($info=='lpblog')
     {
          $fields='';
          $fields.='fecha,';
//           $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
                    
//           $fields.='left(toenti,10) as enti,';
//           $fields.='left(enti_descri,15) as enti_descri,';
          
          $fields.='item, item_descri as producto,';
          
          $fields.='cant,';
          $fields.='umdd,';
          $fields.='uxpre,';
          
          $fields.='cant_conv,';
          $fields.='item_umdd as umdd,';
          
          $fields.='dias as dias_hide,';
          $fields.='limite,';
          
          $fields.='csub as c_sub,';
          $fields.='csub_descri as c_costo,';
          
//           $fields.='left(toenti,10) as enti,';
          $fields.='left(enti_descri,15) as solicita,';
          
          
          $fields.='case when concat(concepto_t,detalle_t)!="" then concat(concepto_t," /",detalle_t) else "" end as concepto,';
          $fields.='if(b_o>0,1,0) as b_o,';
          
          $fields.='substring(idate2,3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
          
//           $fields.='item_status as st,';
//           $fields.='status as st,';
     }

          
          
     if(mb_stristr2('.coenxm.cocaxm.coitxm.coctxm',$info))
     { 
          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               $fields.='sum(case when left(fecha,7)="'.$xames.'" then tsubt-tdcto end) as '.$xanio.'_'.$xmes.',';
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
          }
          
          $fields.='sum(tsubt-tdcto) as total,';
          
     }
          

     if(mb_stristr2('.coanxm',$info))
     { 
          for($idx=1; $idx<=12; $idx++)
          {
//                $xround=2;
               $xmes=str_pad($idx,2,'0',STR_PAD_LEFT);
               $fields.='sum(case when substring(fecha,6,2)="'.$xmes.'" then tsubt-tdcto end) as m$_'.$xmes.',';
          }
          $fields.='sum(tsubt-tdcto) as total,';
     }

          
          
     if(mb_stristr2('.prresu',$info))
     {
          $fields.='tcant as cant,';
//           $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
          
          $fields.='case when subtiva0!=subtiva then subtiva0 else 0 end as subt_iva0, ';
          $fields.='case when subtiva0!=subtiva then subtiva else 0 end as subt_iva, ';
          
          $fields.='tiva as iva,';
          $fields.='subtice as subt_ice,';
          $fields.='tice as ice,';
          $fields.='saldo as total,';
     }
          

          
     if(mb_stristr2('.coenti.coresu.coitem.coxmes.cocair.cociva.coctas',$info))
     {
//           $fields.='sum(tcant) as cant,';
          
          $fields.='sum(tsubt) as subt,';
          $fields.='sum(tdcto) as dcto,';
//           $fields.='sum(tprop) as prop,';
          
          $fields.='sum(case when subtiva0!=subtiva then subtiva0 else 0 end) as subt_iva0, ';
          $fields.='sum(case when subtiva0!=subtiva then subtiva else 0 end) as subt_iva, ';
          
          
          $fields.='sum(tiva) as iva,';
          $fields.='sum(subtice) as subt_ice,';
          $fields.='sum(tice) as ice,';
          $fields.='sum(saldo) as total,';
     }

     if($rete=='true')     
     if(mb_stristr2('.vtresu.coresu',$info))
     {
          $fields.='idn_rete as idn_rete_hide,';
          $fields.='ifnull(nume_rete,"Rete") as nume_rete,';
          $fields.='if(month(fec_rete)=month(fecha) or ifnull(fec_rete,"")="", "", fec_rete)  as f_ret,';
     }
          
          

     if($modu=='comp' or $modu=='prov')
     if($empr0['empr_impo']==1)
     {
//           if(empty($edit))
//           {$fields.='impor as nume_impor,';}
          
//           if($edit>0)
//           {$fields.='case when ifnull(impor,"")="" then "." else impor end as nume_impor,';}
     }
          
          
     if($empr0['empr_inve']==1)
     {
          if(mb_stristr2('.vtresu.coresu.vtdeta.codeta.',$info))
          {
               if($inve=='true')
               {
//                     $fields.='(inve_cant)/cant_conv*100 as porc_inv,';
                    $fields.='round((inve_cant)/cant_conv*100,0) as porc_inv,';

                    if(mb_stristr2('.vtresu.coresu',$info))
                    {$fields.='inve_fecha as inv_fec ,';}
               }
               
//                if(mb_stristr2('.vtresu.vtdeta',$info) and $cost=='true')
//                {$fields.='inve_cost as inv_cos,';}
          }
          
     }
          
          
          
          
     if(mb_stristr2('.coitem.',$info))
     {
          $fields.='min(case when puni1_conv>0 then puni1_conv else 999999 end) as min,';
          $fields.='max(puni1_conv) as max,';
//           $fields.='avg(puni1_conv) as prom,';
//           $fields.='(max(puni1_conv)-min(puni1_conv)) /min(puni1_conv)*100 as porc_var,';
          $fields.='(max(puni1_conv)-min(case when puni1_conv>0 then puni1_conv else 999999 end)) /min(case when puni1_conv>0 then puni1_conv else 999999 end)*100 as porc_var,';
     }
          
          
          
     if(mb_stristr2('.codeta.',$info))
     {
          if($empr0['empr_cont']==1)
          {
//                $fields.='cair,';
//                $fields.='ctas,';
//                $fields.='cair_descri as cair_descri_hide,';
//                $fields.='ctas_descri as contable,';
          }

//           echo '===>'.$empr0['empr_sriats'];
          
          if($empr0['empr_cont']==1)
          {
               $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
               $fields.='if(docu like "PS%","u_f","") as u_f,';
          }

          
          
          if(!empty($empr0['empr_sriats']))
          {
               $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(cair,"")="",".",cair) end as cair,';
               $fields.='cair_descri as cair_descri_hide,';
          }
          
          
          if($empr0['empr_cont']==1)
          {
               $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(ctas,"")="",".",ctas) end as ctas,';
               $fields.='ctas_descri as contable,';
               $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(csub,"")="",".",csub) end as csub,';
          }
          
          
          
          
//           echo '*/*/*'.$edit;
          if(empty($edit))
          {
//           $fields.='fpag,';
//           $fields.='suco,';
//           $fields.='fpag_descri as fpag_descri_hide,';
//           $fields.='suco_descri as suco_descri_hide,';
          }
          
          $fields.='cuni1_conv as c_uni,';
          
          if($empr0['empr_impo']==1)
          {$fields.='if(ifnull(impor,"")="",".",impor) as impor,';}
          
//           echo '==='.$empr0['empr_inve'];
          
          if($empr0['empr_inve']==1)
          {
//                $fields.='uxpre,';
//                $fields.='facon,';
               $fields.='if(ifnull(uxpre,0)=0,1,uxpre) as uxpre,';               
               $fields.='if(ifnull(facon,0)=0,1,facon) as facon,';               
          }
          
          $fields.='concat(replace(detalle_t,item_descri,"")," /",ifnull(itemce,"")) as det_pro,';
          
          if(!empty($edit))
          {
               if($empr0['empr_inve']==1)
               {$fields.='ifnull(itemce,"") as cod_prov,';}
               $fields.='substring(idate,3,8) as idate,';
          }
          
     }
          
     if(mb_stristr2('.codein.',$info))
     {
          $fields.='itemce,';
          $fields.='uxpre,';
          $fields.='facon,';
          $fields.='cant_conv as c_comp,';
          $fields.='inve_cant as c_bode,';
          $fields.='ifnull(cant_conv,0)-ifnull(inve_cant,0) as c_dife,';
          
     }
          
     if(mb_stristr2('.coresu.',$info))
     {
//           $fields.='fpag,';
//           $fields.='suco,';
//           $fields.='fpag_descri as fpag_descri_hide,';
//           $fields.='suco_descri as suco_descri_hide,';
     }

          
     }


     // PRODUCCION
     {
     if(mb_stristr2('.opdein.',$info))
     {
//           $fields.='itemce,';
//           $fields.='uxpre,';
//           $fields.='facon,';
//           $fields.='cant_conv as c_comp,';
          $fields.='inve_numero as nume_inve,';
          $fields.='inve_cant as c_inve,';
          $fields.='ifnull(cant,0)-ifnull(inve_cant,0) as c_dife,';
          
     }

          
     if(mb_stristr2('.pddet2.',$info))
     {
          $fields='';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
//           $fields.='cant,';
          
//           $fields.='hora1 as hora,';
          $fields.='if(entrada>0,hora1,"") as hora,';
          $fields.='entrada,';
          $fields.='salida,';
          $fields.='if(salida>0,hora1,"") as hora,';
          $fields.='item_umdd as U_Mdd,';
//           $fields.='detalle_t as detalle,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          
//           $fields.='b_e,b_o,';
//           $fields.='idnum1 as inum_hide,';
//           $fields.='nega,';
//           $fields.='if(ifnull(nega,0)=0,"",0.00001) as nega,';
          $fields.='idate as idate_hide,';
          $fields.='fecha as fecha_hide,';

          
     }
          
          
          
     }


      
     // INVENTARIO
     {
     $prdo_cpu=date('Y-m-01',strtotime($fecha2.'-360 days'));
     $docu_cpu='"EB10","EB19"';
     $docu_ibc='"IB10","IB15"';
     $docu_lote='"IB10","IB15"';
          
     if($info=='iikrdx')
     {
          $fields='';
          $fields.='item as item_hide,';
          
          if(empty($item))
          {
          $fields.='item,';
          $fields.='item_descri as producto,';
          }
          
          $fields.='case when fecha<"'.$fecha1.'" then max(fechax) else fecha end as fecha,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else docu end as docu,';
//           REPLACE("SQL Tutorial", "SQL", "HTML")
          $fields.='case when fecha<"'.$fecha1.'" then "* I N I C I A L *" else replace(replace(docu_descri,"ING.X","X"),"EGR.X","X") end as documento,';
//           $fields.='bode,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else bode end as bode,';
          $fields.='bode2 as bode2_hide,';
          $fields.='case when fecha<"'.$fecha1.'" then " " else numero end as numero,';
//           $fields.='sum(case when fecha<"'.$fecha1.'" and left(docu,1)="I" then stock end) as inicial_hide,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then stock end) as inicial_hide,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='sum(stock) as stock,';
          $fields.='lote,';
//           $fields.='idate2,';
          
          if($cost=='true')
          {
//                $fields.='puni as cost,';
               $fields.='puni as cost,';
//                $fields.='case when left(docu,1)="I" then cprom else puni end as cost,';
//                $fields.='case when puni-punibak!=0 then punibak else 0 end as pbak,';
               $fields.='sum(case when fecha<"'.$fecha1.'" and left(docu,1)="I" then saldo end) as inicial_$_hide,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='sum(saldo) as saldo_$,';
//                $fields.='if(fecha>="'.$fecha1.'",numfac*1,"") as factu,';
               $fields.='if(fecha>="'.$fecha1.'",numfac*1,"") as nume_fact,';
               $fields.='if(fecha>="'.$fecha1.'",impor,"") as nume_impor,';
//                $fields.='cprom as c_pro,';
//                $fields.='if(puni=cprom,0,cprom) as c_pro,';
          }
          
//           if(empty($bode))
          {
               $fields.='if(ifnull(status,"")not in("O","X") and ifnull(nega,0)>0,"N","") as nega,';
          }
          
          $fields.='case when fecha<"'.$fecha1.'" then "" else left(enti,10) end as enti,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else enti_descri end as nombre,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else concat(concepto_t," /",detalle_t," /",ifnull(numfac,"")) end as detalle,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else status end as st,';
          $fields.='ptoe as ptoe_hide,';
     }

     if($info=='iidet2' or $info=='ifdet2')
     {
          $fields='';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
          $fields.='cant,';
          $fields.='item_umdd as U_Mdd,';
//           $fields.='detalle_t as detalle,';
          $fields.='lote,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          
//           $fields.='b_e,b_o,';
//           $fields.='idnum1 as inum_hide,';
          $fields.='nega,';
//           $fields.='if(ifnull(nega,0)=0,"",0.00001) as nega,';
          $fields.='idate as idate_hide,';
          $fields.='fecha as fecha_hide,';

     }
          
     if($info=='iiblog' )
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='bode,';
          $fields.='bode2 as bode2_hide,';
          $fields.='numero,';
          $fields.='dia_des as dia_hide,';
          $fields.='item, item_descri as producto,';
          $fields.='(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
                    
          if($cost=='true')
          {
               $fields.='puni as cost,';
               $fields.='abs(saldo) as valor,';
          }
          $fields.='lote,';
//           $fields.='numfac*1 as numfac,';
          $fields.='case when docu in ("IB10","EB10") then numfac*1 else 0 end as nume_fact,';
          $fields.='case when docu not in ("IB10","EB10") then numfac*1 else 0 end as orden,';
          
          if($empr0['empr_taller']==1 and $empr0['empr_automotriz']==1)
          {$fields.='plvh,';}
          
          $fields.='left(enti,10) as enti,';
          $fields.='left(enti_descri,15) as enti_descri,';
          $fields.='case when concat(concepto_t,detalle_t)!="" then concat(concepto_t," /",detalle_t) else "" end as concepto,';
          $fields.='if(b_o>0,1,0) as b_o,';
          
          $fields.='substring(idate2,3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
          
//           $fields.='item_status as st,';
//           $fields.='status as st,';
     }

          
     if($info=='ifblog' )
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='bode,';
//           $fields.='bode2 as bode2_hide,';
          $fields.='numero,';
//           $fields.='dia_des as dia_hide,';
          $fields.='lsub_descri as linea,';
          $fields.='item, item_descri as producto,';
          $fields.='cant as cantidad,';
//           $fields.='(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
//           $fields.='(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
                    
          if($cost=='true')
          {
//                $fields.='puni as cost,';
//                $fields.='abs(saldo) as valor,';
          }
          $fields.='lote,';
//           $fields.='numfac*1 as numfac,';
//           $fields.='case when docu in ("IB10","EB10") then numfac*1 else 0 end as nume_fact,';
//           $fields.='case when docu not in ("IB10","EB10") then numfac*1 else 0 end as orden,';
//           $fields.='left(enti,10) as enti,';
          $fields.='left(enti_descri,15) as enti_descri,';
          $fields.='case when concat(concepto_t,detalle_t)!="" then concat(concepto_t," /",detalle_t) else "" end as concepto,';
          $fields.='if(b_o>0,1,0) as b_o,';
          
          $fields.='substring(idate2,3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
          
//           $fields.='item_status as st,';
//           $fields.='status as st,';
     }

          
          
//      if($info=='iiresu')
     if($info=='iiresu' or $info=='ifresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='bode,';
          
          if($info=='iiresu')
          {$fields.='bode2 as bode2_hide,';}
          
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          $fields.='left(enti,10) as enti,';
          $fields.='enti_descri as nombre,';
          $fields.='sum(cant) as cantidad,';
          
          if($info=='iiresu')
          {$fields.='bode2 as bode_t,';}
          
          if($cost=='true')
          {
          $fields.='sum(abs(saldo)) as total,';
          }
          
          
          if($info=='iiresu')
          {
          $fields.='case when docu in ("IB10","IB15","EB10") then numfac*1 else 0 end as nume_fact,';
          $fields.='case when docu in ("IB15") then impor else 0 end as nume_impor,';
          $fields.='case when docu not in ("IB10","IB15","EB10") then numfac*1 else 0 end as orden,';
          }
          
     }

     if($info=='iideta')
     {
          $fields='';
//           $fields.='idnum1,iddet,';
          $fields.='docu,numero,fecha,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='bode,bode_descri,';
          $fields.='lsub_descri as linea,';
          $fields.='item,item_descri as producto,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='item_umdd as umdd,';
          $fields.='enti,enti_descri as entidad,';
          $fields.='lote,';
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='puni as cost,';
          }
          $fields.='concepto_t as concepto,';
          $fields.='status as st,';
     }

     if($info=='iidet1')
     {
          $fields='';
//           $fields.='idnum1,iddet,';
          $fields.='docu,numero,fecha,';
          $fields.='ptoe as ptoe_hide,';
//           $fields.='lsub_codigo, lsub_descri,';
//           $fields.='bode,bode_descri,';
          $fields.='item,item_descri,';
          $fields.='cant as cant,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='item_umdd as umdd,';
//           $fields.='lote,';
          
          if($cost=='true')
          {
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='puni as cost,';
          }
          $fields.='enti,enti_descri,';
//           $fields.='numfac,';
          
//           $fields.='status as st,';
     }

     if($info=='iicuxc')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,numero,';
          $fields.='ptoe as ptoe_hide,';
//           $fields.='lsub_codigo, lsub_descri,';
          $fields.='item_lsub,';
          $fields.='item,item_descri,';
          $fields.='bode,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='cant,';
          $fields.='item_umdd as umdd,';
          $fields.='puni,';
//           $fields.='lote,';
          $fields.='numfac*1 as nume_fact,';
//           $fields.='uxpre,facon,';
          $fields.='left(enti,10) as enti,';
          $fields.='left(enti_descri,20) as proveedor,';
          $fields.='substring(idate2,3) as idate,';
//           $fields.='enti,enti_descri,';
          
//           if($cost=='true')
//           {
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
//                $fields.='puni as cost,';
//           }
          
//           $fields.='status as st,';
     }

          
     if($info=='iiie11')
     {
          $fields='';
//           $fields.='idnum1,iddet,';
          $fields.='docu,numero,fecha,';
          $fields.='ptoe as ptoe_hide,';
//           $fields.='lsub_codigo, lsub_descri,';
          $fields.='bode,bode_descri,';
          $fields.='item,item_descri,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='item_umdd as umdd,';
          $fields.='cambio,';
          $fields.='enti,enti_descri,';
          $fields.='lote,';
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='puni as cost,';
          }
          
//           $fields.='status as st,';
     }
          
     if($info=='iiddbb')
     {
          $fields='';
          $fields.='idnum1,iddet,';
          $fields.='docu,numero,fecha,';
          $fields.='lsub_codigo, lsub_descri,';
          $fields.='item,item_descri,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='item_umdd as umdd,';
          $fields.='bode,bode_descri,';
          $fields.='enti,enti_descri,';
          $fields.='lote,';
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='puni as cost,';
          }
          
//           $fields.='status as st,';
     }
     
     if($info=='iiiiee')
     {
          $fields='';
          $fields.='lsub_codigo as linea,';
//           $fields.='trim(item) as item,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          $fields.='case when trim(item_codigo) not like concat("%",trim(item_codigov),"%") then trim(item_codigov) else "" end as cod_vta,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then stock end) as inicial,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='sum(stock) as stock,';
          
          $fields.='item_umdd as umdd,';
//           $fields.='sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/360 end) as c_pro,';
          $fields.='sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/360 end) as cpd,';
//           $fields.='sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/52 end) as cps,';
//           $fields.='sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/12 end) as cpm,';
          
// https://blog.next-cloud.mx/2018/06/19/calculo-minimos-maximos-inventario/
          
//           $fields.='max(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" and docu in('.$docu_ibc.') then ib_dep end) as d_emax,';
//           $fields.='min(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" and docu in('.$docu_ibc.') then ib_dep end) as d_emin,';
          $fields.='ceil(sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/360 end)* avg(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" and docu in('.$docu_ibc.') then ib_dep end)) as s_min,';
//           $fields.='ceil(sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/360 end)* avg(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" and docu in('.$docu_ibc.') then ib_dep end))*2 as s_max,';
          
          $fields.=$col_pcli.' as pedido,';
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='sum(saldo) as saldo_$, ';
               $fields.='cprom as c_pro_$, ';
               if($pvar=='true')
               {
                    $fecha2m=$fecha2;
                    $fecha2m=date('Y-m-01',strtotime($fecha2m));
                    $fecha2m=date('Y-m-d',strtotime($fecha2m.'-1 days'));
                    $fields.='0.01 as vcp,';
//                     $fields.='cpro_cpro as u_cpro,';
//                     $fields.='cpro1_cpro as cpro1,';
//                     $fields.='cpro2_cpro as cpro2,';
               }
          }
          
//           echo '<br>*/*/*'.$fecha1a.'====='.$fecha2a;
          $fields.='sum(case when fecha>="'.$fecha1a.'" and fecha<="'.$fecha2.'" and docu in ("EB10","EB19") then abs(stock) end) as vta_con_hide,';
//           $fields.='sum(case when fecha>="'.$fecha1a.'" and fecha<="'.$fecha2.'" and docu in ("EB10","EB19") then abs(stock) end) as vta_con,';
          $fecha2a=$fecha1a;
          for($cmes=1; $cmes<=12; $cmes++)
          {
               $fecha2a=date('Y-m-t',strtotime($fecha2a.'28 days'));
               $fields.='sum(case when fecha<="'.$fecha2a.'" then ifnull(stock,0) end) as stk_mes_'.$cmes.'_hide,';
//                $fields.='sum(case when fecha<="'.$fecha2a.'" then ifnull(stock,0) end) as stk_mes_'.$cmes.',';
//           echo '<br>*/*/*'.$fecha1a.'====='.$fecha2a;
          }
          
          
//           $xfields='sum(0';
//           $fecha2a=$fecha1a;
//           for($cmes=1; $cmes<=12; $cmes++)
//           {
//                $fecha2a=date('Y-m-t',strtotime($fecha2a.'28 days'));
//                $xfields.='+(case when fecha<="'.$fecha2a.'" then (saldo) end) ';
//           }
//           $xfields.=') as saldo_full,';
//           $fields.=$xfields;
          
          
          
          $fields.='sum(case when fecha>="'.$fecha1.'" and fecha<="'.$fecha2.'" then convert(tnega,char) else "" end) as nega,';
          $fields.='max(fecha) as u_movi,';          
          $fields.='item_status as st,';
     }

//      if($info=='iiie13')
          if(mb_stristr2('.iiie11.iiie13.iiie14',$info))
          {
          $fields='';
          $fields.='lsub_codigo as linea,';
//           $fields.='trim(item) as item,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          $fields.='case when trim(item_codigo) not like concat("%",trim(item_codigov),"%") then trim(item_codigov) else "" end as cod_vta,';
//           $fields.='sum(case when fecha<"'.$fecha1.'" then stock end) as inicial,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
//           $fields.='sum(case when left(docu,1)="I" then stock end) as ingreso,';
//           $fields.='sum(case when left(docu,1)="E" then abs(stock) end) as egreso,';

          
          $res_bode=msql_query($sql_bode,$link_data);
          msql_data_seek($res_bode);
          while($aso_bode=msql_fetch_assoc($res_bode))
          {
               $xbode=trim($aso_bode['bode_codigo']);
               $fields.='sum(case when left(docu,1)="E" and bode="'.$xbode.'" then abs(stock) end) as '.$xbode.'_UE, ';
          }
          
          msql_data_seek($res_bode);
          while($aso_bode=msql_fetch_assoc($res_bode))
          {
               $xbode=trim($aso_bode['bode_codigo']);
//                $fields.='sum(case when left(docu,1)="I" and bode="'.$xbode.'" then stock end) as '.$xbode.'_UI, ';
               $fields.='sum(case when left(docu,1)="I" and bode="'.$xbode.'" and fecha<="'.$fecha2.'" then stock end) as '.$xbode.'_UI, ';
          }
          
//           $fields.='sum(stock) as neto,';
          $fields.='sum(case when fecha<="'.$fecha2.'" then stock end) as neto,';
          
          msql_data_seek($res_bode);
          while($aso_bode=msql_fetch_assoc($res_bode))
          {
               $xbode=trim($aso_bode['bode_codigo']);
               $fields.='sum(case when left(docu,1)="I" and bode="'.$xbode.'" and fecha>"'.$fecha2.'" then stock end) as '.$xbode.'_UT, ';
          }
          
          $fields.='item_umdd as umdd,';

          
          
//           $fields.='sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/360 end) as c_pro,';
          $fields.='sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/360 end) as cpd,';
          
          $fields.=$col_pcli.' as pedido,';
          
          if($cost=='true')
          {
//                $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='sum(saldo) as saldo_$, ';
               $fields.='cprom as c_pro_$, ';
               if($pvar=='true')
               {
                    $fecha2m=$fecha2;
                    $fecha2m=date('Y-m-01',strtotime($fecha2m));
                    $fecha2m=date('Y-m-d',strtotime($fecha2m.'-1 days'));
                    $fields.='0.01 as vcp,';
               }
          }
          
          $fields.='sum(case when fecha>="'.$fecha1a.'" and fecha<="'.$fecha2.'" and docu in ("EB10","EB19") then abs(stock) end) as vta_con_hide,';
          $fecha2a=$fecha1a;
          for($cmes=1; $cmes<=12; $cmes++)
          {
               $fecha2a=date('Y-m-t',strtotime($fecha2a.'28 days'));
               $fields.='sum(case when fecha<="'.$fecha2a.'" then ifnull(stock,0) end) as stk_mes_'.$cmes.'_hide,';
          }
          
          
//           $fields.='max(fecha) as u_movi,';          
          $fields.='item_status as st,';
     }

          
          
     if($info=='iiddcc')
     {
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='lsub_descri as lineas,';
//           $fields.='trim(item) as item,';
//           $fields.='item,';
//           $fields.='item_descri as producto,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then stock end) as inicial,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='sum(stock) as stock,';
          
//           $fields.='item_umdd as umdd,';
          
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='sum(saldo) as saldo_$, ';
//                $fields.='avg(puni) as c_pro_$, ';
          }
          
          
          $fields.='item_status as st,';
     }

     if($info=='iidcdd' or $info=='iidcmm')
     {
          $fields='';
          if($info=='iidcdd')
          {$fields.='fecha,';}
          if($info=='iidcmm')
          {$fields.='left(fecha,7) as mes,';}
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='sum(stock) as stock,';
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='sum(saldo) as saldo_$, ';
          }
          
          
          $fields.='item_status as st,';
     }
    
     if($info=='iisxlt')
     {
          
          $fields='';
          $fields.='lsub_codigo as linea,';
//           $fields.='trim(item) as item,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
//           $fields.='lote,';
          $fields.='ifnull(lote,"") as lote,';
          $fields.='sum(case when fecha<"'.$fecha1.'"  and docu in('.$docu_lote.') then stock end) as inicial,';
          $fields.='sum(case when fecha>="'.$fecha0.'" and docu not in('.$docu_lote.') and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha0.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
//           $fields.='sum(case when docu not in('.$docu_lote.') then stock end) as stock,';
          $fields.='sum(stock) as stock,';

          $res_bode=msql_query($sql_bode,$link_data);
          if(msql_num_rows($res_bode)>1)
          while($aso_bode=msql_fetch_assoc($res_bode))
          {
               $xbode=trim($aso_bode['bode_codigo']);
               $fields.='sum(case when bode="'.$xbode.'" then stock end) as '.$xbode.$char_unibod.', ';
          }
          
          $fields.='item_umdd as umdd,';
          
          $fields.='sum(case when item_umdd like "KG%" or item_umdd like "KIL%" then stock/50 else 0 end) as S_50K, ';
          $fields.='sum(case when item_umdd like "KG%" or item_umdd like "KIL%" then stock/25 else 0 end) as S_25K, ';
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha<"'.$fecha1.'"  and docu in('.$docu_lote.') then saldo end) as inicial_$,';
               $fields.='sum(case when fecha>="'.$fecha0.'" and docu not in('.$docu_lote.') and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha0.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='sum(saldo) as saldo_$, ';
//                $fields.='avg(puni) as c_pro_$, ';
          }
          
          
          $fields.='item_status as st,';
     }
          
     if($info=='iidocu')
     {
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then stock end) as inicial,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
          $fields.='sum(stock) as stock,';
          
          
          $sql_docu='select distinct docu_codigo from docu0 inner join inve1 on docu_codigo=docu ';
          $sql_docu.='where docu_status not in("I","X") ';
          $sql_docu.='order by right(docu_codigo,2),left(docu_codigo,1) desc';
          $res_docu=msql_query($sql_docu,$link_data);
          while($aso_docu=msql_fetch_assoc($res_docu))
          {
               $xdocu=trim($aso_docu['docu_codigo']);
               $fields.='sum(case when fecha>="'.$fecha1.'" and docu="'.$xdocu.'" then abs(stock) end) as '.$xdocu.$char_unibod.', ';
          }
          $fields.='item_umdd as umdd,';

          $fields.='sum(case when fecha>="'.$prdo_cpu.'" and fecha<="'.$fecha2.'" then eb_cpu/360 end) as cpd,';
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='sum(saldo) as saldo_$, ';
               msql_data_seek($res_docu);
               while($aso_docu=msql_fetch_assoc($res_docu))
               {
                    $xdocu=trim($aso_docu['docu_codigo']);
                    $fields.='sum(case when fecha>="'.$fecha1.'" and docu="'.$xdocu.'" then abs(saldo) end) as '.$xdocu.'_$, ';
               }
               $fields.='avg(puni) as cost_prom, ';
          }
          
          $fields.='item_status as st,';
     }

     if($info=='iiiecf')
     {
          $fields='';
//           $fields.='lsub_codigo as linea,';
          $fields.='enti as enti,';
          $fields.='enti_descri as cliente,';
          $fields.='fecha,';
//           $fields.='item,';
//           $fields.='item_descri as producto,';
//           $fields.='sum(case when fecha<"'.$fecha1.'" then stock end) as inicial,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then stock end) as ingreso,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(stock) end) as egreso,';
//           $fields.='sum(stock) as stock,';
          
          
          $sql_docu='select distinct docu_codigo from docu0 inner join inve1 on docu_codigo=docu ';
          $sql_docu.='where docu_status not in("I","X") ';
          $sql_docu.='order by right(docu_codigo,2),left(docu_codigo,1) desc';
          $res_docu=msql_query($sql_docu,$link_data);
          while($aso_docu=msql_fetch_assoc($res_docu))
          {
               $xdocu=trim($aso_docu['docu_codigo']);
               $fields.='sum(case when fecha>="'.$fecha1.'" and docu="'.$xdocu.'" then abs(stock) end) as '.$xdocu.$char_unibod.', ';
          }
          $fields.='sum(abs(stock)) as kg,';
//           $fields.='item_umdd as umdd,';
          $fields.='sum(abs(stock/1000)) as tm,';
//           $fields.='item_umdd as umdd,';
          
          if($cost=='true')
          {
               $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="I" then saldo end) as debito_$,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,1)="E" then abs(saldo) end) as credito_$,';
               $fields.='sum(saldo) as saldo_$, ';
               msql_data_seek($res_docu);
               while($aso_docu=msql_fetch_assoc($res_docu))
               {
                    $xdocu=trim($aso_docu['docu_codigo']);
                    $fields.='sum(case when fecha>="'.$fecha1.'" and docu="'.$xdocu.'" then abs(saldo) end) as '.$xdocu.'_$, ';
               }
               $fields.='avg(puni) as cost_prom, ';
          }
          
          $fields.='item_status as st,';
     }

          

     if($info=='iiicom' or $info=='iiiimp')
     {
//           $xround=2;
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';

          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               $fields.='sum(case when left(fecha,7)="'.$xames.'" then stock*(1) end) as '.$xanio.'_'.$xmes.',';
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
               
          }
          
          $fields.='sum(ingreso) as total,';
          //promedio
          $fields.='sum(ingreso)/'.$tot_meses.' as pro_mes,';
//           $fields.='avg(egreso) as pro_mes,';
          
          $fields.='item_umdd as umdd,';
          
          if($cost=='true')
          {
               $xfecha=date('Y-m-01',strtotime($fecha1));
               while($xfecha<=$fecha2)
               {
                    $xanio=date('Y',strtotime($xfecha));
                    $xmes=date('m',strtotime($xfecha));
                    $xames=date('Y-m',strtotime($xfecha));
                    $fields.='sum(case when left(fecha,7)="'.$xames.'" then saldo*(1) end) as '.$xanio.'_'.$xmes.'_$,';
//                     $fields.='avg(case when left(fecha,7)="'.$xames.'" then puni end) as p_p,';
                    $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
               }
               $fields.='sum(debito) as total_$,';

               
               $xfecha=date('Y-m-01',strtotime($fecha1));
               while($xfecha<=$fecha2)
               {
                    $xanio=date('Y',strtotime($xfecha));
                    $xmes=date('m',strtotime($xfecha));
                    $xames=date('Y-m',strtotime($xfecha));
                    $fields.='avg(case when left(fecha,7)="'.$xames.'" then puni end) as '.substr($xanio,-2).'_'.$xmes.'_p,';
                    $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
               }
               
               $fields.='min(puni) as min,';
               $fields.='max(puni) as max,';
               $fields.='(max(puni)-min(puni))/min(puni)*100 as porc_var,';
               
               
          }
          
          $fields.='item_status as st,';
     }

          
          
     if($info=='iievta' or $info=='iiecon')
     {
//           $xround=2;
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';

          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               $fields.='sum(case when left(fecha,7)="'.$xames.'" then stock*(-1) end) as '.$xanio.'_'.$xmes.',';
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
          }
          
          $fields.='sum(egreso) as total,';
          //promedio
          $fields.='sum(egreso)/'.$tot_meses.' as pro_mes,';
//           $fields.='avg(egreso) as pro_mes,';
          
          $fields.='item_umdd as umdd,';
          
          if($cost=='true')
          {
               $xfecha=date('Y-m-01',strtotime($fecha1));
               while($xfecha<=$fecha2)
               {
                    $xanio=date('Y',strtotime($xfecha));
                    $xmes=date('m',strtotime($xfecha));
                    $xames=date('Y-m',strtotime($xfecha));
                    $fields.='sum(case when left(fecha,7)="'.$xames.'" then saldo*(-1) end) as '.$xanio.'_'.$xmes.'_$,';
                    $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
               }

               $fields.='sum(credito) as total_$,';
               
          }
          
          $fields.='item_status as st,';
     }

     if($info=='iievxb' or $info=='iiecxb' or $info=='iietxb' )
     {
//           $xround=2;
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';
     }          
          
     if($info=='iieclb')
     {
//           $xround=2;
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='lsub_descri as lineas,';
//           $fields.='item,';
//           $fields.='item_descri as producto,';
     }          
          
     if($info=='iievxb' or $info=='iiecxb' or $info=='iietxb'  or $info=='iieclb')
     {

          $res_bode=msql_query($sql_bode,$link_data);
          if(msql_num_rows($res_bode)>1)
          while($aso_bode=msql_fetch_assoc($res_bode))
          {
               $xbode=trim($aso_bode['bode_codigo']);
               $fields.='sum(case when bode="'.$xbode.'" then egreso end) as '.$xbode.$char_unibod.', ';
          }
          $fields.='sum(egreso) as total,';
          $fields.='item_umdd as umdd,';
          
          if($cost=='true')
          {
               msql_data_seek($res_bode);
               if(msql_num_rows($res_bode)>1)
               while($aso_bode=msql_fetch_assoc($res_bode))
               {
                    $xbode=$aso_bode['bode_codigo'];
                    $fields.='sum(case when bode="'.$xbode.'" then (credito) end) as '.$xbode.'_$, ';
               }
               $fields.='sum(credito) as total_$, ';
               $fields.='sum(credito)/sum(egreso) as prom_$, ';
          }
          $fields.='item_status as st,';
     }
     
     if($info=='iietbb')
     {
//           $xround=2;
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          $fields.='bode as origen,';
//           $fields.='bode_descri as bodega,';

          $res_bode=msql_query($sql_bode,$link_data);
//           if(msql_num_rows($res_bode)>1)
          while($aso_bode=msql_fetch_assoc($res_bode))
          {
               $xbode=trim($aso_bode['bode_codigo']);
               $fields.='sum(case when bode2="'.$xbode.'" then egreso end) as '.$xbode.$char_unibod.', ';
//                $fields.='sum(case when bode2="'.$xbode.'" then egreso end) as '.$xbode.'_U2, ';
          }
          $fields.='sum(egreso) as total,';
          $fields.='item_umdd as umdd,';
          
          if($cost=='true')
          {
               msql_data_seek($res_bode);
//                if(msql_num_rows($res_bode)>1)
               while($aso_bode=msql_fetch_assoc($res_bode))
               {
                    $xbode=$aso_bode['bode_codigo'];
                    $fields.='sum(case when bode2="'.$xbode.'" then (credito) end) as '.$xbode.'_$, ';
               }
               $fields.='sum(credito) as total_$, ';
               $fields.='sum(credito)/sum(egreso) as prom_$, ';
          }
          $fields.='item_status as st,';
     }
     
          
     if(mb_stristr2('.iievta',$info))
     { 
//           $xfecha=date('Y-m-01',strtotime($fecha1));
//           while($xfecha<=$fecha2)
//           {
//                $xanio=date('Y',strtotime($xfecha));
//                $xmes=date('m',strtotime($xfecha));
//                $xames=date('Y-m',strtotime($xfecha));
//                $fields.='sum(case when left(fecha,7)="'.$xames.'" then (cant) end) as '.$xanio.'_'.$xmes.',';
//                $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
//           }
          
//           $fields.='sum(cant) as total,';
          
     }
          
     if($info=='iibode')
     {
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          $fields.='case when trim(item_codigo) not like concat("%",trim(item_codigov),"") then trim(item_codigov) else "" end as cod_vta,';
//           $fields.='case when trim(item_codigo) not like concat("%",trim(item_codigov),"%") then item_codigov else concat("*",item_codigov) end as cod_vta,';

          $fields.='sum(stock) as stock,';
          
          $res_bode=msql_query($sql_bode,$link_data);
          if(msql_num_rows($res_bode)>1)
          while($aso_bode=msql_fetch_assoc($res_bode))
          {
               $xbode=trim($aso_bode['bode_codigo']);
               $fields.='sum(case when bode="'.$xbode.'" then stock end) as '.$xbode.$char_unibod.', ';
          }
          $fields.='item_umdd as umdd,';

          $fields.=$col_pcli.' as pedido,';
          
          if(!empty($bode))
          {
               $fields.='sum(case when item_umdd like "KG%" or item_umdd like "KIL%" then stock/50 else 0 end) as S_50K, ';
               $fields.='sum(case when item_umdd like "KG%" or item_umdd like "KIL%" then stock/25 else 0 end) as S_25K, ';
          }

          if($cost=='true')
          {
//                $fields.='sum(saldo) as saldo_$, ';
               $fields.='sum(saldo) as costo_$, ';
               msql_data_seek($res_bode);
               if(msql_num_rows($res_bode)>1)
               while($aso_bode=msql_fetch_assoc($res_bode))
               {
                    $xbode=$aso_bode['bode_codigo'];
                    $fields.='sum(case when bode="'.$xbode.'" then saldo end) as '.$xbode.'_$, ';
               }
               $fields.='avg(puni) as cost_prom, ';          
//                $fields.='cprom as cost_prom, ';          
          }
          
          
          if(mb_stristr2($prec,'puni'))
          {
               $fields.='sum(stock*item_puni1) as valor_$, ';

               msql_data_seek($res_bode);
               if(msql_num_rows($res_bode)>1)
               while($aso_bode=msql_fetch_assoc($res_bode))
               {
                    $xbode=$aso_bode['bode_codigo'];
                    $fields.='sum(case when bode="'.$xbode.'" then (stock*item_puni1) end) as '.$xbode.'_V$, ';
               }

               $fields.='item_puni1 as p_unit, ';          
          }          
          
//                if(mb_stristr2($prec,'puni'))
//                {for($idx=1;$idx<=5;$idx++){$fields.='item_puni'.$idx.' as Unit_'.$idx.',';}}

//                if(!empty($prec))
//                {
//                     $fields.='item_iva as IVA,';
//                     $fields.='item_ice as ICE,';
//                     $fields.='item_irbp as IRBP,';
//                }
               
//                if(mb_stristr2($prec,'pvp'))
//                {for($idx=1;$idx<=5;$idx++){$fields.='item_pvp'.$idx.' as PVP_'.$idx.',';}}
          
          $fields.='item_status as st,';

          
          
          $fields.='sum(case when fecha>="'.$fecha1a.'" and fecha<="'.$fecha2.'" and docu in ("EB10","EB19") then abs(stock) end) as vta_con_hide,';
          $fecha2a=$fecha1a;
          for($cmes=1; $cmes<=12; $cmes++)
          {
               $fecha2a=date('Y-m-t',strtotime($fecha2a.'28 days'));
               $fields.='sum(case when fecha<="'.$fecha2a.'" then ifnull(stock,0) end) as stk_mes_'.$cmes.'_hide,';
          }
          
     }
     
     if($info=='iillbb')
     {
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='lsub_descri as lineas,';
          $res_bode=msql_query($sql_bode,$link_data);

          if($cost!='true')
          {
          $fields.='sum(stock) as stock,';
          if(msql_num_rows($res_bode)>1)
          while($aso_bode=msql_fetch_assoc($res_bode))
          {
               $xbode=trim($aso_bode['bode_codigo']);
               $fields.='sum(case when bode="'.$xbode.'" then stock end) as '.$xbode.$char_unibod.', ';
          }
               
          }

          if($cost=='true')
          {
               $fields.='sum(saldo) as saldo_$, ';
               msql_data_seek($res_bode);
               if(msql_num_rows($res_bode)>1)
               while($aso_bode=msql_fetch_assoc($res_bode))
               {
                    $xbode=$aso_bode['bode_codigo'];
                    $fields.='sum(case when bode="'.$xbode.'" then saldo end) as '.$xbode.'_$, ';
               }
//           $fields.='avg(puni) as cost_prom, ';          
          }
          
          $fields.='item_status as st,';
     }
     
          
     if($info=='iillcc')
     {
          $fields='';
          $fields.='lsub_codigo as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          if($stock)
          {$fields.='(stock) as stock,';}
          $fields.='item_umdd as umdd,';
          $fields.='" " as conteo_1,';
          $fields.='" " as conteo_2,';
          $fields.='" " as diferencia,';
          $fields.='" " as obser,';
//           $fields.='item_ean13bc,';
          $fields.='item_status as st,';
     }
     
     }
     
     // CAJA /BCOS
     {
     if($info=='cjblog')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='replace(replace(docu_descri,"ING.X","X"),"EGR.X","X") as documento,';
          $fields.='caja,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          
          $fields.='sum(case when left(docu,2)="IE" then saldo end) as $_ing_efe,';
          $fields.='sum(case when left(docu,2)="EE" and docu!="EE13" then abs(saldo) end) as $_egr_efe,';
          $fields.='sum(case when left(docu,4)="EE13" then abs(saldo) end) as $_dep_efe,';
//           $fields.='sum(case when left(docu,2)in("IE","EE") then saldo end) as $_tot_efe,';
          
          $fields.='sum(case when left(docu,2)="IC" then saldo end) as $_ing_che,';
          $fields.='sum(case when left(docu,2)="EC" then abs(saldo) end) as $_dep_che,';
//           $fields.='sum(case when left(docu,2)in("IC","EC") then saldo end) as $_tot_che,';
          
          $sql_docu='select distinct left(docu_codigo,2) as docu_codigo from docu0 inner join caja1 on left(docu_codigo,2)=left(docu,2) ';
          $sql_docu.='where docu_status not in("I","X") ';
          $sql_docu.='order by substring(docu_codigo,1,1) desc,substring(docu_codigo,2,1) desc ';
          $res_docu=msql_query($sql_docu,$link_data);
          while($aso_docu=msql_fetch_assoc($res_docu))
          {
//                $xdocu=trim($aso_docu['docu_codigo']);
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,2) like "'.$xdocu.'%" then abs(saldo) end) as '.$xdocu.'_, ';
          }

          $fields.='docum as docum_hide,';
          $fields.='ptoem as ptoem_hide,';
          $fields.='numer,';

          $fields.='left(enti,10) as enti,';
          $fields.='enti_descri as nombre,';
          
          $fields.='case when concat(concepto_t, detalle_t)!="" then concat(concepto_t," /",detalle_t) else "" end as concepto,';
          $fields.='if(b_o>0,1,0) as b_o,';
          $fields.='substring(idate2,3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
          
          
          
     }
          
     if($info=='cjresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='caja,';
          $fields.='caba2 as caba2_hide,';
          
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          $fields.='case when saldo>0 then sum(abs(saldo)) else 0 end as debito,';
          $fields.='case when saldo<0 then sum(abs(saldo)) else 0 end as credito,';
//           $fields.='abs(saldo) as valor,';
//           $fields.='docum as docum_hide,';
          $fields.='docum,';
          $fields.='numer,';
          $fields.='caba2,';
//           $fields.='case when fecha=fcobro or ifnull(fcobro,"")="" then convert("0000-00-00 00:00:00",date) else fcobro end as f_cobro,';
          $fields.='case when ifnull(fcobro,"")="" or docu not like "ICH%" then convert("0000-00-00 00:00:00",date) else fcobro end as f_cobro,';
          $fields.='ptoem as ptoem_hide,';
          $fields.='left(enti,10) as enti,';
          $fields.='enti_descri as nombre,';
          if($cost=='true')
          {
          $fields.='sum(abs(saldo)) as total,';
          }

          
//           $fields.='numfac*1 as numfac,';
//           $fields.='concepto,';
//           $fields.='enti_descri as nombre,';

          
     }

     if($info=='cjmovi')
     {
          $fields='';
          $fields.='case when fecha<"'.$fecha1.'" then max(fechax) else fecha end as fecha,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else docu end as docu,';
          $fields.='caja,';
          $fields.='case when fecha<"'.$fecha1.'" then "* I N I C I A L *" else docu_descri end as documento,';
          $fields.='case when fecha<"'.$fecha1.'" then 0 else numero end as numero,';

          $fields.='sum(case when fecha<"'.$fecha1.'" and saldo>0 then saldo end) as inicial_hide,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 then saldo end) as debito,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 then abs(saldo) end) as credito,';
          $fields.='sum(saldo) as saldo,';

          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 and left(docu,2)in("IE") then saldo end) as i_efe,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)in("EE") then abs(saldo) end) as e_efe,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 and left(docu,2)in("IC") then saldo end) as i_che,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)in("EC") then abs(saldo) end) as e_che,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)="CH" and ifnull(fcobro,"99999999")<="'.$fecha2.'" then abs(saldo) end) as chq,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)="CH" and ifnull(fcobro,"99999999")>"'.$fecha2.'" then abs(saldo) end) as chq_nc,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else left(enti,10) end as enti,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else enti_descri end as nombre,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else concat(concepto_t," /",detalle_t) end as detalle,';
          
          $fields.='ptoe as ptoe_hide,';
          $fields.='status as st,';
     }
     
          
          
     if($info=='cjdet2')
     {
          $fields='';
          $fields.='docum,';
          $fields.='docd_descri as documento,';
          $fields.='ptoem,';
          $fields.='numer,';
          
          $fields.='abs(cant*puni) as cantidad,';
//           $fields.='abs(total) as total,';
          $fields.='abs(total) as total_hide,';
          $fields.='ctas,';
          $fields.='ctas_descri as contable,';
//           $fields.='detalle_t as detalle,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          
          
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
//           $fields.='b_o,';
//           $fields.='claveacc as claveacc_hide,';
//           $fields.='claveacc2 as claveacc2_hide,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
          
//           $fields.='docum as docum_hide,';
//           $fields.='docum,';
//           $fields.='numer,';
//           $fields.='ptoem as ptoem_hide,';
//           $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as nombre,';
//           if($cost=='true')
//           {
//           $fields.='sum(abs(saldo)) as total,';
//           }

          
//           $fields.='numfac*1 as numfac,';
//           $fields.='concepto,';
//           $fields.='enti_descri as nombre,';

          
     }
          
     if($info=='cjdocu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='replace(replace(docu_descri,"ING.X","X"),"EGR.X","X") as documento,';
          $fields.='caja,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          
          $fields.='sum(case when left(docu,2)="IE" then saldo end) as $_ing_efe,';
          $fields.='sum(case when left(docu,2)="EE" and docu!="EE13" then abs(saldo) end) as $_egr_efe,';
          $fields.='sum(case when left(docu,4)="EE13" then abs(saldo) end) as $_dep_efe,';
//           $fields.='sum(case when left(docu,2)in("IE","EE") then saldo end) as $_tot_efe,';
          
          $fields.='sum(case when left(docu,2)="IC" then saldo end) as $_ing_che,';
          $fields.='sum(case when left(docu,2)="EC" then abs(saldo) end) as $_dep_che,';
//           $fields.='sum(case when left(docu,2)in("IC","EC") then saldo end) as $_tot_che,';
          
          $sql_docu='select distinct left(docu_codigo,2) as docu_codigo from docu0 inner join caja1 on left(docu_codigo,2)=left(docu,2) ';
          $sql_docu.='where docu_status not in("I","X") ';
          $sql_docu.='order by substring(docu_codigo,1,1) desc,substring(docu_codigo,2,1) desc ';
          $res_docu=msql_query($sql_docu,$link_data);
          while($aso_docu=msql_fetch_assoc($res_docu))
          {
//                $xdocu=trim($aso_docu['docu_codigo']);
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,2) like "'.$xdocu.'%" then abs(saldo) end) as '.$xdocu.'_, ';
          }

          $fields.='left(enti,10) as enti,';
//           $fields.='enti_tiporuc as tiporuc,';
          $fields.='enti_descri as nombre,';
          
          $fields.='status as st,';
     }

     if($info=='cjdate')
     {
          $fields='';
          $fields.='fecha,';
//          $fields.='docu,';
//          $fields.='replace(replace(docu_descri,"ING.X","X"),"EGR.X","X") as documento,';
          $fields.='caja,';
          $fields.='caja_descri,';
          $fields.='ptoe as ptoe_hide,';
//          $fields.='numero,';
          
          $fields.='sum(case when left(docu,2)in("IE","EE") and fecha<"'.$fecha1.'" then saldo end) as $_inicial,';
          $fields.='sum(case when left(docu,2)="IE" and fecha>="'.$fecha1.'" then saldo end) as $_ing_efe,';
          $fields.='sum(case when left(docu,2)="EE" and fecha>="'.$fecha1.'" and docu!="EE13" then abs(saldo) end) as $_egr_efe,';
          $fields.='sum(case when left(docu,4)="EE13" and fecha>="'.$fecha1.'" then abs(saldo) end) as $_dep_efe,';
//           $fields.='sum(case when left(docu,2)in("IE","EE") and fecha>="'.$fecha1.'" then saldo end) as $_efectivo,';
          
          $fields.='sum(case when left(docu,2)="IC" and fecha>="'.$fecha1.'" then saldo end) as $_ing_che,';
          $fields.='sum(case when left(docu,2)="EC" and fecha>="'.$fecha1.'" then abs(saldo) end) as $_dep_che,';
//           $fields.='sum(case when left(docu,2)in("IC","EC") and fecha>="'.$fecha1.'" then saldo end) as $_cheque,';
          
          $sql_docu='select distinct left(docu_codigo,2) as docu_codigo from docu0 inner join caja1 on left(docu_codigo,2)=left(docu,2) ';
          $sql_docu.='where docu_status not in("I","X") ';
          $sql_docu.='order by substring(docu_codigo,1,1) desc,substring(docu_codigo,2,1) desc ';
          $res_docu=msql_query($sql_docu,$link_data);
          while($aso_docu=msql_fetch_assoc($res_docu))
          {
//                $xdocu=trim($aso_docu['docu_codigo']);
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,2) like "'.$xdocu.'%" then abs(saldo) end) as '.$xdocu.'_, ';
          }

//          $fields.='enti,';
//          $fields.='enti_descri as nombre,';
          
          $fields.='caja_status as st,';
     }


     if($info=='bcblog')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='replace(replace(docu_descri,"ING.X","X"),"EGR.X","X") as documento,';
          $fields.='ctab,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          
          $fields.='sum(case when left(docu,2)="IE" then saldo end) as $_ing_efe,';
          $fields.='sum(case when left(docu,2)="EE" and docu!="EE13" then abs(saldo) end) as $_egr_efe,';
          $fields.='sum(case when left(docu,4)="EE13" then abs(saldo) end) as $_dep_efe,';
//           $fields.='sum(case when left(docu,2)in("IE","EE") then saldo end) as $_tot_efe,';
          
          $fields.='sum(case when left(docu,2)="IC" then saldo end) as $_ing_che,';
          $fields.='sum(case when left(docu,2)="EC" then abs(saldo) end) as $_dep_che,';
//           $fields.='sum(case when left(docu,2)in("IC","EC") then saldo end) as $_tot_che,';
          
          $sql_docu='select distinct left(docu_codigo,2) as docu_codigo from docu0 inner join caja1 on left(docu_codigo,2)=left(docu,2) ';
          $sql_docu.='where docu_status not in("I","X") ';
          $sql_docu.='order by substring(docu_codigo,1,1) desc,substring(docu_codigo,2,1) desc ';
          $res_docu=msql_query($sql_docu,$link_data);
//           while($aso_docu=msql_fetch_assoc($res_docu))
          {
//                $xdocu=trim($aso_docu['docu_codigo']);
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,2) like "'.$xdocu.'%" then abs(saldo) end) as '.$xdocu.'_, ';
          }

          $fields.='docum as docum_hide,';
          $fields.='ptoem as ptoem_hide,';
          $fields.='numer,';

          $fields.='left(enti,10) as enti,';
//           $fields.='enti_tiporuc as tiporuc,';
          $fields.='enti_descri as nombre,';
          
//           $fields.='status as st,';
//           $fields.='concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")) as concepto,';
          $fields.='case when concat(concepto_t, detalle_t)!="" then concat(concepto_t," /",detalle_t) else "" end as concepto,';
          
//           $fields.='date_format(idate2,"%y-%m-%d") as idate,';
          $fields.='if(b_o>0,1,0) as b_o,';
//           $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          
          $fields.='substring(idate2,3) as idate,';
//           $fields.='idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
          
          
          
     }
          
     if($info=='bcresu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ctab,';
          $fields.='numero,';
          $fields.='case when saldo>0 then sum(abs(saldo)) else 0 end as debito,';
          $fields.='case when saldo<0 then sum(abs(saldo)) else 0 end as credito,';
          
//           $fields.='sum(abs(saldo)) as valor,';
//           $fields.='docum as docum_hide,';
          $fields.='docum,';
          $fields.='numer,';
          $fields.='caba2,';
          $fields.='ptoem as ptoem_hide,';
          
          $fields.='left(enti,10) as enti,';
          $fields.='enti_descri as nombre,';
          if($cost=='true')
          {
          $fields.='sum(abs(saldo)) as total,';
          }
//           $fields.='numfac*1 as numfac,';
//           $fields.='concepto,';
//           $fields.='enti_descri as nombre,';

          $fields.='caba2 as caba2_hide,';
          
          $fields.='ptoe as ptoe_hide,';
          
     }

     if($info=='bcmovi')
     {
          $fields='';
          $fields.='case when fecha<"'.$fecha1.'" then max(fechax) else fecha end as fecha,';
          $fields.='ctab,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else docu end as docu,';
          $fields.='case when fecha<"'.$fecha1.'" then "* I N I C I A L *" else docu_descri end as documento,';
          $fields.='case when fecha<"'.$fecha1.'" then 0 else numero end as numero,';

          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_hide,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 then saldo end) as debito,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 then abs(saldo) end) as credito,';
          $fields.='sum(saldo) as saldo,';

          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 and left(docu,2)in("DB") then saldo end) as depo,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 and left(docu,2)in("DC") then saldo end) as trfr,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)in("DP") then abs(saldo) end) as dbto,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)="RB" then abs(saldo) end) as rete,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)in("DP","NC") and abs(saldo)<=2 then abs(saldo) end) as dbtox,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)="CH" and ifnull(fcobro,"99999999")<="'.$fecha2.'" then abs(saldo) end) as chq,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)="CH" and ifnull(fcobro,"99999999")>"'.$fecha2.'" then abs(saldo) end) as chq_nc,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 and left(docu,2)="CH" then abs(saldo) end) as cheque,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else left(enti,10) end as enti,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else enti_descri end as nombre,';
//           $fields.='case when fecha<"'.$fecha1.'" then "" else concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")) end as detalle,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else concat(concepto_t," /",detalle_t) end as detalle,';
          
//          $fields.='concat(ifnull(concepto,"")," /",ifnull(detalle,"")) as detalle,';
//          $fields.='left(enti,10) as enti,';
//          $fields.='left(enti_descri,15) as enti_descri,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='status as st,';
     }
     
          
     if($info=='bcdocu')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='replace(replace(docu_descri,"ING.X","X"),"EGR.X","X") as documento,';
          $fields.='ctab,';
          $fields.='ptoe as ptoe_hide,';
          $fields.='numero,';
          
          $fields.='sum(case when left(docu,2)in("DB","DC") then saldo end) as debito,';
          $fields.='sum(case when left(docu,2)not in("DB","DC") then abs(saldo) end) as credito,';
//           $fields.='sum(case when left(docu,2)="EE" and docu!="EE13" then abs(saldo) end) as $_egr_efe,';
//           $fields.='sum(case when left(docu,4)="EE13" then abs(saldo) end) as $_dep_efe,';
//           $fields.='sum(case when left(docu,2)in("IE","EE") then saldo end) as $_tot_efe,';
          
//           $fields.='sum(case when left(docu,2)="IC" then saldo end) as $_ing_che,';
//           $fields.='sum(case when left(docu,2)="EC" then abs(saldo) end) as $_dep_che,';
//           $fields.='sum(case when left(docu,2)in("IC","EC") then saldo end) as $_tot_che,';
          
          $sql_docu='select distinct left(docu_codigo,2) as docu_codigo from docu0 inner join bcos1 on left(docu_codigo,2)=left(docu,2) ';
          $sql_docu.='where docu_status not in("I","X") ';
          $sql_docu.='order by substring(docu_codigo,1,1) desc,substring(docu_codigo,2,1) desc ';
          $res_docu=msql_query($sql_docu,$link_data);
          while($aso_docu=msql_fetch_assoc($res_docu))
          {
//                $xdocu=trim($aso_docu['docu_codigo']);
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,2) like "'.$xdocu.'%" then abs(saldo) end) as '.$xdocu.'_, ';
          }

          $fields.='left(enti,10) as enti,';
//           $fields.='enti_tiporuc as tiporuc,';
          $fields.='enti_descri as nombre,';
//           $fields.='concwhen concat(concepto_t, detalle_t)!="" t_t,"")," /",ifnull(detalle_t,"")) as detalle,'; 
          $fields.='case when concat(concepto_t, detalle_t)!="" then concat(concepto_t," /",detalle_t) else "" end as detalle,';
          $fields.='status as st,';
     }

     if($info=='bcdate')
     {
          $fields='';
          $fields.='fecha,';
//          $fields.='docu,';
//          $fields.='replace(replace(docu_descri,"ING.X","X"),"EGR.X","X") as documento,';
          $fields.='ctab,';
          $fields.='ctab_descri,';
          $fields.='ptoe as ptoe_hide,';
//          $fields.='numero,';
          
          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as $_inicial,';
          $fields.='sum(case when left(docu,2)in("DB","DC") and fecha>="'.$fecha1.'" then saldo end) as debito,';
          $fields.='sum(case when left(docu,2)not in("DB","DC") and fecha>="'.$fecha1.'" then abs(saldo) end) as credito,';
//           $fields.='sum(case when left(docu,2)="EE" and fecha>="'.$fecha1.'" and docu!="EE13" then abs(saldo) end) as $_egr_efe,';
//           $fields.='sum(case when left(docu,4)="EE13" and fecha>="'.$fecha1.'" then abs(saldo) end) as $_dep_efe,';
          $fields.='sum(case when fecha>="'.$fecha1.'" then saldo end) as saldo,';
          
//           $fields.='sum(case when left(docu,2)="IC" and fecha>="'.$fecha1.'" then saldo end) as $_ing_che,';
//           $fields.='sum(case when left(docu,2)="EC" and fecha>="'.$fecha1.'" then abs(saldo) end) as $_dep_che,';
//           $fields.='sum(case when left(docu,2)in("IC","EC") and fecha>="'.$fecha1.'" then saldo end) as $_cheque,';
          
          $sql_docu='select distinct left(docu_codigo,2) as docu_codigo from docu0 inner join bcos1 on left(docu_codigo,2)=left(docu,2) ';
          $sql_docu.='where docu_status not in("I","X") ';
          $sql_docu.='order by substring(docu_codigo,1,1) desc,substring(docu_codigo,2,1) desc ';
          $res_docu=msql_query($sql_docu,$link_data);
          while($aso_docu=msql_fetch_assoc($res_docu))
          {
//                $xdocu=trim($aso_docu['docu_codigo']);
//                $fields.='sum(case when fecha>="'.$fecha1.'" and left(docu,2) like "'.$xdocu.'%" then abs(saldo) end) as '.$xdocu.'_, ';
          }

//          $fields.='enti,';
//          $fields.='enti_descri as nombre,';
          
          $fields.='ctab_status as st,';
     }

     if($info=='bcdet2')
     {
          $fields='';
          $fields.='docum,';
          $fields.='docd_descri as documento,';
          $fields.='ptoem,';
          $fields.='numer,';
          
          $fields.='abs(cant*puni) as cantidad,';
//           $fields.='abs(total) as total,';
          $fields.='abs(total) as total_hide,';
          $fields.='ctas,';
          $fields.='ctas_descri as contable,';
//           $fields.='detalle_t as detalle,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
          
          
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
//           $fields.='b_o,';
//           $fields.='claveacc as claveacc_hide,';
//           $fields.='claveacc2 as claveacc2_hide,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
          
//           $fields.='docum as docum_hide,';
//           $fields.='docum,';
//           $fields.='numer,';
//           $fields.='ptoem as ptoem_hide,';
//           $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as nombre,';
//           if($cost=='true')
//           {
//           $fields.='sum(abs(saldo)) as total,';
//           }

          
//           $fields.='numfac*1 as numfac,';
//           $fields.='concepto,';
//           $fields.='enti_descri as nombre,';

          
     }
          
          
          
     }
     

     // DXCO DXPA
     {

          if($info=='dcdet2')
          {
               $fields='';
               $fields.='docum,';
               $fields.='docd_descri as documento,';
               $fields.='ptoem,';
               $fields.='numer,';

               $fields.='abs(cant*puni) as cantidad,';
     //           $fields.='abs(total) as total,';
               $fields.='abs(total) as total_hide,';
               $fields.='ctas,';
               $fields.='ctas_descri as contable,';
     //           $fields.='detalle_t as detalle,';
               $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';


               $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
     //           $fields.='b_o,';
     //           $fields.='claveacc as claveacc_hide,';
     //           $fields.='claveacc2 as claveacc2_hide,';
               $fields.='iuser as iuser_hide,';
               $fields.='idate as idate_hide,';

     //           $fields.='docum as docum_hide,';
     //           $fields.='docum,';
     //           $fields.='numer,';
     //           $fields.='ptoem as ptoem_hide,';
     //           $fields.='left(enti,10) as enti,';
     //           $fields.='enti_descri as nombre,';
     //           if($cost=='true')
     //           {
     //           $fields.='sum(abs(saldo)) as total,';
     //           }


     //           $fields.='numfac*1 as numfac,';
     //           $fields.='concepto,';
     //           $fields.='enti_descri as nombre,';


          }
          
     }


     // CONTABILIDAD
     {
          
     if($info=='ttsald' or $info=='ttsaln')
     {
          $fields='';
          $fields.='ctas_codi'.$nivel.' as ctas_hide,';
          $fields.='sum(saldo) as saldo,';
     }
     
     if($info=='ttssss' or $info=='ttssnn')
     {
          $fields='';
          $fields.='ctas_codi'.$nivel.' as ctas_hide,';
          $fields.='sum(case when docu="DD00" then saldo end) as dd00_hide,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 then saldo end) as debito,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 then abs(saldo) end) as credito,';
          $fields.='sum(saldo) as saldo,';
     }
     
     if($info=='ttssdd' or $info=='ttssmm')
     {
          $fields='';
          $fields.='ctas_codi'.$nivel.' as ctas_hide,';
          
          if($info=='ttssdd'){$fields.='max(fechax) as fecha,';}
          
          if($info=='ttssmm')
          {$fields.='left(mesx,7) as mes,';}
          
          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_hide,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 then saldo end) as debito,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 then abs(saldo) end) as credito,';
          $fields.='sum(saldo) as saldo,';
     }
     
//      if(mb_stristr2('.ttsscc.ttricc.ttsfcc',$info))
     if(mb_stristr2('.ttsscc.ttricc',$info))
     {
          $fields='';
          $fields.='ctas_codi'.$nivel.' as ctas_hide,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial,';
          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               
               if(mb_stristr2('.ttsscc.ttricc',$info))
               $fields.='sum(case when left(fecha,7)="'.$xames.'" then (saldo) end) as '.$xanio.'_'.$xmes.',';
               
//                if(mb_stristr2('.ttsfcc.',$info))
//                $fields.='sum(case when left(fecha,7)<="'.$xames.'" then (saldo) end) as '.$xanio.'_'.$xmes.',';
               
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
          }
          $fields.='sum(saldo) as saldo,';
          
          
          if(mb_stristr2('.ttsscc.ttricc',$info))
          $fields.='sum(case when fecha>="'.$fecha1.'" then abs(total) end) as total_hide,';
          
          if(mb_stristr2('.ttsfcc.',$info))
          {
//           $fields.='sum(case when fecha>="'.$fecha0.'" then abs(saldo) end) as total_hidex,';
//           $fields.='sum(case when fecha>="'.$fecha0.'" then abs(saldo) end) as total_hide,';
          }
          
//           echo '<br>'.$info;
//           echo '<br>'.$fields;
          
          
     }
          
//      if(1==2)
     if(mb_stristr2('.ttsfcc.',$info))
     {
          $fields='';
          $fields.='ctas_codi'.$nivel.' as ctas_hide,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial,';
          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               $fields.='sum(case when left(fecha,7)<="'.$xames.'" then (saldo) end) as '.$xanio.'_'.$xmes.',';
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
          }
          $fields.='sum(saldo) as saldo,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" then abs(debito-credito) end) as total_x,';
          $fields.='sum(case when fecha>="'.$fecha1.'" then abs(saldo) end) as total_hide,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" then abs(debito-credito) end) as total_hide,';
//           $fields.='sum(case when fecha>="'.$fecha0.'" then (debito-credito) end) as total_hidex,';
//           $fields.='sum(case when fecha>="'.$fecha0.'" then (debito-credito) end) as total_hide,';
     }

          
          
          
          
     if($info=='ttssaa')
     {
          $fields='';
          $fields.='ctas_codi'.$nivel.' as ctas_hide,';
          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               $fields.='sum(case when left(fecha,7)<="'.$xames.'" then (saldo) end) as '.$xanio.'_'.$xmes.',';
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
          }
               $fields.='sum(case when left(fecha,7)<="'.$xames.'" then (saldo) end) as saldo_hide,';
     }
     
     if($info=='ttssff')
     {
          $fields='';
          $fields.='ctas_codi'.$nivel.' as ctas_hide,';
          $xfecha=date('Y-m-01',strtotime($fecha1));
          $xfecha=$fecha2;
          {
               $xames=date('Y-m',strtotime($fecha2));
//                $fields.='sum(case when left(fecha,7)<="'.$xames.'" then (saldo) end) as saldo,';
               $fields.='sum(case when left(fecha,7)<="'.$xames.'" then (saldo) end) as saldo_hide,';
          }
     }
     
     if($info=='ttrrii')
     {
          $fields='';
          $fields.='ctas_codi'.$nivel.' as ctas_hide,';
          $xfecha=date('Y-m-01',strtotime($fecha1));
          $xfecha=$fecha2;
          {
               $xames1=date('Y-m',strtotime($fecha1));
               $xames2=date('Y-m',strtotime($fecha2));
               $fields.='sum(case  ';
//                $fields.='when left(fecha,7)>="'.$xames1.'" and left(fecha,7)<="'.$xames2.'" and left(ctas,1)<=6 then (saldo)*(-1) ';
//                $fields.='when left(fecha,7)>="'.$xames1.'" and left(fecha,7)<="'.$xames2.'" and left(ctas,1)>=7 then (saldo)* (1)  end) as saldo_hide,';
               $fields.='when left(fecha,10)>="'.$fecha1.'" and left(fecha,10)<="'.$fecha2.'" and left(ctas,1)<=6 then (saldo)*(-1) ';
               $fields.='when left(fecha,10)>="'.$fecha1.'" and left(fecha,10)<="'.$fecha2.'" and left(ctas,1)>=7 then (saldo)* (1)  end) as saldo_hide,';
          }
     }
     
     if($info=='ttmovi')
     {
              
          $fields='';
          $fields.='ctas as ctas_hide,';
//           if(empty($ctas))
          if($fkrdx==1)
          {
               $fields.='ctas,';
               $fields.='ctas_descri as contable,';
          }
          
          $fields.='case when fecha<"'.$fecha1.'" then max(fechax) else fecha end as fecha,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else docu end as docu,';
          $fields.='case when fecha<"'.$fecha1.'" then "* I N I C I A L *" else docu_descri end as documento,';
          $fields.='case when fecha<"'.$fecha1.'" then 0 else numero end as numero,';

          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_hide,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 then saldo end) as debito,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 then abs(saldo) end) as credito,';
          $fields.='sum(saldo) as saldo,';

//           if($empr0['empr_codigo']!='posa')
          {
          $fields.='case when fecha<"'.$fecha1.'" then "" else left(enti,10) end as enti,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else enti_descri end as nombre,';
          }
          
//           if($empr0['empr_codigo']!='posa')
          {$fields.='case when fecha<"'.$fecha1.'" then "" else concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")) end as detalle,';}
          
          
//           if($empr0['empr_codigo']=='posa')
//           {$fields.='case when fecha<"'.$fecha1.'" then "" when detalle like "%/%" then left(detalle,position("/" in detalle)) else left(detalle,20) end as detalle,';}
//           {$fields.='case when fecha<"'.$fecha1.'" then "" else left(detalle,position("/" in detalle)) end as detalle,';}
          
          $fields.='ptoe as ptoe_hide,';
//           $fields.='status as st,';
          
//           if($empr0['empr_codigo']!='posa')
          {$fields.='case when fecha<"'.$fecha1.'" then "-" else status end as st,';}
     }
     
     if($info=='ttresu')
     {
          $fields='';
          $fields.='fecha,docu,docu_descri as documento,numero, ';
          $fields.='sum(debito) as debito,';
          $fields.='sum(credito) as credito,';
          $fields.='sum(saldo) as difer,';

          $fields.='concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")) as detalle,';
          $fields.='left(enti,10) as enti,';
//           $fields.='left(enti_descri,15) as enti_descri,';
          $fields.='(enti_descri) as enti_descri,';
          $fields.='status as st,';
          
//           $fields.='if(b_e=1 and b_o>0,2,0) as b_o,';
          $fields.='b_o,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';          
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';

          $fields.='ptoe as ptoe_hide,';
          
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
          
     }
     
     if($info=='ttdeta')
     {
          $fields='';
//           $fields.='idnum1 as idnum_hide,';
          $fields.='fecha,docu,docu_descri as documento,numero, ';
//           $fields.='ctas,';
          $fields.='ctas as cuenta,';
          $fields.='ctas_descri as contable,';
          $fields.='sum(debito) as debito,';
          $fields.='sum(credito) as credito,';
//           $fields.='sum(saldo) as difer,';

          $fields.='concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")) as detalle,';
          $fields.='left(enti,10) as enti,';
          $fields.='left(enti_descri,15) as enti_descri,';
          $fields.='status as st,';
          $fields.='mdfrom as mdfrom_hide,';
          $fields.='idfrom as idfrom_hide,';
          
          
     }
     
     if($info=='ttdet2')
     {
          $fields='';
//           $fields.='ctas as ctas, ';
          $fields.='ctas as cuenta, ';
          $fields.='ctas_descri as contable, ';
          $fields.='debito, ';
          $fields.='credito, ';
          $fields.='ifnull(csub,".") as csub,';
          $fields.='ifnull(detalle_t,".") as detalle,';
          
          $fields.='left(enti,10) as enti,';
          $fields.='left(enti_descri,15) as enti_descri,';
          $fields.='status as st,';
          
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
          $fields.='iuser as iuser_hide,';
          $fields.='idate as idate_hide,';
          
          
     }
          

     
     }
     
     // CX COBRAR / PAGAR
     {
          
     if($info=='ccsald' or $info=='cpsald')
     {
          $fields='';
          if($info=='ccsald'){$fields.='enti_zsub as zona,';}
          if($info=='cpsald'){$fields.='enti_tpro as T_Prov,';}
          $fields.='enti,';
          $fields.='left(enti_descri,50) as nombre,';
          $fields.='sum(saldo) as saldo,';
          $fields.='1 as r_saldo,';
          $fields.='sum(anticipo) as anticipo,';
          $fields.='sum(cheque) as cheque,';
          $fields.='sum(protesto) as protesto,';
          
          if($anti=='true')
          {
//                $fields.='case when (sum(saldo))>='.$saldo0.' and diasv>0 then diasv else 0 end as diasv,';               
//                $fields.='max(case when (sum(saldo))>='.$saldo0.' and diasv>0 then diasv else 0 end) as diasv,';               
//                $fields.='(diasv) as diasv,';
               $betw1=1;
               for($idx=0; $idx<count($dias_anti); $idx++)
               {
                    $betw2=$dias_anti[$idx];
                    if($idx==count($dias_anti)){$betw2=9999;}
                    $fields.='case when sum(saldo)>=0.01 and diasv between '.$betw1.' and '.$betw2.' then sum(saldo) else 0 end as A_'.$betw2.',';
//                     $fields.='sum(case when (saldo)>=0.01 and diasv between '.$betw1.' and '.$betw2.' then (saldo) end) as A_'.$betw2.',';
                    $betw1=$dias_anti[$idx]+1;                    
               }
          }
          
          $fields.='vndd_hide,';
          $fields.='enti_vndd_hide,';
          
          if(empty($vndd))
          {$fields.='left(vndd_descri, locate(" ",vndd_descri)+10) as vendedor,';}
          
//           if($info=='ccsald')
          {$fields.='enti_telefonos as telefono,';}
          {$fields.='lower(enti_emails) as emails,';}
          
          $fields.='max(fecha) as u_movi,';
          $fields.='enti_status as st,';
     }

          
     if($info=='ccsacc' or $info=='cpsacc')
     {
          if($info=='ccsacc')
          {$fields.='enti_zsub as zona,';}
          if($info=='cpsacc')
          {$fields.='enti_tpro as T_Prov,';}
          $fields.='enti,';
          $fields.='left(enti_descri,50) as nombre,';

          
          
          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial,';
          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               $fields.='sum(case when left(fecha,7)<="'.$xames.'" then (saldo) end) as '.$xanio.'_'.$xmes.',';
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
          }
          $fields.='sum(case when fecha>="'.$fecha1.'" then (saldo) end) as saldo_hide,';
//           $fields.='sum(case when fecha>="'.$fecha1.'" then (saldo) end) as saldo_x,';
          
          $fields.='sum(saldo) as saldo,';
          $fields.='1 as r_saldo,';
          $fields.='sum(anticipo) as anticipo,';
          $fields.='sum(cheque) as cheque,';
          $fields.='sum(protesto) as protesto,';
          
          $fields.='vndd_hide,';
          $fields.='enti_vndd_hide,';
          
          if(empty($vndd))
          {$fields.='left(vndd_descri, locate(" ",vndd_descri)+10) as vendedor,';}
          $fields.='max(fecha) as u_movi,';
          $fields.='enti_status as st,';
          
          
          
     }
          
          

     if($info=='ccresu' or $info=='cpresu' or $info=='cccred' )
     {
          $fields='';
          if(empty($zhidecols))
          {
          if($info=='ccresu'){$fields.='enti_zsub as zona,';}
          if($info=='cccred'){$fields.='enti_zsub as zona,';}
          if($info=='cpresu'){$fields.='enti_tpro as T_Prov,';}
          }
          
          $fields.='min(fecha) as fecha,';
          $fields.='docum as docu,';
          $fields.='ptoem as ptoe,';
          $fields.='numer*1 as numero,';
          $fields.='vence,';
          if((int)$enti*1==0)
          {
               $fields.='enti,';
               $fields.='left(enti_descri,200) as nombre,';
          }
          
          $fields.='sum(total) as total,';
          
          if(substr($info,2,4)=='resu')
          {
               $fields.='sum(case when substring(docu,1,1)not in("R","N") then (total-saldo) end) as abono,';
               $fields.='sum(case when docu like "N%" then abs(saldo) end) as n_cre,';
               $fields.='sum(case when docu like "R%" then abs(saldo) end) as reten,';
               $fields.='sum(case when docu like "ICH%" then abs(cheque) end) as cheque,';
               $fields.='max(case when docu like "R%" then idnum1 end) as idreten_hide,';
          }
          
          if(substr($info,2,4)=='cred')
          {
               $fields.='sum(case when fecha>="'.$fecha1.'" and docu like "IE%" then abs(saldo) end) as efecti,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and docu like "IC%" then abs(saldo) end) as cheque,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and docu like "DC%" then abs(saldo) end) as transf,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and docu like "N%" then abs(saldo) end) as n_cre,';
               $fields.='sum(case when fecha>="'.$fecha1.'" and docu like "R%" then abs(saldo) end) as reten,';
               $fields.='max(case when fecha>="'.$fecha1.'" and docu like "R%" then idnum1 end) as idreten_hide,';
          }
          
          $fields.='iva as iva_hide,';
          $fields.='sum(saldo) as saldo,';


          $fields.='case when (sum(saldo))>='.$saldo0.' and diasv>0 then diasv else 0 end as dias_v,';
//           $fields.='max(case when (sum(saldo))>='.$saldo0.' and diasv>0 then diasv else 0 end as dias_v),';

          if($anti=='true')
          {
               $betw1=1;
               for($idx=0; $idx<count($dias_anti); $idx++)
               {
                    $betw2=$dias_anti[$idx];
                    if($idx==count($dias_anti)){$betw2=9999;}
                    $fields.='case when sum(saldo)>=0.01 and diasv between '.$betw1.' and '.$betw2.' then sum(saldo) else 0 end as A_'.$betw2.',';
                    $betw1=$dias_anti[$idx]+1;                    
               }
          }
          
          
          if(empty($zhidecols))
          if($anti!='true')
          {
//                //FC/FP
//                $fields.='case when docu=docum then concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")) ';
//                // CAJA/BCOS
//                $fields.='else concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")," :: ",docu,"-",numero) end as concepto,';
               
               //FC/FP
               $fields.='case when docu=docum and concat(concepto_t,detalle_t)!="" then concat(concepto_t," /",detalle_t) ';
               // CAJA/BCOS
               $fields.='when docu!=docum then concat(concepto_t," /",detalle_t," :: ",docu,"-",numero) ';
               $fields.='else "" end as concepto,';
               
          }

          
          if(empty($zhidecols))
          if($info=='ccresu')
          {
               $fields.='(rcdd_hide) as rcdd_hide,';
               $fields.='(enti_rcdd_hide) as enti_rcdd_hide,';
               $fields.='left(rcdd_descri, locate(" ",rcdd_descri)+5) as rcdd,';
               
               $fields.='(vndd_hide) as vndd_hide,';
               $fields.='(enti_vndd_hide) as enti_vndd_hide,';
               $fields.='left(vndd_descri, locate(" ",vndd_descri)+5) as vndd,';
               
               if(empty($anti))
               {$fields.='case when docu like "%CH%" then max(fcobro) else "" end as f_cobro,';}
          }
          
          if(empty($zhidecols))
          {
               $fields.='max(fecha) as u_movi,';

          }
//           if(substr($info,0,2)=='cc')
//           {$fields.='convert(max(dixco),char) as dixco,';}
          
          $fields.='ifnull(status,"") as st,';
//          $fields.='docu as docu_hide,';
//          $fields.='ptoe as ptoe_hide,';
//          $fields.='numero as numero_hide,';
          
     }
          

     if($info=='ccdeta' or $info=='cpdeta' )
     {
          $fields='';
          
          $fields.='headet as headet_hide,';
          $fields.='min(fecha) as fecha_hide,';

          if($info=='ccdeta')
          {$fields.='concat(docum,ptoem,numer) as docu1_hide,';}
          
          if($info=='cpdeta')
          {$fields.='concat(docum,ptoem,numer,left(enti,10)) as docu1_hide,';}
          
          
          $fields.='(fecha) as fecha,';
          $fields.='docu as docu,';
          $fields.='ptoe as ptoe,';
          $fields.='numero,';
//           $fields.='numero*1 as numero,';
//           $fields.='vence,';
          if((int)$enti*1==0)
          {
               $fields.='enti,';
               $fields.='left(enti_descri,200) as nombre,';
          }
          $fields.='sum(case when saldo>0 then saldo end) as debito,';
          $fields.='sum(case when saldo<0 then abs(saldo) end) as credito,';
          
          $fields.='sum(saldo) as total,';

          if($anti=='true')
          {
               $betw1=1;
               for($idx=0; $idx<count($dias_anti); $idx++)
               {
               $betw2=$dias_anti[$idx];
               if($idx==count($dias_anti)){$betw2=9999;}
               $fields.='case when sum(saldo)>=0.01 and diasv between '.$betw1.' and '.$betw2.' then sum(saldo) else 0 end as A_'.$betw2.',';
               $betw1=$dias_anti[$idx]+1;                    
               }
          }
          
          
//           if($anti!='true')
          {
//                //FC/FP
//                $fields.='case when docu=docum then concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")) ';
//                // CAJA/BCOS
//                $fields.='else concat(ifnull(concepto_t,"")," /",ifnull(detalle_t,"")," :: ",docu,"-",numero) end as concepto,';
               
               //FC/FP
               $fields.='case when docu=docum and concat(concepto_t,detalle_t)!="" then concat(concepto_t," /",detalle_t) ';
               // CAJA/BCOS
               $fields.='when docu!=docum then concat(concepto_t," /",detalle_t," :: ",docu,"-",numero) ';
               $fields.='else "" end as concepto,';
               
          }
          
          if($info=='ccdeta')
          {
               $fields.='left(vndd_descri, locate(" ",vndd_descri)+5) as vndd,';
               $fields.='left(vndd_descri, locate(" ",vndd_descri)+5) as vndd_hide,';
          }

          
          if($info=='ccresu')
          {
               $fields.='(vndd_hide) as vndd_hide,';
               $fields.='(enti_vndd_hide) as enti_vndd_hide,';
               $fields.='left(vndd_descri, locate(" ",vndd_descri)+5) as vndd,';
               $fields.='case when docu like "%CH%" then max(fcobro) else "" end as f_cobro,';
          }
          
//           $fields.='max(fecha) as u_movi,';
          
          $fields.='ifnull(status,"") as st,';
//          $fields.='docu as docu_hide,';
//          $fields.='ptoe as ptoe_hide,';
//          $fields.='numero as numero_hide,';
          
     }
          
          
          
          
          
     if($info=='ccddcc' or $info=='cpddcc')
     {
//          $xround=6;
          $fields='';
          if($info=='ccddcc')
          {$fields.='enti_zsub as zona,';}
          if($info=='cpddcc')
          {$fields.='enti_tpro as T_Prov,';}
          $fields.='enti,';
          $fields.='left(enti_descri,50) as nombre,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 then saldo end) as debito,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 then abs(saldo) end) as credito,';
          $fields.='sum(saldo) as saldo,';
          $fields.='1 as r_saldo,';
          
          $fields.='sum(anticipo) as anticipo,';
          $fields.='sum(cheque) as cheque,';
          $fields.='sum(protesto) as protesto,';
          
          $fields.='max(fecha) as u_movi,';          
          $fields.='enti_status as st,';
     }
          
     if($info=='ccdcdd' or $info=='cpdcdd' or $info=='ccdcmm' or $info=='cpdcmm')
     {
//          $xround=6;
          $fields='';
//           $fields.='enti_zsub as zona,';
//           $fields.='enti,';
//           $fields.='left(enti_descri,50) as nombre,';
          if($info=='ccdcdd' or $info=='cpdcdd')
          {$fields.='fecha,';}
          
          if($info=='ccdcmm' or $info=='cpdcmm')
          {$fields.='left(fecha,7) as mes,';}
          
//           $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 then saldo end) as debito,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 then abs(saldo) end) as credito,';
          $fields.='sum(saldo) as saldo,';
          $fields.='enti_status as st,';
     }
          
     if($info=='ccmovi' or $info=='cpmovi' or $info=='ccanti' or $info=='cpanti')
     {
          $fields='';
          $fields.='case when fecha<"'.$fecha1.'" then max(fechax) else fecha end as fecha,';
          $fields.='case when fecha<"'.$fecha1.'" then "" else docu end as docu,';
          $fields.='case when fecha<"'.$fecha1.'" then "* I N I C I A L *" else docu_descri end as documento,';
          $fields.='case when fecha<"'.$fecha1.'" then 0 else ptoe end as ptoe_hide,';
          $fields.='case when fecha<"'.$fecha1.'" then 0 else numero end as numero,';
          $fields.='sum(case when fecha<"'.$fecha1.'" then saldo end) as inicial_hide,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo>0 then saldo end) as debito,';
          $fields.='sum(case when fecha>="'.$fecha1.'" and saldo<0 then abs(saldo) end) as credito,';
          $fields.='sum(saldo) as saldo,';
//           $fields.='idnum1 as idnum1_hide,';
          $fields.='fcobro as fcobro_hide,';
          $fields.='sum(cheque) as cheque_hide,';
//           $fields.='cair as cair_hide,';
          $fields.='max(cair) as cair_hide,';
          $fields.='base as base_hide,';
          $fields.='max(porc_rta) as porc_rta_hide,';
          $fields.='max(porc_iva) as porc_iva_hide,';
          $fields.='docum,';
          $fields.='enti as enti_hide,';
          $fields.='ptoem as ptoem_hide,';
          $fields.='caja as caja_hide,';
          $fields.='ctab as ctab_hide,';
          $fields.='numer,';
          $fields.='concat(concepto_t," /",detalle_t) as detalle,';
//           $fields.='left(idate,10) as idate,';
//           $fields.='headet as headet_x,';
          
          $fields.='min(status) as st,';
     }
          
     }

     // RETENCIONES
     {
     
     if($info=='rpenti')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='zsub as zona,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
     }

     if($info=='rpitem')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='item,';
          $fields.='item_descri as items,';
     }

     if($info=='rpcair')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='lsub_descri as lineas,';
     }

     if($info=='Xrpxmes')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='left(fecha,7) as mes,';
     }

     if($info=='Xrpxsem')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='asema as A_sem,';
          $fields.='min(fecha) as desde,';
          $fields.='max(fecha) as hasta,';
          $fields.='sema,';
          
     }

     if($info=='Xrpxfec')
     {
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='fecha,';
          $fields.='dia_d as dia,';
          
     }

     if($info=='rpcaxm')
     {
//          $xround=6;
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
     }
     
     if($info=='rpcaxm')
     {
//          $xround=6;
          $fields='';
          $fields.='sum(idnum_c) as _c_,';
          $fields.='item_lsub as linea,';
          $fields.='lsub_descri as lineas,';
          
     }
     
//      if(mb_stristr2('.RPXMES.',$info))
     if(mb_stristr2('.rpxmes.',$info))
     { 
          $xfecha=date('Y-m-01',strtotime($fecha1));
          while($xfecha<=$fecha2)
          {
               $xanio=date('Y',strtotime($xfecha));
               $xmes=date('m',strtotime($xfecha));
               $xames=date('Y-m',strtotime($xfecha));
               $fields.='sum(case when left(fecha,7)="'.$xames.'" then tsubt-tdcto end) as '.$xanio.'_'.$xmes.',';
               $xfecha=date('Y-m-01',strtotime($xfecha .'+1 month'));
          }
          
          $fields.='sum(tsubt-tdcto) as total,';
          
     }

     if(mb_stristr2('.Xrpanxm',$info))
     { 
          for($idx=1; $idx<=12; $idx++)
          {
//                $xround=2;
               $xmes=str_pad($idx,2,'0',STR_PAD_LEFT);
               $fields.='sum(case when substring(fecha,6,2)="'.$xmes.'" then tsubt-tdcto end) as m$_'.$xmes.',';
          }
          $fields.='sum(tsubt-tdcto) as total,';
     }

     if(mb_stristr2('.rpresu.rcresu.',$info))
     {
          $fields='';
          
          {
               $fields.='fecha,';
               $fields.='docu,';
               $fields.='ptoe,';
               $fields.='numero,';
               if($modu=='retc' and $rbco==1)
               {$fields.='if(ifnull(ctab,"")="","-",ctab) as ctab,';}

               $fields.='left(enti,10) as enti,';
               if($info=='rpresu')
               {$fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as proveedor,';}
               if($info=='rcresu')
               {$fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';}
          }
          
          {
               $fields.='cod_cair as cair,';
               $fields.='base_rta,';
               $fields.='porc_rta,';
               $fields.='rete_rta,';
          }
          
          {
               $fields.='cod_iva as iva,';
               $fields.='base_iva,';
               $fields.='porc_iva,';
               $fields.='rete_iva,';
          }
          
          {$fields.='ifnull(total,0) as total,';}
               $fields.='errf as err,';
          

          {
               $fields.='cair_descri as cair_descri_hide,';
               $fields.='status as st,';
               $fields.='b_o,';

               $fields.='numer*1 as numer,';
          }

          if($empr0['empr_zeus']==1)               
          {$fields.='zeus as zeus_check,';}
          
          if($info=='rpresu')
          {
               $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';               
               $fields.='convert(idnum1,char) as idn,';
          }
          
          $fields.='idnum1 as idn_hide,';
          $fields.='docum as docum_hide,';
          $fields.='ptoem as ptoem_hide,';
//           $fields.='numer*1 as numer,';

          
     }

//      if(mb_stristr2('.rprrta.rpriva.rcrta.rcriva.',$info))
     if(mb_stristr2('.rprrta.rpriva.rcrrta.rcriva..rprrxm.rprixm.rcrrxm.rcrixm',$info))
     {
          $fields='';
          
          $fields.='sum(idnum_c) as _c_,';
          
          if(mb_stristr2('.rprrxm.rprixm.rcrrxm.rcrixm.',$info))
          {
//                $fields.='left(fecha,7) as mes,';
               $fields.='left(fecha,4) as AÑO,';
          }
          
          if(mb_stristr2('.rprrta.rcrrta.',$info))
          {
               $fields.='cod_cair as cair,';
               $fields.='base_rta,';
               $fields.='porc_rta,';
               
          }
          
          if(mb_stristr2('.rpriva.rcriva',$info))
          {
               $fields.='cod_iva as iva,';
               $fields.='base_iva,';
               $fields.='porc_iva,';
          }

          
          
          if(mb_stristr2('.rprrxm.rcrrxm',$info))
          {
               $fields.='cod_cair as cair,';
               for($idx=1; $idx<=12; $idx++)
               {
                    $xmes=str_pad($idx,2,'0',STR_PAD_LEFT);
                    $fields.='sum(case when substring(fecha,6,2)="'.$xmes.'" then base_rta end) as base_$'.$xmes.',';
                    $fields.='max(case when substring(fecha,6,2)="'.$xmes.'" then porc_rta end) as porc_'.$xmes.',';
                    $fields.='sum(case when substring(fecha,6,2)="'.$xmes.'" then ifnull(total,0) end) as tot_$'.$xmes.',';
               }
          }
          
          if(mb_stristr2('.rprixm.rcrixm',$info))
          {
//                $fields.='cod_cair as cair,';
               for($idx=1; $idx<=12; $idx++)
               {
                    $xmes=str_pad($idx,2,'0',STR_PAD_LEFT);
                    $fields.='sum(case when substring(fecha,6,2)="'.$xmes.'" then base_iva end) as base_$'.$xmes.',';
                    $fields.='max(case when substring(fecha,6,2)="'.$xmes.'" then porc_iva end) as porc_'.$xmes.',';
                    $fields.='sum(case when substring(fecha,6,2)="'.$xmes.'" then ifnull(total,0) end) as tot_$'.$xmes.',';
               }
          }
          
          
          
          
          
          
//           {$fields.='ifnull(total,0) as total,';}
          {$fields.='sum(ifnull(total,0)) as total,';}
          


          
          if($info=='rpresu')
          {
               $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';               
               $fields.='convert(idnum1,char) as idn,';
          }
          
          $fields.='idnum1 as idn_hide,';
          $fields.='docum as docum_hide,';
          $fields.='ptoem as ptoem_hide,';
//           $fields.='numer*1 as numer,';

          
     }

          
          
          
     if($info=='rpdet2' or $info=='rcdet2')
     {
          $fields='';
          $fields.='stfin as stfin_hide, ';
          $fields.='enti as enti_hide,';          
          $fields.='fecha as fecha_hide,';          
          
          $fields.='cant as base,';
          $fields.='cair as cair,';
          $fields.='cair_descri as impuesto,';
//           $fields.='puni as porc_rete,';
          $fields.='case when ifnull(puni,0)=0 then 1/10000 else puni end as porc_rete,';
          $fields.='total as total,';
          $fields.='docum as docu,';
//           $fields.='total as total,';
//           $fields.='concat(" ",ptoem,"-",numer) as numero,';
          $fields.='ptoem as ptoe,';
          $fields.='numer as numero,';
          $fields.='if(ifnull(detalle,"")="",".",detalle_t) as detalle,';
//           $fields.='if(b_o>0,1,0) as b_o,';
          $fields.='if(b_e=1 and b_o>0,1,0) as b_o,';
//           $fields.='b_o,';
     }
          
     if($info=='rpdeta' or $info=='rcdeta')
     {
          $fields='';
          $fields.='fecha,';
//           $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
          $fields.='enti,';
          
          if($info=='rpdeta')
          {$fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as proveedor,';}
          if($info=='rcdeta')
          {$fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';}
          
//           $fields.='cair,';
          $fields.='cod_cair as cair,';
          $fields.='base_rta,';
          $fields.='porc_rta,';
          $fields.='rete_rta,';
          
          $fields.='cod_iva as iva,';
          $fields.='base_iva,';
          $fields.='porc_iva,';
          $fields.='rete_iva,';
          
          $fields.='total,';
          
          
          
          
//           $fields.='left(enti,10) as enti,';
// //           $fields.='enti_descri as cliente,';
//           $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
// //           $fields.='item,';
// //           $fields.='item_descri as producto,';
          
//           $fields.='cant,';
//           $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
// //          $fields.='subtiva0 as subt_iva0,';
// //          $fields.='subtiva as subt_iva,';
//           $fields.='tiva as iva,';
// //          $fields.='subtice as subt_ice,';
//           $fields.='tice as ice,';
//           $fields.='st_ce,';
     }

     if($info=='rcsrid')
     {
          $fields='';
          $fields.='ptoe,';
          $fields.='concat(ptoe,numero) numero';
          $fields.='claveacc,';
          $fields.='fecha,';
          $fields.='enti as emisor,';
//           $fields.='docu,';
//           $fields.='ptoe,';
//           $fields.='left(enti,10) as enti,';
// //           $fields.='enti_descri as cliente,';
//           $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
//           $fields.='item,';
//           $fields.='item_descri as producto,';
          
//           $fields.='cant,';
//           $fields.='tsubt as subt,';
//           $fields.='tdcto as dcto,';
// //          $fields.='subtiva0 as subt_iva0,';
// //          $fields.='subtiva as subt_iva,';
//           $fields.='tiva as iva,';
// //          $fields.='subtice as subt_ice,';
//           $fields.='tice as ice,';
//           $fields.='saldo as total,';
     }
     
          
          
          
     if($info=='rpblog')
     {
          $fields='';
          $fields.='fecha,';
          $fields.='docu,';
          $fields.='ptoe,';
          $fields.='numero,';
//           $fields.='fecha,';
          $fields.='left(enti,10) as enti,';
//           $fields.='enti_descri as cliente,';
          $fields.='case when length(enti_razsoc)>5 then trim(enti_razsoc) else trim(enti_descri) end as cliente,';
          $fields.='item,';
          $fields.='item_descri as producto,';
          
          $fields.='cant,';
          $fields.='tsubt as subt,';
          $fields.='tdcto as dcto,';
//          $fields.='subtiva0 as subt_iva0,';
//          $fields.='subtiva as subt_iva,';
          $fields.='tiva as iva,';
//          $fields.='subtice as subt_ice,';
          $fields.='tice as ice,';
          $fields.='saldo as total,';
          $fields.='detalle_t as detalle,';
//           $fields.='if(b_o>0,1,0) as b_o,';
//           $fields.='if(b_o>0 and autornum is null,1,0) as b_o,';
          $fields.='if(b_o>0 and ifnull(autornum,"")="",1,0) as b_o,';
          
     }
          
     if(mb_stristr2('.vtresu.clresu',$info))
     {
          if($empr0['empr_automotriz']==1 or $empr0['empr_garage']==1)
          {$fields.='plvh,';}
          
          if($empr0['empr_clinica']==1 or $empr0['empr_veterinaria']==1)
          {$fields.='pcnt_nom1 as paciente,';}
          
     }
        
     if($info=='vtresu' and $cfg_empr=='msg1' and 1==2)
     {
//           $fields.='prrta as p_Rta,';
//           $fields.='priva as p_IVA,';
          $fields.='tsubt*prrta/100 as R_Rta,';
          $fields.='tiva*priva/100 as R_IVA,';
//           $fields.='comi as p_comi,';
          $fields.='round (tsubt*comi/100,2) as Comi_Fir,';
          $fields.='round (saldo-(tsubt*prrta/100)-(tiva*priva/100)-(tsubt*comi/100),2) as Reemb,';
          $fields.='Tercero as Comi_3ro,';
          $fields.='round (saldo-(tsubt*prrta/100)-(tiva*priva/100)-(tsubt*comi/100)-tercero,2) as Neto,';
          
     }
          
     }

       // Softball
     {
     if($info=='sbresu')
       {
          $fields ='';
          $fields.='tipo,';
          $fields.='liga,';
          $fields.='torn_descri as torneo,';
          $fields.='jornada,';
          $fields.='dmy1 as fecha,';
          $fields.='horag as hora,';
          $fields.='team1 as home,';
          $fields.='team2 as guest,';
          if ($ptpa=="lineup")
             {
               $fields.='idnum1 as line1,';
               $fields.='idnum1 as line2,';
             }
          else
               $fields.='idnum1 as juego,';
            
          $fields.='docu as docu_hide,';
          $fields.='numero as numero_hide,';
          $fields.='fecha as fecha_hide, ';
//        $fields.='fn_desc(team2) as guest';
       }

     if($info=='lidet2')
         {
            $fields ='';
            $fields.='FORMAT(bateo,0) as bateo, ';
            $fields.='jugador,';
            $fields.='enti_descri as nombre,';
            $fields.='FORMAT(camisa,0) as camisa, ';
            $fields.='FORMAT(posi,0) as posi, ';
            $fields.='posi_descri as lreu,';
         }
  }


// echo '======'.$info;

     // MAESTROS
     { 
     if(substr($info,0,2)=='mt')
     {
          
          $fields='';
//           $fields.=$modu.'_codigo as codigo,';
          $fields.='convert('.$modu.'_codigo,char) as codigo,';
          $fields.=$modu.'_descri as descripcion,';
          $fields.=$modu.'_tipo as tipo,';

          
          if(mb_stristr2('.lreu.',$modu))
          {
               $fields.=$modu.'_direccion as direccion,';
//                $fields.=$modu.'_grupo as grupo,';
//                $fields.='1 as grupox,';
          }

          if(mb_stristr2('.trty.',$modu))
          {
               $fields.=$modu.'_sector as sector,';
               $fields.=$modu.'_bloques as mz_bloques,';
               $fields.=$modu.'_referencia as referencia,';
               $fields.=$modu.'_grupo as grupo,';
               $fields.=$modu.'_color as color,';
//                $fields.='1 as grupox,';
          }

          
          if(mb_stristr2('.refx',$modu))
          {
               if($empr0['empr_refers']==1)
               {
                    $fields.=$modu.'_referx as refx,';
                    $fields.='ifnull('.$modu.'_referx1,"-") as refx1,';
                    $fields.='ifnull('.$modu.'_referx2,"-") as refx2,';
                    $fields.='ifnull('.$modu.'_referx3,"-") as refx3,';
                    $fields.='ifnull('.$modu.'_referx4,"-") as refx4,';
                    $fields.='ifnull('.$modu.'_referx5,"-") as refx5,';
                    
                    $fields.='trim( ';
                    $fields.='concat( ';
                    $fields.='lpad(ifnull('.$modu.'_referx5,""),4," "), ';
                    $fields.='lpad(ifnull('.$modu.'_referx4,""),4," "), ';
                    $fields.='lpad(ifnull('.$modu.'_referx3,""),4," "), ';
                    $fields.='lpad(ifnull('.$modu.'_referx2,""),4," "), ';
                    $fields.='lpad(ifnull('.$modu.'_referx1,""),4," "), ';
                    $fields.='"" ';
                    $fields.=')) as refx0 ,';
                    
//                     $fields.=$modu.'_status as st,';
               }
          }

          
          if(mb_stristr2('.pk12',$modu))
          {
               $fields.=$modu.'_enti as entidad,';
               $fields.='enti_descri as nombre,';
               $fields.=$modu.'_caduca as caduca,';
               $fields.=$modu.'_file as file,';
          }

          
          if(mb_stristr2('.user.usrt',$modu))
          {
               $fields.=$modu.'_email as e_mail,';
               $fields.=$modu.'_wsapp as wsapp,';
               $fields.=$modu.'_cedula as cedula,';
               $fields.=$modu.'_nickname as alias,';
               $fields.=$modu.'_ptov as pto_vta,';
               $fields.=$modu.'_caja as caja,';
               $fields.=$modu.'_bode as bodega,';
               $fields.=$modu.'_caduca as caduca,';
               $fields.=$modu.'_login as login,';
               if($empr0['empr_refers']==1)
               {
                    $fields.=$modu.'_referx as refx,';
               }
               if($empr0['empr_codigo']=='jwib')
               {
                    $fields.=$modu.'_cong as congre,';
                    $fields.='if('.$modu.'_asem=1,"S","-") as asem,';
                    $fields.='if('.$modu.'_mmae=1,"S","-") as mmae,';
                    $fields.='if('.$modu.'_vida=1,"S","-") as vida,';
                    $fields.='if('.$modu.'_estu=1,"S","-") as estu,';
//                     $fields.='if('.$modu.'_estu=1,"S","N") as estu,';
               }
               
               if($_SESSION['user_tipo']=='sist' )
               {$fields.=$modu.'_pin as pin,';}
     //           $fields.='ifnull('.$modu.'_fechanac,now()-now()) as fec_nac,';
          }

          if(mb_stristr2('.rfrx',$modu))
          {
               $fields.=$modu.'_email as e_mail,';
               $fields.=$modu.'_wsapp as wsapp,';
//                $fields.=$modu.'_cedula as cedula,';
               $fields.=$modu.'_nickname as alias,';
//                $fields.=$modu.'_ptov as pto_vta,';
//                $fields.=$modu.'_caja as caja,';
//                $fields.=$modu.'_bode as bodega,';
               $fields.=$modu.'_caduca as caduca,';
               $fields.=$modu.'_referx as Refer_X,';
          }

          if(mb_stristr2('.vndd.codt',$modu))
          {
               $fields.=$modu.'_ape1 as apellido,';
               $fields.=$modu.'_nom1 as nombre,';
          }
          
          if(mb_stristr2('.ptoe',$modu))
          {
//                $fields.=$modu.'_ptoe as pto_emi,';
//                $fields.='concat(left('.$modu.'_ptoe,3),"-",substring('.$modu.'_ptoe,4,3)) as pto_emi,';
               $fields.='ifnull('.$modu.'_ambice,"1") as ambi_ce,';
//                $fields.=$modu.'_direccion as direccion,';
          }
          
          if(mb_stristr2('.ptov',$modu))
          {
               $fields.='ifnull('.$modu.'_ambice,"1") as ambi_ce,';
               $fields.=$modu.'_ptoe as pto_emi,';
            //   $fields.=$modu.'_hora1 as h_ini,';
            //   $fields.=$modu.'_hora2 as h_fin,';
               $fields.=$modu.'_bode as bodega,';
//                $fields.='concat(left('.$modu.'_ptoe,3),"-",substring('.$modu.'_ptoe,4,3)) as pto_emi,';
               $fields.=$modu.'_direccion as direccion,';
          }
          
          if(mb_stristr2('.ppdd',$modu))
          {
               if($_SESSION['empr_edificio']==1)
               {
                    $fields.=$modu.'_calle2 as piso,';
                    $fields.=$modu.'_callen as dpto,';
               }
               
               if($_SESSION['empr_ciudadela']==1)
               {
                    $fields.=$modu.'_calle2 as mz,';
                    $fields.=$modu.'_callen as villa,';
               }
               
               $fields.=$modu.'_pptario1 as pptario_1,';
               $fields.='enti_descri as propietario,';
               $fields.=$modu.'_wsapp1 as wsapp_1,';
               $fields.=$modu.'_wsapp2 as wsapp_2,';
               
               $fields.=$modu.'_wsappr1 as wsapp_r1,';
               $fields.=$modu.'_wsappr2 as wsapp_r2,';
//                $fields.=$modu.'_ean as ean,';
               
               
               
          }

          if(mb_stristr2('.bbii',$modu))
          {
               $fields.=$modu.'_calle2 as piso_mz,';
               $fields.=$modu.'_callen as dpto_v,';
               
               $fields.=$modu.'_pptario as pptario,';
               $fields.='enti_descri as propietario,';
               $fields.=$modu.'_wsapp1 as wsapp_1,';
               $fields.=$modu.'_wsapp2 as wsapp_2,';
//                if($empr0['empr_inmobil'])
               {
                    $fields.=$modu.'_venta as vta,';
                    $fields.=$modu.'_alqui as alq,';
//                     $fields.=$modu.'_prvc as prvc,';
                    $fields.='prvc_descri as provincia,';
                    $fields.=$modu.'_ciudad as ciudad,';
                    $fields.=$modu.'_direccion as direccion,';
                    $fields.=$modu.'_pventa as venta,';
//                     $fields.='convert(round('.$modu.'_pventa/1000,1),char) as venta,';
                    $fields.=$modu.'_palqui as alquiler,';
                    $fields.=$modu.'_puntos as puntos,';
                    $fields.=$modu.'_avaluo as avaluo,';
                    $fields.=$modu.'_plantas as plantas,';
                    $fields.=$modu.'_frente as frente,';
                    $fields.=$modu.'_fondo as fondo,';
                    $fields.=$modu.'_terreno as terre,';
                    $fields.=$modu.'_constru as const,';
                    $fields.='if('.$modu.'_sala=1,"SI","-") as sala,';
                    $fields.='if('.$modu.'_comedor=1,"SI","-") as come,';
                    $fields.='if('.$modu.'_estudio=1,"SI","-") as estu,';
                    $fields.='if('.$modu.'_cocina=1,"SI","-") as coci,';
                    $fields.=$modu.'_habitac as habi,';
                    $fields.=$modu.'_banio as bano,';
                    $fields.=$modu.'_banio2 as ½_bano,';
                    
                    $fields.='if('.$modu.'_patio=1,"SI","-") as pati,';
                    $fields.='if('.$modu.'_garage=1,"SI","-") as grge,';
                    $fields.='if('.$modu.'_terra=1,"SI","-") as trra,';
                    $fields.='if('.$modu.'_vistamar=1,"SI","-") as vmar,';
                    $fields.='if('.$modu.'_bbq=1,"SI","-") as bbq_,';
                    $fields.='if('.$modu.'_piscina=1,"SI","-") as pisc,';
                    $fields.='if('.$modu.'_jacuzzi=1,"SI","-") as jczz,';
                    
                    
               }
               
               
          }
          
          if(mb_stristr2('.rpis',$modu))
          {
               $fields.=$modu.'_fecha as fecha,';
               $fields.=$modu.'_cedula as cedula,';
               $fields.=$modu.'_iess_tipo as iess_tipo,';
               $fields.=$modu.'_iess_cober as iess_cober,';
               $fields.=$modu.'_seguro as seguro,';
//                $fields.='segu_descri as privado,';
               $fields.='segu_nomcom as privado,';
               $fields.=$modu.'_pdf as pdf,';
//                $fields.='"_" as PDF,';
//                $fields.=$modu.'_fabrica as fabrica,';
//                $fields.=$modu.'_caduca as caduca,';
          }
          
          if(mb_stristr2('.pais',$modu))
          {
               $fields.=$modu.'_ats as ats,';
          }
          
          if(mb_stristr2('.lote',$modu))
          {
               $fields.=$modu.'_item as item,';
               $fields.=$modu.'_impor as impor,';
               $fields.=$modu.'_fabrica as fabrica,';
               $fields.=$modu.'_caduca as caduca,';
          }
          
          if(mb_stristr2('.bode',$modu))
          {
               $fields.=$modu.'_direccion as direccion,';
               $fields.=$modu.'_ctacont as cuenta,';
               $fields.='ctas_descri as contable,';
          }
          
          if(mb_stristr2('.zona',$modu))
          {
               $fields.=$modu.'_ctacont as cuenta,';
               $fields.='ctas_descri as contable,';
          }
          
          if(mb_stristr2('.tpro',$modu))
          {
               $fields.=$modu.'_ctacont as cuenta,';
               $fields.='ctas_descri as contable,';
          }
          
          if(mb_stristr2('.caja.ctab',$modu))
          {
               $fields.=$modu.'_ptoe as pto_emi,';
               $fields.=$modu.'_ctacont as cuenta,';
               $fields.='ctas_descri as contable,';
          }
          
          if(mb_stristr2('.lsub',$modu))
          {
               $fields.=$modu.'_recal as recalculo,';
               if($empr0['empr_cont']==1)
               {
               $fields.=$modu.'_ctainve as cta_inve,';
               $fields.='cta1_descri as cta_inventario,';
               $fields.=$modu.'_ctavtas as cta_vtas,';
               $fields.='cta4_descri as cta_ventas,';
               $fields.=$modu.'_ctacvta as cta_cvta,';
               $fields.='cta5_descri as cta_costv,';
               }
          }
          
          if(mb_stristr2('.clac',$modu))
          {
               $fields.=$modu.'_fecha as fecha,';
               $fields.='tcel_descri as T_CEle,';
//                $fields.='case ';
//                $fields.='when '.$modu.'_tipo="01" then "FACTU" ';
//                $fields.='when '.$modu.'_tipo="03" then "L.COM" ';
//                $fields.='when '.$modu.'_tipo="04" then "N.CRE" ';
//                $fields.='when '.$modu.'_tipo="05" then "N.DEB" ';
//                $fields.='when '.$modu.'_tipo="06" then "G.REM" ';
//                $fields.='when '.$modu.'_tipo="07" then "RETEN" ';
//                $fields.='else "." end as t_comp,';
               $fields.='substring('.$modu.'_codigo,31,9) as numero,';
               if($user_codigo==2)
               {$fields.='substring(clac_codigo,38,10) as autor,';}
               $fields.='left('.$modu.'_enti,10) as enti,';
               $fields.='enti_descri as entidad,';
//                $fields.='ifnull('.$modu.'_upldfec,convert("0000-00-00 00:00:00",date)) as fecha_up,';
               $fields.='substring(ifnull('.$modu.'_upldfec,convert("0000-00-00 00:00:00",date)),3) as fecha_up,';
//                $fields.=''.$modu.'_upldfec as fecha_up,';
          }
          
          if(mb_stristr2('.docu',$modu))
          {
//                $fields.=$modu.'_tabla as tabla,';
               $fields.='ifnull('.$modu.'_tabla,"-") as tabla,';
               $fields.='ifnull('.$modu.'_tice,"-") as tice,';
               $fields.=$modu.'_ctadeb as cta_debito,';
               $fields.=$modu.'_ctacre as cta_credito,';
               $fields.=$modu.'_contcabe as cont_c,';
               $fields.=$modu.'_contdeta as cont_d,';
          }
          
          if(mb_stristr2('.cair',$modu))
          {
               $fields.=$modu.'_porc as porc_rete,';
               $fields.=$modu.'_ctacont1 as cta_rcli,';
               $fields.=$modu.'_ctacont2 as cta_rpro,';
               $fields.=$modu.'_ctacont5 as cta_cont5,';
          }
          
          if(mb_stristr2('.civa',$modu))
          {
               $fields.=$modu.'_porc as porc_iva,';
               $fields.=$modu.'_ctaretc as cta_rcli,';
               $fields.=$modu.'_ctaretp as cta_rpro,';
//                $fields.=$modu.'_ctacont5 as cta_cont5,';
          }
          
          if(mb_stristr2('.mrca',$modu))
          {
               $fields.=$modu.'_pais as pais,';
          }
          
          if(mb_stristr2('.mdvh',$modu))
          {
               $fields.=$modu.'_mrca as marca,';
               $fields.=$modu.'_modelo as modelo,';
//                $fields.='substring_index(plvh_modelo," ",20) as modelo, ';
               $fields.='convert('.$modu.'_anio,char) as año,';
               $fields.=$modu.'_clase as clase,';
               $fields.=$modu.'_motor as motor,';
               $fields.='convert('.$modu.'_cilindraje,char) as cilindraje,';
               $fields.='convert('.$modu.'_potencia,char) as potencia,';
               $fields.='convert('.$modu.'_torque,char) as torque,';
               $fields.='convert('.$modu.'_ejes,char) as ejes,';
               $fields.='convert('.$modu.'_ruedas,char) as ruedas,';
               $fields.='convert('.$modu.'_pax,char) as pax,';
               $fields.='convert('.$modu.'_cargatn,char) as cargatn,';
               $fields.=$modu.'_medidas as medidas,';
               $fields.='convert(round('.$modu.'_volm3,2),char) as vol_m3,';
          }
          
          if(mb_stristr2('.vinn',$modu))
          {
//                $fields.=$modu.'_plvh as plvh,';
               $fields.=$modu.'_mrca as marca,';
               $fields.=$modu.'_modelo as modelo,';
               $fields.='convert('.$modu.'_anio,char) as año,';
               $fields.=$modu.'_clase as clase,';
               $fields.=$modu.'_motor as motor,';
               $fields.='convert('.$modu.'_cilindraje,char) as cilindraje,';
               $fields.='convert('.$modu.'_potencia,char) as potencia,';
               $fields.='convert('.$modu.'_torque,char) as torque,';
               $fields.='convert('.$modu.'_ejes,char) as ejes,';
               $fields.='convert('.$modu.'_ruedas,char) as ruedas,';
               $fields.='convert('.$modu.'_pax,char) as pax,';
               $fields.='convert('.$modu.'_cargatn,char) as cargatn,';
               
               $fields.=$modu.'_clor as color,';
          }
          
          if(mb_stristr2('.plvh',$modu))
          {
               $fields.=$modu.'_mrca as marca,';
               $fields.='substring_index(plvh_modelo," ",20) as modelo, ';
               $fields.='convert('.$modu.'_anio,char) as año,';
               $fields.=$modu.'_clase as clase,';
               $fields.=$modu.'_clor as color,';
               $fields.=$modu.'_wsapp as wsapp,';
//                $fields.=$modu.'_clase as clase,';
               $fields.='lcase(item_descri) as item_d,';
               $fields.=$modu.'_propietario as propietario,';
          }

          if(mb_stristr2('.tcvh',$modu))
          {
               if(empty($clvh))
               {
               $fields.=$modu.'_clvh as clvh,';
               $fields.='clvh_descri as clase,';
               }
               $fields.=$modu.'_item as item,';
               $fields.='lsub_descri as linea,';
               $fields.='item_descri as trabajo,';
               $fields.=$modu.'_puni as puni,';
               $fields.=$modu.'_iva as iva,';
               $fields.=$modu.'_pvp as pvp,';
               if($edit=='true')
               {
//                     $fields.=$modu.'_puni as puni_edit,';
               }
               
          }

          
          if(mb_stristr2('.pmdo',$modu))
          {
               $fields.=$modu.'_puni as puni,';
               $fields.=$modu.'_punic as puni_c,';
               $fields.=$modu.'_punii as puni_i,';
               $fields.=$modu.'_punig as puni_g,';
               
          }

          
          if(mb_stristr2('.tmpr',$modu))
          {
               
               if(empty($mdvh))
               {
               $fields.=$modu.'_mdvh as mdvh,';
               $fields.='mdvh_descri as modelo,';
               }
               
               $fields.=$modu.'_item as item,';
               $fields.='lsub_descri as linea,';
               $fields.='item_descri as trabajo,';

               
               if($edit==1)
               {$fields.=$modu.'_horas as horas_edit,';}
               else
               {$fields.=$modu.'_horas as horas,';}
               
          }
          
          
          
          if(mb_stristr2('.cntn',$modu))
          {
               $fields.='case ';
               $fields.='when substring('.$tabla.'_codigo,4,1)="U" then "CONTENEDOR" ';
               $fields.='when substring('.$tabla.'_codigo,4,1)="J" then "AUXILIAR" ';
               $fields.='when substring('.$tabla.'_codigo,4,1)="Z" then "CHASIS" ';
               $fields.='else "" end as tipo_c,';
               $fields.='substring(cntn_codigo,1,3) as propt, ';
               $fields.='substring(cntn_codigo,5,6) as serie, ';
//                $fields.='cntn_tipo_c as tipo_c, ';
//                $fields.='cntn_propt as propt, ';
//                $fields.='cntn_serie as serie, ';
//                $fields.='convert('.$modu.'_anio,char) as año,';
//                $fields.=$modu.'_clor as color,';
//                $fields.=$modu.'_wsapp as wsapp,';
// //                $fields.=$modu.'_clase as clase,';
//                $fields.='lcase(item_descri) as item_d,';
//                $fields.=$modu.'_propietario as propietario,';
          }
          
//           if($info=='mtenti')
          if(mb_stristr2('.enti.clie.prov',$modu))
          {
//                if(mb_stristr2('.enti.clie',$modu))
//                {$fields.=$modu.'_zsub as zona,';}
               if(mb_stristr2('.enti.prov',$modu))
               {$fields.=$modu.'_tpro as t_prov,';}
               
               $fields.='ifnull('.$modu.'_razsoc,"") as raz_social,';
//                $fields.='case when ifnull('.$modu.'_razsoc,"")='.$modu.'_descri then "" else '.$modu.'_razsoc end as raz_social,';
               $fields.='case when ifnull('.$modu.'_nomcom,"")='.$modu.'_descri then "" else '.$modu.'_nomcom end as nom_comercial,';

               $fields.=$modu.'_pais as pais,';
     //           $fields.=$modu.'_prvc as prvc,';
               $fields.=$modu.'_direccion as direccion,';
               
               
               if($user0['user_hide_wsapp']==1)
               {
                    $fields.='concat("******",right('.$modu.'_telefono,4)) as telefono,';
                    $fields.='concat("******",right('.$modu.'_wsapp,4)) as wsapp,';
               }               
               if($user0['user_hide_wsapp']!=1)
               {
                    $fields.=$modu.'_telefono as telefono,';
                    $fields.=$modu.'_wsapp as wsapp,';
               }               
              
     //           $fields.=$modu.'_email as email,';
               $fields.='lower('.$modu.'_email) as email,';
     //           $fields.=$modu.'_tipoCont as tipo_c,';
               $fields.=$modu.'_tipoC as tipo_c,';

               if(mb_stristr2('.clie.prov',$modu))
               {$fields.='max(fecha) as ultima,';}
               
          }
          
          if($info=='mtpcnt')
          {
               $fields.=$modu.'_nom1 as nombre,';
     //           $fields.='ifnull('.$modu.'_fechanac,now()-now()) as fec_nac,';
               $fields.=$modu.'_fechanac as fec_nac,';
               $fields.=$modu.'_edad as edad,';
     //           $fields.='concat('.$modu.'_edad1,":",'.$modu.'_edad2) as edad,';
     //           $fields.=$modu.'_edad2 as edad2,';
               $fields.=$modu.'_sangre as ts,';
               $fields.='substring('.$modu.'_sexod,1,1) as sx,';
     //           $fields.=$modu.'_sexoi as s_,';
               $fields.=$modu.'_icon as i_,';
               $fields.=$modu.'_especie as especie,';
               $fields.=$modu.'_raza as raza,';
               $fields.=$modu.'_color as color,';
               $fields.=$modu.'_factura as facturar,';
     //           $fields.=$modu.'_zsub as zona,';
          }
          
          if($info=='mtzsub')
          {
//                $fields.=$modu.'_vndd as vndd,';
//                $fields.=$modu.'_rcdd as rcdd,';
               $fields.='vndd_descri as vndd,';
               $fields.='rcdd_descri as rcdd,';
          }

          
          if($info=='mtclie' or $info=='mtenti')
          {
               $fields.=$modu.'_zsub as zona,';
//           $fields.=$modu.'_direccion as direccion,';
//                $fields.=$modu.'_vndd as vndd,';
               $fields.=$modu.'_plazo as plazo,';
               $fields.='vndd_descri as vndd,';
               $fields.='rcdd_descri as rcdd,';
          }
          

          
          
          if($info=='mtclie' or $info=='mtenti')
          {
               if(1==2)
              if($empr0['empr_escala_crm'])
              {
                   $fields.=$modu.'_escala_contact as escala_contact,';
                   $fields.=$modu.'_escala_account as escala_account,';
              }
          }

          

          
          
          if($info=='mtcurs')
          {
               $fields.=$modu.'_psco as periodo,';
               $fields.=$modu.'_nivel as nivel,';
               $fields.=$modu.'_seccion as seccion,';
          }
          
          if($info=='mtnrol')
          {
               $fields.=$modu.'_enti as enti,';
               $fields.='enti_descri as nombre,';
               $fields.='curs_psco as periodo,';
               $fields.=$modu.'_curs as curso,';
               $fields.='curs_nivel as nivel,';
               $fields.='curs_seccion as seccion,';
//                $fields.=$modu.'_psco as periodo,';
//                $fields.=$modu.'_nivel as nivel,';
//                $fields.=$modu.'_seccion as seccion,';
          }
          
          
//           if($info=='mtitem')
//           if(mb_stristr2('.mtitem.mtivta',$info))
          
          if(mb_stristr2('.seri',$modu))
          {
               $fields.=$modu.'_numero as num_serie,';
               $fields.=$modu.'_item as item,';
               $fields.='item_descri as producto,';
//                $fields.=$modu.'_modelo as modelo,';
          }          
          
          
          if(mb_stristr2('.item.ivta.ibod',$modu))
          {
               $fields.=$modu.'_lsub as linea,';
               $fields.=$modu.'_mrca as marca,';
               $fields.=$modu.'_modelo as modelo,';
            //   {$fields.=$modu.'_clor as color,';}
            //   {$fields.=$modu.'_tlla as tlla,';}
               {$fields.='clor_descri as color,';}
               {$fields.='tlla_descri as talla,';}
               
//                $fields.='"_" as x,';
               $fields.=$modu.'_ean as ean,';
               $fields.=$modu.'_numpart as num_parte,';
               
//                if($rgsn_ok==1)
//                {
//                $fields.='item_rgsn as regi_sani,';
//                }
               
               if($rgsn_ok==2)               
               {
//                     $fields.=$modu.'_rgsn as regi_sani,';
                    $fields.='rgsn_codreg as regi_sani,';
                    $fields.='rgsn_nomcom as nom_com,';
                    $fields.='rgsn_codpre as cod_pre,';
                    $fields.='rgsn_precom as pre_com,';
               }
//                $fields.=$modu.'_codigov as cod_vta,';
               if(mb_stristr2('.item.ivta.',$modu))
               {$fields.='if(trim('.$modu.'_codigo)!=trim('.$modu.'_codigov),'.$modu.'_codigov,"") as cod_vta,';}
               
               if($empr0['empr_taller'])
               {$fields.=$modu.'_ttrf as tarifa,';}
               
               
               $fields.=$modu.'_umdd as u_mdd,';
               $fields.=$modu.'_duni as d_uni,';
               
               if(mb_stristr2('.item.ibod.',$modu))
               {$fields.=$modu.'_dcos as d_cos,';}
               
               if(mb_stristr2('.item.ivta.',$modu))
               {$fields.=$modu.'_dpre as d_pre,';}
               
                              
               if(mb_stristr2('.item.ivta.',$modu))
               {
                    if(mb_stristr2($prec,'puni'))
                    {for($idx=1;$idx<=5;$idx++){$fields.=$modu.'_puni'.$idx.' as Unit_'.$idx.',';}}

     //                $fields.='round ('.$modu.'_iva,0) as IVA_,';
                    $fields.=$modu.'_iva as IVA,';
                    $fields.=$modu.'_ice as ICE,';
                    $fields.=$modu.'_irbp as IRBP,';
               }
               
               if(mb_stristr2($prec,'pvp'))
               {for($idx=1;$idx<=5;$idx++){$fields.=$modu.'_pvp'.$idx.' as PVP_'.$idx.',';}}
          }

          
//           if(mb_stristr2('.mtigas',$info))
          if(mb_stristr2('.igas',$modu))
          {
               $fields.=$modu.'_cair as cair,';
               $fields.=$modu.'_ctacomp as cuenta,';
               
               $fields.=$modu.'_iva as IVA,';
               $fields.=$modu.'_ice as ICE,';
               $fields.=$modu.'_irbp as IRBP,';
               
          }
          
          
          
          if($info=='mtimgi')
          {
               $fields.=$modu.'_item as item,';
               $fields.=$modu.'_file as file,';
                              
          }
          
          if($info=='mtctas')
          {
               $fields.=$modu.'_tipogd as g_d,';
               $fields.='case when ifnull('.$modu.'_super,"")=1 then "S" else "N" end as s_cia,';
               $fields.='convert('.$modu.'_sri101,char) as sri_101,';
          }

          if($info=='mtadrs')
          {
//          $fields.=$modu.'_calle1 as calle_1,';
//          $fields.=$modu.'_callen as No,';
//          $fields.=$modu.'_calle2 as calle_2,';
          $fields.=$modu.'_enti as ced_ruc,';
          $fields.=$modu.'_pais as pais,';
          $fields.=$modu.'_provincia as provincia,';
          $fields.=$modu.'_ciudad as ciudad,';
          $fields.='concat(ifnull(adrs_calle1,""),"(",ifnull(adrs_callen,""),")",ifnull(adrs_calle3,"")) as direccion,';
          $fields.=$modu.'_calle3 as referencia,';
          }
          
          if($info=='mtrgsn')
          {
               $fields.=$modu.'_codpre as pres_com,';
               $fields.=$modu.'_precom as pres_comercial,';
               $fields.=$modu.'_formaf as for_farmaceut,';
               
               $fields.=$modu.'_farmaco as farmaco,';
//                $fields.='case when locate("tiene",rgsn_priact)=0 then rgsn_priact else substring('.$modu.'_priact,locate("tiene",rgsn_priact)+5) end as pri_activo,';
//                $fields.='case when locate("tiene",rgsn_priact)=0 then rgsn_priact ';
//                $fields.='else trim(substring(rgsn_priact,locate("tiene",rgsn_priact)+6)) end ';
//                $fields.='as pri_activo,';

//                $fields.='case when locate("tiene",rgsn_priact)=0 then rgsn_priact ';
//                $fields.='else trim(substring(rgsn_priact,locate("tiene",rgsn_priact)+6)) end ';
//                $fields.='as '.$modu.'_descri,';

//                $fields.='case when locate("tiene",rgsn_concen)=0 then rgsn_concen ';
//                $fields.='else trim(substring(rgsn_concen,locate("tiene",rgsn_concen)+6)) end ';
//                $fields.='as '.$modu.'_concen,';
               
          }

          
          
          
//           echo '*/*/*'.$info;
          if($info=='mtmtch')
          {
            $fields.=$modu.'_liga as liga,';
            $fields.='torn_descri as torneo,';
            $fields.=$modu.'_jornada as jnda,';
            $fields.=$modu.'_fecha as fecha,';
            $fields.=$modu.'_hora as hora,';
            $fields.=$modu.'_team1 as team_1,';
            $fields.=$modu.'_team2 as team_2,';
//             $fields.='team_descri as team_1,';
//             $fields.='sqad_descri as team_2,';
          }
       
          if($info=='mtposi')
          {
            $fields.=$modu.'_abrevia as abrevia,';
          }
       
          if($info=='mttorn')
          {
            $fields.=$modu.'_liga as liga,';
            $fields.=$modu.'_fecini as inicio,';
            $fields.=$modu.'_fecfin as termino,';
          }

          
          
          $fields.=$modu.'_status as stat,';
//           $fields.='substr('.$modu.'_idate,3) as idate,';
          $fields.='substr(ifnull('.$modu.'_idate,"2000-01-01 00:00:00"),3) as idate,';
          
//           $fields.='substr(ifnull('.$modu.'_udate,"2000-01-01 00:00:00"),3) as udate,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
          
     }
          
     }     

     
     if(!mb_stristr2($info,'resu') and substr($info,0,2)!='mt')
     {
          $stat='';
     }
               
// echo '*/*/'.$info;
     if(substr($info,2,4)=='deta')
     {
//           $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate_hide,';
          $fields.='idate as idate_hide,';
          if(mb_stristr2('.vtas.comp.retc.retp.guia',$modu))
          {
               $fields.='st_ce,';
               $fields.='firmafec as firmafec_hide,';
               $fields.='recepfec as recepfec_hide,';
               $fields.='autorfec as autorfec_hide,';
          }
          
     }

     if(mb_stristr2('.vtres1.clres1.cores1.prres1',$info))
     {
          $fields.='status as st,';
          $fields.='stfin as stfin_hide, ';
          $fields.='b_o,';
          $fields.='ifnull(iuser,0) as usr,';
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
          
          if($empr0['empr_garage']==1)
          {$fields.='substr(ifnull(udate,"2000-01-01 00:00:00"),3) as udate,';}
          
     }
          
     if($info=='vtgrge0')
     {
          $fields='';
          $fields.='plvh,';
          $fields.='plvh_mrca as marca,';
          $fields.='substring_index(plvh_modelo," ",2) as modelo, ';
          $fields.='plvh_clor as color,';
     }



     if(mb_stristr2('.coresu.',$info) and $empr0['empr_codigo']=='pec1')
     {$fields.='ifnull(cchk,0) as cchk_check,';}

          
     if(mb_stristr2('.vtresu.coresu.clresu.prresu.iiresu.caresu.cjresu.bcresu.rmresu',$info))
     {
//           if(mb_stristr2('.vtresu.ccresu.clresu.prresu',$info))
//           $fields.='concat(ifnull(concepto,"")," /",ifnull(detalle,"")) as concepto,';
//           $fields.='caja as caja_edit,';
          if($modu=='vtas')
          {$fields.='tonume*1 as num_modi,';}
          $fields.='concepto_t as concepto,';

          if($modu=='vtas' or $modu=='clie')
          {
//                $sql_vndd='select distinct vndd from vtas1 where status not in ("O","X") and vndd*1>0 and ifnull(vndd,"")!="" limit 5';
               $sql_vndd='select distinct vndd from vtas1 where status not in ("O","X") and ifnull(vndd,"")!="" limit 5';
               $res_vndd=msql_query($sql_vndd,$link_data);
               if(msql_num_rows($res_vndd)>1){$vndd_ok=1;}
               
               if(mb_stristr2('.vtresu.clresu.',$info) and $vndd_ok==1)
               if(is_numeric($vndd)==0 or strlen($vndd)<10)     
               {$fields.='case when length(trim(vndd_ape1))>=3 then concat(vndd_ape1," ",vndd_nom1) else left(vndd_descri, locate(" ",vndd_descri)+5) end as vndd,';}
               $fields.='vndd as vndd_hide,';
               
          }
               
          
          if($modu=='comp' or $modu=='prov')
          {
               $cont_ok=1;
               if(mb_stristr2('.coresu.prresu.',$info) )
               {
                    if(!empty($impor))
                    {
                         $fields.='case when docu in("FP10","NP10") then tsubt else 0 end as f_loc,';
                         $fields.='case when docu="FP15" then tsubt else 0 end as f_ext,';
                    }

//                     if($modu=='comp' or $modu=='prov')
                    if($empr0['empr_impo']==1)
                    {
                         if(empty($edit))
                         {$fields.='impor as nume_impor,';}

                         if($edit>0)
                         {$fields.='case when ifnull(impor,"")="" then "." else impor end as nume_impor,';}
                         
                         if($modu=='prov')
                         {
                              $fields.='costoe1 as c_ext,';
                              $fields.='seguro1 as seguro,';
                              $fields.='flete1 as  flete,';

                              $fields.='costol1 as c_loc,';
                              $fields.='case when ifnull(impor,"")!="" then d_ce else "" end as d_ce,';
                              $fields.='case when ifnull(impor,"")!="" then d_sg else "" end as d_sg,';
                              $fields.='case when ifnull(impor,"")!="" then d_fl else "" end as d_fl,';
                              $fields.='case when ifnull(impor,"")!="" then d_cl else "" end as d_cl,';
                         }
                    }
                    
                    if($empr0['empr_sriats']!=0)
                    {
                         if($modu=='comp')
                         {
//                               $fields.='case when ifnull(claveacc,"")="" then atrz else "CE" end as atrz,';
                              $fields.='if(ifnull(cair,"")="","",cair) as cair,';
                              $fields.='if(ifnull(fpag,"")="","",fpag) as fp,';
                              $fields.='if(ifnull(suco,"")="","",suco) as sc,';
                              $fields.='if(ifnull(autornum,"")="","",autornum) as autornum_hide,';
                              $fields.='if(ifnull(atrz,"")="","",atrz) as atrz,';
                         }
//                          $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(cair,"")="","",cair) end as cair,';
//                          $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(fpag,"")="",".",fpag) end as fp,';
//                          $fields.='case when substring(docu,1,2)in("PT") then "" else if(ifnull(suco,"")="",".",suco) end as sc,';
                    }
                    
               }
               
               if($modu=='comp' and substr($empr0['empr_ruc'],2,1)!=9)
               {$fields.='c_r,';}
               
//                $fields.='fpag,';
//                $fields.='suco,';
               $fields.='cair_descri as cair_descri_hide,';
               $fields.='fpag_descri as fpag_descri_hide,';
               $fields.='suco_descri as suco_descri_hide,';
          }
           
          $fields.='status as st,';
          $fields.='stfin as stfin_hide, ';
          $fields.='b_o,';
          
          // aprobar
//           if($user0['apro']==1)
          if($modu=='clie' or $modu=='prov' or $modu=='opro')
          {
//                $acce_user=accexuser($_SESSION['user_codigo'],$docu);               
//                $fields.='case ';
//                $fields.='when ifnull(status,"-") in("-") then 1 ';
//                $fields.='when ifnull(status,"-") in("A") then 2 ';
//                $fields.='when ifnull(status,"-") not in("-","A","R","O","X") then 3 ';
//                $fields.='else 0 end as b_a,';
          }
          
          $fields.='substr(ifnull(idate,"2000-01-01 00:00:00"),3) as idate,';
          $fields.='convert(idnum1,char) as idn,';
          $fields.='ifnull(iuser,0) as usr,';
//           $fields.='concat(idnum1,if(ifnull(iuser,0)!=""," -",""),iuser) as idn,';          
     }
     
     if(mb_stristr2('.vtresu.rpresu.guresu,coresu.guresu.rcresu',$info))
     {
          $fields.='st_ce,';
          $fields.='firmafec as firmafec_hide,';
          $fields.='recepfec as recepfec_hide,';
          $fields.='autorfec as autorfec_hide,';
          $fields.='autormsj as autormsj_hide,';
          $fields.='recepmsj as recepmsj_hide,';
          $fields.='emailfec as emailfec_hide,';
          $fields.='claveacc as claveacc_hide,';
          
     }

     if(mb_stristr2('.vtcomi.clcomi',$info))
     {
//           $fields.='st_ce,';
//           $fields.='recepfec as recepfec_hide,';
//           $fields.='autorfec as autorfec_hide,';
//           $fields.='autormsj as autormsj_hide,';
     }

     if(mb_stristr2('.vtxfec',$info))
     { 
//           $xround=2;
//           $fields.='sum(tefectivo) as efectivo,';
//           $fields.='sum(tarjeta) as tarjeta,';
//           $fields.='sum(credito) as credito,';
//           $fields.='sum(case when dia_n=1 then tsubt-tdcto end) as LUN,';
//           $fields.='sum(case when dia_n=2 then tsubt-tdcto end) as MAR,';
//           $fields.='sum(case when dia_n=3 then tsubt-tdcto end) as MIE,';
//           $fields.='sum(case when dia_n=4 then tsubt-tdcto end) as JUE,';
//           $fields.='sum(case when dia_n=5 then tsubt-tdcto end) as VIE,';
//           $fields.='sum(case when dia_n=6 then tsubt-tdcto end) as SAB,';
//           $fields.='sum(case when dia_n=0 then tsubt-tdcto end) as DOM,';
     }

     

  
     // fields de cierre
     if(empty($fields)){$fields='*, ';}

     if(!empty($fields) and $modu=='cont')
     {
          $fields.='ctas as ctas_codigo_hide,';
     }
          
     if(!empty($fields) and $modu=='inve')
     {
//           $fields.='idnum1 as idnum1_hide,';
//           $fields.='idfrom as idfrom_hide,';
//           $fields.='mdfrom as mdfrom_hide,';
          $fields.='item_lsub as item_lsub_hide,';
          $fields.='item_codigo as item_codigo_hide,';
          $fields.='item_duni as item_duni_hide,';
          $fields.='item_dpre as item_dpre_hide,';
          $fields.='item_dval as item_dval_hide,';
          $fields.='item_dcos as item_dcos_hide,';
          $fields.='bode_codigo as bode_codigo_hide,';
          $fields.='bode_color as bode_color_hide,';
//           $fields.='status as st_hide ';
     }

     if(!empty($fields) and $modu=='caja')
     {
          $fields.='caja_codigo as caja_codigo_hide,';
          $fields.='caja_color as caja_color_hide,';
     }
     
     if(!empty($fields) and $modu=='bcos')
     {
          if(substr($info,0,2)!='mt')
          {
               $fields.='ctab_codigo as ctab_codigo_hide,';
               $fields.='ctab_color as ctab_color_hide,';
          }
     }

     if(!empty($fields) and substr($info,0,2)=='mt')
     {
          $fields.=$modu.'_status as st_hide ';
     }
     
     if(!empty($fields) and substr($info,0,2)!='mt')
     {
          
//           $fields.='docu_descri as docu_descri_hide,';
          $fields.='tabla1 as tabla1_hide,';
          $fields.='docu as docu_hide,';
          $fields.='numero as numero_hide,';
          $fields.='idnum1 as idnum1_hide,';
//           $fields.='idate as idate_hide,';
          $fields.='iddet as iddet_hide,';
          $fields.='idfrom as idfrom_hide,';
          $fields.='mdfrom as mdfrom_hide,';
//           $fields.='odate as odate_hide,';
//           $fields.='ouser as ouser_hide,';
          $fields.='status as st_hide ';
//           $fields.='tabla as tabla_hide ';
          
          
     }          
  
if($user_codigo==2)
{
//      echo '<br>==== '.$info;
//      echo '<br>==== '.$sql_info;
}



?>