<?php 
session_start();
foreach($_GET as $campo => $valor){${$campo}=trim($valor);} 
foreach($_POST as $campo => $valor){${$campo}=trim($valor);} 



include_once('lib_main.php');
if(!empty($empr)){$link_data=msql_connect('','','',$empr); $cfg_empr=$empr;}

if(empty($fecha1)){$fecha1=date('Ymd');}
if(empty($fecha2)){$fecha2=$fecha1;}
if($fecha2<$fecha1){$fecha2=$fecha1;}

$sql_info ='select * from vtas1 ';
$sql_info.='where docu like "FC%" ';
$sql_info.='and fecha>="'.$fecha1.'" ';
$sql_info.='and fecha<="'.$fecha2.'" ';
// if(!empty($enti))
$res_info=msql_query($sql_info,$link_data);

while($aso_info=msql_fetch_assoc($res_info))
{
     echo '<br>*/*/* '.$aso_info['docu'].'-'.$aso_info['numero'].'-'.$aso_info['idnum1'];     
}


return;



$user_codigo=$_SESSION['user_codigo'];
$user0=data_maes('user',$user_codigo);

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

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

echo $dom->saveXML();


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

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



$modu=strtolower($modu);     

if($modu=='inve'){$xtitulo='INVENTARIOS';}
if($modu=='vtas'){$xtitulo='VENTAS';}

// $fecha0=inve_fecha0();
$fecha0=fecha0($tabla);

// echo '------'.$proc;

if(!empty($proc))
{
     if($proc=='lifi')
     {
          $sql_info ='select * ';
//           $sql_info.=',sum(case when left(docu,1)="I" then cant else cant*(-1) end) as saldound ';
          $sql_info.='from inve1 ';
          $sql_info.='left join inve2 on idnum1=idnum2 ';
          $sql_info.='left join item0 on item=item_codigo ';
          $sql_info.='left join lsub0 on item_lsub=lsub_codigo ';
          
          $sql_info=calc_tran('inve',$sql_info);
          
          $sql_info.='where status not in("O","X") ';
          if(!empty($lsub))
          {$sql_info.='and item_lsub like "'.$lsub.'%"';}
          if(!empty($bode))
          {$sql_info.='and bode like "'.$bode.'%"';}
          
          $sql_info.='and item_codigo in(';
          $sql_info.='select distinct item from inve1  ';
          $sql_info.='left join inve2 on idnum1=idnum2 ';
          $sql_info.='where status not in("O","X") and left(fecha,7)>="'.substr($fecha1,0,7).'"';
          $sql_info.='and fecha >="'.$fecha0.'" ';
          $sql_info.='and fecha <="'.$fecha2.'" ';
               if(!empty($bode))
               {$sql_info.='and bode like "'.$bode.'%"';}
          $sql_info.=')';
          
          $xgroupby='group by item ';
          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 lsub_descri,item_descri,item_codigo ';}
          if(mb_stristr($orden,'Linea')){$xorderby='order by item_lsub,item_descri,item_codigo ';}
     }
     $sql_info.=$xgroupby;
     $sql_info.=$xorderby;
     
     
     
     if($proc=='lifi')
     {
//           $fields.='lsub_descri as linea,';
          $fields.='lsub_codigo as linea,';
          $fields.=$tabla.'_codigo as codigo,';
          $fields.=$tabla.'_descri as producto,';
          if($unid)
          {$fields.='saldound as saldo,';}
          $fields.=$tabla.'_umdd as umdd,';
          $fields.='" " as conteo_1,';
          $fields.='" " as conteo_2,';
//           $fields.='" " as conteo_3,';
          $fields.='" " as obser,';
          $fields.='item_duni,';
          $fields.=$tabla.'_status as st';
     }
     
//      $fields='';
     if(!empty($fields))
     {
          $sql_info='select '.$fields.' from ('.$sql_info.') ';
          $sql_info.='as maes0 ';
          if($saldo>0)
          {
//                echo '*/*/*/'.$saldo;
               if($saldo==6) {$sql_info.='where saldound<0 ';}
               if($saldo==8) {$sql_info.='where saldound=0 ';}
               if($saldo==9) {$sql_info.='where saldound>0 ';}
               if($saldo==68){$sql_info.='where saldound<=0 ';}
               if($saldo==69){$sql_info.='where saldound!=0 ';}
               if($saldo==98){$sql_info.='where saldound>=0 ';}
          }
     }
     
//      echo '*/*/*/'.$sql_info;
     
     $res_info=msql_query($sql_info,$link_data);
     $msgres='';
     $msgres.=msql_num_rows($res_info).' Resultado(s)...';
     
}

