<?php 
declare(strict_types=0);
// session_start();
// echo '<meta http-equiv="refresh" content="5">';
foreach($_GET  as $key => $value){${$key}=trim($value);$_PARAMS[$key]=${$key};}  
foreach($_POST as $key => $value){${$key}=trim($value);$_PARAMS[$key]=${$key};}
include_once('lib_main.php');
$modu=strtolower($modu);

// $empr0=data_maes('empr',$cfg_empr);
// $modu0=data_maes('modu',$modu);
// $user0=data_maes('user',$user_codigo);

vali_modu($modu);

if($tkn=='1234567890'){$_SESSION['user_codigo']='2'; $prnt=1;}

// if($modu=='bcos'){gen_rbnd0($fecha1,$fecha2);}

if(!empty($empr)){$link_data=msql_connect('','','',$empr); $cfg_empr=$empr;}
$user_codigo=$_SESSION['user_codigo'];
// $_SESSION['link_data']=$link_data;

//      echo '<br>';
//      echo '<br>M ';
//      var_dump( $_SESSION['link_data']);


if(empty($user_codigo)){include('user_login0.php');return;}

$empr0=data_maes('empr',$cfg_empr);
$modu0=data_maes('modu',$modu);
$user0=data_maes('user',$user_codigo);


if($modu=='bcos'){gen_rbnd0($fecha1,$fecha2);}
// if($empr0['empr_codigo']=='demo')
// if($modu=='inve'){gen_bode0($fecha1,$fecha2);}



if($empr0['empr_ceuser']==1 and !mb_stristr('sist.supe',$user0['user_tipo'])  )
{$vndd=$user0['user_cedula'];}

$docu0=data_maes('docu',$docu);
$enti0=data_maes('enti',$enti);
$caja0=data_maes('caja',$caja);
$ctab0=data_maes('ctab',$ctab);
$bcos0=data_maes('bcos',$bcos);
$item0=data_maes('item',$item);
$ctas0=data_maes('ctas',$ctas);
$lsub0=data_maes('lsub',$lsub);
$bode0=data_maes('bode',$bode);
$csub0=data_maes('csub',$csub);
$lote0=data_maes('lote',$lote);
$cair0=data_maes('cair',$cair);
$vndd0=data_maes('vndd',$vndd);

if($empr0['empr_clinica']==1 or $empr0['empr_veterinaria']==1)
{$pcnt0=data_maes('pcnt',$pcnt);}

if(gettype($fecha1)=='NULL'){$tsaldo=69;};
if(gettype($fecha1)=='NULL' and $modu=='cont'){$nivel=5;};
if(gettype($fecha1)=='NULL' and $modu=='inve' and $cfg_empr=='hfre'){$lsub='INAG-';};
if(gettype($fecha1)=='NULL' and $modu=='comp' and $cfg_empr=='hfre'){$lsub='INAG-';};

if(empty($pgsize)){$pgsize='A4-V';}
if(empty($info))
{
//      if(gettype($fecha1)=='NULL' and $modu=='sri1'){$info='sriats';};
     if(gettype($fecha1)=='NULL' and $modu=='sri1'){$info='sriats';};
     if(gettype($fecha1)=='NULL' and $modu=='cont'){$info='ttssss';};
     if(gettype($fecha1)=='NULL' and $modu=='vtas'){$info='vtresu';};
     if(gettype($fecha1)=='NULL' and $modu=='clie'){$info='clresu';};
     if(gettype($fecha1)=='NULL' and $modu=='comp'){$info='coresu';};
     if(gettype($fecha1)=='NULL' and $modu=='prov'){$info='prresu';};
     if(gettype($fecha1)=='NULL' and $modu=='caja'){$info='cjdocu';};
     if(gettype($fecha1)=='NULL' and $modu=='bcos'){$info='bcdocu';};
//      if(gettype($fecha1)=='NULL' and $modu=='atvd'){$info='atdeta';};
     if(gettype($fecha1)=='NULL' and $modu=='atvd'){$info='atblog';};
     if(gettype($fecha1)=='NULL' and $modu=='inve'){$info='iibode';};
//      if(gettype($fecha1)=='NULL' and $modu=='inve'){$info='iiresu';};
     if(gettype($fecha1)=='NULL' and $modu=='cxco'){$info='ccsald';};
     if(gettype($fecha1)=='NULL' and $modu=='cxpa'){$info='cpsald';};
     if(gettype($fecha1)=='NULL' and $modu=='plan'){$info='plresu';};
     if(gettype($fecha1)=='NULL' and $modu=='retc'){$info='rcresu';};
     if(gettype($fecha1)=='NULL' and $modu=='retp'){$info='rpresu';};
     if(gettype($fecha1)=='NULL' and $modu=='guia'){$info='guresu';};
     if(gettype($fecha1)=='NULL' and $modu=='opro'){$info='opresu';};
     if(gettype($fecha1)=='NULL' and $modu=='hcli'){$info='hcresu';};
     if(gettype($fecha1)=='NULL' and $modu=='btcr'){$info='btresu';};
     
     if(gettype($fecha1)=='NULL' and $modu=='susa'){$info='suresu';};
     if(gettype($fecha1)=='NULL' and $modu=='nomi'){$info='noresu';};
     
     if(gettype($fecha1)=='NULL' and $modu=='acce'){$info='acdeta';};
     
     if(gettype($fecha1)=='NULL' and $modu=='smma'){$info='mmresu';};
     
     
}

//      if(mb_stristr('smma.vida.asem',$modu)){$modu='jwib'; }
//      if($empr0['empr_codigo']=='jwib'){$modu='jwib';}


if(gettype($fecha1)=='NULL' and mb_stristr('resu.res1',substr($info,-4)))
{
     $sql_coun='select * from '.$modu.'1 where ifnull(status,"")!="X" and fecha>="'.date('Y-m-01').'"';
     $res_coun=msql_query($sql_coun,$link_data);
     if(msql_num_rows($res_coun)>=400){$fecha1=date('Y-m-d');}
}

if(gettype($fecha1)!='NULL' and mb_stristr('resu.res1',substr($info,-4)))
{
     $fechao=$fecha1;
     
     $sql_coun='select * from '.$modu.'1 where ifnull(status,"")!="X" and fecha>="'.$fecha1.'"';
     $res_coun=msql_query($sql_coun,$link_data);
     if(msql_num_rows($res_coun)==0){$fecha1=date('Y-m-01');}

     $sql_coun='select * from '.$modu.'1 where ifnull(status,"")!="X" and fecha>="'.$fecha1.'"';
     $res_coun=msql_query($sql_coun,$link_data);
     if(msql_num_rows($res_coun)==0){$fecha1=$fechao;}
     
}


if(gettype($fecha1)=='NULL')
{
     $fecha1=date('Y-m-01');
     if(date('d')<=7)
     {$fecha1=date('Y-m-01', strtotime(' -1 month'));}
     if($modu=='sri1'){$fecha1=date('Y-01-01');}
};


// echo '<br>====='.$cost;

if(empty($user0['user_tipo'])){$cost='false';}
if(empty($user0['user_tipo'])){$prec='false';}


// echo '<br>====='.$cost;

if(@!mb_stristr('sist.supe',$user0['user_tipo']) and $modu=='inve')
{
     $sql_acce ='select docu,numero, ';
     $sql_acce.='case when docum="COST" and info=1 then 1 else 0 end as cost, ';
     $sql_acce.='case when docum="PREC" and info=1 then 1 else 0 end as prec, ';
     $sql_acce.='status ';
     $sql_acce.='from acce1 ';
     $sql_acce.='left join acce2 on idnum1=idnum2 ';
     $sql_acce.='left join docu0 on docum=docu_codigo ';
     $sql_acce.='where numero='.$user_codigo.' ';
     $sql_acce.='group by idnum1';
     $res_acce=msql_query($sql_acce,$link_data);
     if(empty(msql_result($res_acce,0,'cost'))){$cost='false';}
     if(empty(msql_result($res_acce,0,'prec'))){$prec='false';}
}

if($modu=='atvd')
{
     $sql_updt='update atvd2 set clie=enti2 where clie="" or clie is null';
     $res_updt=msql_query($sql_updt,$link_data);
}

$modu_descri=$modu0['modu_descri'];
$info_descri='INFORMES';
if($info=='vtxfec'){$info_descri='FECHA';}
if($info=='vtxsem'){$info_descri='SEMANAL';}
if($info=='vtxano'){$info_descri='ANUAL';}
if($info=='coxano'){$info_descri='ANUAL';}
if($info=='vtanxm'){$info_descri='ANUAL /MES';}
if($info=='coanxm'){$info_descri='ANUAL /MES';}
if($info=='vtxmes'){$info_descri='MENSUAL';}
if($info=='coenti'){$info_descri='PROVEEDOR';}
if($info=='vtenti'){$info_descri='CLIENTE';}
if($info=='vtenxm'){$info_descri='CLIENTE /MES';}
if($info=='vtptov'){$info_descri='PTO.VENTA';}
if($info=='vtvndd'){$info_descri='VENDEDOR';}
if($info=='vtvnxm'){$info_descri='VENDEDOR /MES';}
if($info=='coxmes'){$info_descri='MENSUAL';}
if($info=='vtitem'){$info_descri='ITEM';}
if($info=='coitem'){$info_descri='ITEM';}
if($info=='coctas'){$info_descri='CTA.CONTABLE';}
if($info=='vtrpm1'){$info_descri='PRECIOS MEDICAMENTOS';}
if($info=='vtitxm'){$info_descri='ITEM /MES';}
if($info=='cocair'){$info_descri='CAIR';}
if($info=='cocaxm'){$info_descri='CAIR /MES';}
if($info=='coitxm'){$info_descri='ITEM /MES';}
if($info=='coctxm'){$info_descri='CTA.CONT. /MES';}
if($info=='vtlsub'){$info_descri='LINEA';}
if($info=='vtlsxm'){$info_descri='LINEA /MES';}
if($info=='ccitem'){$info_descri='ITEM';}
if($info=='vtresu'){$info_descri='RESUMEN';}
if($info=='guresu'){$info_descri='RESUMEN';}
if($info=='opresu'){$info_descri='RESUMEN';}
if($info=='opdeta'){$info_descri='DETALLE';}
if($info=='opitem'){$info_descri='ITEM';}
if($info=='vtres1'){$info_descri='RESUMEN';}
if($info=='vtcomi'){$info_descri='COMISIONES';}
if($info=='caresu'){$info_descri='RESUMEN';}
if($info=='vtdeta'){$info_descri='DETALLE';}
if($info=='codeta'){$info_descri='DETALLE';}
if($info=='corela'){$info_descri='RELACIONES';}
if($info=='coresu'){$info_descri='RESUMEN';}
if($info=='prresu'){$info_descri='RESUMEN';}
if($info=='clresu'){$info_descri='RESUMEN';}
if($info=='clenti'){$info_descri='CLIENTE';}

if($info=='codein'){$info_descri='COMPRAS X INVENT.';}
if($info=='opdein'){$info_descri='O.PRODUC X INVENT.';}

if($info=='cjdocu'){$info_descri='CAJA X DOCUMENTO';}
if($info=='cjdate'){$info_descri='CAJA X FECHA';}

if($info=='bcmovi'){$info_descri='BANCO (MOVIMIENTOS)';}
if($info=='bcdocu'){$info_descri='BANCO X DOCUMENTO';}
if($info=='bcdate'){$info_descri='BANCO X FECHA';}

if($info=='rcresu'){$info_descri='RESUMEN';}
if($info=='rcdeta'){$info_descri='DETALLE';}
if($info=='rpresu'){$info_descri='RESUMEN';}
if($info=='rpdeta'){$info_descri='DETALLE';}

