Help range field hour_date Mysql, AJAX


Good morning maybe someone can help me, I have the following problem: I'm running this query that allows me to get the value of the accuracy of the inventory, So far everything works well the query traps the data, but what I want is that by changing the range of the date the numbers vary according to income and sales that occur in that selected range, I really have no idea how to relate the field date_hours that I have in the tables entry and sale, I think that would be missing to add that functionality, I attach my code:

Consultas.php Model

public function exactitudinventario($fecha_inicio,$fecha_fin){

    $sql="SELECT (SELECT nombre FROM articulo WHERE idarticulo=dv.idarticulo) as articulo,
          IFNULL(dv.faltantes,0) faltantes,
          IFNULL(di.total_ingresos,0) - IFNULL(dv.total_salidas,0) - IFNULL(dv.faltantes,0) as total_inventario,
          (1-(IFNULL(dv.faltantes,0)/(IFNULL(di.total_ingresos,0) - IFNULL(dv.total_salidas,0) - IFNULL(dv.faltantes,0)))) as exactitud
          FROM articulo a 
          LEFT JOIN (SELECT idarticulo, SUM(cantidad) as total_ingresos FROM detalle_ingreso
                     GROUP BY idarticulo) di ON a.idarticulo=di.idarticulo
          LEFT JOIN (SELECT idarticulo, SUM(cantidad) as total_salidas, SUM(faltantes) as faltantes FROM detalle_venta
                     GROUP BY idarticulo) dv ON a.idarticulo=dv.idarticulo


        return ejecutarConsulta($sql);  

AJAX: consultas.php

    case 'exactitudinventario':

    //Vamos a declarar un array
    $data= Array();

    while ($reg=$rspta->fetch_object()){
    $results = array(
        "sEcho"=>1, //Información para el datatables
        "iTotalRecords"=>count($data), //enviamos el total registros al datatable
        "iTotalDisplayRecords"=>count($data), //enviamos el total registros a visualizar
    echo json_encode($results);


I look forward to your prompt help. Thanks.

What I want is that in my view to change the range of dates are modified according to the income or outputs that have been made in a certain range, So far performs the entire operation but does not change when changing the date is which is because the clause where date is missing but I do not know how to add Helpa

asked by Jherson OHuay 17.12.2018 в 15:05

0 answers