2350 lines
83 KiB
HTML
2350 lines
83 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Dashboard</title>
|
|
<style>
|
|
:root {
|
|
--primary: #0284c7;
|
|
--primary-hover: #0369a1;
|
|
--primary-light: #f0f9ff;
|
|
--primary-border: #bae6fd;
|
|
--primary-focus-ring: rgba(2, 132, 199, 0.18);
|
|
|
|
--surface: #ffffff;
|
|
--background: #f8fafc;
|
|
--border: #e2e8f0;
|
|
--border-hover: #cbd5e1;
|
|
|
|
--text-primary: #0f172a;
|
|
--text-secondary: #475569;
|
|
--text-muted: #64748b;
|
|
|
|
--success: #059669;
|
|
--success-light: #ecfdf5;
|
|
--success-border: #a7f3d0;
|
|
--success-text: #065f46;
|
|
|
|
--warning: #d97706;
|
|
--warning-light: #fffbeb;
|
|
--warning-border: #fde68a;
|
|
--warning-text: #92400e;
|
|
|
|
--danger: #dc2626;
|
|
--danger-light: #fef2f2;
|
|
--danger-border: #fecaca;
|
|
--danger-text: #991b1b;
|
|
|
|
--info: #0284c7;
|
|
--info-light: #f0f9ff;
|
|
--info-border: #bae6fd;
|
|
--info-text: #075985;
|
|
|
|
--radius-sm: 4px;
|
|
--radius: 6px;
|
|
--radius-lg: 8px;
|
|
--shadow-subtle: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
|
|
--shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
|
|
}
|
|
|
|
* {
|
|
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);
|
|
line-height: 1.5;
|
|
-webkit-font-smoothing: antialiased;
|
|
}
|
|
|
|
/* Top Navigation Bar */
|
|
.navbar {
|
|
background-color: var(--surface);
|
|
border-bottom: 1px solid var(--border);
|
|
padding: 8px 32px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 100;
|
|
}
|
|
|
|
/* Dedicated Logo Placeholder Area */
|
|
.navbar-brand-area {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 16px;
|
|
}
|
|
|
|
.logo-placeholder-slot {
|
|
height: 56px;
|
|
display: flex;
|
|
align-items: center;
|
|
user-select: none;
|
|
}
|
|
|
|
.logo-placeholder-slot img {
|
|
max-height: 56px;
|
|
height: 54px;
|
|
width: auto;
|
|
object-fit: contain;
|
|
display: block;
|
|
}
|
|
|
|
.navbar-right {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 20px;
|
|
}
|
|
|
|
.user-info {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.user-avatar {
|
|
width: 34px;
|
|
height: 34px;
|
|
border-radius: 50%;
|
|
background-color: var(--primary-light);
|
|
border: 1px solid var(--primary-border);
|
|
color: var(--primary);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-weight: 600;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.user-meta-name {
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
display: block;
|
|
line-height: 1.2;
|
|
}
|
|
|
|
.user-meta-status {
|
|
font-size: 11px;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.logout-btn {
|
|
padding: 7px 14px;
|
|
background-color: transparent;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
color: var(--text-secondary);
|
|
transition: all 0.15s ease;
|
|
}
|
|
|
|
.logout-btn:hover {
|
|
background-color: #f1f5f9;
|
|
color: var(--text-primary);
|
|
border-color: var(--border-hover);
|
|
}
|
|
|
|
/* Main Container */
|
|
.container {
|
|
max-width: 1240px;
|
|
margin: 0 auto;
|
|
padding: 32px 24px;
|
|
}
|
|
|
|
/* Page Header */
|
|
.header {
|
|
margin-bottom: 28px;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 22px;
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
letter-spacing: -0.01em;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.header p {
|
|
color: var(--text-secondary);
|
|
font-size: 14px;
|
|
}
|
|
|
|
/* Navigation Tabs */
|
|
.tabs {
|
|
display: flex;
|
|
gap: 8px;
|
|
border-bottom: 1px solid var(--border);
|
|
margin-bottom: 28px;
|
|
overflow-x: auto;
|
|
}
|
|
|
|
.tab {
|
|
padding: 10px 16px;
|
|
cursor: pointer;
|
|
font-weight: 500;
|
|
font-size: 14px;
|
|
color: var(--text-muted);
|
|
border-bottom: 2px solid transparent;
|
|
margin-bottom: -1px;
|
|
transition: all 0.15s ease;
|
|
white-space: nowrap;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.tab:hover {
|
|
color: var(--primary);
|
|
}
|
|
|
|
.tab.active {
|
|
color: var(--primary);
|
|
font-weight: 600;
|
|
border-bottom-color: var(--primary);
|
|
}
|
|
|
|
.tab-badge {
|
|
background-color: var(--warning-light);
|
|
color: var(--warning-text);
|
|
border: 1px solid var(--warning-border);
|
|
padding: 1px 7px;
|
|
border-radius: 10px;
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.tab-badge:empty {
|
|
display: none;
|
|
}
|
|
|
|
.tab-content {
|
|
display: none;
|
|
}
|
|
|
|
.tab-content.active {
|
|
display: block;
|
|
}
|
|
|
|
/* Metric / Stats Cards */
|
|
.stats {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
|
gap: 16px;
|
|
margin-bottom: 28px;
|
|
}
|
|
|
|
.stat {
|
|
background-color: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-lg);
|
|
padding: 20px;
|
|
box-shadow: var(--shadow-card);
|
|
}
|
|
|
|
.stat.green {
|
|
background-color: #f0fdf4;
|
|
border: 1px solid #bbf7d0;
|
|
border-left: 4px solid #16a34a;
|
|
}
|
|
|
|
.stat.green .stat-label {
|
|
color: #15803d;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.stat.green .stat-value {
|
|
color: #14532d;
|
|
}
|
|
|
|
.stat.green .stat-sub {
|
|
color: #166534;
|
|
}
|
|
|
|
.stat.red {
|
|
background-color: #fef2f2;
|
|
border: 1px solid #fecaca;
|
|
border-left: 4px solid #dc2626;
|
|
}
|
|
|
|
.stat.red .stat-label {
|
|
color: #b91c1c;
|
|
font-weight: 700;
|
|
}
|
|
|
|
.stat.red .stat-value {
|
|
color: #991b1b;
|
|
}
|
|
|
|
.stat.red .stat-sub {
|
|
color: #b91c1c;
|
|
}
|
|
|
|
.stat.red.zero {
|
|
background-color: #fef2f2;
|
|
border: 1px solid #fecaca;
|
|
border-left: 4px solid #ef4444;
|
|
}
|
|
|
|
.stat.red.zero .stat-label {
|
|
color: #b91c1c;
|
|
}
|
|
|
|
.stat.red.zero .stat-value {
|
|
color: #991b1b;
|
|
}
|
|
|
|
.stat.red.zero .stat-sub {
|
|
color: #b91c1c;
|
|
}
|
|
|
|
.stat.plain {
|
|
background-color: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-left: 4px solid #94a3b8;
|
|
}
|
|
|
|
.stat-label {
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
color: var(--text-muted);
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
.stat-value {
|
|
font-size: 26px;
|
|
font-weight: 700;
|
|
color: var(--text-primary);
|
|
line-height: 1.1;
|
|
}
|
|
|
|
.stat-sub {
|
|
font-size: 12px;
|
|
color: var(--text-muted);
|
|
margin-top: 6px;
|
|
}
|
|
|
|
/* Upload Dropzone Area */
|
|
.upload-area {
|
|
background-color: var(--surface);
|
|
border: 2px dashed #cbd5e1;
|
|
border-radius: var(--radius-lg);
|
|
padding: 48px 32px;
|
|
text-align: center;
|
|
transition: all 0.2s ease;
|
|
margin-bottom: 28px;
|
|
}
|
|
|
|
.upload-area:hover,
|
|
.upload-area.dragover {
|
|
border-color: var(--primary);
|
|
background-color: var(--primary-light);
|
|
}
|
|
|
|
.upload-text h3 {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
.upload-text p {
|
|
color: var(--text-secondary);
|
|
font-size: 13px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.file-input {
|
|
display: none;
|
|
}
|
|
|
|
/* Buttons */
|
|
.btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 8px;
|
|
padding: 9px 18px;
|
|
border: 1px solid transparent;
|
|
border-radius: var(--radius);
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.15s ease;
|
|
font-family: inherit;
|
|
line-height: 1.4;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: var(--primary);
|
|
color: #ffffff;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background-color: var(--primary-hover);
|
|
}
|
|
|
|
.btn-secondary {
|
|
background-color: #f1f5f9;
|
|
color: var(--text-secondary);
|
|
border-color: var(--border);
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background-color: #e2e8f0;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.btn-success {
|
|
background-color: var(--success);
|
|
color: #ffffff;
|
|
}
|
|
|
|
.btn-success:hover {
|
|
background-color: #047857;
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.review-btn {
|
|
background-color: var(--warning-light);
|
|
color: var(--warning-text);
|
|
border: 1px solid var(--warning-border);
|
|
padding: 6px 14px;
|
|
border-radius: var(--radius);
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: background-color 0.15s ease;
|
|
}
|
|
|
|
.review-btn:hover {
|
|
background-color: #fef3c7;
|
|
}
|
|
|
|
.approve-btn {
|
|
background-color: var(--surface);
|
|
color: var(--primary);
|
|
border: 1px solid var(--primary-border);
|
|
padding: 5px 12px;
|
|
border-radius: var(--radius-sm);
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.15s ease;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.approve-btn:hover {
|
|
background-color: var(--primary-light);
|
|
border-color: var(--primary);
|
|
}
|
|
|
|
.approve-btn:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
/* Loading / Progress States */
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
padding: 36px 24px;
|
|
background-color: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-lg);
|
|
margin-top: 24px;
|
|
}
|
|
|
|
.loading.show {
|
|
display: block;
|
|
}
|
|
|
|
.spinner {
|
|
width: 32px;
|
|
height: 32px;
|
|
border: 3px solid var(--border);
|
|
border-top-color: var(--primary);
|
|
border-radius: 50%;
|
|
animation: spin 0.7s linear infinite;
|
|
margin: 0 auto 16px;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
/* Results Card */
|
|
.results {
|
|
background-color: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-lg);
|
|
padding: 24px;
|
|
box-shadow: var(--shadow-card);
|
|
margin-top: 24px;
|
|
display: none;
|
|
}
|
|
|
|
.results.show {
|
|
display: block;
|
|
}
|
|
|
|
.result-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 20px;
|
|
padding-bottom: 16px;
|
|
border-bottom: 1px solid var(--border);
|
|
flex-wrap: wrap;
|
|
gap: 12px;
|
|
}
|
|
|
|
.result-header h2 {
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.badge {
|
|
padding: 4px 10px;
|
|
border-radius: 12px;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
}
|
|
|
|
.badge.success {
|
|
background-color: var(--success-light);
|
|
color: var(--success-text);
|
|
border: 1px solid var(--success-border);
|
|
}
|
|
|
|
.badge.warning {
|
|
background-color: var(--warning-light);
|
|
color: var(--warning-text);
|
|
border: 1px solid var(--warning-border);
|
|
}
|
|
|
|
/* Metadata Grid */
|
|
.metadata {
|
|
background-color: #f8fafc;
|
|
border: 1px solid var(--border);
|
|
padding: 16px;
|
|
border-radius: var(--radius);
|
|
margin-bottom: 20px;
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
|
gap: 16px;
|
|
}
|
|
|
|
.metadata-item {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}
|
|
|
|
.metadata-label {
|
|
font-size: 11px;
|
|
color: var(--text-muted);
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
}
|
|
|
|
.metadata-value {
|
|
font-size: 13px;
|
|
color: var(--text-primary);
|
|
font-weight: 500;
|
|
word-break: break-word;
|
|
}
|
|
|
|
/* View Toolbar (Segmented Controls) */
|
|
.view-toolbar {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 16px;
|
|
flex-wrap: wrap;
|
|
gap: 12px;
|
|
}
|
|
|
|
.segmented {
|
|
display: inline-flex;
|
|
background-color: #f1f5f9;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
padding: 3px;
|
|
gap: 2px;
|
|
}
|
|
|
|
.seg-btn {
|
|
background: transparent;
|
|
border: none;
|
|
padding: 6px 14px;
|
|
border-radius: var(--radius-sm);
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
color: var(--text-secondary);
|
|
cursor: pointer;
|
|
transition: all 0.15s ease;
|
|
}
|
|
|
|
.seg-btn:hover {
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.seg-btn.active {
|
|
background-color: var(--surface);
|
|
color: var(--primary);
|
|
font-weight: 600;
|
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
}
|
|
|
|
/* Tables */
|
|
.table-scroll {
|
|
overflow-x: auto;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
}
|
|
|
|
.items-table,
|
|
.history-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
font-size: 13px;
|
|
text-align: left;
|
|
}
|
|
|
|
.items-table th,
|
|
.history-table th {
|
|
background-color: #f8fafc;
|
|
color: var(--text-secondary);
|
|
font-weight: 600;
|
|
font-size: 12px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.03em;
|
|
padding: 10px 14px;
|
|
border-bottom: 1px solid var(--border);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.items-table td,
|
|
.history-table td {
|
|
padding: 11px 14px;
|
|
border-bottom: 1px solid var(--border);
|
|
color: var(--text-primary);
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.items-table tr:last-child td,
|
|
.history-table tr:last-child td {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.items-table tbody tr:hover,
|
|
.history-table tbody tr:hover {
|
|
background-color: #f8fafc;
|
|
}
|
|
|
|
.history-table tbody tr {
|
|
cursor: pointer;
|
|
}
|
|
|
|
/* Status Tags / Chips */
|
|
.tag {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
padding: 3px 8px;
|
|
border-radius: 4px;
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
letter-spacing: 0.01em;
|
|
line-height: 1.2;
|
|
}
|
|
|
|
.tag.insheet {
|
|
background-color: var(--success-light);
|
|
color: var(--success-text);
|
|
border: 1px solid var(--success-border);
|
|
}
|
|
|
|
.tag.pending {
|
|
background-color: var(--warning-light);
|
|
color: var(--warning-text);
|
|
border: 1px solid var(--warning-border);
|
|
}
|
|
|
|
.tag.matched {
|
|
background-color: var(--success-light);
|
|
color: var(--success-text);
|
|
border: 1px solid var(--success-border);
|
|
}
|
|
|
|
.tag.manual {
|
|
background-color: #f5f3ff;
|
|
color: #6d28d9;
|
|
border: 1px solid #ddd6fe;
|
|
}
|
|
|
|
.tag.edited {
|
|
background-color: var(--warning-light);
|
|
color: var(--warning-text);
|
|
border: 1px solid var(--warning-border);
|
|
}
|
|
|
|
.tag.missing {
|
|
background-color: var(--danger-light);
|
|
color: var(--danger-text);
|
|
border: 1px solid var(--danger-border);
|
|
}
|
|
|
|
.tag.api {
|
|
background-color: var(--info-light);
|
|
color: var(--info-text);
|
|
border: 1px solid var(--info-border);
|
|
}
|
|
|
|
.muted {
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
/* Code Input & Autocomplete */
|
|
.code-input-wrapper {
|
|
position: relative;
|
|
}
|
|
|
|
.code-input {
|
|
width: 100%;
|
|
padding: 7px 10px;
|
|
border: 1px solid #cbd5e1;
|
|
border-radius: var(--radius-sm);
|
|
font-size: 13px;
|
|
color: var(--text-primary);
|
|
background-color: #ffffff;
|
|
font-family: inherit;
|
|
transition: border-color 0.15s ease, box-shadow 0.15s ease;
|
|
}
|
|
|
|
.code-input:focus {
|
|
outline: none;
|
|
border-color: var(--primary);
|
|
box-shadow: 0 0 0 3px var(--primary-focus-ring);
|
|
}
|
|
|
|
.code-input.empty {
|
|
border-color: var(--warning);
|
|
background-color: #fffdf5;
|
|
}
|
|
|
|
.autocomplete-list {
|
|
display: none;
|
|
position: absolute;
|
|
top: 100%;
|
|
left: 0;
|
|
right: 0;
|
|
z-index: 50;
|
|
background: #ffffff;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius);
|
|
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
|
|
max-height: 200px;
|
|
overflow-y: auto;
|
|
margin-top: 4px;
|
|
}
|
|
|
|
.autocomplete-list.show {
|
|
display: block;
|
|
}
|
|
|
|
.autocomplete-item {
|
|
padding: 8px 12px;
|
|
cursor: pointer;
|
|
font-size: 12px;
|
|
border-bottom: 1px solid #f1f5f9;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.autocomplete-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.autocomplete-item:hover,
|
|
.autocomplete-item.active {
|
|
background-color: var(--primary-light);
|
|
}
|
|
|
|
.autocomplete-item .ac-code {
|
|
font-weight: 700;
|
|
color: var(--primary);
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.autocomplete-item .ac-name {
|
|
color: var(--text-secondary);
|
|
flex: 1;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.autocomplete-item .ac-category {
|
|
font-size: 11px;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
/* File Chip */
|
|
.file-chip {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
margin-top: 14px;
|
|
padding: 6px 12px;
|
|
background-color: #f1f5f9;
|
|
border: 1px solid var(--border);
|
|
border-radius: 16px;
|
|
font-size: 13px;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.file-chip button {
|
|
border: none;
|
|
background: transparent;
|
|
cursor: pointer;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
color: var(--text-muted);
|
|
padding: 0 4px;
|
|
}
|
|
|
|
.file-chip button:hover {
|
|
color: var(--danger);
|
|
}
|
|
|
|
.hint {
|
|
color: var(--text-secondary);
|
|
font-size: 13px;
|
|
margin: 12px 0 16px;
|
|
line-height: 1.4;
|
|
}
|
|
|
|
.action-buttons {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-top: 20px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
/* Messages / Alerts */
|
|
.message {
|
|
padding: 12px 16px;
|
|
border-radius: var(--radius);
|
|
margin-bottom: 20px;
|
|
display: none;
|
|
font-size: 13px;
|
|
line-height: 1.4;
|
|
}
|
|
|
|
.message.show {
|
|
display: block;
|
|
}
|
|
|
|
.message.error {
|
|
background-color: var(--danger-light);
|
|
color: var(--danger-text);
|
|
border: 1px solid var(--danger-border);
|
|
}
|
|
|
|
.message.success {
|
|
background-color: var(--success-light);
|
|
color: var(--success-text);
|
|
border: 1px solid var(--success-border);
|
|
}
|
|
|
|
.message.warning {
|
|
background-color: var(--warning-light);
|
|
color: var(--warning-text);
|
|
border: 1px solid var(--warning-border);
|
|
}
|
|
|
|
/* Empty State */
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 48px 20px;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
.empty-state-title {
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
color: var(--text-secondary);
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
.empty-state-desc {
|
|
font-size: 13px;
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
/* JSON Viewer */
|
|
.json-viewer {
|
|
background-color: #0f172a;
|
|
color: #e2e8f0;
|
|
padding: 18px;
|
|
border-radius: var(--radius);
|
|
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
font-size: 12px;
|
|
line-height: 1.6;
|
|
max-height: 500px;
|
|
overflow: auto;
|
|
}
|
|
|
|
.json-key { color: #38bdf8; }
|
|
.json-string { color: #34d399; }
|
|
.json-number { color: #f59e0b; }
|
|
.json-boolean { color: #ec4899; }
|
|
.json-null { color: #94a3b8; }
|
|
|
|
.hidden {
|
|
display: none !important;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.navbar {
|
|
flex-direction: column;
|
|
gap: 12px;
|
|
padding: 12px 16px;
|
|
align-items: flex-start;
|
|
}
|
|
|
|
.navbar-right {
|
|
width: 100%;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.container {
|
|
padding: 20px 16px;
|
|
}
|
|
|
|
.upload-area {
|
|
padding: 32px 16px;
|
|
}
|
|
|
|
.action-buttons {
|
|
flex-direction: column;
|
|
}
|
|
|
|
.action-buttons .btn {
|
|
width: 100%;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Top Navigation Bar -->
|
|
<nav class="navbar">
|
|
<div class="navbar-brand-area">
|
|
<div class="logo-placeholder-slot" id="logoPlaceholder">
|
|
<img src="{{ url_for('static', filename='logo.png') }}" alt="Logo">
|
|
</div>
|
|
</div>
|
|
<div class="navbar-right">
|
|
<div class="user-info">
|
|
<div class="user-avatar" id="userAvatar">U</div>
|
|
<div>
|
|
<span class="user-meta-name" id="userName">{{ username }}</span>
|
|
<span class="user-meta-status">Active Session</span>
|
|
</div>
|
|
</div>
|
|
<a href="/logout" class="logout-btn">Sign Out</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Main Container -->
|
|
<div class="container">
|
|
<!-- Page Header -->
|
|
<div class="header">
|
|
<h1>Invoice & Item Code Management</h1>
|
|
<p>Upload invoices to extract line items and match standardized item codes</p>
|
|
</div>
|
|
|
|
<!-- Navigation Tabs -->
|
|
<div class="tabs">
|
|
<div class="tab active" data-tab="extract" onclick="switchTab('extract')">
|
|
Extract Invoice
|
|
</div>
|
|
<div class="tab" data-tab="manual" onclick="switchTab('manual')">
|
|
Manual Item Codes
|
|
</div>
|
|
<div class="tab" data-tab="pending" onclick="switchTab('pending')">
|
|
Pending Approval<span class="tab-badge" id="pendingTabBadge"></span>
|
|
</div>
|
|
<div class="tab" data-tab="history" onclick="switchTab('history')">
|
|
History
|
|
</div>
|
|
<div class="tab" data-tab="profile" onclick="switchTab('profile')">
|
|
Profile
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab 1: Extract Invoice -->
|
|
<div id="extract" class="tab-content active">
|
|
<!-- Stats Grid -->
|
|
<div class="stats">
|
|
<div class="stat green">
|
|
<div class="stat-label">Item Codes From Catalog</div>
|
|
<div class="stat-value" id="itemsFromSheet">—</div>
|
|
<div class="stat-sub">Current invoice</div>
|
|
</div>
|
|
<div class="stat red" id="statPending">
|
|
<div class="stat-label">Approval Remaining</div>
|
|
<div class="stat-value" id="itemsPending">0</div>
|
|
<div class="stat-sub">Across all invoices</div>
|
|
</div>
|
|
<div class="stat plain">
|
|
<div class="stat-label">Total Items</div>
|
|
<div class="stat-value" id="totalItems">—</div>
|
|
<div class="stat-sub">Current invoice</div>
|
|
</div>
|
|
<div class="stat plain">
|
|
<div class="stat-label">Total Invoices Processed</div>
|
|
<div class="stat-value" id="totalInvoices">0</div>
|
|
<div class="stat-sub">To date</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="message" id="message"></div>
|
|
|
|
<!-- Upload Dropzone Area -->
|
|
<div class="upload-area" id="uploadArea">
|
|
<div class="upload-text">
|
|
<h3>Upload Invoice</h3>
|
|
<p>Drag and drop a PDF, PNG, or JPG file here, or browse from your device</p>
|
|
</div>
|
|
<button type="button" class="btn btn-primary" onclick="document.getElementById('fileInput').click()">
|
|
Select File
|
|
</button>
|
|
<input type="file" id="fileInput" class="file-input" accept=".pdf,.png,.jpg,.jpeg" onchange="handleFileSelect(event)">
|
|
<p style="margin-top: 14px; color: var(--text-muted); font-size: 12px;">
|
|
Maximum file size: 100 MB • Supported formats: PDF, PNG, JPG, JPEG
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Loading State -->
|
|
<div class="loading" id="loading">
|
|
<div class="spinner"></div>
|
|
<p id="loadingStatusText" style="font-weight: 500; color: var(--text-primary); font-size: 14px;">Extracting invoice data...</p>
|
|
<div style="max-width: 320px; margin: 14px auto 0; background: #e2e8f0; border-radius: 4px; overflow: hidden; height: 6px;">
|
|
<div id="loadingProgressBar" style="width: 0%; height: 100%; background: var(--primary); transition: width 0.3s ease;"></div>
|
|
</div>
|
|
<p id="loadingProgressPct" style="color: var(--primary); margin-top: 8px; font-size: 13px; font-weight: 600;">0%</p>
|
|
<p style="color: var(--text-muted); margin-top: 4px; font-size: 12px;">Processing may take 10 to 30 seconds</p>
|
|
</div>
|
|
|
|
<!-- Results Card -->
|
|
<div class="results" id="results">
|
|
<div class="result-header">
|
|
<h2>Extraction Results</h2>
|
|
<div id="resultBadge"></div>
|
|
</div>
|
|
|
|
<!-- Metadata -->
|
|
<div class="metadata" id="metadata"></div>
|
|
|
|
<!-- View Toolbar -->
|
|
<div class="view-toolbar">
|
|
<div class="segmented">
|
|
<button class="seg-btn active" id="viewTableBtn" onclick="setView('table')">Table</button>
|
|
<button class="seg-btn" id="viewJsonBtn" onclick="setView('json')">JSON</button>
|
|
</div>
|
|
<div class="segmented hidden" id="jsonSourceToggle">
|
|
<button class="seg-btn active" id="srcApiBtn" onclick="setJsonSource('api')">API Response</button>
|
|
<button class="seg-btn" id="srcEnrichedBtn" onclick="setJsonSource('enriched')">With Item Codes</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Table View -->
|
|
<div id="tableView">
|
|
<div class="table-scroll">
|
|
<table class="items-table" id="itemsTable">
|
|
<thead>
|
|
<tr>
|
|
<th>Description</th>
|
|
<th>Quantity</th>
|
|
<th>Unit Price</th>
|
|
<th>Item Code</th>
|
|
<th>Source</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="itemsTableBody"></tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- JSON View -->
|
|
<div id="jsonView" class="hidden">
|
|
<pre class="json-viewer" id="jsonViewer"></pre>
|
|
</div>
|
|
|
|
<!-- Actions -->
|
|
<div class="action-buttons">
|
|
<button class="btn btn-primary" onclick="copyJSON()">Copy JSON</button>
|
|
<button class="btn btn-success" onclick="downloadJSON()">Download JSON</button>
|
|
<button class="btn btn-secondary" onclick="resetForm()">Upload Another</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab 2: Manual Item Codes -->
|
|
<div id="manual" class="tab-content">
|
|
<div class="message" id="manualMessage"></div>
|
|
|
|
<div class="upload-area" id="manualUploadArea">
|
|
<div class="upload-text">
|
|
<h3>Upload Invoice for Manual Item Code Entry</h3>
|
|
<p>Select a file to extract line items, then review and assign item codes manually.</p>
|
|
</div>
|
|
<button type="button" class="btn btn-secondary" onclick="document.getElementById('manualFileInput').click()">
|
|
Select File
|
|
</button>
|
|
<input type="file" id="manualFileInput" class="file-input" accept=".pdf,.png,.jpg,.jpeg" onchange="handleManualFileSelect(event)">
|
|
|
|
<div>
|
|
<div class="file-chip hidden" id="manualFileChip">
|
|
<span id="manualFileName"></span>
|
|
<button type="button" onclick="clearManualFile()" title="Remove file">Remove</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="margin-top: 18px;">
|
|
<button type="button" class="btn btn-primary" id="manualExtractBtn" onclick="extractForManual()" disabled>
|
|
Extract Invoice
|
|
</button>
|
|
</div>
|
|
<p style="margin-top: 14px; color: var(--text-muted); font-size: 12px;">
|
|
Maximum file size: 100 MB • Supported formats: PDF, PNG, JPG, JPEG
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Loading -->
|
|
<div class="loading" id="manualLoading">
|
|
<div class="spinner"></div>
|
|
<p style="font-weight: 500; color: var(--text-primary); font-size: 14px;">Extracting invoice data...</p>
|
|
<p style="color: var(--text-muted); margin-top: 4px; font-size: 12px;">Processing may take 10 to 30 seconds</p>
|
|
</div>
|
|
|
|
<!-- Results -->
|
|
<div class="results" id="manualResults">
|
|
<div class="result-header">
|
|
<h2>Manual Item Code Entry</h2>
|
|
<div id="manualBadge"></div>
|
|
</div>
|
|
|
|
<div class="metadata" id="manualMetadata"></div>
|
|
|
|
<p class="hint">Enter an item code for each row. Rows highlighted in amber are missing a code. Press Enter to navigate to the next line.</p>
|
|
|
|
<div class="table-scroll">
|
|
<table class="items-table">
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Description</th>
|
|
<th>Quantity</th>
|
|
<th>Unit Price</th>
|
|
<th>Item Code</th>
|
|
<th>Source</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="manualTableBody"></tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="action-buttons">
|
|
<button class="btn btn-primary" id="manualSaveBtn" onclick="saveManualCodes()" disabled>Save Item Codes</button>
|
|
<button class="btn btn-secondary" id="manualJsonBtn" onclick="toggleManualJson()">Show JSON</button>
|
|
<button class="btn btn-success" onclick="downloadManualJSON()">Download JSON</button>
|
|
<button class="btn btn-secondary" onclick="resetManual()">Upload Another</button>
|
|
</div>
|
|
|
|
<pre class="json-viewer hidden" id="manualJsonViewer" style="margin-top: 20px;"></pre>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab 3: Pending Approval -->
|
|
<div id="pending" class="tab-content">
|
|
<div class="message" id="pendingMessage"></div>
|
|
|
|
<div class="results show" id="pendingCard">
|
|
<div class="result-header">
|
|
<h2>Pending Approval Queue</h2>
|
|
<div id="pendingSubtitle"></div>
|
|
</div>
|
|
|
|
<div id="pendingEmpty" class="empty-state hidden"></div>
|
|
|
|
<div id="pendingTableWrap">
|
|
<p class="hint">The items below were extracted from invoices but do not have confirmed catalog matches. Enter and approve codes to add them to your catalog for future matching.</p>
|
|
<div class="table-scroll">
|
|
<table class="items-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Invoice</th>
|
|
<th>Description</th>
|
|
<th>Quantity</th>
|
|
<th>Unit Price</th>
|
|
<th style="min-width: 220px;">Item Code</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="pendingTableBody"></tbody>
|
|
</table>
|
|
</div>
|
|
<div class="action-buttons">
|
|
<button class="btn btn-success" id="approveAllBtn" onclick="approveAllPending()">Approve All Filled</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab 4: History -->
|
|
<div id="history" class="tab-content">
|
|
<div class="results show">
|
|
<div class="result-header">
|
|
<h2>Invoice History</h2>
|
|
</div>
|
|
<div class="table-scroll">
|
|
<table class="history-table" id="historyTable">
|
|
<thead>
|
|
<tr>
|
|
<th>Invoice ID</th>
|
|
<th>File Name</th>
|
|
<th>Date Processed</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="historyTableBody">
|
|
<tr>
|
|
<td colspan="4" style="text-align: center; padding: 36px; color: var(--text-muted);">
|
|
Loading history...
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tab 5: Profile -->
|
|
<div id="profile" class="tab-content">
|
|
<div class="results show" style="max-width: 600px;">
|
|
<div class="result-header">
|
|
<h2>User Account</h2>
|
|
</div>
|
|
<div class="metadata" id="profileInfo"></div>
|
|
|
|
<div style="margin-top: 24px;">
|
|
<h3 style="margin-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--text-primary);">Account Security</h3>
|
|
<p style="color: var(--text-secondary); margin-bottom: 16px; font-size: 13px; line-height: 1.5;">
|
|
Authenticated user account for medical management and invoice data processing.
|
|
</p>
|
|
<button class="btn btn-secondary" onclick="alert('Password changes are managed by the administrator.')">Change Password</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let lastExtractedData = null;
|
|
let lastExtractionId = null;
|
|
let pendingItems = []; // persistent approval queue (all invoices), from /api/pending-items
|
|
let currentView = 'table'; // 'table' | 'json'
|
|
let jsonSource = 'api'; // 'api' (as returned by the API) | 'enriched' (with item codes)
|
|
|
|
// Drag and drop
|
|
const uploadArea = document.getElementById('uploadArea');
|
|
|
|
uploadArea.addEventListener('dragover', (e) => {
|
|
e.preventDefault();
|
|
uploadArea.classList.add('dragover');
|
|
});
|
|
|
|
uploadArea.addEventListener('dragleave', () => {
|
|
uploadArea.classList.remove('dragover');
|
|
});
|
|
|
|
uploadArea.addEventListener('drop', (e) => {
|
|
e.preventDefault();
|
|
uploadArea.classList.remove('dragover');
|
|
if (e.dataTransfer.files.length > 0) {
|
|
handleFile(e.dataTransfer.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)) {
|
|
showMessage('Invalid file type. Please upload a PDF, PNG, or JPG file.', 'error');
|
|
return;
|
|
}
|
|
|
|
if (file.size > 100 * 1024 * 1024) {
|
|
showMessage('File size exceeds the 100 MB limit.', 'error');
|
|
return;
|
|
}
|
|
|
|
uploadInvoice(file);
|
|
}
|
|
|
|
function startFakeProgress(barId, pctId, textId) {
|
|
const bar = document.getElementById(barId);
|
|
const pct = document.getElementById(pctId);
|
|
const text = document.getElementById(textId);
|
|
let value = 0;
|
|
|
|
const stages = [
|
|
[0, 'Reading invoice file...'],
|
|
[25, 'Extracting line items...'],
|
|
[55, 'Checking item codes against catalog...'],
|
|
[80, 'Finalizing data...'],
|
|
];
|
|
|
|
const timer = setInterval(() => {
|
|
value = Math.min(90, value + (value < 50 ? 4 : 1.5));
|
|
if (bar) bar.style.width = value + '%';
|
|
if (pct) pct.textContent = Math.round(value) + '%';
|
|
if (text) {
|
|
const stage = [...stages].reverse().find(([threshold]) => value >= threshold);
|
|
if (stage) text.textContent = stage[1];
|
|
}
|
|
}, 350);
|
|
|
|
return timer;
|
|
}
|
|
|
|
function finishFakeProgress(timer, barId, pctId) {
|
|
clearInterval(timer);
|
|
const bar = document.getElementById(barId);
|
|
const pct = document.getElementById(pctId);
|
|
if (bar) bar.style.width = '100%';
|
|
if (pct) pct.textContent = '100%';
|
|
}
|
|
|
|
async function uploadInvoice(file) {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
|
|
document.getElementById('loading').classList.add('show');
|
|
document.getElementById('results').classList.remove('show');
|
|
document.getElementById('uploadArea').classList.add('hidden');
|
|
hideMessage();
|
|
|
|
const progressTimer = startFakeProgress('loadingProgressBar', 'loadingProgressPct', 'loadingStatusText');
|
|
|
|
try {
|
|
const response = await fetch('/api/upload', {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
const result = await response.json();
|
|
finishFakeProgress(progressTimer, 'loadingProgressBar', 'loadingProgressPct');
|
|
|
|
if (response.ok && result.success) {
|
|
lastExtractedData = result.data;
|
|
lastExtractionId = result.extraction_id || null;
|
|
displayResults(result.data);
|
|
showMessage('Invoice extracted and processed successfully.', 'success');
|
|
loadInvoiceTotal();
|
|
loadPending();
|
|
} else {
|
|
document.getElementById('uploadArea').classList.remove('hidden');
|
|
showMessage(result.error || 'Extraction failed.', 'error');
|
|
}
|
|
} catch (error) {
|
|
finishFakeProgress(progressTimer, 'loadingProgressBar', 'loadingProgressPct');
|
|
document.getElementById('uploadArea').classList.remove('hidden');
|
|
showMessage('Connection error during upload. Please try again.', 'error');
|
|
} finally {
|
|
setTimeout(() => {
|
|
document.getElementById('loading').classList.remove('show');
|
|
document.getElementById('loadingProgressBar').style.width = '0%';
|
|
document.getElementById('loadingProgressPct').textContent = '0%';
|
|
document.getElementById('loadingStatusText').textContent = 'Extracting invoice data...';
|
|
}, 300);
|
|
}
|
|
}
|
|
|
|
function displayResults(data) {
|
|
document.getElementById('uploadArea').classList.add('hidden');
|
|
|
|
document.getElementById('metadata').innerHTML = `
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Upload ID</span>
|
|
<span class="metadata-value">${data._metadata?.upload_id || '-'}</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Timestamp</span>
|
|
<span class="metadata-value">${data._metadata?.upload_timestamp ? new Date(data._metadata.upload_timestamp).toLocaleString() : '-'}</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Invoice ID</span>
|
|
<span class="metadata-value">${data.invoice_id || '-'}</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Seller</span>
|
|
<span class="metadata-value">${data.seller_name || '-'}</span>
|
|
</div>
|
|
`;
|
|
|
|
refreshAll();
|
|
document.getElementById('results').classList.add('show');
|
|
}
|
|
|
|
function refreshAll() {
|
|
const items = (lastExtractedData && lastExtractedData.items) || [];
|
|
updateStats(items);
|
|
renderResultBadge(items);
|
|
renderItemsTable(items);
|
|
renderJson();
|
|
}
|
|
|
|
function isInCsv(item) {
|
|
if (typeof item.in_csv === 'boolean') return item.in_csv;
|
|
return item.item_code_source === 'drug_list_match';
|
|
}
|
|
|
|
function updateStats(items) {
|
|
if (!items) {
|
|
document.getElementById('itemsFromSheet').textContent = '—';
|
|
document.getElementById('totalItems').textContent = '—';
|
|
return;
|
|
}
|
|
document.getElementById('itemsFromSheet').textContent = items.filter(isInCsv).length;
|
|
document.getElementById('totalItems').textContent = items.length;
|
|
}
|
|
|
|
function updatePendingCounts() {
|
|
const n = pendingItems.length;
|
|
document.getElementById('itemsPending').textContent = n;
|
|
document.getElementById('statPending').classList.toggle('zero', n === 0);
|
|
document.getElementById('pendingTabBadge').textContent = n > 0 ? n : '';
|
|
}
|
|
|
|
async function loadPending() {
|
|
try {
|
|
const response = await fetch('/api/pending-items');
|
|
const result = await response.json();
|
|
if (result.success) {
|
|
pendingItems = result.data;
|
|
updatePendingCounts();
|
|
renderPending();
|
|
if (typeof result.total_invoices === 'number') updateTotalInvoicesBadge(result.total_invoices);
|
|
}
|
|
} catch (error) { /* silent */ }
|
|
}
|
|
|
|
function renderResultBadge(items) {
|
|
const pending = items.filter(i => !isInCsv(i)).length;
|
|
const badge = document.getElementById('resultBadge');
|
|
if (items.length > 0 && pending === 0) {
|
|
badge.innerHTML = '<span class="badge success">All items matched in catalog</span>';
|
|
} else if (pending > 0) {
|
|
badge.innerHTML = `<button type="button" class="review-btn" onclick="switchTab('pending')">${pending} item${pending === 1 ? '' : 's'} awaiting approval — Review</button>`;
|
|
} else {
|
|
badge.innerHTML = '';
|
|
}
|
|
}
|
|
|
|
function renderItemsTable(items) {
|
|
const tbody = document.getElementById('itemsTableBody');
|
|
tbody.innerHTML = '';
|
|
|
|
items.forEach((item, index) => {
|
|
const row = document.createElement('tr');
|
|
row.dataset.index = index;
|
|
|
|
[item.description, item.quantity, item.unit_price].forEach(v => {
|
|
const td = document.createElement('td');
|
|
td.textContent = (v === undefined || v === null || v === '') ? '-' : v;
|
|
row.appendChild(td);
|
|
});
|
|
|
|
const codeTd = document.createElement('td');
|
|
const sourceTd = document.createElement('td');
|
|
|
|
if (isInCsv(item)) {
|
|
const strong = document.createElement('strong');
|
|
strong.textContent = item.item_code;
|
|
codeTd.appendChild(strong);
|
|
const label = item.item_code_source === 'manual' ? 'Approved' : 'From Catalog';
|
|
sourceTd.innerHTML = `<span class="tag insheet">${label}</span>`;
|
|
} else {
|
|
codeTd.innerHTML = '<span class="muted">—</span>';
|
|
sourceTd.innerHTML = '<span class="tag pending">Pending Approval</span>';
|
|
}
|
|
|
|
row.appendChild(codeTd);
|
|
row.appendChild(sourceTd);
|
|
tbody.appendChild(row);
|
|
});
|
|
}
|
|
|
|
// ---------- Pending Approval tab ----------
|
|
|
|
function showPendingMessage(msg, type) {
|
|
const el = document.getElementById('pendingMessage');
|
|
el.textContent = msg;
|
|
el.className = `message show ${type}`;
|
|
}
|
|
|
|
function renderPending() {
|
|
const tbody = document.getElementById('pendingTableBody');
|
|
const wrap = document.getElementById('pendingTableWrap');
|
|
const empty = document.getElementById('pendingEmpty');
|
|
const subtitle = document.getElementById('pendingSubtitle');
|
|
|
|
const drafts = {};
|
|
tbody.querySelectorAll('.code-input').forEach(i => { drafts[i.dataset.key] = i.value; });
|
|
tbody.innerHTML = '';
|
|
|
|
if (pendingItems.length === 0) {
|
|
wrap.classList.add('hidden');
|
|
empty.classList.remove('hidden');
|
|
empty.innerHTML = '<div class="empty-state-title">No Pending Items</div><div class="empty-state-desc">All extracted item codes across all invoices have been confirmed and cataloged.</div>';
|
|
subtitle.innerHTML = '<span class="badge success">All items approved</span>';
|
|
return;
|
|
}
|
|
|
|
empty.classList.add('hidden');
|
|
wrap.classList.remove('hidden');
|
|
subtitle.innerHTML = `<span class="badge warning">${pendingItems.length} remaining</span>`;
|
|
|
|
pendingItems.forEach((p) => {
|
|
const key = `${p.extraction_id}:${p.index}`;
|
|
const tr = document.createElement('tr');
|
|
|
|
const invTd = document.createElement('td');
|
|
invTd.textContent = p.invoice_id || p.filename || ('#' + p.extraction_id);
|
|
invTd.title = p.created_at ? new Date(p.created_at).toLocaleString() : '';
|
|
tr.appendChild(invTd);
|
|
|
|
[p.description, p.quantity, p.unit_price].forEach(v => {
|
|
const td = document.createElement('td');
|
|
td.textContent = (v === undefined || v === null || v === '') ? '-' : v;
|
|
tr.appendChild(td);
|
|
});
|
|
|
|
const codeTd = document.createElement('td');
|
|
const wrapper = document.createElement('div');
|
|
wrapper.className = 'code-input-wrapper';
|
|
const input = document.createElement('input');
|
|
input.type = 'text';
|
|
input.className = 'code-input empty';
|
|
input.placeholder = 'Search or enter item code...';
|
|
input.maxLength = 50;
|
|
input.autocomplete = 'off';
|
|
input.dataset.key = key;
|
|
input.dataset.extraction = p.extraction_id;
|
|
input.dataset.index = p.index;
|
|
input.value = (drafts[key] !== undefined) ? drafts[key] : (p.item_code || '');
|
|
const dropdown = document.createElement('div');
|
|
dropdown.className = 'autocomplete-list';
|
|
wrapper.appendChild(input);
|
|
wrapper.appendChild(dropdown);
|
|
attachAutocomplete(input, dropdown);
|
|
codeTd.appendChild(wrapper);
|
|
tr.appendChild(codeTd);
|
|
|
|
const actionTd = document.createElement('td');
|
|
const btn = document.createElement('button');
|
|
btn.type = 'button';
|
|
btn.className = 'approve-btn';
|
|
btn.textContent = 'Approve';
|
|
btn.addEventListener('click', () => approveRows([input], btn));
|
|
input.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Enter') { e.preventDefault(); btn.click(); }
|
|
});
|
|
actionTd.appendChild(btn);
|
|
tr.appendChild(actionTd);
|
|
|
|
tbody.appendChild(tr);
|
|
});
|
|
}
|
|
|
|
function approveAllPending() {
|
|
const inputs = [...document.querySelectorAll('#pendingTableBody .code-input')]
|
|
.filter(i => i.value.trim());
|
|
if (!inputs.length) {
|
|
showPendingMessage('Please enter at least one item code before approving.', 'error');
|
|
return;
|
|
}
|
|
approveRows(inputs, document.getElementById('approveAllBtn'));
|
|
}
|
|
|
|
async function approveRows(inputs, button) {
|
|
const byExtraction = {};
|
|
for (const input of inputs) {
|
|
const code = input.value.trim();
|
|
if (!code) {
|
|
input.focus();
|
|
showPendingMessage('Enter an item code before approving.', 'error');
|
|
return;
|
|
}
|
|
(byExtraction[input.dataset.extraction] ||= []).push({
|
|
index: parseInt(input.dataset.index, 10),
|
|
item_code: code
|
|
});
|
|
}
|
|
|
|
const originalText = button.textContent;
|
|
button.disabled = true;
|
|
button.textContent = 'Saving...';
|
|
|
|
let approved = 0, newCodes = 0, csvWarning = null, failed = null;
|
|
|
|
for (const [extractionId, item_codes] of Object.entries(byExtraction)) {
|
|
try {
|
|
const response = await fetch(`/api/extraction/${extractionId}/item-codes`, {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ item_codes })
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (response.ok && result.success) {
|
|
approved += item_codes.length;
|
|
newCodes += result.new_codes_added || 0;
|
|
if (result.csv_warning) csvWarning = result.csv_warning;
|
|
|
|
if (String(lastExtractionId) === String(extractionId)) {
|
|
lastExtractedData = result.data;
|
|
refreshAll();
|
|
}
|
|
} else {
|
|
failed = result.error || 'Failed to save item code';
|
|
}
|
|
} catch (error) {
|
|
failed = 'Network error. Please try again.';
|
|
}
|
|
}
|
|
|
|
await loadPending();
|
|
button.disabled = false;
|
|
button.textContent = originalText;
|
|
|
|
if (failed) {
|
|
showPendingMessage(approved ? `${approved} approved, but: ${failed}` : failed, 'error');
|
|
return;
|
|
}
|
|
let msg = `${approved} item${approved === 1 ? '' : 's'} approved.`;
|
|
if (newCodes) {
|
|
msg += csvWarning
|
|
? ` Added to catalog, but ${csvWarning}`
|
|
: ` ${newCodes} new code${newCodes === 1 ? '' : 's'} saved to catalog.`;
|
|
}
|
|
showPendingMessage(msg, csvWarning ? 'error' : 'success');
|
|
}
|
|
|
|
// ---------- JSON view ----------
|
|
|
|
function setView(view) {
|
|
currentView = view;
|
|
const isJson = view === 'json';
|
|
document.getElementById('tableView').classList.toggle('hidden', isJson);
|
|
document.getElementById('jsonView').classList.toggle('hidden', !isJson);
|
|
document.getElementById('jsonSourceToggle').classList.toggle('hidden', !isJson);
|
|
document.getElementById('viewTableBtn').classList.toggle('active', !isJson);
|
|
document.getElementById('viewJsonBtn').classList.toggle('active', isJson);
|
|
}
|
|
|
|
function setJsonSource(source) {
|
|
jsonSource = source;
|
|
document.getElementById('srcApiBtn').classList.toggle('active', source === 'api');
|
|
document.getElementById('srcEnrichedBtn').classList.toggle('active', source === 'enriched');
|
|
renderJson();
|
|
}
|
|
|
|
function getJsonPayload() {
|
|
if (!lastExtractedData) return null;
|
|
|
|
const { _raw_api_response, ...enriched } = lastExtractedData;
|
|
|
|
if (jsonSource === 'enriched') {
|
|
return enriched;
|
|
}
|
|
|
|
if (_raw_api_response) return _raw_api_response;
|
|
|
|
const { _metadata, ...rest } = enriched;
|
|
if (Array.isArray(rest.items)) {
|
|
rest.items = rest.items.map(item => {
|
|
if (!item || typeof item !== 'object') return item;
|
|
const { item_code_source, ...clean } = item;
|
|
if (item_code_source === 'drug_list_match' || item_code_source === 'manual') delete clean.item_code;
|
|
return clean;
|
|
});
|
|
}
|
|
return rest;
|
|
}
|
|
|
|
function highlightJson(obj) {
|
|
const json = JSON.stringify(obj, null, 2)
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>');
|
|
|
|
return json.replace(
|
|
/("(?:\\u[a-fA-F0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(?:true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g,
|
|
(match) => {
|
|
let cls = 'json-number';
|
|
if (match.startsWith('"')) {
|
|
cls = match.endsWith(':') ? 'json-key' : 'json-string';
|
|
} else if (match === 'true' || match === 'false') {
|
|
cls = 'json-boolean';
|
|
} else if (match === 'null') {
|
|
cls = 'json-null';
|
|
}
|
|
return `<span class="${cls}">${match}</span>`;
|
|
}
|
|
);
|
|
}
|
|
|
|
function renderJson() {
|
|
const payload = getJsonPayload();
|
|
document.getElementById('jsonViewer').innerHTML =
|
|
payload ? highlightJson(payload) : '';
|
|
}
|
|
|
|
function copyJSON() {
|
|
const json = JSON.stringify(getJsonPayload(), null, 2);
|
|
navigator.clipboard.writeText(json).then(() => {
|
|
showMessage('JSON data copied to clipboard.', 'success');
|
|
}).catch(() => {
|
|
showMessage('Failed to copy JSON data.', 'error');
|
|
});
|
|
}
|
|
|
|
function downloadJSON() {
|
|
const json = JSON.stringify(getJsonPayload(), null, 2);
|
|
const blob = new Blob([json], { type: 'application/json' });
|
|
const url = window.URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
const id = lastExtractedData._metadata?.upload_id || 'export';
|
|
a.download = `invoice_${id}_${jsonSource === 'api' ? 'api' : 'enriched'}.json`;
|
|
a.click();
|
|
window.URL.revokeObjectURL(url);
|
|
}
|
|
|
|
function resetForm() {
|
|
document.getElementById('fileInput').value = '';
|
|
lastExtractedData = null;
|
|
lastExtractionId = null;
|
|
document.getElementById('results').classList.remove('show');
|
|
document.getElementById('uploadArea').classList.remove('hidden');
|
|
updateStats(null);
|
|
hideMessage();
|
|
}
|
|
|
|
function switchTab(tabName) {
|
|
document.querySelectorAll('.tab-content').forEach(tab => {
|
|
tab.classList.remove('active');
|
|
});
|
|
document.querySelectorAll('.tab').forEach(tab => {
|
|
tab.classList.toggle('active', tab.dataset.tab === tabName);
|
|
});
|
|
|
|
document.getElementById(tabName).classList.add('active');
|
|
|
|
if (tabName === 'history') {
|
|
loadHistory();
|
|
} else if (tabName === 'profile') {
|
|
loadProfile();
|
|
} else if (tabName === 'pending') {
|
|
loadPending();
|
|
}
|
|
}
|
|
|
|
async function loadHistory() {
|
|
try {
|
|
const response = await fetch('/api/history');
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
const tbody = document.getElementById('historyTableBody');
|
|
if (result.data.length === 0) {
|
|
tbody.innerHTML = '<tr><td colspan="4" style="text-align: center; padding: 36px; color: var(--text-muted);">No extractions found</td></tr>';
|
|
} else {
|
|
tbody.innerHTML = result.data.map(item => `
|
|
<tr onclick="loadExtraction(${item.id})">
|
|
<td>${item.invoice_id || '-'}</td>
|
|
<td>${item.filename}</td>
|
|
<td>${new Date(item.created_at).toLocaleString()}</td>
|
|
<td><span class="tag api">View</span></td>
|
|
</tr>
|
|
`).join('');
|
|
}
|
|
updateTotalInvoicesBadge(result.total);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error loading history:', error);
|
|
}
|
|
}
|
|
|
|
async function loadInvoiceTotal() {
|
|
try {
|
|
const response = await fetch('/api/history');
|
|
const result = await response.json();
|
|
if (result.success) updateTotalInvoicesBadge(result.total);
|
|
} catch (error) { /* silent */ }
|
|
}
|
|
|
|
function updateTotalInvoicesBadge(total) {
|
|
const box = document.getElementById('totalInvoices');
|
|
if (box && typeof total === 'number') box.textContent = total;
|
|
}
|
|
|
|
async function loadExtraction(id) {
|
|
try {
|
|
const response = await fetch(`/api/extraction/${id}`);
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
lastExtractedData = result.data;
|
|
lastExtractionId = id;
|
|
displayResults(result.data);
|
|
switchTab('extract');
|
|
}
|
|
} catch (error) {
|
|
showMessage('Failed to load extraction details.', 'error');
|
|
}
|
|
}
|
|
|
|
async function loadProfile() {
|
|
try {
|
|
const response = await fetch('/api/profile');
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
const data = result.data;
|
|
document.getElementById('profileInfo').innerHTML = `
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Username</span>
|
|
<span class="metadata-value">${data.username}</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Email</span>
|
|
<span class="metadata-value">${data.email}</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Account Created</span>
|
|
<span class="metadata-value">${new Date(data.created_at).toLocaleDateString()}</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Last Sign In</span>
|
|
<span class="metadata-value">${data.last_login ? new Date(data.last_login).toLocaleString() : 'Current session'}</span>
|
|
</div>
|
|
`;
|
|
|
|
const initials = data.username.substring(0, 1).toUpperCase();
|
|
document.getElementById('userAvatar').textContent = initials;
|
|
}
|
|
} catch (error) {
|
|
console.error('Error loading profile:', error);
|
|
}
|
|
}
|
|
|
|
// ---------- Manual Item Codes tab ----------
|
|
|
|
let manualFile = null;
|
|
let manualData = null;
|
|
let manualExtractionId = null;
|
|
|
|
const manualUploadArea = document.getElementById('manualUploadArea');
|
|
|
|
manualUploadArea.addEventListener('dragover', (e) => {
|
|
e.preventDefault();
|
|
manualUploadArea.classList.add('dragover');
|
|
});
|
|
|
|
manualUploadArea.addEventListener('dragleave', () => {
|
|
manualUploadArea.classList.remove('dragover');
|
|
});
|
|
|
|
manualUploadArea.addEventListener('drop', (e) => {
|
|
e.preventDefault();
|
|
manualUploadArea.classList.remove('dragover');
|
|
if (e.dataTransfer.files.length > 0) {
|
|
handleManualFile(e.dataTransfer.files[0]);
|
|
}
|
|
});
|
|
|
|
function handleManualFileSelect(event) {
|
|
if (event.target.files.length > 0) {
|
|
handleManualFile(event.target.files[0]);
|
|
}
|
|
}
|
|
|
|
function handleManualFile(file) {
|
|
const validTypes = ['application/pdf', 'image/png', 'image/jpeg'];
|
|
|
|
if (!validTypes.includes(file.type)) {
|
|
showManualMessage('Invalid file type. Please upload a PDF, PNG, or JPG file.', 'error');
|
|
return;
|
|
}
|
|
if (file.size > 100 * 1024 * 1024) {
|
|
showManualMessage('File size exceeds the 100 MB limit.', 'error');
|
|
return;
|
|
}
|
|
|
|
manualFile = file;
|
|
hideManualMessage();
|
|
document.getElementById('manualFileName').textContent = file.name;
|
|
document.getElementById('manualFileChip').classList.remove('hidden');
|
|
document.getElementById('manualExtractBtn').disabled = false;
|
|
}
|
|
|
|
function clearManualFile() {
|
|
manualFile = null;
|
|
document.getElementById('manualFileInput').value = '';
|
|
document.getElementById('manualFileChip').classList.add('hidden');
|
|
document.getElementById('manualExtractBtn').disabled = true;
|
|
}
|
|
|
|
async function extractForManual() {
|
|
if (!manualFile) return;
|
|
|
|
const formData = new FormData();
|
|
formData.append('file', manualFile);
|
|
formData.append('enrich', 'false');
|
|
|
|
document.getElementById('manualLoading').classList.add('show');
|
|
document.getElementById('manualResults').classList.remove('show');
|
|
document.getElementById('manualExtractBtn').disabled = true;
|
|
hideManualMessage();
|
|
|
|
try {
|
|
const response = await fetch('/api/upload', { method: 'POST', body: formData });
|
|
const result = await response.json();
|
|
|
|
if (response.ok && result.success) {
|
|
manualData = result.data;
|
|
manualExtractionId = result.extraction_id || null;
|
|
renderManualResults();
|
|
document.getElementById('manualResults').classList.add('show');
|
|
loadInvoiceTotal();
|
|
|
|
const items = Array.isArray(manualData.items) ? manualData.items : [];
|
|
if (!manualExtractionId) {
|
|
showManualMessage('Invoice extracted, but could not be logged to history. Manual codes cannot be persisted.', 'warning');
|
|
} else if (items.length === 0) {
|
|
showManualMessage('Invoice extracted, but no line items were discovered.', 'warning');
|
|
} else {
|
|
showManualMessage('Invoice extracted. Enter item codes below and save when complete.', 'success');
|
|
}
|
|
} else {
|
|
showManualMessage(result.error || 'Extraction failed.', 'error');
|
|
}
|
|
} catch (error) {
|
|
showManualMessage('Connection error. Please try again.', 'error');
|
|
} finally {
|
|
document.getElementById('manualLoading').classList.remove('show');
|
|
document.getElementById('manualExtractBtn').disabled = !manualFile;
|
|
}
|
|
}
|
|
|
|
function makeMetaItem(label, value) {
|
|
const wrap = document.createElement('div');
|
|
wrap.className = 'metadata-item';
|
|
const l = document.createElement('span');
|
|
l.className = 'metadata-label';
|
|
l.textContent = label;
|
|
const v = document.createElement('span');
|
|
v.className = 'metadata-value';
|
|
v.textContent = (value === undefined || value === null || value === '') ? '-' : value;
|
|
wrap.append(l, v);
|
|
return wrap;
|
|
}
|
|
|
|
function makeSourceTag(source, hasCode) {
|
|
const tag = document.createElement('span');
|
|
tag.className = 'tag';
|
|
if (source === 'api_extracted') {
|
|
tag.classList.add('api'); tag.textContent = 'API';
|
|
} else if (source === 'drug_list_match') {
|
|
tag.classList.add('matched'); tag.textContent = 'Matched';
|
|
} else if (source === 'manual') {
|
|
tag.classList.add('manual'); tag.textContent = 'Manual';
|
|
} else {
|
|
tag.classList.add('missing'); tag.textContent = 'Not Found';
|
|
}
|
|
return tag;
|
|
}
|
|
|
|
function renderManualResults() {
|
|
const items = Array.isArray(manualData.items) ? manualData.items : [];
|
|
|
|
const meta = document.getElementById('manualMetadata');
|
|
meta.replaceChildren(
|
|
makeMetaItem('Invoice ID', manualData.invoice_id),
|
|
makeMetaItem('Seller', manualData.seller_name),
|
|
makeMetaItem('Items', items.length)
|
|
);
|
|
|
|
const tbody = document.getElementById('manualTableBody');
|
|
tbody.replaceChildren();
|
|
|
|
items.forEach((rawItem, i) => {
|
|
const item = (rawItem && typeof rawItem === 'object') ? rawItem : {};
|
|
const code = (item.item_code === undefined || item.item_code === null) ? '' : String(item.item_code).trim();
|
|
|
|
const tr = document.createElement('tr');
|
|
tr.dataset.source = item.item_code_source || 'not_found';
|
|
|
|
[i + 1, item.description, item.quantity, item.unit_price].forEach(value => {
|
|
const td = document.createElement('td');
|
|
td.textContent = (value === undefined || value === null || value === '') ? '-' : value;
|
|
tr.appendChild(td);
|
|
});
|
|
|
|
const codeTd = document.createElement('td');
|
|
const wrapper = document.createElement('div');
|
|
wrapper.className = 'code-input-wrapper';
|
|
|
|
const input = document.createElement('input');
|
|
input.type = 'text';
|
|
input.className = 'code-input' + (code ? '' : ' empty');
|
|
input.value = code;
|
|
input.placeholder = 'Enter item code or search...';
|
|
input.maxLength = 50;
|
|
input.autocomplete = 'off';
|
|
input.dataset.index = i;
|
|
input.dataset.original = code;
|
|
input.addEventListener('input', onManualCodeInput);
|
|
input.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Enter') {
|
|
const list = wrapper.querySelector('.autocomplete-list');
|
|
const activeItem = list && list.querySelector('.autocomplete-item.active');
|
|
if (activeItem) {
|
|
e.preventDefault();
|
|
activeItem.click();
|
|
return;
|
|
}
|
|
e.preventDefault();
|
|
const inputs = [...document.querySelectorAll('#manualTableBody .code-input')];
|
|
const next = inputs[inputs.indexOf(input) + 1];
|
|
if (next) next.focus();
|
|
}
|
|
});
|
|
|
|
const dropdown = document.createElement('div');
|
|
dropdown.className = 'autocomplete-list';
|
|
wrapper.appendChild(input);
|
|
wrapper.appendChild(dropdown);
|
|
attachAutocomplete(input, dropdown);
|
|
|
|
codeTd.appendChild(wrapper);
|
|
tr.appendChild(codeTd);
|
|
|
|
const statusTd = document.createElement('td');
|
|
statusTd.className = 'status-cell';
|
|
statusTd.appendChild(makeSourceTag(tr.dataset.source, !!code));
|
|
tr.appendChild(statusTd);
|
|
|
|
tbody.appendChild(tr);
|
|
});
|
|
|
|
updateManualSummary();
|
|
refreshManualJson();
|
|
}
|
|
|
|
function attachAutocomplete(input, dropdown) {
|
|
let debounceTimer = null;
|
|
let activeIndex = -1;
|
|
let currentItems = [];
|
|
|
|
function closeDropdown() {
|
|
dropdown.classList.remove('show');
|
|
dropdown.replaceChildren();
|
|
activeIndex = -1;
|
|
currentItems = [];
|
|
}
|
|
|
|
function renderSuggestions(items) {
|
|
currentItems = items;
|
|
activeIndex = -1;
|
|
dropdown.replaceChildren();
|
|
|
|
if (!items.length) {
|
|
closeDropdown();
|
|
return;
|
|
}
|
|
|
|
items.forEach((item, idx) => {
|
|
const row = document.createElement('div');
|
|
row.className = 'autocomplete-item';
|
|
|
|
const codeSpan = document.createElement('span');
|
|
codeSpan.className = 'ac-code';
|
|
codeSpan.textContent = item.item_code;
|
|
|
|
const nameSpan = document.createElement('span');
|
|
nameSpan.className = 'ac-name';
|
|
nameSpan.textContent = item.name;
|
|
|
|
const catSpan = document.createElement('span');
|
|
catSpan.className = 'ac-category';
|
|
catSpan.textContent = item.category || '';
|
|
|
|
row.appendChild(codeSpan);
|
|
row.appendChild(nameSpan);
|
|
row.appendChild(catSpan);
|
|
|
|
row.addEventListener('mousedown', (e) => {
|
|
e.preventDefault();
|
|
input.value = item.item_code;
|
|
input.dispatchEvent(new Event('input'));
|
|
closeDropdown();
|
|
});
|
|
|
|
row.dataset.idx = idx;
|
|
dropdown.appendChild(row);
|
|
});
|
|
|
|
dropdown.classList.add('show');
|
|
}
|
|
|
|
function updateActiveHighlight() {
|
|
[...dropdown.children].forEach((el, idx) => {
|
|
el.classList.toggle('active', idx === activeIndex);
|
|
});
|
|
}
|
|
|
|
input.addEventListener('input', () => {
|
|
clearTimeout(debounceTimer);
|
|
const q = input.value.trim();
|
|
if (q.length < 2) {
|
|
closeDropdown();
|
|
return;
|
|
}
|
|
debounceTimer = setTimeout(async () => {
|
|
try {
|
|
const res = await fetch(`/api/catalog/autocomplete?q=${encodeURIComponent(q)}`);
|
|
const data = await res.json();
|
|
if (data.success) renderSuggestions(data.data);
|
|
} catch (e) { /* silent */ }
|
|
}, 200);
|
|
});
|
|
|
|
input.addEventListener('keydown', (e) => {
|
|
if (!dropdown.classList.contains('show')) return;
|
|
if (e.key === 'ArrowDown') {
|
|
e.preventDefault();
|
|
activeIndex = Math.min(activeIndex + 1, currentItems.length - 1);
|
|
updateActiveHighlight();
|
|
} else if (e.key === 'ArrowUp') {
|
|
e.preventDefault();
|
|
activeIndex = Math.max(activeIndex - 1, 0);
|
|
updateActiveHighlight();
|
|
} else if (e.key === 'Escape') {
|
|
closeDropdown();
|
|
}
|
|
});
|
|
|
|
input.addEventListener('blur', () => {
|
|
setTimeout(closeDropdown, 150);
|
|
});
|
|
}
|
|
|
|
function onManualCodeInput(e) {
|
|
const input = e.target;
|
|
const value = input.value.trim();
|
|
const changed = value !== input.dataset.original;
|
|
const tr = input.closest('tr');
|
|
const statusCell = tr.querySelector('.status-cell');
|
|
|
|
input.classList.toggle('empty', value === '');
|
|
|
|
if (changed) {
|
|
const tag = document.createElement('span');
|
|
tag.className = 'tag edited';
|
|
tag.textContent = 'Edited';
|
|
statusCell.replaceChildren(tag);
|
|
} else {
|
|
statusCell.replaceChildren(makeSourceTag(tr.dataset.source, value !== ''));
|
|
}
|
|
|
|
updateManualSummary();
|
|
refreshManualJson();
|
|
}
|
|
|
|
function updateManualSummary() {
|
|
const inputs = [...document.querySelectorAll('#manualTableBody .code-input')];
|
|
const total = inputs.length;
|
|
const withCode = inputs.filter(i => i.value.trim() !== '').length;
|
|
const unsaved = inputs.filter(i => i.value.trim() !== i.dataset.original).length;
|
|
|
|
const badge = document.getElementById('manualBadge');
|
|
if (total > 0 && withCode === total) {
|
|
badge.innerHTML = '<span class="badge success">All items coded</span>';
|
|
} else {
|
|
badge.innerHTML = `<span class="badge warning">${total - withCode} of ${total} items missing code</span>`;
|
|
}
|
|
|
|
const saveBtn = document.getElementById('manualSaveBtn');
|
|
saveBtn.disabled = unsaved === 0 || !manualExtractionId;
|
|
saveBtn.textContent = unsaved > 0 ? `Save Item Codes (${unsaved})` : 'Save Item Codes';
|
|
}
|
|
|
|
async function saveManualCodes() {
|
|
if (!manualExtractionId) {
|
|
showManualMessage('Extraction not stored in database. Item codes cannot be saved.', 'error');
|
|
return;
|
|
}
|
|
|
|
const item_codes = [...document.querySelectorAll('#manualTableBody .code-input')]
|
|
.filter(i => i.value.trim() !== i.dataset.original)
|
|
.map(i => ({ index: Number(i.dataset.index), item_code: i.value.trim() }));
|
|
|
|
if (item_codes.length === 0) return;
|
|
|
|
const saveBtn = document.getElementById('manualSaveBtn');
|
|
saveBtn.disabled = true;
|
|
saveBtn.textContent = 'Saving...';
|
|
|
|
try {
|
|
const response = await fetch(`/api/extraction/${manualExtractionId}/item-codes`, {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ item_codes })
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (response.ok && result.success) {
|
|
manualData = result.data;
|
|
renderManualResults();
|
|
let msg = `Successfully saved ${result.updated} item code(s).`;
|
|
if (result.new_codes_added) {
|
|
msg += ` Added ${result.new_codes_added} new code(s) to the catalog for future matching.`;
|
|
}
|
|
showManualMessage(msg, 'success');
|
|
} else {
|
|
showManualMessage(result.error || 'Failed to save item codes.', 'error');
|
|
}
|
|
} catch (error) {
|
|
showManualMessage('Connection error. Please try again.', 'error');
|
|
} finally {
|
|
updateManualSummary();
|
|
}
|
|
}
|
|
|
|
function getManualPayload() {
|
|
if (!manualData) return null;
|
|
const { _raw_api_response, ...out } = manualData;
|
|
|
|
out.items = (Array.isArray(out.items) ? out.items : []).map((item, i) => {
|
|
const input = document.querySelector(`#manualTableBody .code-input[data-index="${i}"]`);
|
|
if (!input || !item || typeof item !== 'object') return item;
|
|
const value = input.value.trim();
|
|
if (value === input.dataset.original) return item;
|
|
return { ...item, item_code: value, item_code_source: value ? 'manual' : 'not_found' };
|
|
});
|
|
return out;
|
|
}
|
|
|
|
function toggleManualJson() {
|
|
const viewer = document.getElementById('manualJsonViewer');
|
|
const nowHidden = viewer.classList.toggle('hidden');
|
|
document.getElementById('manualJsonBtn').textContent = nowHidden ? 'Show JSON' : 'Hide JSON';
|
|
refreshManualJson();
|
|
}
|
|
|
|
function refreshManualJson() {
|
|
const viewer = document.getElementById('manualJsonViewer');
|
|
if (viewer.classList.contains('hidden')) return;
|
|
const payload = getManualPayload();
|
|
viewer.innerHTML = payload ? highlightJson(payload) : '';
|
|
}
|
|
|
|
function downloadManualJSON() {
|
|
const payload = getManualPayload();
|
|
if (!payload) return;
|
|
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });
|
|
const url = window.URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = `invoice_${payload._metadata?.upload_id || 'export'}_manual.json`;
|
|
a.click();
|
|
window.URL.revokeObjectURL(url);
|
|
}
|
|
|
|
function resetManual() {
|
|
if (document.querySelectorAll('#manualTableBody .code-input').length &&
|
|
!document.getElementById('manualSaveBtn').disabled &&
|
|
!confirm('There are unsaved item codes. Discard modifications?')) {
|
|
return;
|
|
}
|
|
clearManualFile();
|
|
manualData = null;
|
|
manualExtractionId = null;
|
|
document.getElementById('manualResults').classList.remove('show');
|
|
document.getElementById('manualJsonViewer').classList.add('hidden');
|
|
document.getElementById('manualJsonBtn').textContent = 'Show JSON';
|
|
hideManualMessage();
|
|
}
|
|
|
|
function showManualMessage(msg, type) {
|
|
const msgDiv = document.getElementById('manualMessage');
|
|
msgDiv.textContent = msg;
|
|
msgDiv.className = `message show ${type}`;
|
|
}
|
|
|
|
function hideManualMessage() {
|
|
document.getElementById('manualMessage').classList.remove('show');
|
|
}
|
|
|
|
function showMessage(msg, type) {
|
|
const msgDiv = document.getElementById('message');
|
|
msgDiv.textContent = msg;
|
|
msgDiv.className = `message show ${type}`;
|
|
}
|
|
|
|
function hideMessage() {
|
|
document.getElementById('message').classList.remove('show');
|
|
}
|
|
|
|
// Initialize application data
|
|
loadProfile();
|
|
loadInvoiceTotal();
|
|
updateStats(null);
|
|
loadPending();
|
|
</script>
|
|
</body>
|
|
</html> |