if($info=='iikrdx'){$info_descri='KARDEX';}
if($info=='iiiiee'){$info_descri='INGRESOS - EGRESOS';}
if($info=='iiddcc'){$info_descri='DEBITOS - CREDITOS X LINEAS';}
if($info=='iidcdd'){$info_descri='DEBITOS - CREDITOS (Diarios)';}
if($info=='iidcmm'){$info_descri='DEBITOS - CREDITOS (Mensual)';}
if($info=='iibode'){$info_descri='STOCK X BODEGA';}
if($info=='iidocu'){$info_descri='INGR - EGRE X DOC';}
if($info=='iievta'){$info_descri='EGRE.X VENTAS';}
if($info=='iiicom'){$info_descri='INGR.X COMPRA';}
if($info=='iiecon'){$info_descri='EGRE.X CONSUMO';}
if($info=='iiecxb'){$info_descri='EGRE.X CONSUMO /BODEGA';}
if($info=='iieclb'){$info_descri='EGRE.X CONSUMO /LINEA /BODEGA';}
if($info=='iietxb'){$info_descri='EGRE.X TRANSF /BODEGA';}
if($info=='iietbb'){$info_descri='EGRE.XTRANSF. ORIGEN/DESTINO';}
if($info=='iisxlt'){$info_descri='STOCK X LOTE';}
if($info=='iillcc'){$info_descri='LISTA CONTEO FISICO';}
if($info=='iiresu'){$info_descri='DOCUMENTOS';}
if($info=='iiddbb'){$info_descri='DATA BASE';}
if($info=='iiblog'){$info_descri='DETALLE BODEGA';}
if($info=='iideta'){$info_descri='DETALLE DOCUM';}
if($info=='iiie11'){$info_descri='CAMBIOS';}
if($info=='iiie13'){$info_descri='TRANSFERENCIAS';}
if($info=='iiie14'){$info_descri='PRODUCCION';}
if($info=='iicuxc'){$info_descri='COSTO UNIT.X COMPRA';}

if($info=='iiiecf'){$info_descri='INGR - EGRE X CLIE - FEC';}


if($info=='ccsald'){$info_descri='SALDOS';}
if($info=='ccddcc'){$info_descri='DEBITOS - CREDITOS';}
if($info=='ccdcdd'){$info_descri='DEBITOS - CREDITOS (Diarios)';}
if($info=='ccdcmm'){$info_descri='DEBITOS - CREDITOS (Mensual)';}
if($info=='ccmovi'){$info_descri='MOVIMIENTOS';}
if($info=='ccanti'){$info_descri='ANTICIPOS';}
if($info=='ccresu'){$info_descri='RESUMEN';}

if($info=='cpsald'){$info_descri='SALDOS';}
if($info=='cpddcc'){$info_descri='DEBITOS - CREDITOS';}
if($info=='cpdcdd'){$info_descri='DEBITOS - CREDITOS (Diarios)';}
if($info=='cpdcmm'){$info_descri='DEBITOS - CREDITOS (Mensual)';}
if($info=='cpmovi'){$info_descri='MOVIMIENTOS';}
if($info=='cpanti'){$info_descri='ANTICIPOS';}
if($info=='cpresu'){$info_descri='RESUMEN';}


if($info=='suresu'){$info_descri='RESUMEN';}
if($info=='sudeta'){$info_descri='DETALLE';}

if($info=='noresu'){$info_descri='RESUMEN';}
if($info=='nodeta'){$info_descri='DETALLE';}



if($info=='ttsald'){$info_descri='SALDOS';}
if($info=='ttsaln'){$info_descri='SALDOS (Nivel)';}
if($info=='ttssss'){$info_descri='SUMAS & SALDOS';}
if($info=='ttssdd'){$info_descri='SUMAS & SALDOS (Diario)';}
if($info=='ttssmm'){$info_descri='SUMAS & SALDOS (Mensual)';}
if($info=='ttssnn'){$info_descri='SUMAS & SALDOS (Nivel)';}
if($info=='ttsscc'){$info_descri='SALDOS (Comparativo)';}
if($info=='ttssaa'){$info_descri='SALDOS (Acumulado)';}
if($info=='ttssff'){$info_descri='SITUACION FINANCIERA';}
if($info=='ttsfcc'){$info_descri='SITUACION FINANCIERA (Comparativo)';}
if($info=='ttrrii'){$info_descri='RESULTADO INTEGRAL';}
if($info=='ttricc'){$info_descri='RESULTADO INTEGRAL (Comparativo)';}
if($info=='ttmovi'){$info_descri='LIBRO MAYOR';}
// if($info=='ttldia'){$info_descri='LIBRO DIARIO';}
if($info=='ttresu'){$info_descri='RESUMEN';}
if($info=='ttdeta'){$info_descri='LIBRO DIARIO';}

if($info=='atenti'){$info_descri='X USUARIO';}
if($info=='atclie'){$info_descri='X CLIENTE';}
if($info=='atresu'){$info_descri='X USUARIO/DIA';}
if($info=='atblog'){$info_descri='DETALLE DIARIO';}

if($info=='vtgrge0'){$info_descri='INVENTARIO VHCL';}
if($info=='vtgrge2'){$info_descri='INVENTARIO VHCL';}


if($info=='sriats'){$info_descri='ANEXO TRANSACCIONAL';}



if($info=='iillcc'){$cost='false';}
if($info=='iillcc'){$item='';}
if($info=='iiblog'){$item='';$tbod='';$lsub='';$lote='';$mrca='';$clor='';$mdlo='';}
// if($info=='iideta'){$item='';$tbod='';$lsub='';$lote='';$mrca='';$clor='';$mdlo='';}
if($info=='iideta'){$tbod='';$lsub='';$lote='';$mrca='';$clor='';$mdlo='';}
if($info=='ttresu'){$ctas='';}
if($info=='ttdeta'){$ctas='';}


// 2023-01-16
// if(!mb_stristr($info,'resu') and !mb_stristr($info,'deta')){$docu='';}
// if(!mb_stristr($info,'resu') and !mb_stristr($info,'deta')){$concep='';}
// if(!mb_stristr('resu.deta.',substr($info,2,4))){$docu='';}
// if(!mb_stristr('resu.deta.',substr($info,2,4))){$concep='';}

if(mb_stristr('det2.blog.',substr($info,2,4))){$docu='';}
if(mb_stristr('det2.blog.',substr($info,2,4))){$concep='';}



// if(){$docu='';}


if(!empty($item))
{
     $sql_lsub='select * from item0 where item_codigo="'.$item.'"';
     $res_lsub=msql_query($sql_lsub,$link_data);
     if(msql_num_rows($res_lsub)==1){$lsub=msql_result($res_lsub,0,'item_lsub');}
}

if($info=='iikrdx' and empty($lsub) and empty($item))
{
     $sql_lsub='select ';
     $sql_lsub.='count(item_lsub) as clsub,item_lsub ';
     $sql_lsub.='from inve1 ';
     $sql_lsub.='left join inve2 on idnum1=idnum2 ';
     $sql_lsub.='left join item0 on item=item_codigo ';
     $sql_lsub.='left join bode0 on bode=bode_codigo ';
     $sql_lsub.='where ifnull(status,"") not in ("O","X") ';
     $sql_lsub.='and bode_tipo like "D%" ';
     if($cfg_empr=='hfre')
     {$sql_lsub.='and item_lsub like "INAG%" ';}
     $sql_lsub.='group by item_lsub ';
     $sql_lsub.='order by clsub desc ';
     $sql_lsub.='limit 1 ';
     $res_lsub=msql_query($sql_lsub,$link_data);
     $lsub=msql_result($res_lsub,0,'item_lsub');
     
     $clsub=msql_result($res_lsub,0,'clsub');
     
     if($clsub>=20)
     {
          $sql_item='select * ';
          $sql_item.='from inve1 ';
          $sql_item.='left join inve2 on idnum1=idnum2 ';
          $sql_item.='where ifnull(status,"") not in ("O","X") ';
          $sql_item.='and fecha<=now() ';
          $sql_item.='order by idnum1 desc, iddet desc ';
          $sql_item.='limit 1 ';
          $res_item=msql_query($sql_item,$link_data);
          $item=msql_result($res_item,0,'item');
     }
     
}

if($info=='iikrdx')
{
     $sql_krdx ='select * ';
     $sql_krdx.='from item0 ';
//      $sql_krdx.='where item_status not in("I","X") ';
     $sql_krdx.='where item_status not in("X") ';
     if(!empty($item)){$sql_krdx.='and (item_codigo like "'.$item.'%" or item_ean like "'.$item.'%" or item_codigov like "'.$item.'%"  or item_descri like "%'.$item.'%")';}
     if(!empty($lsub)){$sql_krdx.='and item_lsub like "'.$lsub.'%" ';}
     if(!empty($mrca)){$sql_krdx.='and item_mrca like "'.$mrca.'%" ';}
     
     if(mb_stristr($orden,'Código')){$xorderby='order by item_codigo ';}
     if(mb_stristr($orden,'Nombre')){$xorderby='order by item_descri,item_codigo ';}
     if(mb_stristr($orden,'Linea')){$xorderby='order by item_lsub,item_descri,item_codigo ';}
     
     $sql_krdx.=$xorderby;
     $res_krdx=msql_query($sql_krdx,$link_data);
}

if($info=='cjdocu')
{
     $sql_krdx ='select * ';
     $sql_krdx.='from caja0 ';
     $sql_krdx.='where caja_status not in("I","X") ';
     $sql_krdx.='and caja_codigo in(select distinct caja from caja1 where status not in("O","X")) ';
     if(!empty($caja)){$sql_krdx.='and caja_codigo="'.$caja.'" ';}
     
     $xorderby='order by caja_tipo,caja_codigo ';
     if(mb_stristr($orden,'Código')){$xorderby='order by caja_tipo,caja_codigo ';}
     if(mb_stristr($orden,'Nombre')){$xorderby='order by caja_tipo,caja_descri,caja_codigo ';}
     
     $sql_krdx.=$xorderby;
     $res_krdx=msql_query($sql_krdx,$link_data);
}

if($info=='bcdocu')
{
     $sql_krdx ='select * ';
     $sql_krdx.='from ctab0 ';
     $sql_krdx.='where ctab_status not in("I","X") ';
     $sql_krdx.='and ctab_codigo in(select distinct ctab from bcos1 where status not in("O","X")) ';
     if(!empty($ctab)){$sql_krdx.='and ctab_codigo="'.$ctab.'" ';}
     
     $xorderby='order by ctab_tipo,ctab_codigo ';
     if(mb_stristr($orden,'Código')){$xorderby='order by ctab_tipo,ctab_codigo ';}
     if(mb_stristr($orden,'Nombre')){$xorderby='order by ctab_tipo,ctab_descri,ctab_codigo ';}
     
     $sql_krdx.=$xorderby;
     $res_krdx=msql_query($sql_krdx,$link_data);
}

if($info=='iiblog')
{
     $sql_krdx ='select * ';
     $sql_krdx.='from bode0 ';
     $sql_krdx.='where bode_status not in("I","X") ';
     $sql_krdx.='and bode_codigo in(select distinct bode from inve1 where status not in("O","X")) ';
     if(!empty($bode)){$sql_krdx.='and bode_codigo="'.$bode.'" ';}
     if(!empty($tbod)){$sql_krdx.='and left(bode_tipo,1)="'.substr($tbod,0,1).'" ';}
     
     $xorderby='order by bode_tipo,bode_codigo ';
     if(mb_stristr($orden,'Código')){$xorderby='order by bode_tipo,bode_codigo ';}
     if(mb_stristr($orden,'Nombre')){$xorderby='order by bode_tipo,bode_descri,bode_codigo ';}
//      if(mb_stristr($orden,'Linea')){$xorderby='order by bode_lsub,item_descri,item_codigo ';}
     
     $sql_krdx.=$xorderby;
     $res_krdx=msql_query($sql_krdx,$link_data);
}

if($info=='ccmovi' or $info=='ccresu' or $info=='ccanti')
{
     $sql_krdx ='select * ';
     $sql_krdx.='from enti0 ';
     $sql_krdx.='where enti_status not in("X") ';
     $sql_krdx.='and enti_codigo in(select distinct enti from vtas1 where status not in("O","X")) ';
     if(!empty($enti)){$sql_krdx.='and enti_codigo like "'.substr($enti,0,10).'%" ';}
     if(!empty($zsub)){$sql_krdx.='and enti_zsub like "'.$zsub.'%" ';}
     
     $xorderby='order by enti_zsub,enti_codigo ';
     if(mb_stristr($orden,'Código')){$xorderby='order by enti_zsub,enti_codigo ';}
     if(mb_stristr($orden,'Nombre')){$xorderby='order by enti_zsub,enti_descri,enti_codigo ';}
//      if(mb_stristr($orden,'Linea')){$xorderby='order by bode_lsub,item_descri,item_codigo ';}
     
     $sql_krdx.=$xorderby;
     $res_krdx=msql_query($sql_krdx,$link_data);
}
// echo '<br>*/*/'.$sql_krdx;

