Primer version funcional

This commit is contained in:
Administrador Ibiza
2025-12-29 23:37:11 -06:00
commit 5289fd4133
294 changed files with 111418 additions and 0 deletions

152
views/houses/index.php Executable file
View File

@@ -0,0 +1,152 @@
<div class="row mb-4">
<div class="col-12">
<h2><i class="bi bi-building"></i> Gestión de Casas</h2>
<p class="text-muted">Administración del registro de propietarios</p>
</div>
</div>
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-dark">
<tr>
<th>Número</th>
<th>Estado</th>
<th>Consumo Only</th>
<th>Propietario</th>
<th>Email</th>
<th>Teléfono</th>
<th>Ver</th>
<?php if (Auth::isAdmin()): ?>
<th>Acciones</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php foreach ($houses as $house): ?>
<tr>
<td><strong><?= $house['number'] ?></strong></td>
<td>
<span class="badge <?= $house['status'] == 'activa' ? 'bg-success' : 'bg-secondary' ?>">
<?= $house['status'] == 'activa' ? 'Activa' : 'Deshabitada' ?>
</span>
</td>
<td>
<?php if ($house['consumption_only']): ?>
<span class="badge bg-warning" title="Solo consumo">Sí</span>
<?php else: ?>
<span class="text-muted">No</span>
<?php endif; ?>
</td>
<td><?= htmlspecialchars($house['owner_name'] ?? '-') ?></td>
<td><?= htmlspecialchars($house['owner_email'] ?? '-') ?></td>
<td><?= htmlspecialchars($house['owner_phone'] ?? '-') ?></td>
<td>
<a href="/dashboard.php?page=house_view&id=<?= $house['id'] ?>" class="btn btn-sm btn-info">
<i class="bi bi-eye"></i>
</a>
</td>
<?php if (Auth::isAdmin()): ?>
<td>
<button class="btn btn-sm btn-primary" onclick="editHouse(<?= $house['id'] ?>)">
<i class="bi bi-pencil"></i>
</button>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php if (Auth::isAdmin()): ?>
<div class="modal fade" id="houseModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Editar Casa</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form id="houseForm">
<div class="modal-body">
<input type="hidden" id="houseId" name="id">
<div class="mb-3">
<label class="form-label">Estado</label>
<select class="form-select" name="status" required>
<option value="activa">Activa</option>
<option value="deshabitada">Deshabitada</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Solo Consumo</label>
<select class="form-select" name="consumption_only">
<option value="0">No</option>
<option value="1">Sí (Descuento $100)</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">Propietario</label>
<input type="text" class="form-control" name="owner_name">
</div>
<div class="mb-3">
<label class="form-label">Email</label>
<input type="email" class="form-control" name="owner_email">
</div>
<div class="mb-3">
<label class="form-label">Teléfono</label>
<input type="text" class="form-control" name="owner_phone">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-primary">Guardar</button>
</div>
</form>
</div>
</div>
</div>
<script>
let housesData = <?= json_encode($houses) ?>;
function editHouse(id) {
const house = housesData.find(h => h.id === id);
if (house) {
document.getElementById('houseId').value = house.id;
document.querySelector('[name="status"]').value = house.status;
document.querySelector('[name="consumption_only"]').value = house.consumption_only;
document.querySelector('[name="owner_name"]').value = house.owner_name || '';
document.querySelector('[name="owner_email"]').value = house.owner_email || '';
document.querySelector('[name="owner_phone"]').value = house.owner_phone || '';
new bootstrap.Modal(document.getElementById('houseModal')).show();
}
}
document.getElementById('houseForm').addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const data = Object.fromEntries(formData.entries());
data.consumption_only = parseInt(data.consumption_only);
data.consumption_only = parseInt(data.consumption_only);
fetch('/dashboard.php?page=house_actions&action=save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
})
.then(r => r.json())
.then(result => {
if (result.success) {
Swal.fire('Éxito', 'Casa actualizada', 'success').then(() => location.reload());
} else {
Swal.fire('Error', result.message, 'error');
}
});
});
</script>
<?php endif; ?>

164
views/houses/view.php Executable file
View File

