Ver Mensaje Individual
  #2 (permalink)  
Antiguo 19/12/2019, 13:34
marianomartelli
 
Fecha de Ingreso: agosto-2012
Ubicación: Barcelona
Mensajes: 243
Antigüedad: 11 años, 8 meses
Puntos: 1
Respuesta: Sumar totales de una busqueda que coincida

Cita:
Iniciado por marianomartelli Ver Mensaje
Buenos días,

Tengo el siguiente problema el que no se solucionarlo y no se si con php o javascript.

Tengo un programa que muestra en pantalla todas las facturas ingresadas, esto lo hace bien, lo que necesito es que cuando se realice una búsqueda, para una empresa en concreto, me de los totales de venta de esa empresa.
He puesto una sumatoria de total, que hace bien si muestra todas las facturas, pero al seleccionar un cliente, la sumatoria va mal.

Aquí el codigo

Código HTML:
Ver original
  1. <?php
  2.     include ('conexion.php');
  3.   $con=conectar();
  4.    
  5.    
  6.     $consulta="SELECT * FROM facturas ORDER by empresa";
  7.     $datos=mysqli_query($con, $consulta);
  8.    
  9.     $total = 0;
  10.     $empresa="";
  11.    
  12. ?>
  13.  
  14.  
  15. <!DOCTYPE html>
  16. <html lang="es">
  17.  
  18.      <head>
  19.      
  20.         <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
  21.        
  22.         <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximun-scale=1.0, minimum-scale=1.0">
  23.         <link rel="stylesheet" href="css/bootstrap.min.css">
  24.         <link rel="stylesheet" href="css/bootstrap-theme.css">
  25.         <link rel="stylesheet" href="css/dataTables.bootstrap.min.css">
  26.         <link rel="stylesheet" href="css/bootstrap-glyphicons.css">
  27.         <link rel="stylesheet" href="css/jquery.dataTables.min.css">
  28.        
  29.         <script src="js/jquery.js"></script>
  30.         <script src="js/bootstrap.min.js"></script>
  31.         <script src="js/jquery.dataTables.min.js"></script>
  32.         <script src="js/dataTables.bootstrap.min.js"></script> 
  33.        
  34.         <script>
  35.         $(document).ready(function () {
  36.         $('#mitabla').DataTable({
  37.            "order": [[2, "asc"]],
  38.            "language":{
  39.            "lengthMenu": "Mostrar _MENU_ registros por pagina",
  40.            "info": "Mostrando pagina _PAGE_ de _PAGES_",
  41.            "infoEmpty": "No hay registros disponibles",
  42.            "infoFiltered": "(filtrada de _MAX_ registros)",
  43.            "loadingRecords": "Cargando...",
  44.            "processing": "Procesando...",
  45.            "search": "Buscar:",
  46.            "zeroRecords": "No se encontraron registros coincidentes",
  47.            "paginate": {
  48.                "next":  "Siguiente",
  49.                "previous": "Anterior"
  50.                  },  
  51.               }        
  52.                
  53.            });
  54.        
  55.          });
  56.         </script>
  57.        
  58.          
  59.          
  60.        
  61.      
  62.          <title>Listado Facturas x clientes x pantalla</title>
  63.      </head>
  64.      
  65.      
  66.      <body>
  67.      
  68.      <div class="container">
  69.           <div><br></div>
  70.           <h2 style="text-align: center;">Listado de Facturas x Cliente</h2>
  71.          
  72.           <div class="row">
  73.               <a href="index.php" class="btn btn-info" role="button">Volver</a>
  74.           </div>
  75.    
  76.      
  77.      <br>
  78.      <div class="row table-responsive">
  79.        <table class="display" id="mitabla">
  80.           <thead>
  81.              <tr>
  82.          
  83.                 <th>Id</th>
  84.                     <th>Numero Factura</th>
  85.                     <th>Empresa</th>
  86.                     <th>Fecha factura</th>
  87.                     <th>Importe</th>
  88.                     <th>Total</th>
  89.                     <th>Modificar</th>
  90.                     <th>Eliminar</th>
  91.          
  92.              </tr>
  93.           </thead>
  94.          
  95.           <tbody>
  96.          
  97.          
  98.           <?php while($row = mysqli_fetch_array($datos))
  99.          {
  100.          
  101.            if( $row['empresa'] != '$empresa') {
  102.                
  103.    
  104.                     $total = $total+$row['total'];
  105.                     $valorgral= $total;  
  106.                    $valorgral=number_format($valorgral, 2, ',', '.');  
  107.            
  108.          
  109.          ?>
  110.          
  111.          
  112.          
  113.           <tr>
  114.            
  115.              <td><?php echo $row['id']; ?></td>
  116.              <td align="center"><?php echo $row['numfac']; ?></td>
  117.              <td><?php echo $row['empresa']; ?></td>
  118.              <td ><?php echo $row['fechafac']; ?></td>
  119.              <td><?php echo $row['total']; ?></td>
  120.              <td><?php echo $valorgral; ?></td>
  121.              <td><a href="modifpos1.php?id=<?php echo $row['id'];?>"><img src='iconos/44.png' /></a></td>
  122.              <td><a href="elimpos1.php?id=<?php echo $row['id'];?>"><img align=center  src='iconos/eliminar.png' /></a></td>
  123.          
  124.           </tr>
  125.          <?php  }}?>
  126.          
  127.          
  128.          
  129.           </tbody>
  130.      
  131.       </table>
  132.      
  133.       </div>
  134.      </div>
  135.  
  136.      
  137.      
  138.      </body>
  139.      
  140.  
  141.      
  142.  </html>