$xtitulo='INFORMES';

if($modu=='caja'){$xtitulo='CAJA';}
if($modu=='inve'){$xtitulo='INVENTARIOS';}
if($modu=='vtas'){$xtitulo='VENTAS';}
if($modu=='clie'){$xtitulo='CLIENTES';}
if($modu=='comp'){$xtitulo='COMPRAS';}
if($modu=='prov'){$xtitulo='PROVEEDORES';}
if($modu=='lpro'){$xtitulo='PROVEEDURIA';}
if($modu=='cxco'){$xtitulo='CTAS.X COBRAR';}
if($modu=='cxpa'){$xtitulo='CTAS.X PAGAR';}
if($modu=='cont'){$xtitulo='CONTABILIDAD';}
if($modu=='atvd'){$xtitulo='ACTIVIDADES';}
if($modu=='hcli'){$xtitulo='HISTORIA CLINICA';}

$xtitle=$xtitulo;
$xtopcenter='INFORMES';
if($blog_info==1){$xtitulo='BLOG INFORMES';}
if($blog_info==1){$xtopcenter='BLOG INFORMES';}



if(!empty($modu)){$xtitle=strtoupper($modu);}
$xtitle.=' /'.$info_descri;
if($modu=='cont' and (int)$ctas*1!=0){$xtitle.=' /'.$ctas0['ctas_descri'];}
if($modu=='inve' and (int)$item*1!=0){$xtitle.=' /'.$item0['item_descri'];}
if($modu=='vtas' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}
if($modu=='comp' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}
if($modu=='clie' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}
if($modu=='prov' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}
if($modu=='lpro' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}
if($modu=='cxco' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}
if($modu=='cxpa' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}
if($modu=='atvd' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}
if($modu=='hcli' and (int)$enti*1!=0){$xtitle.=' /'.$enti0['enti_descri'];}


$fecha0=fecha0($modu);
$fecha9=fecha9($modu);
// if(empty($fecha2)){$fecha2=$fecha9;}
// echo '*/*/*/'.$fecha0;
// echo '*/*/*/'.$fecha9;
if(empty($fecha2) and $fecha9>=date('Y-m-d')){$fecha2=$fecha9;}

if(!empty($fecha2))
{
     $fecha2dia=substr($fecha2,-2);
     $fecha2max=substr(date('Y-m-t', strtotime(substr($fecha2,0,7))),-2);
     if($fecha2max<$fecha2dia)
     {$fecha2=date('Y-m-t', strtotime(substr($fecha2,0,7)));}
}

if($info=='iillcc'){$fecha1=$fecha0;}
if(empty($fecha1)){$fecha1=date('Y-m-d',strtotime($fecha0.' +1 day'));}
if(empty($fecha2) and date('H')<6){$fecha2=date('Y-m-d',strtotime('-1 day'));}
// if(empty($fecha2)){$fecha2=date('Y-m-d');}
if(empty($fecha1)){$fecha1=date('Y-m-01', strtotime($fecha2));}
if($fecha1>$fecha2 and $fecha1<date('Y-m-01')){$fecha2=date('Y-m-t', strtotime($fecha1));}
if($fecha1>$fecha2 and $fecha1<date('Y-m-t')){$fecha2=date('Y-m-d');}
if($fecha1>$fecha2){$fecha1=date('Y-m-01', strtotime($fecha2));}
if(empty($fecha2)){$fecha2=date('Y-m-d');}


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

//      $src='//'.$domain.'/_lib/info_modu.js'.$js_version;
//      $script=$dom->appendChild($dom->createElement("script"," "));
//      $script->setAttribute("src",$src);
echo $dom->saveXML();

if($empr0['empr_garage']==1 and $modu=='vtas')
{set_hora2grg($modu,'FC10',$ptov);}


// incluir variacion del costo promedio
if($pvar=='true' and $info=='iiiiee')
{
     $sal_inve=sal_inve($item,$lsub,$bode,$tbod,$fecha0,date('Y-m-d',strtotime($fecha1.'-1 day')),$link_data);
}

//  SELECT DB
include('sele_info.php');
if(empty($prnt) and mb_stristr('resu.blog.res1',substr($info,2,4)))
{
//      $sql_info=str_replace('order by fecha','order by fecha desc, idnum1 desc',$sql_info);
     $sql_info=str_replace('order by fecha','order by fecha desc, idnum1 desc, iddet desc ',$sql_info);
     $sql_info=str_replace('order by docu,ptoe,numero','order by docu,ptoe,numero desc ',$sql_info);
//      $sql_info=str_replace('desc desc ','desc ',$sql_info);
}

if($blog_info==1){$sql_info='';}

$user_info=0;
$user_edit=0;
if(@mb_stristr('sist.supe',$user0['user_tipo']))
{
     $user_info=1;
     $user_edit=1;
}
else
{
     $sql_acce ='select *, ';
//      $sql_acce ='select docu,numero, ';
//      $sql_acce.='case when docum="COST" and info=1 then 1 else 0 end as cost, ';
//      $sql_acce.='case when docum="PREC" and info=1 then 1 else 0 end as prec, ';
     $sql_acce.='sum(cons) as acce_cons, ';
     $sql_acce.='sum(info) as acce_info, ';
     $sql_acce.='status ';
     $sql_acce.='from acce1 ';
     $sql_acce.='left join acce2 on idnum1=idnum2 ';
     $sql_acce.='left join docu0 on docum=docu_codigo ';
     $sql_acce.='left join user0 on numero=user_codigo ';
     $sql_acce.='where user_status not in("I","O","X") ';
     $sql_acce.='and numero="'.$user_codigo.'" ';
     $sql_acce.='and docu_tabla="'.$modu.'" ';
     $sql_acce.='and (cons=1 or info=1) ';
     if(!empty($docu))
     {$sql_acce.='and docu_codigo = "'.$docu.'" ';}
     
     $res_acce=msql_query($sql_acce,$link_data);
//      if(msql_num_rows($res_acce)==0){$user_info=1;}
     $user_info=msql_result($res_acce,0,'acce_info');
     
}
$user_info=1;


if(empty($user_info))
{
     $sql_info='';  
     $msgres.='( NO TIENE ACCESO ) ';
}


if($blog_info==1)
{
     $fecha0=date('Y-m-d',strtotime('-12 month'));
     
     $sql_blog='create temporary table tblog select ';
     $sql_blog.='repeat(" ",4) as modu, ';
     $sql_blog.='date(now()) as fecha, ';
     $sql_blog.='repeat(" ",8) as hora, ';
     $sql_blog.='repeat(" ",250) as file ';
     $res_blog=msql_query($sql_blog,$link_data);
     $sql_blog='delete from tblog';
     $res_blog=msql_query($sql_blog,$link_data);

     $info_scan=scandir('info');
     foreach($info_scan as $file)
     {
          $file_ok=1;
          if(strlen(trim($file))<4){$file_ok=0;}
          if(mb_stristr($file,'__')){unlink('info/'.$file);$file_ok=0;}

          if($file_ok)
          {
               $filec=filectime('info/'.$file);
               $fecha=date('Y-m-d',$filec);
               $hora=date('H:i:s',$filec);
               $imodu=substr($file,5,4);
               $sql_inse='insert into tblog(modu,fecha,hora,file) value("'.$imodu.'","'.$fecha.'","'.$hora.'","'.$file.'")';
               $res_inse=msql_query($sql_inse,$link_data);
               
               if($fecha<=$fecha0){unlink('info/'.$file);}
               
          }
     }

     $sql_blog ='select * from tblog ';
     $sql_blog.='where fecha>="'.$fecha1.'" ';
     $sql_blog.='and fecha<="'.$fecha2.'" ';
     if(!empty($modu))
     {$sql_blog.='and modu like"'.$modu.'" ';}
     $sql_blog.='order by fecha desc, hora desc ';
     $res_blog=msql_query($sql_blog,$link_data);

     $res_info=$res_blog;

     
}




if(!empty($sql_info))
{
     
     if($info=='coresu')
     {
          $sql_clac ='select * from clac0 ';
          $sql_clac.='where clac_tipo in ("01","04","05") ';
          $sql_clac.='and ifnull(clac_status,"")not in("X") ';
          $sql_clac.='and clac_fecha>="'.$fecha1.'" ';
          $sql_clac.='and clac_fecha<="'.$fecha2.'" ';
          $sql_clac.='and clac_enti!="'.$empr0['empr_ruc'].'" ';
          $sql_clac.='and clac_codigo not in(select claveacc from '.$modu.'1 where status!="X" and ifnull(claveacc,"")!="") ';
          if(!empty($enti))
          {$sql_clac.='and clac_codigo like "%'.$enti.'%" ';}
          $sql_clac.='order by clac_fecha ';

          $res_clac=msql_query($sql_clac,$link_data);
          while($aso_clac=msql_fetch_assoc($res_clac))
          {upl_cexml($aso_clac['clac_codigo']);}
     }     
     
//      if($modu=='retc')
//      if($info=='rcresu')
     if($info=='rcresu' or $info=='rcride' or $info=='rcsrid')
     {
          $sql_clac ='select * from clac0 ';
          $sql_clac.='where ifnull(clac_status,"")not in("X") ';
          $sql_clac.='and clac_tipo in ("07") ';
          $sql_clac.='and clac_fecha>="'.$fecha1.'" ';
          $sql_clac.='and clac_fecha<="'.$fecha2.'" ';
          $sql_clac.='and clac_enti != "'.$empr0['empr_ruc'].'" ';
          $sql_clac.='and clac_codigo not in(select claveacc from '.$modu.'1 where ifnull(claveacc,"")!="") ';
          $sql_clac.='order by clac_fecha ';

          $res_clac=msql_query($sql_clac,$link_data);
          
//           echo '<br>*/*/*/'.$sql_clac;
          while($aso_clac=msql_fetch_assoc($res_clac))
          {
               upl_cexml($aso_clac['clac_codigo']); 
          }
     }     

     
     if($modu=='vtas')
     {
          if($cost=='true')
          {
               $sql_vtas='select * from vtas1 where ifnull(status,"")not in("O","X") and fecha>="'.$fecha1.'" and fecha<="'.$fecha2.'"';
               $res_vtas=msql_query($sql_vtas,$link_data);
               while($aso_vtas=msql_fetch_assoc($res_vtas))
               {set_vtascuni($aso_vtas['docu'],$aso_vtas['idnum1']);}
          }
     }

     if($modu=='comp')
     {
     }

     
     if($modu=='inve')
     {
          // actualiza ib13
          if($empr0['empr_codigo']=='demo')
          {
               $sql_eb13='create temporary table docueb13 ';
               $sql_eb13.='select docu as e_docu,bode as e_bode,bode2 as e_bode2,idnum1 as e_idnum,ouser as e_ouser,odate as e_odate,status as e_status ';
               $sql_eb13.='from inve1 where docu="EB13" ';
//                $sql_eb13.='and ifnull(status,"") in("O","X") ';
               $sql_eb13.='and fecha>="'.date('Y-m-01',strtotime('-3 month')).'" ';
//                $sql_eb13.='and idate>="'.date('Y-m-d',strtotime('-1 week')).'" ';
               $res_eb13=msql_query($sql_eb13,$link_data);

               $sql_updt='update inve1,docueb13 ';
               $sql_updt.='set status=e_status, ';
               $sql_updt.='ouser=e_ouser, ';
               $sql_updt.='odate=e_odate ';
               $sql_updt.='where docu="IB13" ';
               $sql_updt.='and bode=e_bode2 ';
               $sql_updt.='and bode2=e_bode ';
               $sql_updt.='and idfrom=e_idnum ';
               $res_updt=msql_query($sql_updt,$link_data);
          }
          

          // asocia ib10 a fp10
          if($info=='iiresu')
          {
               $sql_ib10='select * from inve1 where docu="IB10" and ifnull(numfac,"")="" and fecha>="'.date('Y-m-01',strtotime('-1 month')).'" order by fecha ';
               $res_ib10=msql_query($sql_ib10,$link_data);
               while($aso_ib10=msql_fetch_assoc($res_ib10))
               {get_factu($aso_ib10['docu'],$aso_ib10['idnum1']);}
          }

          
          // genera eb13->ib13
          if($empr0['empr_codigo']=='demo')
          if($fecha1>=date('Y-m-d',strtotime('-1 week')))
          if($info=='iiresu')
          {
//                $sql_eb13='select * from inve1 where docu="EB13" and fecha>="'.date('Y-m-01',strtotime('-1 month')).'" order by fecha ';
//                $sql_eb13='select * from inve1 where docu="EB13" and fecha>="'.date('Y-m-d',strtotime('-1 week')).'" order by fecha ';
//                $res_eb13=msql_query($sql_eb13,$link_data);
//                while($aso_eb13=msql_fetch_assoc($res_eb13))
//                {gen_bode13($aso_eb13['docu'],$aso_eb13['idnum1']);}
               
               $sql_resu=$sql_info;
               $sql_resu=str_replace('order by ','order by fecha, idnum1, ',$sql_resu);
               
               $res_resu=msql_query($sql_resu,$link_data);
               msql_data_seek($res_resu);
               while($aso_resu=msql_fetch_assoc($res_resu))
               {
                    if(mb_stristr('IB11.EB13',$aso_resu['docu']))
                    {$idinve=gen_invent($aso_resu['docu'],$aso_resu['idn']);}
               }
          //      return;
               
          }
          
          
          
          
          if($prcs=='recalc')
          {
               $sql_item='select * from item0 where item_codigo in (select distinct item from inve2)';
               $res_item=msql_query($sql_item,$link_data);
               
               $date1=date('H:i:s');
               while($aso_item=msql_fetch_assoc($res_item))
               {cost_prom($aso_item['item_codigo']);}
               $date2=date('H:i:s');
               $msgres.='Recalculo : '.$date1.' - '.$date2.' == ';
               
          }
          else{if((int)$item>0){cost_prom($item);}}
               
     }
     
     $date1=date('H:i:s');
     $res_info=msql_query($sql_info,$link_data);
     $date2=date('H:i:s');
     
//      $t_secs=secs_diff($date1,$date2);
     
     $msgres.=number_format(msql_num_rows($res_info)).' Resultado(s)...';
//      $msgres.=$_SESSION['qtime'].' secs';
}



