versao 15
This commit is contained in:
parent
9fcffa06dc
commit
6e8e69c52f
41
delete_macro_area.php
Normal file
41
delete_macro_area.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'includes/session.php';
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||||
|
header('Location: macro_areas.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $_GET['id'];
|
||||||
|
$pdo = db();
|
||||||
|
|
||||||
|
// Get the slug of the macro area
|
||||||
|
$stmt = $pdo->prepare('SELECT slug FROM macro_areas WHERE id = ?');
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
$macro_area = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
if (!$macro_area) {
|
||||||
|
$_SESSION['error_message'] = 'Macro área não encontrada.';
|
||||||
|
header('Location: macro_areas.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$slug = $macro_area['slug'];
|
||||||
|
|
||||||
|
// Check for associated expenses (categories)
|
||||||
|
$stmt = $pdo->prepare('SELECT COUNT(*) FROM expenses WHERE category = ?');
|
||||||
|
$stmt->execute([$slug]);
|
||||||
|
$count = $stmt->fetchColumn();
|
||||||
|
|
||||||
|
if ($count > 0) {
|
||||||
|
$_SESSION['error_message'] = 'Não é possível excluir a macro área, pois existem despesas associadas a ela.';
|
||||||
|
} else {
|
||||||
|
// Delete the macro area
|
||||||
|
$stmt = $pdo->prepare('DELETE FROM macro_areas WHERE id = ?');
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
$_SESSION['success_message'] = 'Macro área excluída com sucesso.';
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: macro_areas.php');
|
||||||
|
exit;
|
||||||
@ -85,7 +85,7 @@ include_once 'includes/header.php';
|
|||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="card shadow mb-4">
|
||||||
<div class="card-header py-3">
|
<div class="card-header py-3">
|
||||||
<h6 class="m-0 font-weight-bold text-primary">Detalhes da Macro Área</h6>
|
<h6 class="m-0 font-weight-bold" style="color: #005C53;">Detalhes da Macro Área</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form id="macroAreaForm" method="POST" action="macro_area_form.php<?php echo !empty($macro_area['id']) ? '?id='.$macro_area['id'] : ''; ?>">
|
<form id="macroAreaForm" method="POST" action="macro_area_form.php<?php echo !empty($macro_area['id']) ? '?id='.$macro_area['id'] : ''; ?>">
|
||||||
|
|||||||
@ -5,16 +5,6 @@ include_once 'includes/header.php';
|
|||||||
|
|
||||||
$pdo = db();
|
$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');
|
$stmt = $pdo->query('SELECT * FROM macro_areas ORDER BY nome ASC');
|
||||||
$macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
@ -24,7 +14,7 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
||||||
<h1 class="h3 mb-0">Macro Áreas</h1>
|
<h1 class="h3 mb-0">Macro Áreas</h1>
|
||||||
<div>
|
<div>
|
||||||
<button id="printButton" class="btn btn-secondary btn-icon-split btn-sm">
|
<button id="printButton" class="btn btn-secondary btn-icon-split">
|
||||||
<span class="icon text-white-50"><i data-lucide="file-text" style="color: #FFFFFF;"></i></span>
|
<span class="icon text-white-50"><i data-lucide="file-text" style="color: #FFFFFF;"></i></span>
|
||||||
<span class="text">Imprimir Lista</span>
|
<span class="text">Imprimir Lista</span>
|
||||||
</button>
|
</button>
|
||||||
@ -35,10 +25,26 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php if (isset($_SESSION['success_message'])): ?>
|
||||||
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||||
|
<?php echo $_SESSION['success_message']; ?>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<?php unset($_SESSION['success_message']); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (isset($_SESSION['error_message'])): ?>
|
||||||
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||||
|
<?php echo $_SESSION['error_message']; ?>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<?php unset($_SESSION['error_message']); ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="card shadow mb-4">
|
||||||
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
|
<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">
|
<h6 class="m-0 font-weight-bold" style="color: #005C53;">
|
||||||
<i data-lucide="layers" class="me-2" style="color: #005C53;"></i>Lista de Macro Áreas
|
<i data-lucide="layers" class="me-2"></i>Lista de Macro Áreas
|
||||||
</h6>
|
</h6>
|
||||||
<div class="input-group" style="width: 250px;">
|
<div class="input-group" style="width: 250px;">
|
||||||
<span class="input-group-text text-slate-400"><i data-lucide="search"></i></span>
|
<span class="input-group-text text-slate-400"><i data-lucide="search"></i></span>
|
||||||
@ -70,16 +76,16 @@ $macro_areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|||||||
<td>
|
<td>
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<a href="macro_area_form.php?id=<?php echo $area['id']; ?>" class="btn btn-sm">
|
<a href="macro_area_form.php?id=<?php echo $area['id']; ?>" class="btn btn-sm">
|
||||||
<i data-lucide="edit" style="color: #4C5958;"></i>
|
<i data-lucide="edit" style="color: #4C5958; width: 18px; height: 18px;"></i>
|
||||||
</a>
|
</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?');">
|
<a href="delete_macro_area.php?id=<?php echo $area['id']; ?>" class="btn btn-sm">
|
||||||
<i data-lucide="trash-2" style="color: #4C5958;"></i>
|
<i data-lucide="trash-2" style="color: #4C5958; width: 18px; height: 18px;"></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if (empty($macro_areas)): ?>
|
<?php if (empty($macro_areas)):
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4" class="text-center">Nenhuma macro área encontrada.</td>
|
<td colspan="4" class="text-center">Nenhuma macro área encontrada.</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -150,6 +156,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
#printButton {
|
||||||
|
background-color: #005C53;
|
||||||
|
border-color: #005C53;
|
||||||
|
}
|
||||||
|
#printButton:hover {
|
||||||
|
background-color: #004c43;
|
||||||
|
border-color: #004c43;
|
||||||
|
}
|
||||||
.input-group-text {
|
.input-group-text {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-right: 0;
|
border-right: 0;
|
||||||
@ -174,3 +188,4 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
border: 1px solid #f5c2c7;
|
border: 1px solid #f5c2c7;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user