faça um aplicativo de gerenciamento de farmacia , use indexedb como banco de dados, backup e restauração do banco de dados, cadastro de clientes - Initial Deployment
Browse files- README.md +6 -4
- index.html +1062 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: teste
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: blue
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,1062 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="pt-BR">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>PharmaManager - Sistema de Gerenciamento de Farmácia</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
.sidebar {
|
| 11 |
+
transition: all 0.3s ease;
|
| 12 |
+
}
|
| 13 |
+
.sidebar.collapsed {
|
| 14 |
+
width: 70px;
|
| 15 |
+
}
|
| 16 |
+
.sidebar.collapsed .sidebar-text {
|
| 17 |
+
display: none;
|
| 18 |
+
}
|
| 19 |
+
.sidebar.collapsed .logo-text {
|
| 20 |
+
display: none;
|
| 21 |
+
}
|
| 22 |
+
.main-content {
|
| 23 |
+
transition: all 0.3s ease;
|
| 24 |
+
}
|
| 25 |
+
.main-content.expanded {
|
| 26 |
+
margin-left: 70px;
|
| 27 |
+
}
|
| 28 |
+
@media (max-width: 768px) {
|
| 29 |
+
.sidebar {
|
| 30 |
+
width: 0;
|
| 31 |
+
overflow: hidden;
|
| 32 |
+
}
|
| 33 |
+
.sidebar.collapsed {
|
| 34 |
+
width: 0;
|
| 35 |
+
}
|
| 36 |
+
.main-content {
|
| 37 |
+
margin-left: 0;
|
| 38 |
+
}
|
| 39 |
+
.mobile-menu-btn {
|
| 40 |
+
display: block;
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
.toast {
|
| 44 |
+
animation: fadeInOut 3s ease-in-out;
|
| 45 |
+
}
|
| 46 |
+
@keyframes fadeInOut {
|
| 47 |
+
0% { opacity: 0; }
|
| 48 |
+
10% { opacity: 1; }
|
| 49 |
+
90% { opacity: 1; }
|
| 50 |
+
100% { opacity: 0; }
|
| 51 |
+
}
|
| 52 |
+
</style>
|
| 53 |
+
</head>
|
| 54 |
+
<body class="bg-gray-100">
|
| 55 |
+
<!-- Mobile Menu Button -->
|
| 56 |
+
<button class="mobile-menu-btn fixed top-4 left-4 z-50 bg-blue-600 text-white p-2 rounded-md shadow-lg md:hidden">
|
| 57 |
+
<i class="fas fa-bars"></i>
|
| 58 |
+
</button>
|
| 59 |
+
|
| 60 |
+
<!-- Sidebar -->
|
| 61 |
+
<div class="sidebar fixed h-full bg-blue-800 text-white w-64 shadow-lg">
|
| 62 |
+
<div class="p-4 flex items-center">
|
| 63 |
+
<i class="fas fa-pills text-2xl mr-2"></i>
|
| 64 |
+
<span class="logo-text text-xl font-bold">PharmaManager</span>
|
| 65 |
+
</div>
|
| 66 |
+
<nav class="mt-6">
|
| 67 |
+
<div class="px-4 py-2 hover:bg-blue-700 cursor-pointer flex items-center">
|
| 68 |
+
<i class="fas fa-tachometer-alt mr-3"></i>
|
| 69 |
+
<span class="sidebar-text">Dashboard</span>
|
| 70 |
+
</div>
|
| 71 |
+
<div class="px-4 py-2 hover:bg-blue-700 cursor-pointer flex items-center" id="customer-nav">
|
| 72 |
+
<i class="fas fa-users mr-3"></i>
|
| 73 |
+
<span class="sidebar-text">Clientes</span>
|
| 74 |
+
</div>
|
| 75 |
+
<div class="px-4 py-2 hover:bg-blue-700 cursor-pointer flex items-center" id="products-nav">
|
| 76 |
+
<i class="fas fa-boxes mr-3"></i>
|
| 77 |
+
<span class="sidebar-text">Produtos</span>
|
| 78 |
+
</div>
|
| 79 |
+
<div class="px-4 py-2 hover:bg-blue-700 cursor-pointer flex items-center" id="sales-nav">
|
| 80 |
+
<i class="fas fa-shopping-cart mr-3"></i>
|
| 81 |
+
<span class="sidebar-text">Vendas</span>
|
| 82 |
+
</div>
|
| 83 |
+
<div class="px-4 py-2 hover:bg-blue-700 cursor-pointer flex items-center" id="inventory-nav">
|
| 84 |
+
<i class="fas fa-warehouse mr-3"></i>
|
| 85 |
+
<span class="sidebar-text">Estoque</span>
|
| 86 |
+
</div>
|
| 87 |
+
<div class="px-4 py-2 hover:bg-blue-700 cursor-pointer flex items-center" id="reports-nav">
|
| 88 |
+
<i class="fas fa-chart-bar mr-3"></i>
|
| 89 |
+
<span class="sidebar-text">Relatórios</span>
|
| 90 |
+
</div>
|
| 91 |
+
<div class="px-4 py-2 hover:bg-blue-700 cursor-pointer flex items-center" id="settings-nav">
|
| 92 |
+
<i class="fas fa-cog mr-3"></i>
|
| 93 |
+
<span class="sidebar-text">Configurações</span>
|
| 94 |
+
</div>
|
| 95 |
+
<div class="px-4 py-2 hover:bg-blue-700 cursor-pointer flex items-center" id="backup-nav">
|
| 96 |
+
<i class="fas fa-database mr-3"></i>
|
| 97 |
+
<span class="sidebar-text">Backup/Restore</span>
|
| 98 |
+
</div>
|
| 99 |
+
</nav>
|
| 100 |
+
</div>
|
| 101 |
+
|
| 102 |
+
<!-- Main Content -->
|
| 103 |
+
<div class="main-content ml-64 min-h-screen">
|
| 104 |
+
<!-- Header -->
|
| 105 |
+
<header class="bg-white shadow-sm p-4 flex justify-between items-center">
|
| 106 |
+
<h1 class="text-2xl font-semibold text-gray-800" id="page-title">Dashboard</h1>
|
| 107 |
+
<div class="flex items-center space-x-4">
|
| 108 |
+
<div class="relative">
|
| 109 |
+
<i class="fas fa-bell text-gray-600 cursor-pointer hover:text-blue-600"></i>
|
| 110 |
+
<span class="absolute -top-1 -right-1 bg-red-500 text-white text-xs rounded-full h-4 w-4 flex items-center justify-center">3</span>
|
| 111 |
+
</div>
|
| 112 |
+
<div class="flex items-center space-x-2">
|
| 113 |
+
<img src="https://via.placeholder.com/40" alt="User" class="rounded-full">
|
| 114 |
+
<span class="text-gray-700">Admin</span>
|
| 115 |
+
</div>
|
| 116 |
+
</div>
|
| 117 |
+
</header>
|
| 118 |
+
|
| 119 |
+
<!-- Content Area -->
|
| 120 |
+
<div class="p-6">
|
| 121 |
+
<!-- Dashboard Content (default) -->
|
| 122 |
+
<div id="dashboard-content">
|
| 123 |
+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-6">
|
| 124 |
+
<div class="bg-white p-6 rounded-lg shadow-md">
|
| 125 |
+
<div class="flex justify-between items-center">
|
| 126 |
+
<div>
|
| 127 |
+
<p class="text-gray-500">Clientes Cadastrados</p>
|
| 128 |
+
<h3 class="text-2xl font-bold" id="customer-count">0</h3>
|
| 129 |
+
</div>
|
| 130 |
+
<div class="bg-blue-100 p-3 rounded-full">
|
| 131 |
+
<i class="fas fa-users text-blue-600"></i>
|
| 132 |
+
</div>
|
| 133 |
+
</div>
|
| 134 |
+
</div>
|
| 135 |
+
<div class="bg-white p-6 rounded-lg shadow-md">
|
| 136 |
+
<div class="flex justify-between items-center">
|
| 137 |
+
<div>
|
| 138 |
+
<p class="text-gray-500">Produtos em Estoque</p>
|
| 139 |
+
<h3 class="text-2xl font-bold" id="product-count">0</h3>
|
| 140 |
+
</div>
|
| 141 |
+
<div class="bg-green-100 p-3 rounded-full">
|
| 142 |
+
<i class="fas fa-boxes text-green-600"></i>
|
| 143 |
+
</div>
|
| 144 |
+
</div>
|
| 145 |
+
</div>
|
| 146 |
+
<div class="bg-white p-6 rounded-lg shadow-md">
|
| 147 |
+
<div class="flex justify-between items-center">
|
| 148 |
+
<div>
|
| 149 |
+
<p class="text-gray-500">Vendas Hoje</p>
|
| 150 |
+
<h3 class="text-2xl font-bold" id="sales-today">0</h3>
|
| 151 |
+
</div>
|
| 152 |
+
<div class="bg-yellow-100 p-3 rounded-full">
|
| 153 |
+
<i class="fas fa-shopping-cart text-yellow-600"></i>
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
</div>
|
| 157 |
+
<div class="bg-white p-6 rounded-lg shadow-md">
|
| 158 |
+
<div class="flex justify-between items-center">
|
| 159 |
+
<div>
|
| 160 |
+
<p class="text-gray-500">Receita Mensal</p>
|
| 161 |
+
<h3 class="text-2xl font-bold" id="monthly-revenue">R$ 0,00</h3>
|
| 162 |
+
</div>
|
| 163 |
+
<div class="bg-purple-100 p-3 rounded-full">
|
| 164 |
+
<i class="fas fa-money-bill-wave text-purple-600"></i>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
</div>
|
| 169 |
+
|
| 170 |
+
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
| 171 |
+
<div class="bg-white p-6 rounded-lg shadow-md lg:col-span-2">
|
| 172 |
+
<h2 class="text-xl font-semibold mb-4">Vendas Recentes</h2>
|
| 173 |
+
<div class="overflow-x-auto">
|
| 174 |
+
<table class="min-w-full divide-y divide-gray-200">
|
| 175 |
+
<thead class="bg-gray-50">
|
| 176 |
+
<tr>
|
| 177 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
|
| 178 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cliente</th>
|
| 179 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Data</th>
|
| 180 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Total</th>
|
| 181 |
+
</tr>
|
| 182 |
+
</thead>
|
| 183 |
+
<tbody class="bg-white divide-y divide-gray-200" id="recent-sales">
|
| 184 |
+
<tr>
|
| 185 |
+
<td colspan="4" class="px-6 py-4 text-center text-gray-500">Nenhuma venda recente</td>
|
| 186 |
+
</tr>
|
| 187 |
+
</tbody>
|
| 188 |
+
</table>
|
| 189 |
+
</div>
|
| 190 |
+
</div>
|
| 191 |
+
<div class="bg-white p-6 rounded-lg shadow-md">
|
| 192 |
+
<h2 class="text-xl font-semibold mb-4">Estoque Baixo</h2>
|
| 193 |
+
<div class="space-y-4" id="low-stock">
|
| 194 |
+
<div class="text-center text-gray-500">Nenhum produto com estoque baixo</div>
|
| 195 |
+
</div>
|
| 196 |
+
</div>
|
| 197 |
+
</div>
|
| 198 |
+
</div>
|
| 199 |
+
|
| 200 |
+
<!-- Customer Management Content -->
|
| 201 |
+
<div id="customer-content" class="hidden">
|
| 202 |
+
<div class="flex justify-between items-center mb-6">
|
| 203 |
+
<h2 class="text-2xl font-semibold">Gerenciamento de Clientes</h2>
|
| 204 |
+
<button id="add-customer-btn" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 flex items-center">
|
| 205 |
+
<i class="fas fa-plus mr-2"></i> Novo Cliente
|
| 206 |
+
</button>
|
| 207 |
+
</div>
|
| 208 |
+
|
| 209 |
+
<div class="bg-white rounded-lg shadow-md overflow-hidden">
|
| 210 |
+
<div class="p-4 border-b flex justify-between items-center">
|
| 211 |
+
<div class="relative w-64">
|
| 212 |
+
<input type="text" id="customer-search" placeholder="Buscar clientes..." class="w-full pl-10 pr-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 213 |
+
<i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
|
| 214 |
+
</div>
|
| 215 |
+
<div class="flex space-x-2">
|
| 216 |
+
<button id="export-customers" class="bg-green-600 text-white px-3 py-1 rounded-md hover:bg-green-700 flex items-center">
|
| 217 |
+
<i class="fas fa-file-export mr-1"></i> Exportar
|
| 218 |
+
</button>
|
| 219 |
+
<button id="import-customers" class="bg-purple-600 text-white px-3 py-1 rounded-md hover:bg-purple-700 flex items-center">
|
| 220 |
+
<i class="fas fa-file-import mr-1"></i> Importar
|
| 221 |
+
</button>
|
| 222 |
+
</div>
|
| 223 |
+
</div>
|
| 224 |
+
<div class="overflow-x-auto">
|
| 225 |
+
<table class="min-w-full divide-y divide-gray-200">
|
| 226 |
+
<thead class="bg-gray-50">
|
| 227 |
+
<tr>
|
| 228 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
|
| 229 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nome</th>
|
| 230 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">CPF</th>
|
| 231 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Telefone</th>
|
| 232 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
|
| 233 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Ações</th>
|
| 234 |
+
</tr>
|
| 235 |
+
</thead>
|
| 236 |
+
<tbody class="bg-white divide-y divide-gray-200" id="customer-table-body">
|
| 237 |
+
<!-- Customer data will be inserted here -->
|
| 238 |
+
</tbody>
|
| 239 |
+
</table>
|
| 240 |
+
</div>
|
| 241 |
+
<div class="p-4 border-t flex justify-between items-center">
|
| 242 |
+
<div class="text-sm text-gray-500">
|
| 243 |
+
Mostrando <span id="customer-start">1</span> a <span id="customer-end">10</span> de <span id="customer-total">0</span> clientes
|
| 244 |
+
</div>
|
| 245 |
+
<div class="flex space-x-2">
|
| 246 |
+
<button id="customer-prev" class="px-3 py-1 border rounded-md disabled:opacity-50" disabled>Anterior</button>
|
| 247 |
+
<button id="customer-next" class="px-3 py-1 border rounded-md disabled:opacity-50" disabled>Próximo</button>
|
| 248 |
+
</div>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
|
| 253 |
+
<!-- Backup/Restore Content -->
|
| 254 |
+
<div id="backup-content" class="hidden">
|
| 255 |
+
<div class="flex justify-between items-center mb-6">
|
| 256 |
+
<h2 class="text-2xl font-semibold">Backup e Restauração</h2>
|
| 257 |
+
</div>
|
| 258 |
+
|
| 259 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
| 260 |
+
<div class="bg-white p-6 rounded-lg shadow-md">
|
| 261 |
+
<h3 class="text-xl font-semibold mb-4 flex items-center">
|
| 262 |
+
<i class="fas fa-download mr-2 text-blue-600"></i> Criar Backup
|
| 263 |
+
</h3>
|
| 264 |
+
<p class="text-gray-600 mb-4">Crie um backup completo do banco de dados para restaurar posteriormente.</p>
|
| 265 |
+
<button id="create-backup-btn" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 flex items-center w-full justify-center">
|
| 266 |
+
<i class="fas fa-save mr-2"></i> Criar Backup
|
| 267 |
+
</button>
|
| 268 |
+
</div>
|
| 269 |
+
|
| 270 |
+
<div class="bg-white p-6 rounded-lg shadow-md">
|
| 271 |
+
<h3 class="text-xl font-semibold mb-4 flex items-center">
|
| 272 |
+
<i class="fas fa-upload mr-2 text-green-600"></i> Restaurar Backup
|
| 273 |
+
</h3>
|
| 274 |
+
<p class="text-gray-600 mb-4">Restaurar o banco de dados a partir de um arquivo de backup.</p>
|
| 275 |
+
<div class="mb-4">
|
| 276 |
+
<label class="block text-gray-700 mb-2">Selecione o arquivo de backup:</label>
|
| 277 |
+
<input type="file" id="restore-file" class="block w-full text-sm text-gray-500
|
| 278 |
+
file:mr-4 file:py-2 file:px-4
|
| 279 |
+
file:rounded-md file:border-0
|
| 280 |
+
file:text-sm file:font-semibold
|
| 281 |
+
file:bg-blue-50 file:text-blue-700
|
| 282 |
+
hover:file:bg-blue-100">
|
| 283 |
+
</div>
|
| 284 |
+
<button id="restore-backup-btn" class="bg-green-600 text-white px-4 py-2 rounded-md hover:bg-green-700 flex items-center w-full justify-center">
|
| 285 |
+
<i class="fas fa-redo mr-2"></i> Restaurar Backup
|
| 286 |
+
</button>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
|
| 290 |
+
<div class="bg-white p-6 rounded-lg shadow-md mt-6">
|
| 291 |
+
<h3 class="text-xl font-semibold mb-4 flex items-center">
|
| 292 |
+
<i class="fas fa-history mr-2 text-purple-600"></i> Backups Disponíveis
|
| 293 |
+
</h3>
|
| 294 |
+
<div class="overflow-x-auto">
|
| 295 |
+
<table class="min-w-full divide-y divide-gray-200">
|
| 296 |
+
<thead class="bg-gray-50">
|
| 297 |
+
<tr>
|
| 298 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Data</th>
|
| 299 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Tamanho</th>
|
| 300 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Ações</th>
|
| 301 |
+
</tr>
|
| 302 |
+
</thead>
|
| 303 |
+
<tbody class="bg-white divide-y divide-gray-200" id="backup-list">
|
| 304 |
+
<!-- Backup data will be inserted here -->
|
| 305 |
+
</tbody>
|
| 306 |
+
</table>
|
| 307 |
+
</div>
|
| 308 |
+
</div>
|
| 309 |
+
</div>
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
|
| 313 |
+
<!-- Add Customer Modal -->
|
| 314 |
+
<div id="customer-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 315 |
+
<div class="bg-white rounded-lg shadow-xl w-full max-w-2xl max-h-[90vh] overflow-y-auto">
|
| 316 |
+
<div class="p-6">
|
| 317 |
+
<div class="flex justify-between items-center mb-4">
|
| 318 |
+
<h3 class="text-xl font-semibold" id="modal-title">Adicionar Novo Cliente</h3>
|
| 319 |
+
<button id="close-modal" class="text-gray-500 hover:text-gray-700">
|
| 320 |
+
<i class="fas fa-times"></i>
|
| 321 |
+
</button>
|
| 322 |
+
</div>
|
| 323 |
+
<form id="customer-form">
|
| 324 |
+
<input type="hidden" id="customer-id">
|
| 325 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
| 326 |
+
<div>
|
| 327 |
+
<label for="customer-name" class="block text-gray-700 mb-2">Nome Completo*</label>
|
| 328 |
+
<input type="text" id="customer-name" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
|
| 329 |
+
</div>
|
| 330 |
+
<div>
|
| 331 |
+
<label for="customer-cpf" class="block text-gray-700 mb-2">CPF*</label>
|
| 332 |
+
<input type="text" id="customer-cpf" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
|
| 333 |
+
</div>
|
| 334 |
+
</div>
|
| 335 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
| 336 |
+
<div>
|
| 337 |
+
<label for="customer-phone" class="block text-gray-700 mb-2">Telefone*</label>
|
| 338 |
+
<input type="text" id="customer-phone" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
|
| 339 |
+
</div>
|
| 340 |
+
<div>
|
| 341 |
+
<label for="customer-email" class="block text-gray-700 mb-2">Email</label>
|
| 342 |
+
<input type="email" id="customer-email" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 343 |
+
</div>
|
| 344 |
+
</div>
|
| 345 |
+
<div class="mb-4">
|
| 346 |
+
<label for="customer-address" class="block text-gray-700 mb-2">Endereço</label>
|
| 347 |
+
<input type="text" id="customer-address" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 348 |
+
</div>
|
| 349 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
|
| 350 |
+
<div>
|
| 351 |
+
<label for="customer-city" class="block text-gray-700 mb-2">Cidade</label>
|
| 352 |
+
<input type="text" id="customer-city" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 353 |
+
</div>
|
| 354 |
+
<div>
|
| 355 |
+
<label for="customer-state" class="block text-gray-700 mb-2">Estado</label>
|
| 356 |
+
<input type="text" id="customer-state" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 357 |
+
</div>
|
| 358 |
+
<div>
|
| 359 |
+
<label for="customer-zip" class="block text-gray-700 mb-2">CEP</label>
|
| 360 |
+
<input type="text" id="customer-zip" class="w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 361 |
+
</div>
|
| 362 |
+
</div>
|
| 363 |
+
<div class="flex justify-end space-x-3">
|
| 364 |
+
<button type="button" id="cancel-customer" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-100">Cancelar</button>
|
| 365 |
+
<button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Salvar</button>
|
| 366 |
+
</div>
|
| 367 |
+
</form>
|
| 368 |
+
</div>
|
| 369 |
+
</div>
|
| 370 |
+
</div>
|
| 371 |
+
|
| 372 |
+
<!-- Toast Notification -->
|
| 373 |
+
<div id="toast" class="fixed bottom-4 right-4 bg-green-500 text-white px-6 py-3 rounded-md shadow-lg hidden">
|
| 374 |
+
<div class="flex items-center">
|
| 375 |
+
<i class="fas fa-check-circle mr-2"></i>
|
| 376 |
+
<span id="toast-message">Operação realizada com sucesso!</span>
|
| 377 |
+
</div>
|
| 378 |
+
</div>
|
| 379 |
+
|
| 380 |
+
<!-- Confirmation Modal -->
|
| 381 |
+
<div id="confirm-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 382 |
+
<div class="bg-white rounded-lg shadow-xl w-full max-w-md">
|
| 383 |
+
<div class="p-6">
|
| 384 |
+
<div class="flex justify-between items-center mb-4">
|
| 385 |
+
<h3 class="text-xl font-semibold" id="confirm-title">Confirmar ação</h3>
|
| 386 |
+
<button id="close-confirm" class="text-gray-500 hover:text-gray-700">
|
| 387 |
+
<i class="fas fa-times"></i>
|
| 388 |
+
</button>
|
| 389 |
+
</div>
|
| 390 |
+
<p id="confirm-message">Tem certeza que deseja realizar esta ação?</p>
|
| 391 |
+
<div class="flex justify-end space-x-3 mt-6">
|
| 392 |
+
<button type="button" id="cancel-confirm" class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-100">Cancelar</button>
|
| 393 |
+
<button type="button" id="confirm-action" class="px-4 py-2 bg-red-600 text-white rounded-md hover:bg-red-700">Confirmar</button>
|
| 394 |
+
</div>
|
| 395 |
+
</div>
|
| 396 |
+
</div>
|
| 397 |
+
</div>
|
| 398 |
+
|
| 399 |
+
<script>
|
| 400 |
+
// Database setup
|
| 401 |
+
let db;
|
| 402 |
+
const DB_NAME = "PharmaManagerDB";
|
| 403 |
+
const DB_VERSION = 1;
|
| 404 |
+
|
| 405 |
+
// Open or create database
|
| 406 |
+
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
| 407 |
+
|
| 408 |
+
request.onupgradeneeded = (event) => {
|
| 409 |
+
db = event.target.result;
|
| 410 |
+
|
| 411 |
+
// Create customers store
|
| 412 |
+
if (!db.objectStoreNames.contains('customers')) {
|
| 413 |
+
const customersStore = db.createObjectStore('customers', { keyPath: 'id', autoIncrement: true });
|
| 414 |
+
customersStore.createIndex('name', 'name', { unique: false });
|
| 415 |
+
customersStore.createIndex('cpf', 'cpf', { unique: true });
|
| 416 |
+
customersStore.createIndex('phone', 'phone', { unique: false });
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
// Create products store
|
| 420 |
+
if (!db.objectStoreNames.contains('products')) {
|
| 421 |
+
const productsStore = db.createObjectStore('products', { keyPath: 'id', autoIncrement: true });
|
| 422 |
+
productsStore.createIndex('name', 'name', { unique: false });
|
| 423 |
+
productsStore.createIndex('barcode', 'barcode', { unique: true });
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
// Create sales store
|
| 427 |
+
if (!db.objectStoreNames.contains('sales')) {
|
| 428 |
+
const salesStore = db.createObjectStore('sales', { keyPath: 'id', autoIncrement: true });
|
| 429 |
+
salesStore.createIndex('customerId', 'customerId', { unique: false });
|
| 430 |
+
salesStore.createIndex('date', 'date', { unique: false });
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
// Create backups store
|
| 434 |
+
if (!db.objectStoreNames.contains('backups')) {
|
| 435 |
+
db.createObjectStore('backups', { keyPath: 'id', autoIncrement: true });
|
| 436 |
+
}
|
| 437 |
+
};
|
| 438 |
+
|
| 439 |
+
request.onsuccess = (event) => {
|
| 440 |
+
db = event.target.result;
|
| 441 |
+
console.log("Database opened successfully");
|
| 442 |
+
updateDashboardCounts();
|
| 443 |
+
loadCustomers();
|
| 444 |
+
loadBackups();
|
| 445 |
+
};
|
| 446 |
+
|
| 447 |
+
request.onerror = (event) => {
|
| 448 |
+
console.error("Database error:", event.target.error);
|
| 449 |
+
};
|
| 450 |
+
|
| 451 |
+
// UI Functions
|
| 452 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 453 |
+
// Mobile menu toggle
|
| 454 |
+
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
|
| 455 |
+
const sidebar = document.querySelector('.sidebar');
|
| 456 |
+
const mainContent = document.querySelector('.main-content');
|
| 457 |
+
|
| 458 |
+
mobileMenuBtn.addEventListener('click', () => {
|
| 459 |
+
sidebar.classList.toggle('hidden');
|
| 460 |
+
});
|
| 461 |
+
|
| 462 |
+
// Navigation
|
| 463 |
+
document.getElementById('customer-nav').addEventListener('click', () => {
|
| 464 |
+
showSection('customer-content', 'Clientes');
|
| 465 |
+
loadCustomers();
|
| 466 |
+
});
|
| 467 |
+
|
| 468 |
+
document.getElementById('backup-nav').addEventListener('click', () => {
|
| 469 |
+
showSection('backup-content', 'Backup/Restore');
|
| 470 |
+
loadBackups();
|
| 471 |
+
});
|
| 472 |
+
|
| 473 |
+
// Customer management
|
| 474 |
+
document.getElementById('add-customer-btn').addEventListener('click', () => {
|
| 475 |
+
openCustomerModal();
|
| 476 |
+
});
|
| 477 |
+
|
| 478 |
+
document.getElementById('close-modal').addEventListener('click', () => {
|
| 479 |
+
closeCustomerModal();
|
| 480 |
+
});
|
| 481 |
+
|
| 482 |
+
document.getElementById('cancel-customer').addEventListener('click', () => {
|
| 483 |
+
closeCustomerModal();
|
| 484 |
+
});
|
| 485 |
+
|
| 486 |
+
document.getElementById('customer-form').addEventListener('submit', (e) => {
|
| 487 |
+
e.preventDefault();
|
| 488 |
+
saveCustomer();
|
| 489 |
+
});
|
| 490 |
+
|
| 491 |
+
// Backup functionality
|
| 492 |
+
document.getElementById('create-backup-btn').addEventListener('click', () => {
|
| 493 |
+
createBackup();
|
| 494 |
+
});
|
| 495 |
+
|
| 496 |
+
document.getElementById('restore-backup-btn').addEventListener('click', () => {
|
| 497 |
+
restoreBackup();
|
| 498 |
+
});
|
| 499 |
+
|
| 500 |
+
// Initialize dashboard
|
| 501 |
+
showSection('dashboard-content', 'Dashboard');
|
| 502 |
+
});
|
| 503 |
+
|
| 504 |
+
function showSection(sectionId, title) {
|
| 505 |
+
// Hide all sections
|
| 506 |
+
document.querySelectorAll('[id$="-content"]').forEach(section => {
|
| 507 |
+
section.classList.add('hidden');
|
| 508 |
+
});
|
| 509 |
+
|
| 510 |
+
// Show selected section
|
| 511 |
+
document.getElementById(sectionId).classList.remove('hidden');
|
| 512 |
+
|
| 513 |
+
// Update page title
|
| 514 |
+
document.getElementById('page-title').textContent = title;
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
// Customer functions
|
| 518 |
+
function loadCustomers(page = 1, search = '') {
|
| 519 |
+
const transaction = db.transaction(['customers'], 'readonly');
|
| 520 |
+
const store = transaction.objectStore('customers');
|
| 521 |
+
const request = store.getAll();
|
| 522 |
+
|
| 523 |
+
request.onsuccess = () => {
|
| 524 |
+
const customers = request.result;
|
| 525 |
+
let filteredCustomers = customers;
|
| 526 |
+
|
| 527 |
+
// Apply search filter
|
| 528 |
+
if (search) {
|
| 529 |
+
const searchTerm = search.toLowerCase();
|
| 530 |
+
filteredCustomers = customers.filter(customer =>
|
| 531 |
+
customer.name.toLowerCase().includes(searchTerm) ||
|
| 532 |
+
customer.cpf.includes(searchTerm) ||
|
| 533 |
+
customer.phone.includes(searchTerm) ||
|
| 534 |
+
(customer.email && customer.email.toLowerCase().includes(searchTerm))
|
| 535 |
+
);
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
// Pagination
|
| 539 |
+
const itemsPerPage = 10;
|
| 540 |
+
const startIndex = (page - 1) * itemsPerPage;
|
| 541 |
+
const endIndex = startIndex + itemsPerPage;
|
| 542 |
+
const paginatedCustomers = filteredCustomers.slice(startIndex, endIndex);
|
| 543 |
+
const totalPages = Math.ceil(filteredCustomers.length / itemsPerPage);
|
| 544 |
+
|
| 545 |
+
// Update table
|
| 546 |
+
const tbody = document.getElementById('customer-table-body');
|
| 547 |
+
tbody.innerHTML = '';
|
| 548 |
+
|
| 549 |
+
if (paginatedCustomers.length === 0) {
|
| 550 |
+
const row = document.createElement('tr');
|
| 551 |
+
row.innerHTML = `<td colspan="6" class="px-6 py-4 text-center text-gray-500">Nenhum cliente encontrado</td>`;
|
| 552 |
+
tbody.appendChild(row);
|
| 553 |
+
} else {
|
| 554 |
+
paginatedCustomers.forEach(customer => {
|
| 555 |
+
const row = document.createElement('tr');
|
| 556 |
+
row.innerHTML = `
|
| 557 |
+
<td class="px-6 py-4 whitespace-nowrap">${customer.id}</td>
|
| 558 |
+
<td class="px-6 py-4 whitespace-nowrap">${customer.name}</td>
|
| 559 |
+
<td class="px-6 py-4 whitespace-nowrap">${formatCPF(customer.cpf)}</td>
|
| 560 |
+
<td class="px-6 py-4 whitespace-nowrap">${formatPhone(customer.phone)}</td>
|
| 561 |
+
<td class="px-6 py-4 whitespace-nowrap">${customer.email || '-'}</td>
|
| 562 |
+
<td class="px-6 py-4 whitespace-nowrap">
|
| 563 |
+
<button class="edit-customer text-blue-600 hover:text-blue-800 mr-3" data-id="${customer.id}">
|
| 564 |
+
<i class="fas fa-edit"></i>
|
| 565 |
+
</button>
|
| 566 |
+
<button class="delete-customer text-red-600 hover:text-red-800" data-id="${customer.id}">
|
| 567 |
+
<i class="fas fa-trash"></i>
|
| 568 |
+
</button>
|
| 569 |
+
</td>
|
| 570 |
+
`;
|
| 571 |
+
tbody.appendChild(row);
|
| 572 |
+
});
|
| 573 |
+
|
| 574 |
+
// Add event listeners to edit/delete buttons
|
| 575 |
+
document.querySelectorAll('.edit-customer').forEach(btn => {
|
| 576 |
+
btn.addEventListener('click', (e) => {
|
| 577 |
+
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 578 |
+
editCustomer(id);
|
| 579 |
+
});
|
| 580 |
+
});
|
| 581 |
+
|
| 582 |
+
document.querySelectorAll('.delete-customer').forEach(btn => {
|
| 583 |
+
btn.addEventListener('click', (e) => {
|
| 584 |
+
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 585 |
+
confirmDeleteCustomer(id);
|
| 586 |
+
});
|
| 587 |
+
});
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
// Update pagination info
|
| 591 |
+
document.getElementById('customer-start').textContent = startIndex + 1;
|
| 592 |
+
document.getElementById('customer-end').textContent = Math.min(endIndex, filteredCustomers.length);
|
| 593 |
+
document.getElementById('customer-total').textContent = filteredCustomers.length;
|
| 594 |
+
|
| 595 |
+
// Update pagination buttons
|
| 596 |
+
const prevBtn = document.getElementById('customer-prev');
|
| 597 |
+
const nextBtn = document.getElementById('customer-next');
|
| 598 |
+
|
| 599 |
+
prevBtn.disabled = page <= 1;
|
| 600 |
+
nextBtn.disabled = page >= totalPages;
|
| 601 |
+
|
| 602 |
+
prevBtn.onclick = () => loadCustomers(page - 1, search);
|
| 603 |
+
nextBtn.onclick = () => loadCustomers(page + 1, search);
|
| 604 |
+
};
|
| 605 |
+
|
| 606 |
+
request.onerror = () => {
|
| 607 |
+
console.error("Error loading customers");
|
| 608 |
+
};
|
| 609 |
+
}
|
| 610 |
+
|
| 611 |
+
function openCustomerModal(customer = null) {
|
| 612 |
+
const modal = document.getElementById('customer-modal');
|
| 613 |
+
const form = document.getElementById('customer-form');
|
| 614 |
+
|
| 615 |
+
if (customer) {
|
| 616 |
+
document.getElementById('modal-title').textContent = 'Editar Cliente';
|
| 617 |
+
document.getElementById('customer-id').value = customer.id;
|
| 618 |
+
document.getElementById('customer-name').value = customer.name;
|
| 619 |
+
document.getElementById('customer-cpf').value = customer.cpf;
|
| 620 |
+
document.getElementById('customer-phone').value = customer.phone;
|
| 621 |
+
document.getElementById('customer-email').value = customer.email || '';
|
| 622 |
+
document.getElementById('customer-address').value = customer.address || '';
|
| 623 |
+
document.getElementById('customer-city').value = customer.city || '';
|
| 624 |
+
document.getElementById('customer-state').value = customer.state || '';
|
| 625 |
+
document.getElementById('customer-zip').value = customer.zip || '';
|
| 626 |
+
} else {
|
| 627 |
+
document.getElementById('modal-title').textContent = 'Adicionar Novo Cliente';
|
| 628 |
+
form.reset();
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
modal.classList.remove('hidden');
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
function closeCustomerModal() {
|
| 635 |
+
document.getElementById('customer-modal').classList.add('hidden');
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
function saveCustomer() {
|
| 639 |
+
const id = document.getElementById('customer-id').value;
|
| 640 |
+
const customer = {
|
| 641 |
+
name: document.getElementById('customer-name').value.trim(),
|
| 642 |
+
cpf: document.getElementById('customer-cpf').value.replace(/\D/g, ''),
|
| 643 |
+
phone: document.getElementById('customer-phone').value.replace(/\D/g, ''),
|
| 644 |
+
email: document.getElementById('customer-email').value.trim() || null,
|
| 645 |
+
address: document.getElementById('customer-address').value.trim() || null,
|
| 646 |
+
city: document.getElementById('customer-city').value.trim() || null,
|
| 647 |
+
state: document.getElementById('customer-state').value.trim() || null,
|
| 648 |
+
zip: document.getElementById('customer-zip').value.replace(/\D/g, '') || null
|
| 649 |
+
};
|
| 650 |
+
|
| 651 |
+
if (!customer.name || !customer.cpf || !customer.phone) {
|
| 652 |
+
showToast('Por favor, preencha os campos obrigatórios', 'error');
|
| 653 |
+
return;
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
const transaction = db.transaction(['customers'], 'readwrite');
|
| 657 |
+
const store = transaction.objectStore('customers');
|
| 658 |
+
|
| 659 |
+
if (id) {
|
| 660 |
+
customer.id = parseInt(id);
|
| 661 |
+
const request = store.put(customer);
|
| 662 |
+
|
| 663 |
+
request.onsuccess = () => {
|
| 664 |
+
showToast('Cliente atualizado com sucesso!');
|
| 665 |
+
closeCustomerModal();
|
| 666 |
+
loadCustomers();
|
| 667 |
+
updateDashboardCounts();
|
| 668 |
+
};
|
| 669 |
+
|
| 670 |
+
request.onerror = () => {
|
| 671 |
+
showToast('Erro ao atualizar cliente', 'error');
|
| 672 |
+
};
|
| 673 |
+
} else {
|
| 674 |
+
const request = store.add(customer);
|
| 675 |
+
|
| 676 |
+
request.onsuccess = () => {
|
| 677 |
+
showToast('Cliente cadastrado com sucesso!');
|
| 678 |
+
closeCustomerModal();
|
| 679 |
+
loadCustomers();
|
| 680 |
+
updateDashboardCounts();
|
| 681 |
+
};
|
| 682 |
+
|
| 683 |
+
request.onerror = (e) => {
|
| 684 |
+
if (e.target.error.name === 'ConstraintError') {
|
| 685 |
+
showToast('CPF já cadastrado', 'error');
|
| 686 |
+
} else {
|
| 687 |
+
showToast('Erro ao cadastrar cliente', 'error');
|
| 688 |
+
}
|
| 689 |
+
};
|
| 690 |
+
}
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
function editCustomer(id) {
|
| 694 |
+
const transaction = db.transaction(['customers'], 'readonly');
|
| 695 |
+
const store = transaction.objectStore('customers');
|
| 696 |
+
const request = store.get(id);
|
| 697 |
+
|
| 698 |
+
request.onsuccess = () => {
|
| 699 |
+
openCustomerModal(request.result);
|
| 700 |
+
};
|
| 701 |
+
|
| 702 |
+
request.onerror = () => {
|
| 703 |
+
showToast('Erro ao carregar cliente', 'error');
|
| 704 |
+
};
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
function confirmDeleteCustomer(id) {
|
| 708 |
+
const modal = document.getElementById('confirm-modal');
|
| 709 |
+
document.getElementById('confirm-title').textContent = 'Excluir Cliente';
|
| 710 |
+
document.getElementById('confirm-message').textContent = 'Tem certeza que deseja excluir este cliente? Esta ação não pode ser desfeita.';
|
| 711 |
+
|
| 712 |
+
document.getElementById('confirm-action').onclick = () => {
|
| 713 |
+
deleteCustomer(id);
|
| 714 |
+
modal.classList.add('hidden');
|
| 715 |
+
};
|
| 716 |
+
|
| 717 |
+
modal.classList.remove('hidden');
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
function deleteCustomer(id) {
|
| 721 |
+
const transaction = db.transaction(['customers'], 'readwrite');
|
| 722 |
+
const store = transaction.objectStore('customers');
|
| 723 |
+
const request = store.delete(id);
|
| 724 |
+
|
| 725 |
+
request.onsuccess = () => {
|
| 726 |
+
showToast('Cliente excluído com sucesso!');
|
| 727 |
+
loadCustomers();
|
| 728 |
+
updateDashboardCounts();
|
| 729 |
+
};
|
| 730 |
+
|
| 731 |
+
request.onerror = () => {
|
| 732 |
+
showToast('Erro ao excluir cliente', 'error');
|
| 733 |
+
};
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
// Backup functions
|
| 737 |
+
function createBackup() {
|
| 738 |
+
// Get all data from the database
|
| 739 |
+
const transaction = db.transaction(['customers', 'products', 'sales'], 'readonly');
|
| 740 |
+
|
| 741 |
+
const customersRequest = transaction.objectStore('customers').getAll();
|
| 742 |
+
const productsRequest = transaction.objectStore('products').getAll();
|
| 743 |
+
const salesRequest = transaction.objectStore('sales').getAll();
|
| 744 |
+
|
| 745 |
+
Promise.all([
|
| 746 |
+
new Promise(resolve => { customersRequest.onsuccess = () => resolve(customersRequest.result); }),
|
| 747 |
+
new Promise(resolve => { productsRequest.onsuccess = () => resolve(productsRequest.result); }),
|
| 748 |
+
new Promise(resolve => { salesRequest.onsuccess = () => resolve(salesRequest.result); })
|
| 749 |
+
]).then(([customers, products, sales]) => {
|
| 750 |
+
const backupData = {
|
| 751 |
+
timestamp: new Date().getTime(),
|
| 752 |
+
date: new Date().toISOString(),
|
| 753 |
+
customers,
|
| 754 |
+
products,
|
| 755 |
+
sales
|
| 756 |
+
};
|
| 757 |
+
|
| 758 |
+
// Save backup to IndexedDB
|
| 759 |
+
const backupTransaction = db.transaction(['backups'], 'readwrite');
|
| 760 |
+
const backupStore = backupTransaction.objectStore('backups');
|
| 761 |
+
backupStore.add(backupData);
|
| 762 |
+
|
| 763 |
+
backupTransaction.oncomplete = () => {
|
| 764 |
+
showToast('Backup criado com sucesso!');
|
| 765 |
+
loadBackups();
|
| 766 |
+
|
| 767 |
+
// Create download link
|
| 768 |
+
const dataStr = JSON.stringify(backupData);
|
| 769 |
+
const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr);
|
| 770 |
+
|
| 771 |
+
const exportName = `pharmamanager_backup_${new Date().toISOString().slice(0, 10)}.json`;
|
| 772 |
+
|
| 773 |
+
const linkElement = document.createElement('a');
|
| 774 |
+
linkElement.setAttribute('href', dataUri);
|
| 775 |
+
linkElement.setAttribute('download', exportName);
|
| 776 |
+
linkElement.click();
|
| 777 |
+
};
|
| 778 |
+
|
| 779 |
+
backupTransaction.onerror = () => {
|
| 780 |
+
showToast('Erro ao salvar backup local', 'error');
|
| 781 |
+
};
|
| 782 |
+
}).catch(error => {
|
| 783 |
+
console.error("Backup error:", error);
|
| 784 |
+
showToast('Erro ao criar backup', 'error');
|
| 785 |
+
});
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
function restoreBackup() {
|
| 789 |
+
const fileInput = document.getElementById('restore-file');
|
| 790 |
+
const file = fileInput.files[0];
|
| 791 |
+
|
| 792 |
+
if (!file) {
|
| 793 |
+
showToast('Selecione um arquivo de backup', 'error');
|
| 794 |
+
return;
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
const reader = new FileReader();
|
| 798 |
+
reader.onload = (event) => {
|
| 799 |
+
try {
|
| 800 |
+
const backupData = JSON.parse(event.target.result);
|
| 801 |
+
|
| 802 |
+
// Confirm restore
|
| 803 |
+
const modal = document.getElementById('confirm-modal');
|
| 804 |
+
document.getElementById('confirm-title').textContent = 'Restaurar Backup';
|
| 805 |
+
document.getElementById('confirm-message').textContent = `Tem certeza que deseja restaurar o backup de ${new Date(backupData.timestamp).toLocaleString()}? Todos os dados atuais serão substituídos.`;
|
| 806 |
+
|
| 807 |
+
document.getElementById('confirm-action').onclick = () => {
|
| 808 |
+
performRestore(backupData);
|
| 809 |
+
modal.classList.add('hidden');
|
| 810 |
+
};
|
| 811 |
+
|
| 812 |
+
modal.classList.remove('hidden');
|
| 813 |
+
} catch (e) {
|
| 814 |
+
console.error("Error parsing backup file:", e);
|
| 815 |
+
showToast('Arquivo de backup inválido', 'error');
|
| 816 |
+
}
|
| 817 |
+
};
|
| 818 |
+
reader.readAsText(file);
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
function performRestore(backupData) {
|
| 822 |
+
// Start a transaction for all object stores
|
| 823 |
+
const transaction = db.transaction(['customers', 'products', 'sales', 'backups'], 'readwrite');
|
| 824 |
+
|
| 825 |
+
// Clear existing data
|
| 826 |
+
transaction.objectStore('customers').clear();
|
| 827 |
+
transaction.objectStore('products').clear();
|
| 828 |
+
transaction.objectStore('sales').clear();
|
| 829 |
+
|
| 830 |
+
// Add backup data
|
| 831 |
+
backupData.customers.forEach(customer => {
|
| 832 |
+
transaction.objectStore('customers').add(customer);
|
| 833 |
+
});
|
| 834 |
+
|
| 835 |
+
backupData.products.forEach(product => {
|
| 836 |
+
transaction.objectStore('products').add(product);
|
| 837 |
+
});
|
| 838 |
+
|
| 839 |
+
backupData.sales.forEach(sale => {
|
| 840 |
+
transaction.objectStore('sales').add(sale);
|
| 841 |
+
});
|
| 842 |
+
|
| 843 |
+
// Add to backups list
|
| 844 |
+
transaction.objectStore('backups').add(backupData);
|
| 845 |
+
|
| 846 |
+
transaction.oncomplete = () => {
|
| 847 |
+
showToast('Backup restaurado com sucesso!');
|
| 848 |
+
loadCustomers();
|
| 849 |
+
updateDashboardCounts();
|
| 850 |
+
loadBackups();
|
| 851 |
+
};
|
| 852 |
+
|
| 853 |
+
transaction.onerror = () => {
|
| 854 |
+
showToast('Erro ao restaurar backup', 'error');
|
| 855 |
+
};
|
| 856 |
+
}
|
| 857 |
+
|
| 858 |
+
function loadBackups() {
|
| 859 |
+
const transaction = db.transaction(['backups'], 'readonly');
|
| 860 |
+
const store = transaction.objectStore('backups');
|
| 861 |
+
const request = store.getAll();
|
| 862 |
+
|
| 863 |
+
request.onsuccess = () => {
|
| 864 |
+
const backups = request.result;
|
| 865 |
+
const tbody = document.getElementById('backup-list');
|
| 866 |
+
tbody.innerHTML = '';
|
| 867 |
+
|
| 868 |
+
if (backups.length === 0) {
|
| 869 |
+
const row = document.createElement('tr');
|
| 870 |
+
row.innerHTML = `<td colspan="3" class="px-6 py-4 text-center text-gray-500">Nenhum backup disponível</td>`;
|
| 871 |
+
tbody.appendChild(row);
|
| 872 |
+
} else {
|
| 873 |
+
// Sort by timestamp (newest first)
|
| 874 |
+
backups.sort((a, b) => b.timestamp - a.timestamp);
|
| 875 |
+
|
| 876 |
+
backups.forEach(backup => {
|
| 877 |
+
const date = new Date(backup.timestamp);
|
| 878 |
+
const size = JSON.stringify(backup).length;
|
| 879 |
+
const sizeKB = (size / 1024).toFixed(2);
|
| 880 |
+
|
| 881 |
+
const row = document.createElement('tr');
|
| 882 |
+
row.innerHTML = `
|
| 883 |
+
<td class="px-6 py-4 whitespace-nowrap">${date.toLocaleString()}</td>
|
| 884 |
+
<td class="px-6 py-4 whitespace-nowrap">${sizeKB} KB</td>
|
| 885 |
+
<td class="px-6 py-4 whitespace-nowrap">
|
| 886 |
+
<button class="download-backup text-blue-600 hover:text-blue-800 mr-3" data-id="${backup.id}">
|
| 887 |
+
<i class="fas fa-download"></i> Download
|
| 888 |
+
</button>
|
| 889 |
+
<button class="restore-from-list text-green-600 hover:text-green-800" data-id="${backup.id}">
|
| 890 |
+
<i class="fas fa-redo"></i> Restaurar
|
| 891 |
+
</button>
|
| 892 |
+
</td>
|
| 893 |
+
`;
|
| 894 |
+
tbody.appendChild(row);
|
| 895 |
+
});
|
| 896 |
+
|
| 897 |
+
// Add event listeners
|
| 898 |
+
document.querySelectorAll('.download-backup').forEach(btn => {
|
| 899 |
+
btn.addEventListener('click', (e) => {
|
| 900 |
+
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 901 |
+
downloadBackup(id);
|
| 902 |
+
});
|
| 903 |
+
});
|
| 904 |
+
|
| 905 |
+
document.querySelectorAll('.restore-from-list').forEach(btn => {
|
| 906 |
+
btn.addEventListener('click', (e) => {
|
| 907 |
+
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 908 |
+
confirmRestoreBackup(id);
|
| 909 |
+
});
|
| 910 |
+
});
|
| 911 |
+
}
|
| 912 |
+
};
|
| 913 |
+
}
|
| 914 |
+
|
| 915 |
+
function downloadBackup(id) {
|
| 916 |
+
const transaction = db.transaction(['backups'], 'readonly');
|
| 917 |
+
const store = transaction.objectStore('backups');
|
| 918 |
+
const request = store.get(id);
|
| 919 |
+
|
| 920 |
+
request.onsuccess = () => {
|
| 921 |
+
const backupData = request.result;
|
| 922 |
+
const dataStr = JSON.stringify(backupData);
|
| 923 |
+
const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr);
|
| 924 |
+
|
| 925 |
+
const exportName = `pharmamanager_backup_${new Date(backupData.timestamp).toISOString().slice(0, 10)}.json`;
|
| 926 |
+
|
| 927 |
+
const linkElement = document.createElement('a');
|
| 928 |
+
linkElement.setAttribute('href', dataUri);
|
| 929 |
+
linkElement.setAttribute('download', exportName);
|
| 930 |
+
linkElement.click();
|
| 931 |
+
|
| 932 |
+
showToast('Download do backup iniciado');
|
| 933 |
+
};
|
| 934 |
+
}
|
| 935 |
+
|
| 936 |
+
function confirmRestoreBackup(id) {
|
| 937 |
+
const modal = document.getElementById('confirm-modal');
|
| 938 |
+
document.getElementById('confirm-title').textContent = 'Restaurar Backup';
|
| 939 |
+
document.getElementById('confirm-message').textContent = 'Tem certeza que deseja restaurar este backup? Todos os dados atuais serão substituídos.';
|
| 940 |
+
|
| 941 |
+
document.getElementById('confirm-action').onclick = () => {
|
| 942 |
+
restoreFromBackup(id);
|
| 943 |
+
modal.classList.add('hidden');
|
| 944 |
+
};
|
| 945 |
+
|
| 946 |
+
modal.classList.remove('hidden');
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
function restoreFromBackup(id) {
|
| 950 |
+
const transaction = db.transaction(['backups'], 'readonly');
|
| 951 |
+
const store = transaction.objectStore('backups');
|
| 952 |
+
const request = store.get(id);
|
| 953 |
+
|
| 954 |
+
request.onsuccess = () => {
|
| 955 |
+
performRestore(request.result);
|
| 956 |
+
};
|
| 957 |
+
|
| 958 |
+
request.onerror = () => {
|
| 959 |
+
showToast('Erro ao carregar backup', 'error');
|
| 960 |
+
};
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
// Dashboard functions
|
| 964 |
+
function updateDashboardCounts() {
|
| 965 |
+
// Customer count
|
| 966 |
+
const customerTransaction = db.transaction(['customers'], 'readonly');
|
| 967 |
+
const customerStore = customerTransaction.objectStore('customers');
|
| 968 |
+
const customerCountRequest = customerStore.count();
|
| 969 |
+
|
| 970 |
+
customerCountRequest.onsuccess = () => {
|
| 971 |
+
document.getElementById('customer-count').textContent = customerCountRequest.result;
|
| 972 |
+
};
|
| 973 |
+
|
| 974 |
+
// Product count
|
| 975 |
+
const productTransaction = db.transaction(['products'], 'readonly');
|
| 976 |
+
const productStore = productTransaction.objectStore('products');
|
| 977 |
+
const productCountRequest = productStore.count();
|
| 978 |
+
|
| 979 |
+
productCountRequest.onsuccess = () => {
|
| 980 |
+
document.getElementById('product-count').textContent = productCountRequest.result;
|
| 981 |
+
};
|
| 982 |
+
|
| 983 |
+
// Sales today
|
| 984 |
+
const salesTransaction = db.transaction(['sales'], 'readonly');
|
| 985 |
+
const salesStore = salesTransaction.objectStore('sales');
|
| 986 |
+
const today = new Date().toISOString().slice(0, 10);
|
| 987 |
+
const salesTodayRequest = salesStore.index('date').getAll(today);
|
| 988 |
+
|
| 989 |
+
salesTodayRequest.onsuccess = () => {
|
| 990 |
+
document.getElementById('sales-today').textContent = salesTodayRequest.result.length;
|
| 991 |
+
};
|
| 992 |
+
|
| 993 |
+
// Monthly revenue (placeholder - would need actual sales data with amounts)
|
| 994 |
+
document.getElementById('monthly-revenue').textContent = 'R$ 0,00';
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
// Utility functions
|
| 998 |
+
function showToast(message, type = 'success') {
|
| 999 |
+
const toast = document.getElementById('toast');
|
| 1000 |
+
const toastMessage = document.getElementById('toast-message');
|
| 1001 |
+
|
| 1002 |
+
toastMessage.textContent = message;
|
| 1003 |
+
|
| 1004 |
+
// Set color based on type
|
| 1005 |
+
if (type === 'error') {
|
| 1006 |
+
toast.classList.remove('bg-green-500');
|
| 1007 |
+
toast.classList.add('bg-red-500');
|
| 1008 |
+
} else {
|
| 1009 |
+
toast.classList.remove('bg-red-500');
|
| 1010 |
+
toast.classList.add('bg-green-500');
|
| 1011 |
+
}
|
| 1012 |
+
|
| 1013 |
+
toast.classList.remove('hidden');
|
| 1014 |
+
|
| 1015 |
+
// Hide after 3 seconds
|
| 1016 |
+
setTimeout(() => {
|
| 1017 |
+
toast.classList.add('hidden');
|
| 1018 |
+
}, 3000);
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
function formatCPF(cpf) {
|
| 1022 |
+
return cpf.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$4');
|
| 1023 |
+
}
|
| 1024 |
+
|
| 1025 |
+
function formatPhone(phone) {
|
| 1026 |
+
if (phone.length === 11) {
|
| 1027 |
+
return phone.replace(/(\d{2})(\d{5})(\d{4})/, '($1) $2-$3');
|
| 1028 |
+
} else if (phone.length === 10) {
|
| 1029 |
+
return phone.replace(/(\d{2})(\d{4})(\d{4})/, '($1) $2-$3');
|
| 1030 |
+
}
|
| 1031 |
+
return phone;
|
| 1032 |
+
}
|
| 1033 |
+
|
| 1034 |
+
// Initialize search functionality
|
| 1035 |
+
document.getElementById('customer-search').addEventListener('input', (e) => {
|
| 1036 |
+
loadCustomers(1, e.target.value);
|
| 1037 |
+
});
|
| 1038 |
+
|
| 1039 |
+
// Close modals when clicking outside
|
| 1040 |
+
window.addEventListener('click', (e) => {
|
| 1041 |
+
const customerModal = document.getElementById('customer-modal');
|
| 1042 |
+
if (e.target === customerModal) {
|
| 1043 |
+
closeCustomerModal();
|
| 1044 |
+
}
|
| 1045 |
+
|
| 1046 |
+
const confirmModal = document.getElementById('confirm-modal');
|
| 1047 |
+
if (e.target === confirmModal) {
|
| 1048 |
+
confirmModal.classList.add('hidden');
|
| 1049 |
+
}
|
| 1050 |
+
});
|
| 1051 |
+
|
| 1052 |
+
// Close confirm modal buttons
|
| 1053 |
+
document.getElementById('close-confirm').addEventListener('click', () => {
|
| 1054 |
+
document.getElementById('confirm-modal').classList.add('hidden');
|
| 1055 |
+
});
|
| 1056 |
+
|
| 1057 |
+
document.getElementById('cancel-confirm').addEventListener('click', () => {
|
| 1058 |
+
document.getElementById('confirm-modal').classList.add('hidden');
|
| 1059 |
+
});
|
| 1060 |
+
</script>
|
| 1061 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=jptec2024/teste" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 1062 |
+
</html>
|