// EJECUTA PROCESOS
{

// if($empr0['empr_codigo']=='demo')     
if($prcs=='contab' or $fecha1>=date('Y-m-d',strtotime('-0 day')))
if(mb_stristr($info,'resu'))
{
     $sql_resu=$sql_info;
     $sql_resu=str_replace('order by ','order by fecha, idnum1, ',$sql_resu);
     
     $res_resu=msql_query($sql_resu,$link_data);
     msql_data_seek($res_resu);
     while($aso_resu=msql_fetch_assoc($res_resu))
     {$idcont=gen_contab($aso_resu['docu'],$aso_resu['idn']);}
}     
   
if(mb_stristr($info,'ride'))
{
     $sql_ride=$sql_info11;
//      $res_ride=$res_info;
     $res_ride=msql_query($sql_ride,$link_data);
     msql_data_seek($res_ride);
     while($aso_ride=msql_fetch_assoc($res_ride))
     {
          $prnt=1;
          $docu=$aso_ride['docu'];
          $idnum=$aso_ride['idn'];
          if(empty($idnum)){$idnum=$aso_ride['idnum1'];}
          include('info_docu3.php');
          echo str_repeat('<br>',1);
     }
     return;
}     
     
if(mb_stristr($info,'coresu') )
{
     msql_data_seek($res_info);
     while($aso_info=msql_fetch_assoc($res_info))
     {
          set_uxpre($aso_info['docu'],$aso_info['idn']);
          set_facon($aso_info['docu'],$aso_info['idn']);
     }
}
          
if(mb_stristr($info,'resu') and $prcs=='fcie10')
{
     msql_data_seek($res_info);
     while($aso_info=msql_fetch_assoc($res_info))
     {gen_fcie10($aso_info['docu'],$aso_info['idn']);}
}

if(mb_stristr($info,'resu') and $prcs=='fcpp10')
{
     msql_data_seek($res_info);
     while($aso_info=msql_fetch_assoc($res_info))
     {gen_fcpp10($aso_info['docu'],$aso_info['idn']);}
}

if($modu=='inve')
{
     if($prcs=='recalc' and 1==2)
     {
          msql_data_seek($res_info);
          while($aso_info=msql_fetch_assoc($res_info))
          {cost_prom($aso_info['item'],$fecha2);}
          $res_info=msql_query($sql_info,$link_data);
     }
}

}


// PANTALLA FILTROS

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

//      $sql_imgi='select * from item0 left join imgi0 on item_codigo=imgi_item where item_status not in ("I","X") and imgi_status not in("I","X") limit 1';
//      $res_imgi=msql_query($sql_imgi,$link_data);
//      if(msql_num_rows($res_imgi)!=0){$imgi_ok=1;}

//      $sql_mrca='select * from mrca0 where mrca_status not in("I","X") limit 1';
//      $res_mrca=msql_query($sql_mrca,$link_data);
//      if(msql_num_rows($res_mrca)!=0){$mrca_ok=1;}

//      $sql_lote='select * from lote0 where lote_status not in("I","X") limit 1';
//      $res_lote=msql_query($sql_lote,$link_data);
//      if(msql_num_rows($res_lote)!=0){$lote_ok=1;}
}

// if($modu=='comp')

if($modu=='comp')
{
     $sql_tpro='select distinct enti_tpro from enti0 where ifnull(enti_status,"") not in ("O","X","")';
     $res_tpro=msql_query($sql_tpro,$link_data);
     if(msql_num_rows($res_tpro)>1){$tpro_ok=1;}
}

if($modu=='guia')
{
     $sql_cntn='select * from cntn0 where cntn_status not in("I","X") limit 1';
     $res_cntn=msql_query($sql_cntn,$link_data);
     if(msql_num_rows($res_cntn)!=0){$cntn_ok=1;}
}

if($modu=='comp')
{
     $sql_lsub='select distinct item_lsub from inve1 left join inve2 on idnum1=idnum2 left join item0 on item=item_codigo where status not in ("O","X") and ifnull(item_lsub,"")!=""  limit 10';
     $res_lsub=msql_query($sql_lsub,$link_data);
     if(msql_num_rows($res_lsub)>1){$lsub_ok=1;}
}

if($modu=='inve')
{
     $sql_lsub='select distinct item_lsub from inve1 left join inve2 on idnum1=idnum2 left join item0 on item=item_codigo where status not in ("O","X") and ifnull(item_lsub,"")!=""  limit 10';
     $res_lsub=msql_query($sql_lsub,$link_data);
     if(msql_num_rows($res_lsub)>1){$lsub_ok=1;}
     
     $sql_tbod='select distinct bode_tipo from bode0 where bode_status not in("I","X") and bode_tipo!="" and bode_tipo is not null';
     $res_tbod=msql_query($sql_tbod,$link_data);
     if(msql_num_rows($res_tbod)>1){$tbod_ok=1;}

     $sql_imgi='select * from item0 left join imgi0 on item_codigo=imgi_item where item_status not in ("I","X") and imgi_status not in("I","X") limit 1';
     $res_imgi=msql_query($sql_imgi,$link_data);
     if(msql_num_rows($res_imgi)!=0){$imgi_ok=1;}

     $sql_mrca='select * from mrca0 where mrca_status not in("I","X") limit 1';
     $res_mrca=msql_query($sql_mrca,$link_data);
     if(msql_num_rows($res_mrca)!=0){$mrca_ok=1;}

     $sql_lote='select * from lote0 where lote_status not in("I","X") limit 1';
     $res_lote=msql_query($sql_lote,$link_data);
     if(msql_num_rows($res_lote)!=0){$lote_ok=1;}
}

if(@mb_stristr('vtas.clie.cxco.',$modu))     
{
     $sql_lsub='select distinct item_lsub from vtas1 left join vtas2 on idnum1=idnum2 left join item0 on item=item_codigo where status not in ("O","X") and ifnull(item_lsub,"")!=""  limit 10';
     $res_lsub=msql_query($sql_lsub,$link_data);
     if(msql_num_rows($res_lsub)>1){$lsub_ok=1;}
     
     $sql_zsub='select distinct zsub from vtas1 where status not in ("O","X") and ifnull(zsub,"")!=""  limit 10';
     $res_zsub=msql_query($sql_zsub,$link_data);
     if(msql_num_rows($res_zsub)>1){$zsub_ok=1;}
     
     $sql_vndd='select distinct vndd from vtas1 where status not in ("O","X") and ifnull(vndd,"")!="" and vndd*1>0 limit 20';
     $res_vndd=msql_query($sql_vndd,$link_data);
     if(msql_num_rows($res_vndd)>1){$vndd_ok=1;}
     if(msql_num_rows($res_vndd)>10){$vndd_ok=2;}
//      echo '*/*/*'.$vndd_ok;
}



if($modu=='cxpa')
{
//      $sql_zsub='select * from zsub0 where zsub_status not in ("I","X")  limit 1';

     $sql_tpro='select distinct tpro_codigo from tpro0 where tpro_status not in ("O","X") and length(trim(tpro_codigo))>2 ';
     $sql_tpro.='and(tpro_codigo in(select enti_tpro from enti0 where left(enti_codigo,10) in (select left(enti,10) from comp1 where status not in("O","X"))) )';
     $res_tpro=msql_query($sql_tpro,$link_data);
     if(msql_num_rows($res_tpro)!=0){$tpro_ok=1;}
     
}


// echo '<div id="filtros" noprint style="background-color:'.$_SESSION['empr_color2'].';">';
if(empty($prnt))
{
echo '<div id="filtros" noprint style="background-color:;">';

// OCULTOS
echo '<div hide>';     
echo '<input id="rbco" hide value="'.$rbco.'">';
echo '<input id="blog_info" hide value="'.$blog_info.'">';
// echo '<input id="limit" hide value="'.$limit.'">';
// echo '<input id="fechaa" hide value="'.$fechaa.'">';
echo '</div>';     
     
// if(!empty($modu) and @!mb_stristr('cxco.cxpa.',$modu))
if(!empty($modu) and @!mb_stristr('cxco.cxpa.sri1.',$modu))
{
     $ztabla='stat';
     $zwhere='(stat_codigo in(select distinct status from '.$modu.'1))';     
     include('ele_datalist.php');
}
     
     
if(@mb_stristr('acce',$modu)) 
{
$ztabla='modu';
include('ele_datalist.php');
$ztabla='docd';
if(!empty($modulo)) 
{$zwhere='(docd_tabla like "'.$modulo.'%")';}
include('ele_datalist.php');
$ztabla='user';
include('ele_datalist.php');
}

if(@mb_stristr('plan',$modu)) 
{
$zid='dlasub0';     
$ztabla='asub';
$zwhere='(asub_codigo like "%0000")';
include('ele_datalist.php');
}

     
if(@mb_stristr('guia',$modu)) 
{
// $ztabla='ptov';
// include('ele_datalist.php');
     
$ztabla='codt';
// $zwhere='(vndd_codigo in(select distinct vndd from '.$modu.'1))';     
include('ele_datalist.php');
}
     
if(@mb_stristr('vtas.clie',$modu)) 
{
$ztabla='ptov';
include('ele_datalist.php');
     
$ztabla='vndd';
$zwhere='(vndd_codigo in(select distinct vndd from '.$modu.'1))';     
include('ele_datalist.php');
}
     
if(@mb_stristr('vtas.clie.guia',$modu)) 
{
$ztabla='vhcl';
include('ele_datalist.php');
}
     
if(@mb_stristr('vtas.clie.hcli',$modu) and ($empr0['empr_clinica']==1 or $empr0['empr_veterinaria']==1) )
{
$zid='dlpcnt';
$ztabla='enti';
// $zwhere='(enti_codigo in(select distinct pcnt from vtas1))';     
$zwhere='(enti_codigo in(select distinct pcnt from vtas1 union select distinct enti from hcli1))';     
include('ele_datalist.php');
}
     
if(@mb_stristr('susa.numi',$modu)) 
{
$ztabla='empl';
include('ele_datalist.php');
}
     
if(@mb_stristr('cont.comp',$modu)) 
{
$ztabla='ctas';
include('ele_datalist.php');
     
}


if($modu=='comp' or $modu=='inve')
{
     $sql_impo='select * from comp1 where docu="FP15" and ifnull(status,"") not in ("O","X") limit 1';
     $res_impo=msql_query($sql_impo,$link_data);
     if(msql_num_rows($res_impo)!=0){$impo_ok=1;}
}
     
     
     
// if($empr0['empr_impor']==1) 
if($impo_ok)     
{
     $zid='dlimpo';     
     $zdocu='FP15';     
     $zcolu='impor';   
     // $zwhere='(fecha>="2000-01-01")';     
     include('ele_datalist.php');
     
}
     
if(@mb_stristr('comp.prov',$modu)) 
{
     $ztabla='cair';
     $zwhere='(left(cair_codigo,3) in(select distinct left(cair,3) from comp2) and cair_codigo*1>0)';
     include('ele_datalist.php');
     
     $ztabla='fpag';
     include('ele_datalist.php');
     
     $ztabla='suco';
     include('ele_datalist.php');
}
     
if(@mb_stristr('caja',$modu)) 
{
$ztabla='caja';
include('ele_datalist.php');
}
     
if(@mb_stristr('bcos',$modu)) 
{
$ztabla='bcos';
include('ele_datalist.php');
}
     
$ztabla='enti';
if(@mb_stristr('vtas.clie',$modu)) 
{$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from vtas1) or left(enti_codigo,10) in(select distinct left(enti,10) from clie1))';}
// {$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from vtas1 union select distinct left(enti,10) from clie1))';}
if(@mb_stristr('comp.prov',$modu)) 
{$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from comp1) or left(enti_codigo,10) in(select distinct left(enti,10) from prov1))';}
if(@mb_stristr('plan',$modu)) 
{$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from plan1))';}
if(@mb_stristr('atvd',$modu)) 
{$zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from atvd1))';}
include('ele_datalist.php');
     
