Ir al contenido


Foto

sumar datos ubicados en fechas consecutivas


  • Por favor identifícate para responder
4 respuestas en este tema

#1 vasquez

vasquez

    Member

  • Miembros
  • PipPip
  • 14 mensajes

Escrito 15 mayo 2012 - 05:54

Hola. Tengo un formulario mediante el cual registro  ventas durante un periodo de tiempo de 7 días. El asunto es que tengo que generar un reporte en el que se despliegan las cantidades vendidas durante ese periodo y al final se suman esas cantidades. El formulario está en html. He intentado usando dos archivos llamados por el formulario; en el primero llamado reporte_semanal_ventas.php, hay dos campos en los cuales introduzco la fecha y un numero que corresponde al id de esa fecha. al darle buscar me envía a  reporte_ventas, que es donde se efectúan las operaciones, pero solo logro desplegar un registro, y el objetivo es que se desplieguen los 7 registros y al final se sumen las ventas de esos registros. No se como agrupar ese rango de fechas y luego sumar sus datos. Mi problema es como llamarlos.  Les adjunto los archivos. Gracias.

reporte_semanal_ventas.php

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <head><title>
busqueda lote
</title>
<link  rel="stylesheet"      href="../herramientas/calendario/system.css"/>
        <script type="text/javascript" src="../herramientas/calendario/zapatec.js"></script>
        <script type="text/javascript" src="../herramientas/calendario/calendar.js"></script>
        <script type="text/javascript" src="../herramientas/calendario/calendar-es.js"></script>

<link rel="Stylesheet" href="estilos/formscss.css">
</head>

<body class="cuerpo12">
<form name="formulario_busqueda_lote" method="post" action="reporte_ventas.php">
<table align="center">
<tr >
<td>INGRESE NUMERO SEMANA
</td>
  <!--<td align="center"><input name="semana" class="estil_cajota" type='text'  title='Destino'></td>-->
    <td>
<select name="id_ventas" id="ventas" title='ventas' class="estilo_caja"  >
<option value='0'> </option>
<?php
include 'conexion.php';
$sql = "select fec_venta from ventas where id_ventas >=1 and id_ventas<=7";
                                $result = mysql_query("$sql");
                                $row = mysql_fetch_array($result);

$consulta=mysql_query("SELECT * FROM ventas");
while($registro=mysql_fetch_row($consulta))
{
    echo "<option class='uno'>".$registro[0]."</option>";

}
mysql_close($conectar);
?>
</select>
</td>


<td>

</td>
<td>
</td>

      <td  valign="middle" align="center"><input id="fch_venta1" class="estil_caja" name="fch_venta1" class="campo_fcha" type="text"
        size ="13%"  title='Fecha venta1' readonly>
<img id='btn_fch_venta1' title="Calendario para Seleccionar la fecha de venta" 
src='../herramientas/calendario/calendario_1.gif' border='0' style="cursor:pointer" >
</td>



<td><input name="boton" type="submit" value="buscar"></td>
</tr>
</table>
</form>

<script type="text/javascript">
Zapatec.Calendar.setup({
weekNumbers : false,
showOthers : true,
showsTime : false,
step : 1,
electric : true,
inputField : "fch_venta1",
button : "btn_fch_venta1",
timeFormat : 24,
timeInterval : 05,
ifFormat : '%Y-%m-%d',
daFormat : '%Y-%m-%d'
  });
</script>


</body>
</html>



Reporte_ventas.php

<?php
$fecha1=$_POST["fch_venta1"];
$id_ventas =$_POST["id_ventas"];
$huevosA =$_POST["huevosA"];
$precio_unitarioA =$_POST["precio_unitarioA"];
$subtotalA =$_POST["subtotalA"];
$huevosAA =$_POST["huevosAA"];
$precio_unitarioAA =$_POST["precio_unitarioAA"];
$subtotalAA =$_POST["subtotalAA"];
$huevosAAA =$_POST["huevosAAA"];
$precio_unitarioAAA =$_POST["precio_unitarioAAA"];
$subtotalAAA =$_POST["subtotalAAA"];
$huevos_super =$_POST["huevos_super"];
$precio_unitarioSUPER =$_POST["precio_unitarioSUPER"];
$subtotal_super =$_POST["subtotal_super"];
$descarte  =$_POST["descarte"];
$precio_unitarioDESCARTE  =$_POST["precio_unitarioDESCARTE"];
$subtotal_descarte =$_POST["subtotal_descarte"];
$total =$_POST["total"];
$conectar= mysql_connect("localhost","root","sena");
mysql_select_db("tecnoavicola19",$conectar);


