Files
ibiza_sistema/models/MonthlyBill.php
Administrador Ibiza 0858a9c9cd feat: Implementar página dedicada de gráficos para análisis de pagos de agua
- Crear nueva página /graficos con 4 tipos de gráficos interactivos
- Agregar compatibilidad con tema oscuro en selectores
- Implementar exportación a PDF profesional con encabezados
- Agregar campo 'Monto Real del Recibo' a configuración mensual
- Crear migración para nueva columna real_amount en monthly_bills
- Mejorar filtros con botones interactivos en lugar de select múltiple
- Agregar resumen ejecutivo con estadísticas detalladas
- Optimizar espacio visual y responsividad de gráficos
- Integrar Chart.js y jsPDF para funcionalidad avanzada
- Corregir problemas de carga de datos y filtros dinámicos
2026-01-03 22:23:05 -06:00

91 lines
2.8 KiB
PHP
Executable File

<?php
class MonthlyBill {
public static function getYear($year) {
$db = Database::getInstance();
$months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];
$result = [];
foreach ($months as $month) {
$bill = $db->fetchOne(
"SELECT * FROM monthly_bills WHERE year = ? AND month = ?",
[$year, $month]
);
$result[$month] = $bill;
}
return $result;
}
public static function save($data) {
$db = Database::getInstance();
$activeHouses = House::countActive();
if (isset($data['amount_per_house']) && !empty($data['amount_per_house'])) {
$amountPerHouse = $data['amount_per_house'];
} else {
$amountPerHouse = round($data['total_amount'] / $activeHouses, 2);
}
$existing = $db->fetchOne(
"SELECT id FROM monthly_bills WHERE year = ? AND month = ?",
[$data['year'], $data['month']]
);
if ($existing) {
$db->execute(
"UPDATE monthly_bills SET total_amount = ?, amount_per_house = ?, real_amount = ?, due_date = ? WHERE id = ?",
[
$data['total_amount'],
$amountPerHouse,
$data['real_amount'] ?? null,
$data['due_date'] ?? null,
$existing['id']
]
);
return $existing['id'];
} else {
$db->execute(
"INSERT INTO monthly_bills (year, month, total_amount, amount_per_house, real_amount, due_date)
VALUES (?, ?, ?, ?, ?, ?)",
[
$data['year'],
$data['month'],
$data['total_amount'],
$amountPerHouse,
$data['real_amount'] ?? null,
$data['due_date'] ?? null
]
);
return $db->lastInsertId();
}
}
public static function updatePayments($year, $month) {
$db = Database::getInstance();
$bill = $db->fetchOne(
"SELECT * FROM monthly_bills WHERE year = ? AND month = ?",
[$year, $month]
);
if (!$bill) {
return false;
}
$houses = House::getActive();
foreach ($houses as $house) {
$monto_esperado = $bill['amount_per_house'];
if ($house['consumption_only'] && $year >= 2025) {
$monto_esperado = max(0, $monto_esperado - 100.00);
}
}
return true;
}
}