$ztabla='item';
if(@mb_stristr('inve',$modu)) 
{$zwhere='(item_codigo in(select distinct item from inve2))';}
     
if(@mb_stristr('vtas.clie',$modu)) 
{$zwhere='(item_codigo in(select distinct item from vtas2) or item_codigo in(select distinct item from clie2))';}
     
if(@mb_stristr('comp.prov',$modu)) 
{$zwhere='(item_codigo in(select distinct item from comp2) or item_codigo in(select distinct item from inve2))';}
     
include('ele_datalist.php');
     
if($modu=='guia') 
{
     $ztabla='cntn';
     include('ele_datalist.php');
}     
     
     
if($modu=='inve') 
{
     $ztabla='lote';
     include('ele_datalist.php');
     $ztabla='mrca';
     include('ele_datalist.php');
}
     
if(@mb_stristr('vtas.clie.cxco',$modu)) 
{
     $ztabla='zsub';
     include('ele_datalist.php');

     $ztabla='vndd';
     $zwhere='(vndd_codigo in(select distinct vndd from vtas1))';     
     include('ele_datalist.php');
}
     
if(@mb_stristr('vtas.clie.inve',$modu)) 
{
     $ztabla='lsub';
     include('ele_datalist.php');
//      $zmaintag='datalist';     
//      include('ele_select.php');
}
     
     
if(@mb_stristr('comp.prov.tpro',$modu)) 
{
     $ztabla='tpro';
     include('ele_datalist.php');
}
     
// $thisfile=basename(__FILE__,'.php');     

$zobj=2;     
include('ele_break.php');
     
     
$zid='modu';
$ztabla='modu';
$zlabel='Módulo';
$zvalue=$modu; 
$zsize=1.2;     
if(!empty($modu)){$zreado=1;}
if($blog_info==1){$zreado=0;}
// if($user_codigo==2){$zreado=0;}     
$zondblclick='{document.getElementById("modu").removeAttribute("disabled");}';     
// $zonchange='{location.href="?scri='.basename(__FILE__,'.php').'&modu="+document.getElementById("modu").value;}';
$zonchange='{location.href="?scri='.basename(__FILE__,'.php').'&modu="+document.getElementById("modu").value+"'.'&blog_info="+document.getElementById("blog_info").value'.';}';
$zonblur  =$zonchange;
include('ele_select.php');

     
if($rbco==1)
{
     $zobj=1;
     $zid='rbco2';
//      $ztabla='modu';
     $zlabel='';
     $zvalue='BANCOS'; 
     $zsize=1.2;     
     $zreado=1;
//      // if($user_codigo==2){$zreado=0;}     
//      $zondblclick='{document.getElementById("modu").removeAttribute("disabled");}';     
//      $zonchange='{location.href="?scri='.basename(__FILE__,'.php').'&modu="+document.getElementById("modu").value;}';
//      $zonblur  =$zonchange;
     include('ele_input.php');
}
     
     
// echo '*** '.$info;     
$zid='info';
$zlabel='Informe';
$zvalue=$info;
$zsize=1.2;     
$zexact=1;     
     
if($modu=='acce')
{
     $zoptions='';
     $zoptions.='acdeta,Detalle;';     
//      $zoptions.='vtres1,Resumen 1;';     
}

     
if($modu=='vtas')
{
     $zoptions='';
     
     $zoptions.='ogroup,Generales;';     
     $zoptions.='vtresu,Resumen;';     
     $zoptions.='vtdeta,Detalle;';   
     $zoptions.='vtres1,Resumen 1;';     

     
     $zoptions.='ogroup,Consolidados;';     
     $zoptions.='vtenti,Cliente;';  
     $zoptions.='vtitem,Item;';     
     $zoptions.='vtlsub,Linea;';     
     $zoptions.='vtptov,Pto.Venta;';     
     $zoptions.='vtvndd,Vendedor;';     
     $zoptions.='vtcomi,Comisiones;';     

     $zoptions.='ogroup,Fechas;';     
     $zoptions.='vtxfec,Fecha;';     
     $zoptions.='vtxsem,Semanal;';     
     $zoptions.='vtxmes,Mensual;';     
     $zoptions.='vtxano,Anual;';     
     
     $zoptions.='ogroup,Comparativos;';     
     $zoptions.='vtenxm,Cliente /Mes;';     
     $zoptions.='vtitxm,Item /Mes;';     
     $zoptions.='vtlsxm,Linea /Mes;'; 
     $zoptions.='vtanxm,Anual /Mes;';     
     $zoptions.='vtvnxm,Vendedor /Mes;';     
     
     $zoptions.='vtride,RIDEs;';     
     
     $zoptions.='ogroup,Especial;';     
     if($empr0['empr_farmacia']==1)
     {$zoptions.='vtrpm1,Rep.Prec.Med.;'; }
     if($empr0['empr_garage']==1)
     {
          $zoptions.='vtgrge0,Invent.Vhcl.;'; 
          $zoptions.='vtgrge2,Invent.X Hora.;'; 
     }

}

if($modu=='clie')
{
     $zoptions='';
     $zoptions.='clresu,Resumen;';     
     $zoptions.='clres1,Resumen 1;';     
     $zoptions.='clenti,Cliente;';     
     $zoptions.='clitem,Item;';     
     $zoptions.='clxmes,Mensual;';     
//      include('ele_select.php');
}

if($modu=='carr')
{
     $zoptions='';
     $zoptions.='caresu,Resumen;';     
     $zoptions.='caitem,Item;';     
//      include('ele_select.php');
}
         
if($modu=='comp')
{
     $zoptions='';
     $zoptions.='ogroup,Generales;';     
     $zoptions.='coresu,Resumen;';     
     $zoptions.='codeta,Detalle;';     
     $zoptions.='codein,Det.Invent;';     
     
     $zoptions.='ogroup,Fechas;';     
     $zoptions.='coxmes,Mensual;';     
     $zoptions.='coxano,Anual;';     
     
     
     $zoptions.='ogroup,Consolidados;';     
     $zoptions.='coenti,Proveedores;';     
     $zoptions.='coitem,Item;';     
     $zoptions.='cocair,CAIR;';     
     $zoptions.='coctas,Cta.Contable;';     
     
     $zoptions.='ogroup,Comparativos;';     
     $zoptions.='coitxm,Item /Mes;';     
     $zoptions.='coanxm,Anual /Mes;';     
     $zoptions.='coctxm,Cta.Cont. /Mes;';
     $zoptions.='cocaxm,CAIR /Mes;';     
     
     
}

if($modu=='prov')
{
     $zoptions='';
     $zoptions.='prresu,Resumen;';     
     $zoptions.='prdeta,Detalle;';     
     $zoptions.='prenti,Solicitud;';     
     $zoptions.='prcsub,Centro;';     
     $zoptions.='pritem,Item;';     
     $zoptions.='pritxm,Item /Mes;';     
}

if($modu=='lpro')
{
     $zoptions='';
     $zoptions.='lpresu,Resumen;';     
     $zoptions.='lpdeta,Detalle;';     
//      $zoptions.='lpenti,Solicitud;';     
     $zoptions.='lpcsub,Centro;';     
     $zoptions.='lpitem,Item;';     
//      $zoptions.='lpitxm,Item /Mes;';     
}

if($modu=='cont')
{
     $zoptions='';
     
     $zoptions.='ogroup,Generales;';     
     $zoptions.='ttdeta,Libro Diario;';     
     $zoptions.='ttmovi,Libro Mayor;';     
     $zoptions.='ttssss,Sumas & Saldos;';
     $zoptions.='ttssff,Situación Financiera;';     
     $zoptions.='ttsfcc,Situación Financiera (Comparativo);';     
     $zoptions.='ttrrii,Resultado Integral;';     
     $zoptions.='ttricc,Resultado Integral (Comparativo);';     
     $zoptions.='ttresu,Resumen;';     
     
     $zoptions.='ogroup,Consolidados;';     
     $zoptions.='ttssdd,Sumas & Saldos (Diario);';     
     $zoptions.='ttssmm,Sumas & Saldos (Mensual);';     
     $zoptions.='ttssnn,Sumas & Saldos (Nivel);';     
     $zoptions.='ttssaa,Saldos (Acumulado);';     
     $zoptions.='ttsscc,Saldos (Comparativo);';     
     
     $zoptions.='ogroup,Datos;';     
     $zoptions.='ttddbb,Data Base;';     
     
//      include('ele_select.php');
}
     
if($modu=='caja')
{
     $zoptions='';
//      $zoptions.='cjiiee,Ingresos /Egresos;';     
     $zoptions.='cjresu,Resumen;';     
     $zoptions.='cjdocu,Caja X Docum.;';     
     $zoptions.='cjdate,Caja X Fecha.;';     
     $zoptions.='cjddbb,Data Base;';     
     
//      include('ele_select.php');
}
    
if($modu=='bcos')
{
     $zoptions='';
//      $zoptions.='bciiee,Ingresos /Egresos;';     
     $zoptions.='bcresu,Resumen;';     
     $zoptions.='bcmovi,Movimientos;';     
     $zoptions.='bcdocu,Bancos X Docum.;';     
     $zoptions.='bcdate,Bancos X Fecha.;';     
     $zoptions.='bcddbb,Data Base;';     
     
//      include('ele_select.php');
}
     
if($modu=='inve')
{
     $zoptions='';
     
     
     $zoptions.='ogroup,Generales;';     
     $zoptions.='iiiiee,Ingresos /Egresos;';     
     $zoptions.='iiresu,Resumen X Doc.;';
     $zoptions.='iikrdx,Kardex;'; 
     $zoptions.='iibode,Stock X Bodega;';     
     $zoptions.='iisxlt,Stock X Lote;';     
     $zoptions.='iillcc,Lista Conteo Físico;';     

     $zoptions.='ogroup,Detalles;';     
     $zoptions.='iideta,Detalle X Doc.;';     
     $zoptions.='iiblog,Detalle Bodega;';     
     $zoptions.='iidocu,Ingresos /Egresos X Doc.;';     
     
     $zoptions.='ogroup,Consolidados;';     
     $zoptions.='iiddcc,Debi /Cred X Linea;';     
     $zoptions.='iillbb,Saldos X Linea / Bodega;';     
     $zoptions.='iidcdd,Debi /Cred (X Diar);';     
     $zoptions.='iidcmm,Debi /Cred (X Mes);';     
//      $zoptions.='iiie11,Cambios;';     
//      $zoptions.='iiie13,Transferencias;';     
//      $zoptions.='iiie14,Produccion;';     
     
     $zoptions.='ogroup,Ingresos;';     
//      $zoptions.='iievta,Egre.Ventas;';     
     $zoptions.='iiicom,Ingr.Compra;';     
     $zoptions.='iicuxc,Unit.x Compra;';
     
     $zoptions.='ogroup,Egresos;';     
     $zoptions.='iievta,E.Ventas;';     
     $zoptions.='iiecon,E.Consumo;';     
     $zoptions.='iiecxb,E.Consumo /Bodega;';     
     $zoptions.='iieclb,E.Consumo /Linea /Bodega;';     
     $zoptions.='iietxb,E.Transf. /Bodega;';     
     $zoptions.='iietbb,E.Transf. Orig/Dest;';     

     $zoptions.='ogroup,Verificar;';     
     $zoptions.='iiie11,Cambios;';     
     $zoptions.='iiie13,Transferencias;';     
     $zoptions.='iiie14,Produccion;';     
     
     $zoptions.='iiddbb,Data Base;';     

     
     $zoptions.='ogroup,Especiales;';     
     $zoptions.='iiiecf,Ingr /Egre X Clie /Fecha;';     
//      $zoptions.='iillbb,Saldos X Lin/Bodega;';     
     
     
     
     
     
     
}
    
