<?php
    require('../conexion.php');
    
    $from_date = $_POST['from_date'];
    $to_date = $_POST['to_date'];
    $i=0;

    $result = query("SELECT IFNULL(SUM(pdn.pdn_cantidad),0) cant_productos,
        IFNULL(SUM(pdn.pdn_cantidad * pdn.pdn_precio),0) total FROM productos_nota AS pdn 
        INNER JOIN productos AS pd ON pd.id = pdn.id_producto
        INNER JOIN notas_venta AS nv ON nv.id = pdn.id_nota_venta
        INNER JOIN usuarios AS us ON us.id = pdn.id_cocinero
        WHERE nv.ntv_fecha_creacion BETWEEN '$from_date' AND '$to_date' 
        AND pdn.pdn_estatus NOT IN('eliminado', 'cancelado') 
        AND nv.ntv_estatus IN ('finalizado','impreso');");
        
    while($row = mysqli_fetch_assoc($result)){
        $rowdata[$i] = $row;
        $i++;
    }

    if ($i>0){
        $res =  json_encode($rowdata,JSON_UNESCAPED_UNICODE);
    } else {
        $res =  '[{"id":"0"}]';	
    }
    echo $res;
?>