177 lines
6.8 KiB
PHP
177 lines
6.8 KiB
PHP
<?php
|
|
require_once 'includes/session.php';
|
|
require_once 'db/config.php';
|
|
include_once 'includes/header.php';
|
|
|
|
$pdo = db();
|
|
|
|
// Handle deletion
|
|
if (isset($_GET['delete'])) {
|
|
$id = $_GET['delete'];
|
|
// TODO: Add check to see if there are expenses associated before deleting
|
|
$stmt = $pdo->prepare('DELETE FROM macro_areas WHERE id = ?');
|
|
$stmt->execute([$id]);
|
|
header("Location: macro_areas.php");
|
|
exit;
|
|
}
|
|
|
|
$stmt = $pdo->query('SELECT * FROM macro_areas ORDER BY nome ASC');
|
|
$macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
|
|
<div class="container-fluid">
|
|
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
|
<h1 class="h3 mb-0">Macro Áreas</h1>
|
|
<div>
|
|
<button id="printButton" class="btn btn-secondary btn-icon-split btn-sm">
|
|
<span class="icon text-white-50"><i data-lucide="file-text" style="color: #FFFFFF;"></i></span>
|
|
<span class="text">Imprimir Lista</span>
|
|
</button>
|
|
<a href="macro_area_form.php" class="btn btn-primary btn-icon-split">
|
|
<span class="icon text-white-50"><i data-lucide="plus" style="color: #FFFFFF;"></i></span>
|
|
<span class="text">Nova Macro Área</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow mb-4">
|
|
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
|
|
<h6 class="m-0 font-weight-bold text-primary">
|
|
<i data-lucide="layers" class="me-2" style="color: #005C53;"></i>Lista de Macro Áreas
|
|
</h6>
|
|
<div class="input-group" style="width: 250px;">
|
|
<span class="input-group-text text-slate-400"><i data-lucide="search"></i></span>
|
|
<input type="text" class="form-control" id="searchInput" placeholder="Buscar...">
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered table-sm" id="dataTable" width="100%" cellspacing="0">
|
|
<thead>
|
|
<tr>
|
|
<th>Nome</th>
|
|
<th>Descrição</th>
|
|
<th>Status</th>
|
|
<th style="width: 85px;">Ações</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tableBody">
|
|
<?php foreach ($macro_areas as $area):
|
|
$badgeClass = $area['ativo'] ? 'badge-status-ativo' : 'badge-status-arquivado';
|
|
$statusText = $area['ativo'] ? 'Ativo' : 'Arquivado';
|
|
?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($area['nome']); ?></td>
|
|
<td><?php echo htmlspecialchars($area['descricao']); ?></td>
|
|
<td>
|
|
<span class="badge <?php echo $badgeClass; ?>"><?php echo $statusText; ?></span>
|
|
</td>
|
|
<td>
|
|
<div class="d-flex">
|
|
<a href="macro_area_form.php?id=<?php echo $area['id']; ?>" class="btn btn-sm">
|
|
<i data-lucide="edit" style="color: #4C5958;"></i>
|
|
</a>
|
|
<a href="macro_areas.php?delete=<?php echo $area['id']; ?>" class="btn btn-sm" onclick="return confirm('Tem certeza que deseja excluir este item?');">
|
|
<i data-lucide="trash-2" style="color: #4C5958;"></i>
|
|
</a>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($macro_areas)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center">Nenhuma macro área encontrada.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include_once 'includes/footer.php'; ?>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Search functionality
|
|
const searchInput = document.getElementById('searchInput');
|
|
const tableBody = document.getElementById('tableBody');
|
|
const tableRows = tableBody.getElementsByTagName('tr');
|
|
|
|
searchInput.addEventListener('keyup', function() {
|
|
const searchTerm = searchInput.value.toLowerCase();
|
|
|
|
for (let i = 0; i < tableRows.length; i++) {
|
|
const row = tableRows[i];
|
|
const cells = row.getElementsByTagName('td');
|
|
let match = false;
|
|
// Start search from the first cell, and not the last one (actions)
|
|
for (let j = 0; j < cells.length - 1; j++) {
|
|
if (cells[j]) {
|
|
if (cells[j].textContent.toLowerCase().indexOf(searchTerm) > -1) {
|
|
match = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (match) {
|
|
row.style.display = '';
|
|
} else {
|
|
row.style.display = 'none';
|
|
}
|
|
}
|
|
});
|
|
|
|
// Print functionality
|
|
const printButton = document.getElementById('printButton');
|
|
printButton.addEventListener('click', function() {
|
|
fetch('print_macro_areas.php')
|
|
.then(response => response.text())
|
|
.then(html => {
|
|
const printWindow = window.open('', '_blank');
|
|
printWindow.document.write(html);
|
|
printWindow.document.close();
|
|
printWindow.focus(); // Required for some browsers
|
|
|
|
// Use a small timeout to ensure content is loaded before printing
|
|
setTimeout(() => {
|
|
printWindow.print();
|
|
}, 250);
|
|
|
|
printWindow.addEventListener('afterprint', () => {
|
|
printWindow.close();
|
|
});
|
|
})
|
|
.catch(error => console.error('Error fetching print content:', error));
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<style>
|
|
.input-group-text {
|
|
background-color: #fff;
|
|
border-right: 0;
|
|
}
|
|
#searchInput {
|
|
border-left: 0;
|
|
}
|
|
.btn-sm i[data-lucide] {
|
|
width: 18px;
|
|
height: 18px;
|
|
}
|
|
/* Custom styles for status badges */
|
|
.badge-status-ativo {
|
|
background-color: #d1e7dd; /* Light green */
|
|
color: #0f5132; /* Dark green */
|
|
border: 1px solid #badbcc;
|
|
}
|
|
|
|
.badge-status-arquivado {
|
|
background-color: #f8d7da; /* Light red */
|
|
color: #842029; /* Dark red */
|
|
border: 1px solid #f5c2c7;
|
|
}
|
|
</style>
|