if($modu=='plan')
{
     $zoptions='';
     $zoptions.='plresu,Resumen;';     
     $zoptions.='plblog,Detalle;';     
//      $zoptions.='atxsem,Semanal;';     
     $zoptions.='plddbb,Data Base;';     
     
//      include('ele_select.php');
}
    
if($modu=='atvd')
{
     $zoptions='';
     $zoptions.='atresu,Resumen;';     
     $zoptions.='atblog,Detalle;';     
     $zoptions.='atxsem,Semanal;';     
     $zoptions.='atddbb,Data Base;';     
     
//      include('ele_select.php');
}
    
if($modu=='cxco')
{
     $zoptions='';
     $zoptions.='ccresu,Resumen x Doc.;'; 
     $zoptions.='ccsald,Saldos;'; 
     $zoptions.='ccddcc,Débitos /Créditos;'; 
     $zoptions.='ccdcdd,Débitos /Créditos (Diarios);'; 
     $zoptions.='ccdcmm,Débitos /Créditos (Mensual);'; 
     $zoptions.='ccmovi,Movimientos X Clie;'; //kardex 
     $zoptions.='ccanti,Anticipos;';  
//      $zoptions.='ccdeta,Detalle Ctas.X Cobrar;'; 
     $zoptions.='ccddbb,Data Base;';     
     
//      include('ele_select.php');
}
     
if($modu=='cxpa')
{
     $zoptions='';
     $zoptions.='cpresu,Resumen X Doc.;'; 
     $zoptions.='cpsald,Saldos;'; 
     $zoptions.='cpddcc,Débitos /Créditos;'; 
     $zoptions.='cpdcdd,Débitos /Créditos (Diarios);'; 
     $zoptions.='cpdcmm,Débitos /Créditos (Mensual);'; 
     $zoptions.='cpmovi,Movimientos X Prov.;'; //kardex 
     $zoptions.='cpanti,Anticipos;'; 
//      $zoptions.='cpdeta,Detalle Ctas.X Pagar;'; 
     $zoptions.='cpddbb,Data Base;';     
     
//      include('ele_select.php');
}

if($modu=='retp')
{
     $zoptions='';
     $zoptions.='rpresu,Resumen;';     
     $zoptions.='rpddbb,Data Base;';     
     
//      include('ele_select.php');
}
     
if($modu=='retc')
{
     $zoptions='';
     $zoptions.='rcresu,Resumen;';     
     $zoptions.='rcdeta,Detalle;';     
     $zoptions.='rcride,RIDEs;';     
//      $zoptions.='rcsrid,Devol.SRI;';     
     $zoptions.='rcddbb,Data Base;';     
     
//      include('ele_select.php');
}
     
if($modu=='susa')
{
     $zoptions='';
     $zoptions.='suresu,Resumen;';     
     $zoptions.='sudeta,Detalle;';     
//      $zoptions.='rcsrid,Devol.SRI;';     
     $zoptions.='rcddbb,Data Base;';     
     
//      include('ele_select.php');
}
     
if($modu=='nomi')
{
     $zoptions='';
     $zoptions.='noresu,Resumen;';     
     $zoptions.='nodeta,Detalle;';     
//      $zoptions.='rcsrid,Devol.SRI;';     
     $zoptions.='rcddbb,Data Base;';     
     
//      include('ele_select.php');
}
     
if($modu=='guia')
{
     $zoptions='';
     $zoptions.='guresu,Resumen;';     
//      $zoptions.='rcddbb,Data Base;';     
}
     
if($modu=='opro')
{
     $zoptions='';
     $zoptions.='opresu,Resumen;';     
     $zoptions.='opdeta,Detalle;';     
     $zoptions.='opitem,Item;';     
     $zoptions.='opdein,Det.Invent;';     
//      $zoptions.='rcddbb,Data Base;';     
}
     
if($modu=='hcli')
{
     $zoptions='';
     $zoptions.='hcresu,Resumen;';     
     $zoptions.='hcdeta,Detalle;';     
     $zoptions.='hcitem,Item;';     
//      $zoptions.='rcddbb,Data Base;';     
}
     
if($modu=='btcr')
{
     $zoptions='';
     $zoptions.='btresu,Resumen;';     
}
     
if($modu=='sri1')
{
     $zoptions='';
     $zoptions.='sriats,Anexo Transaccional;';     
//      $zoptions.='rcddbb,Data Base;';     
}
     
include('ele_select.php');
// include('ele_reset.php');

     
// PROCESO     
// $zalign='right';     
$zid='prcs';
$zlabel='Proceso';
// $zvalue=$prcs;
$zsize=1.2;     
if($modu=='vtas')
{
$zoptions='';
$zoptions.='contab,Contabilizar;';     
$zoptions.='fcie10,Cobros Efectivo;';        
$zoptions.='fcpp10,Comisiones;';        
}
     
if($modu=='comp')
{
$zoptions='';
$zoptions.='contab,Contabiliza;';     
}
     
if($modu=='inve')
{
$zoptions='';
$zoptions.='contab,Contabilizar;';     
$zoptions.='recalc,Recálculo;';        
}
     
if($modu=='nomi')
{
$zoptions='';
$zoptions.='contab,Contabilizar;';     
$zoptions.='recalc,Recálculo;';        
}
     
if($modu=='prov')
{
$zoptions='';
if(substr($docu,0,2)=='PS')     
{$zoptions.='genpp10,Genera Pedido PP10;';}
// $zoptions.='recalc,Recálculo;';        
}
     
// if($info=='coresu' or $info=='rcresu'){$zhide=1;}
include('ele_select.php');

     
     
     

if($user_edit==1 and mb_stristr('resu.deta.dein.cuxc',substr($info,2,4)))
{
     $zid='edit';
     $zlabel='Editar';
     $zvalue=0;
     $zexact=1;
     $zoptions='0;1;5;15;30;';
     $zonchange='{fn_consulta(event);}';
     if(mb_stristr('retc',$modu))
     {$zhide=1;}
     include('ele_select.php');
}
     
     
     
     
     
//orden     
if(!empty($modu))     
{
     $zid='orden';
     $zvalue=$orden;
     $zlabel='Ordenar X';
     $zoptions='';
     $zoptions.='Nombre;';
     $zoptions.='Código;';
//      $zoptions.='Fecha;';
     if($modu=='cont'){$zhide=1;}
     if($modu=='inve')     
     {
          $zoptions.='Linea;';
     }     
     if($modu=='vtas' or $modu=='clie')     
     {
          $zoptions.='Zona;';
          $zoptions.='Linea;';
     }
     if($modu=='comp')     
     {
          $zoptions.='T.Prov.;';
          $zoptions.='CAIR;';
     }
     $zonchange='{fn_consulta(event);}';
     $zalign='right';
//      $zhide=1;
     include('ele_select.php');

     $zid='pgsize';
     $zlabel='Pág';
     $zvalue=$pgsize;
     $zdefa=$pgsize;
     $zoptions='';
     $zoptions.='A4-V;';
     $zoptions.='A4-H;';
     $zalign='right';
     $zsize=0.9;
     include('ele_select.php');
     
     
}     
     
$zsize=3;
include('ele_break.php');

     
$domd_f = new DOMDocument();
     $domd_f->encoding = 'utf-8';
     $domd_f->xmlVersion = '1.0';
     $domd_f->formatOutput = true;
$elem_f=$domd_f->appendChild($domd_f->createElement('span'));

     
// $xstyle0="float:".$zalign.";margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:0.1em;";
$xstyle0="float:left".";margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:0.1em;";
$elem_f->setAttribute("style",$xstyle0);     
     
$domd_f='';     
$elem_f='';     

$zdom=$domd_f;     
$zele=$elem_f;
$zid='fecha1';
$ztype='date';
// $zlabel='Fec.Ini.';
$zlabel='Desde';
$zvalue=$fecha1;
$zdefa=$fecha0;    
$zmin=$fecha0;
$zmax=date('Y-m-01',strtotime('+1 month'));     
//$ztype='month';     
include('ele_input.php');  

     
// $zdom=$domd_f;     
// $zele=$elem_f;
// $zobj=1;     
// include('ele_break.php');  
     

$zdom=$domd_f;     
$zele=$elem_f;
$zid='fecha2';
$ztype='date';
// $zlabel='Fec.Fin';
$zlabel='Hasta';
$zvalue=$fecha2;
$zmin=$fecha0;     
$zmax=date('Y-m-t',strtotime('+12 month'));     
//$ztype='month';     
include('ele_input.php');  

if($domd_f!='')     
echo $domd_f->saveHTML();     
     
     
     

if(!empty($modu) and @mb_stristr('vtas.comp.guia.retp.retc',$modu))
{
$zid='fautor';
$ztype='checkbox';
$zlabel='F.Aut.';
$zvalue=$fautor;
// $zalign='right';
$zhide=1;     
include('ele_input.php');  
}     
     

// if(@!mb_stristr('cxco.cxpa',$modu))
if(!empty($modu) and @!mb_stristr('cxco.cxpa.rete.retc.retp',$modu))
if(!empty($modu) and @!mb_stristr('cxco.cxpa.sri1.',$modu))
{
     $zid='docu';
     $zlabel='Docum.';
     $zvalue=$docu;     
     $ztabla='docu';
     $ztodo=1;
     {$zwhere='(docu_codigo in (select distinct docu from '.$modu.'1 where status not in ("X")))';}
     include('ele_select.php');  
     
}     
     
     
     
if(@mb_stristr('acce',$modu))
{
     $zobj=1;
     include('ele_break.php');  
     
     $zid='modulo';
     $zlabel='Módulo';
     $zvalue=$modulo;     
     $ztabla='modu';
     $ztodo=1;
//      $zonchange='{fn_consulta(event);}';
//      include('ele_select.php');  
     include('ele_input.php');  

     $zid='docd';
     $zlabel='Docum.';
     $zvalue=$docd;     
     $ztabla='docd';
     $ztodo=1;
//      include('ele_select.php');  
     include('ele_input.php');  
     
     $zid='usuario';
     $zlabel='usuario';
     $zvalue=$usuario;     
     $ztabla='user';
     include('ele_input.php');  
     
}     
     
     
     
if(@mb_stristr('guia',$modu))
{
     $zid='ptoe';
     $zlabel='Pto.Emi.';
     $zvalue=$ptoe;     
     $ztabla='ptoe';
     $ztodo=1;
//      $zwhere='(ptov_codigo in(select distinct ptov from '.$modu.'1 where ifnull(status,"") not in("O","X")))';
//      $zwhere='('.$zid.'_codigo in(select distinct '.$zid.' from '.$modu.'1 where ifnull(status,"") not in("O","X")))';
     include('ele_select.php');  
     
}     