// echo '*/*/*/*'.$sql_info;

echo '<div id="filtros" >';
{
//      echo basename(__FILE__,'.php'); 
// echo __FILE__;
     
// OCULTOS
// echo '<input id="format" hide value="'.$format.'">';
// echo '<input id="limit" hide value="'.$limit.'">';
     
{$ztitulo='FILTROS'; include('ele_title.php');}

$zid='modu';
$ztabla='modu';
$zlabel='Módulo';
$zvalue=$modu; 
if(!empty($modu)){$zreado=1;}
$zonblur='{location.href="?scri=proc_modu3&modu="+document.getElementById("modu").value;}';
$zonchange='{location.href="?scri=proc_modu3&modu="+document.getElementById("modu").value;}';
include('ele_select.php');

     
$ztabla='enti';
//           $zwhere='(left(enti_codigo,10) in(select distinct left(enti,10) from vtas1 union select distinct left(enti,10) from clie1))';
include('ele_datalist.php');
     
$ztabla='item';
include('ele_datalist.php');
     
$ztabla='ctas';
include('ele_datalist.php');
     
if($modu=='vtas')
{
     $zid='proc';
     $zlabel='Proceso';
     $zvalue=$proc;
     $zoptions='';
//      $zoptions.='enti,X Cliente;';     
//      $zoptions.='item,X Producto;';     
//      $zoptions.='lsub,X Lineas;';     
//      $zoptions.='fmes,X Mes;';     
//      $zoptions.='docu,X Documento;';     
//      $zoptions.='idnum,X Transacción;';     
     // $zonchange='{proc_modu3(event);}';
     // $zonchange='{location.href="?scri=proc_modu3"+"&modu="+document.getElementById("modu").value+"&repo="+document.getElementById("repo").value;}';
     include('ele_select.php');
}
     
if($modu=='inve')
{
     $zid='proc';
     $zlabel='Proceso';
     $zvalue=$proc;
     $zoptions='';
//      $zoptions.='ssss,Sumas & Saldos;';     
//      $zoptions.='ssgg,Saldos General;';     
//      $zoptions.='ssbb,Saldos X Bodega;';     
//      $zoptions.='item,Kardex;';     
//      $zoptions.='ie13,Transferencias;';     
//      $zoptions.='evta,Egresos X Venta;';     
//      $zoptions.='econ,Egresos X Consumo;';     
     $zoptions.='lifi,Lista Invent. Físico;';     
     // $zonchange='{proc_modu3(event);}';
     // $zonchange='{location.href="?scri=proc_modu3"+"&modu="+document.getElementById("modu").value+"&repo="+document.getElementById("repo").value;}';
     include('ele_select.php');
     
     
// $poptions=' ,TODOS;D,DISPO;N,NO-DIS';     
     
     $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';
     include('ele_select.php');
     
//      if($unid==''){$unid=1;}
     $zid='saldo';
     $zlabel='Saldo';
     $zvalue=$saldo;
     $zheptav=1;
     $zonchange='{proc_modu(event);}';
     include('ele_select.php');  

     
     $zid='cero';
     $zlabel='Cero';
     $zvalue=$cero;
     $zclass='numeric-dec';
     $zmax=1;
     $zmin=0;
     $zstep=0.01;
     $zhide=1;
     include('ele_input.php');
     
     
     $zid='unid';
     $ztype='checkbox';
     $zlabel='Unidades';
     $zvalue=$unid;
     include('ele_input.php');  
     
     $zid='cost';
     $ztype='checkbox';
     $zlabel='Costos';
     $zvalue=$cost;
     include('ele_input.php');  
     
     $zid='imgi';
     $ztype='checkbox';
     $zlabel='Imagen';
     $zvalue=$imgi;
     include('ele_input.php');  
     
     
$zobj=1;     
include('ele_break.php');
     
}
    
     
if($proc=='lifi' and empty($fecha1))
{$fecha1=$fecha0;}
     
$zid='fecha1';
$ztype='date';
$zlabel='Fec.Ini.';
$zvalue=$fecha1;     
include('ele_input.php');  
     
$zid='fecha2';
$ztype='date';
$zlabel='Fec.Fin';
$zvalue=$fecha2;     
include('ele_input.php');  

// if(empty($lsub) and $cfg_empr=='hfre'){$lsub='INAG-';} 
// if(!isset($lsub) and $cfg_empr=='hfre'){$lsub='INAG-';} 
$zid='lsub';
$zlabel='Linea';
$zvalue=$lsub;
$ztabla='lsub';
$ztodo=1;
include('ele_select.php');
     
$zid='item';
$zlabel='Item';
$zvalue=$item;
$ztabla='item';
include('ele_input.php');
     
$zid='btn_acepta'; 
$zlabel='Aceptar';
$zalign='right';
$zonclick='{proc_modu(event);}';
include('ele_button.php');

// echo '<span style="float:right; white-space:nowrap;">';     
// echo '</span>';     

echo '<span style="float:right; white-space:nowrap;">';     
// if($format!=4)
{echo $msgres;}
echo '</span>';     


{    
     
include('ele_break.php');

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



$zid='orden';
$zvalue=$orden;
$zlabel='Ordenar X';
// $zoptions='Código;Nombre (A-Z);';
$zoptions='';
$zoptions.='Código;';
$zoptions.='Nombre;';
if($modu=='inve')     
{
     $zoptions.='Linea;';
}     
if($modu=='vtas')     
{
     $zoptions.='Zona;';
     $zoptions.='Linea;';
}
if($modu=='comp')     
{
     $zoptions.='T.Prov.;';
     $zoptions.='CAIR;';
}
     
$zonchange='{proc_modu(event);}';
$zalign='right';
include('ele_select.php');

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

echo '<div id="main2">';     
{     
     
     $dom = new DOMDocument();
          $dom->encoding = 'utf-8';
          $dom->xmlVersion = '1.0';
          $dom->formatOutput = true;
     $ele=$dom;

     
          $xcont=0;
          $thead=array();
          $tfoot=array();
          $field_name=array();
          $field_type=array();
          $field_leng=array();
          $table='grid';
          $trow='row';
          $tcol='col';
          $type='html';
          if($type=='html')
          {
               $table='table';
               $trow='tr';
               $tcol='td';
          }
     
          $name=$proc;
          $blockrows=5;
          $blockbott='dotted 1px;';
          $heightrow='';
     
          if($proc=='lifi')
          {
               $blockrows=5;
               $blockbott='solid 2px;';
//                $heightrow='50px;';
          }
          if(empty($name)){$name='tablename';}
          $root=$dom->appendChild($dom->createElement($name));
               $root->setAttribute('date',date('Y-m-d'));
               $root->setAttribute('time',date('H:i:s'));

//           $zdom=$dom;
//           $zele=$root;
//           $zid='print_'.$name; 
//           $zlabel='Imprimir';
//           $zalign='right';
//           $zonclick='{window.print();}';
// //           $zonclick='{print_selec("main2");}';
//           $znoprint=1;
//           $zsize=0.8;
//           include('ele_button.php');
     
          $zdom=$dom;
          $zele=$root;
          $zid='xls_'.$name; 
          $zlabel='Excel';
          $zalign='right';
          $zonclick="javascript:fnExcelReport('".$name."',this,'".$cfg_empr."_".$name."_".date('Ymd_His')."');";
          $zhref='#';
          $znoprint=1;
          $zsize=0.8;
          include('ele_button.php');
     

     
// FILTROS /CABECERAS IMPRESION     
     if($proc=='lifi'){$print_titulo='LISTADO PARA CONTEO FISICO';}

          $grid=$root->appendChild($dom->createElement($table));
               $grid->setAttribute("border","1");
          {
//                $grid->setAttribute('id',$name);
               $grid->setAttribute('width','99%');
               $grid->setAttribute('align','center');
//                $grid->setAttribute('cellspacing','0');
//                $grid->setAttribute('cellpadding','0');
               $style='';
               $style.='border-collapse:collapse;';
               $style.='background-color:snow;';
               $style.='font-family:arial;';
               $grid->setAttribute('style',$style);
          }
          $headg=$grid->appendChild($dom->createElement('thead'));
//                $headg->setAttribute("noscreen","");
               $row=$headg->appendChild($dom->createElement($trow));
                    $col=$row->appendChild($dom->createElement($tcol));       
                    $div=$col->appendChild($dom->createElement('div',$print_titulo));   
     
               $row=$headg->appendChild($dom->createElement($trow));
                    $col=$row->appendChild($dom->createElement($tcol));       
                    $div=$col->appendChild($dom->createElement('div','subti'));   
     
     
     
          $rowg=$grid->appendChild($dom->createElement('tbody'));
     
//                $row=$rowg->appendChild($dom->createElement($trow));
//                     $col=$row->appendChild($dom->createElement($tcol));       
     

               $row=$rowg->appendChild($dom->createElement($trow));
                    $col=$row->appendChild($dom->createElement($tcol));       
                         $col->setAttribute("style","padding:0;");
                    $div=$col->appendChild($dom->createElement('div'," "));                           
     
     
// DETALLE

          $style='';
          $style.='tr[name]:hover{background-color:lightblue !important;}; ';
//           $style.='td.align-r{text-align:right;}; ';
//           $style.='td[class].align-r{text-align:right;background-color:green;};';
//           $style.='td[td_date]{white-space:nowrap;text-align:center;}; ';
//           $style.='.td_date{white-space:nowrap;text-align:center;}; ';
          $root->appendChild($dom->createElement('style',$style));
     
//           $grid=$root->appendChild($dom->createElement($table));
          $grid=$div->appendChild($dom->createElement($table));
               $grid->setAttribute('name',$name);
               $grid->setAttribute('blockrows',$blockrows);
               $grid->setAttribute('blockbott',$blockbott);
               $grid->setAttribute('heightrow',$heightrow);
               if($proc=='lifi')
               {$grid->setAttribute("border","1");}
//                $grid->setAttribute('class','fix_table');
     
          if($type=='html')
          {
               $grid->setAttribute('id',$name);
               $grid->setAttribute('width','100%');
//                $grid->setAttribute('cellspacing','0');
//                $grid->setAttribute('cellpadding','0');
               
               $style='';
               $style.='border-collapse:collapse;';
               $style.='background-color:snow;';
               $style.='font-family:arial;';
//                $style.='font-size:90%;';
               $grid->setAttribute('style',$style);
          }
     
     
     
     $caption='';
     $grid->appendChild($dom->createElement('caption',$caption));
     $colg=$grid->appendChild($dom->createElement('colgroup'));
     $headg=$grid->appendChild($dom->createElement('thead'));
     $rowg=$grid->appendChild($dom->createElement('tbody'));
     $footg=$grid->appendChild($dom->createElement('tfoot'));
          $style='';
          $style.='background-color:silver;';
          $style.='border-top:2px solid;border-bottom:2px solid;';
          $headg->setAttribute('style',$style);
          $footg->setAttribute('style',$style);
          $rowg->setAttribute('valign','top');
          $rowg->setAttribute('style','overflow-y:auto;');
     
     
          // validar totales
          for($xcol=0; $xcol<msql_num_fields($res_info); $xcol++)
          {
               $field_name[$xcol]=msql_field_name($res_info,$xcol);
               $field_type[$xcol]=msql_field_type($res_info,$xcol);
               if(mb_stristr($field_name[$xcol],'__')){$field_name[$xcol]=str_replace('__','-',$field_name[$xcol]);}
               for($xrow=0; $xrow<msql_num_rows($res_info); $xrow++)
               {
                    $value=msql_result($res_info,$xrow,$xcol);
                    $value_leng=strlen($value);
//                     echo ' ==>'.$field_name[$xcol].'='.$value_leng;
                    if($value_leng>$field_leng[$xcol]){$field_leng[$xcol]=$value_leng;}
                    if(mb_stristr('int.real',$field_type[$xcol])){$value=$value*1;}
                    if(mb_stristr('int.real',$field_type[$xcol]) and $type=='xml'){$value=1;}
                    if(mb_stristr('saldo.total',$field_name[$xcol])){$value=1;}
                    if(mb_stristr('item_duni.item_dpre.item_dval.item_dcos',$field_name[$xcol])){$value=0;}
                    if(!empty($value)){$thead[$xcol]='1';break;}
               }
          }

          // llena detalle
          msql_data_seek($res_info,0);
          for($xrow=0; $xrow<msql_num_rows($res_info); $xrow++)
          {
               $asoc=msql_fetch_assoc($res_info);
               $item_duni=$asoc['item_duni'];
               $item_dval=$asoc['item_dval'];
               $item_dpre=$asoc['item_dpre'];
               $item_dcos=$asoc['item_dcos'];
               $status=$asoc['status'];
               $stat=$asoc['stat'];
               $st=$asoc['st'];
//                if(empty($status)){$status=$asoc['stat'];}
               if($item_dval<2){$item_dval=2;}
               if($item_dpre<2){$item_dpre=2;}
               if($item_dcos<2){$item_dcos=2;}

//                     echo ' ==>'.$xrow.':'.$status.$item_dval;
               $style=''; 
               $class='';
               if(($xrow+1)%$blockrows==0){$style.='border-bottom:'.$blockbott; } 
//                if(($xrow+1)%2==0){$style.='background-color:#f8f8f8;'; } 
//                if(($xrow+1)%2==0){$style.='background-color:gainsboro;'; } 
               if($xrow+1==msql_num_rows($res_info)){$style.='border-bottom:solid 2px;'; } 
//                if($status=='O'){$style.='text-decoration:line-through;';}
//                if($status=='O'){$class.='linethrough ';}
               
               $row=$rowg->appendChild($dom->createElement($trow));
               if(!empty($heightrow))
               {$row->setAttribute('height',$heightrow);}
               
               if($proc=='lifi')
               {
//                     $row->setAttribute('valign-m'," ");
               }
               
               if($type=='html')
               {
                    $row->setAttribute('name',"");
                    if($status=='O' or $stat=='O' or $st=='O'){$row->setAttribute('linethr',"");}
                    if(!empty($style)){$row->setAttribute('style',$style);}
                    if(!empty($class)){$row->setAttribute('class',$class);}
                    
                    // COLUMNA #linea
                    $col=$row->appendChild($dom->createElement($tcol,str_pad($xrow+1,strlen(msql_num_rows($res_info)),'0',STR_PAD_LEFT)));
                    $style='';
                    $class='';
                    
                    $col->setAttribute('align-c',"");
                    $col->setAttribute('size80',"");
                    $col->setAttribute('border-l',"");
                    $col->setAttribute('border-r',"");
                    if(!empty($class)){$col->setAttribute('class',$class);}
                    if(!empty($style)){$col->setAttribute('style',$style);}
               }
               
               
               for($xcol=0; $xcol<msql_num_fields($res_info); $xcol++)
               {
                    $value=msql_result($res_info,$xrow,$xcol);
                    
                    if($type=='xml'){$tcol=$field_name[$xcol];}
                    if($field_type[$xcol]=='int'){$tfoot[$xcol]++;}
                    if($field_type[$xcol]=='real'){$tfoot[$xcol]+=$value;}

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

                    if($type=='html' and !empty($thead[$xcol]))
                    {
                         if(mb_stristr('puni.p_unit.p-unit.unit.punit.pvp',$field_name[$xcol]))
                         {$value=number_format(trunc_real($value,$item_dval),$item_dpre);}
                         
                         if(mb_stristr('cost',$field_name[$xcol]) and mb_stristr('int.real',$field_type[$xcol]))
                         {$value=number_format(trunc_real($value,$item_dval),$item_dcos);}
                         
                         if(mb_stristr('cant.ingreso.egreso.saldound.saldound',$field_name[$xcol]))
                         {$value=number_format((float)$value,$item_duni);}
                         
//                          if(mb_stristr('puni.p-unit.unit.subt.subtiva0.subtiva.subtice.pvp.cost',$field_name[$xcol]))
//                          {$value=number_format($value,$item_dval);}
                         
                         if(mb_stristr('tdcto.subt.subtiva0.subtiva.subtice.sub-total.sub-tot.saldo',$field_name[$xcol]))
                         {$value=number_format($value,2);}
                         
                         if(mb_stristr('debito.credito',$field_name[$xcol]))
                         {$value=number_format($value,2);}
                         
//                          if(mb_stristr('total.saldo',$field_name[$xcol]))
//                          {$value=number_format($value,2);}

                         if(mb_stristr('img',$field_name[$xcol]))
                         {
//                               if(file_exists($value))
//                               {$value_img=$value;$value="";}
                              if(empty($value)){$value="SIN FOTO";}
                              else{$value_img=$value;$value="";}
                         }

                         $crea_value=true;
                         if(mb_stristr('numero',$field_name[$xcol]))
                         {
                              $ptoe=$asoc['ptoe'];
                              $col=$row->appendChild($dom->createElement($tcol));       
                              $div=$col->appendChild($dom->createElement('div',htmlspecialchars($ptoe.$value)));                           
                                   $div->setAttribute('hide',"");
                              
                              $href='';
                              $href='?prnt=1&docu='.$asoc['docu'].'&idnum='.$asoc['idnum1'].'&formato=';
                              $ref=$col->appendChild($dom->createElement('a',htmlspecialchars($value)));                           
                                   $ref->setAttribute('href',$href);
                                   $ref->setAttribute('target','_blank');
                              
                              $crea_value=false;
                         }

                         if($crea_value)
                         {$col=$row->appendChild($dom->createElement($tcol,htmlspecialchars($value)));}
                         $class='';
                         $style='';
                         if(empty($value_img))
                         {}
                         else
                         {
                              $col->setAttribute("align-c","");
                              $img=$col->appendChild($dom->createElement("img",""));
                              $img->setAttribute("src",$value_img);
                              $img->setAttribute("width","50");
                              $img->setAttribute("heigth","50");
                              $value_img="";
                         }
                      
//                         $col->setAttribute('nowrap',"");                      
//                          <img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="600">

                         if(strlen($value)>20){$col->setAttribute('size80',"");}
                         if(strlen($value)>40){$col->setAttribute('size60',"");}
                         if(mb_stristr('idnum1.idnum2.idn.iddet.idd',$field_name[$xcol])){$col->setAttribute('size80',"");}
                         if(mb_stristr('tdcto.tiva.tice.tirbp',$field_name[$xcol])){$col->setAttribute('size80',"");}
                         if(mb_stristr('tiva.tice.tirbp',$field_name[$xcol])){$col->setAttribute('italic',"");}
                         if(mb_stristr('ptoe.ptov.bode.caja.ctab',$field_name[$xcol])){$col->setAttribute('size80',"");}
                         if(mb_stristr('tdcto',$field_name[$xcol])){$col->setAttribute('underline',"");}
                         if(mb_stristr('ptoe.numero.status.st',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                         if(mb_stristr('color.talla',$field_name[$xcol])){$col->setAttribute('size80',"");}
                         if(mb_stristr('color.talla',$field_name[$xcol])){$col->setAttribute('align-c',"");}
                         if(mb_stristr('item',$field_name[$xcol]))
                         {
                              $onclick ="";
                              $onclick.="{window.location.href=\"?scri=shop_item2&buscar=".$value."\"}";
                              $col->setAttribute('onclick',$onclick);
                         }
                      
                         if($field_type[$xcol]=='string' and mb_stristr($value,'-')){$col->setAttribute('nowrap',"");}
                         if($field_type[$xcol]=='string' and mb_stristr($value,'-')){$col->setAttribute('size80',"");}
                         if($field_type[$xcol]=='string' and $field_leng[$xcol]<=9){$col->setAttribute('nowrap',"");}
                         if($field_type[$xcol]=='string' and $field_leng[$xcol]<=4){$col->setAttribute('align-c',"");}
                         if($field_type[$xcol]=='int' and $field_leng[$xcol]<=2){$col->setAttribute('align-c',"");}
                         if($field_type[$xcol]=='int' and $field_leng[$xcol]>2){$col->setAttribute('align-r',"");}
                         if($field_type[$xcol]=='real'){$col->setAttribute('align-r',"");}
                         if($field_type[$xcol]=='date'){$col->setAttribute('td_date',"");}
                         if($field_type[$xcol]=='datetime'){$col->setAttribute('td_date',"");}
                         if(mb_stristr('total.saldo',$field_name[$xcol])){$col->setAttribute('td_total',"");}
                         if(!empty($class)){$col->setAttribute('class',$class);}
                         if(!empty($style)){$col->setAttribute('style',$style);}
                    }
               }
          }

          if($type=='xml')
          {
               $rowf=$footg->appendChild($dom->createElement($trow));
               for($xcol=0; $xcol<msql_num_fields($res_info); $xcol++)
               {
                    if(!empty($thead[$xcol]))
                    {$col=$rowf->appendChild($dom->createElement($field_name[$xcol],$tfoot[$xcol]));}
               }
          }
     
          // col head foot
          $xsort=0;
          if($type=='html')
          {
               $rowh=$headg->appendChild($dom->createElement($trow));
               $rowf=$footg->appendChild($dom->createElement($trow));
                    if($proc=='lifi')
                    {$rowf->setAttribute('hide',"");}
               
               $ccolg=$colg->appendChild($dom->createElement('col',""));
                    $ccolg->setAttribute('colu','L');
               $crowh=$rowh->appendChild($dom->createElement('th','L'));
               $crowf=$rowf->appendChild($dom->createElement('th'));

               $class='size80 ';
               $onclick='sortTable(this,'.$xsort++.'';
               if($field_type[$xcol]=='real'){$onclick.=',"N"';}
               $onclick.=');';
//                if(!empty($onclick))
               {$crowh->setAttribute('onclick',$onclick);}
               {$crowh->setAttribute('class',$class);}
               
               
               for($xcol=0; $xcol<msql_num_fields($res_info); $xcol++)
               {
                    if(!empty($thead[$xcol]))
                    {
                         // group col
                         $style='';
                         $class='';
                         if(mb_stristr('enti.item.ctas',$field_name[$xcol])){$style.='background-color:gainsboro;';}
                         if(mb_stristr($field_name[$xcol],'conteo') and $proc=='lifi'){$style.='background-color:whitesmoke;';}
//                          if(mb_stristr($field_name[$xcol],'observaciones')){$style.='min-width:50%;';}
//                          if(mb_stristr('item_duni',$field_name[$xcol])){$style.='display:none;';}
//                          if(mb_stristr($field_name[$xcol],'observac')){$style.='width:15%;';}

                         $col=$colg->appendChild($dom->createElement('col',""));
                              $col->setAttribute('colu',$field_name[$xcol]);
                              $col->setAttribute('type',$field_type[$xcol]);
                              if(empty($thead[$xcol])){$col->setAttribute('hide',"");}                         
                              if($field_type[$xcol]=='date'){$col->setAttribute('td_date',"");}
                              if($field_type[$xcol]=='real'){$col->setAttribute('align-r',"");}
                              if(mb_stristr('total.saldo',$field_name[$xcol])){$col->setAttribute('td_total',"");}
                              if(mb_stristr('puni.p-unit.unit.punit.pvp.cost',$field_name[$xcol])){$col->setAttribute('border-l',"");}
                              if(mb_stristr('puni.p-unit.unit.punit.pvp.cost',$field_name[$xcol])){$col->setAttribute('border-r',"");}
//                               if(mb_stristr('item_duni',$field_name[$xcol])){$col->setAttribute('hide',"");}
                              if(!empty($class)){$col->setAttribute('class',$class);}
                              if(!empty($style)){$col->setAttribute('style',$style);}

                         $style='';
                         $class='';
                         $onclick='';
                         
                              if(mb_stristr('idnum1.idnum2.idn.iddet.idd',$field_name[$xcol])){$class.='size80 ';}
                              if(mb_stristr('tdcto.tiva.tice.tirbp',$field_name[$xcol])){$class.='italic size80 ';}
                              if(mb_stristr('tdcto',$field_name[$xcol])){$class.='underline ';}
                              if($field_type[$xcol]=='date'){$class.='date';}
                                   $onclick.='sortTable(this,'.$xsort++.'';
                                   if($field_type[$xcol]=='real'){$onclick.=',"N"';}
                                   $onclick.=');';
                         
                         // group head
                         $val_fieldname=$field_name[$xcol];
                         $val_fieldname=strtoupper($val_fieldname);
                         $val_fieldname=str_replace('_','-',$val_fieldname);
                         
//                          if($val_fieldname=='')
                         
                         $col=$rowh->appendChild($dom->createElement('th',$val_fieldname));
                              $col->setAttribute('name',$field_name[$xcol]);
                              if(!empty($onclick)){$col->setAttribute('onclick',$onclick);}
                              if(!empty($class)){$col->setAttribute('class',$class);}
                              if(!empty($style)){$col->setAttribute('style',$style);}
//                               if($field_type[$xcol]=='string' and strlen($field_name[$xcol])==9){$col->setAttribute('size80',"");}
//                               if(mb_stristr($field_name[$xcol],'descri')){$col->setAttribute('size80',"");}
                              if($field_leng[$xcol]<=5){$col->setAttribute('size60',"");}
                              elseif($field_leng[$xcol]<=9){$col->setAttribute('size80',"");}
                         
//                               if($field_name[$xcol]=='obser'){$col->setAttribute('width',"20%");}
//                               if($field_name[$xcol]=='observac'){$col->setAttribute('width',"30%");}
//                               if($field_name[$xcol]=='observaciones'){$col->setAttribute('width',"40%");}
                              if($field_name[$xcol]=='obser'){$col->setAttribute('style',"min-width:10em;");}
                              if($field_name[$xcol]=='observac'){$col->setAttribute('style',"min-width:20em;");}
                              if($field_name[$xcol]=='observaciones'){$col->setAttribute('style',"min-width:30em;");}
                         
                 
                         $tfoot_val=$tfoot[$xcol];
                         if($field_type[$xcol]=='real'){$tfoot_val=number_format($tfoot_val,2);}
                         $col=$rowf->appendChild($dom->createElement('th',$tfoot_val));
                              $col->setAttribute('name',$field_name[$xcol]);
                              if(!empty($class)){$col->setAttribute('class',$class);}
                              if(!empty($style)){$col->setAttribute('style',$style);}
                    }
               }
          }

     echo $dom->saveXML();
     
     
//      while($aso_info=msql_fetch_assoc($res_info))
//      {
//           $zid=$aso_info['item_codigo'];
//           $ztabla='item';
//           $zprecio=$lpre;

//           $zcodigo=$aso_info['item_rfer'];
//           if(empty($zcodigo)){$zcodigo=$aso_info['item_mdlo'];}
//           if(empty($zcodigo)){$zcodigo=$aso_info['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_info['total']; 
//           $zbode=$bode;
// //           $zcarr=1;
//           $zstockv=1;
//           if($format==5)
//           {
//                $zcarr=0;
//                $zupld=1;
//                $zobj=2;
//           }
//           include('ele_master.php');  
          
//           if($format==4){$zobj=1;include('ele_break.php');}
//           $simi_codi=$zcodigo;
//           $same_codi=trim($aso_info['item_codigo']);
//           $same_desc=trim($aso_info['item_descri']);
          

//      }
     
     
}
echo '</div>';     
     
     



?>


<script>
function proc_modu(event)
{
     var xhref='',dataget;
//      xhref=xhref+'?scri=proc_modu3';
     xhref=xhref+'?scri=<?php echo basename(__FILE__,'.php');?>';
     
     dataget=new_FormData('filtros','get');
     xhref=xhref+dataget;

     document.getElementById("main2").innerHTML='Espere...';
     location.href=xhref;
     
//      var datapost;
//      datapost=new_FormData('filtros','post');
//      datapost.append('script','prueba2');
//      exe_ajax(datapost);
     
}
</script>





<script>document.title="<?php echo $xtitulo;?>"</script>
