<?php
     $filename=$xlsf.'_sridr.xls';
     
     $file_content='';
     $file_content.='<?php '."\n";
     $file_content.='header("Content-type: application/vnd.ms-excel");'."\n";
//      $file_content.='header("Content-type: application/vnd.ms-excel"); charset=iso-8859-1'."\n";
     $file_content.='header("Content-Disposition: attachment; filename='.$filename.'");'."\n";
     $file_content.='header("Pragma: no-cache");'."\n";
     $file_content.='header("Expires: 0");'."\n";
     
     $file_content.="\n".'?> ';
     $file_content.="\n";

     $file_content.="<style>"."\n";
     /*force text*/     
     $file_content.='.text{mso-number-format:"\@";}'."\n";
     $file_content.='.num {mso-number-format:General;}'."\n";
     $file_content.="</style>"."\n";

// $file_content='';
     
     
$sql_retc='';
$sql_retc.='select ';
$sql_retc.='concat("\'",ptoe,numero) as Numero,';
$sql_retc.='concat("\'",claveacc) as Autorizacion,';
$sql_retc.='fecha as Fecha,';
$sql_retc.='concat("\'",enti) as RUC,';
$sql_retc.='cant as Base,';
$sql_retc.='puni as Porcentaje,';
$sql_retc.='(cant*puni/100) as Valor ';
$sql_retc.='from retc1 left join retc2 on idnum1=idnum2 ';
$sql_retc.='where ifnull(status,"") not in("O","X") ';
$sql_retc.='and cant*puni!=0 ';
// $sql_retc.='and puni<10 ';

// $sql_retc.='and cair*1>=300 ';
$sql_retc.='and ifnull(cair,0)*1>=300 ';
// $sql_retc.='and docu="RCLI" ';
$sql_retc.='and docu in("RCLI","RBCO") ';

$sql_retc.='and fecha>="'.$fecha1.'" ';
$sql_retc.='and fecha<="'.$fecha2.'" ';



// echo '<br>===R '.$sql_retc;

$res_retc=msql_query($sql_retc,$link_data);

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

     
     $style='';
     $style.='.text{mso-number-format:"\@";}';
     $style.='.num {mso-number-format:General;}';

     $element=$domg->appendChild($domg->createElement("style",htmlspecialchars($style)));     


     $table=$domg->appendChild($domg->createElement("table",""));  
          $xstyle='';
          $xstyle.='font-family:arial;';
          $xstyle.='font-size:14px;';
          $xstyle.='white-space:nowrap;';
          $xstyle.='border-collapse:collapse;';
          $table->setAttribute("style",$xstyle) ;  
//           $table->setAttribute("width","300%") ;  

     $trow=$table->appendChild($domg->createElement("tr",""));
          $trow->setAttribute("style",'background:#d3d3d3;') ;  
     for($xcol=0; $xcol<msql_num_fields($res_retc); $xcol++)
     {
          $field_name=msql_field_name($res_retc,$xcol);
          $field_name=str_replace('_',' ',$field_name);
          $tcol=$trow->appendChild($domg->createElement('th',$field_name));

     }          
     while($aso_retc=msql_fetch_assoc($res_retc))
     {
          $trow=$table->appendChild($domg->createElement("tr",""));
//                if($aso_retc['Valor']<0)
//                {$trow->setAttribute("style",'background:#d3d3d3;');}

          for($xcol=0; $xcol<msql_num_fields($res_retc); $xcol++)
          {
               $value=$aso_retc[msql_field_name($res_retc,$xcol)];
//                if(mb_stristr('int.real',msql_field_type($res_retc,$xcol)))
//                {$value=round($value,2);}
               $tcol=$trow->appendChild($domg->createElement('td',$value));
          }          
          
     }
     
     
     
     $html2=$domg->saveHTML();
     $file_content.=$html2;
//      file_put_contents($file_php_xls_zeus,$file_content); 
     file_put_contents($file_php_xls_sridr,$file_content); 

?>