$resultado = mysql_query("SELECT ventas.id_ventas,fch_venta,huevosA,precio_unitarioA,subtotalA,huevosAA,precio_unitarioAA,subtotalAA,huevosAAA,precio_unitarioAAA,subtotalAAA,
                          huevos_super,precio_unitarioSUPER,subtotal_super,descarte,precio_unitarioDESCARTE,subtotal_descarte,total FROM ventas WHERE(ventas.id_ventas='$id_ventas' AND fch_venta='$fecha1')",$conectar) or die (mysql_error()) ;
 
{

echo"
<table width='180' height='200' align='center' cellspacing='0' border='1'  cellpadding='0'>
       
  <td align='right' width='9%' height='100' valign='top'><img src='../imagenes/SENA.gif' width='167' height='200' alt='gif' >
  </td>
  <td align='left' valign='top'><img src='../imagenes/logo4.png' width='765' height='200' alt='gif'></td>";

echo"</table><BR>";

echo"
<table width='100%' bgcolor='#5F9EA0' border='0'>
<td align='center'><h3>Reporte de Ventas</h3></td>";
echo"</table>";
echo "
<table width='100%' bgcolor='#5F9EA0' border='1'>
<tr>
<td align='center'>Fecha</td>
<td align='center'>Dia</td>
<td align='center'>Huevos A</td>
<td align='center'>Huevos AA</td>
<td align='center'>Huevos AAA</td>
<td align='center'>Huevos Super</td>
<td align='center'>Descarte</td>

</tr>";


$sum_huevosA = $sum_huevosA    $fila[total_huevosA];
    $sum_huevosAA = $sum_huevosAA    $fila[total_huevosAA];
    $sum_huevosAAA = $sum_huevosAAA    $fila[total_huevosAAA];
    $sum_huevos_super = $sum_huevos_super    $fila[total_super];
    $sum_descarte = $sum_descarte    $fila[total_descarte];
    $sum_subtotalA = $sum_subtotalA  $fila[subtotalA];
    $sum_subtotalAA = $sum_subtotalAA  $fila[subtotalAA];
    $sum_subtotalAAA = $sum_subtotalAAA  $fila[subtotalAAA];
    $sum_subtotal_super = $sum_subtotal_super  $fila[subtotal_super];
    $sum_subtotal_descarte= $sum_subtotal_descarte $fila[subtotal_descarte];
    $Total_total=$sum_subtotalA  $sum_subtotalAA  $sum_subtotalAAA  $sum_subtotalAAA  $sum_subtotal_descarte;



//Contador lineas (registros)
$numreg = 0;

while($fila = mysql_fetch_array($resultado))

{




echo"
   

<tr>
    <td align='center'>$fila[fch_venta]</td>
<td align='center'>$fila[id_ventas]</td>
<td align='center'>$fila[huevosA]</td>
<td align='center'>$fila[huevosAA]</td>
<td align='center'>$fila[huevosAAA]</td>
<td align='center'>$fila[huevos_super]</td>
<td align='center'>$fila[descarte]</td>

</tr>";





    echo "</table>";




mysql_close($conectar);

}
}
exit;
?>


(y)
  • 0

#2 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 15 mayo 2012 - 06:18

A ver, es un rango de fechas o es sólo una fecha?., porque si es un rango debes especificar la fecha final, por eso antes de seguir debes confirmarnos ese dato.

Saludos.
  • 0

#3 vasquez

vasquez

    Member

  • Miembros
  • PipPip
  • 14 mensajes

Escrito 18 mayo 2012 - 09:40

Hola. Gracias por atender. La consulta se efectúa en un rango de fechas, o sea una fecha inicial y una final. Los datos que están guardados en la base de datos, ocupan un espacio de tiempo de un año. Requiero poder tomar los datos ubicados en un espacio de tiempo de una semana, a partir del primer día de ingreso. O sea en un año debo poder hacer 52 consultas, que es el número de semanas que tiene un año..
Gracias.
  • 0

#4 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 19 mayo 2012 - 10:36

A ver si te entendi, quieres mostrar los valores agrupado por semana del año?.
  • 0

#5 vasquez

vasquez

    Member

  • Miembros
  • PipPip
  • 14 mensajes

Escrito 21 mayo 2012 - 10:56

Muchas gracias por responder. En la base de datos se ingresan 365 ventas, o sea una venta por dia. Mi deseo es poder reunir las ventas en grupos de 7 días, o sea los días de una semana. Como en el año hay 52 semanas, requiero poder hacer 52 reportes por año. Esto se realizaría desde la fecha en que se registre la primea venta. He logrado algo: para efectuar la consulta en el ' reporte_semanal_ventas.php', introduzco el número del lote, pero me aparece con una serie de errores, y si habilito la fecha en $resultado, solo me permite ver la venta de ese día  y como te digo quiero poder ver las ventas de los 7 días siguientes a la fecha de primera venta, y en ese mismo reporte poder sumar las cantidades tanto de huevos vendidos como de sus valores. No se como hacer la consulta para agrupar los 7 días en un solo reporte.
Adjunto el nuevo código:
reporte_semanal_ventas.php


<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <head><title>
busqueda lote
</title>
<link  rel="stylesheet"      href="../herramientas/calendario/system.css"/>
        <script type="text/javascript" src="../herramientas/calendario/zapatec.js"></script>
        <script type="text/javascript" src="../herramientas/calendario/calendar.js"></script>
        <script type="text/javascript" src="../herramientas/calendario/calendar-es.js"></script>

<link rel="Stylesheet" href="estilos/formscss.css">
</head>

<body class="cuerpo12">
<form name="formulario_busqueda_lote" method="post" action="reporte_ventas.php">
<table align="center">
<tr >
<td>INGRESE NUMERO LOTE
</td>
  <!--<td align="center"><input name="id_ventas" class="estil_cajota" type='text'  title='Destino'></td>-->
    <td>
<select name="id_lote" id="id_lote" title='lote' class="estilo_caja"  >
<option value='0'> </option>
<?php
include 'conexion.php';
$consulta=mysql_query("SELECT * FROM lote");
while($registro=mysql_fetch_row($consulta))
{
    echo "<option class='uno'>".$registro[0]."</option>";

}
mysql_close($conectar);
?>
</select>
</td>-->
   

<td>

</td>
<td>
</td>

      <td  valign="middle" align="center"><input id="fch_venta1" class="estil_caja" name="fch_venta1" class="campo_fcha" type="text"
        size ="13%"  title='Fecha venta1' readonly>
<img id='btn_fch_venta1' title="Calendario para Seleccionar la fecha de venta" 
src='../herramientas/calendario/calendario_1.gif' border='0' style="cursor:pointer" >
</td>



<td><input name="boton" type="submit" value="buscar"></td>
</tr>
</table>
</form>

<script type="text/javascript">
Zapatec.Calendar.setup({
weekNumbers : false,
showOthers : true,
showsTime : false,
step : 1,
electric : true,
inputField : "fch_venta1",
button : "btn_fch_venta1",
timeFormat : 24,
timeInterval : 05,
ifFormat : '%Y-%m-%d',
daFormat : '%Y-%m-%d'
  });
</script>


</body>
</html>


reporte_ventas.php


<?php
$fecha1=$_POST["fch_venta1"];
$id_lote =$_POST["id_lote"];
$huevosA =$_POST["huevosA"];
$precio_unitarioA =$_POST["precio_unitarioA"];
$subtotalA =$_POST["subtotalA"];
$huevosAA =$_POST["huevosAA"];
$precio_unitarioAA =$_POST["precio_unitarioAA"];
$subtotalAA =$_POST["subtotalAA"];
$huevosAAA =$_POST["huevosAAA"];
$precio_unitarioAAA =$_POST["precio_unitarioAAA"];
$subtotalAAA =$_POST["subtotalAAA"];
$huevos_super =$_POST["huevos_super"];
$precio_unitarioSUPER =$_POST["precio_unitarioSUPER"];
$subtotal_super =$_POST["subtotal_super"];
$descarte  =$_POST["descarte"];
$precio_unitarioDESCARTE  =$_POST["precio_unitarioDESCARTE"];
$subtotal_descarte =$_POST["subtotal_descarte"];
$total =$_POST["total"];

$conectar= mysql_connect("localhost","root","sena");
mysql_select_db("tecnoavicola19",$conectar);
$resultado = mysql_query("SELECT ventas.id_lote,fch_venta,huevosA,precio_unitarioA,subtotalA,huevosAA,precio_unitarioAA,subtotalAA,huevosAAA,precio_unitarioAAA,subtotalAAA,
                          huevos_super,precio_unitarioSUPER,subtotal_super,descarte,precio_unitarioDESCARTE,subtotal_descarte,total FROM ventas WHERE(ventas.id_lote='$id_lote' AND fch_venta='$fecha1'  )",$conectar) or die (mysql_error()) ;  
{
echo"
<table width='180' height='200' align='center' cellspacing='0' border='1'  cellpadding='0'>
       
  <td align='right' width='9%' height='100' valign='top'><img src='../imagenes/SENA.gif' width='167' height='200' alt='gif' >
  </td>
  <td align='left' valign='top'><img src='../imagenes/logo4.png' width='765' height='200' alt='gif'></td>";
echo"</table><BR>";
echo"
<table width='100%'  border='0'>
<td align='center'><h3>Reportes de Ventas</h3></td>";
echo"</table>";
echo "
<table width='100%' bgcolor='#5F9EA0' border='1'>
<tr>
<td align='center'>Fecha</td>
<td align='center'>Lote</td>
<td align='center'>Huevos A</td>
<td align='center'>Huevos AA</td>
<td align='center'>Huevos AAA</td>
<td align='center'>Huevos Super</td>
<td align='center'>Descarte</td>

</tr>";
$sum_huevosA = $sum_huevosA    $fila[total_huevosA];
    $sum_huevosAA = $sum_huevosAA    $fila[total_huevosAA];
    $sum_huevosAAA = $sum_huevosAAA    $fila[total_huevosAAA];
    $sum_huevos_super = $sum_huevos_super    $fila[total_super];
    $sum_descarte = $sum_descarte    $fila[total_descarte];
    $sum_subtotalA = $sum_subtotalA  $fila[subtotalA];
    $sum_subtotalAA = $sum_subtotalAA  $fila[subtotalAA];
    $sum_subtotalAAA = $sum_subtotalAAA  $fila[subtotalAAA];
    $sum_subtotal_super = $sum_subtotal_super  $fila[subtotal_super];
    $sum_subtotal_descarte= $sum_subtotal_descarte $fila[subtotal_descarte];
    $Total_total=$sum_subtotalA  $sum_subtotalAA  $sum_subtotalAAA  $sum_subtotalAAA  $sum_subtotal_descarte;
//Contador lineas (registros)
$numreg = 0;

while($fila = mysql_fetch_array($resultado))

{
echo"
    <tr>
    <td align='center'>$fila[fch_venta]</td>
<td align='center'>$fila[id_lote]</td>
<td align='center'>$fila[huevosA]</td>
<td align='center'>$fila[huevosAA]</td>
<td align='center'>$fila[huevosAAA]</td>
<td align='center'>$fila[huevos_super]</td>
<td align='center'>$fila[descarte]</td>

</tr>";
switch ($fila[fch_venta])
{
case '1':
$sum_TP_1 = $sum_TP_1  $fila[fch_venta];
break;
case '2':
$sum_TP_2 = $sum_TP_2  $fila[fch_venta];
break;
case '3':
$sum_TP_3 = $sum_TP_3  $fila[fch_venta];
break;
case '4':
$sum_TP_4 = $sum_TP_4  $fila[fch_venta];
break;
case '5':
$sum_TP_5 = $sum_TP_5  $fila[fch_venta];
break;
case '6':
$sum_TP_6 = $sum_TP_6  $fila[fch_venta];
default:
break;
case '7':
$sum_TP_7 = $sum_TP_7  $fila[total_primera];
}
//incrementamos en uno por cada iteración del bucle while
  $numreg;
    echo "</table>";
mysql_close($conectar);
}
}
exit;
?>
<p align="center">
<input id="registro" name="Imprimir" type="button" value="imprimir" style='cursor:pointer' onClick="window.print()"></td></tr>
<input id="reporte ventas"  class="boton" name="reporte ventas" type="button" value="Reporte de Ventas" style='cursor:pointer' onclick="location.href='formulario_ventas.php';" />
</p>

  • 0




IP.Board spam blocked by CleanTalk.