diff --git a/add_crop.php b/add_crop.php new file mode 100644 index 0000000..4819c66 --- /dev/null +++ b/add_crop.php @@ -0,0 +1,95 @@ + +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(); + } + } +} +?> + + + Adicionar Lavoura + + + + + + Nova Lavoura + + + + + + + + Nome da Cultura (ex: Soja, Milho) + + + + Área (em hectares) + + + + Data de Início + + + Adicionar + + + Voltar para Lavouras + + + + + + diff --git a/add_product.php b/add_product.php new file mode 100644 index 0000000..746d814 --- /dev/null +++ b/add_product.php @@ -0,0 +1,93 @@ + +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(); + } + } +} +?> + + + Adicionar Produto + + + + + + Novo Produto + + + + + + + + Nome do Produto + + + + Unidade (ex: kg, L, un) + + + + Quantidade Inicial + + + Adicionar + + + Voltar para o Estoque + + + + + + diff --git a/add_transaction.php b/add_transaction.php new file mode 100644 index 0000000..aa75499 --- /dev/null +++ b/add_transaction.php @@ -0,0 +1,123 @@ + +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(); + } + } +} +?> + + + Adicionar Transação + + + + + + Nova Transação Financeira + + + + + + + + Descrição + + + + Tipo + + Despesa + Receita + + + + Valor (R$) + + + + Categoria + + Selecione uma categoria + + + + + + + + + Data + + + Adicionar + + + Voltar para o Financeiro + + + + + + diff --git a/assets/css/style.css b/assets/css/style.css new file mode 100644 index 0000000..9a5ca26 --- /dev/null +++ b/assets/css/style.css @@ -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; + } +} diff --git a/crops.php b/crops.php new file mode 100644 index 0000000..46dd8fe --- /dev/null +++ b/crops.php @@ -0,0 +1,88 @@ + +query('SELECT * FROM crops ORDER BY start_date DESC'); + $crops = $stmt->fetchAll(); +} catch (PDOException $e) { + $crops = []; + $error = "Erro ao buscar lavouras: " . $e->getMessage(); +} + +?> + + + Controle de Lavouras + + + + + + Lavouras Cadastradas + Adicionar Lavoura + + + + + + + + + + Lavoura + Área (ha) + Data de Início + Data de Colheita + Ações + + + + + + Nenhuma lavoura encontrada. + + + + + + + + + + Ver Detalhes + + + + + + + + + + + + diff --git a/db/database.sql b/db/database.sql new file mode 100644 index 0000000..c2cd22a --- /dev/null +++ b/db/database.sql @@ -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; + diff --git a/financial.php b/financial.php new file mode 100644 index 0000000..84e9b68 --- /dev/null +++ b/financial.php @@ -0,0 +1,138 @@ + +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(); +} + +?> + + + Controle Financeiro + + + + + + Resumo Financeiro + + + + Receitas + R$ + + + Despesas + R$ + + + Resultado Líquido + R$ + + + + + + + Histórico de Transações + Adicionar Transação + + + + + + + + + + Data + Descrição + Tipo + Categoria + Valor + + + + + + Nenhuma transação encontrada. + + + + + + + + + + R$ + + + + + + + + + + + + diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..6379e66 --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,4 @@ + + +
R$