Hola a todos,

Ya solucioné el problema de los totales, ahora quiero agregar que me muestre el texto en Español y me muestre los totales con decimales, tengo el codigo, pero cada vez que lo quiero agregar me da error.

Este es el codigo que me muestra los totales y funciona
Código Javascript:
Ver original
  1. <script>
  2.      
  3.      
  4.         $(document).ready(function() {
  5.     $('#mitabla').DataTable( {
  6.          
  7.          
  8.        
  9.         "footerCallback": function ( row, data, start, end, display ) {
  10.             var api = this.api(), data;
  11.            
  12.          
  13.  
  14.             // Remove the formatting to get integer data for summation
  15.             var intVal = function ( i ) {
  16.                 return typeof i === 'string' ?
  17.                     i.replace(/[\$,]/g, '')*1 :
  18.                     typeof i === 'number' ?
  19.                         i : 0;
  20.             };
  21.            
  22.          
  23.  
  24.             // Total over all pages
  25.             total = api
  26.                 .column( 4 )
  27.                 .data()
  28.                 .reduce( function (a, b) {
  29.                     return intVal(a) + intVal(b);
  30.                 }, 0 );
  31.  
  32.             // Total over this page
  33.             pageTotal = api
  34.                 .column( 4, { page: 'current'} )
  35.                 .data()
  36.                 .reduce( function (a, b) {
  37.                     return intVal(a) + intVal(b);
  38.                 }, 0 );
  39.  
  40.             // Update footer
  41.             $( api.column( 4 ).footer() ).html(
  42.                 '$'+pageTotal +' ( €'+ total +' total)'
  43.                
  44.            
  45.             );
  46.         }
  47.     } );
  48. } );
  49.      
  50.       </script>

Ahora quiero agregar este otro codigo en esta tabla

Código Javascript:
Ver original
  1. "order": [[2, "asc"]],
  2.            "language":{
  3.             "decimal": ",",
  4.             "thousands": ".",
  5.            "lengthMenu": "Mostrar _MENU_ registros por pagina",
  6.            "info": "Mostrando pagina _PAGE_ de _PAGES_",
  7.            "infoEmpty": "No hay registros disponibles",
  8.            "infoFiltered": "(filtrada de _MAX_ registros)",
  9.            "loadingRecords": "Cargando...",
  10.            "processing": "Procesando...",
  11.            "search": "Buscar:",
  12.            "zeroRecords": "No se encontraron registros coincidentes",
  13.            
  14.            "paginate": {
  15.                "next":  "Siguiente",
  16.                "previous": "Anterior"
  17.                  },  
  18.               }


Si porfavor alguien me puede echar una mano donde debo agregar este código

Gracias y saludos