@@ -0,0 +1,164 @@
<div class="row mb-4">
<div class="col-12">
<a href="/dashboard.php?page=casas" class="btn btn-outline-secondary mb-2">
<i class="bi bi-arrow-left"></i> Volver a Casas
</a>
<h2><i class="bi bi-building"></i> Casa <?= $house['number'] ?></h2>
<p class="text-muted">Vista unificada de pagos y finanzas</p>
</div>
</div>
<div class="row mb-4">
<div class="col-md-3">
<div class="card">
<div class="card-header">Información</div>
<div class="card-body">
<p><strong>Número:</strong> <?= $house['number'] ?></p>
<p><strong>Estado:</strong>
<span class="badge <?= $house['status'] == 'activa' ? 'bg-success' : 'bg-secondary' ?>">
<?= $house['status'] == 'activa' ? 'Activa' : 'Deshabitada' ?>
</span>
</p>
<p><strong>Consumo Only:</strong>
<?= $house['consumption_only'] ? '<span class="badge bg-warning">Sí</span>' : 'No' ?>
</p>
<p><strong>Propietario:</strong> <?= htmlspecialchars($house['owner_name'] ?? '-') ?></p>
<p><strong>Email:</strong> <?= htmlspecialchars($house['owner_email'] ?? '-') ?></p>
<p><strong>Teléfono:</strong> <?= htmlspecialchars($house['owner_phone'] ?? '-') ?></p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card border-success">
<div class="card-body text-center">
<h6 class="text-muted">Total Pagado Agua (Histórico)</h6>
<h3 class="text-success">$<?= number_format($totalWaterPayments, 2) ?></h3>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card border-info">
<div class="card-body text-center">
<h6 class="text-muted">Total Conceptos</h6>
<h3 class="text-info">$<?= number_format($totalConceptPayments, 2) ?></h3>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card border-primary">
<div class="card-body text-center">
<h6 class="text-muted">Total General</h6>
<h3 class="text-primary">$<?= number_format($totalWaterPayments + $totalConceptPayments, 2) ?></h3>
</div>
</div>
</div>
</div>
<ul class="nav nav-tabs mb-4" id="houseTabs">
<li class="nav-item">
<button class="nav-link active" data-bs-toggle="tab" data-bs-target="#waterPayments">
<i class="bi bi-droplet-fill"></i> Pagos de Agua
</button>
</li>
<li class="nav-item">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#conceptPayments">
<i class="bi bi-collection"></i> Conceptos Especiales
</button>
</li>
<li class="nav-item">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#activityLog">
<i class="bi bi-clock-history"></i> Historial
</button>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="waterPayments">
<div class="card">
<div class="card-body">
<table class="table table-sm">
<thead>
<tr>
<th>Mes</th>
<th>Año</th>
<th>Monto</th>
<th>Fecha de Pago</th>
<th>Método</th>
</tr>
</thead>
<tbody>
<?php foreach ($waterPayments as $payment):
$expected = Payment::getExpectedAmount($house, $payment['year'], $payment['month']);
$statusClass = $payment['amount'] >= $expected ? 'paid' : 'pending';
?>
<tr>
<td><?= $payment['month'] ?></td>
<td><?= $payment['year'] ?></td>
<td class="<?= $statusClass ?>">$<?= number_format($payment['amount'], 2) ?></td>
<td><?= $payment['payment_date'] ? date('d/m/Y', strtotime($payment['payment_date'])) : '-' ?></td>
<td><?= htmlspecialchars($payment['payment_method'] ?? '-') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="tab-pane fade" id="conceptPayments">
<div class="card">
<div class="card-body">
<table class="table table-sm">
<thead>
<tr>
<th>Concepto</th>
<th>Monto</th>
<th>Fecha de Pago</th>
<th>Notas</th>
</tr>
</thead>
<tbody>
<?php foreach ($conceptPayments as $payment): ?>
<tr>
<td><?= htmlspecialchars($payment['concept_name']) ?></td>
<td>$<?= number_format($payment['amount'], 2) ?></td>
<td><?= $payment['payment_date'] ? date('d/m/Y', strtotime($payment['payment_date'])) : '-' ?></td>
<td><?= htmlspecialchars($payment['notes'] ?? '-') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<div class="tab-pane fade" id="activityLog">
<div class="card">
<div class="card-body">
<table class="table table-sm">
<thead>
<tr>
<th>Fecha</th>
<th>Acción</th>
<th>Detalles</th>
<th>Usuario</th>
</tr>
</thead>
<tbody>
<?php foreach ($activityLogs as $log): ?>
<tr>
<td><?= date('d/m/Y H:i', strtotime($log['created_at'])) ?></td>
<td><?= htmlspecialchars($log['action']) ?></td>
<td><?= htmlspecialchars($log['details'] ?? '-') ?></td>
<td><?= htmlspecialchars($log['username'] ?? '-') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>