Ver Mensaje Individual
  #13 (permalink)  
Antiguo 25/10/2010, 16:55
seyerben
 
Fecha de Ingreso: octubre-2010
Mensajes: 53
Antigüedad: 13 años, 6 meses
Puntos: 0
Pregunta Respuesta: Funcion para generar reporte en php y javascrip

Hola bueno creo que la consulta ya anda bien, eso creo
ahora te comento esos datos que tengo necesitos filtrarlos a la misma paguina para ello e creado una funcion donde genero la consulta y creo mi tabla y otra Funcion en javascrip que recibe la peticion y se encarga de llamar al objeto ajax para la ejecucion de la consulta, bueno la verdad no tengo conocimiento en javascrip y muy poco en php, asi que mi codigo no me esta generando ningun resultado. dejo el codigo aver si hay algo que puedan aportar

Código PHP:
function filtro_fecha($filtro_sel)
      {
       
$argumento explode("@"$filtro_sel);
       
//2009-01-01 2010-12-31
       
       
$argumento[0] = FormatoFecha($argumento[0]);
       
$argumento[1] = FormatoFecha($argumento[1]);
     
       
$consulta "SELECT tiendas.nombre,retarje.fechatr::DATE, to_char(div(sum(retarje.monto),100),'999,999,999,99') as total_monto 
       FROM oxxo.tiendas,oxxo.retarje WHERE tiendas.idtienda = retarje.tienda AND tiendas.idplaza = retarje.plaza  
       AND fechatr::DATE BETWEEN  '"
$argumento[0] . "' >= fechaInicial  and '".$argumento[0]."' <= fechaFinal and '"$argumento[1] . "' >= fechaInicial  and '".$argumento[1]."' <= fechaFinal  
       GROUP BY fechatr::DATE,nombre ORDER BY fechatr::DATE DESC"
;
       
$idConexion pg_connect($_SESSION['db_conection']);       
       
$listado pg_query($consulta) or die(pg_last_error($idConexion));
        
       
      
$strTitulo "Reporte";
      return 
reporte$listado$strTitulo );
    }
    
     function 
FormatoFecha($Fecha)
    {
        
$Fecha substr($Fecha,6,4)."-".substr($Fecha,3,2)."-".substr($Fecha,0,2);
        return 
$Fecha;
            
    }
  
    function 
reporte($listado$strTitulo )
    {
        
$salida "<div style=\"border: solid 0px black; height: 445px; overflow: auto; background-color: #BDCDDB;\">";
       
$salida .= "<br/><table id=\"ilumi\" width=\"70%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"table-layout: ;\">
                                            <tr>
                                                <td valign=\"top\">
                                                     <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"Header\">
                                                        <tr>
                                                             <td class=\"HeaderLeft\"></td> 
                                                                <th>$strTitulo</th>
                                                             <td class=\"HeaderRight\"></td> 
                                                        </tr>
                                                     </table>"
;
                                                     
       
$salida .= '<table class="Grid" >';
       if ( 
$listado ){
           
$NumRegistro pg_num_rows$listado );
                if (
$NumRegistro 0)
                {
                   
$salida .=' <table class="Grid" cellspacing="\" cellpadding="" style="empty-cells: show;">
                                                                    <tr class="Caption">
                                                                        <th width="100">Tienda</th>
                                                                        <th width="100">fecha</th>
                                                                        <th width="100">Monto</th>                                                                       
                                                                    </tr>
                                                                </table>'
;
                    
                    
$salida .= "<div style=\"border: solid 0px black; height: 387px; overflow: auto; background-color:#BDCDDB;\">";
        
                    
$salida .= "<table width=\"70%\"  class=\"Grid\" cellspacing=\"\" cellpadding=\"\" style=\"empty-cells: show;\"> ";
                    
$salida .= '<tr class="Row">';
                    
                    while(
$row pg_fetch_assoc$listado ) )
                    {                                                       
                          
$salida .= '<tr class="Row">';
                                                                    
                                    
//$strVarEco = $aryRegistros["economico"];
                                                                    
                                    //NOMBRE    
                                    
if (!empty($row["nombre"]))          
                                    
$salida .= '<td width="100" style="text-align:right;">'.$row["nombre"].'</td>'
                                    else
                                    
$salida .= '<td width="100" style="text-align:right;"><font color="#f7f7f7">.</font></td>';
                                                                        
                                    
//FECHA    
                                    
if (!empty($row["fechatr"]))
                                    {
                                        
$salida .= '<td width="100" style="text-align:right; background-color: #f7f7f7;">'.$row["fechatr"].'</td>';
                                    }
                                    else
                                    
$salida .= '<td width="100" style="text-align:right;"><font color="#f7f7f7">.</font></td>';
                                                                            
                                    
//MONTO 
                                    
if (!empty($row["total_monto"]))     
                                    
$salida .= '<td width="100" style="text-align:right;">'.$row["total_monto"].'</td>';
                                    else
                                    
$salida .= '<td width="100" style="text-align:right;"><font color="#f7f7f7">.</font></td>';                                                                        
                                    
$salida .= '</tr>'."\n";
                          }  
//FIN WHILE
                                                                
                          
$salida .= '</tr>'."\n"
                     return 
$salida;          
                }
                    
            }
              
        }   
         
        
     
//$sajax_request_type = "GET";      
sajax_init();
sajax_export("filtro_fecha");
sajax_handle_client_request(); 

y esto es en javascript

function filtro_fecha()
{

var sel_fecha_ini = document.getElementById("fechaInicial").value;
var sel_fecha_fin = document.getElementById("fechaFinal").value;

//(document.getElementById("fecha_ini").value + "@" + document.getElementById("fecha_fin").value + "@" + document.getElementById("org").value );
x_filtro_fecha(document.getElementById("fechaInici al").value + "@" + document.getElementById("fechaFinal").value , contenedorFiltro3 );
}


function contenedorFiltro3( respuesta )
{
document.getElementById("x_salida").innerHTML = respuesta;
}

en el voton con el evento onclik

<input name="{Button_Name}" type="submit" value="Entrar" class="Button" onclick="filtro_fecha();">

gracias por la ayuda