gestor fazenda
This commit is contained in:
parent
48b59943c9
commit
a8e4c72927
95
add_crop.php
Normal file
95
add_crop.php
Normal file
@ -0,0 +1,95 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
require_once 'db/config.php';
|
||||
include 'includes/header.php';
|
||||
include 'includes/sidebar.php';
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$name = $_POST['name'] ?? '';
|
||||
$area = $_POST['area'] ?? 0;
|
||||
$start_date = $_POST['start_date'] ?? '';
|
||||
|
||||
if (empty($name) || empty($area) || empty($start_date)) {
|
||||
$error = 'Por favor, preencha todos os campos.';
|
||||
} elseif ($area <= 0) {
|
||||
$error = 'A área deve ser maior que zero.';
|
||||
} else {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('INSERT INTO crops (name, area, start_date) VALUES (?, ?, ?)');
|
||||
$stmt->execute([$name, $area, $start_date]);
|
||||
$success = 'Lavoura adicionada com sucesso!';
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Erro ao adicionar lavoura: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Adicionar Lavoura</h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Nova Lavoura
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?><p class="error"><?php echo $error; ?></p><?php endif; ?>
|
||||
<?php if ($success): ?><p class="success"><?php echo $success; ?></p><?php endif; ?>
|
||||
|
||||
<form action="add_crop.php" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="name">Nome da Cultura (ex: Soja, Milho)</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="area">Área (em hectares)</label>
|
||||
<input type="number" step="0.01" id="area" name="area" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="start_date">Data de Início</label>
|
||||
<input type="date" id="start_date" name="start_date" required>
|
||||
</div>
|
||||
<button type="submit" class="btn">Adicionar</button>
|
||||
</form>
|
||||
<br>
|
||||
<a href="crops.php">Voltar para Lavouras</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.btn {
|
||||
background-color: #27ae60;
|
||||
color: white;
|
||||
padding: 10px 15px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.error { color: red; }
|
||||
.success { color: green; }
|
||||
</style>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
93
add_product.php
Normal file
93
add_product.php
Normal file
@ -0,0 +1,93 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
require_once 'db/config.php';
|
||||
include 'includes/header.php';
|
||||
include 'includes/sidebar.php';
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$name = $_POST['name'] ?? '';
|
||||
$unit = $_POST['unit'] ?? '';
|
||||
$quantity = $_POST['quantity'] ?? 0;
|
||||
|
||||
if (empty($name) || empty($unit)) {
|
||||
$error = 'Por favor, preencha o nome e a unidade do produto.';
|
||||
} else {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('INSERT INTO products (name, unit, quantity) VALUES (?, ?, ?)');
|
||||
$stmt->execute([$name, $unit, $quantity]);
|
||||
$success = 'Produto adicionado com sucesso!';
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Erro ao adicionar produto: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Adicionar Produto</h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Novo Produto
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?><p class="error"><?php echo $error; ?></p><?php endif; ?>
|
||||
<?php if ($success): ?><p class="success"><?php echo $success; ?></p><?php endif; ?>
|
||||
|
||||
<form action="add_product.php" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="name">Nome do Produto</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="unit">Unidade (ex: kg, L, un)</label>
|
||||
<input type="text" id="unit" name="unit" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="quantity">Quantidade Inicial</label>
|
||||
<input type="number" step="0.01" id="quantity" name="quantity" value="0">
|
||||
</div>
|
||||
<button type="submit" class="btn">Adicionar</button>
|
||||
</form>
|
||||
<br>
|
||||
<a href="inventory.php">Voltar para o Estoque</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.btn {
|
||||
background-color: #27ae60;
|
||||
color: white;
|
||||
padding: 10px 15px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.error { color: red; }
|
||||
.success { color: green; }
|
||||
</style>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
123
add_transaction.php
Normal file
123
add_transaction.php
Normal file
@ -0,0 +1,123 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
require_once 'db/config.php';
|
||||
include 'includes/header.php';
|
||||
include 'includes/sidebar.php';
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
// Fetch categories for the dropdown
|
||||
try {
|
||||
$pdo = db();
|
||||
$categories = $pdo->query('SELECT * FROM financial_categories ORDER BY name')->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
$categories = [];
|
||||
$error = 'Erro ao carregar categorias.';
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$description = $_POST['description'] ?? '';
|
||||
$type = $_POST['type'] ?? '';
|
||||
$amount = $_POST['amount'] ?? 0;
|
||||
$category_id = $_POST['category_id'] ?? null;
|
||||
$date = $_POST['date'] ?? '';
|
||||
|
||||
if (empty($description) || empty($type) || empty($amount) || empty($category_id) || empty($date)) {
|
||||
$error = 'Por favor, preencha todos os campos.';
|
||||
} elseif ($amount <= 0) {
|
||||
$error = 'O valor deve ser maior que zero.';
|
||||
} else {
|
||||
try {
|
||||
$stmt = $pdo->prepare('INSERT INTO financial_transactions (description, type, amount, category_id, user_id, date) VALUES (?, ?, ?, ?, ?, ?)');
|
||||
$stmt->execute([$description, $type, $amount, $category_id, $_SESSION['user_id'], $date]);
|
||||
$success = 'Transação adicionada com sucesso!';
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Erro ao adicionar transação: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Adicionar Transação</h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Nova Transação Financeira
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?><p class="error"><?php echo $error; ?></p><?php endif; ?>
|
||||
<?php if ($success): ?><p class="success"><?php echo $success; ?></p><?php endif; ?>
|
||||
|
||||
<form action="add_transaction.php" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="description">Descrição</label>
|
||||
<input type="text" id="description" name="description" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="type">Tipo</label>
|
||||
<select id="type" name="type" required>
|
||||
<option value="despesa">Despesa</option>
|
||||
<option value="receita">Receita</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="amount">Valor (R$)</label>
|
||||
<input type="number" step="0.01" id="amount" name="amount" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="category_id">Categoria</label>
|
||||
<select id="category_id" name="category_id" required>
|
||||
<option value="">Selecione uma categoria</option>
|
||||
<?php foreach ($categories as $category): ?>
|
||||
<option value="<?php echo htmlspecialchars($category['id']); ?>">
|
||||
<?php echo htmlspecialchars($category['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="date">Data</label>
|
||||
<input type="date" id="date" name="date" required>
|
||||
</div>
|
||||
<button type="submit" class="btn">Adicionar</button>
|
||||
</form>
|
||||
<br>
|
||||
<a href="financial.php">Voltar para o Financeiro</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-group input, .form-group select {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.btn {
|
||||
background-color: #27ae60;
|
||||
color: white;
|
||||
padding: 10px 15px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.error { color: red; }
|
||||
.success { color: green; }
|
||||
</style>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
140
assets/css/style.css
Normal file
140
assets/css/style.css
Normal file
@ -0,0 +1,140 @@
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
background-color: #f4f6f9;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 250px;
|
||||
background-color: #2c3e50; /* Dark blue-gray for sidebar */
|
||||
color: #ecf0f1; /* Light gray text */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 0 20px 20px 20px;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #34495e;
|
||||
}
|
||||
|
||||
.sidebar-header h3 {
|
||||
margin: 0;
|
||||
font-size: 1.5rem;
|
||||
color: #ffffff; /* White header text */
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
list-style: none;
|
||||
padding: 20px 0;
|
||||
margin: 0;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.sidebar-nav a {
|
||||
display: block;
|
||||
color: #ecf0f1;
|
||||
text-decoration: none;
|
||||
padding: 15px 25px;
|
||||
font-size: 1.1rem;
|
||||
transition: background-color 0.3s, padding-left 0.3s;
|
||||
}
|
||||
|
||||
.sidebar-nav a:hover,
|
||||
.sidebar-nav a.active {
|
||||
background-color: #34495e; /* Slightly lighter dark blue on hover */
|
||||
padding-left: 30px;
|
||||
border-left: 3px solid #27ae60; /* Green accent */
|
||||
}
|
||||
|
||||
.main-content {
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
header.top-bar {
|
||||
background-color: #ffffff;
|
||||
padding: 15px 30px;
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
|
||||
}
|
||||
|
||||
header.top-bar h1 {
|
||||
margin: 0;
|
||||
font-size: 1.8rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 30px;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.card {
|
||||
background-color: #ffffff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.08);
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 15px;
|
||||
border-bottom: 1px solid #eee;
|
||||
padding-bottom: 10px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
body {
|
||||
flex-direction: column;
|
||||
}
|
||||
.sidebar {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
padding-top: 0;
|
||||
}
|
||||
.sidebar-header {
|
||||
padding: 15px;
|
||||
border-bottom: none;
|
||||
}
|
||||
.sidebar-nav {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
padding: 0;
|
||||
justify-content: center;
|
||||
}
|
||||
.sidebar-nav a {
|
||||
padding: 15px;
|
||||
border-left: none;
|
||||
border-bottom: 3px solid transparent;
|
||||
}
|
||||
.sidebar-nav a:hover,
|
||||
.sidebar-nav a.active {
|
||||
padding-left: 15px;
|
||||
border-left: none;
|
||||
border-bottom: 3px solid #27ae60;
|
||||
background-color: transparent;
|
||||
}
|
||||
header.top-bar {
|
||||
padding: 15px;
|
||||
}
|
||||
.content {
|
||||
padding: 15px;
|
||||
}
|
||||
}
|
||||
88
crops.php
Normal file
88
crops.php
Normal file
@ -0,0 +1,88 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
require_once 'db/config.php';
|
||||
include 'includes/header.php';
|
||||
include 'includes/sidebar.php';
|
||||
|
||||
// Fetch crops from the database
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query('SELECT * FROM crops ORDER BY start_date DESC');
|
||||
$crops = $stmt->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
$crops = [];
|
||||
$error = "Erro ao buscar lavouras: " . $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Controle de Lavouras</h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<span>Lavouras Cadastradas</span>
|
||||
<a href="add_crop.php" class="btn" style="float: right; background-color: #3498db; color: white; text-decoration: none; padding: 5px 10px; border-radius: 4px;">Adicionar Lavoura</a>
|
||||
</div>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<p class="error"><?php echo $error; ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Lavoura</th>
|
||||
<th>Área (ha)</th>
|
||||
<th>Data de Início</th>
|
||||
<th>Data de Colheita</th>
|
||||
<th>Ações</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($crops)): ?>
|
||||
<tr>
|
||||
<td colspan="5">Nenhuma lavoura encontrada.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($crops as $crop): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($crop['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($crop['area']); ?></td>
|
||||
<td><?php echo htmlspecialchars(date('d/m/Y', strtotime($crop['start_date']))); ?></td>
|
||||
<td><?php echo $crop['end_date'] ? htmlspecialchars(date('d/m/Y', strtotime($crop['end_date']))) : 'Em andamento'; ?></td>
|
||||
<td>
|
||||
<a href="view_crop.php?id=<?php echo $crop['id']; ?>">Ver Detalhes</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
82
db/database.sql
Normal file
82
db/database.sql
Normal file
@ -0,0 +1,82 @@
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `roles` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL UNIQUE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
INSERT INTO `roles` (name) VALUES ('Administrador'), ('Gestor'), ('Funcionário');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`email` VARCHAR(255) NOT NULL UNIQUE,
|
||||
`password` VARCHAR(255) NOT NULL,
|
||||
`role_id` INT,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `products` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`unit` VARCHAR(50) NOT NULL, -- e.g., kg, L, un
|
||||
`quantity` DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `stock_movements` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`product_id` INT NOT NULL,
|
||||
`type` ENUM('entrada', 'saída') NOT NULL,
|
||||
`quantity` DECIMAL(10, 2) NOT NULL,
|
||||
`user_id` INT,
|
||||
`notes` TEXT,
|
||||
`date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`product_id`) REFERENCES `products`(`id`),
|
||||
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `financial_categories` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
INSERT INTO `financial_categories` (name) VALUES ('Combustível'), ('Sementes'), ('Defensivos'), ('Maquinário'), ('Mão de Obra'), ('Manutenção'), ('Receita de Venda'), ('Outros');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `financial_transactions` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`description` VARCHAR(255) NOT NULL,
|
||||
`type` ENUM('receita', 'despesa') NOT NULL,
|
||||
`amount` DECIMAL(10, 2) NOT NULL,
|
||||
`category_id` INT,
|
||||
`user_id` INT,
|
||||
`date` DATE NOT NULL,
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (`category_id`) REFERENCES `financial_categories`(`id`),
|
||||
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `crops` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`area` DECIMAL(10, 2) NOT NULL, -- in hectares
|
||||
`start_date` DATE NOT NULL,
|
||||
`end_date` DATE,
|
||||
`expected_yield` DECIMAL(10, 2),
|
||||
`actual_yield` DECIMAL(10, 2),
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `crop_inputs` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`crop_id` INT NOT NULL,
|
||||
`product_id` INT NOT NULL,
|
||||
`quantity` DECIMAL(10, 2) NOT NULL,
|
||||
`application_date` DATE NOT NULL,
|
||||
`user_id` INT,
|
||||
`notes` TEXT,
|
||||
FOREIGN KEY (`crop_id`) REFERENCES `crops`(`id`),
|
||||
FOREIGN KEY (`product_id`) REFERENCES `products`(`id`),
|
||||
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
138
financial.php
Normal file
138
financial.php
Normal file
@ -0,0 +1,138 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
require_once 'db/config.php';
|
||||
include 'includes/header.php';
|
||||
include 'includes/sidebar.php';
|
||||
|
||||
// Fetch transactions from the database
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query('SELECT ft.*, fc.name as category_name FROM financial_transactions ft JOIN financial_categories fc ON ft.category_id = fc.id ORDER BY ft.date DESC');
|
||||
$transactions = $stmt->fetchAll();
|
||||
|
||||
// Calculate summary
|
||||
$total_income = 0;
|
||||
$total_expenses = 0;
|
||||
foreach ($transactions as $t) {
|
||||
if ($t['type'] == 'receita') {
|
||||
$total_income += $t['amount'];
|
||||
} else {
|
||||
$total_expenses += $t['amount'];
|
||||
}
|
||||
}
|
||||
$net_result = $total_income - $total_expenses;
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$transactions = [];
|
||||
$error = "Erro ao buscar transações: " . $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Controle Financeiro</h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Resumo Financeiro
|
||||
</div>
|
||||
<div class="financial-summary">
|
||||
<div class="summary-item income">
|
||||
<h4>Receitas</h4>
|
||||
<p>R$ <?php echo number_format($total_income, 2, ',', '.'); ?></p>
|
||||
</div>
|
||||
<div class="summary-item expense">
|
||||
<h4>Despesas</h4>
|
||||
<p>R$ <?php echo number_format($total_expenses, 2, ',', '.'); ?></p>
|
||||
</div>
|
||||
<div class="summary-item net-result">
|
||||
<h4>Resultado Líquido</h4>
|
||||
<p>R$ <?php echo number_format($net_result, 2, ',', '.'); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<span>Histórico de Transações</span>
|
||||
<a href="add_transaction.php" class="btn" style="float: right; background-color: #3498db; color: white; text-decoration: none; padding: 5px 10px; border-radius: 4px;">Adicionar Transação</a>
|
||||
</div>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<p class="error"><?php echo $error; ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data</th>
|
||||
<th>Descrição</th>
|
||||
<th>Tipo</th>
|
||||
<th>Categoria</th>
|
||||
<th>Valor</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($transactions)): ?>
|
||||
<tr>
|
||||
<td colspan="5">Nenhuma transação encontrada.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($transactions as $transaction): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars(date('d/m/Y', strtotime($transaction['date']))); ?></td>
|
||||
<td><?php echo htmlspecialchars($transaction['description']); ?></td>
|
||||
<td><?php echo htmlspecialchars(ucfirst($transaction['type'])); ?></td>
|
||||
<td><?php echo htmlspecialchars($transaction['category_name']); ?></td>
|
||||
<td style="color: <?php echo $transaction['type'] == 'receita' ? 'green' : 'red'; ?>;">
|
||||
R$ <?php echo number_format($transaction['amount'], 2, ',', '.'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.financial-summary {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.summary-item h4 {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.summary-item p {
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
.income p { color: green; }
|
||||
.expense p { color: red; }
|
||||
.net-result p { color: <?php echo $net_result >= 0 ? 'blue' : 'red'; ?>; }
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
4
includes/footer.php
Normal file
4
includes/footer.php
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
</div> <!-- .main-content -->
|
||||
</body>
|
||||
</html>
|
||||
10
includes/header.php
Normal file
10
includes/header.php
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Gestão Agrícola</title>
|
||||
<link rel="stylesheet" href="assets/css/style.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
17
includes/sidebar.php
Normal file
17
includes/sidebar.php
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
<div class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h3>Gestão Agrícola</h3>
|
||||
</div>
|
||||
<nav>
|
||||
<ul class="sidebar-nav">
|
||||
<li><a href="index.php" class="active">Dashboard</a></li>
|
||||
<li><a href="inventory.php">Estoque</a></li>
|
||||
<li><a href="financial.php">Financeiro</a></li>
|
||||
<li><a href="crops.php">Lavouras</a></li>
|
||||
<li><a href="#">Relatórios</a></li>
|
||||
<li><a href="logout.php">Sair</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="main-content">
|
||||
133
index.php
133
index.php
@ -1,103 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
include 'includes/header.php';
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #4B0082;
|
||||
--bg-color-end: #8A2BE2;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<?php include 'includes/sidebar.php'; ?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Dashboard</h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<div class="card">
|
||||
<h1>Welcome!</h1>
|
||||
<p>This is your new landing page.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
<div class="card-header">
|
||||
Resumo Financeiro
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
<p>Aqui vai um resumo das finanças da fazenda.</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Níveis de Estoque
|
||||
</div>
|
||||
<p>Aqui vai um resumo dos níveis de estoque.</p>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Produtividade da Lavoura
|
||||
</div>
|
||||
<p>Aqui vai um resumo da produtividade da lavoura.</p>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
86
inventory.php
Normal file
86
inventory.php
Normal file
@ -0,0 +1,86 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
require_once 'db/config.php';
|
||||
include 'includes/header.php';
|
||||
include 'includes/sidebar.php';
|
||||
|
||||
// Fetch products from the database
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query('SELECT * FROM products ORDER BY name');
|
||||
$products = $stmt->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
$products = [];
|
||||
$error = "Erro ao buscar produtos: " . $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Estoque</h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<span>Produtos em Estoque</span>
|
||||
<a href="add_product.php" class="btn" style="float: right; background-color: #3498db; color: white; text-decoration: none; padding: 5px 10px; border-radius: 4px;">Adicionar Produto</a>
|
||||
</div>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<p class="error"><?php echo $error; ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Produto</th>
|
||||
<th>Unidade</th>
|
||||
<th>Quantidade</th>
|
||||
<th>Ações</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($products)): ?>
|
||||
<tr>
|
||||
<td colspan="4">Nenhum produto encontrado.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($products as $product): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($product['name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($product['unit']); ?></td>
|
||||
<td><?php echo htmlspecialchars($product['quantity']); ?></td>
|
||||
<td>
|
||||
<a href="stock.php?product_id=<?php echo $product['id']; ?>">Movimentar</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 20px;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
117
login.php
Normal file
117
login.php
Normal file
@ -0,0 +1,117 @@
|
||||
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
session_start();
|
||||
|
||||
$error = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
if (empty($_POST['email']) || empty($_POST['password'])) {
|
||||
$error = 'Por favor, preencha todos os campos.';
|
||||
} else {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = ?');
|
||||
$stmt->execute([$_POST['email']]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($_POST['password'], $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['user_name'] = $user['name'];
|
||||
$_SESSION['user_role'] = $user['role_id'];
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
} else {
|
||||
$error = 'E-mail ou senha inválidos.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Erro no banco de dados: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login - Gestão Agrícola</title>
|
||||
<link rel="stylesheet" href="assets/css/style.css?v=<?php echo time(); ?>">
|
||||
<style>
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
background-color: #f4f6f9;
|
||||
}
|
||||
.login-container {
|
||||
background: #fff;
|
||||
padding: 40px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
text-align: center;
|
||||
}
|
||||
.login-container h2 {
|
||||
margin-bottom: 20px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
text-align: left;
|
||||
}
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.btn {
|
||||
background-color: #27ae60;
|
||||
color: #fff;
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
font-size: 1rem;
|
||||
}
|
||||
.error {
|
||||
color: #e74c3c;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.register-link {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<h2>Login</h2>
|
||||
<?php if ($error): ?>
|
||||
<p class="error"><?php echo $error; ?></p>
|
||||
<?php endif; ?>
|
||||
<form action="login.php" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="email">E-mail</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Senha</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn">Entrar</button>
|
||||
</form>
|
||||
<div class="register-link">
|
||||
<p>Não tem uma conta? <a href="register.php">Cadastre-se</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
7
logout.php
Normal file
7
logout.php
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
150
register.php
Normal file
150
register.php
Normal file
@ -0,0 +1,150 @@
|
||||
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$name = $_POST['name'] ?? '';
|
||||
$email = $_POST['email'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
$role_id = $_POST['role_id'] ?? 3; // Default to 'Funcionário'
|
||||
|
||||
if (empty($name) || empty($email) || empty($password)) {
|
||||
$error = 'Por favor, preencha todos os campos.';
|
||||
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$error = 'Formato de e-mail inválido.';
|
||||
} else {
|
||||
try {
|
||||
$pdo = db();
|
||||
|
||||
// Check if email already exists
|
||||
$stmt = $pdo->prepare('SELECT COUNT(*) FROM users WHERE email = ?');
|
||||
$stmt->execute([$email]);
|
||||
if ($stmt->fetchColumn() > 0) {
|
||||
$error = 'Este e-mail já está cadastrado.';
|
||||
} else {
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $pdo->prepare('INSERT INTO users (name, email, password, role_id) VALUES (?, ?, ?, ?)');
|
||||
$stmt->execute([$name, $email, $hashed_password, $role_id]);
|
||||
$success = 'Usuário cadastrado com sucesso! Você pode fazer o login agora.';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Erro no banco de dados: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch roles for the dropdown
|
||||
try {
|
||||
$pdo = db();
|
||||
$roles = $pdo->query('SELECT * FROM roles')->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
$roles = [];
|
||||
$error = 'Erro ao carregar os papéis de usuário.';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="pt-BR">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cadastro - Gestão Agrícola</title>
|
||||
<link rel="stylesheet" href="assets/css/style.css?v=<?php echo time(); ?>">
|
||||
<style>
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
background-color: #f4f6f9;
|
||||
}
|
||||
.register-container {
|
||||
background: #fff;
|
||||
padding: 40px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
||||
width: 100%;
|
||||
max-width: 450px;
|
||||
text-align: center;
|
||||
}
|
||||
.register-container h2 {
|
||||
margin-bottom: 20px;
|
||||
color: #2c3e50;
|
||||
}
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
text-align: left;
|
||||
}
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-group input, .form-group select {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.btn {
|
||||
background-color: #27ae60;
|
||||
color: #fff;
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
font-size: 1rem;
|
||||
}
|
||||
.error {
|
||||
color: #e74c3c;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.success {
|
||||
color: #27ae60;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.login-link {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="register-container">
|
||||
<h2>Cadastro de Usuário</h2>
|
||||
<?php if ($error): ?><p class="error"><?php echo $error; ?></p><?php endif; ?>
|
||||
<?php if ($success): ?><p class="success"><?php echo $success; ?></p><?php endif; ?>
|
||||
<form action="register.php" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="name">Nome Completo</label>
|
||||
<input type="text" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">E-mail</label>
|
||||
<input type="email" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Senha</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="role_id">Função</label>
|
||||
<select id="role_id" name="role_id">
|
||||
<?php foreach ($roles as $role): ?>
|
||||
<option value="<?php echo htmlspecialchars($role['id']); ?>" <?php echo $role['id'] == 3 ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($role['name']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn">Cadastrar</button>
|
||||
</form>
|
||||
<div class="login-link">
|
||||
<p>Já tem uma conta? <a href="login.php">Faça o login</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
185
stock.php
Normal file
185
stock.php
Normal file
@ -0,0 +1,185 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
require_once 'db/config.php';
|
||||
include 'includes/header.php';
|
||||
include 'includes/sidebar.php';
|
||||
|
||||
$product_id = $_GET['product_id'] ?? null;
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
if (!$product_id) {
|
||||
header('Location: inventory.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Fetch product details
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('SELECT * FROM products WHERE id = ?');
|
||||
$stmt->execute([$product_id]);
|
||||
$product = $stmt->fetch();
|
||||
} catch (PDOException $e) {
|
||||
$error = "Erro ao buscar produto: " . $e->getMessage();
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$type = $_POST['type'] ?? '';
|
||||
$quantity = $_POST['quantity'] ?? 0;
|
||||
$notes = $_POST['notes'] ?? '';
|
||||
|
||||
if (empty($type) || empty($quantity) || $quantity <= 0) {
|
||||
$error = 'Por favor, preencha o tipo e a quantidade (maior que zero).';
|
||||
} else {
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Insert into stock_movements
|
||||
$stmt = $pdo->prepare('INSERT INTO stock_movements (product_id, type, quantity, user_id, notes) VALUES (?, ?, ?, ?, ?)');
|
||||
$stmt->execute([$product_id, $type, $quantity, $_SESSION['user_id'], $notes]);
|
||||
|
||||
// Update product quantity
|
||||
if ($type == 'entrada') {
|
||||
$update_sql = 'UPDATE products SET quantity = quantity + ? WHERE id = ?';
|
||||
} else {
|
||||
$update_sql = 'UPDATE products SET quantity = quantity - ? WHERE id = ?';
|
||||
}
|
||||
$stmt = $pdo->prepare($update_sql);
|
||||
$stmt->execute([$quantity, $product_id]);
|
||||
|
||||
$pdo->commit();
|
||||
$success = 'Movimentação de estoque registrada com sucesso!';
|
||||
|
||||
// Refresh product data
|
||||
$stmt = $pdo->prepare('SELECT * FROM products WHERE id = ?');
|
||||
$stmt->execute([$product_id]);
|
||||
$product = $stmt->fetch();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
$error = 'Erro ao registrar movimentação: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch stock movements for this product
|
||||
try {
|
||||
$stmt = $pdo->prepare('SELECT sm.*, u.name as user_name FROM stock_movements sm JOIN users u ON sm.user_id = u.id WHERE sm.product_id = ? ORDER BY sm.date DESC');
|
||||
$stmt->execute([$product_id]);
|
||||
$movements = $stmt->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
$movements = [];
|
||||
$error = "Erro ao buscar movimentações: " . $e->getMessage();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Movimentar Estoque: <?php echo htmlspecialchars($product['name'] ?? 'Produto não encontrado'); ?></h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Registrar Entrada/Saída
|
||||
</div>
|
||||
|
||||
<p><b>Estoque Atual:</b> <?php echo htmlspecialchars($product['quantity'] . ' ' . $product['unit']); ?></p>
|
||||
|
||||
<?php if ($error): ?><p class="error"><?php echo $error; ?></p><?php endif; ?>
|
||||
<?php if ($success): ?><p class="success"><?php echo $success; ?></p><?php endif; ?>
|
||||
|
||||
<form action="stock.php?product_id=<?php echo $product_id; ?>" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="type">Tipo de Movimentação</label>
|
||||
<select id="type" name="type" required>
|
||||
<option value="entrada">Entrada</option>
|
||||
<option value="saída">Saída</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="quantity">Quantidade</label>
|
||||
<input type="number" step="0.01" id="quantity" name="quantity" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="notes">Notas</label>
|
||||
<textarea id="notes" name="notes" rows="3"></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn">Registrar</button>
|
||||
</form>
|
||||
<br>
|
||||
<a href="inventory.php">Voltar para o Estoque</a>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Histórico de Movimentações
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data</th>
|
||||
<th>Tipo</th>
|
||||
<th>Quantidade</th>
|
||||
<th>Usuário</th>
|
||||
<th>Notas</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($movements as $movement): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars(date('d/m/Y H:i', strtotime($movement['date']))); ?></td>
|
||||
<td><?php echo htmlspecialchars(ucfirst($movement['type'])); ?></td>
|
||||
<td><?php echo htmlspecialchars($movement['quantity']); ?></td>
|
||||
<td><?php echo htmlspecialchars($movement['user_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($movement['notes']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.form-group, table {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.form-group input, .form-group select, .form-group textarea {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.btn {
|
||||
background-color: #27ae60;
|
||||
color: white;
|
||||
padding: 10px 15px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.error { color: red; }
|
||||
.success { color: green; }
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
</style>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
189
view_crop.php
Normal file
189
view_crop.php
Normal file
@ -0,0 +1,189 @@
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
require_once 'db/config.php';
|
||||
include 'includes/header.php';
|
||||
include 'includes/sidebar.php';
|
||||
|
||||
$crop_id = $_GET['id'] ?? null;
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
if (!$crop_id) {
|
||||
header('Location: crops.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
|
||||
// Handle Input Application
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_input'])) {
|
||||
$product_id = $_POST['product_id'] ?? null;
|
||||
$quantity = $_POST['quantity'] ?? 0;
|
||||
$application_date = $_POST['application_date'] ?? '';
|
||||
|
||||
if (empty($product_id) || empty($quantity) || empty($application_date) || $quantity <= 0) {
|
||||
$error = 'Por favor, preencha todos os campos para adicionar o insumo.';
|
||||
} else {
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// 1. Check if there is enough stock
|
||||
$stmt = $pdo->prepare('SELECT quantity FROM products WHERE id = ?');
|
||||
$stmt->execute([$product_id]);
|
||||
$stock_quantity = $stmt->fetchColumn();
|
||||
|
||||
if ($stock_quantity < $quantity) {
|
||||
throw new Exception('Quantidade em estoque insuficiente.');
|
||||
}
|
||||
|
||||
// 2. Add to crop_inputs
|
||||
$stmt = $pdo->prepare('INSERT INTO crop_inputs (crop_id, product_id, quantity, application_date, user_id) VALUES (?, ?, ?, ?, ?)');
|
||||
$stmt->execute([$crop_id, $product_id, $quantity, $application_date, $_SESSION['user_id']]);
|
||||
|
||||
// 3. Update product stock (create a stock movement)
|
||||
$stmt = $pdo->prepare('UPDATE products SET quantity = quantity - ? WHERE id = ?');
|
||||
$stmt->execute([$quantity, $product_id]);
|
||||
|
||||
// 4. Log the stock movement
|
||||
$notes = "Aplicação na lavoura ID: $crop_id";
|
||||
$stmt = $pdo->prepare('INSERT INTO stock_movements (product_id, type, quantity, user_id, notes) VALUES (?, 'saída', ?, ?, ?)');
|
||||
$stmt->execute([$product_id, $quantity, $_SESSION['user_id'], $notes]);
|
||||
|
||||
$pdo->commit();
|
||||
$success = 'Insumo aplicado com sucesso!';
|
||||
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
$error = 'Erro ao aplicar insumo: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fetch crop details
|
||||
try {
|
||||
$stmt = $pdo->prepare('SELECT * FROM crops WHERE id = ?');
|
||||
$stmt->execute([$crop_id]);
|
||||
$crop = $stmt->fetch();
|
||||
|
||||
if (!$crop) {
|
||||
header('Location: crops.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Fetch applied inputs
|
||||
$stmt = $pdo->prepare('
|
||||
SELECT ci.*, p.name as product_name, p.unit
|
||||
FROM crop_inputs ci
|
||||
JOIN products p ON ci.product_id = p.id
|
||||
WHERE ci.crop_id = ?
|
||||
ORDER BY ci.application_date DESC
|
||||
');
|
||||
$stmt->execute([$crop_id]);
|
||||
$applied_inputs = $stmt->fetchAll();
|
||||
|
||||
// Fetch products for the dropdown
|
||||
$products = $pdo->query('SELECT id, name, unit, quantity FROM products WHERE quantity > 0 ORDER BY name')->fetchAll();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error = "Erro ao buscar dados da lavoura: " . $e->getMessage();
|
||||
$crop = null;
|
||||
$applied_inputs = [];
|
||||
$products = [];
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<header class="top-bar">
|
||||
<h1>Detalhes da Lavoura: <?php echo htmlspecialchars($crop['name'] ?? ''); ?></h1>
|
||||
</header>
|
||||
|
||||
<main class="content">
|
||||
<?php if ($error): ?><p class="error"><?php echo $error; ?></p><?php endif; ?>
|
||||
<?php if ($success): ?><p class="success"><?php echo $success; ?></p><?php endif; ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">Informações Gerais</div>
|
||||
<?php if ($crop): ?>
|
||||
<p><strong>Cultura:</strong> <?php echo htmlspecialchars($crop['name']); ?></p>
|
||||
<p><strong>Área:</strong> <?php echo htmlspecialchars($crop['area']); ?> ha</p>
|
||||
<p><strong>Data de Início:</strong> <?php echo htmlspecialchars(date('d/m/Y', strtotime($crop['start_date']))); ?></p>
|
||||
<p><strong>Data de Colheita:</strong> <?php echo $crop['end_date'] ? htmlspecialchars(date('d/m/Y', strtotime($crop['end_date']))) : 'Em andamento'; ?></p>
|
||||
<?php else: ?>
|
||||
<p>Lavoura não encontrada.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">Aplicar Insumo</div>
|
||||
<form action="view_crop.php?id=<?php echo $crop_id; ?>" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="product_id">Insumo</label>
|
||||
<select id="product_id" name="product_id" required>
|
||||
<option value="">Selecione um insumo</option>
|
||||
<?php foreach ($products as $product): ?>
|
||||
<option value="<?php echo htmlspecialchars($product['id']); ?>">
|
||||
<?php echo htmlspecialchars($product['name'] . ' (' . $product['quantity'] . ' ' . $product['unit'] . ' em estoque)'); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="quantity">Quantidade Aplicada</label>
|
||||
<input type="number" step="0.01" id="quantity" name="quantity" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="application_date">Data da Aplicação</label>
|
||||
<input type="date" id="application_date" name="application_date" required>
|
||||
</div>
|
||||
<button type="submit" name="add_input" class="btn">Adicionar Insumo</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">Histórico de Insumos Aplicados</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Data</th>
|
||||
<th>Produto</th>
|
||||
<th>Quantidade</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($applied_inputs)): ?>
|
||||
<tr><td colspan="3">Nenhum insumo aplicado ainda.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($applied_inputs as $input): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars(date('d/m/Y', strtotime($input['application_date']))); ?></td>
|
||||
<td><?php echo htmlspecialchars($input['product_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($input['quantity'] . ' ' . $input['unit']); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<br>
|
||||
<a href="crops.php">Voltar para Lavouras</a>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.form-group { margin-bottom: 15px; }
|
||||
.form-group label { display: block; margin-bottom: 5px; }
|
||||
.form-group input, .form-group select { width: 100%; padding: 8px; box-sizing: border-box; }
|
||||
.btn { background-color: #27ae60; color: white; padding: 10px 15px; border: none; border-radius: 4px; cursor: pointer; }
|
||||
.error { color: red; background-color: #fdd; padding: 10px; border-radius: 4px; margin-bottom: 15px; }
|
||||
.success { color: green; background-color: #dfd; padding: 10px; border-radius: 4px; margin-bottom: 15px; }
|
||||
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
|
||||
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
|
||||
th { background-color: #f2f2f2; }
|
||||
</style>
|
||||
|
||||
<?php include 'includes/footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user