manual item code
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,684 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard - Invoice Extraction Pro</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: #f5f7fa;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
background: white;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
padding: 15px 30px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.navbar-right {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.navbar-right a {
|
||||
padding: 8px 16px;
|
||||
background: #f0f0f0;
|
||||
border-radius: 6px;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.navbar-right a:hover { background: #e0e0e0; }
|
||||
|
||||
.container { max-width: 1200px; margin: 0 auto; padding: 30px; }
|
||||
|
||||
.header { margin-bottom: 30px; }
|
||||
.header h1 { font-size: 28px; margin-bottom: 8px; }
|
||||
.header p { color: #888; font-size: 15px; }
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.tab-button {
|
||||
padding: 12px 20px;
|
||||
border: none;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: #888;
|
||||
border-bottom: 3px solid transparent;
|
||||
margin-bottom: -2px;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.tab-button.active {
|
||||
color: #667eea;
|
||||
border-bottom-color: #667eea;
|
||||
}
|
||||
|
||||
.tab-button:hover {
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.summary-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
gap: 15px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.summary-card {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
padding: 18px;
|
||||
border-left: 4px solid #667eea;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.06);
|
||||
}
|
||||
|
||||
.summary-label {
|
||||
font-size: 12px;
|
||||
color: #888;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.summary-value {
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.day-block {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 20px 24px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.06);
|
||||
}
|
||||
|
||||
.day-block h2 {
|
||||
font-size: 17px;
|
||||
margin-bottom: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.day-block h2 .today-badge {
|
||||
display: inline-block;
|
||||
margin-left: 8px;
|
||||
padding: 2px 10px;
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
border-radius: 12px;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
table.stats-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.stats-table th {
|
||||
background: #f8f9fa;
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.stats-table td {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid #eee;
|
||||
color: #444;
|
||||
}
|
||||
|
||||
.stats-table tbody tr:hover { background: #f8f9fa; }
|
||||
|
||||
.num { text-align: right; font-variant-numeric: tabular-nums; }
|
||||
|
||||
.tag {
|
||||
display: inline-block;
|
||||
padding: 3px 9px;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.tag.matched { background: #d4edda; color: #155724; }
|
||||
.tag.manual { background: #e2d9f3; color: #4b2a85; }
|
||||
.tag.missing { background: #f8d7da; color: #721c24; }
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-state-icon { font-size: 42px; margin-bottom: 12px; }
|
||||
|
||||
/* User Management Styles */
|
||||
.user-management-section {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 20px 24px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.06);
|
||||
}
|
||||
|
||||
.management-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.management-header h3 {
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #5568d3;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #dc3545;
|
||||
color: white;
|
||||
font-size: 12px;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: #c82333;
|
||||
}
|
||||
|
||||
.users-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.users-table th {
|
||||
background: #f8f9fa;
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.users-table td {
|
||||
padding: 12px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
.users-table tbody tr:hover {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.admin-badge {
|
||||
display: inline-block;
|
||||
padding: 3px 8px;
|
||||
background: #ffc107;
|
||||
color: #000;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0,0,0,0.5);
|
||||
z-index: 1000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.modal.active {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 30px;
|
||||
width: 90%;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 10px 40px rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
float: right;
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.modal-close:hover {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
||||
}
|
||||
|
||||
.modal-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
justify-content: flex-end;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.modal-buttons button {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
background: #e0e0e0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.btn-cancel:hover {
|
||||
background: #d0d0d0;
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: 12px 16px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 15px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.message.success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
border: 1px solid #c3e6cb;
|
||||
}
|
||||
|
||||
.message.error {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
border: 1px solid #f5c6cb;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.container { padding: 15px; }
|
||||
.stats-table { font-size: 12px; }
|
||||
.stats-table th, .stats-table td { padding: 7px 8px; }
|
||||
.management-header {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar">
|
||||
<div class="navbar-brand"> Admin Dashboard — Invoice Pro</div>
|
||||
<div class="navbar-right">
|
||||
<a href="{{ url_for('dashboard') }}">← Back to Dashboard</a>
|
||||
<a href="{{ url_for('logout') }}">Logout</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>Admin Dashboard</h1>
|
||||
<p>Manage users and view invoice processing statistics</p>
|
||||
</div>
|
||||
|
||||
<!-- Tab Navigation -->
|
||||
<div class="tabs">
|
||||
<button class="tab-button active" onclick="switchTab('statistics')">📊 Statistics</button>
|
||||
<button class="tab-button" onclick="switchTab('users')">👥 User Management</button>
|
||||
</div>
|
||||
|
||||
<!-- Statistics Tab -->
|
||||
<div id="statistics" class="tab-content active">
|
||||
<div class="summary-grid">
|
||||
<div class="summary-card">
|
||||
<div class="summary-label">PDFs Today</div>
|
||||
<div class="summary-value">{{ summary.today_pdfs }}</div>
|
||||
</div>
|
||||
<div class="summary-card">
|
||||
<div class="summary-label">Active Users Today</div>
|
||||
<div class="summary-value">{{ summary.today_active_users }}</div>
|
||||
</div>
|
||||
<div class="summary-card">
|
||||
<div class="summary-label">Total PDFs Processed</div>
|
||||
<div class="summary-value">{{ summary.total_pdfs }}</div>
|
||||
</div>
|
||||
<div class="summary-card">
|
||||
<div class="summary-label">Total Items Seen</div>
|
||||
<div class="summary-value">{{ summary.total_items }}</div>
|
||||
</div>
|
||||
<div class="summary-card">
|
||||
<div class="summary-label">Item Codes Added Manually</div>
|
||||
<div class="summary-value">{{ summary.total_manual }}</div>
|
||||
</div>
|
||||
<div class="summary-card">
|
||||
<div class="summary-label">Items Still Missing a Code</div>
|
||||
<div class="summary-value">{{ summary.total_missing }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if stats %}
|
||||
{% for day in stats %}
|
||||
<div class="day-block">
|
||||
<h2>
|
||||
{{ day.date }}
|
||||
{% if day.date == today %}<span class="today-badge">TODAY</span>{% endif %}
|
||||
</h2>
|
||||
<table class="stats-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th class="num">PDFs</th>
|
||||
<th class="num">Items</th>
|
||||
<th class="num">With Code</th>
|
||||
<th class="num">Auto-Matched</th>
|
||||
<th class="num">Manual</th>
|
||||
<th class="num">Missing</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for u in day.users %}
|
||||
<tr>
|
||||
<td>{{ u.username }}</td>
|
||||
<td class="num">{{ u.pdfs_processed }}</td>
|
||||
<td class="num">{{ u.total_items }}</td>
|
||||
<td class="num">{{ u.items_with_code }}</td>
|
||||
<td class="num"><span class="tag matched">{{ u.items_auto_matched }}</span></td>
|
||||
<td class="num"><span class="tag manual">{{ u.items_manual }}</span></td>
|
||||
<td class="num">
|
||||
{% if u.items_missing > 0 %}<span class="tag missing">{{ u.items_missing }}</span>
|
||||
{% else %}0{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="day-block">
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">📭</div>
|
||||
<p>No invoices have been processed yet.</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- User Management Tab -->
|
||||
<div id="users" class="tab-content">
|
||||
<div id="messageContainer"></div>
|
||||
|
||||
<div class="user-management-section">
|
||||
<div class="management-header">
|
||||
<h3>👥 Registered Users</h3>
|
||||
<button class="btn btn-primary" onclick="openAddUserModal()">+ Add New User</button>
|
||||
</div>
|
||||
|
||||
{% if all_users %}
|
||||
<table class="users-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Email</th>
|
||||
<th>Registered</th>
|
||||
<th>Last Login</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in all_users %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{{ user.username }}</strong>
|
||||
{% if user.is_admin %}<span class="admin-badge">👑 ADMIN</span>{% endif %}
|
||||
</td>
|
||||
<td>{{ user.email }}</td>
|
||||
<td>{{ user.created_at[:10] if user.created_at else 'N/A' }}</td>
|
||||
<td>{{ user.last_login[:10] if user.last_login else 'Never' }}</td>
|
||||
<td>
|
||||
{% if user.is_active %}
|
||||
<span style="color: #28a745;">✓ Active</span>
|
||||
{% else %}
|
||||
<span style="color: #dc3545;">✗ Inactive</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if user.username != 'admin' %}
|
||||
<button class="btn btn-danger" onclick="deleteUser('{{ user.username }}')">Delete</button>
|
||||
{% else %}
|
||||
<span style="color: #888; font-size: 12px;">Protected</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">👥</div>
|
||||
<p>No users registered yet.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Add User Modal -->
|
||||
<div id="addUserModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="modal-close" onclick="closeAddUserModal()">×</span>
|
||||
<div class="modal-header">Add New User</div>
|
||||
<form onsubmit="submitAddUser(event)">
|
||||
<div class="form-group">
|
||||
<label>Username</label>
|
||||
<input type="text" id="newUsername" required placeholder="Enter username">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Email</label>
|
||||
<input type="email" id="newEmail" required placeholder="Enter email">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Password</label>
|
||||
<input type="password" id="newPassword" required placeholder="Enter password">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Confirm Password</label>
|
||||
<input type="password" id="newPasswordConfirm" required placeholder="Confirm password">
|
||||
</div>
|
||||
<div class="modal-buttons">
|
||||
<button type="button" class="btn btn-cancel" onclick="closeAddUserModal()">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Add User</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function switchTab(tabName) {
|
||||
// Hide all tabs
|
||||
document.querySelectorAll('.tab-content').forEach(tab => tab.classList.remove('active'));
|
||||
document.querySelectorAll('.tab-button').forEach(btn => btn.classList.remove('active'));
|
||||
|
||||
// Show selected tab
|
||||
document.getElementById(tabName).classList.add('active');
|
||||
event.target.classList.add('active');
|
||||
}
|
||||
|
||||
function openAddUserModal() {
|
||||
document.getElementById('addUserModal').classList.add('active');
|
||||
}
|
||||
|
||||
function closeAddUserModal() {
|
||||
document.getElementById('addUserModal').classList.remove('active');
|
||||
document.getElementById('addUserForm')?.reset();
|
||||
}
|
||||
|
||||
function submitAddUser(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const username = document.getElementById('newUsername').value;
|
||||
const email = document.getElementById('newEmail').value;
|
||||
const password = document.getElementById('newPassword').value;
|
||||
const passwordConfirm = document.getElementById('newPasswordConfirm').value;
|
||||
|
||||
if (password !== passwordConfirm) {
|
||||
showMessage('Passwords do not match!', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/api/admin/add-user', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: username,
|
||||
email: email,
|
||||
password: password
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
showMessage('User added successfully!', 'success');
|
||||
closeAddUserModal();
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
} else {
|
||||
showMessage(data.message || 'Failed to add user', 'error');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
showMessage('Error: ' + error.message, 'error');
|
||||
});
|
||||
}
|
||||
|
||||
function deleteUser(username) {
|
||||
if (confirm(`Are you sure you want to delete user "${username}"? This cannot be undone.`)) {
|
||||
fetch('/api/admin/delete-user', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: username
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
showMessage('User deleted successfully!', 'success');
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
} else {
|
||||
showMessage(data.message || 'Failed to delete user', 'error');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
showMessage('Error: ' + error.message, 'error');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function showMessage(message, type) {
|
||||
const container = document.getElementById('messageContainer');
|
||||
container.innerHTML = `<div class="message ${type}">${message}</div>`;
|
||||
setTimeout(() => container.innerHTML = '', 5000);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,796 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Invoice Extraction with Item Code Enrichment</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
max-width: 1000px;
|
||||
width: 100%;
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
color: #333;
|
||||
font-size: 28px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
color: #666;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.upload-section {
|
||||
background: #f8f9fa;
|
||||
border: 2px dashed #667eea;
|
||||
border-radius: 8px;
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.upload-section:hover {
|
||||
border-color: #764ba2;
|
||||
background: #f0f2ff;
|
||||
}
|
||||
|
||||
.upload-section.dragover {
|
||||
border-color: #764ba2;
|
||||
background: #e8ebff;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
font-size: 48px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.upload-section p {
|
||||
color: #666;
|
||||
font-size: 16px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.upload-section .file-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.upload-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 12px 30px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
.upload-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.upload-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: #e9ecef;
|
||||
color: #333;
|
||||
border: none;
|
||||
padding: 12px 30px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.secondary-btn:hover {
|
||||
background: #dee2e6;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: none;
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
display: inline-block;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #667eea;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.loading p {
|
||||
color: #666;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.results {
|
||||
display: none;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.results.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.result-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 15px;
|
||||
border-bottom: 2px solid #e9ecef;
|
||||
}
|
||||
|
||||
.result-header h2 {
|
||||
color: #333;
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.success-badge {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
padding: 8px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.error-badge {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
padding: 8px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.metadata {
|
||||
background: #f8f9fa;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.metadata p {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.metadata strong {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.json-display {
|
||||
background: #1e1e1e;
|
||||
color: #d4d4d4;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
overflow-x: auto;
|
||||
font-family: 'Courier New', monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
max-height: 600px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.json-display::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
.json-display::-webkit-scrollbar-track {
|
||||
background: #2d2d2d;
|
||||
}
|
||||
|
||||
.json-display::-webkit-scrollbar-thumb {
|
||||
background: #555;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.json-display::-webkit-scrollbar-thumb:hover {
|
||||
background: #777;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 2px solid #e9ecef;
|
||||
}
|
||||
|
||||
.tab {
|
||||
padding: 12px 20px;
|
||||
cursor: pointer;
|
||||
border-bottom: 3px solid transparent;
|
||||
color: #666;
|
||||
font-weight: 600;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tab:hover {
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
color: #667eea;
|
||||
border-bottom-color: #667eea;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.items-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.items-table th {
|
||||
background: #f8f9fa;
|
||||
padding: 12px;
|
||||
text-align: left;
|
||||
border-bottom: 2px solid #dee2e6;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.items-table td {
|
||||
padding: 12px;
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.items-table tbody tr:hover {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.item-code-tag {
|
||||
display: inline-block;
|
||||
padding: 4px 8px;
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.item-code-api {
|
||||
background: #d1ecf1;
|
||||
color: #0c5460;
|
||||
}
|
||||
|
||||
.item-code-matched {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.item-code-missing {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
justify-content: center;
|
||||
margin-top: 30px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
background: #6c757d;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.copy-btn:hover {
|
||||
background: #5a6268;
|
||||
}
|
||||
|
||||
.download-btn {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.download-btn:hover {
|
||||
background: #218838;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background: #f8d7da;
|
||||
border: 1px solid #f5c6cb;
|
||||
color: #721c24;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-top: 20px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.error-message.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.success-message {
|
||||
background: #d4edda;
|
||||
border: 1px solid #c3e6cb;
|
||||
color: #155724;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-top: 20px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.success-message.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.info-message {
|
||||
background: #d1ecf1;
|
||||
border: 1px solid #bee5eb;
|
||||
color: #0c5460;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.upload-section {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.upload-btn, .secondary-btn {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.items-table {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.items-table th, .items-table td {
|
||||
padding: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.stat {
|
||||
display: inline-block;
|
||||
margin: 0 15px;
|
||||
padding: 10px 15px;
|
||||
background: #f8f9fa;
|
||||
border-radius: 5px;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.stat strong {
|
||||
color: #667eea;
|
||||
font-size: 18px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>📋 Invoice Extraction & Item Code Enrichment</h1>
|
||||
<p>Upload invoices and automatically extract item codes from your drug database</p>
|
||||
</div>
|
||||
|
||||
<div class="upload-section" id="uploadSection">
|
||||
<div class="upload-icon">📄</div>
|
||||
<p>Drag and drop your invoice PDF here, or click to select</p>
|
||||
<button class="upload-btn" onclick="document.getElementById('fileInput').click()">
|
||||
Choose File
|
||||
</button>
|
||||
<input
|
||||
type="file"
|
||||
id="fileInput"
|
||||
class="file-input"
|
||||
accept=".pdf,.png,.jpg,.jpeg"
|
||||
onchange="handleFileSelect(event)"
|
||||
>
|
||||
<p style="margin-top: 15px; color: #999; font-size: 12px;">
|
||||
Supported: PDF, PNG, JPG, JPEG • Max: 100MB
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="loading" id="loading">
|
||||
<div class="spinner"></div>
|
||||
<p>Extracting invoice data...</p>
|
||||
<p style="font-size: 12px; color: #999; margin-top: 10px;">This may take a few moments</p>
|
||||
</div>
|
||||
|
||||
<div class="error-message" id="errorMessage"></div>
|
||||
<div class="success-message" id="successMessage"></div>
|
||||
|
||||
<div class="results" id="results">
|
||||
<div class="result-header">
|
||||
<h2>Extraction Results</h2>
|
||||
<div id="resultBadge"></div>
|
||||
</div>
|
||||
|
||||
<div class="metadata">
|
||||
<p><strong>Upload ID:</strong> <span id="uploadId">-</span></p>
|
||||
<p><strong>Timestamp:</strong> <span id="timestamp">-</span></p>
|
||||
<p><strong>Filename:</strong> <span id="filename">-</span></p>
|
||||
<div style="margin-top: 10px;">
|
||||
<span class="stat"><strong id="totalItems">0</strong> Total Items</span>
|
||||
<span class="stat"><strong id="itemsWithCode">0</strong> With Codes</span>
|
||||
<span class="stat"><strong id="itemsMatched">0</strong> Matched from DB</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs">
|
||||
<div class="tab active" onclick="switchTab('headers')">📋 Header Fields</div>
|
||||
<div class="tab" onclick="switchTab('items')">📦 Line Items</div>
|
||||
<div class="tab" onclick="switchTab('raw')">📄 Raw JSON</div>
|
||||
</div>
|
||||
|
||||
<div id="headers" class="tab-content active">
|
||||
<div id="headerFields"></div>
|
||||
</div>
|
||||
|
||||
<div id="items" class="tab-content">
|
||||
<table class="items-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Description</th>
|
||||
<th>Quantity</th>
|
||||
<th>Unit Price</th>
|
||||
<th>Item Code</th>
|
||||
<th>Source</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="itemsTable">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="raw" class="tab-content">
|
||||
<div class="json-display" id="jsonDisplay"></div>
|
||||
</div>
|
||||
|
||||
<div class="action-buttons">
|
||||
<button class="copy-btn" onclick="copyToClipboard()">📋 Copy JSON</button>
|
||||
<button class="download-btn" onclick="downloadJSON()">⬇️ Download JSON</button>
|
||||
<button class="secondary-btn" onclick="resetForm()">🔄 Extract Another</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let lastExtractedData = null;
|
||||
let selectedFile = null;
|
||||
|
||||
// Drag and drop
|
||||
const uploadSection = document.getElementById('uploadSection');
|
||||
|
||||
uploadSection.addEventListener('dragover', (e) => {
|
||||
e.preventDefault();
|
||||
uploadSection.classList.add('dragover');
|
||||
});
|
||||
|
||||
uploadSection.addEventListener('dragleave', () => {
|
||||
uploadSection.classList.remove('dragover');
|
||||
});
|
||||
|
||||
uploadSection.addEventListener('drop', (e) => {
|
||||
e.preventDefault();
|
||||
uploadSection.classList.remove('dragover');
|
||||
|
||||
const files = e.dataTransfer.files;
|
||||
if (files.length > 0) {
|
||||
handleFile(files[0]);
|
||||
}
|
||||
});
|
||||
|
||||
function handleFileSelect(event) {
|
||||
const files = event.target.files;
|
||||
if (files.length > 0) {
|
||||
handleFile(files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function handleFile(file) {
|
||||
const validTypes = ['application/pdf', 'image/png', 'image/jpeg'];
|
||||
|
||||
if (!validTypes.includes(file.type)) {
|
||||
showError('Invalid file type. Please upload PDF, PNG, or JPG');
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > 100 * 1024 * 1024) {
|
||||
showError('File size exceeds 100MB limit');
|
||||
return;
|
||||
}
|
||||
|
||||
selectedFile = file;
|
||||
uploadInvoice();
|
||||
}
|
||||
|
||||
async function uploadInvoice() {
|
||||
if (!selectedFile) return;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', selectedFile);
|
||||
|
||||
document.getElementById('loading').style.display = 'block';
|
||||
document.getElementById('results').classList.remove('show');
|
||||
hideMessages();
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/upload', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok && result.success) {
|
||||
lastExtractedData = result.data;
|
||||
displayResults(result.data);
|
||||
showSuccess('Invoice extracted and enriched successfully!');
|
||||
} else {
|
||||
showError(result.error || 'Failed to extract invoice');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
showError('Network error. Please try again.');
|
||||
} finally {
|
||||
document.getElementById('loading').style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function displayResults(data) {
|
||||
// Update metadata
|
||||
document.getElementById('uploadId').textContent = data._metadata?.upload_id || '-';
|
||||
document.getElementById('timestamp').textContent = new Date(data._metadata?.upload_timestamp).toLocaleString();
|
||||
document.getElementById('filename').textContent = data._metadata?.original_filename || '-';
|
||||
|
||||
// Calculate statistics
|
||||
const items = data.items || [];
|
||||
const itemsWithCode = items.filter(i => i.item_code).length;
|
||||
const itemsMatched = items.filter(i => i.item_code_source === 'drug_list_match').length;
|
||||
|
||||
document.getElementById('totalItems').textContent = items.length;
|
||||
document.getElementById('itemsWithCode').textContent = itemsWithCode;
|
||||
document.getElementById('itemsMatched').textContent = itemsMatched;
|
||||
|
||||
// Set badge
|
||||
const badge = document.getElementById('resultBadge');
|
||||
if (items.length > 0 && itemsWithCode === items.length) {
|
||||
badge.innerHTML = '<span class="success-badge">✓ All items have codes</span>';
|
||||
} else if (itemsWithCode > 0) {
|
||||
badge.innerHTML = `<span class="success-badge">✓ ${itemsWithCode}/${items.length} items have codes</span>`;
|
||||
} else {
|
||||
badge.innerHTML = '<span class="error-badge">⚠ Some items missing codes</span>';
|
||||
}
|
||||
|
||||
// Display header fields
|
||||
displayHeaderFields(data);
|
||||
|
||||
// Display items table
|
||||
displayItemsTable(items);
|
||||
|
||||
// Display raw JSON
|
||||
document.getElementById('jsonDisplay').textContent = JSON.stringify(data, null, 2);
|
||||
|
||||
// Show results section
|
||||
document.getElementById('results').classList.add('show');
|
||||
}
|
||||
|
||||
function displayHeaderFields(data) {
|
||||
const headerContainer = document.getElementById('headerFields');
|
||||
const headerFields = [
|
||||
'invoice_id', 'date', 'seller_name', 'seller_gstin',
|
||||
'buyer_name', 'buyer_gstin', 'total_quantity',
|
||||
'total_taxable_amount', 'total_gst_amount', 'invoice_amount'
|
||||
];
|
||||
|
||||
let html = '<table class="items-table" style="margin-bottom: 20px;"><tbody>';
|
||||
|
||||
headerFields.forEach(field => {
|
||||
if (field in data) {
|
||||
const value = data[field];
|
||||
const displayValue = value !== null ? String(value) : 'N/A';
|
||||
html += `
|
||||
<tr>
|
||||
<td style="font-weight: 600; width: 30%;">${field}</td>
|
||||
<td>${displayValue}</td>
|
||||
</tr>
|
||||
`;
|
||||
}
|
||||
});
|
||||
|
||||
html += '</tbody></table>';
|
||||
headerContainer.innerHTML = html;
|
||||
}
|
||||
|
||||
function displayItemsTable(items) {
|
||||
const tbody = document.getElementById('itemsTable');
|
||||
tbody.innerHTML = '';
|
||||
|
||||
items.forEach((item, index) => {
|
||||
const code = item.item_code || '-';
|
||||
const source = item.item_code_source || 'unknown';
|
||||
|
||||
let sourceTag = 'item-code-missing';
|
||||
let sourceText = 'Not Found';
|
||||
|
||||
if (source === 'api_extracted') {
|
||||
sourceTag = 'item-code-api';
|
||||
sourceText = 'API Extracted';
|
||||
} else if (source === 'drug_list_match') {
|
||||
sourceTag = 'item-code-matched';
|
||||
sourceText = 'Matched from DB';
|
||||
}
|
||||
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td>${item.description || '-'}</td>
|
||||
<td>${item.quantity || '-'}</td>
|
||||
<td>${item.unit_price || '-'}</td>
|
||||
<td><strong>${code}</strong></td>
|
||||
<td><span class="item-code-tag ${sourceTag}">${sourceText}</span></td>
|
||||
`;
|
||||
tbody.appendChild(row);
|
||||
});
|
||||
}
|
||||
|
||||
function switchTab(tabName) {
|
||||
// Hide all tabs
|
||||
document.querySelectorAll('.tab-content').forEach(tab => {
|
||||
tab.classList.remove('active');
|
||||
});
|
||||
document.querySelectorAll('.tab').forEach(tab => {
|
||||
tab.classList.remove('active');
|
||||
});
|
||||
|
||||
// Show selected tab
|
||||
document.getElementById(tabName).classList.add('active');
|
||||
event.target.classList.add('active');
|
||||
}
|
||||
|
||||
function copyToClipboard() {
|
||||
const json = JSON.stringify(lastExtractedData, null, 2);
|
||||
navigator.clipboard.writeText(json).then(() => {
|
||||
showSuccess('JSON copied to clipboard!');
|
||||
}).catch(err => {
|
||||
showError('Failed to copy to clipboard');
|
||||
});
|
||||
}
|
||||
|
||||
function downloadJSON() {
|
||||
const json = JSON.stringify(lastExtractedData, null, 2);
|
||||
const blob = new Blob([json], { type: 'application/json' });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `invoice_${lastExtractedData._metadata?.upload_id || 'export'}.json`;
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
selectedFile = null;
|
||||
lastExtractedData = null;
|
||||
document.getElementById('fileInput').value = '';
|
||||
document.getElementById('results').classList.remove('show');
|
||||
hideMessages();
|
||||
document.getElementById('uploadSection').style.display = 'block';
|
||||
}
|
||||
|
||||
function showError(message) {
|
||||
const errorDiv = document.getElementById('errorMessage');
|
||||
errorDiv.textContent = '❌ ' + message;
|
||||
errorDiv.classList.add('show');
|
||||
}
|
||||
|
||||
function showSuccess(message) {
|
||||
const successDiv = document.getElementById('successMessage');
|
||||
successDiv.textContent = '✓ ' + message;
|
||||
successDiv.classList.add('show');
|
||||
setTimeout(() => {
|
||||
successDiv.classList.remove('show');
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function hideMessages() {
|
||||
document.getElementById('errorMessage').classList.remove('show');
|
||||
document.getElementById('successMessage').classList.remove('show');
|
||||
}
|
||||
|
||||
// Load config on page load
|
||||
window.addEventListener('load', async () => {
|
||||
try {
|
||||
const response = await fetch('/api/config');
|
||||
const config = await response.json();
|
||||
console.log('✅ Application loaded', config);
|
||||
} catch (error) {
|
||||
console.error('Error loading config:', error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,332 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sign In</title>
|
||||
<style>
|
||||
:root {
|
||||
--primary: #0284c7;
|
||||
--primary-hover: #0369a1;
|
||||
--primary-focus-ring: rgba(2, 132, 199, 0.2);
|
||||
--surface: #ffffff;
|
||||
--background: #f8fafc;
|
||||
--border: #e2e8f0;
|
||||
--border-focus: #0284c7;
|
||||
--text-primary: #0f172a;
|
||||
--text-secondary: #475569;
|
||||
--text-muted: #64748b;
|
||||
--danger: #dc2626;
|
||||
--danger-bg: #fef2f2;
|
||||
--danger-border: #fecaca;
|
||||
--success: #059669;
|
||||
--success-bg: #ecfdf5;
|
||||
--success-border: #a7f3d0;
|
||||
--radius: 8px;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
background-color: var(--background);
|
||||
color: var(--text-primary);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 24px 16px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
background-color: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
padding: 40px 32px;
|
||||
}
|
||||
|
||||
/* Dedicated Logo Placeholder Area */
|
||||
.logo-placeholder-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.logo-placeholder {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.logo-placeholder img {
|
||||
max-height: 72px;
|
||||
height: 68px;
|
||||
width: auto;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.auth-header {
|
||||
text-align: center;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
letter-spacing: -0.01em;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.auth-header p {
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
background-color: #ffffff;
|
||||
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
input[type="text"]:focus,
|
||||
input[type="password"]:focus {
|
||||
outline: none;
|
||||
border-color: var(--border-focus);
|
||||
box-shadow: 0 0 0 3px var(--primary-focus-ring);
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 100%;
|
||||
padding: 11px 16px;
|
||||
background-color: var(--primary);
|
||||
color: #ffffff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.submit-btn:hover {
|
||||
background-color: var(--primary-hover);
|
||||
}
|
||||
|
||||
.submit-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.links-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.links-row a,
|
||||
.auth-footer a {
|
||||
color: var(--primary);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.links-row a:hover,
|
||||
.auth-footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.auth-footer {
|
||||
text-align: center;
|
||||
margin-top: 28px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid var(--border);
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: 10px 14px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 13px;
|
||||
display: none;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.message.error {
|
||||
background-color: var(--danger-bg);
|
||||
color: var(--danger);
|
||||
border: 1px solid var(--danger-border);
|
||||
display: block;
|
||||
}
|
||||
|
||||
.message.success {
|
||||
background-color: var(--success-bg);
|
||||
color: var(--success);
|
||||
border: 1px solid var(--success-border);
|
||||
display: block;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: none;
|
||||
text-align: center;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 2px solid var(--border);
|
||||
border-top: 2px solid var(--primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.6s linear infinite;
|
||||
margin-right: 8px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.auth-card {
|
||||
padding: 28px 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="auth-card">
|
||||
<div class="logo-placeholder-container">
|
||||
<div class="logo-placeholder" id="logoPlaceholder">
|
||||
<img src="{{ url_for('static', filename='logo.png') }}" alt="Logo">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="auth-header">
|
||||
<h1>Sign In</h1>
|
||||
<p>Access your management dashboard</p>
|
||||
</div>
|
||||
|
||||
<div id="message" class="message"></div>
|
||||
|
||||
<form id="loginForm">
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" placeholder="Enter username" autocomplete="username" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" placeholder="Enter password" autocomplete="current-password" required>
|
||||
</div>
|
||||
|
||||
<div class="loading" id="loading">
|
||||
<span class="spinner"></span>
|
||||
Authenticating...
|
||||
</div>
|
||||
|
||||
<button type="submit" class="submit-btn" id="submitBtn">Sign In</button>
|
||||
</form>
|
||||
|
||||
<div class="links-row">
|
||||
<a href="#" onclick="showForgot(event)">Forgot password?</a>
|
||||
</div>
|
||||
|
||||
<div class="auth-footer">
|
||||
Do not have an account? <a href="/register">Register</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('loginForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const username = document.getElementById('username').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
const messageDiv = document.getElementById('message');
|
||||
const loading = document.getElementById('loading');
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
|
||||
if (!username || !password) {
|
||||
showMessage('Please fill in all fields', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
loading.style.display = 'block';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
try {
|
||||
const response = await fetch('/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
showMessage('Sign in successful. Redirecting...', 'success');
|
||||
setTimeout(() => {
|
||||
window.location.href = '/dashboard';
|
||||
}, 800);
|
||||
} else {
|
||||
showMessage(data.message || 'Invalid username or password', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage('Connection error. Please try again.', 'error');
|
||||
} finally {
|
||||
loading.style.display = 'none';
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
function showMessage(text, type) {
|
||||
const messageDiv = document.getElementById('message');
|
||||
messageDiv.textContent = text;
|
||||
messageDiv.className = `message ${type}`;
|
||||
}
|
||||
|
||||
function showForgot(e) {
|
||||
if (e) e.preventDefault();
|
||||
alert('Password reset assistance is managed by the system administrator. Please contact your administrative team.');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,367 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Create Account</title>
|
||||
<style>
|
||||
:root {
|
||||
--primary: #0284c7;
|
||||
--primary-hover: #0369a1;
|
||||
--primary-focus-ring: rgba(2, 132, 199, 0.2);
|
||||
--surface: #ffffff;
|
||||
--background: #f8fafc;
|
||||
--border: #e2e8f0;
|
||||
--border-focus: #0284c7;
|
||||
--text-primary: #0f172a;
|
||||
--text-secondary: #475569;
|
||||
--text-muted: #64748b;
|
||||
--danger: #dc2626;
|
||||
--danger-bg: #fef2f2;
|
||||
--danger-border: #fecaca;
|
||||
--success: #059669;
|
||||
--success-bg: #ecfdf5;
|
||||
--success-border: #a7f3d0;
|
||||
--radius: 8px;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
background-color: var(--background);
|
||||
color: var(--text-primary);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 32px 16px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
background-color: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
|
||||
width: 100%;
|
||||
max-width: 480px;
|
||||
padding: 40px 32px;
|
||||
}
|
||||
|
||||
/* Dedicated Logo Placeholder Area */
|
||||
.logo-placeholder-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.logo-placeholder {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.logo-placeholder img {
|
||||
max-height: 72px;
|
||||
height: 68px;
|
||||
width: auto;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.auth-header {
|
||||
text-align: center;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
|
||||
.auth-header h1 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
letter-spacing: -0.01em;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.auth-header p {
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
input[type="email"],
|
||||
input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 10px 14px;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
background-color: #ffffff;
|
||||
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
input[type="text"]:focus,
|
||||
input[type="email"]:focus,
|
||||
input[type="password"]:focus {
|
||||
outline: none;
|
||||
border-color: var(--border-focus);
|
||||
box-shadow: 0 0 0 3px var(--primary-focus-ring);
|
||||
}
|
||||
|
||||
.helper-text {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 100%;
|
||||
padding: 11px 16px;
|
||||
background-color: var(--primary);
|
||||
color: #ffffff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.submit-btn:hover {
|
||||
background-color: var(--primary-hover);
|
||||
}
|
||||
|
||||
.submit-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.auth-footer {
|
||||
text-align: center;
|
||||
margin-top: 28px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid var(--border);
|
||||
font-size: 13px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.auth-footer a {
|
||||
color: var(--primary);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.auth-footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: 10px 14px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 20px;
|
||||
font-size: 13px;
|
||||
display: none;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.message.error {
|
||||
background-color: var(--danger-bg);
|
||||
color: var(--danger);
|
||||
border: 1px solid var(--danger-border);
|
||||
display: block;
|
||||
}
|
||||
|
||||
.message.success {
|
||||
background-color: var(--success-bg);
|
||||
color: var(--success);
|
||||
border: 1px solid var(--success-border);
|
||||
display: block;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: none;
|
||||
text-align: center;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 2px solid var(--border);
|
||||
border-top: 2px solid var(--primary);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.6s linear infinite;
|
||||
margin-right: 8px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.auth-card {
|
||||
padding: 28px 20px;
|
||||
}
|
||||
.form-row {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="auth-card">
|
||||
<div class="logo-placeholder-container">
|
||||
<div class="logo-placeholder" id="logoPlaceholder">
|
||||
<img src="{{ url_for('static', filename='logo.png') }}" alt="Logo">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="auth-header">
|
||||
<h1>Create Account</h1>
|
||||
<p>Register a new user account</p>
|
||||
</div>
|
||||
|
||||
<div id="message" class="message"></div>
|
||||
|
||||
<form id="registerForm">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" placeholder="Choose username" autocomplete="username" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" id="email" name="email" placeholder="user@domain.com" autocomplete="email" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" placeholder="Minimum 6 characters" autocomplete="new-password" required>
|
||||
<div class="helper-text">Minimum 6 characters</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="confirm">Confirm Password</label>
|
||||
<input type="password" id="confirm" name="confirm_password" placeholder="Confirm password" autocomplete="new-password" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="loading" id="loading">
|
||||
<span class="spinner"></span>
|
||||
Creating account...
|
||||
</div>
|
||||
|
||||
<button type="submit" class="submit-btn" id="submitBtn">Register</button>
|
||||
</form>
|
||||
|
||||
<div class="auth-footer">
|
||||
Already have an account? <a href="/login">Sign In</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('registerForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const username = document.getElementById('username').value.trim();
|
||||
const email = document.getElementById('email').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
const confirmPassword = document.getElementById('confirm').value;
|
||||
const messageDiv = document.getElementById('message');
|
||||
const loading = document.getElementById('loading');
|
||||
const submitBtn = document.getElementById('submitBtn');
|
||||
|
||||
// Validation
|
||||
if (!username || !email || !password || !confirmPassword) {
|
||||
showMessage('Please fill in all fields', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length < 6) {
|
||||
showMessage('Password must be at least 6 characters', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
showMessage('Passwords do not match', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!email.includes('@')) {
|
||||
showMessage('Please enter a valid email address', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
loading.style.display = 'block';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
try {
|
||||
const response = await fetch('/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
confirm_password: confirmPassword
|
||||
})
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
showMessage('Account created successfully. Redirecting to sign in...', 'success');
|
||||
setTimeout(() => {
|
||||
window.location.href = '/login';
|
||||
}, 1200);
|
||||
} else {
|
||||
showMessage(data.message || 'Registration failed', 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage('Connection error. Please try again.', 'error');
|
||||
} finally {
|
||||
loading.style.display = 'none';
|
||||
submitBtn.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
function showMessage(msg, type) {
|
||||
const messageDiv = document.getElementById('message');
|
||||
messageDiv.textContent = msg;
|
||||
messageDiv.className = `message ${type}`;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user