if(@mb_stristr('vtas.clie',$modu))
{
     $zid='ptov';
     $zlabel='Pto.Vta.';
     $zvalue=$ptov;     
     $ztabla='ptov';
     $ztodo=1;
     $zwhere='('.$zid.'_codigo in(select distinct '.$zid.' from '.$modu.'1 where ifnull(status,"") not in("O","X")))';
     include('ele_select.php');  
     
     
     $sql_plazo='select distinct ifnull(plazo,0) as plazo from '.$modu.'1 where ifnull(status,"") not in("O","X")';
     $res_plazo=msql_query($sql_plazo, $link_data);
     if(msql_num_rows($res_plazo)>1)
     {
          $zid='tpago';
          $zlabel='T.Pago';
          $zvalue=$tpago;  
          $zoptions='1,Contado;2,Crédito';
          $ztodo=1;
          include('ele_select.php');  
     }
     
}     

     
// $zobj=1;     
// include('ele_break.php');
     
     
if(@mb_stristr('inve.cxco.cxpa',$modu))
{
     $zid='tsaldo';
     $zlabel='Saldo';
     $zvalue=$tsaldo;
     $zheptav=1;
     $zalign='right';
//      if($modu=='inve'){$zlabel='Stock'}
     include('ele_select.php');  
     
     $zid='cero';
     $zlabel='Cero';
     $zvalue=$cero;
     $zclass='numeric-dec';
     $zmax=.99;
     $zmin=0;
     $zstep=0.01;
     $zhide=1;
//      $zwidth=20;
     $zalign='right';
     include('ele_input.php');
}

     
if($empr0['empr_inve']==1 and @mb_stristr('vtas',$modu))
{
     $zid='cost';
     $ztype='checkbox';
     $zlabel='Costo$';
     $zvalue=$cost;
     $zalign='right';
     include('ele_input.php');  
     
}

     
     
if($empr0['empr_inve']==1 and @mb_stristr('vtas',$modu))
{
     $zid='inve';
     $ztype='checkbox';
     $zlabel='Invent.';
     $zvalue=$inve;
     $zalign='right';
     include('ele_input.php');  
}
     
     
     
     
if(@mb_stristr('inve',$modu))
{
     
     $zid='pvar';
     $ztype='checkbox';
     $zlabel='%Var';
     $zvalue=$pvar;
     $zalign='right';
     include('ele_input.php');  
     
     
     
     $zid='prec';
     $zlabel='Precio$';
     $zvalue=$prec;
     $zalign='right';
     $zoptions='nn,N/A;puni,Unit.;pvp,P.V.P.';
     $zhide=1;
     include('ele_select.php');  
     
     $zid='cost';
     $ztype='checkbox';
     $zlabel='Costo$';
     $zvalue=$cost;
     $zalign='right';
     include('ele_input.php');  

     
     $zid='stock';
     $ztype='checkbox';
     $zlabel='Stock';
     $zvalue=$stock;
     $zalign='right';
     include('ele_input.php');  
     
     
     
     if($imgi_ok==1)
     {
          $zid='imgi';
          $ztype='checkbox';
          $zlabel='Imagen';
          $zvalue=$imgi;
          $zalign='right';
          include('ele_input.php');  
     }
     
}     

if(@mb_stristr('cxco.cxpa',$modu))
{
     $zid='anti';
     $ztype='checkbox';
     $zlabel='Antiguedad';
     $zvalue=$anti;
     $zalign='right';
     include('ele_input.php');  
}     
     

if(@mb_stristr('cont',$modu))
{
     if(empty($dtr1)){$dtr1=1;}
     $zid='dtr1';
     $zlabel='DTR';
     $zvalue=$dtr1;
     $zbool=1;
     $zexact=1;
     include('ele_select.php');  
     
}     

     
     
     
if(!empty($modu) and @!mb_stristr('cxco.cxpa.sri1.',$modu))
{
     $zid='stat';
     $zlabel='Status';
     $ztodo=1;
     $zalign='right';
     $zvalue=$stat;     
     $ztabla='stat';
     {$zwhere='(stat_codigo in (select distinct status from '.$modu.'1 where status not in ("X")))';}
     include('ele_select.php');  
}     

     
if(mb_stristr('vtas.retp.guia.comp',$modu))
{
     $zid='stce';
     $zlabel='Aut.SRI';
     $zvalue=$stce;
     $zbool=1;
     $ztodo=1;
     $zalign='right';
     $zsize=0.9;
     include('ele_select.php');  
}
     
     
$zobj=1;     
include('ele_break.php');

if(@mb_stristr('caja',$modu))
{
     $zid='caja';
     $zlabel='Caja';
     $ztodo=1;
     $zvalue=$caja;
     $ztabla='caja';
     $zwhere='('.$zid.'_codigo in(select distinct '.$zid.' from '.$modu.'1 where ifnull(status,"") not in("O","X")))';
     include('ele_select.php');
}     

if(@mb_stristr('bcos',$modu))
{
     $zid='ctab';
     $zlabel='Cta.Banc.';
     $ztodo=1;
     $zvalue=$ctab;
     $ztabla='ctab';
     $zwhere='('.$zid.'_codigo in(select distinct '.$zid.' from '.$modu.'1 where ifnull(status,"") not in("O","X")))';
     include('ele_select.php');
}     

     
     
     
if(@mb_stristr('guia',$modu))
{
     $zid='vhcl';
     $zlabel='Placa';
     $ztodo=1;
     $zvalue=$vhcl;
     $ztabla='vhcl';
//      $zwhere='(bode_codigo in(select bode from inve1 where ifnull(status,"")not in("O","X")))';
//      $zwhere='('.$zid.'_codigo in(select distinct '.$zid.' from '.$modu.'1 where ifnull(status,"") not in("O","X")))';
     include('ele_input.php');
     
     $zid='codt';
     $zlabel='Conductor';
     $ztodo=1;
     $zvalue=$codt;
     $ztabla='codt';
//      $zwhere='(bode_codigo in(select bode from inve1 where ifnull(status,"")not in("O","X")))';
//      $zwhere='('.$zid.'_codigo in(select distinct '.$zid.' from '.$modu.'1 where ifnull(status,"") not in("O","X")))';
     include('ele_input.php');

     
     if($cntn_ok==1)
     {
          $zid='cntn';
          $zlabel='Contenedor';
          $zvalue=$cntn;
          $ztabla='cntn';
          include('ele_input.php');
     }
     
     
     
}     

     
     
     
if(@mb_stristr('inve',$modu))
{
     if($tbod_ok==1)
     {
          $zid='tbod';
          $zlabel='T.Bod.';
          $zvalue=$tbod;
          $ztodo=1;
          $zoptions='D,DISPO;N,NO-DIS';
          $ztabla='bode';
          include('ele_select.php');
     }

     $zid='bode';
     $zlabel='Bodega';
     $ztodo=1;
     $zvalue=$bode;
     $ztabla='bode';
//      $zwhere='(bode_codigo in(select bode from inve1 where ifnull(status,"")not in("O","X")))';
     $zwhere='('.$zid.'_codigo in(select distinct '.$zid.' from '.$modu.'1 where ifnull(status,"") not in("O","X")))';
     include('ele_select.php');
}     

// if($modu=='cxco' or $modu=='vtas' or $modu=='clie')
if(@mb_stristr('vtas.clie.cxco.retc.plan.atvd.',$modu))     
{
     if($zsub_ok==1)
     {
          $zid='zsub';
          $zlabel='Zona';
          $zvalue=$zsub;
          $ztabla='zsub';
          $ztodo=1;
          $zwhere='(zsub_codigo in(select enti_zsub from enti0 where left(enti_codigo,10) in (select left(enti,10) from vtas1 where status not in("O","X"))) )';
          include('ele_select.php');
     }

     $zid='enti';
     $zlabel='Cliente';
     $zvalue=$enti;
     if($modu=='atvd'){$zlabel='Empleado';}
     $ztabla='enti';
     $zopen=1;
     include('ele_input.php');
     
     
     
     
     

     
     if($modu=='plan')
     {
          
          $zid='asub';
          $zlabel='Servicio';
          $zvalue=$asub;
          $ztabla='asub';
//           $zopen=0;
          $zlist='dlasub0';
          include('ele_input.php');
          
          $zid='empr1';
          $zlabel='Empresa';
          $zvalue=$empr1;     
          $ztabla='';
          $zdocu='PLA1';
          $zcolu='empr1';
          $zcolu2='empr1';
          $ztodo=1;
          include('ele_select.php');  
          
     }


     if(!empty($vndd_ok))
     {
          $zid='vndd';
          $zlabel='Vendedor';
          $zvalue=$vndd;     
          $ztabla='vndd';
          $ztodo=1;
          $zwhere='('.$zid.'_codigo in(select distinct '.$zid.' from vtas1 where ifnull(status,"") not in("O","X")))';

          if($empr0['empr_ceuser']==1 and !mb_stristr('sist.supe',$user0['user_tipo'])  )
          {
               $zreado=1;
               $zvalue=$user0['user_cedula'];
          }
          
          if($vndd_ok==1)
          {include('ele_select.php');}
          if($vndd_ok==2)
          {include('ele_input.php');}
     }


     if($empr0['empr_garage']==1 or $empr0['empr_automotriz']==1 )          
     {
          $zid='vhcl';
          $zlabel='Vehículo';
          $zvalue=$vhcl;
          $ztabla='vhcl';
          include('ele_input.php');
     }
     
     
     if($empr0['empr_garage']==1)          
     {
          $zid='stfin';
          $zlabel='Garage';
          $zvalue=$stfin;
          $ztriv=1;
          $ztodo=1;
          include('ele_select.php');
          
     }
     
//      if(mb_stristr('anml',$cfg_empr))
     if($empr0['empr_clinica']==1 or $empr0['empr_veterinaria']==1) 
     {
          $zid='pcnt';
          $zlabel='Paciente';
          if($empr0['empr_veterinaria']==1)
          {$zlabel='Mascota';}
          $zvalue=$pcnt;
          $zlist='dlpcnt';
          $ztabla='pcnt';
          $zwhere='(pcnt_codigo in(select distinct pcnt from vtas1 where status not in("X")))';
          include('ele_input.php');
     }
     
     
     if($empr0['empr_ptovta']==1)          
     {
          
          $zid='cobro';
          $zlabel='Cobro';
          $zvalue=$cobro;
          $zoptions='';
          $zoptions.='_efe_,Efectivo;';     
          $zoptions.='_tar_,Tarjeta;';     
          $zoptions.='_cre_,Crédito;';   
          $ztodo=1;
          include('ele_select.php');
     }
     
     
     
}


     
     

if(@mb_stristr('comp.prov.cxpa.retp.caja.bcos',$modu))     
{
     if(@mb_stristr('comp.prov.cxpa',$modu))     
     {
          if($tpro_ok==1)
          {
               $zid='tpro';
               $zlabel='T.Provee.';
               $zvalue=$tpro;
               $ztabla='tpro';
               $ztodo=1;
               $zwhere='(tpro_codigo in(select enti_tpro from enti0 where left(enti_codigo,10) in (select left(enti,10) from comp1 where status not in("O","X"))) )';
     //           if(empty($tpro_ok)){$zhide=1;}
               $zsize=0.9;
               include('ele_select.php');
          }
     }
     
     $zid='enti';
     $zlabel='Proveedor';
     if(@mb_stristr('caja.bcos',$modu)){$zlabel='Entidad';}
     $zvalue=$enti;
     $ztabla='enti';
     $zopen=1;
     include('ele_input.php');
     
     
}

     
if($empr0['empr_codigo']=='demo')     
if(@mb_stristr('comp.retc',$modu))
{
     $zid='toenti';
     $zlabel='Adquiriente';
     if(@mb_stristr('retc',$modu)){$zlabel='Sujeto Retenido';}
     $zvalue=$toenti;
     $ztabla='enti';
//      $zopen=1;
     include('ele_input.php');
     
}
     
     
if(@mb_stristr('vtas.clie.inve.comp',$modu))
{
// $zobj=1;     
// include('ele_break.php');
     
     

$domd_f = new DOMDocument();
     $domd_f->encoding = 'utf-8';
     $domd_f->xmlVersion = '1.0';
     $domd_f->formatOutput = true;
$elem_f=$domd_f->appendChild($domd_f->createElement('span'));
     
// $xstyle0="float:".$zalign.";margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:0.1em;";
$xstyle0="float:left".";margin-left:".$zsize*(0.5)."em;margin-right:".$zsize*(0.5)."em;margin-bottom:0.1em;";
$elem_f->setAttribute("style",$xstyle0);     
$domd_f='';
$elem_f='';     
     
     if($lsub_ok==1)
     {
          $zdom=$domd_f;     
          $zele=$elem_f;
          $zid='lsub';
          $zlabel='Linea';
          $zvalue=$lsub;
          $ztabla='lsub';
          $ztodo=1;
          $zsize=0.9;
          include('ele_select.php');
          
//           $zdom=$domd_f;     
//           $zele=$elem_f;
//           $zobj=1;
//           include('ele_break.php');
     }
     
     
     $zdom=$domd_f;     
     $zele=$elem_f;
     $zid='item';
     $zlabel='Item';
     $zvalue=$item;
     $ztabla='item';
     $zopen=1;
     include('ele_input.php');
     
if($domd_f!='')
echo $domd_f->saveHTML();     
}

     
     
     
     
     
if(@mb_stristr('opro',$modu))
{
     $zid='csub1';
     $zlabel='Centro-Sub';
     $zvalue=$csub1;
     $ztabla='csub';
     $ztodo=1;
     include('ele_select.php');
}

