Ver Mensaje Individual
  #8 (permalink)  
Antiguo 05/11/2011, 15:13
Disfrith
 
Fecha de Ingreso: junio-2011
Mensajes: 21
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Ordenar y sumar totales con condiciones

Este es el codigo complto que tengo y el que quiero adaptar es el codigo que me proporcionaste


Código PHP:
<?php
include ("../conectar.php");

$cadena_busqueda=$_GET["cadena_busqueda"];

if (!isset(
$cadena_busqueda)) { $cadena_busqueda=""; } else { $cadena_busqueda=str_replace("",",",$cadena_busqueda); }

if (
$cadena_busqueda<>"") {
    
$array_cadena_busqueda=split("~",$cadena_busqueda);
    
$codproveedor=$array_cadena_busqueda[1];
    
$nombre=$array_cadena_busqueda[2];
    
$numfactura=$array_cadena_busqueda[3];
    
$cboEstados=$array_cadena_busqueda[4];
    
$fechainicio=$array_cadena_busqueda[5];
    
$fechafin=$array_cadena_busqueda[6];
} else {
    
$codproveedor="";
    
$nombre="";
    
$numfactura="";
    
$cboEstados="";
    
$fechainicio="";
    
$fechafin="";
}

//Conexion con la base
$link = ("../conectar.php");
//Se selecciona la base

$sql mysql_query("SELECT sum(totalfactura) as suma FROM facturasp");
//$my_error = mysql_error($link);
if($row=mysql_fetch_array($sql)){
}
//mysql_close($link);



?>


