format('Y-m-d 00:00:00'); $params_asesoras[] = $fecha_fin_obj->format('Y-m-d 23:59:59'); } if (!empty($where_clauses_asesoras)) { $sql_asesoras .= " WHERE " . implode(' AND ', $where_clauses_asesoras); } $sql_asesoras .= " GROUP BY u.id, u.nombre_asesor ORDER BY monto_total DESC"; $stmt_asesoras = $pdo->prepare($sql_asesoras); $stmt_asesoras->execute($params_asesoras); $asesoras_summary = $stmt_asesoras->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { error_log("Error en RESUMEN POR ASESORA: " . $e->getMessage()); } // --- RANKING DE PRODUCTOS --- $productos_ranking = []; try { $sql_productos = " SELECT p.producto AS producto_nombre, SUM(p.cantidad) AS total_ventas, SUM(p.monto_total) AS monto_total FROM pedidos p "; $where_clauses_productos = ["p.estado LIKE 'COMPLETADO%'"]; $params_productos = []; if ($fecha_inicio_obj && $fecha_fin_obj) { $where_clauses_productos[] = "p.created_at BETWEEN ? AND ?"; $params_productos[] = $fecha_inicio_obj->format('Y-m-d 00:00:00'); $params_productos[] = $fecha_fin_obj->format('Y-m-d 23:59:59'); } if (!empty($where_clauses_productos)) { $sql_productos .= " WHERE " . implode(' AND ', $where_clauses_productos); } $sql_productos .= " GROUP BY p.producto ORDER BY total_ventas DESC"; $stmt_productos = $pdo->prepare($sql_productos); $stmt_productos->execute($params_productos); $productos_ranking = $stmt_productos->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { error_log("Error en RANKING DE PRODUCTOS: " . $e->getMessage()); } include 'layout_header.php'; ?>
| Asesora | Total Pedidos | Monto Total | Promos Vendidas | Resumen de Productos | ||
|---|---|---|---|---|---|---|
| No hay datos disponibles para el rango seleccionado. | ||||||
| = htmlspecialchars($summary['asesora_nombre']) ?> | = $summary['total_pedidos'] ?> | S/ = number_format($summary['monto_total'], 2) ?> |
';
echo '| Tipo de Promo | Producto | Unidades | |
| ' . htmlspecialchars($promo_key) . ' (' . $rowspan . ' pedidos) | '; $first_row = false; } echo '' . htmlspecialchars($pedido_item['producto']) . ' | '; echo '' . $pedido_item['cantidad'] . ' | '; echo '||||
| Producto | Total Ventas | Monto Total |
|---|---|---|
| No hay datos disponibles para el rango seleccionado. | ||
| = htmlspecialchars($producto['producto_nombre']) ?> | = $producto['total_ventas'] ?> | S/ = number_format($producto['monto_total'], 2) ?> |