2535 lines
106 KiB
HTML
2535 lines
106 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>DMH Hospital Pharmacy — PO Approval & Item Code Management</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%;
|
|
}
|
|
}
|
|
|
|
/* ===== PO Approval Modal ===== */
|
|
.modal-overlay {
|
|
position: fixed; inset: 0; background: rgba(0,0,0,0.45);
|
|
z-index: 200; display: flex; align-items: center; justify-content: center;
|
|
padding: 24px;
|
|
}
|
|
.modal-overlay.hidden { display: none; }
|
|
.modal-content {
|
|
background: var(--surface); border-radius: var(--radius-lg);
|
|
border: 1px solid var(--border); box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
|
|
width: 100%; max-width: 700px; max-height: 90vh; overflow-y: auto; padding: 28px;
|
|
position: relative;
|
|
}
|
|
.modal-close {
|
|
position: absolute; top: 16px; right: 16px; border: none; background: transparent;
|
|
font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1;
|
|
}
|
|
.modal-close:hover { color: var(--text-primary); }
|
|
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 20px; color: var(--text-primary); }
|
|
.po-input-group { margin: 20px 0; }
|
|
.po-input-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
|
|
.po-input-field {
|
|
width: 100%; padding: 10px 14px; border: 1px solid var(--border);
|
|
border-radius: var(--radius); font-size: 14px; font-family: inherit;
|
|
transition: border-color 0.15s, box-shadow 0.15s;
|
|
}
|
|
.po-input-field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(2,132,199,0.18); }
|
|
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
|
|
.btn-danger { background-color: var(--danger); color: #fff; }
|
|
.btn-danger:hover { background-color: #b91c1c; }
|
|
|
|
|
|
/* ── Modern Sidebar & Layout Additions ───────────────────── */
|
|
html, body {
|
|
height: 100%;
|
|
margin: 0;
|
|
padding: 0;
|
|
overflow: hidden;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
background-color: #f8fafc;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.app-layout {
|
|
display: flex;
|
|
height: 100vh;
|
|
width: 100vw;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* ── Left Sidebar ────────────────────────────────────────── */
|
|
.app-sidebar {
|
|
width: 270px;
|
|
min-width: 270px;
|
|
background: #ffffff;
|
|
border-right: 1px solid var(--border);
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
z-index: 100;
|
|
box-shadow: 1px 0 3px rgba(0,0,0,0.02);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.sidebar-brand {
|
|
padding: 20px 20px 18px;
|
|
border-bottom: 1px solid var(--border);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
background: #ffffff;
|
|
}
|
|
|
|
.brand-logo-box {
|
|
width: 44px;
|
|
height: 44px;
|
|
border-radius: 10px;
|
|
background: #ffffff;
|
|
border: 1px solid #e2e8f0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 4px;
|
|
flex-shrink: 0;
|
|
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
|
|
}
|
|
|
|
.brand-logo-img {
|
|
max-height: 36px;
|
|
max-width: 36px;
|
|
width: auto;
|
|
height: auto;
|
|
object-fit: contain;
|
|
display: block;
|
|
}
|
|
|
|
.brand-text h2 {
|
|
font-size: 15px;
|
|
font-weight: 700;
|
|
color: #0f172a;
|
|
margin: 0;
|
|
line-height: 1.25;
|
|
}
|
|
|
|
.brand-text span {
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
color: var(--primary);
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.6px;
|
|
}
|
|
|
|
.sidebar-nav {
|
|
flex: 1;
|
|
padding: 16px 12px;
|
|
overflow-y: auto;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 5px;
|
|
}
|
|
|
|
.nav-section-title {
|
|
font-size: 10.5px;
|
|
font-weight: 700;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.7px;
|
|
color: var(--text-muted);
|
|
padding: 12px 12px 4px;
|
|
}
|
|
|
|
.sidebar-nav-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
padding: 11px 14px;
|
|
border-radius: var(--radius);
|
|
color: var(--text-secondary);
|
|
font-size: 13.5px;
|
|
font-weight: 500;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
transition: all 0.15s ease;
|
|
position: relative;
|
|
}
|
|
|
|
.sidebar-nav-item:hover {
|
|
background: #f1f5f9;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.sidebar-nav-item.active {
|
|
background: #e0f2fe;
|
|
color: #0369a1;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.sidebar-nav-item .nav-icon {
|
|
width: 20px;
|
|
height: 20px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex-shrink: 0;
|
|
color: var(--text-muted);
|
|
transition: color 0.15s ease;
|
|
}
|
|
|
|
.sidebar-nav-item:hover .nav-icon {
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.sidebar-nav-item.active .nav-icon {
|
|
color: #0284c7;
|
|
}
|
|
|
|
.sidebar-nav-item .tab-badge {
|
|
margin-left: auto;
|
|
background: #ef4444;
|
|
color: #ffffff;
|
|
font-size: 11px;
|
|
font-weight: 700;
|
|
padding: 2px 8px;
|
|
border-radius: 12px;
|
|
display: none;
|
|
}
|
|
|
|
.sidebar-footer {
|
|
padding: 14px 16px;
|
|
border-top: 1px solid var(--border);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
background: #f8fafc;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.user-chip {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.user-avatar-small {
|
|
width: 32px;
|
|
height: 32px;
|
|
border-radius: 50%;
|
|
background: #e0f2fe;
|
|
color: #0284c7;
|
|
font-weight: 700;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 12px;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.user-meta-box .user-name-text {
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
line-height: 1.2;
|
|
display: block;
|
|
}
|
|
|
|
.user-meta-box .user-role-text {
|
|
font-size: 11px;
|
|
color: var(--text-muted);
|
|
display: block;
|
|
}
|
|
|
|
.logout-icon-btn {
|
|
padding: 6px 10px;
|
|
border-radius: var(--radius-sm);
|
|
color: var(--text-muted);
|
|
text-decoration: none;
|
|
font-size: 15px;
|
|
transition: all 0.15s ease;
|
|
}
|
|
|
|
.logout-icon-btn:hover {
|
|
color: #dc2626;
|
|
background: #fee2e2;
|
|
}
|
|
|
|
/* ── Main Content Layout ─────────────────────────────────── */
|
|
.app-main {
|
|
flex: 1;
|
|
min-width: 0;
|
|
height: 100vh;
|
|
overflow-y: auto;
|
|
display: flex;
|
|
flex-direction: column;
|
|
background: #f8fafc;
|
|
}
|
|
|
|
.main-topbar {
|
|
padding: 18px 32px;
|
|
background: #ffffff;
|
|
border-bottom: 1px solid var(--border);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.main-title-box h1 {
|
|
font-size: 20px;
|
|
font-weight: 700;
|
|
color: #0f172a;
|
|
margin: 0;
|
|
line-height: 1.2;
|
|
}
|
|
|
|
.main-title-box p {
|
|
font-size: 13px;
|
|
color: var(--text-muted);
|
|
margin: 4px 0 0;
|
|
}
|
|
|
|
.topbar-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
.main-container {
|
|
padding: 24px 32px 48px;
|
|
flex: 1;
|
|
}
|
|
|
|
/* ── Always-Visible Top Stats Grid ──────────────────────── */
|
|
.stats-bar {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
|
gap: 16px;
|
|
margin-bottom: 24px;
|
|
}
|
|
|
|
.stat-card-box {
|
|
background: #ffffff;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-lg);
|
|
padding: 16px 18px;
|
|
box-shadow: var(--shadow-card);
|
|
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.stat-card-box:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.06);
|
|
}
|
|
|
|
.stat-card-top {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.stat-icon-circle {
|
|
width: 36px;
|
|
height: 36px;
|
|
border-radius: 8px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 18px;
|
|
}
|
|
|
|
.stat-card-pill {
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
padding: 3px 8px;
|
|
border-radius: 10px;
|
|
}
|
|
|
|
.stat-card-val {
|
|
font-size: 26px;
|
|
font-weight: 700;
|
|
color: #0f172a;
|
|
line-height: 1.2;
|
|
}
|
|
|
|
.stat-card-name {
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
color: var(--text-secondary);
|
|
margin-top: 3px;
|
|
}
|
|
|
|
.stat-card-desc {
|
|
font-size: 11.5px;
|
|
color: var(--text-muted);
|
|
margin-top: 2px;
|
|
}
|
|
|
|
.tab-content {
|
|
display: none;
|
|
}
|
|
.tab-content.active {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="app-layout">
|
|
<!-- ── Left Sidebar Navigation ── -->
|
|
<aside class="app-sidebar">
|
|
<div class="sidebar-brand">
|
|
<div class="brand-logo-box">
|
|
<img src="{{ url_for('static', filename='logo.png') }}" alt="DMH Logo" class="brand-logo-img">
|
|
</div>
|
|
<div class="brand-text">
|
|
<h2>DMH Hospital</h2>
|
|
<span>Pharmacy Portal</span>
|
|
</div>
|
|
</div>
|
|
|
|
<nav class="sidebar-nav">
|
|
<div class="nav-section-title">Approval Queues</div>
|
|
<a class="sidebar-nav-item active" data-tab="po-pending" onclick="switchTab('po-pending')">
|
|
<span class="nav-icon">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/>
|
|
<rect x="8" y="2" width="8" height="4" rx="1" ry="1"/>
|
|
<path d="m9 14 2 2 4-4"/>
|
|
</svg>
|
|
</span>
|
|
<span class="nav-label">PO Number Approval</span>
|
|
<span class="tab-badge" id="poPendingTabBadge">0</span>
|
|
</a>
|
|
<a class="sidebar-nav-item" data-tab="item-pending" onclick="switchTab('item-pending')">
|
|
<span class="nav-icon">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="m10.5 20.5 10-10a4.95 4.95 0 1 0-7-7l-10 10a4.95 4.95 0 1 0 7 7Z"/>
|
|
<path d="m8.5 8.5 7 7"/>
|
|
</svg>
|
|
</span>
|
|
<span class="nav-label">Item Code Approval</span>
|
|
<span class="tab-badge" id="itemPendingTabBadge">0</span>
|
|
</a>
|
|
|
|
<div class="nav-section-title">Reports & Master Data</div>
|
|
<a class="sidebar-nav-item" data-tab="po-history" onclick="switchTab('po-history')">
|
|
<span class="nav-icon">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<circle cx="12" cy="12" r="10"/>
|
|
<polyline points="12 6 12 12 16 14"/>
|
|
</svg>
|
|
</span>
|
|
<span class="nav-label">Approval History & Audit</span>
|
|
</a>
|
|
<a class="sidebar-nav-item" data-tab="manual" onclick="switchTab('manual')">
|
|
<span class="nav-icon">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<ellipse cx="12" cy="5" rx="9" ry="3"/>
|
|
<path d="M3 5V19A9 3 0 0 0 21 19V5"/>
|
|
<path d="M3 12A9 3 0 0 0 21 12"/>
|
|
</svg>
|
|
</span>
|
|
<span class="nav-label">Drug Master Catalog</span>
|
|
</a>
|
|
<a class="sidebar-nav-item" data-tab="profile" onclick="switchTab('profile')">
|
|
<span class="nav-icon">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<circle cx="12" cy="12" r="3"/>
|
|
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
|
|
</svg>
|
|
</span>
|
|
<span class="nav-label">Account & Settings</span>
|
|
</a>
|
|
|
|
{% if is_admin %}
|
|
<div class="nav-section-title">Administration</div>
|
|
<a href="/admin" class="sidebar-nav-item" style="color:var(--primary);font-weight:600;">
|
|
<span class="nav-icon" style="color:var(--primary);">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 7h10"/><path d="M7 12h10"/><path d="M7 17h10"/>
|
|
</svg>
|
|
</span>
|
|
<span class="nav-label">Admin Portal</span>
|
|
</a>
|
|
{% endif %}
|
|
</nav>
|
|
|
|
<div class="sidebar-footer">
|
|
<div class="user-chip">
|
|
<div class="user-avatar-small" id="sidebarUserAvatar">U</div>
|
|
<div class="user-meta-box">
|
|
<span class="user-name-text" id="sidebarUserName">{{ username }}</span>
|
|
<span class="user-role-text">{% if is_admin %}Administrator{% else %}Pharmacy Staff{% endif %}</span>
|
|
</div>
|
|
</div>
|
|
<a href="/logout" class="logout-icon-btn" title="Sign Out">
|
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>
|
|
<polyline points="16 17 21 12 16 7"/>
|
|
<line x1="21" y1="12" x2="9" y2="12"/>
|
|
</svg>
|
|
</a>
|
|
</div>
|
|
</aside>
|
|
|
|
<!-- ── Main App Content ── -->
|
|
<main class="app-main">
|
|
<!-- Top Bar -->
|
|
<header class="main-topbar">
|
|
<div class="main-title-box">
|
|
<h1 id="viewTitle">Manual PO Number Approval</h1>
|
|
<p id="viewSubtitle">Review and approve Purchase Order numbers for pending invoices</p>
|
|
</div>
|
|
<div class="topbar-actions">
|
|
{% if is_admin %}
|
|
<a href="/admin" class="btn btn-primary" style="padding:7px 16px;font-size:13px;display:flex;align-items:center;gap:7px;text-decoration:none;font-weight:600;background:linear-gradient(135deg, #0284c7 0%, #0369a1 100%);color:#ffffff;box-shadow:0 2px 5px rgba(2,132,199,0.25);">
|
|
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 7h10"/><path d="M7 12h10"/><path d="M7 17h10"/>
|
|
</svg>
|
|
Admin Panel
|
|
</a>
|
|
{% endif %}
|
|
<button class="btn btn-secondary" onclick="refreshDashboard()" style="padding:7px 14px;font-size:13px;display:flex;align-items:center;gap:6px;">
|
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M21 2v6h-6"/>
|
|
<path d="M3 12a9 9 0 0 1 15-6.7L21 8"/>
|
|
<path d="M3 22v-6h6"/>
|
|
<path d="M21 12a9 9 0 0 1-15 6.7L3 16"/>
|
|
</svg>
|
|
Refresh
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="main-container">
|
|
<!-- ── Always-Visible Top Stats Bar ── -->
|
|
<div class="stats-bar">
|
|
<!-- Stat 1: Pending PO Approval -->
|
|
<div class="stat-card-box" onclick="switchTab('po-pending')" title="Click to view PO Approval queue">
|
|
<div class="stat-card-top">
|
|
<span class="stat-icon-circle" style="background:#fee2e2;color:#dc2626;">
|
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/>
|
|
<rect x="8" y="2" width="8" height="4" rx="1" ry="1"/>
|
|
<path d="m9 14 2 2 4-4"/>
|
|
</svg>
|
|
</span>
|
|
<span class="stat-card-pill" style="background:#fee2e2;color:#991b1b;">Queue 1</span>
|
|
</div>
|
|
<div class="stat-card-val" id="statPendingPOCount">0</div>
|
|
<div class="stat-card-name">Pending PO Number Approval</div>
|
|
<div class="stat-card-desc">Invoices awaiting PO number verification</div>
|
|
</div>
|
|
|
|
<!-- Stat 2: Pending Item Code Approval -->
|
|
<div class="stat-card-box" onclick="switchTab('item-pending')" title="Click to view Item Code queue">
|
|
<div class="stat-card-top">
|
|
<span class="stat-icon-circle" style="background:#ffedd5;color:#ea580c;">
|
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="m10.5 20.5 10-10a4.95 4.95 0 1 0-7-7l-10 10a4.95 4.95 0 1 0 7 7Z"/>
|
|
<path d="m8.5 8.5 7 7"/>
|
|
</svg>
|
|
</span>
|
|
<span class="stat-card-pill" style="background:#ffedd5;color:#9a3412;">Queue 2</span>
|
|
</div>
|
|
<div class="stat-card-val" id="statPendingItemCount">0</div>
|
|
<div class="stat-card-name">Pending Item Code Approval</div>
|
|
<div class="stat-card-desc">Invoices awaiting standardized item codes</div>
|
|
</div>
|
|
|
|
<!-- Stat 3: Total Invoices Processed -->
|
|
<div class="stat-card-box" onclick="switchTab('po-history')" title="Click to view Completed invoices">
|
|
<div class="stat-card-top">
|
|
<span class="stat-icon-circle" style="background:#ecfdf5;color:#059669;">
|
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/>
|
|
<polyline points="22 4 12 14.01 9 11.01"/>
|
|
</svg>
|
|
</span>
|
|
<span class="stat-card-pill" style="background:#d1fae5;color:#065f46;">Stored in DMH</span>
|
|
</div>
|
|
<div class="stat-card-val" id="statTotalProcessed">0</div>
|
|
<div class="stat-card-name">Total Invoices Processed</div>
|
|
<div class="stat-card-desc">Completed & stored to DMH Database</div>
|
|
</div>
|
|
|
|
<!-- Stat 4: Drug Master Catalog -->
|
|
<div class="stat-card-box" onclick="switchTab('manual')" title="Click to view Drug Master Catalog">
|
|
<div class="stat-card-top">
|
|
<span class="stat-icon-circle" style="background:#e0f2fe;color:#0284c7;">
|
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<ellipse cx="12" cy="5" rx="9" ry="3"/>
|
|
<path d="M3 5V19A9 3 0 0 0 21 19V5"/>
|
|
<path d="M3 12A9 3 0 0 0 21 12"/>
|
|
</svg>
|
|
</span>
|
|
<span class="stat-card-pill" style="background:#e0f2fe;color:#0369a1;">Master DB</span>
|
|
</div>
|
|
<div class="stat-card-val" id="statCatalogCount">14,324</div>
|
|
<div class="stat-card-name">Drug Master Catalog</div>
|
|
<div class="stat-card-desc">Standardized item codes available</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<!-- TAB 1: MANUAL PO APPROVAL QUEUE -->
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<div id="po-pending" class="tab-content active">
|
|
<div class="message" id="poPendingMessage"></div>
|
|
<div class="results show">
|
|
<div class="result-header">
|
|
<h2>Invoices Awaiting PO Number Approval</h2>
|
|
<span class="tag pending" id="poPendingCountTag">0 Invoices Pending</span>
|
|
</div>
|
|
<p class="hint">These invoices have missing or unverified PO Numbers. Review the extracted line items and provide the validated Purchase Order Number.</p>
|
|
<div class="table-scroll">
|
|
<table class="items-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Invoice No.</th>
|
|
<th>Vendor Name</th>
|
|
<th>Invoice Date</th>
|
|
<th>Filename</th>
|
|
<th>Queue Reason</th>
|
|
<th>PO Status</th>
|
|
<th>Item Code Status</th>
|
|
<th>Approval Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="poPendingBody">
|
|
<tr><td colspan="9" style="text-align:center;padding:36px;color:var(--text-muted);">Loading pending PO invoices...</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<!-- TAB 2: MANUAL ITEM CODE APPROVAL QUEUE -->
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<div id="item-pending" class="tab-content">
|
|
<div class="message" id="itemPendingMessage"></div>
|
|
<div class="results show">
|
|
<div class="result-header">
|
|
<h2>Invoices Awaiting Item Code Approval</h2>
|
|
<span class="tag warning" id="itemPendingCountTag">0 Invoices Pending</span>
|
|
</div>
|
|
<p class="hint">These invoices have a verified PO Number, but item codes require manual mapping. Review the invoice details and assign standardized item codes from the Drug Master catalog.</p>
|
|
<div class="table-scroll">
|
|
<table class="items-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Invoice No.</th>
|
|
<th>Vendor Name</th>
|
|
<th>Invoice Date</th>
|
|
<th>Filename</th>
|
|
<th>Approved PO</th>
|
|
<th>Queue Reason</th>
|
|
<th>Item Code Status</th>
|
|
<th>Approval Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="itemPendingBody">
|
|
<tr><td colspan="9" style="text-align:center;padding:36px;color:var(--text-muted);">Loading pending item code invoices...</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<!-- TAB 3: APPROVAL HISTORY & AUDIT TRAIL -->
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<div id="po-history" class="tab-content">
|
|
<div class="results show">
|
|
<div class="result-header">
|
|
<h2>Approval History & Audit Trail</h2>
|
|
<span class="tag insheet">Permanent System Record</span>
|
|
</div>
|
|
<p class="hint">Permanent audit record of all PO Number approvals, Item Code approvals, and automated GRN records stored in the DMH Database.</p>
|
|
|
|
<!-- Filter Controls -->
|
|
<div style="display:flex;gap:12px;margin-bottom:16px;flex-wrap:wrap;">
|
|
<select id="poHistoryTypeFilter" class="code-input" style="width:auto;padding:7px 12px;" onchange="loadPOHistory()">
|
|
<option value="all">All Approval Types</option>
|
|
<option value="po_approval">PO Number Approvals</option>
|
|
<option value="item_code_approval">Item Code Approvals</option>
|
|
<option value="auto_grn">Automated Invoices (Direct & API)</option>
|
|
</select>
|
|
<select id="poHistoryConditionFilter" class="code-input" style="width:auto;padding:7px 12px;" onchange="loadPOHistory()">
|
|
<option value="all">All Processing Flows</option>
|
|
<option value="condition_1">Direct Store (PO & Code Present)</option>
|
|
<option value="condition_2">API Lookup (Item Code from PO)</option>
|
|
<option value="condition_3">Manual Item Code Mapped</option>
|
|
<option value="condition_4">Manual PO Approved</option>
|
|
<option value="condition_5">Manual PO & Item Code Resolved</option>
|
|
</select>
|
|
<select id="poHistoryStatusFilter" class="code-input" style="width:auto;padding:7px 12px;" onchange="loadPOHistory()">
|
|
<option value="all">All Statuses</option>
|
|
<option value="completed">Completed / Stored in DMH</option>
|
|
<option value="pending_po">Pending PO Approval</option>
|
|
<option value="pending_item_code">Pending Item Code</option>
|
|
<option value="rejected">Rejected</option>
|
|
</select>
|
|
<select id="poHistoryWebhookFilter" class="code-input" style="width:auto;padding:7px 12px;" onchange="loadPOHistory()">
|
|
<option value="all">All Webhook / GRN Statuses</option>
|
|
<option value="success">Success</option>
|
|
<option value="not_configured">Not Configured</option>
|
|
<option value="failed">Failed</option>
|
|
<option value="not_triggered">Not Triggered</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="table-scroll">
|
|
<table class="history-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Invoice No.</th>
|
|
<th>Vendor</th>
|
|
<th>Type</th>
|
|
<th>Processing Flow</th>
|
|
<th>PO Number</th>
|
|
<th>Status</th>
|
|
<th>Approved By</th>
|
|
<th>Date & Time</th>
|
|
<th>Webhook / GRN</th>
|
|
<th>Audit Details / Notes</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="poHistoryBody">
|
|
<tr><td colspan="10" style="text-align:center;padding:36px;color:var(--text-muted);">Loading audit history...</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<!-- TAB 4: DRUG MASTER CATALOG -->
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<div id="manual" class="tab-content">
|
|
<div class="message" id="manualMessage"></div>
|
|
<div class="results show">
|
|
<div class="result-header">
|
|
<h2>Drug Master Database Catalog</h2>
|
|
<div id="manualBadge"></div>
|
|
</div>
|
|
<p class="hint">Standardized item codes and medication database (14,324 items). Used by the automated matching engine and manual item code assignment.</p>
|
|
|
|
<div class="catalog-toolbar" style="display:flex;gap:12px;margin:16px 0;flex-wrap:wrap;">
|
|
<input type="text" id="catalogSearchInput" class="code-input" placeholder="Search drug name or code..." style="flex:1;min-width:240px;padding:8px 12px;" oninput="debounceCatalogSearch()">
|
|
<select id="catalogCategorySelect" class="code-input" style="width:auto;padding:8px 12px;" onchange="searchCatalog()">
|
|
<option value="">All Categories</option>
|
|
</select>
|
|
<button class="btn btn-primary" onclick="openAddModal()">+ Add New Drug</button>
|
|
</div>
|
|
|
|
<div class="table-scroll" style="max-height:550px;">
|
|
<table class="items-table" id="catalogTable">
|
|
<thead>
|
|
<tr>
|
|
<th>Item Code</th>
|
|
<th>Drug Name / Description</th>
|
|
<th>Category</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="catalogTableBody">
|
|
<tr><td colspan="4" style="text-align:center;padding:36px;color:var(--text-muted);">Loading catalog items...</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<!-- TAB 5: PROFILE & SETTINGS -->
|
|
<!-- ═══════════════════════════════════════════════════════ -->
|
|
<div id="profile" class="tab-content">
|
|
<div class="results show" style="max-width: 650px;">
|
|
<div class="result-header">
|
|
<h2>User Account & System Configuration</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);">Integration Endpoints</h3>
|
|
<div style="background:#f1f5f9;border-radius:6px;padding:14px;font-size:12.5px;font-family:monospace;color:#334155;line-height:1.6;">
|
|
<div><strong>DMH PO Details API:</strong> https://mapp.dmhospital.org/dmhApiRef/po/getPoDetails.php</div>
|
|
<div><strong>DMH GRN API:</strong> https://mapp.dmhospital.org/dmhApiRef/grn/createGRN.php</div>
|
|
<div><strong>DMH GSTIN:</strong> 27AAATL1944N1ZA (Deenanath Medical Stores)</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════════════ -->
|
|
<!-- MODAL 1: MANUAL PO APPROVAL MODAL -->
|
|
<!-- ═══════════════════════════════════════════════════════════════ -->
|
|
<div id="poApprovalModal" class="modal-overlay hidden">
|
|
<div class="modal-content" style="max-width:850px;">
|
|
<button class="modal-close" onclick="closePOModal()" title="Close">×</button>
|
|
<div class="modal-title">PO Number Approval</div>
|
|
<div id="poModalConditionBadge" style="margin:12px 0 6px;"></div>
|
|
|
|
<div class="metadata" id="poModalMeta">
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Invoice No.</span>
|
|
<span class="metadata-value" id="poModalInvoiceNo">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Vendor</span>
|
|
<span class="metadata-value" id="poModalVendor">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Invoice Date</span>
|
|
<span class="metadata-value" id="poModalDate">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Document File</span>
|
|
<span class="metadata-value" id="poModalFile" style="font-size:12px;">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Current Status</span>
|
|
<span class="metadata-value" id="poModalStatus">-</span>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 style="font-size:14px;font-weight:600;margin:16px 0 10px;color:var(--text-secondary);">Extracted Line Items</h3>
|
|
<div class="table-scroll" style="margin-bottom:20px;max-height:280px;">
|
|
<table class="items-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Description</th>
|
|
<th>Qty</th>
|
|
<th>Price</th>
|
|
<th>Item Code Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="poModalItemsBody"></tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="po-input-group">
|
|
<label for="poNumberInput">Purchase Order Number *</label>
|
|
<input type="text" id="poNumberInput" class="po-input-field" placeholder="Enter validated PO Number (e.g. PO-12345)" maxlength="100" autocomplete="off">
|
|
</div>
|
|
|
|
<div class="message" id="poModalMessage"></div>
|
|
|
|
<div class="modal-actions">
|
|
<button class="btn btn-success" id="poApproveBtn" onclick="approvePONumber()">✓ Approve PO Number</button>
|
|
<button class="btn btn-danger" onclick="rejectPOInvoice()">✗ Reject</button>
|
|
<button class="btn btn-secondary" onclick="closePOModal()">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════════════ -->
|
|
<!-- MODAL 2: MANUAL ITEM CODE APPROVAL MODAL -->
|
|
<!-- ═══════════════════════════════════════════════════════════════ -->
|
|
<div id="itemApprovalModal" class="modal-overlay hidden">
|
|
<div class="modal-content" style="max-width:920px;">
|
|
<button class="modal-close" onclick="closeItemModal()" title="Close">×</button>
|
|
<div class="modal-title">Manual Item Code Approval</div>
|
|
<div id="itemModalConditionBadge" style="margin:12px 0 8px;"></div>
|
|
|
|
<div class="metadata" id="itemModalMeta">
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Invoice No.</span>
|
|
<span class="metadata-value" id="itemModalInvoiceNo">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Vendor</span>
|
|
<span class="metadata-value" id="itemModalVendor">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Invoice Date</span>
|
|
<span class="metadata-value" id="itemModalDate">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Filename</span>
|
|
<span class="metadata-value" id="itemModalFile" style="font-size:12px;">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Approved PO</span>
|
|
<span class="metadata-value" id="itemModalPO" style="font-weight:700;color:var(--primary);">-</span>
|
|
</div>
|
|
<div class="metadata-item">
|
|
<span class="metadata-label">Status</span>
|
|
<span class="metadata-value" id="itemModalStatus">-</span>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 style="font-size:14px;font-weight:600;margin:16px 0 10px;color:var(--text-secondary);">Assign Standardized Item Codes</h3>
|
|
<div class="table-scroll" style="margin-bottom:20px;max-height:340px;">
|
|
<table class="items-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Description</th>
|
|
<th>Qty</th>
|
|
<th>Price</th>
|
|
<th style="min-width:240px;">Standardized Item Code</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="itemModalItemsBody"></tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="message" id="itemModalMessage"></div>
|
|
|
|
<div class="modal-actions">
|
|
<button class="btn btn-success" id="itemApproveBtn" onclick="approveInvoiceItemCodes()">✓ Approve Item Codes & Store in DMH</button>
|
|
<button class="btn btn-danger" onclick="rejectItemInvoice()">✗ Reject</button>
|
|
<button class="btn btn-secondary" onclick="closeItemModal()">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════════════ -->
|
|
<!-- MODAL 3: ADD DRUG TO CATALOG -->
|
|
<!-- ═══════════════════════════════════════════════════════════════ -->
|
|
<div id="addDrugModal" class="modal-overlay hidden">
|
|
<div class="modal-content" style="max-width:500px;">
|
|
<button class="modal-close" onclick="closeAddModal()" title="Close">×</button>
|
|
<div class="modal-title">Add Drug to Master Catalog</div>
|
|
<div style="display:flex;flex-direction:column;gap:12px;margin:16px 0;">
|
|
<div>
|
|
<label style="display:block;font-size:12px;font-weight:600;margin-bottom:4px;">Item Code *</label>
|
|
<input type="text" id="newDrugCode" class="code-input" placeholder="e.g. DMH-PARA-500" style="width:100%;padding:8px;">
|
|
</div>
|
|
<div>
|
|
<label style="display:block;font-size:12px;font-weight:600;margin-bottom:4px;">Drug Name / Description *</label>
|
|
<input type="text" id="newDrugName" class="code-input" placeholder="e.g. PARACETAMOL 500MG TABLET" style="width:100%;padding:8px;">
|
|
</div>
|
|
<div>
|
|
<label style="display:block;font-size:12px;font-weight:600;margin-bottom:4px;">Category</label>
|
|
<input type="text" id="newDrugCat" class="code-input" placeholder="e.g. Analgesic" style="width:100%;padding:8px;">
|
|
</div>
|
|
</div>
|
|
<div class="modal-actions">
|
|
<button class="btn btn-primary" onclick="submitAddDrug()">Save to Catalog</button>
|
|
<button class="btn btn-secondary" onclick="closeAddModal()">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ═══════════════════════════════════════════════════════════════ -->
|
|
<!-- JAVASCRIPT APPLICATION LOGIC -->
|
|
<!-- ═══════════════════════════════════════════════════════════════ -->
|
|
<script>
|
|
let currentPOInvoice = null;
|
|
let currentItemInvoice = null;
|
|
|
|
// ── Tab Descriptions for Main Header ────────────────────────
|
|
const TAB_INFO = {
|
|
'po-pending': {
|
|
title: 'Manual PO Number Approval',
|
|
sub: 'Review and approve Purchase Order numbers for pending invoices'
|
|
},
|
|
'item-pending': {
|
|
title: 'Manual Item Code Approval',
|
|
sub: 'Review and assign standardized item codes from the Drug Master catalog'
|
|
},
|
|
'po-history': {
|
|
title: 'Approval History & Audit Trail',
|
|
sub: 'Permanent record of all PO Number approvals, Item Code approvals, and automated GRN entries'
|
|
},
|
|
'manual': {
|
|
title: 'Drug Master Database Catalog',
|
|
sub: 'Search, manage and update the 14,324 standardized drug items and codes'
|
|
},
|
|
'profile': {
|
|
title: 'Account & Settings',
|
|
sub: 'Manage pharmacy staff session and view active integration parameters'
|
|
}
|
|
};
|
|
|
|
function switchTab(tabName) {
|
|
document.querySelectorAll('.tab-content').forEach(tab => {
|
|
tab.classList.remove('active');
|
|
});
|
|
document.querySelectorAll('.sidebar-nav-item').forEach(item => {
|
|
item.classList.toggle('active', item.dataset.tab === tabName);
|
|
});
|
|
|
|
const targetTab = document.getElementById(tabName);
|
|
if (targetTab) targetTab.classList.add('active');
|
|
|
|
// Update Header Title & Subtitle
|
|
const info = TAB_INFO[tabName] || { title: 'Pharmacy Dashboard', sub: 'Invoice Reconciliation' };
|
|
document.getElementById('viewTitle').textContent = info.title;
|
|
document.getElementById('viewSubtitle').textContent = info.sub;
|
|
|
|
// Load Data for Tab
|
|
if (tabName === 'po-pending') {
|
|
loadPOPending();
|
|
} else if (tabName === 'item-pending') {
|
|
loadItemPending();
|
|
} else if (tabName === 'po-history') {
|
|
loadPOHistory();
|
|
} else if (tabName === 'manual') {
|
|
loadCatalog();
|
|
} else if (tabName === 'profile') {
|
|
loadProfile();
|
|
}
|
|
|
|
loadDashboardStats();
|
|
}
|
|
|
|
// ── Live Top Stats Loader ───────────────────────────────────
|
|
async function loadDashboardStats() {
|
|
try {
|
|
const res = await fetch('/api/dashboard/stats');
|
|
const d = await res.json();
|
|
if (d.success) {
|
|
document.getElementById('statPendingPOCount').textContent = d.pending_po_count;
|
|
document.getElementById('statPendingItemCount').textContent = d.pending_item_code_count;
|
|
document.getElementById('statTotalProcessed').textContent = d.total_processed_count;
|
|
document.getElementById('statCatalogCount').textContent = Number(d.total_catalog_count).toLocaleString();
|
|
|
|
// Badges in sidebar
|
|
const poBadge = document.getElementById('poPendingTabBadge');
|
|
if (poBadge) {
|
|
poBadge.textContent = d.pending_po_count;
|
|
poBadge.style.display = d.pending_po_count > 0 ? 'inline-block' : 'none';
|
|
}
|
|
const itemBadge = document.getElementById('itemPendingTabBadge');
|
|
if (itemBadge) {
|
|
itemBadge.textContent = d.pending_item_code_count;
|
|
itemBadge.style.display = d.pending_item_code_count > 0 ? 'inline-block' : 'none';
|
|
}
|
|
|
|
// Header tags
|
|
const poTag = document.getElementById('poPendingCountTag');
|
|
if (poTag) poTag.textContent = `${d.pending_po_count} Invoices Pending`;
|
|
const itemTag = document.getElementById('itemPendingCountTag');
|
|
if (itemTag) itemTag.textContent = `${d.pending_item_code_count} Invoices Pending`;
|
|
}
|
|
} catch(e) {
|
|
console.error('Error fetching dashboard stats:', e);
|
|
}
|
|
}
|
|
|
|
function refreshDashboard() {
|
|
loadDashboardStats();
|
|
const activeNav = document.querySelector('.sidebar-nav-item.active');
|
|
if (activeNav) {
|
|
switchTab(activeNav.dataset.tab);
|
|
} else {
|
|
switchTab('po-pending');
|
|
}
|
|
}
|
|
|
|
// ── Manual PO Approval Queue ────────────────────────────────
|
|
async function loadPOPending() {
|
|
try {
|
|
const res = await fetch('/api/po-approval/pending');
|
|
const result = await res.json();
|
|
if (result.success) {
|
|
renderPOPending(result.data);
|
|
}
|
|
} catch(e) {
|
|
console.error('Error loading pending POs:', e);
|
|
}
|
|
}
|
|
|
|
function renderPOPending(items) {
|
|
const tbody = document.getElementById('poPendingBody');
|
|
if (!tbody) return;
|
|
if (!items || items.length === 0) {
|
|
tbody.innerHTML = '<tr><td colspan="9" class="empty-state" style="padding:48px;text-align:center;"><div class="empty-state-title">No Invoices Pending PO Approval</div><div class="empty-state-desc">All invoices have validated PO numbers.</div></td></tr>';
|
|
return;
|
|
}
|
|
tbody.innerHTML = items.map(inv => {
|
|
const cond = inv.condition_type || 'condition_4';
|
|
const condBadge = cond === 'condition_4'
|
|
? '<span class="tag edited" style="background:#fef3c7;color:#92400e;border:1px solid #fde68a;">Missing PO</span>'
|
|
: '<span class="tag missing" style="background:#fee2e2;color:#991b1b;border:1px solid #fecaca;">Missing PO & Code</span>';
|
|
const itemCodeClass = inv.item_code_status === 'present' ? 'insheet' : 'missing';
|
|
const itemCodeLabel = inv.item_code_status === 'present' ? 'Present' : 'Missing';
|
|
return `
|
|
<tr>
|
|
<td><strong>${inv.invoice_number || '-'}</strong></td>
|
|
<td>${inv.vendor_name || '-'}</td>
|
|
<td>${inv.invoice_date || '-'}</td>
|
|
<td style="font-size:12px;color:var(--text-muted);">${inv.invoice_filename || '-'}</td>
|
|
<td>${condBadge}</td>
|
|
<td><span class="tag missing">Missing</span></td>
|
|
<td><span class="tag ${itemCodeClass}">${itemCodeLabel}</span></td>
|
|
<td><span class="tag pending">Pending PO</span></td>
|
|
<td><button class="approve-btn" onclick="openPOModal(${inv.id})">Open Approval</button></td>
|
|
</tr>`;
|
|
}).join('');
|
|
}
|
|
|
|
async function openPOModal(poInvoiceId) {
|
|
try {
|
|
const res = await fetch(`/api/po-approval/invoice/${poInvoiceId}`);
|
|
const result = await res.json();
|
|
if (!result.success) { alert('Failed to load invoice details.'); return; }
|
|
currentPOInvoice = result.data;
|
|
renderPOModal(result.data, result.items || []);
|
|
document.getElementById('poApprovalModal').classList.remove('hidden');
|
|
document.getElementById('poNumberInput').value = '';
|
|
document.getElementById('poModalMessage').className = 'message';
|
|
document.getElementById('poModalMessage').textContent = '';
|
|
} catch(e) { alert('Error: ' + e.message); }
|
|
}
|
|
|
|
function renderPOModal(data, items) {
|
|
document.getElementById('poModalInvoiceNo').textContent = data.invoice_number || '-';
|
|
document.getElementById('poModalVendor').textContent = data.vendor_name || '-';
|
|
document.getElementById('poModalDate').textContent = data.invoice_date || '-';
|
|
document.getElementById('poModalFile').textContent = data.invoice_filename || '-';
|
|
document.getElementById('poModalStatus').textContent = data.approval_status || 'pending_po';
|
|
|
|
const cond = data.condition_type || 'condition_4';
|
|
const condEl = document.getElementById('poModalConditionBadge');
|
|
if (condEl) {
|
|
if (cond === 'condition_4') {
|
|
condEl.innerHTML = `
|
|
<span class="tag edited" style="font-size:13px;padding:5px 12px;background:#fef3c7;color:#92400e;">
|
|
Missing / Invalid PO Number (Item Codes Available)
|
|
</span>
|
|
<p style="margin:8px 0 0;font-size:13px;color:var(--text-muted);line-height:1.4;">
|
|
Item codes are already extracted from this invoice. Enter the validated PO Number to store directly in the DMH Database.
|
|
</p>`;
|
|
} else {
|
|
condEl.innerHTML = `
|
|
<span class="tag missing" style="font-size:13px;padding:5px 12px;background:#fee2e2;color:#991b1b;">
|
|
Missing PO Number & Item Codes
|
|
</span>
|
|
<p style="margin:8px 0 0;font-size:13px;color:var(--text-muted);line-height:1.4;">
|
|
Upon approving this PO Number, the system will query the DMH PO Details API to fetch item codes. If found, it stores directly; if not found, it routes to Manual Item Code Approval.
|
|
</p>`;
|
|
}
|
|
}
|
|
|
|
const tbody = document.getElementById('poModalItemsBody');
|
|
if (!items.length) {
|
|
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center;color:var(--text-muted);padding:16px;">No items extracted</td></tr>';
|
|
} else {
|
|
tbody.innerHTML = items.map(item => `
|
|
<tr>
|
|
<td><strong>${item.description || '-'}</strong></td>
|
|
<td>${item.quantity || '-'}</td>
|
|
<td>${item.unit_price || '-'}</td>
|
|
<td><span class="tag ${item.item_code ? 'insheet' : 'missing'}">${item.item_code || 'Missing'}</span></td>
|
|
</tr>
|
|
`).join('');
|
|
}
|
|
}
|
|
|
|
function closePOModal() {
|
|
document.getElementById('poApprovalModal').classList.add('hidden');
|
|
currentPOInvoice = null;
|
|
}
|
|
|
|
async function approvePONumber() {
|
|
if (!currentPOInvoice) return;
|
|
const poNumber = document.getElementById('poNumberInput').value.trim();
|
|
if (!poNumber) {
|
|
showPOModalMessage('Please enter a PO Number before approving.', 'error');
|
|
return;
|
|
}
|
|
if (!confirm(`Approve invoice "${currentPOInvoice.invoice_number || currentPOInvoice.id}" with PO Number: ${poNumber}?`)) return;
|
|
|
|
const btn = document.getElementById('poApproveBtn');
|
|
btn.disabled = true; btn.textContent = 'Processing Approval...';
|
|
|
|
try {
|
|
const res = await fetch(`/api/po-approval/${currentPOInvoice.id}/approve`, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({po_number: poNumber})
|
|
});
|
|
const result = await res.json();
|
|
btn.disabled = false; btn.textContent = '✓ Approve PO Number';
|
|
|
|
if (result.success) {
|
|
alert('Success: ' + result.message);
|
|
closePOModal();
|
|
loadPOPending();
|
|
loadItemPending();
|
|
loadDashboardStats();
|
|
} else {
|
|
showPOModalMessage(result.error || 'Failed to approve invoice.', 'error');
|
|
}
|
|
} catch(e) {
|
|
btn.disabled = false; btn.textContent = '✓ Approve PO Number';
|
|
showPOModalMessage('Network error: ' + e.message, 'error');
|
|
}
|
|
}
|
|
|
|
async function rejectPOInvoice() {
|
|
if (!currentPOInvoice) return;
|
|
const reason = prompt('Enter rejection reason:');
|
|
if (reason === null) return;
|
|
try {
|
|
const res = await fetch(`/api/po-approval/${currentPOInvoice.id}/reject`, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({notes: reason})
|
|
});
|
|
const result = await res.json();
|
|
if (result.success) {
|
|
alert('Invoice marked as rejected.');
|
|
closePOModal();
|
|
loadPOPending();
|
|
loadDashboardStats();
|
|
}
|
|
} catch(e) { alert('Error: ' + e.message); }
|
|
}
|
|
|
|
function showPOModalMessage(msg, type) {
|
|
const el = document.getElementById('poModalMessage');
|
|
el.className = `message ${type}`;
|
|
el.textContent = msg;
|
|
}
|
|
|
|
|
|
// ── Manual Item Code Approval Queue ─────────────────────────
|
|
async function loadItemPending() {
|
|
try {
|
|
const res = await fetch('/api/item-approval/pending');
|
|
const result = await res.json();
|
|
if (result.success) {
|
|
renderItemPending(result.data);
|
|
}
|
|
} catch(e) {
|
|
console.error('Error loading item pending queue:', e);
|
|
}
|
|
}
|
|
|
|
function renderItemPending(invoices) {
|
|
const tbody = document.getElementById('itemPendingBody');
|
|
if (!tbody) return;
|
|
if (!invoices || invoices.length === 0) {
|
|
tbody.innerHTML = '<tr><td colspan="9" class="empty-state" style="padding:48px;text-align:center;"><div class="empty-state-title">No Invoices Pending Item Code Approval</div><div class="empty-state-desc">All item codes are fully assigned and approved.</div></td></tr>';
|
|
return;
|
|
}
|
|
tbody.innerHTML = invoices.map(inv => {
|
|
const cond = inv.condition_type || 'condition_3';
|
|
const condBadge = cond === 'condition_5'
|
|
? '<span class="tag missing" style="background:#fdf2f8;color:#9d174d;border:1px solid #fbcfe8;">PO Approved, Code Pending</span>'
|
|
: '<span class="tag warning" style="background:#fffbeb;color:#92400e;border:1px solid #fde68a;">Code Pending</span>';
|
|
return `
|
|
<tr>
|
|
<td><strong>${inv.invoice_number || '-'}</strong></td>
|
|
<td>${inv.vendor_name || '-'}</td>
|
|
<td>${inv.invoice_date || '-'}</td>
|
|
<td style="font-size:12px;color:var(--text-muted);">${inv.invoice_filename || '-'}</td>
|
|
<td><strong style="color:var(--primary);font-family:monospace;">${inv.po_number_approved || inv.po_number_original || '-'}</strong></td>
|
|
<td>${condBadge}</td>
|
|
<td><span class="tag missing">Missing</span></td>
|
|
<td><span class="tag pending">Pending Codes</span></td>
|
|
<td><button class="approve-btn" onclick="openItemModal(${inv.id})">Review & Approve</button></td>
|
|
</tr>`;
|
|
}).join('');
|
|
}
|
|
|
|
async function openItemModal(poInvoiceId) {
|
|
try {
|
|
const res = await fetch(`/api/po-approval/invoice/${poInvoiceId}`);
|
|
const result = await res.json();
|
|
if (!result.success) { alert('Failed to load invoice details'); return; }
|
|
currentItemInvoice = result.data;
|
|
renderItemModal(result.data, result.items || []);
|
|
document.getElementById('itemApprovalModal').classList.remove('hidden');
|
|
document.getElementById('itemModalMessage').className = 'message';
|
|
document.getElementById('itemModalMessage').textContent = '';
|
|
} catch(e) { alert('Error: ' + e.message); }
|
|
}
|
|
|
|
function renderItemModal(data, items) {
|
|
document.getElementById('itemModalInvoiceNo').textContent = data.invoice_number || '-';
|
|
document.getElementById('itemModalVendor').textContent = data.vendor_name || '-';
|
|
document.getElementById('itemModalDate').textContent = data.invoice_date || '-';
|
|
document.getElementById('itemModalFile').textContent = data.invoice_filename || '-';
|
|
document.getElementById('itemModalPO').textContent = data.po_number_approved || data.po_number_original || '-';
|
|
document.getElementById('itemModalStatus').textContent = data.approval_status || 'pending_item_code';
|
|
|
|
const cond = data.condition_type || 'condition_3';
|
|
const badgeEl = document.getElementById('itemModalConditionBadge');
|
|
if (badgeEl) {
|
|
badgeEl.innerHTML = `
|
|
<span class="tag warning" style="font-size:13px;padding:5px 12px;">
|
|
${cond === 'condition_5' ? 'PO Approved — Standardized Item Codes Required' : 'PO Verified — Standardized Item Codes Required'}
|
|
</span>
|
|
<p style="margin:6px 0 0;font-size:13px;color:var(--text-muted);line-height:1.4;">
|
|
Assign standardized item codes for each extracted line item. Upon approval, the completed record is stored in the DMH Database.
|
|
</p>`;
|
|
}
|
|
|
|
const tbody = document.getElementById('itemModalItemsBody');
|
|
if (!items.length) {
|
|
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center;padding:16px;color:var(--text-muted);">No items found</td></tr>';
|
|
} else {
|
|
tbody.innerHTML = items.map((item, idx) => `
|
|
<tr>
|
|
<td>
|
|
<strong>${item.description || '-'}</strong>
|
|
${item.pack ? `<div style="font-size:11px;color:var(--text-muted)">Pack: ${item.pack}</div>` : ''}
|
|
</td>
|
|
<td>${item.quantity || '-'}</td>
|
|
<td>${item.unit_price || '-'}</td>
|
|
<td>
|
|
<input type="text" class="code-input item-code-entry" data-index="${idx}"
|
|
placeholder="Enter Item Code (e.g. DMH-001)..." value="${item.item_code || ''}"
|
|
style="width:100%;padding:7px 10px;font-family:monospace;font-weight:600;font-size:13px;">
|
|
</td>
|
|
</tr>
|
|
`).join('');
|
|
}
|
|
}
|
|
|
|
function closeItemModal() {
|
|
document.getElementById('itemApprovalModal').classList.add('hidden');
|
|
currentItemInvoice = null;
|
|
}
|
|
|
|
async function approveInvoiceItemCodes() {
|
|
if (!currentItemInvoice) return;
|
|
const inputs = document.querySelectorAll('.item-code-entry');
|
|
const items = [];
|
|
let allFilled = true;
|
|
|
|
inputs.forEach(input => {
|
|
const idx = parseInt(input.dataset.index, 10);
|
|
const code = input.value.trim();
|
|
if (!code) allFilled = false;
|
|
items.push({ index: idx, item_code: code });
|
|
});
|
|
|
|
if (!allFilled) {
|
|
const msgEl = document.getElementById('itemModalMessage');
|
|
msgEl.className = 'message error';
|
|
msgEl.textContent = 'Please enter a standardized item code for all items before approving.';
|
|
return;
|
|
}
|
|
|
|
const btn = document.getElementById('itemApproveBtn');
|
|
btn.disabled = true; btn.textContent = 'Storing in DMH Database...';
|
|
|
|
try {
|
|
const res = await fetch(`/api/item-approval/${currentItemInvoice.id}/approve`, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({ items })
|
|
});
|
|
const result = await res.json();
|
|
btn.disabled = false; btn.textContent = '✓ Approve Item Codes & Store in DMH';
|
|
|
|
if (result.success) {
|
|
alert('Success! ' + result.message);
|
|
closeItemModal();
|
|
loadItemPending();
|
|
loadDashboardStats();
|
|
} else {
|
|
const msgEl = document.getElementById('itemModalMessage');
|
|
msgEl.className = 'message error';
|
|
msgEl.textContent = result.error || 'Failed to approve item codes.';
|
|
}
|
|
} catch(e) {
|
|
btn.disabled = false; btn.textContent = '✓ Approve Item Codes & Store in DMH';
|
|
alert('Error: ' + e.message);
|
|
}
|
|
}
|
|
|
|
async function rejectItemInvoice() {
|
|
if (!currentItemInvoice) return;
|
|
const reason = prompt('Enter rejection reason:');
|
|
if (reason === null) return;
|
|
try {
|
|
const res = await fetch(`/api/po-approval/${currentItemInvoice.id}/reject`, {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({notes: reason})
|
|
});
|
|
const result = await res.json();
|
|
if (result.success) {
|
|
alert('Invoice marked as rejected.');
|
|
closeItemModal();
|
|
loadItemPending();
|
|
loadDashboardStats();
|
|
}
|
|
} catch(e) { alert('Error: ' + e.message); }
|
|
}
|
|
|
|
|
|
// ── Approval History & Audit Trail (Both PO & Item Code) ────
|
|
async function loadPOHistory() {
|
|
const typeFilter = document.getElementById('poHistoryTypeFilter')?.value || '';
|
|
const condFilter = document.getElementById('poHistoryConditionFilter')?.value || '';
|
|
const statusFilter = document.getElementById('poHistoryStatusFilter')?.value || '';
|
|
const webhookFilter = document.getElementById('poHistoryWebhookFilter')?.value || '';
|
|
|
|
let url = '/api/po-approval/history?per_page=50';
|
|
if (typeFilter && typeFilter !== 'all') url += `&approval_type=${encodeURIComponent(typeFilter)}`;
|
|
if (condFilter && condFilter !== 'all') url += `&condition_type=${encodeURIComponent(condFilter)}`;
|
|
if (statusFilter && statusFilter !== 'all') url += `&status=${encodeURIComponent(statusFilter)}`;
|
|
if (webhookFilter && webhookFilter !== 'all') url += `&webhook_status=${encodeURIComponent(webhookFilter)}`;
|
|
|
|
try {
|
|
const res = await fetch(url);
|
|
const result = await res.json();
|
|
if (result.success) renderPOHistory(result.data);
|
|
} catch(e) {
|
|
console.error('Error loading history:', e);
|
|
}
|
|
}
|
|
|
|
function renderPOHistory(items) {
|
|
const tbody = document.getElementById('poHistoryBody');
|
|
if (!tbody) return;
|
|
if (!items || items.length === 0) {
|
|
tbody.innerHTML = '<tr><td colspan="10" class="empty-state" style="text-align:center;padding:48px;color:var(--text-muted);"><div class="empty-state-title">No Audit Records Found</div><div class="empty-state-desc">All approvals and reconciliations will be logged here permanently.</div></td></tr>';
|
|
return;
|
|
}
|
|
tbody.innerHTML = items.map(h => {
|
|
// Type Badge
|
|
const appType = h.approval_type || 'po_approval';
|
|
let typeBadge = '<span class="tag api" style="background:#e0f2fe;color:#0369a1;font-weight:600;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="margin-right:4px;vertical-align:-1px;"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><rect x="8" y="2" width="8" height="4" rx="1" ry="1"/><path d="m9 14 2 2 4-4"/></svg>PO Approval</span>';
|
|
if (appType === 'item_code_approval') {
|
|
typeBadge = '<span class="tag warning" style="background:#ffedd5;color:#9a3412;font-weight:600;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="margin-right:4px;vertical-align:-1px;"><path d="m10.5 20.5 10-10a4.95 4.95 0 1 0-7-7l-10 10a4.95 4.95 0 1 0 7 7Z"/><path d="m8.5 8.5 7 7"/></svg>Item Code</span>';
|
|
} else if (appType === 'auto_grn') {
|
|
typeBadge = '<span class="tag insheet" style="background:#ecfdf5;color:#065f46;font-weight:600;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" style="margin-right:4px;vertical-align:-1px;"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>Auto GRN</span>';
|
|
}
|
|
|
|
// Processing Flow Badge
|
|
const cond = h.condition_type || 'condition_1';
|
|
let condBadge = '<span class="tag insheet" style="background:#ecfdf5;color:#065f46;border:1px solid #a7f3d0;font-weight:600;">Direct Store</span>';
|
|
if (cond === 'condition_2') {
|
|
condBadge = '<span class="tag api" style="background:#eff6ff;color:#1e40af;border:1px solid #bfdbfe;font-weight:600;">API Lookup</span>';
|
|
} else if (cond === 'condition_3') {
|
|
condBadge = '<span class="tag warning" style="background:#fffbeb;color:#92400e;border:1px solid #fde68a;font-weight:600;">Manual Item Code</span>';
|
|
} else if (cond === 'condition_4') {
|
|
condBadge = '<span class="tag edited" style="background:#fef3c7;color:#92400e;border:1px solid #fde68a;font-weight:600;">Manual PO</span>';
|
|
} else if (cond === 'condition_5') {
|
|
condBadge = '<span class="tag missing" style="background:#fdf2f8;color:#9d174d;border:1px solid #fbcfe8;font-weight:600;">Manual PO & Code</span>';
|
|
}
|
|
|
|
const st = h.approval_status || 'completed';
|
|
const statusTag = (st === 'completed' || st === 'approved') ? 'insheet' : st === 'rejected' ? 'missing' : 'pending';
|
|
const statusLabel = st.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
|
|
|
const wsTag = h.webhook_status === 'success' ? 'insheet' : h.webhook_status === 'failed' ? 'missing' : h.webhook_status === 'not_configured' ? 'edited' : 'pending';
|
|
const wsLabel = (h.webhook_status || 'not_triggered').replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
|
const retryBtn = (h.webhook_status === 'failed' || h.webhook_status === 'not_configured') && (st === 'completed' || st === 'approved')
|
|
? `<button class="approve-btn" style="margin-left:6px;padding:2px 8px;font-size:11px;" onclick="retryWebhook(${h.id})">Retry</button>` : '';
|
|
|
|
const poDisplay = h.po_number_approved
|
|
? `<strong>${h.po_number_approved}</strong>`
|
|
: (h.po_number_previous ? `<span style="color:var(--text-muted);">${h.po_number_previous}</span>` : '-');
|
|
|
|
return `<tr>
|
|
<td><strong>${h.invoice_number || '-'}</strong></td>
|
|
<td>${h.vendor_name || '-'}</td>
|
|
<td>${typeBadge}</td>
|
|
<td>${condBadge}</td>
|
|
<td>${poDisplay}</td>
|
|
<td><span class="tag ${statusTag}">${statusLabel}</span></td>
|
|
<td>${h.approved_by_username || (h.approved_by ? 'User #' + h.approved_by : 'System')}</td>
|
|
<td style="font-size:12px;">${h.approval_timestamp ? new Date(h.approval_timestamp).toLocaleString() : '-'}</td>
|
|
<td><span class="tag ${wsTag}">${wsLabel}</span>${retryBtn}</td>
|
|
<td style="font-size:12px;color:var(--text-secondary);max-width:260px;">${h.notes || '-'}</td>
|
|
</tr>`;
|
|
}).join('');
|
|
}
|
|
|
|
async function retryWebhook(historyId) {
|
|
if (!confirm('Retry webhook for this approval record?')) return;
|
|
try {
|
|
const res = await fetch(`/api/po-approval/${historyId}/retry-webhook`, {method: 'POST'});
|
|
const result = await res.json();
|
|
if (result.success) {
|
|
alert(`Webhook retry: ${result.webhook_status}`);
|
|
loadPOHistory();
|
|
} else {
|
|
alert('Retry failed: ' + (result.error || 'Unknown error'));
|
|
}
|
|
} catch(e) { alert('Error: ' + e.message); }
|
|
}
|
|
|
|
|
|
// ── Drug Master Catalog Logic ───────────────────────────────
|
|
let catalogDebounceTimer = null;
|
|
function debounceCatalogSearch() {
|
|
clearTimeout(catalogDebounceTimer);
|
|
catalogDebounceTimer = setTimeout(searchCatalog, 300);
|
|
}
|
|
|
|
async function loadCatalog() {
|
|
loadCategories();
|
|
searchCatalog();
|
|
}
|
|
|
|
async function loadCategories() {
|
|
try {
|
|
const res = await fetch('/api/catalog/categories');
|
|
const d = await res.json();
|
|
if (d.success) {
|
|
const sel = document.getElementById('catalogCategorySelect');
|
|
sel.innerHTML = '<option value="">All Categories</option>' + d.data.map(c => `<option value="${c}">${c}</option>`).join('');
|
|
}
|
|
} catch(e) {}
|
|
}
|
|
|
|
async function searchCatalog() {
|
|
const q = document.getElementById('catalogSearchInput')?.value || '';
|
|
const cat = document.getElementById('catalogCategorySelect')?.value || '';
|
|
try {
|
|
const res = await fetch(`/api/catalog?q=${encodeURIComponent(q)}&category=${encodeURIComponent(cat)}&per_page=50`);
|
|
const d = await res.json();
|
|
if (d.success) {
|
|
const tbody = document.getElementById('catalogTableBody');
|
|
if (!d.data.length) {
|
|
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center;padding:24px;color:var(--text-muted);">No drugs found</td></tr>';
|
|
} else {
|
|
tbody.innerHTML = d.data.map(item => `
|
|
<tr>
|
|
<td><strong style="font-family:monospace;color:var(--primary);">${item.item_code}</strong></td>
|
|
<td>${item.name}</td>
|
|
<td><span class="tag api">${item.category || 'General'}</span></td>
|
|
<td><button class="approve-btn" onclick="promptEditDrug(${item.id}, '${item.item_code}', '${item.name.replace(/'/g, "\\'")}')">Edit</button></td>
|
|
</tr>
|
|
`).join('');
|
|
}
|
|
}
|
|
} catch(e) {}
|
|
}
|
|
|
|
function openAddModal() {
|
|
document.getElementById('newDrugCode').value = '';
|
|
document.getElementById('newDrugName').value = '';
|
|
document.getElementById('newDrugCat').value = '';
|
|
document.getElementById('addDrugModal').classList.remove('hidden');
|
|
}
|
|
|
|
function closeAddModal() {
|
|
document.getElementById('addDrugModal').classList.add('hidden');
|
|
}
|
|
|
|
async function submitAddDrug() {
|
|
const code = document.getElementById('newDrugCode').value.trim();
|
|
const name = document.getElementById('newDrugName').value.trim();
|
|
const cat = document.getElementById('newDrugCat').value.trim() || 'General';
|
|
if (!code || !name) { alert('Item Code and Drug Name are required.'); return; }
|
|
|
|
try {
|
|
const res = await fetch('/api/catalog', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({ item_code: code, name: name, category: cat })
|
|
});
|
|
const d = await res.json();
|
|
if (d.success) {
|
|
alert('Drug added to catalog successfully!');
|
|
closeAddModal();
|
|
searchCatalog();
|
|
loadDashboardStats();
|
|
} else {
|
|
alert(d.error || 'Failed to add drug');
|
|
}
|
|
} catch(e) { alert('Error: ' + e.message); }
|
|
}
|
|
|
|
async function promptEditDrug(id, code, currentName) {
|
|
const newName = prompt(`Edit name for ${code}:`, currentName);
|
|
if (!newName || newName === currentName) return;
|
|
try {
|
|
const res = await fetch(`/api/catalog/${id}`, {
|
|
method: 'PUT',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({ name: newName })
|
|
});
|
|
const d = await res.json();
|
|
if (d.success) {
|
|
searchCatalog();
|
|
}
|
|
} catch(e) { alert('Error: ' + e.message); }
|
|
}
|
|
|
|
|
|
// ── Profile Loader ──────────────────────────────────────────
|
|
async function loadProfile() {
|
|
try {
|
|
const res = await fetch('/api/profile');
|
|
const d = await res.json();
|
|
if (d.success) {
|
|
const el = document.getElementById('profileInfo');
|
|
el.innerHTML = `
|
|
<div class="metadata-item"><span class="metadata-label">Username</span><span class="metadata-value">${d.data.username}</span></div>
|
|
<div class="metadata-item"><span class="metadata-label">Role</span><span class="metadata-value">${d.data.is_admin ? 'Administrator' : 'Pharmacy Staff'}</span></div>
|
|
<div class="metadata-item"><span class="metadata-label">Created At</span><span class="metadata-value">${new Date(d.data.created_at).toLocaleString()}</span></div>
|
|
`;
|
|
}
|
|
} catch(e) {}
|
|
}
|
|
|
|
// ── Initial Setup ───────────────────────────────────────────
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
switchTab('po-pending');
|
|
loadDashboardStats();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|