diff --git a/api/equipamento_handler.php b/api/equipamento_handler.php new file mode 100644 index 0000000..ce5c19c --- /dev/null +++ b/api/equipamento_handler.php @@ -0,0 +1,38 @@ + false, 'message' => 'Invalid request']; +$pdoconn = db(); +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $data = json_decode(file_get_contents('php://input'), true); + + if (empty($data['nome']) || empty($data['status'])) { + $response['message'] = 'Nome and status are required.'; + } else { + try { + $sql = "INSERT INTO equipamentos (nome, categoria, numero_serie, status) VALUES (:nome, :categoria, :numero_serie, :status)"; + $stmt = $pdoconn->prepare($sql); + $stmt->execute([ + ':nome' => $data['nome'], + ':categoria' => $data['categoria'] ?? null, + ':numero_serie' => $data['numero_serie'] ?? null, + ':status' => $data['status'] + ]); + $response = ['success' => true, 'message' => 'Equipamento adicionado com sucesso!']; + } catch (PDOException $e) { + $response['message'] = 'Database error: ' . $e->getMessage(); + } + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') { + try { + $stmt = $pdoconn->query("SELECT id, nome, categoria, numero_serie, status FROM equipamentos ORDER BY created_at DESC"); + $equipamentos = $stmt->fetchAll(); + $response = ['success' => true, 'data' => $equipamentos]; + } catch (PDOException $e) { + $response['message'] = 'Database error: ' . $e->getMessage(); + } +} + +echo json_encode($response); +?> \ No newline at end of file diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..4d42fc8 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,65 @@ +body { + background-color: #F1FAEE; /* Off-white */ + font-family: 'Inter', sans-serif; + color: #1D3557; /* Dark blue text for contrast */ +} + +.toast-container { + position: fixed; + top: 1rem; + right: 1rem; + z-index: 1055; +} + +.navbar { + box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); + background-color: #ffffff; +} + +.hero { + background: linear-gradient(45deg, #E63946, #D62828); /* Vibrant Red Gradient */ + color: white; + padding: 6rem 0; + text-align: center; +} + +.hero h1 { + font-weight: 700; + font-size: 3.5rem; +} + +.hero p { + font-size: 1.25rem; + margin-bottom: 2rem; +} + +/* Button override */ +.btn-primary { + background-color: #E63946; + border-color: #E63946; +} + +.btn-primary:hover { + background-color: #D62828; + border-color: #D62828; +} + +/* Table header */ +.table > thead { + background-color: #E63946; + color: #ffffff; +} + +.table > thead th { + color: #ffffff; +} + +/* Modal Header */ +.modal-header { + background-color: #E63946; + color: #ffffff; +} + +.modal-header .btn-close { + filter: invert(1) grayscale(100%) brightness(200%); +} \ No newline at end of file diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..41b04e9 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,107 @@ +document.addEventListener('DOMContentLoaded', function () { + const addEquipmentForm = document.getElementById('addEquipmentForm'); + const addEquipmentModal = new bootstrap.Modal(document.getElementById('addEquipmentModal')); + + if (addEquipmentForm) { + addEquipmentForm.addEventListener('submit', function (e) { + e.preventDefault(); + + const formData = new FormData(addEquipmentForm); + const data = Object.fromEntries(formData.entries()); + + fetch('/api/equipamento_handler.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }) + .then(response => response.json()) + .then(result => { + showToast(result.message, result.success ? 'success' : 'danger'); + if (result.success) { + addEquipmentModal.hide(); + addEquipmentForm.reset(); + loadEquipment(); + } + }) + .catch(error => { + showToast('An error occurred.', 'danger'); + console.error('Error:', error); + }); + }); + } + + if (document.getElementById('equipmentTableBody')) { + loadEquipment(); + } +}); + +function loadEquipment() { + const tableBody = document.getElementById('equipmentTableBody'); + if (!tableBody) return; + + fetch('/api/equipamento_handler.php') + .then(response => response.json()) + .then(result => { + if (result.success) { + tableBody.innerHTML = ''; + if (result.data.length === 0) { + tableBody.innerHTML = 'Nenhum equipamento encontrado.'; + } + result.data.forEach(eq => { + const row = ` + ${eq.nome} + ${eq.categoria} + ${eq.numero_serie} + ${eq.status} + + + + `; + tableBody.innerHTML += row; + }); + } else { + showToast(result.message, 'danger'); + } + }) + .catch(error => { + showToast('Failed to load equipment.', 'danger'); + console.error('Error:', error); + }); +} + +function getBadgeClass(status) { + switch (status) { + case 'Disponível': + return 'success'; + case 'Em Manutenção': + return 'warning'; + case 'Danificado': + return 'danger'; + default: + return 'secondary'; + } +} + +function showToast(message, type = 'success') { + const toastContainer = document.getElementById('toast-container'); + if (!toastContainer) return; + + const toastId = 'toast-' + Date.now(); + const toastHTML = ` + `; + + toastContainer.innerHTML += toastHTML; + const toastElement = document.getElementById(toastId); + const toast = new bootstrap.Toast(toastElement, { delay: 5000 }); + toast.show(); + toastElement.addEventListener('hidden.bs.toast', () => toastElement.remove()); +} diff --git a/db/config.php b/db/config.php index bb98f7d..e063c9e 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,21 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; + $host = '127.0.0.1'; + $db = 'app'; + $user = 'app'; + $pass = 'password'; + $charset = 'utf8mb4'; + + $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; + $options = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + try { + return new PDO($dsn, $user, $pass, $options); + } catch (\PDOException $e) { + throw new \PDOException($e->getMessage(), (int)$e->getCode()); + } } +?> \ No newline at end of file diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..781c056 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,19 @@ +exec($sql); + echo "Database migration successful!"; +} catch (PDOException $e) { + die("Database migration failed: " . $e->getMessage()); +} +?> \ No newline at end of file diff --git a/equipamentos.php b/equipamentos.php new file mode 100644 index 0000000..220e317 --- /dev/null +++ b/equipamentos.php @@ -0,0 +1,119 @@ + + + + + + Lox - Inventário de Equipamentos + + + + + + + + + + + + + + + + + + + +
+
+

Inventário de Equipamentos

+ +
+ +
+
+
+ + + + + + + + + + + + + +
NomeCategoriaNº de SérieStatusAções
+
+
+
+
+ + + + + +
+ + + + + \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..6f37e4a 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,90 @@ - - - + + - - - New Style - - - - - - - - - - - - - - - - - - - + + + Lox - ERP para Locadoras de Equipamentos + + + + + + + + + + + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- + + + +
+
+

ERP Moderno para sua Locadora

+

Controle seu inventário, gerencie contratos e otimize suas operações com Lox.

+ Acessar o Painel +
+
+ +
+
+

Funcionalidades Principais

+
+
+
+
+
Gestão de Inventário
+

Adicione e gerencie todos os seus equipamentos em um só lugar.

+
+
+
+
+
+
+
Controle de Contratos
+

Crie cotações e converta-as em contratos de locação com facilidade.

+
+
+
+
+
+
+
Relatórios Inteligentes
+

Acompanhe a performance do seu negócio com relatórios detalhados.

+
+
+
+
+
+
+ + + + - + \ No newline at end of file