🌹🏠🌹？》《》？《》？<?php
include "../include/inicio.php";

set_time_limit(0);

//tomo la grilla filtrada
$filtrada = $_SESSION['grilla']['HR_mes']['sqlFiltrada'];

if(!$filtrada)$filtrada = $sqlDatos;

$partes = sql2array($filtrada);

$nuevoFrom = $partes['from'];
//$sqlNuevo = "SELECT SUM(bultos) bultos,SUM(bultos_PLD) bultos_PLD 
//               FROM ".$nuevoFrom." WHERE ".$partes['where'];
$cant_viajes = 0;
$sqlNuevo = "SELECT a.hruta_d
               FROM {$db->base_wms}hoja_ruta a, {$db->base_wms}hoja_ruta_det b
              WHERE a.hruta_d = b.hruta_d
                AND empresa = '{$_SESSION['empresa_login']}' 
                AND year(a.fecha)  = '{$_REQUEST['anio']}' 
                AND month(a.fecha) = '{$_REQUEST['mes']}'
                AND b.estado_rm != 'N'
                AND b.tdoc = 'RTO'
                group by a.hruta_d";
$resultado = $db->resultado($sqlNuevo);
foreach($resultado as $hr){
    $cant_viajes++;
}

$sqlNuevo = "SELECT SUM(b.bultos) bultos,
                    SUM(b.unidades) unidades, 
                    SUM(b.volumen) volumen
               FROM {$db->base_wms}hoja_ruta a, {$db->base_wms}hoja_ruta_det b
              WHERE a.hruta_d = b.hruta_d
                AND empresa = '{$_SESSION['empresa_login']}' 
                AND year(a.fecha)  = '{$_REQUEST['anio']}' 
                AND month(a.fecha) = '{$_REQUEST['mes']}'
                AND b.estado_rm != 'N'
                AND b.tdoc = 'RTO' ";
$resultado=$db->campos($sqlNuevo);
                
$cant_bultos = number_format( (float)$resultado['bultos'], 0);
$cant_unidades = number_format( (float)$resultado['unidades'], 0);
$cant_volumen = number_format( (float)$resultado['volumen'], 2);
                                                          
echo $cant_bultos."@".$cant_unidades."@".$cant_volumen."@".$cant_viajes;

?>