<html>
    <head>
        <title>Facturas</title>
        <link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
        <link href="../calendario/calendar-blue.css" rel="stylesheet" type="text/css">
        <script type="text/JavaScript" language="javascript" src="../calendario/calendar.js"></script>
        <script type="text/JavaScript" language="javascript" src="../calendario/lang/calendar-sp.js"></script>
        <script type="text/JavaScript" language="javascript" src="../calendario/calendar-setup.js"></script>
        <script language="javascript">
        
        var cursor;
        if (document.all) {
        // Está utilizando EXPLORER
        cursor='hand';
        } else {
        // Está utilizando MOZILLA/NETSCAPE
        cursor='pointer';
        }
        
        function inicio() {
            document.getElementById("form_busqueda").submit();
        }
        
        function nueva_factura() {
            location.href="nueva_factura.php";
        }
        
        function buscar() {
            var cadena;
            cadena=hacer_cadena_busqueda();
            document.getElementById("cadena_busqueda").value=cadena;
            if (document.getElementById("iniciopagina").value=="") {
                document.getElementById("iniciopagina").value=1;
            } else {
                document.getElementById("iniciopagina").value=document.getElementById("paginas").value;
            }
            document.getElementById("form_busqueda").submit();
        }
        
        function paginar() {
            document.getElementById("iniciopagina").value=document.getElementById("paginas").value;
            document.getElementById("form_busqueda").submit();
        }
        
        function hacer_cadena_busqueda() {
            var codproveedor=document.getElementById("codproveedor").value;
            var nombre=document.getElementById("nombre").value;
            var numfactura=document.getElementById("numfactura").value;            
            var cboEstados=document.getElementById("cboEstados").value;
            var fechainicio=document.getElementById("fechainicio").value;
            var fechafin=document.getElementById("fechafin").value;
            var cadena="";
            cadena="~"+codproveedor+"~"+nombre+"~"+numfactura+"~"+cboEstados+"~"+fechainicio+"~"+fechafin+"~";
            return cadena;
            }
        
        function limpiar() {
            document.getElementById("form_busqueda").reset();
        }
        
        function abreVentana(){
            miPopup = window.open("ventana_proveedores.php","miwin","width=700,height=380,scrollbars=yes");
            miPopup.focus();
        }
        
        function validarproveedor(){
            var codigo=document.getElementById("codproveedor").value;
            miPopup = window.open("comprobarproveedor_ini.php?codproveedor="+codigo,"frame_datos","width=700,height=80,scrollbars=yes");
        }
        </script>
    </head>
    <body onLoad="inicio()">
        <div id="pagina">
            <div id="zonaContenido">
                <div align="center">
                <div id="tituloForm" class="header">Buscar FACTURA </div>
                <div id="frmBusqueda">
                <form id="form_busqueda" name="form_busqueda" method="post" action="rejilla.php" target="frame_rejilla">
                    <table class="fuente8" width="100%" cellspacing=0 cellpadding=3 border=0>                    
                        <tr>
                            <td width="16%">Codigo de proveedor </td>
                            <td width="68%"><input id="codproveedor" type="text" class="cajaPequena" NAME="codproveedor" maxlength="10" value="<? echo $codproveedor?>"> <img src="http://www.forosdelweb.com/f18/img/ver.png" width="16" height="16" onClick="abreVentana()" title="Buscar proveedor" onMouseOver="style.cursor=cursor"> <img src="http://www.forosdelweb.com/f18/img/cliente.png" width="16" height="16" onClick="validarproveedor()" title="Validar proveedor" onMouseOver="style.cursor=cursor"></td>
                            <td width="5%">&nbsp;</td>
                            <td width="5%">&nbsp;</td>
                            <td width="6%" align="right"></td>
                        </tr>
                        <tr>
                            <td>Nombre</td>
                            <td><input id="nombre" name="nombre" type="text" class="cajaGrande" maxlength="45" value="<? echo $nombre?>"></td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                          <td>Num. Factura</td>
                          <td><input id="numfactura" type="text" class="cajaPequena" NAME="numfactura" maxlength="15" value="<? echo $numfactura?>"></td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                      </tr>
                        <tr>
                            <td>Estado</td>
                            <td><select id="cboEstados" name="cboEstados" class="comboMedio">
                                <option value="0" selected>Todos los estados</option>
                                <option value="1">Sin Pagar</option>
                                <option value="2">Pagada</option>            
                                </select></td>
                        </tr>
                      <tr>
                          <td>Fecha de inicio</td>
                          <td><input id="fechainicio" type="text" class="cajaPequena" NAME="fechainicio" maxlength="10" value="<? echo $fechainicio?>" readonly><img src="http://www.forosdelweb.com/f18/img/calendario.png" name="Image1" id="Image1" width="16" height="16" border="0" onMouseOver="this.style.cursor='pointer'" title="Calendario">
        <script type="text/javascript">
                    Calendar.setup(
                      {
                    inputField : "fechainicio",
                    ifFormat   : "%d/%m/%Y",
                    button     : "Image1"
                      }
                    );
        </script>    </td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                      </tr>
                        <tr>
                          <td>Fecha de fin</td>
                          <td><input id="fechafin" type="text" class="cajaPequena" NAME="fechafin" maxlength="10" value="<? echo $fechafin?>" readonly><img src="http://www.forosdelweb.com/f18/img/calendario.png" name="Image1" id="Image2" width="16" height="16" border="0" onMouseOver="this.style.cursor='pointer'" title="Calendario2">
        <script type="text/javascript">
                    Calendar.setup(
                      {
                    inputField : "fechafin",
                    ifFormat   : "%d/%m/%Y",
                    button     : "Image2"
                      }
                    );
        </script></td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                          <td>&nbsp;</td>
                      </tr>
                    </table>
              </div>
                 <div id="botonBusqueda">
                    <img src="http://www.forosdelweb.com/f18/img/botonbuscar.jpg" width="69" height="22" border="1" onClick="buscar()" onMouseOver="style.cursor=cursor">
                   <img src="http://www.forosdelweb.com/f18/img/botonlimpiar.jpg" width="69" height="22" border="1" onClick="limpiar()" onMouseOver="style.cursor=cursor">
                     <img src="http://www.forosdelweb.com/f18/img/botonnuevafactura.jpg" width="106" height="22" border="1" onClick="nueva_factura()" onMouseOver="style.cursor=cursor">                
                </div>
              <div id="lineaResultado">
              <table class="fuente8" width="80%" cellspacing=0 cellpadding=3 border=0>
                  <tr>
                <td width="50%" align="left">N de facturas encontradas <input id="filas" type="text" class="cajaPequena" NAME="filas" maxlength="5" readonly></td>
                <td width="50%" align="right">Mostradas <select name="paginas" id="paginas" onChange="paginar()">
                  </select></td>
              </table>
                </div>
                <div id="cabeceraResultado" class="header">
                    relacion de FACTURAS </div>
                <div id="frmResultado">
                <table class="fuente8" width="100%" cellspacing=0 cellpadding=3 border=0 ID="Table1">
                        <tr class="cabeceraTabla">
                            <td width="8%">ITEM</td>
                            <td width="12%">N. FACTURA</td>
                            <td width="30%">PROVEEDORES</td>
                            <td width="12%">IMPORTE</td>
                            <td width="10%">FECHA</td>
                            <td width="10%">ESTADO</td>
                            <td width="6%">&nbsp;</td>
                            <td width="6%">&nbsp;</td>
                            <td width="6%">&nbsp;</td>
                        </tr>
                </table>
                </div>
                <input type="hidden" id="iniciopagina" name="iniciopagina">
                <input type="hidden" id="cadena_busqueda" name="cadena_busqueda">
            </form>
                <div id="lineaResultado_pagos">
                    <iframe width="100%" height="250" id="frame_rejilla" name="frame_rejilla" frameborder="0">
                        <ilayer width="100%" height="250" id="frame_rejilla" name="frame_rejilla"></ilayer>
                    </iframe>
                    <iframe id="frame_datos" name="frame_datos" width="0" height="0" frameborder="0">
                    <ilayer width="0" height="0" id="frame_datos" name="frame_datos"></ilayer>
                    </iframe>
                    <table width="25%" border=0 align="right" cellpadding=3 cellspacing=0 class="fuente8">
        
               
              
                        
<?php
                      
$suma
=$row['suma'];
$iva= ($suma*$ivaimp)/100;
$total=$suma+$iva;
echo 
"<h3>";

?> 

     




<br />
Sub-Total ::::::: <? echo $simbolomoneda ?><?php  echo number_format($suma,2);?>  <br ><br >    
I.V.A <?php echo $ivaimp?>% :::::::: <? echo $simbolomoneda ?><?php  echo number_format($iva,2);?>  <br ><br >     
Total :::::::::::::::   <? echo $simbolomoneda ?><?php echo number_format($total,2);?>             


                    </table>
                    
                    
                    
                    
                </div>
            </div>
          </div>            
        </div>
    </body>
</html>