if(@mb_stristr('hcli',$modu))
{
          $zid='dato';
          $zlabel='Dato';
          $zvalue=$dato;
          $zdocu='HC10';
          $zcolu='dato';
          $zcolu2='dato';
          $ztodo=1;     
          include('ele_select.php');
     
     
          $zid='pcnt';
          $zlabel='Paciente';
          $zvalue=$pcnt;
          $zlist='dlpcnt';
          $ztabla='pcnt';
//           $zwhere='(pcnt_codigo in(select distinct pcnt from vtas1 where status not in("X")))';
          include('ele_input.php');
     

          
     
}
     
if(@mb_stristr('cont',$modu))
{
     $zid='nivel';
     $zlabel='Nivel';
     $zvalue=$nivel;
     $zdefa=5;
     $zexact=1;
//      $zoptions='1;2;3;4;5';
     $zoptions='3;4;5';
     include('ele_select.php');
     
     $zid='ctas';
     $zlabel='Cuenta';
     $zvalue=$ctas;
     $ztabla='ctas';
     $ztodo=1;
     include('ele_input.php');

     $zid='csub';
     $zlabel='Centro-Sub';
     $zvalue=$csub;
     $ztabla='csub';
     $ztodo=1;
     include('ele_select.php');
     
}

     
if(@mb_stristr('comp',$modu))     
{
     $zobj=1;     
     include('ele_break.php');

     
     $zid='ctas';
     $zlabel='Cuenta';
     $zvalue=$ctas;
     $ztabla='ctas';
     $ztodo=1;
     include('ele_input.php');
     
}
     
if(@mb_stristr('retp.retc',$modu))     
{
     $zid='cair';
     $zlabel='CAIR';
     $zvalue=$cair;
     $ztabla='cair';
     $ztodo=1;
     $zsize=0.8;
     include('ele_input.php');
//      include('ele_select.php');

}
     
     

     
     
if(@mb_stristr('vtas.clie.inve',$modu))
{     
     if($empr0['empr_farmacia']==1)
     {
          $zid='dl_pcom';     
          $ztabla='pcom';
          include('ele_datalist.php');

          $zid='pcom';
          $zlabel='Pres.Com.';
          $zvalue=$pcom;
          $ztabla='pcom';
          $zopen=1;
          include('ele_input.php');
     }
     
     if($lote_ok==1)
     {
          $zid='lote';
          $zlabel='Lote';
          $zvalue=$lote;
          $ztabla='lote';
          include('ele_input.php');
     }
     
     if($mrca_ok==1)
     {
          $zid='mrca';
          $zlabel='Marca';
          $zvalue=$mrca;
          $ztabla='mrca';
          $ztodo=1;
          include('ele_select.php');
     }
     
}

     
if(@mb_stristr('susa.nomi',$modu))     
{
     $zid='csub1';
     $zlabel='Centro-Sub';
     $zvalue=$csub1;
     $ztabla='csub';
     $ztodo=1;
     include('ele_select.php');
     
     $zid='enti';
     $zlabel='Empleado';
     $zvalue=$enti;
     $ztabla='enti';
     $zlist='dl_empl';
     $ztodo=1;
//      $zsize=0.8;
     include('ele_input.php');
//      include('ele_select.php');

}
     
     
     
     
     
if(!empty($modu))
{
$zid='concep';
$zlabel='Concepto';
$zvalue=$concep;
include('ele_input.php');
}    

     
// echo '===='.$modu.$impo_ok;     
     
// if(($modu=='comp' or $modu=='inve') and $impo_ok==1)
if($modu=='comp' and $impo_ok==1)
{
     $zid='impor';
     $zlabel='#Impor.';
     $zvalue=$impor;
//      $zlist='dlimpo';
//      include('ele_input.php');
     $zdocu='FP15';
     $zcolu='impor';
     $zcolu2='impor';
     $ztodo=1;     
     include('ele_select.php');
}
     
     
     
// $zobj=1;     
// include('ele_break.php');
     
$zid='btn_consul'; 
$zlabel='Consultar';
$zalign='right';
$zonclick='{fn_consulta(event);}';

include('ele_button.php');
     
echo '<span style="float:right; white-space:nowrap;">';     
echo $msgres;
echo '</span>';     

     
// if(1==2)     
if($info=='coresu' or $info=='rcresu')
{
//      📁📂🗄🗃
     $zid='celfile';
     $zlabel='Archivos';
     $ztype='file';
     $zmulti=1;
     $zaccept='.xml,.txt,.pdf';
     $zlabel2='';
     $zsize=0.8;
     $zalign='right';
     $zonclick2="upld_cele('celfile')";
     include('ele_input.php');
     
     $zid='claveacc';
     $zlabel='Claves';
     $zlabel2='';
     $zsize=0.8;
     $zalign='right';
     $zvalue=$claveacc;
//      $value='ffgd';
//      $zonclick2="upld_cele('celfile')";
     $zonblur="upld_cele('claveacc')";
     include('ele_input.php');
     
     
}
     
     
     
     
     
include('ele_break.php');

// TITULO     
{
// $ztitulo=$xtitulo;     
// include('ele_title.php');
// include('ele_break.php');

}
     
echo '</div>';
}     

if($modu=='inve' and $cost=='true'){$pgsize=str_replace('V','H',$pgsize);}
if(mb_stristr('sriats',$info)){$pgsize=str_replace('V','H',$pgsize);}
if(substr($info,-4)=='deta'){$pgsize=str_replace('V','H',$pgsize);}

// $psize=substr($pgsize,0,2).' ';
// if(substr($pgsize,-1,1)=='V'){$psize.=' portrait';}else{$psize.=' landscape';}

if(empty($prnt)){$fsize='';}
if(!empty($edit)){$fsize=12;}
if(!empty($prnt)){$fsize=10;}
// if(!empty($ifsize)){$fsize=$ifsize;}

// echo '*/*/*'.$_COOKIE['user_codigo'];
// RESULTADO
// echo '<div id="main2" >';
echo '<div id="main2" style="font-size:'.$fsize.'px;" >';

$sql_idx=1;
if($info=='iikrdx')
{
     $sql_orig=$sql_info;
     $sql_array=array();
     $sql_idx=0;
     while($aso_krdx=msql_fetch_assoc($res_krdx))
     {
          $sql_idx++;
          if(empty($item))
          {$sql_info=str_replace('where ','where item="'.$aso_krdx['item_codigo'].'" and ',$sql_orig);}
          if(!empty($item))
          {$sql_info=str_replace($item.'%',$aso_krdx['item_codigo'].'%',$sql_orig);}
          $sql_array[$sql_idx]=$sql_info;
     }
}

if($info=='iiblog')
{
     $sql_orig=$sql_info;
     $sql_array=array();
     $sql_idx=0;
     while($aso_krdx=msql_fetch_assoc($res_krdx))
     {
          $sql_idx++;
          if(empty($bode))
          {$sql_info=str_replace('where ','where bode="'.$aso_krdx['bode_codigo'].'" and ',$sql_orig);}
          if(!empty($bode))
          {$sql_info=str_replace($bode.'%',$aso_krdx['bode_codigo'].'%',$sql_orig);}
          $sql_array[$sql_idx]=$sql_info;
     }
}


?>
<!-- <input type="range"> -->
<?php

echo '<result>';
for($idx=1; $idx<=$sql_idx; $idx++)
{
     if($info=='iikrdx'){$res_info=msql_query($sql_array[$idx],$link_data);}
     if($info=='iikrdx' and msql_num_rows($res_krdx)>1 and msql_num_rows($res_info)==0){continue;}     

     if(gettype($res_info)!='NULL')
     {
          $zreso=$res_info;
          $zinfo=$info;
          $zhead=1;
          $zheightrow='1.6';
//           $type='xml';
//           $zwidthtable='100%';
//           $zfile='../'.$cfg_empr.'/info/'.$cfg_empr.'_'.$modu.'_'.$info.'_'.date('Ymd_His').'.csv';
          
          if($info=='vtrpm1')
          {$zfile='../'.$cfg_empr.'/info/'.$cfg_empr.'_'.$modu.'_'.$info.'_'.$fecha2.'_'.date('Ymd_His').'.csv';}
          if($info=='vtgrge2'){$zblockfield='sema';}
          if($info=='iicuxc'){$zblockfield='item';}
          if($info=='iiiiee' and $orden=='Linea'){$zblockfield='linea';}
          if($info=='iikrdx'){$zblockmonth=1;}
          if(substr($info,2,4)=='deta' and empty($item)){$zblockfield='idate_hide';}
          if(substr($info,2,4)=='dein' and empty($item)){$zblockfield='idate_hide';}
          
          $xlsf=$cfg_empr.'_'.$modu.'_'.$info.'_'.date('ymd_His');
          if($prnt==1){$xlsf='';}
          
          if($blog_info==1)
          {
               $modu_descri='INFO';
               $info_descri='FILES';
          }
          
          include('ele_grid.php');     

     
          if($info=='iikrdx')
          {if($idx<msql_num_rows($res_krdx)){echo '<div id="pgbreak" style="height:2em;"></div>';}}
     }
     
}
   
echo '</result>';

if(1==2)
{
     
msql_data_seek($res_info);
while($aso_item=msql_fetch_assoc($res_info))
{
          $zid=$aso_item['item'];
          $ztabla='item';
//           $zprecio=$lpre;
          $zcodigo=$aso_item['item'];
          if(empty($zcodigo)){$zcodigo=$aso_item['item_mdlo'];}
          if(empty($zcodigo)){$zcodigo=$aso_item['item_codigo'];}
//           $zstockv=3;
          if(mb_stristr('gnya.gmny',$cfg_empr) and !esMovil()){$zobj=4;}
          if(mb_stristr('gnya.gmny',$cfg_empr)){$zstockv=0;}
          if(mb_stristr('orel.imcp',$cfg_empr)){$zfixh=1;}
          if($format==4){$zobj=5; $zstockv=0;}
//           $ztotpvp=$aso_item['total']; 
//           $zbode=$bode;
//           $zcarr=1;
          if($format==5)
          {
//                $zcarr=0;
//                $zupld=1;
//                $zobj=2;
          }
          include('ele_image.php');  
     
}

}


echo '</div>';     


// if($modu=='inve' and $cost=='true'){$pgsize=str_replace('V','H',$pgsize);}
// if(mb_stristr('sriats',$info)){$pgsize=str_replace('V','H',$pgsize);}


$psize=substr($pgsize,0,2).' ';
if(substr($pgsize,-1,1)=='V'){$psize.='portrait';}
// else{$psize.='landscape';}

if(substr($pgsize,-1,1)=='H'){$psize.='landscape';}

?>

<style>
@page
{
size: <?php echo $psize; ?>;
margin: 10mm 10mm 10mm 10mm; /*	top right bottom left */
}  
     
@media print
{
/*     body {transform: scale(.5);} */
/*     table {page-break-inside: avoid;} */
}     
</style>  




<script>
function fn_consulta(event)
{
     var xhref='',dataget;
     xhref=xhref+'?scri=<?php echo basename(__FILE__,'.php');?>';
     dataget=new_FormData('filtros','get');
     xhref=xhref+dataget;
//      alert(xhref);
     document.getElementById("main2").innerHTML='Espere...';
     location.href=xhref;
}
</script>


<script>document.title="<?php echo $xtitle;?>"</script>
<script>document.getElementById('topcenter').innerHTML="<?php echo $xtopcenter;?>"</script>


