feat: Implement modular plugin architecture
- Convert invcount to self-contained module - Add Module Manager for install/uninstall - Create module_registry database table - Support hot-reloading of modules - Move data imports into invcount module - Update all templates and routes to new structure Version bumped to 0.16.0
This commit is contained in:
@@ -4,28 +4,45 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="dashboard-header" style="margin-top: var(--space-lg);">
|
||||
<div class="dashboard-header" style="margin-top: var(--space-lg);">
|
||||
<div class="header-left" style="display: flex; align-items: center; gap: var(--space-md);">
|
||||
<a href="{{ url_for('home') }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Home
|
||||
</a>
|
||||
<h1 class="page-title" style="margin-bottom: 0;">Admin Dashboard</h1>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<a href="{{ url_for('module_manager_ui') }}" class="btn btn-primary btn-sm">
|
||||
<i class="fa-solid fa-puzzle-piece"></i> Module Manager
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modules-section">
|
||||
<h2 class="section-title">Modules</h2>
|
||||
|
||||
{% if modules %}
|
||||
<div class="modules-grid">
|
||||
<a href="{{ url_for('counting.admin_dashboard') }}" class="module-card">
|
||||
<div class="module-icon">📊</div> <h3 class="module-name">Counts</h3>
|
||||
<p class="module-desc">Cycle counts & physical inventory</p>
|
||||
</a>
|
||||
|
||||
<a href="{{ url_for('cons_sheets.admin_processes') }}" class="module-card module-card-link">
|
||||
<div class="module-icon">📝</div> <h3 class="module-name">Consumption Sheets</h3>
|
||||
<p class="module-desc">Production consumption tracking</p>
|
||||
{% for module in modules %}
|
||||
<a href="/{{ module.module_key }}/admin" class="module-card module-card-link">
|
||||
<div class="module-icon">
|
||||
{% if module.icon %}
|
||||
<i class="{{ module.icon }}"></i>
|
||||
{% else %}
|
||||
📦
|
||||
{% endif %}
|
||||
</div>
|
||||
<h3 class="module-name">{{ module.module_name }}</h3>
|
||||
<p class="module-desc">{{ module.description }}</p>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-info">
|
||||
<i class="fa-solid fa-info-circle"></i> No modules installed yet.
|
||||
<a href="{{ url_for('module_manager_ui') }}">Install modules</a> to get started.
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,81 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Add {{ 'Header' if table_type == 'header' else 'Detail' }} Field - {{ process.process_name }} - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Fields
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="form-container" style="max-width: 600px; margin: 0 auto;">
|
||||
<h1 class="page-title" style="text-align: center;">Add {{ 'Header' if table_type == 'header' else 'Detail' }} Field</h1>
|
||||
<p class="page-subtitle" style="text-align: center; margin-bottom: var(--space-xl);">{{ process.process_name }}</p>
|
||||
|
||||
<form method="POST" class="form-card">
|
||||
<div class="form-group">
|
||||
<label for="field_label" class="form-label">Field Label *</label>
|
||||
<input type="text" id="field_label" name="field_label" class="form-input"
|
||||
placeholder="e.g., Lot Number" required autofocus>
|
||||
<p class="form-hint">Display name (field_name is auto-generated)</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="field_type" class="form-label">Data Type *</label>
|
||||
<select id="field_type" name="field_type" class="form-input" required>
|
||||
<option value="TEXT">TEXT (words, codes, etc.)</option>
|
||||
<option value="INTEGER">INTEGER (whole numbers)</option>
|
||||
<option value="REAL">REAL (decimals, weights)</option>
|
||||
<option value="DATE">DATE</option>
|
||||
<option value="DATETIME">DATETIME</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="max_length" class="form-label">Max Length</label>
|
||||
<input type="number" id="max_length" name="max_length" class="form-input"
|
||||
placeholder="Leave blank for no limit" min="1">
|
||||
<p class="form-hint">Only applies to TEXT fields</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" name="is_required" value="1">
|
||||
<span>Required field</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{% if table_type == 'detail' %}
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" name="is_duplicate_key" value="1">
|
||||
<span>Use for duplicate detection</span>
|
||||
</label>
|
||||
<p class="form-hint">Check this for the field that should be checked for duplicates (e.g., Lot Number)</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="form-group">
|
||||
<label for="excel_cell" class="form-label">Excel Cell{% if table_type == 'detail' %} (Column){% endif %}</label>
|
||||
<input type="text" id="excel_cell" name="excel_cell" class="form-input"
|
||||
placeholder="{% if table_type == 'header' %}e.g., A3{% else %}e.g., A{% endif %}"
|
||||
style="text-transform: uppercase;">
|
||||
<p class="form-hint">
|
||||
{% if table_type == 'header' %}
|
||||
Full cell reference (e.g., A3, B5)
|
||||
{% else %}
|
||||
Column letter only (e.g., A, B) — row is calculated
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Add Field</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,36 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Create Process - Consumption Sheets - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.admin_processes') }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Processes
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="form-container" style="max-width: 600px; margin: 0 auto;">
|
||||
<h1 class="page-title" style="text-align: center; margin-bottom: var(--space-xl);">Create New Process</h1>
|
||||
|
||||
<form method="POST" class="form-card">
|
||||
<div class="form-group">
|
||||
<label for="process_name" class="form-label">Process Name</label>
|
||||
<input type="text"
|
||||
id="process_name"
|
||||
name="process_name"
|
||||
class="form-input"
|
||||
placeholder="e.g., AD WIP"
|
||||
required
|
||||
autofocus>
|
||||
<p class="form-hint">This will be displayed in menus and reports</p>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('cons_sheets.admin_processes') }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Create Process</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,80 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Edit Field - {{ process.process_name }} - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Fields
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="form-container" style="max-width: 600px; margin: 0 auto;">
|
||||
<h1 class="page-title" style="text-align: center;">Edit Field</h1>
|
||||
<p class="page-subtitle" style="text-align: center; margin-bottom: var(--space-xl);">
|
||||
{{ process.process_name }} — {{ 'Header' if field.table_type == 'header' else 'Detail' }}
|
||||
</p>
|
||||
|
||||
<form method="POST" class="form-card">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Field Name</label>
|
||||
<input type="text" class="form-input" value="{{ field.field_name }}" disabled
|
||||
style="opacity: 0.6; font-family: var(--font-mono);">
|
||||
<p class="form-hint">Cannot be changed (used in database)</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="field_label" class="form-label">Field Label *</label>
|
||||
<input type="text" id="field_label" name="field_label" class="form-input"
|
||||
value="{{ field.field_label }}" required autofocus>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="field_type" class="form-label">Data Type *</label>
|
||||
<select id="field_type" name="field_type" class="form-input" required>
|
||||
<option value="TEXT" {% if field.field_type == 'TEXT' %}selected{% endif %}>TEXT</option>
|
||||
<option value="INTEGER" {% if field.field_type == 'INTEGER' %}selected{% endif %}>INTEGER</option>
|
||||
<option value="REAL" {% if field.field_type == 'REAL' %}selected{% endif %}>REAL</option>
|
||||
<option value="DATE" {% if field.field_type == 'DATE' %}selected{% endif %}>DATE</option>
|
||||
<option value="DATETIME" {% if field.field_type == 'DATETIME' %}selected{% endif %}>DATETIME</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="max_length" class="form-label">Max Length</label>
|
||||
<input type="number" id="max_length" name="max_length" class="form-input"
|
||||
value="{{ field.max_length or '' }}" min="1">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" name="is_required" value="1" {% if field.is_required %}checked{% endif %}>
|
||||
<span>Required field</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{% if field.table_type == 'detail' %}
|
||||
<div class="form-group">
|
||||
<label class="checkbox-label">
|
||||
<input type="checkbox" name="is_duplicate_key" value="1" {% if field.is_duplicate_key %}checked{% endif %}>
|
||||
<span>Use for duplicate detection</span>
|
||||
</label>
|
||||
<p class="form-hint">Check this for the field that should be checked for duplicates (e.g., Lot Number)</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="form-group">
|
||||
<label for="excel_cell" class="form-label">Excel Cell{% if field.table_type == 'detail' %} (Column){% endif %}</label>
|
||||
<input type="text" id="excel_cell" name="excel_cell" class="form-input"
|
||||
value="{{ field.excel_cell or '' }}" style="text-transform: uppercase;">
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,99 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}New {{ process.process_name }} Session - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.index') }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="form-container" style="max-width: 600px; margin: 0 auto;">
|
||||
<h1 class="page-title" style="text-align: center;">New {{ process.process_name }} Session</h1>
|
||||
<p class="page-subtitle" style="text-align: center; margin-bottom: var(--space-xl);">Enter header information to begin scanning</p>
|
||||
|
||||
<form method="POST" class="form-card">
|
||||
{% for field in header_fields %}
|
||||
<div class="form-group">
|
||||
<label for="{{ field.field_name }}" class="form-label">
|
||||
{{ field.field_label }}
|
||||
{% if field.is_required %}<span class="required">*</span>{% endif %}
|
||||
</label>
|
||||
|
||||
{% if field.field_type == 'DATE' %}
|
||||
<input type="date"
|
||||
id="{{ field.field_name }}"
|
||||
name="{{ field.field_name }}"
|
||||
class="form-input"
|
||||
value="{{ form_data.get(field.field_name, '') }}"
|
||||
{% if field.is_required %}required{% endif %}>
|
||||
|
||||
{% elif field.field_type == 'DATETIME' %}
|
||||
<input type="datetime-local"
|
||||
id="{{ field.field_name }}"
|
||||
name="{{ field.field_name }}"
|
||||
class="form-input"
|
||||
value="{{ form_data.get(field.field_name, '') }}"
|
||||
{% if field.is_required %}required{% endif %}>
|
||||
|
||||
{% elif field.field_type == 'INTEGER' %}
|
||||
<input type="number"
|
||||
id="{{ field.field_name }}"
|
||||
name="{{ field.field_name }}"
|
||||
class="form-input"
|
||||
value="{{ form_data.get(field.field_name, '') }}"
|
||||
step="1"
|
||||
{% if field.is_required %}required{% endif %}>
|
||||
|
||||
{% elif field.field_type == 'REAL' %}
|
||||
<input type="number"
|
||||
id="{{ field.field_name }}"
|
||||
name="{{ field.field_name }}"
|
||||
class="form-input"
|
||||
value="{{ form_data.get(field.field_name, '') }}"
|
||||
step="0.01"
|
||||
{% if field.is_required %}required{% endif %}>
|
||||
|
||||
{% else %}
|
||||
<input type="text"
|
||||
id="{{ field.field_name }}"
|
||||
name="{{ field.field_name }}"
|
||||
class="form-input"
|
||||
value="{{ form_data.get(field.field_name, '') }}"
|
||||
{% if field.max_length %}maxlength="{{ field.max_length }}"{% endif %}
|
||||
{% if field.is_required %}required{% endif %}>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% if not header_fields %}
|
||||
<div class="empty-state-small">
|
||||
<p>No header fields configured for this process.</p>
|
||||
<p>Contact your administrator to set up fields.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('cons_sheets.index') }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary" {% if not header_fields %}disabled{% endif %}>
|
||||
Start Scanning
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.required {
|
||||
color: var(--color-danger);
|
||||
}
|
||||
|
||||
.empty-state-small {
|
||||
text-align: center;
|
||||
padding: var(--space-xl);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
@@ -1,245 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ process.process_name }} - Consumption Sheets - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.admin_processes') }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Processes
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-header">
|
||||
<div class="header-left">
|
||||
<h1 class="page-title">{{ process.process_name }}</h1>
|
||||
<p class="page-subtitle">Key: <code style="font-family: var(--font-mono); color: var(--color-primary);">{{ process.process_key }}</code></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Configuration Options -->
|
||||
<div class="config-grid">
|
||||
<!-- Database Configuration Card -->
|
||||
<div class="config-card">
|
||||
<div class="config-card-header">
|
||||
<div class="config-icon">🗄️</div>
|
||||
<h2 class="config-title">Database</h2>
|
||||
</div>
|
||||
<p class="config-desc">Define fields for header and detail tables</p>
|
||||
|
||||
<div class="config-stats">
|
||||
<div class="config-stat">
|
||||
<span class="stat-number">{{ header_fields|length }}</span>
|
||||
<span class="stat-label">Header Fields</span>
|
||||
</div>
|
||||
<div class="config-stat">
|
||||
<span class="stat-number">{{ detail_fields|length }}</span>
|
||||
<span class="stat-label">Detail Fields</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-primary btn-block">
|
||||
Configure Fields
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Excel Template Card -->
|
||||
<div class="config-card">
|
||||
<div class="config-card-header">
|
||||
<div class="config-icon">📊</div>
|
||||
<h2 class="config-title">Excel Template</h2>
|
||||
</div>
|
||||
<p class="config-desc">Upload template and map fields to cells</p>
|
||||
|
||||
<div class="config-stats">
|
||||
<div class="config-stat">
|
||||
{% if process.template_file %}
|
||||
<span class="stat-number" style="color: var(--color-success);">✓</span>
|
||||
<span class="stat-label">{{ process.template_filename or 'Uploaded' }}</span>
|
||||
{% else %}
|
||||
<span class="stat-number" style="color: var(--color-warning);">—</span>
|
||||
<span class="stat-label">No template</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="config-stat">
|
||||
<span class="stat-number">{{ process.rows_per_page or 30 }}</span>
|
||||
<span class="stat-label">Rows/Page</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('cons_sheets.process_template', process_id=process.id) }}" class="btn btn-primary btn-block">
|
||||
Configure Template
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quick Field Preview -->
|
||||
{% if header_fields or detail_fields %}
|
||||
<div class="fields-preview">
|
||||
<h3 class="section-title">Field Preview</h3>
|
||||
|
||||
{% if header_fields %}
|
||||
<div class="field-section">
|
||||
<h4 class="field-section-title">Header Fields</h4>
|
||||
<div class="field-list">
|
||||
{% for field in header_fields %}
|
||||
<div class="field-chip">
|
||||
<span class="field-name">{{ field.field_label }}</span>
|
||||
<span class="field-type">{{ field.field_type }}</span>
|
||||
{% if field.excel_cell %}
|
||||
<span class="field-cell">→ {{ field.excel_cell }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if detail_fields %}
|
||||
<div class="field-section">
|
||||
<h4 class="field-section-title">Detail Fields</h4>
|
||||
<div class="field-list">
|
||||
{% for field in detail_fields %}
|
||||
<div class="field-chip">
|
||||
<span class="field-name">{{ field.field_label }}</span>
|
||||
<span class="field-type">{{ field.field_type }}</span>
|
||||
{% if field.excel_cell %}
|
||||
<span class="field-cell">→ Col {{ field.excel_cell }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.config-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: var(--space-xl);
|
||||
margin-top: var(--space-xl);
|
||||
}
|
||||
|
||||
.config-card {
|
||||
background: var(--color-surface);
|
||||
border: 2px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--space-xl);
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.config-card:hover {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: var(--shadow-glow);
|
||||
}
|
||||
|
||||
.config-card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-md);
|
||||
margin-bottom: var(--space-md);
|
||||
}
|
||||
|
||||
.config-icon {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.config-title {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: var(--color-text);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.config-desc {
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: var(--space-lg);
|
||||
}
|
||||
|
||||
.config-stats {
|
||||
display: flex;
|
||||
gap: var(--space-xl);
|
||||
margin-bottom: var(--space-lg);
|
||||
padding: var(--space-md);
|
||||
background: var(--color-surface-elevated);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.config-stat {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.config-stat .stat-number {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
color: var(--color-primary);
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.config-stat .stat-label {
|
||||
font-size: 0.75rem;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.fields-preview {
|
||||
margin-top: var(--space-2xl);
|
||||
padding-top: var(--space-xl);
|
||||
border-top: 2px solid var(--color-border);
|
||||
}
|
||||
|
||||
.field-section {
|
||||
margin-bottom: var(--space-lg);
|
||||
}
|
||||
|
||||
.field-section-title {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
margin-bottom: var(--space-md);
|
||||
}
|
||||
|
||||
.field-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-sm);
|
||||
}
|
||||
|
||||
.field-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-xs);
|
||||
padding: var(--space-xs) var(--space-sm);
|
||||
background: var(--color-surface-elevated);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.field-name {
|
||||
color: var(--color-text);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.field-type {
|
||||
color: var(--color-text-dim);
|
||||
font-size: 0.75rem;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.field-cell {
|
||||
color: var(--color-primary);
|
||||
font-size: 0.75rem;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
@@ -1,173 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Fields - {{ process.process_name }} - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to {{ process.process_name }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-header">
|
||||
<div class="header-left">
|
||||
<h1 class="page-title">Database Fields</h1>
|
||||
<p class="page-subtitle">{{ process.process_name }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Header Fields Section -->
|
||||
<div class="fields-section">
|
||||
<div class="section-header">
|
||||
<h2 class="section-title">Header Fields</h2>
|
||||
<a href="{{ url_for('cons_sheets.add_field', process_id=process.id, table_type='header') }}" class="btn btn-primary btn-sm">
|
||||
<span class="btn-icon">+</span> Add Field
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if header_fields %}
|
||||
<div class="fields-table-wrapper">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field Name</th>
|
||||
<th>Label</th>
|
||||
<th>Type</th>
|
||||
<th>Required</th>
|
||||
<th>Excel Cell</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for field in header_fields %}
|
||||
<tr>
|
||||
<td><code>{{ field.field_name }}</code></td>
|
||||
<td>{{ field.field_label }}</td>
|
||||
<td>{{ field.field_type }}</td>
|
||||
<td>{{ '✓' if field.is_required else '—' }}</td>
|
||||
<td>{{ field.excel_cell or '—' }}</td>
|
||||
<td>
|
||||
<a href="{{ url_for('cons_sheets.edit_field', process_id=process.id, field_id=field.id) }}" class="btn btn-secondary btn-sm">Edit</a>
|
||||
<button onclick="confirmDelete(this)"
|
||||
data-id="{{ field.id }}"
|
||||
data-label="{{ field.field_label }}"
|
||||
class="btn btn-sm"
|
||||
style="background: var(--color-danger); color: white;">
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state-small">
|
||||
<p>No header fields defined yet.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Detail Fields Section -->
|
||||
<div class="fields-section">
|
||||
<div class="section-header">
|
||||
<h2 class="section-title">Detail Fields</h2>
|
||||
<a href="{{ url_for('cons_sheets.add_field', process_id=process.id, table_type='detail') }}" class="btn btn-primary btn-sm">
|
||||
<span class="btn-icon">+</span> Add Field
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{% if detail_fields %}
|
||||
<div class="fields-table-wrapper">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field Name</th>
|
||||
<th>Label</th>
|
||||
<th>Type</th>
|
||||
<th>Required</th>
|
||||
<th>Excel Column</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for field in detail_fields %}
|
||||
<tr>
|
||||
<td><code>{{ field.field_name }}</code></td>
|
||||
<td>{{ field.field_label }}</td>
|
||||
<td>{{ field.field_type }}</td>
|
||||
<td>{{ '✓' if field.is_required else '—' }}</td>
|
||||
<td>{{ field.excel_cell or '—' }}</td>
|
||||
<td>
|
||||
<a href="{{ url_for('cons_sheets.edit_field', process_id=process.id, field_id=field.id) }}" class="btn btn-secondary btn-sm">Edit</a>
|
||||
<button onclick="confirmDelete(this)"
|
||||
data-id="{{ field.id }}"
|
||||
data-label="{{ field.field_label }}"
|
||||
class="btn btn-sm"
|
||||
style="background: var(--color-danger); color: white;">
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state-small">
|
||||
<p>No detail fields defined yet.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.fields-section {
|
||||
margin-top: var(--space-xl);
|
||||
padding: var(--space-lg);
|
||||
background: var(--color-surface);
|
||||
border: 2px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: var(--space-lg);
|
||||
}
|
||||
|
||||
.fields-table-wrapper {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.empty-state-small {
|
||||
text-align: center;
|
||||
padding: var(--space-xl);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
function confirmDelete(btn) {
|
||||
// Read values from data attributes
|
||||
const fieldId = btn.dataset.id;
|
||||
const fieldLabel = btn.dataset.label;
|
||||
|
||||
if (confirm('Delete field "' + fieldLabel + '"?\n\nThis will soft-delete the field (data preserved but hidden).')) {
|
||||
fetch('{{ url_for("cons_sheets.delete_field", process_id=process.id, field_id=0) }}'.replace('0', fieldId), {
|
||||
method: 'POST'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert('Error: ' + data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,293 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Excel Template - {{ process.process_name }} - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to {{ process.process_name }}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="dashboard-header">
|
||||
<div class="header-left">
|
||||
<h1 class="page-title">Excel Template</h1>
|
||||
<p class="page-subtitle">{{ process.process_name }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="template-grid">
|
||||
<!-- Upload Section -->
|
||||
<div class="config-section">
|
||||
<h2 class="section-title">Template File</h2>
|
||||
|
||||
<div class="current-template">
|
||||
{% if process.template_filename %}
|
||||
<div class="template-info">
|
||||
<span class="template-icon">📄</span>
|
||||
<span class="template-name">{{ process.template_filename }}</span>
|
||||
<a href="{{ url_for('cons_sheets.download_template', process_id=process.id) }}" class="btn btn-secondary btn-sm">Download</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="no-template">No template uploaded yet</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<form method="POST" action="{{ url_for('cons_sheets.upload_template', process_id=process.id) }}" enctype="multipart/form-data" class="upload-form">
|
||||
<div class="form-group">
|
||||
<label for="template_file" class="form-label">Upload New Template</label>
|
||||
<input type="file" id="template_file" name="template_file" accept=".xlsx" class="form-input" required>
|
||||
<p class="form-hint">Excel files (.xlsx) only</p>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Upload</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Settings Section -->
|
||||
<div class="config-section">
|
||||
<h2 class="section-title">Page Settings</h2>
|
||||
|
||||
<form method="POST" action="{{ url_for('cons_sheets.update_template_settings', process_id=process.id) }}">
|
||||
<div class="form-group">
|
||||
<label for="rows_per_page" class="form-label">Rows Per Page (Capacity)</label>
|
||||
<input type="number" id="rows_per_page" name="rows_per_page"
|
||||
value="{{ process.rows_per_page or 30 }}" min="1" max="5000" class="form-input">
|
||||
<p class="form-hint">How many items fit in the grid before we need a new page?</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label for="print_start_col" class="form-label">Print Start Column</label>
|
||||
<input type="text" id="print_start_col" name="print_start_col"
|
||||
value="{{ process.print_start_col or 'A' }}" class="form-input"
|
||||
placeholder="e.g. A" pattern="[A-Za-z]+" title="Letters only">
|
||||
<p class="form-hint">First column to print.</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label for="print_end_col" class="form-label">Print End Column</label>
|
||||
<input type="text" id="print_end_col" name="print_end_col"
|
||||
value="{{ process.print_end_col or '' }}" class="form-input"
|
||||
placeholder="e.g. K" pattern="[A-Za-z]+" title="Letters only">
|
||||
<p class="form-hint">Last column to print (defines width).</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label for="page_height" class="form-label">Page Height (Total Rows)</label>
|
||||
<input type="number" id="page_height" name="page_height"
|
||||
value="{{ process.page_height or '' }}" min="1" class="form-input">
|
||||
<p class="form-hint">The exact distance (in Excel rows) from the top of Page 1 to the top of Page 2.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="detail_start_row" class="form-label">Detail Start Row</label>
|
||||
<input type="number" id="detail_start_row" name="detail_start_row"
|
||||
value="{{ process.detail_start_row or 10 }}" min="1" max="5000" class="form-input">
|
||||
<p class="form-hint">Excel row number where detail data begins</p>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save Settings</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Field Mapping Summary -->
|
||||
<div class="mapping-section">
|
||||
<h2 class="section-title">Field Mappings</h2>
|
||||
<p class="section-desc">Excel cell mappings are configured per-field in the Database section. Here's a summary:</p>
|
||||
|
||||
{% if header_fields or detail_fields %}
|
||||
<div class="mapping-grid">
|
||||
{% if header_fields %}
|
||||
<div class="mapping-group">
|
||||
<h3 class="mapping-group-title">Header Fields</h3>
|
||||
<table class="mapping-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Excel Cell</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for field in header_fields %}
|
||||
<tr>
|
||||
<td>{{ field.field_label }}</td>
|
||||
<td>
|
||||
{% if field.excel_cell %}
|
||||
<code>{{ field.excel_cell }}</code>
|
||||
{% else %}
|
||||
<span class="not-mapped">Not mapped</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if detail_fields %}
|
||||
<div class="mapping-group">
|
||||
<h3 class="mapping-group-title">Detail Fields</h3>
|
||||
<p class="mapping-note">Columns only — rows start at {{ process.detail_start_row or 10 }}</p>
|
||||
<table class="mapping-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Excel Column</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for field in detail_fields %}
|
||||
<tr>
|
||||
<td>{{ field.field_label }}</td>
|
||||
<td>
|
||||
{% if field.excel_cell %}
|
||||
<code>{{ field.excel_cell }}</code>
|
||||
{% else %}
|
||||
<span class="not-mapped">Not mapped</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary" style="margin-top: var(--space-lg);">
|
||||
Edit Field Mappings
|
||||
</a>
|
||||
{% else %}
|
||||
<div class="empty-state-small">
|
||||
<p>No fields defined yet. <a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}">Add fields first</a>.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.template-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
gap: var(--space-xl);
|
||||
margin-top: var(--space-xl);
|
||||
}
|
||||
|
||||
.config-section {
|
||||
background: var(--color-surface);
|
||||
border: 2px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--space-xl);
|
||||
}
|
||||
|
||||
.current-template {
|
||||
margin-bottom: var(--space-lg);
|
||||
padding: var(--space-md);
|
||||
background: var(--color-surface-elevated);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.template-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-md);
|
||||
}
|
||||
|
||||
.template-icon {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.template-name {
|
||||
flex: 1;
|
||||
font-family: var(--font-mono);
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.no-template {
|
||||
color: var(--color-text-muted);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.upload-form {
|
||||
margin-top: var(--space-lg);
|
||||
padding-top: var(--space-lg);
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.mapping-section {
|
||||
margin-top: var(--space-xl);
|
||||
padding: var(--space-xl);
|
||||
background: var(--color-surface);
|
||||
border: 2px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: var(--space-lg);
|
||||
}
|
||||
|
||||
.mapping-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: var(--space-xl);
|
||||
}
|
||||
|
||||
.mapping-group-title {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
margin-bottom: var(--space-sm);
|
||||
}
|
||||
|
||||
.mapping-note {
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: var(--space-sm);
|
||||
}
|
||||
|
||||
.mapping-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.mapping-table th,
|
||||
.mapping-table td {
|
||||
padding: var(--space-sm);
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.mapping-table th {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.mapping-table code {
|
||||
background: var(--color-primary-glow);
|
||||
color: var(--color-primary);
|
||||
padding: 0.1rem 0.4rem;
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.not-mapped {
|
||||
color: var(--color-warning);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.empty-state-small {
|
||||
text-align: center;
|
||||
padding: var(--space-xl);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.empty-state-small a {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
@@ -1,455 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Scanning - {{ session.process_name }} - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="count-location-container">
|
||||
<div class="location-header">
|
||||
<div class="location-info">
|
||||
<a href="{{ url_for('cons_sheets.index') }}" class="breadcrumb">← Back to Sessions</a>
|
||||
<div class="location-label">{{ session.process_name }}</div>
|
||||
<div class="header-values">
|
||||
{% for hv in header_values %}
|
||||
<span class="header-pill"><strong>{{ hv.field_label }}:</strong> {{ hv.field_value }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="location-stats">
|
||||
<span class="stat-pill">Scanned: <span id="scanCount">{{ scans|length }}</span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if not dup_key_field %}
|
||||
<div class="alert alert-warning" style="margin: var(--space-lg) 0; padding: var(--space-lg); background: rgba(255,170,0,0.2); border-radius: var(--radius-md);">
|
||||
<strong>⚠️ No duplicate key configured!</strong><br>
|
||||
Please configure a detail field with "Use for duplicate detection" checked in the admin panel.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="scan-card scan-card-active">
|
||||
<div class="scan-header">
|
||||
<h2 class="scan-title">Scan {{ dup_key_field.field_label if dup_key_field else 'Item' }}</h2>
|
||||
</div>
|
||||
<form id="lotScanForm" class="scan-form">
|
||||
<div class="scan-input-group">
|
||||
<input type="text" name="dup_key_input" id="dupKeyInput" inputmode="none"
|
||||
class="scan-input" placeholder="Scan {{ dup_key_field.field_label if dup_key_field else 'Item' }}"
|
||||
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus
|
||||
{% if not dup_key_field %}disabled{% endif %}>
|
||||
<button type="submit" style="display: none;"></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="duplicateSameModal" class="modal">
|
||||
<div class="modal-content modal-duplicate">
|
||||
<div class="duplicate-lot-number" id="dupSameLotNumber"></div>
|
||||
<h3 class="duplicate-title" style="color: var(--color-duplicate);">Already Scanned</h3>
|
||||
<p class="duplicate-message">This was already scanned in this session.<br>Add it again?</p>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn btn-secondary btn-lg" onclick="cancelDuplicate()">No</button>
|
||||
<button type="button" class="btn btn-lg" style="background: var(--color-duplicate); color: white;" onclick="confirmDuplicate()">Yes, Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="duplicateOtherModal" class="modal">
|
||||
<div class="modal-content modal-duplicate">
|
||||
<div class="duplicate-lot-number" id="dupOtherLotNumber"></div>
|
||||
<h3 class="duplicate-title" style="color: var(--color-warning);">⚠️ Previously Consumed</h3>
|
||||
<p class="duplicate-message" id="dupOtherInfo"></p>
|
||||
<p class="duplicate-message">Are you sure you want to add it?</p>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn btn-secondary btn-lg" onclick="cancelDuplicate()">No</button>
|
||||
<button type="button" class="btn btn-lg" style="background: var(--color-warning); color: var(--color-bg);" onclick="confirmDuplicate()">Yes, Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="fieldsModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<h3 class="modal-title">Enter Details</h3>
|
||||
<div class="modal-lot-info">
|
||||
<div id="modalDupKeyValue" class="modal-lot-number"></div>
|
||||
</div>
|
||||
<form id="fieldsForm" class="weight-form">
|
||||
{% for field in detail_fields %}
|
||||
{% if not field.is_duplicate_key %}
|
||||
<div class="form-group">
|
||||
<label class="form-label">{{ field.field_label }}{% if field.is_required %}<span style="color: var(--color-danger);">*</span>{% endif %}</label>
|
||||
{% if field.field_type == 'REAL' %}
|
||||
<input type="number" id="field_{{ field.field_name }}" name="{{ field.field_name }}" class="form-input" step="0.01" inputmode="decimal" {% if field.is_required %}required{% endif %}>
|
||||
{% elif field.field_type == 'INTEGER' %}
|
||||
<input type="number" id="field_{{ field.field_name }}" name="{{ field.field_name }}" class="form-input" step="1" {% if field.is_required %}required{% endif %}>
|
||||
{% elif field.field_type == 'DATE' %}
|
||||
<input type="date" id="field_{{ field.field_name }}" name="{{ field.field_name }}" class="form-input" {% if field.is_required %}required{% endif %}>
|
||||
{% else %}
|
||||
<input type="text" id="field_{{ field.field_name }}" name="{{ field.field_name }}" class="form-input" {% if field.max_length %}maxlength="{{ field.max_length }}"{% endif %} {% if field.is_required %}required{% endif %}>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn btn-secondary" onclick="cancelFields()">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="scans-section">
|
||||
<div class="scans-header">
|
||||
<h3 class="scans-title">Scanned Items (<span id="scanListCount">{{ scans|length }}</span>)</h3>
|
||||
</div>
|
||||
<div style="margin-top: 10px;">
|
||||
<button type="button" class="btn btn-secondary btn-sm" onclick="document.getElementById('importModal').style.display='flex'">
|
||||
<i class="fa-solid fa-file-import"></i> Bulk Import Excel
|
||||
</button>
|
||||
</div>
|
||||
<div id="scansList" class="scans-grid" style="--field-count: {{ detail_fields|length }};">
|
||||
{% for scan in scans %}
|
||||
<div class="scan-row scan-row-{{ scan.duplicate_status }}"
|
||||
data-detail-id="{{ scan.id }}"
|
||||
onclick="openScanDetail(this.dataset.detailId)">
|
||||
{% for field in detail_fields %}
|
||||
<div class="scan-row-cell">{% if field.field_type == 'REAL' %}{{ '%.1f'|format(scan[field.field_name]|float) if scan[field.field_name] else '-' }}{% else %}{{ scan[field.field_name] or '-' }}{% endif %}</div>
|
||||
{% endfor %}
|
||||
<div class="scan-row-status">
|
||||
{% if scan.duplicate_status == 'dup_same_session' %}<span class="status-dot status-dot-blue"></span> Dup
|
||||
{% elif scan.duplicate_status == 'dup_other_session' %}<span class="status-dot status-dot-orange"></span> Warn
|
||||
{% else %}<span class="status-dot status-dot-green"></span> OK{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="scanDetailModal" class="modal">
|
||||
<div class="modal-content modal-large">
|
||||
<div class="modal-header-bar">
|
||||
<h3 class="modal-title">Scan Details</h3>
|
||||
<button type="button" class="btn-close-modal" onclick="closeScanDetail()">✕</button>
|
||||
</div>
|
||||
<div id="scanDetailContent" class="scan-detail-content"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="finish-section">
|
||||
<div class="action-buttons-row">
|
||||
<a href="{{ url_for('cons_sheets.index') }}" class="btn btn-secondary btn-block btn-lg">← Back to Sessions</a>
|
||||
<button class="btn btn-success btn-block btn-lg" onclick="exportToExcel()">📊 Export to Excel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="importModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header-bar">
|
||||
<h3 class="modal-title">Bulk Import Data</h3>
|
||||
<button type="button" class="btn-close-modal" onclick="document.getElementById('importModal').style.display='none'">×</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body" style="text-align: center;">
|
||||
<p style="color: var(--color-text-muted); margin-bottom: 20px;">
|
||||
Upload an Excel file (.xlsx) to automatically populate this session.
|
||||
<br><strong>Warning:</strong> This bypasses all validation checks.
|
||||
</p>
|
||||
|
||||
<div style="margin-bottom: 30px; padding: 15px; background: var(--color-bg); border-radius: 8px;">
|
||||
<p style="font-size: 0.9rem; margin-bottom: 10px;">Step 1: Get the correct format</p>
|
||||
<a href="{{ url_for('cons_sheets.download_import_template', session_id=session['id']) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-download"></i> Download Template
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<form action="{{ url_for('cons_sheets.import_session_data', session_id=session['id']) }}" method="POST" enctype="multipart/form-data">
|
||||
<div style="margin-bottom: 20px;">
|
||||
<input type="file" name="file" accept=".xlsx" class="file-input" required style="width: 100%;">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-block">
|
||||
<i class="fa-solid fa-upload"></i> Upload & Process
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.header-values { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin: var(--space-sm) 0; }
|
||||
.header-pill { background: var(--color-surface-elevated); padding: var(--space-xs) var(--space-sm); border-radius: var(--radius-sm); font-size: 0.8rem; color: var(--color-text-muted); }
|
||||
.header-pill strong { color: var(--color-text); }
|
||||
.scan-row { display: grid; grid-template-columns: repeat(var(--field-count), 1fr) auto; gap: var(--space-sm); padding: var(--space-md); background: var(--color-surface); border: 2px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: var(--space-sm); cursor: pointer; transition: var(--transition); }
|
||||
.scan-row:hover { border-color: var(--color-primary); }
|
||||
.scan-row-cell { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.scan-row-dup_same_session { border-left: 4px solid var(--color-duplicate) !important; background: rgba(0, 163, 255, 0.1) !important; }
|
||||
.scan-row-dup_other_session { border-left: 4px solid var(--color-warning) !important; background: rgba(255, 170, 0, 0.1) !important; }
|
||||
.scan-row-normal { border-left: 4px solid var(--color-success); }
|
||||
.modal-duplicate { text-align: center; padding: var(--space-xl); }
|
||||
.duplicate-lot-number { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; color: var(--color-primary); margin-bottom: var(--space-md); }
|
||||
.duplicate-title { font-size: 1.25rem; margin-bottom: var(--space-sm); }
|
||||
.duplicate-message { color: var(--color-text-muted); margin-bottom: var(--space-lg); }
|
||||
</style>
|
||||
|
||||
<script id="session-data" type="application/json">
|
||||
{
|
||||
"detailFields": {{ detail_fields|tojson|safe }},
|
||||
"dupKeyFieldName": {{ (dup_key_field.field_name if dup_key_field else '')|tojson|safe }},
|
||||
"sessionId": {{ session.id }}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// Read data from the JSON block above
|
||||
const sessionData = JSON.parse(document.getElementById('session-data').textContent);
|
||||
const detailFields = sessionData.detailFields;
|
||||
const dupKeyFieldName = sessionData.dupKeyFieldName;
|
||||
const sessionId = sessionData.sessionId;
|
||||
|
||||
// Standard variables
|
||||
let currentDupKeyValue = '';
|
||||
let currentDuplicateStatus = '';
|
||||
let isDuplicateConfirmed = false;
|
||||
let isProcessing = false;
|
||||
|
||||
document.getElementById('lotScanForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
if (isProcessing) return;
|
||||
const scannedValue = document.getElementById('dupKeyInput').value.trim();
|
||||
if (!scannedValue) return;
|
||||
isProcessing = true;
|
||||
currentDupKeyValue = scannedValue;
|
||||
document.getElementById('dupKeyInput').value = '';
|
||||
checkDuplicate();
|
||||
});
|
||||
|
||||
function checkDuplicate() {
|
||||
const fieldValues = {};
|
||||
fieldValues[dupKeyFieldName] = currentDupKeyValue;
|
||||
fetch(`/cons-sheets/session/${sessionId}/scan`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ field_values: fieldValues, check_only: true })
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.needs_confirmation) {
|
||||
currentDuplicateStatus = data.duplicate_status;
|
||||
if (data.duplicate_status === 'dup_same_session') {
|
||||
document.getElementById('dupSameLotNumber').textContent = currentDupKeyValue;
|
||||
document.getElementById('duplicateSameModal').style.display = 'flex';
|
||||
} else if (data.duplicate_status === 'dup_other_session') {
|
||||
document.getElementById('dupOtherLotNumber').textContent = currentDupKeyValue;
|
||||
document.getElementById('dupOtherInfo').textContent = data.duplicate_info;
|
||||
document.getElementById('duplicateOtherModal').style.display = 'flex';
|
||||
}
|
||||
} else {
|
||||
showFieldsModal();
|
||||
}
|
||||
})
|
||||
.catch(error => { console.error('Error:', error); showFieldsModal(); });
|
||||
}
|
||||
|
||||
function confirmDuplicate() {
|
||||
isDuplicateConfirmed = true;
|
||||
document.getElementById('duplicateSameModal').style.display = 'none';
|
||||
document.getElementById('duplicateOtherModal').style.display = 'none';
|
||||
showFieldsModal();
|
||||
}
|
||||
|
||||
function cancelDuplicate() {
|
||||
document.getElementById('duplicateSameModal').style.display = 'none';
|
||||
document.getElementById('duplicateOtherModal').style.display = 'none';
|
||||
document.getElementById('dupKeyInput').focus();
|
||||
isDuplicateConfirmed = false;
|
||||
isProcessing = false;
|
||||
currentDuplicateStatus = '';
|
||||
}
|
||||
|
||||
function showFieldsModal() {
|
||||
document.getElementById('modalDupKeyValue').textContent = currentDupKeyValue;
|
||||
document.getElementById('fieldsModal').style.display = 'flex';
|
||||
const form = document.getElementById('fieldsForm');
|
||||
form.reset();
|
||||
// Focus on first required field, or first input if none required
|
||||
const firstRequired = form.querySelector('input[required]');
|
||||
const firstInput = form.querySelector('input:not([disabled])');
|
||||
if (firstRequired) firstRequired.focus();
|
||||
else if (firstInput) firstInput.focus();
|
||||
}
|
||||
|
||||
function cancelFields() {
|
||||
document.getElementById('fieldsModal').style.display = 'none';
|
||||
document.getElementById('dupKeyInput').focus();
|
||||
isDuplicateConfirmed = false;
|
||||
isProcessing = false;
|
||||
currentDuplicateStatus = '';
|
||||
}
|
||||
|
||||
document.getElementById('fieldsForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
submitScan();
|
||||
});
|
||||
|
||||
function submitScan() {
|
||||
const fieldValues = {};
|
||||
fieldValues[dupKeyFieldName] = currentDupKeyValue;
|
||||
detailFields.forEach(field => {
|
||||
if (!field.is_duplicate_key) {
|
||||
const input = document.getElementById('field_' + field.field_name);
|
||||
if (input) fieldValues[field.field_name] = input.value;
|
||||
}
|
||||
});
|
||||
fetch(`/cons-sheets/session/${sessionId}/scan`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ field_values: fieldValues, confirm_duplicate: isDuplicateConfirmed })
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
document.getElementById('fieldsModal').style.display = 'none';
|
||||
if (data.updated_entry_ids && data.updated_entry_ids.length > 0) {
|
||||
data.updated_entry_ids.forEach(id => {
|
||||
const row = document.querySelector(`[data-detail-id="${id}"]`);
|
||||
if (row) {
|
||||
row.className = 'scan-row scan-row-dup_same_session';
|
||||
row.querySelector('.scan-row-status').innerHTML = '<span class="status-dot status-dot-blue"></span> Dup';
|
||||
}
|
||||
});
|
||||
}
|
||||
addScanToList(data.detail_id, fieldValues, data.duplicate_status);
|
||||
currentDupKeyValue = '';
|
||||
isDuplicateConfirmed = false;
|
||||
isProcessing = false;
|
||||
currentDuplicateStatus = '';
|
||||
document.getElementById('dupKeyInput').focus();
|
||||
} else {
|
||||
alert(data.message || 'Error saving scan');
|
||||
isProcessing = false;
|
||||
}
|
||||
})
|
||||
.catch(error => { console.error('Error:', error); alert('Error saving scan'); isProcessing = false; });
|
||||
}
|
||||
|
||||
function addScanToList(detailId, fieldValues, duplicateStatus) {
|
||||
const scansList = document.getElementById('scansList');
|
||||
let statusClass = duplicateStatus || 'normal';
|
||||
let statusDot = 'green', statusText = 'OK';
|
||||
if (duplicateStatus === 'dup_same_session') { statusDot = 'blue'; statusText = 'Dup'; }
|
||||
else if (duplicateStatus === 'dup_other_session') { statusDot = 'orange'; statusText = 'Warn'; }
|
||||
const scanRow = document.createElement('div');
|
||||
scanRow.className = 'scan-row scan-row-' + statusClass;
|
||||
scanRow.setAttribute('data-detail-id', detailId);
|
||||
scanRow.onclick = function() { openScanDetail(detailId); };
|
||||
let cellsHtml = '';
|
||||
detailFields.forEach(field => {
|
||||
let value = fieldValues[field.field_name] || '-';
|
||||
if (field.field_type === 'REAL' && value !== '-') value = parseFloat(value).toFixed(1);
|
||||
cellsHtml += `<div class="scan-row-cell">${value}</div>`;
|
||||
});
|
||||
cellsHtml += `<div class="scan-row-status"><span class="status-dot status-dot-${statusDot}"></span> ${statusText}</div>`;
|
||||
scanRow.innerHTML = cellsHtml;
|
||||
scansList.insertBefore(scanRow, scansList.firstChild);
|
||||
const countSpan = document.getElementById('scanListCount');
|
||||
const scanCountSpan = document.getElementById('scanCount');
|
||||
const newCount = scansList.children.length;
|
||||
if (countSpan) countSpan.textContent = newCount;
|
||||
if (scanCountSpan) scanCountSpan.textContent = newCount;
|
||||
}
|
||||
|
||||
function openScanDetail(detailId) {
|
||||
fetch(`/cons-sheets/session/${sessionId}/detail/${detailId}`)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) displayScanDetail(data.detail);
|
||||
else alert('Error loading details');
|
||||
});
|
||||
}
|
||||
|
||||
function displayScanDetail(detail) {
|
||||
const content = document.getElementById('scanDetailContent');
|
||||
let statusBadge = '<span class="badge badge-success">✓ OK</span>';
|
||||
if (detail.duplicate_status === 'dup_same_session') statusBadge = '<span class="badge badge-duplicate">🔵 Duplicate</span>';
|
||||
else if (detail.duplicate_status === 'dup_other_session') statusBadge = '<span class="badge badge-warning">🟠 Previously Consumed</span>';
|
||||
let detailRows = '';
|
||||
detailFields.forEach(field => {
|
||||
let value = detail[field.field_name] || 'N/A';
|
||||
if (field.field_type === 'REAL' && value !== 'N/A') value = parseFloat(value).toFixed(2);
|
||||
detailRows += `<div class="detail-row"><span class="detail-label">${field.field_label}:</span><span class="detail-value">${value}</span></div>`;
|
||||
});
|
||||
let editFields = '';
|
||||
detailFields.forEach(field => {
|
||||
let inputType = 'text', extraAttrs = '';
|
||||
if (field.field_type === 'REAL') { inputType = 'number'; extraAttrs = 'step="0.01"'; }
|
||||
else if (field.field_type === 'INTEGER') { inputType = 'number'; extraAttrs = 'step="1"'; }
|
||||
else if (field.field_type === 'DATE') { inputType = 'date'; }
|
||||
let value = detail[field.field_name] || '';
|
||||
editFields += `<div class="form-group"><label class="form-label">${field.field_label}</label><input type="${inputType}" id="edit_${field.field_name}" class="form-input" value="${value}" ${extraAttrs}></div>`;
|
||||
});
|
||||
content.innerHTML = `
|
||||
<div class="detail-section">${detailRows}
|
||||
<div class="detail-row"><span class="detail-label">Status:</span><span class="detail-value">${statusBadge}</span></div>
|
||||
${detail.duplicate_info ? `<div class="detail-row"><span class="detail-label">Info:</span><span class="detail-value">${detail.duplicate_info}</span></div>` : ''}
|
||||
<div class="detail-row"><span class="detail-label">Scanned:</span><span class="detail-value">${detail.scanned_at} by ${detail.scanned_by_name}</span></div>
|
||||
</div>
|
||||
<div class="detail-section"><h4 class="detail-section-title">Edit Scan</h4><div class="detail-form">${editFields}
|
||||
<div class="form-group"><label class="form-label">Comment</label><textarea id="editComment" class="form-textarea" rows="3">${detail.comment || ''}</textarea></div>
|
||||
</div></div>
|
||||
<div class="detail-actions">
|
||||
<button class="btn btn-secondary" onclick="closeScanDetail()">Cancel</button>
|
||||
<button class="btn btn-danger" onclick="deleteDetail(${detail.id})">Delete</button>
|
||||
<button class="btn btn-primary" onclick="saveDetail(${detail.id})">Save Changes</button>
|
||||
</div>`;
|
||||
document.getElementById('scanDetailModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeScanDetail() { document.getElementById('scanDetailModal').style.display = 'none'; }
|
||||
|
||||
function saveDetail(detailId) {
|
||||
const fieldValues = {};
|
||||
detailFields.forEach(field => {
|
||||
const input = document.getElementById('edit_' + field.field_name);
|
||||
if (input) fieldValues[field.field_name] = input.value;
|
||||
});
|
||||
const comment = document.getElementById('editComment').value;
|
||||
fetch(`/cons-sheets/session/${sessionId}/detail/${detailId}/update`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ field_values: fieldValues, comment: comment })
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) { closeScanDetail(); location.reload(); }
|
||||
else alert(data.message || 'Error updating');
|
||||
});
|
||||
}
|
||||
|
||||
function deleteDetail(detailId) {
|
||||
if (!confirm('Delete this scan?')) return;
|
||||
fetch(`/cons-sheets/session/${sessionId}/detail/${detailId}/delete`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) { closeScanDetail(); location.reload(); }
|
||||
else alert(data.message || 'Error deleting');
|
||||
});
|
||||
}
|
||||
|
||||
function exportToExcel() {
|
||||
window.location.href = `/cons-sheets/session/${sessionId}/export?format=xlsx`;
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
document.getElementById('fieldsModal').style.display = 'none';
|
||||
document.getElementById('duplicateSameModal').style.display = 'none';
|
||||
document.getElementById('duplicateOtherModal').style.display = 'none';
|
||||
document.getElementById('scanDetailModal').style.display = 'none';
|
||||
document.getElementById('dupKeyInput').focus();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,166 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Consumption Sheets - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<a href="{{ url_for('home') }}" class="breadcrumb">← Back to Home</a>
|
||||
<h1 class="page-title">Consumption Sheets</h1>
|
||||
<p class="page-subtitle">Scan and record lot consumption</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- New Session Button -->
|
||||
<div class="new-session-section">
|
||||
<h2 class="section-title">Start New Session</h2>
|
||||
<div class="process-buttons">
|
||||
{% for p in processes %}
|
||||
<a href="{{ url_for('cons_sheets.new_session', process_id=p.id) }}" class="btn btn-primary">
|
||||
<span class="btn-icon">+</span> {{ p.process_name }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% if not processes %}
|
||||
<p class="empty-text">No process types configured yet. Contact your administrator.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Active Sessions -->
|
||||
{% if sessions %}
|
||||
<div class="section-card">
|
||||
<h2 class="section-title">📋 My Active Sessions</h2>
|
||||
<div class="sessions-list">
|
||||
{% for s in sessions %}
|
||||
<div class="session-list-item-container">
|
||||
<a href="{{ url_for('cons_sheets.scan_session', session_id=s.id) }}" class="session-list-item">
|
||||
<div class="session-list-info">
|
||||
<h3 class="session-list-name">{{ s.process_name }}</h3>
|
||||
<div class="session-list-meta">
|
||||
<span>Started: {{ s.created_at[:16] }}</span>
|
||||
<span>•</span>
|
||||
<span>{{ s.scan_count or 0 }} lots scanned</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="session-list-action">
|
||||
<span class="arrow-icon">→</span>
|
||||
</div>
|
||||
</a>
|
||||
<button class="btn-archive" onclick="archiveSession(this)" data-id="{{ s.id }}" data-name="{{ s.process_name }}" title="Archive this session">
|
||||
🗑️
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">📝</div>
|
||||
<h2 class="empty-title">No Active Sessions</h2>
|
||||
<p class="empty-text">Start a new session by selecting a process type above</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.new-session-section {
|
||||
background: var(--color-surface);
|
||||
border: 2px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--space-xl);
|
||||
margin-bottom: var(--space-xl);
|
||||
}
|
||||
|
||||
.process-buttons {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-md);
|
||||
margin-top: var(--space-md);
|
||||
}
|
||||
|
||||
.section-card {
|
||||
margin-top: var(--space-xl);
|
||||
}
|
||||
|
||||
.session-list-item-container {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: var(--space-sm);
|
||||
margin-bottom: var(--space-sm);
|
||||
}
|
||||
|
||||
.session-list-item {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: var(--color-surface);
|
||||
border: 2px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--space-lg);
|
||||
text-decoration: none;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.session-list-item:hover {
|
||||
border-color: var(--color-primary);
|
||||
transform: translateX(4px);
|
||||
}
|
||||
|
||||
.session-list-name {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 700;
|
||||
color: var(--color-text);
|
||||
margin: 0 0 var(--space-xs) 0;
|
||||
}
|
||||
|
||||
.session-list-meta {
|
||||
display: flex;
|
||||
gap: var(--space-sm);
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.arrow-icon {
|
||||
font-size: 1.5rem;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.btn-archive {
|
||||
background: var(--color-surface);
|
||||
border: 2px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--space-md);
|
||||
cursor: pointer;
|
||||
font-size: 1.25rem;
|
||||
transition: var(--transition);
|
||||
}
|
||||
|
||||
.btn-archive:hover {
|
||||
border-color: var(--color-danger);
|
||||
background: rgba(255, 51, 102, 0.1);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
function archiveSession(sessionId, processName) {
|
||||
if (!confirm(`Archive this ${processName} session?\n\nYou can still view it later from the admin panel.`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/cons-sheets/session/${sessionId}/archive`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message || 'Error archiving session');
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,94 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Count - {{ session.session_name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="count-container">
|
||||
<div class="count-header">
|
||||
<a href="{{ url_for('admin_dashboard') }}" class="breadcrumb">← Back</a>
|
||||
<h1 class="page-title">{{ session.session_name }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="scan-card">
|
||||
<div class="scan-header">
|
||||
<h2 class="scan-title">Scan Location Barcode</h2>
|
||||
<p class="scan-subtitle">Point scanner at location label and trigger</p>
|
||||
</div>
|
||||
|
||||
<form id="locationScanForm" class="scan-form">
|
||||
<div class="scan-input-group">
|
||||
<input
|
||||
type="text"
|
||||
id="locationInput"
|
||||
class="scan-input"
|
||||
placeholder="Scan or type location code..."
|
||||
autocomplete="off"
|
||||
autofocus
|
||||
>
|
||||
<button type="submit" class="btn-scan">START</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="scan-help">
|
||||
<div class="help-item">
|
||||
<span class="help-icon">📱</span>
|
||||
<span class="help-text">Hold scanner trigger to scan barcode</span>
|
||||
</div>
|
||||
<div class="help-item">
|
||||
<span class="help-icon">⌨️</span>
|
||||
<span class="help-text">Or manually type location code</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('locationScanForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const locationCode = document.getElementById('locationInput').value.trim().toUpperCase();
|
||||
|
||||
if (!locationCode) {
|
||||
alert('Please scan or enter a location code');
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading state
|
||||
const btn = this.querySelector('.btn-scan');
|
||||
const originalText = btn.textContent;
|
||||
btn.textContent = 'LOADING...';
|
||||
btn.disabled = true;
|
||||
|
||||
fetch('{{ url_for("start_location", session_id=session.session_id) }}', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: 'location_code=' + encodeURIComponent(locationCode)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
window.location.href = data.redirect;
|
||||
} else {
|
||||
alert(data.message);
|
||||
btn.textContent = originalText;
|
||||
btn.disabled = false;
|
||||
document.getElementById('locationInput').value = '';
|
||||
document.getElementById('locationInput').focus();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error starting location count');
|
||||
console.error(error);
|
||||
btn.textContent = originalText;
|
||||
btn.disabled = false;
|
||||
});
|
||||
});
|
||||
|
||||
// Auto-uppercase input
|
||||
document.getElementById('locationInput').addEventListener('input', function(e) {
|
||||
this.value = this.value.toUpperCase();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,102 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Inventory Counts - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="dashboard-header">
|
||||
<div class="header-left">
|
||||
<a href="{{ url_for('admin_dashboard') }}" class="btn btn-secondary btn-sm" style="margin-right: var(--space-md);">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Admin
|
||||
</a>
|
||||
<div>
|
||||
<h1 class="page-title">Inventory Counts</h1>
|
||||
<p class="page-subtitle">Manage cycle counts and physical inventory</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<label class="filter-toggle" style="margin-right: var(--space-lg);">
|
||||
<input type="checkbox" id="showArchived" {% if show_archived %}checked{% endif %} onchange="toggleArchived()">
|
||||
<span class="filter-label">Show Archived</span>
|
||||
</label>
|
||||
<a href="{{ url_for('sessions.create_session') }}" class="btn btn-primary">
|
||||
<span class="btn-icon">+</span> New Session
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if sessions %}
|
||||
<div class="sessions-grid">
|
||||
{% for session in sessions %}
|
||||
<div class="session-card {% if session.status == 'archived' %}session-archived{% endif %}">
|
||||
<div class="session-card-header">
|
||||
<h3 class="session-name">
|
||||
{{ session.session_name }}
|
||||
{% if session.status == 'archived' %}<span class="archived-badge">ARCHIVED</span>{% endif %}
|
||||
</h3>
|
||||
<span class="session-type-badge session-type-{{ session.session_type }}">
|
||||
{{ 'Full Physical' if session.session_type == 'full_physical' else 'Cycle Count' }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="session-stats">
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ session.total_locations or 0 }}</div>
|
||||
<div class="stat-label">Total Locations</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ session.completed_locations or 0 }}</div>
|
||||
<div class="stat-label">Completed</div>
|
||||
</div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ session.in_progress_locations or 0 }}</div>
|
||||
<div class="stat-label">In Progress</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="session-meta">
|
||||
<div class="meta-item">
|
||||
<span class="meta-label">Created:</span>
|
||||
<span class="meta-value">{{ session.created_timestamp[:16] }}</span>
|
||||
</div>
|
||||
<div class="meta-item">
|
||||
<span class="meta-label">By:</span>
|
||||
<span class="meta-value">{{ session.created_by_name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="session-actions">
|
||||
<a href="{{ url_for('sessions.session_detail', session_id=session.session_id) }}" class="btn btn-secondary btn-block">
|
||||
View Details
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">📋</div>
|
||||
<h2 class="empty-title">No Active Sessions</h2>
|
||||
<p class="empty-text">Create a new count session to get started</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleArchived() {
|
||||
const checked = document.getElementById('showArchived').checked;
|
||||
window.location.href = '{{ url_for("counting.admin_dashboard") }}' + (checked ? '?show_archived=1' : '');
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.dashboard-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: var(--space-xl);
|
||||
}
|
||||
.header-left { display: flex; align-items: center; }
|
||||
.header-right { display: flex; align-items: center; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
@@ -1,607 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Counting {{ location.location_name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="count-location-container">
|
||||
<div class="location-header">
|
||||
<div class="location-info">
|
||||
<div class="location-label">Counting Location</div>
|
||||
<h1 class="location-name">{{ location.location_name }}</h1>
|
||||
<div class="location-stats">
|
||||
<span class="stat-pill">Expected: {{ location.expected_lots_master }}</span>
|
||||
<span class="stat-pill">Found: <span id="foundCount">{{ location.lots_found }}</span></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="scan-card scan-card-active">
|
||||
<div class="scan-header">
|
||||
<h2 class="scan-title">Scan Lot Barcode</h2>
|
||||
</div>
|
||||
|
||||
<form id="lotScanForm" class="scan-form">
|
||||
<div class="scan-input-group">
|
||||
<input type="text"
|
||||
name="lot_number"
|
||||
id="lotInput"
|
||||
inputmode="none"
|
||||
class="scan-input"
|
||||
placeholder="Scan Lot Number"
|
||||
autocomplete="off"
|
||||
autocorrect="off"
|
||||
autocapitalize="off"
|
||||
spellcheck="false"
|
||||
autofocus>
|
||||
<button type="submit" style="display: none;" aria-hidden="true"></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="duplicateModal" class="modal">
|
||||
<div class="modal-content modal-duplicate">
|
||||
<div class="duplicate-lot-number" id="duplicateLotNumber"></div>
|
||||
<h3 class="duplicate-title">Already Scanned</h3>
|
||||
<p class="duplicate-message">Do you wish to Resubmit?</p>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn btn-secondary btn-lg" onclick="cancelDuplicate()">No</button>
|
||||
<button type="button" class="btn btn-primary btn-lg" onclick="confirmDuplicate()">Yes</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="weightModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<h3 class="modal-title">Enter Weight</h3>
|
||||
<div class="modal-lot-info">
|
||||
<div id="modalLotNumber" class="modal-lot-number"></div>
|
||||
<div id="modalItemDesc" class="modal-item-desc"></div>
|
||||
</div>
|
||||
<form id="weightForm" class="weight-form">
|
||||
<input
|
||||
type="number"
|
||||
id="weightInput"
|
||||
class="weight-input"
|
||||
placeholder="0.0"
|
||||
step="0.01"
|
||||
min="0"
|
||||
inputmode="decimal"
|
||||
autocomplete="off"
|
||||
autocorrect="off"
|
||||
spellcheck="false"
|
||||
required
|
||||
>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn btn-secondary" onclick="cancelWeight()">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="scans-section">
|
||||
<div class="scans-header">
|
||||
<h3 class="scans-title">Scanned Lots (<span id="scanListCount">{{ scans|length }}</span>)</h3>
|
||||
</div>
|
||||
|
||||
<div id="scansList" class="scans-grid">
|
||||
{% for scan in scans %}
|
||||
|
||||
{# LOGIC FIX: Determine CSS class based on weight difference #}
|
||||
{% set row_class = scan.master_status %}
|
||||
|
||||
{% if scan.duplicate_status and scan.duplicate_status != '00' %}
|
||||
{% set row_class = 'duplicate-' + scan.duplicate_status %}
|
||||
{% elif scan.master_status == 'match' and scan.master_expected_weight and (scan.actual_weight - scan.master_expected_weight)|abs >= 0.01 %}
|
||||
{# If it is a match but weight is off, force class to weight_discrepancy #}
|
||||
{% set row_class = 'weight_discrepancy' %}
|
||||
{% endif %}
|
||||
|
||||
<div class="scan-row scan-row-{{ row_class }}"
|
||||
data-entry-id="{{ scan.entry_id }}"
|
||||
onclick="openScanDetail('{{ scan.entry_id }}')">
|
||||
<div class="scan-row-lot">{{ scan.lot_number }}</div>
|
||||
<div class="scan-row-item">{{ scan.item or 'N/A' }}</div>
|
||||
<div class="scan-row-weight">{{ '%.1f'|format(scan.actual_weight) if scan.actual_weight is not none else '-' }} lbs</div>
|
||||
<div class="scan-row-status">
|
||||
{% if scan.duplicate_status == '01' or scan.duplicate_status == '04' %}
|
||||
<span class="status-dot status-dot-blue"></span> Duplicate
|
||||
{% elif scan.duplicate_status == '03' %}
|
||||
<span class="status-dot status-dot-orange"></span> Dup (Other Loc)
|
||||
{% elif row_class == 'weight_discrepancy' %}
|
||||
<span class="status-dot status-dot-orange"></span> Weight Off
|
||||
{% elif scan.master_status == 'match' %}
|
||||
<span class="status-dot status-dot-green"></span> Match
|
||||
{% elif scan.master_status == 'wrong_location' %}
|
||||
<span class="status-dot status-dot-yellow"></span> Wrong Loc
|
||||
{% elif scan.master_status == 'ghost_lot' %}
|
||||
<span class="status-dot status-dot-purple"></span> Ghost
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if session_type == 'cycle_count' and expected_lots %}
|
||||
<div class="expected-section" id="expectedSection">
|
||||
<div class="scans-header">
|
||||
<h3 class="scans-title expected-title">Expected Items (<span id="expectedCount">{{ expected_lots|length }}</span>)</h3>
|
||||
</div>
|
||||
<div class="scans-grid" id="expectedList">
|
||||
{% for lot in expected_lots %}
|
||||
<div class="scan-row expected-row"
|
||||
id="expected-{{ lot.lot_number }}"
|
||||
onclick="scanExpectedLot('{{ lot.lot_number }}')">
|
||||
<div class="scan-row-lot">{{ lot.lot_number }}</div>
|
||||
<div class="scan-row-item">{{ lot.item }}</div>
|
||||
<div class="scan-row-weight">{{ lot.total_weight }} lbs</div>
|
||||
<div class="scan-row-status">
|
||||
<span class="status-dot status-dot-gray"></span> Pending
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div id="scanDetailModal" class="modal">
|
||||
<div class="modal-content modal-large">
|
||||
<div class="modal-header-bar">
|
||||
<h3 class="modal-title">Scan Details</h3>
|
||||
<button type="button" class="btn-close-modal" onclick="closeScanDetail()">✕</button>
|
||||
</div>
|
||||
|
||||
<div id="scanDetailContent" class="scan-detail-content">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="finish-section">
|
||||
<div class="action-buttons-row">
|
||||
<a href="{{ url_for('counting.my_counts', session_id=session_id) }}" class="btn btn-secondary btn-block btn-lg">
|
||||
← Back to My Counts
|
||||
</a>
|
||||
{# Finish button moved to Admin Dashboard #}
|
||||
</div>
|
||||
</div>
|
||||
<button class="scroll-to-top" onclick="window.scrollTo({top: 0, behavior: 'smooth'})">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="18 15 12 9 6 15"></polyline>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="scroll-to-bottom" onclick="window.scrollTo({top: document.body.scrollHeight, behavior: 'smooth'})">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
|
||||
<polyline points="6 9 12 15 18 9"></polyline>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentLotNumber = '';
|
||||
let isDuplicateConfirmed = false;
|
||||
let isProcessing = false;
|
||||
|
||||
function parseWeight(value) {
|
||||
const num = Number(value);
|
||||
return Number.isFinite(num) ? num : null;
|
||||
}
|
||||
|
||||
function formatWeight(value) {
|
||||
const num = parseWeight(value);
|
||||
return num === null ? '-' : num.toFixed(1);
|
||||
}
|
||||
|
||||
function weightsDiffer(actual, expected) {
|
||||
const actualNum = parseWeight(actual);
|
||||
const expectedNum = parseWeight(expected);
|
||||
if (actualNum === null || expectedNum === null) return false;
|
||||
return Math.abs(actualNum - expectedNum) >= 0.01;
|
||||
}
|
||||
|
||||
// Lot scan handler
|
||||
document.getElementById('lotScanForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
if (isProcessing) return;
|
||||
|
||||
const scannedValue = document.getElementById('lotInput').value.trim();
|
||||
if (!scannedValue) return;
|
||||
|
||||
isProcessing = true;
|
||||
currentLotNumber = scannedValue;
|
||||
document.getElementById('lotInput').value = '';
|
||||
|
||||
checkDuplicate();
|
||||
});
|
||||
|
||||
function checkDuplicate() {
|
||||
fetch('{{ url_for("counting.scan_lot", session_id=session_id, location_count_id=location.location_count_id) }}', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
lot_number: currentLotNumber,
|
||||
weight: 0,
|
||||
check_only: true
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.needs_confirmation) {
|
||||
document.getElementById('duplicateLotNumber').textContent = currentLotNumber;
|
||||
document.getElementById('duplicateModal').style.display = 'flex';
|
||||
} else {
|
||||
showWeightModal();
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error checking duplicate:', error);
|
||||
showWeightModal();
|
||||
});
|
||||
}
|
||||
|
||||
function confirmDuplicate() {
|
||||
isDuplicateConfirmed = true;
|
||||
document.getElementById('duplicateModal').style.display = 'none';
|
||||
showWeightModal();
|
||||
}
|
||||
|
||||
function cancelDuplicate() {
|
||||
document.getElementById('duplicateModal').style.display = 'none';
|
||||
document.getElementById('lotInput').focus();
|
||||
isDuplicateConfirmed = false;
|
||||
isProcessing = false;
|
||||
}
|
||||
|
||||
function showWeightModal() {
|
||||
if (!currentLotNumber) {
|
||||
alert('Error: Lot number lost. Please scan again.');
|
||||
document.getElementById('lotInput').focus();
|
||||
return;
|
||||
}
|
||||
document.getElementById('modalLotNumber').textContent = currentLotNumber;
|
||||
document.getElementById('modalItemDesc').textContent = 'Loading...';
|
||||
document.getElementById('weightModal').style.display = 'flex';
|
||||
document.getElementById('weightInput').value = '';
|
||||
document.getElementById('weightInput').focus();
|
||||
}
|
||||
|
||||
// Weight form handler
|
||||
document.getElementById('weightForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const weight = document.getElementById('weightInput').value;
|
||||
if (!weight || weight <= 0) {
|
||||
alert('Please enter a valid weight');
|
||||
return;
|
||||
}
|
||||
submitScan(weight);
|
||||
});
|
||||
|
||||
function submitScan(weight) {
|
||||
if (!currentLotNumber) {
|
||||
alert('Error: Lot number lost. Please scan again.');
|
||||
document.getElementById('weightModal').style.display = 'none';
|
||||
document.getElementById('lotInput').focus();
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('{{ url_for("counting.scan_lot", session_id=session_id, location_count_id=location.location_count_id) }}', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
lot_number: currentLotNumber.trim(),
|
||||
weight: parseFloat(weight),
|
||||
confirm_duplicate: isDuplicateConfirmed
|
||||
})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
document.getElementById('weightModal').style.display = 'none';
|
||||
isDuplicateConfirmed = false;
|
||||
|
||||
if (data.updated_entry_ids && data.updated_entry_ids.length > 0) {
|
||||
updateExistingScansStatus(data.updated_entry_ids, data.duplicate_status);
|
||||
}
|
||||
|
||||
addScanToList(data, weight);
|
||||
|
||||
// NEW: Instacart Logic - Remove from Expected List if it exists
|
||||
const expectedRow = document.getElementById('expected-' + currentLotNumber);
|
||||
if (expectedRow) {
|
||||
expectedRow.remove();
|
||||
|
||||
// Update Expected count
|
||||
const countSpan = document.getElementById('expectedCount');
|
||||
if (countSpan) {
|
||||
let currentCount = parseInt(countSpan.textContent);
|
||||
if (currentCount > 0) {
|
||||
countSpan.textContent = currentCount - 1;
|
||||
}
|
||||
// Hide section if empty
|
||||
if (currentCount - 1 <= 0) {
|
||||
const section = document.getElementById('expectedSection');
|
||||
if (section) section.style.display = 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentLotNumber = '';
|
||||
isProcessing = false;
|
||||
document.getElementById('lotInput').focus();
|
||||
} else {
|
||||
alert(data.message || 'Error saving scan');
|
||||
isProcessing = false;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error saving scan');
|
||||
console.error(error);
|
||||
isProcessing = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Function to handle clicking an Expected Lot
|
||||
function scanExpectedLot(lotNumber) {
|
||||
if (isProcessing) return;
|
||||
|
||||
// Set the lot number as if it was scanned
|
||||
currentLotNumber = lotNumber;
|
||||
|
||||
// Visual feedback (optional, but nice)
|
||||
console.log('Clicked expected lot:', lotNumber);
|
||||
|
||||
// Proceed to check logic (just like a normal scan)
|
||||
// We go through checkDuplicate just in case, consistency is safer
|
||||
checkDuplicate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function cancelWeight() {
|
||||
document.getElementById('weightModal').style.display = 'none';
|
||||
document.getElementById('lotInput').focus();
|
||||
isDuplicateConfirmed = false;
|
||||
isProcessing = false;
|
||||
}
|
||||
|
||||
function updateExistingScansStatus(entryIds, duplicateStatus) {
|
||||
entryIds.forEach(entryId => {
|
||||
const scanRow = document.querySelector(`[data-entry-id="${entryId}"]`);
|
||||
if (scanRow) {
|
||||
const statusElement = scanRow.querySelector('.scan-row-status');
|
||||
if (statusElement) {
|
||||
let statusText = 'Duplicate';
|
||||
let statusDot = 'blue';
|
||||
if (duplicateStatus === '03') {
|
||||
statusText = 'Dup (Other Loc)';
|
||||
statusDot = 'orange';
|
||||
}
|
||||
statusElement.innerHTML = `<span class="status-dot status-dot-${statusDot}"></span> ${statusText}`;
|
||||
}
|
||||
scanRow.className = 'scan-row scan-row-duplicate-' + duplicateStatus;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addScanToList(data, weight) {
|
||||
const scansList = document.getElementById('scansList');
|
||||
|
||||
let statusClass = '';
|
||||
let statusText = '';
|
||||
let statusDot = '';
|
||||
|
||||
if (data.duplicate_status && data.duplicate_status !== '00') {
|
||||
statusClass = 'duplicate-' + data.duplicate_status;
|
||||
if (data.duplicate_status === '01' || data.duplicate_status === '04') {
|
||||
statusText = 'Duplicate';
|
||||
statusDot = 'blue';
|
||||
} else if (data.duplicate_status === '03') {
|
||||
statusText = 'Dup (Other Loc)';
|
||||
statusDot = 'orange';
|
||||
}
|
||||
} else if (data.master_status === 'match') {
|
||||
if (data.master_expected_weight && weightsDiffer(weight, data.master_expected_weight)) {
|
||||
statusClass = 'weight_discrepancy';
|
||||
statusText = 'Weight Off';
|
||||
statusDot = 'orange';
|
||||
} else {
|
||||
statusClass = 'match';
|
||||
statusText = 'Match';
|
||||
statusDot = 'green';
|
||||
}
|
||||
} else if (data.master_status === 'wrong_location') {
|
||||
statusClass = 'wrong_location';
|
||||
statusText = 'Wrong Loc';
|
||||
statusDot = 'yellow';
|
||||
} else if (data.master_status === 'ghost_lot') {
|
||||
statusClass = 'ghost_lot';
|
||||
statusText = 'Ghost';
|
||||
statusDot = 'purple';
|
||||
}
|
||||
|
||||
const scanRow = document.createElement('div');
|
||||
scanRow.className = 'scan-row scan-row-' + statusClass;
|
||||
scanRow.setAttribute('data-entry-id', data.entry_id);
|
||||
scanRow.onclick = function() { openScanDetail(data.entry_id); };
|
||||
scanRow.innerHTML = `
|
||||
<div class="scan-row-lot">${currentLotNumber}</div>
|
||||
<div class="scan-row-item">${data.item || 'N/A'}</div>
|
||||
<div class="scan-row-weight">${formatWeight(weight)} lbs</div>
|
||||
<div class="scan-row-status">
|
||||
<span class="status-dot status-dot-${statusDot}"></span> ${statusText}
|
||||
</div>
|
||||
`;
|
||||
|
||||
scansList.insertBefore(scanRow, scansList.firstChild);
|
||||
|
||||
// Update Scanned Lots count
|
||||
const countSpan = document.getElementById('scanListCount');
|
||||
if (countSpan) {
|
||||
countSpan.textContent = scansList.children.length;
|
||||
}
|
||||
|
||||
// Update Header Found Count
|
||||
const foundStat = document.getElementById('foundCount');
|
||||
if (foundStat) {
|
||||
foundStat.textContent = scansList.children.length;
|
||||
}
|
||||
}
|
||||
|
||||
function openScanDetail(entryId) {
|
||||
fetch('/scan/' + entryId + '/details').then(r => r.json()).then(data => {
|
||||
if (data.success) displayScanDetail(data.scan);
|
||||
else alert('Error loading scan details');
|
||||
});
|
||||
}
|
||||
|
||||
function displayScanDetail(scan) {
|
||||
const content = document.getElementById('scanDetailContent');
|
||||
|
||||
// LOGIC FIX: Check weight variance for the badge
|
||||
let statusBadge = '';
|
||||
|
||||
// Check for weight discrepancy (Tolerance 0.01)
|
||||
let isWeightOff = false;
|
||||
if (scan.master_status === 'match' && scan.master_expected_weight) {
|
||||
if (weightsDiffer(scan.actual_weight, scan.master_expected_weight)) {
|
||||
isWeightOff = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (scan.duplicate_status === '01' || scan.duplicate_status === '04') {
|
||||
statusBadge = '<span class="badge badge-duplicate">🔵 Duplicate</span>';
|
||||
} else if (scan.duplicate_status === '03') {
|
||||
statusBadge = '<span class="badge badge-orange">🟠 Duplicate (Other Location)</span>';
|
||||
} else if (isWeightOff) {
|
||||
// NEW BADGE FOR WEIGHT OFF
|
||||
statusBadge = '<span class="badge badge-warning">🟠 Weight Discrepancy</span>';
|
||||
} else if (scan.master_status === 'match') {
|
||||
statusBadge = '<span class="badge badge-success">✓ Match</span>';
|
||||
} else if (scan.master_status === 'wrong_location') {
|
||||
statusBadge = '<span class="badge badge-warning">⚠ Wrong Location</span>';
|
||||
} else if (scan.master_status === 'ghost_lot') {
|
||||
statusBadge = '<span class="badge badge-purple">🟣 Ghost Lot</span>';
|
||||
}
|
||||
|
||||
// ... (rest of the function continues as normal)
|
||||
|
||||
content.innerHTML = `
|
||||
<div class="detail-section">
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Lot Number:</span>
|
||||
<span class="detail-value detail-lot">${scan.lot_number}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Description:</span>
|
||||
<span class="detail-value">${scan.description || 'N/A'}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Status:</span>
|
||||
<span class="detail-value">${statusBadge}</span>
|
||||
</div>
|
||||
${scan.duplicate_info ? `<div class="detail-row"><span class="detail-label">Info:</span><span class="detail-value detail-info">${scan.duplicate_info}</span></div>` : ''}
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Scanned:</span>
|
||||
<span class="detail-value">${scan.scan_timestamp}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="detail-section">
|
||||
<h4 class="detail-section-title">Edit Scan</h4>
|
||||
<div class="detail-form">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Item Number</label>
|
||||
<input type="text" id="editItem" class="form-input" value="${scan.item || ''}" placeholder="Item/SKU">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Weight (lbs)</label>
|
||||
<input type="number" id="editWeight" class="form-input" value="${formatWeight(scan.actual_weight)}" step="0.01" min="0" inputmode="decimal">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Comment</label>
|
||||
<textarea id="editComment" class="form-textarea" rows="3" placeholder="Add a comment...">${scan.comment || ''}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="detail-actions">
|
||||
<button class="btn btn-secondary" onclick="closeScanDetail()">Cancel</button>
|
||||
<button class="btn btn-danger" onclick="deleteFromDetail(${scan.entry_id})">Delete</button>
|
||||
<button class="btn btn-primary" onclick="saveScanEdit(${scan.entry_id})">Save Changes</button>
|
||||
</div>
|
||||
`;
|
||||
document.getElementById('scanDetailModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeScanDetail() {
|
||||
document.getElementById('scanDetailModal').style.display = 'none';
|
||||
}
|
||||
|
||||
function saveScanEdit(entryId) {
|
||||
const item = document.getElementById('editItem').value.trim();
|
||||
const weight = document.getElementById('editWeight').value;
|
||||
const comment = document.getElementById('editComment').value;
|
||||
|
||||
if (!weight || weight <= 0) {
|
||||
alert('Please enter a valid weight');
|
||||
return;
|
||||
}
|
||||
|
||||
fetch('/scan/' + entryId + '/update', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ item: item, weight: parseFloat(weight), comment: comment })
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
closeScanDetail();
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message || 'Error updating scan');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteFromDetail(entryId) {
|
||||
if (!confirm('Delete this scan?')) return;
|
||||
|
||||
fetch('/scan/' + entryId + '/delete', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
closeScanDetail();
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function finishLocation() {
|
||||
if (!confirm('Are you finished counting this location?')) return;
|
||||
|
||||
fetch('{{ url_for("counting.finish_location", session_id=session_id, location_count_id=location.location_count_id) }}', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) window.location.href = data.redirect;
|
||||
else alert('Error finishing location');
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
document.getElementById('weightModal').style.display = 'none';
|
||||
document.getElementById('duplicateModal').style.display = 'none';
|
||||
document.getElementById('lotInput').focus();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,43 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Create Session - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="form-container">
|
||||
<div class="form-card">
|
||||
<div class="form-header">
|
||||
<h1 class="form-title">Create New Count Session</h1>
|
||||
</div>
|
||||
|
||||
<form method="POST" class="standard-form">
|
||||
<div class="form-group">
|
||||
<label for="session_name" class="form-label">Session Name *</label>
|
||||
<input
|
||||
type="text"
|
||||
id="session_name"
|
||||
name="session_name"
|
||||
class="form-input"
|
||||
placeholder="e.g., January 17, 2026 - Daily Cycle Count"
|
||||
required
|
||||
autofocus
|
||||
>
|
||||
<small class="form-help">Descriptive name for this count session</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="session_type" class="form-label">Session Type *</label>
|
||||
<select id="session_type" name="session_type" class="form-select" required>
|
||||
<option value="cycle_count">Cycle Count</option>
|
||||
<option value="full_physical">Full Physical Inventory</option>
|
||||
</select>
|
||||
<small class="form-help">Choose the type of inventory count</small>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('admin_dashboard') }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Create Session</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,194 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}My Counts - {{ count_session.session_name }} - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<a href="{{ url_for('counting.index') }}" class="breadcrumb">← Back to Sessions</a>
|
||||
<h1 class="page-title">My Active Counts</h1>
|
||||
<p class="page-subtitle">{{ count_session.session_name }}</p>
|
||||
{% if not count_session.master_baseline_timestamp %}
|
||||
<p class="page-subtitle">Master File not uploaded yet. Please contact an admin before starting bins.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if count_session.master_baseline_timestamp %}
|
||||
<button class="btn btn-primary" onclick="showStartBinModal()">
|
||||
<span class="btn-icon">+</span> Start New Bin
|
||||
</button>
|
||||
{% else %}
|
||||
<button class="btn btn-primary" disabled title="Upload a Master File to start bins">
|
||||
<span class="btn-icon">+</span> Start New Bin
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Active Bins -->
|
||||
{% if active_bins %}
|
||||
<div class="section-card">
|
||||
<h2 class="section-title">🔄 Active Bins (In Progress)</h2>
|
||||
<div class="bins-grid">
|
||||
{% for bin in active_bins %}
|
||||
<div class="bin-card bin-active">
|
||||
<div class="bin-header">
|
||||
<h3 class="bin-name">{{ bin.location_name }}</h3>
|
||||
<span class="bin-status status-progress">In Progress</span>
|
||||
</div>
|
||||
<div class="bin-stats">
|
||||
<div class="bin-stat">
|
||||
<span class="stat-label">Scanned:</span>
|
||||
<span class="stat-value">{{ bin.scan_count or 0 }}</span>
|
||||
</div>
|
||||
<div class="bin-stat">
|
||||
<span class="stat-label">Started:</span>
|
||||
<span class="stat-value">{{ bin.start_timestamp[11:16] if bin.start_timestamp else '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bin-actions">
|
||||
<a href="{{ url_for('counting.count_location', session_id=count_session.session_id, location_count_id=bin.location_count_id) }}" class="btn btn-primary btn-block">
|
||||
Resume Counting
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Completed Bins -->
|
||||
{% if completed_bins %}
|
||||
<div class="section-card">
|
||||
<h2 class="section-title">✅ Completed Bins</h2>
|
||||
<div class="bins-grid">
|
||||
{% for bin in completed_bins %}
|
||||
<div class="bin-card bin-completed">
|
||||
<div class="bin-header">
|
||||
<h3 class="bin-name">{{ bin.location_name }}</h3>
|
||||
<span class="bin-status status-success">Completed</span>
|
||||
</div>
|
||||
<div class="bin-stats">
|
||||
<div class="bin-stat">
|
||||
<span class="stat-label">Scanned:</span>
|
||||
<span class="stat-value">{{ bin.scan_count or 0 }}</span>
|
||||
</div>
|
||||
<div class="bin-stat">
|
||||
<span class="stat-label">Completed:</span>
|
||||
<span class="stat-value">{{ bin.end_timestamp[11:16] if bin.end_timestamp else '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bin-actions">
|
||||
<button class="btn btn-secondary btn-block" disabled title="This bin has been finalized">
|
||||
🔒 Finalized (Read-Only)
|
||||
</button>
|
||||
<p class="bin-note">Contact an admin to view details</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if not active_bins and not completed_bins %}
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">📦</div>
|
||||
<h2 class="empty-title">No Bins Started Yet</h2>
|
||||
<p class="empty-text">Click "Start New Bin" to begin counting</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Start New Bin Modal -->
|
||||
<div id="startBinModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header-bar">
|
||||
<h3 class="modal-title">Start New Bin</h3>
|
||||
<button type="button" class="btn-close-modal" onclick="closeStartBinModal()">✕</button>
|
||||
</div>
|
||||
|
||||
<form id="startBinForm" action="{{ url_for('counting.start_bin_count', session_id=count_session.session_id) }}" method="POST">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Bin Number *</label>
|
||||
<input type="text" name="location_name" class="form-input scan-input" required autofocus placeholder="Scan or type bin number">
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn btn-secondary" onclick="closeStartBinModal()">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">Start Counting</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function showStartBinModal() {
|
||||
document.getElementById('startBinModal').style.display = 'flex';
|
||||
document.querySelector('#startBinForm input[name="location_name"]').focus();
|
||||
}
|
||||
|
||||
function closeStartBinModal() {
|
||||
document.getElementById('startBinModal').style.display = 'none';
|
||||
document.getElementById('startBinForm').reset();
|
||||
}
|
||||
|
||||
function markComplete(locationCountId) {
|
||||
if (!confirm('Mark this bin as complete? You can still view it later.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/location/${locationCountId}/complete`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message || 'Error marking bin as complete');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error: ' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
function deleteBinCount(locationCountId, binName) {
|
||||
if (!confirm(`Delete ALL counts for bin "${binName}"?\n\nThis will remove all scanned entries for this bin. This action cannot be undone.`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Double confirmation for safety
|
||||
if (!confirm('Are you absolutely sure? All data for this bin will be lost.')) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/location/${locationCountId}/delete`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message || 'Error deleting bin count');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error: ' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
// Close modal on escape
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
closeStartBinModal();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,12 +0,0 @@
|
||||
<div class="counter-list">
|
||||
{% for counter in active_counters %}
|
||||
<div class="counter-item">
|
||||
<div class="counter-avatar">{{ counter.full_name[0] }}</div>
|
||||
<div class="counter-info">
|
||||
<div class="counter-name">{{ counter.full_name }}</div>
|
||||
<div class="counter-location">📍 {{ counter.location_name }}</div>
|
||||
</div>
|
||||
<div class="counter-time">{{ counter.start_timestamp[11:16] }}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
@@ -1,807 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}{{ count_session.session_name }} - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="session-detail-container">
|
||||
<div class="session-detail-header">
|
||||
<div>
|
||||
<a href="{{ url_for('admin_dashboard') }}{% if count_session.status == 'archived' %}?show_archived=1{% endif %}" class="breadcrumb">← Back to Dashboard</a>
|
||||
<h1 class="page-title">
|
||||
{{ count_session.session_name }}
|
||||
{% if count_session.status == 'archived' %}<span class="archived-badge">ARCHIVED</span>{% endif %}
|
||||
</h1>
|
||||
<span class="session-type-badge session-type-{{ count_session.session_type }}">
|
||||
{{ 'Full Physical' if count_session.session_type == 'full_physical' else 'Cycle Count' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="session-actions-header">
|
||||
{% if count_session.status == 'archived' %}
|
||||
<button class="btn btn-success" onclick="activateSession()">✓ Activate Session</button>
|
||||
{% else %}
|
||||
<button class="btn btn-secondary" onclick="archiveSession()">📦 Archive Session</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Baseline Upload Section -->
|
||||
<div class="section-card">
|
||||
<h2 class="section-title">Baseline Data</h2>
|
||||
|
||||
<div class="baseline-grid">
|
||||
<div class="baseline-item">
|
||||
<div class="baseline-label">MASTER Baseline</div>
|
||||
<div class="baseline-status">
|
||||
{% if count_session.master_baseline_timestamp %}
|
||||
<span class="status-badge status-success">✓ Uploaded</span>
|
||||
<small class="baseline-time">{{ count_session.master_baseline_timestamp[:16] }}</small>
|
||||
{% else %}
|
||||
<span class="status-badge status-warning">⚠ Not Uploaded</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if not count_session.master_baseline_timestamp %}
|
||||
<!-- Note: Using data_imports blueprint URL -->
|
||||
<form method="POST" action="{{ url_for('data_imports.upload_master', session_id=count_session.session_id) }}" enctype="multipart/form-data" class="upload-form">
|
||||
<input type="file" name="csv_file" accept=".csv" required class="file-input">
|
||||
<button type="submit" class="btn btn-primary btn-sm">Upload MASTER</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="baseline-item">
|
||||
<div class="baseline-label">CURRENT Baseline (Optional)</div>
|
||||
<div class="baseline-status">
|
||||
{% if count_session.current_baseline_timestamp %}
|
||||
<span class="status-badge status-success">✓ Uploaded</span>
|
||||
<small class="baseline-time">{{ count_session.current_baseline_timestamp[:16] }}</small>
|
||||
{% else %}
|
||||
<span class="status-badge status-neutral">Not Uploaded</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if count_session.master_baseline_timestamp %}
|
||||
<form method="POST" action="{{ url_for('data_imports.upload_current', session_id=count_session.session_id) }}" enctype="multipart/form-data" class="upload-form">
|
||||
<input type="hidden" name="baseline_type" value="current">
|
||||
<input type="file" name="csv_file" accept=".csv" required class="file-input">
|
||||
<button type="submit" class="btn btn-secondary btn-sm">
|
||||
{{ 'Refresh CURRENT' if count_session.current_baseline_timestamp else 'Upload CURRENT' }}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Statistics Section -->
|
||||
<div class="section-card">
|
||||
<h2 class="section-title">Real-Time Statistics</h2>
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card stat-match" onclick="showStatusDetails('match')">
|
||||
<div class="stat-number" id="count-matched">{{ stats.matched or 0 }}</div>
|
||||
<div class="stat-label">✓ Matched</div>
|
||||
</div>
|
||||
<div class="stat-card stat-duplicate" onclick="showStatusDetails('duplicates')">
|
||||
<div class="stat-number" id="count-duplicates">{{ stats.duplicates or 0 }}</div>
|
||||
<div class="stat-label">🔵 Duplicates</div>
|
||||
</div>
|
||||
<div class="stat-card stat-weight-disc" onclick="showStatusDetails('weight_discrepancy')">
|
||||
<div class="stat-number" id="count-discrepancy">{{ stats.weight_discrepancy or 0 }}</div>
|
||||
<div class="stat-label">⚖️ Weight Discrepancy</div>
|
||||
</div>
|
||||
<div class="stat-card stat-wrong" onclick="showStatusDetails('wrong_location')">
|
||||
<div class="stat-number" id="count-wrong">{{ stats.wrong_location or 0 }}</div>
|
||||
<div class="stat-label">⚠ Wrong Location</div>
|
||||
</div>
|
||||
<div class="stat-card stat-ghost" onclick="showStatusDetails('ghost_lot')">
|
||||
<div class="stat-number" id="count-ghost">{{ stats.ghost_lots or 0 }}</div>
|
||||
<div class="stat-label">🟣 Ghost Lots</div>
|
||||
</div>
|
||||
<div class="stat-card stat-missing" onclick="showStatusDetails('missing')">
|
||||
<div class="stat-number" id="count-missing">{{ stats.missing_lots or 0 }}</div>
|
||||
<div class="stat-label">🔴 Missing</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Active Counters Section -->
|
||||
{% if active_counters %}
|
||||
<div class="section-card">
|
||||
<h2 class="section-title">Active Counters</h2>
|
||||
<div id="active-counters-container"> <div class="counter-list">
|
||||
{% for counter in active_counters %}
|
||||
<div class="counter-item">
|
||||
<div class="counter-avatar">{{ counter.full_name[0] }}</div>
|
||||
<div class="counter-info">
|
||||
<div class="counter-name">{{ counter.full_name }}</div>
|
||||
<div class="counter-location">📍 {{ counter.location_name }}</div>
|
||||
</div>
|
||||
<div class="counter-time">{{ counter.start_timestamp[11:16] }}</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Location Progress Section -->
|
||||
{% if locations %}
|
||||
<div class="section-card">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-md);">
|
||||
<h2 class="section-title" style="margin-bottom: 0;">Location Progress</h2>
|
||||
<button class="btn btn-danger btn-sm" onclick="showFinalizeAllConfirm()">
|
||||
⚠️ Finalize All Bins
|
||||
</button>
|
||||
</div>
|
||||
<div class="location-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Location</th>
|
||||
<th>Status</th>
|
||||
<th>Counter</th>
|
||||
<th>Expected</th>
|
||||
<th>Found</th>
|
||||
<th>Missing</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for loc in locations %}
|
||||
<!-- Refactored to use data attributes instead of direct Jinja injection in onclick -->
|
||||
<tr class="location-row-clickable"
|
||||
data-id="{{ loc.location_count_id }}"
|
||||
data-name="{{ loc.location_name }}"
|
||||
data-status="{{ loc.status }}"
|
||||
onclick="handleLocationClick(this)">
|
||||
<td><strong>{{ loc.location_name }}</strong></td>
|
||||
<td>
|
||||
<span class="status-badge status-{{ loc.status }}">
|
||||
{% if loc.status == 'completed' %}✓ Done
|
||||
{% elif loc.status == 'in_progress' %}⏳ Counting
|
||||
{% else %}○ Pending{% endif %}
|
||||
</span>
|
||||
</td>
|
||||
<td>{{ loc.counter_name or '-' }}</td>
|
||||
<td>{{ loc.expected_lots_master }}</td>
|
||||
<td>{{ loc.lots_found }}</td>
|
||||
<td>{{ loc.lots_missing_calc }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Status Details Modal -->
|
||||
<div id="statusModal" class="modal">
|
||||
<div class="modal-content modal-xl">
|
||||
<div class="modal-header-bar">
|
||||
<h3 class="modal-title" id="statusModalTitle">Details</h3>
|
||||
<div class="modal-header-actions">
|
||||
<button class="btn btn-secondary btn-sm" onclick="exportStatusToCSV()">
|
||||
📥 Export CSV
|
||||
</button>
|
||||
<button type="button" class="btn-close-modal" onclick="closeStatusModal()">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="statusDetailContent" class="status-detail-content">
|
||||
<div class="loading-spinner">Loading...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Location Detail Modal -->
|
||||
<div id="locationModal" class="modal">
|
||||
<div class="modal-content modal-xl">
|
||||
<div class="modal-header-bar">
|
||||
<h3 class="modal-title" id="locationModalTitle">Location Details</h3>
|
||||
<div class="modal-header-actions">
|
||||
<button id="finalizeLocationBtn" class="btn btn-success btn-sm" style="display: none;" onclick="showFinalizeConfirm()">
|
||||
✓ Finalize Location
|
||||
</button>
|
||||
<button id="reopenLocationBtn" class="btn btn-warning btn-sm" style="display: none;" onclick="showReopenConfirm()">
|
||||
🔓 Reopen Location
|
||||
</button>
|
||||
<button id="deleteLocationBtn" class="btn btn-danger btn-sm" style="display: none;" onclick="showDeleteBinConfirm()">
|
||||
🗑️ Delete Bin
|
||||
</button>
|
||||
<button class="btn btn-secondary btn-sm" onclick="exportLocationToCSV()">
|
||||
📥 Export CSV
|
||||
</button>
|
||||
<button type="button" class="btn-close-modal" onclick="closeLocationModal()">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="locationDetailContent" class="status-detail-content">
|
||||
<div class="loading-spinner">Loading...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Finalize Confirmation Modal -->
|
||||
<div id="finalizeConfirmModal" class="modal">
|
||||
<div class="modal-content modal-small">
|
||||
<div class="modal-header-bar">
|
||||
<h3 class="modal-title">Finalize Location?</h3>
|
||||
<button type="button" class="btn-close-modal" onclick="closeFinalizeConfirm()">✕</button>
|
||||
</div>
|
||||
|
||||
<div class="confirm-modal-content">
|
||||
<div class="confirm-icon">⚠️</div>
|
||||
<p class="confirm-text">
|
||||
Are you sure you want to finalize <strong id="finalizeBinName"></strong>?
|
||||
</p>
|
||||
<p class="confirm-subtext">
|
||||
This will mark the location as completed. The counter can no longer add scans to this location.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button class="btn btn-secondary" onclick="closeFinalizeConfirm()">Cancel</button>
|
||||
<button class="btn btn-success" onclick="confirmFinalize()">✓ Yes, Finalize</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Reopen Confirmation Modal -->
|
||||
<div id="reopenConfirmModal" class="modal">
|
||||
<div class="modal-content modal-small">
|
||||
<div class="modal-header-bar">
|
||||
<h3 class="modal-title">Reopen Location?</h3>
|
||||
<button type="button" class="btn-close-modal" onclick="closeReopenConfirm()">✕</button>
|
||||
</div>
|
||||
|
||||
<div class="confirm-modal-content">
|
||||
<div class="confirm-icon">🔓</div>
|
||||
<p class="confirm-text">
|
||||
Are you sure you want to reopen <strong id="reopenBinName"></strong>?
|
||||
</p>
|
||||
<p class="confirm-subtext">
|
||||
This will mark the location as in progress. The counter will be able to add more scans to this location.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button class="btn btn-secondary" onclick="closeReopenConfirm()">Cancel</button>
|
||||
<button class="btn btn-warning" onclick="confirmReopen()">🔓 Yes, Reopen</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Store the Session ID globally to use in functions without passing it every time
|
||||
const CURRENT_SESSION_ID = "{{ count_session.session_id }}";
|
||||
|
||||
function showStatusDetails(status) {
|
||||
document.getElementById('statusModal').style.display = 'flex';
|
||||
document.getElementById('statusDetailContent').innerHTML = '<div class="loading-spinner">Loading...</div>';
|
||||
|
||||
// Set modal title
|
||||
const titles = {
|
||||
'match': '✓ Matched Lots',
|
||||
'duplicates': '🔵 Duplicate Lots',
|
||||
'weight_discrepancy': '⚖️ Weight Discrepancy',
|
||||
'wrong_location': '⚠ Wrong Location',
|
||||
'ghost_lot': '🟣 Ghost Lots',
|
||||
'missing': '🔴 Missing Lots'
|
||||
};
|
||||
document.getElementById('statusModalTitle').textContent = titles[status] || 'Details';
|
||||
|
||||
// Fetch details using the blueprint URL structure
|
||||
fetch(`/session/${CURRENT_SESSION_ID}/status-details/${status}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
currentStatusData = data.items;
|
||||
currentStatusType = status;
|
||||
displayStatusDetails(data.items, status);
|
||||
} else {
|
||||
document.getElementById('statusDetailContent').innerHTML =
|
||||
`<div class="empty-state"><p>Error: ${data.message || 'Unknown error'}</p></div>`;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
document.getElementById('statusDetailContent').innerHTML =
|
||||
`<div class="empty-state"><p>Network error: ${error.message}</p></div>`;
|
||||
});
|
||||
}
|
||||
|
||||
function displayStatusDetails(items, status) {
|
||||
const content = document.getElementById('statusDetailContent');
|
||||
|
||||
if (!items || items.length === 0) {
|
||||
content.innerHTML = '<div class="empty-state"><p>No items found</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '<div class="detail-table-container"><table class="detail-table"><thead><tr>';
|
||||
|
||||
// Table headers based on status type
|
||||
if (status === 'missing') {
|
||||
html += `
|
||||
<th colspan="4" class="section-header section-counted">EXPECTED (MASTER)</th>
|
||||
</tr><tr>
|
||||
<th>LOT #</th>
|
||||
<th>SKU #</th>
|
||||
<th>E Bin</th>
|
||||
<th>E Weight</th>
|
||||
`;
|
||||
} else {
|
||||
html += `
|
||||
<th colspan="4" class="section-header section-counted">COUNTED</th>
|
||||
<th colspan="2" class="section-header section-expected">EXPECTED (MASTER)</th>
|
||||
<th colspan="2" class="section-header section-current">CURRENT</th>
|
||||
<th colspan="2" class="section-header section-counted">INFO</th>
|
||||
</tr><tr>
|
||||
<th class="col-counted">LOT #</th>
|
||||
<th class="col-counted">SKU #</th>
|
||||
<th class="col-counted">Counted Bin</th>
|
||||
<th class="col-counted">Weight</th>
|
||||
<th class="col-expected">E Bin</th>
|
||||
<th class="col-expected">E Weight</th>
|
||||
<th class="col-current">C Bin</th>
|
||||
<th class="col-current">C Weight</th>
|
||||
<th class="col-counted">Scanned By</th>
|
||||
<th class="col-counted">Scanned At</th>
|
||||
`;
|
||||
}
|
||||
|
||||
html += '</tr></thead><tbody>';
|
||||
|
||||
// Table rows
|
||||
items.forEach(item => {
|
||||
html += '<tr>';
|
||||
|
||||
if (status === 'missing') {
|
||||
html += `
|
||||
<td><strong>${item.lot_number}</strong></td>
|
||||
<td>${item.item || '-'}</td>
|
||||
<td>${item.system_bin || '-'}</td>
|
||||
<td>${item.system_quantity || '-'} lbs</td>
|
||||
`;
|
||||
} else {
|
||||
html += `
|
||||
<td class="col-counted"><strong>${item.lot_number}</strong></td>
|
||||
<td class="col-counted">${item.item || '-'}</td>
|
||||
<td class="col-counted">${item.scanned_location || '-'}</td>
|
||||
<td class="col-counted">${item.actual_weight || '-'} lbs</td>
|
||||
<td class="col-expected">${item.master_expected_location || '-'}</td>
|
||||
<td class="col-expected">${item.master_expected_weight ? item.master_expected_weight + ' lbs' : '-'}</td>
|
||||
<td class="col-current">${item.current_system_location || '-'}</td>
|
||||
<td class="col-current">${item.current_system_weight ? item.current_system_weight + ' lbs' : '-'}</td>
|
||||
<td class="col-counted">${item.scanned_by_name || '-'}</td>
|
||||
<td class="col-counted">${item.scan_timestamp ? item.scan_timestamp.substring(0, 19) : '-'}</td>
|
||||
`;
|
||||
}
|
||||
|
||||
html += '</tr>';
|
||||
});
|
||||
|
||||
html += '</tbody></table></div>';
|
||||
content.innerHTML = html;
|
||||
}
|
||||
|
||||
function closeStatusModal() {
|
||||
document.getElementById('statusModal').style.display = 'none';
|
||||
}
|
||||
|
||||
let currentStatusData = null;
|
||||
let currentStatusType = null;
|
||||
|
||||
function exportStatusToCSV() {
|
||||
if (!currentStatusData || currentStatusData.length === 0) {
|
||||
alert('No data to export');
|
||||
return;
|
||||
}
|
||||
|
||||
// Build CSV content
|
||||
let csv = '';
|
||||
|
||||
// Headers based on status type
|
||||
if (currentStatusType === 'missing') {
|
||||
csv = 'LOT #,SKU #,E Bin,E Weight\n';
|
||||
|
||||
currentStatusData.forEach(item => {
|
||||
csv += `"${item.lot_number}",`;
|
||||
csv += `"${item.item || ''}",`;
|
||||
csv += `"${item.system_bin || ''}",`;
|
||||
csv += `"${item.system_quantity || ''} lbs"\n`;
|
||||
});
|
||||
} else {
|
||||
csv = 'LOT #,SKU #,Counted Bin,Weight,E Bin,E Weight,C Bin,C Weight,Scanned By,Scanned At\n';
|
||||
|
||||
currentStatusData.forEach(item => {
|
||||
csv += `"${item.lot_number}",`;
|
||||
csv += `"${item.item || ''}",`;
|
||||
csv += `"${item.scanned_location || ''}",`;
|
||||
csv += `"${item.actual_weight || ''} lbs",`;
|
||||
csv += `"${item.master_expected_location || ''}",`;
|
||||
csv += `"${item.master_expected_weight ? item.master_expected_weight + ' lbs' : ''}",`;
|
||||
csv += `"${item.current_system_location || ''}",`;
|
||||
csv += `"${item.current_system_weight ? item.current_system_weight + ' lbs' : ''}",`;
|
||||
csv += `"${item.scanned_by_name || ''}",`;
|
||||
csv += `"${item.scan_timestamp ? item.scan_timestamp.substring(0, 19) : ''}"\n`;
|
||||
});
|
||||
}
|
||||
|
||||
// Create download link
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
const link = document.createElement('a');
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
// Generate filename with status type and timestamp
|
||||
const timestamp = new Date().toISOString().slice(0, 19).replace(/[:.]/g, '-');
|
||||
const statusName = document.getElementById('statusModalTitle').textContent.replace(/[^a-z0-9]/gi, '_');
|
||||
link.setAttribute('href', url);
|
||||
link.setAttribute('download', `${statusName}_${timestamp}.csv`);
|
||||
link.style.visibility = 'hidden';
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
let currentLocationId = null;
|
||||
let currentLocationName = '';
|
||||
let currentLocationStatus = '';
|
||||
let currentLocationData = null;
|
||||
|
||||
// New helper function to handle click from data attributes
|
||||
function handleLocationClick(row) {
|
||||
const id = row.getAttribute('data-id');
|
||||
const name = row.getAttribute('data-name');
|
||||
const status = row.getAttribute('data-status');
|
||||
showLocationDetails(id, name, status);
|
||||
}
|
||||
|
||||
function showLocationDetails(locationCountId, locationName, status) {
|
||||
currentLocationId = locationCountId;
|
||||
currentLocationName = locationName;
|
||||
currentLocationStatus = status;
|
||||
|
||||
document.getElementById('locationModal').style.display = 'flex';
|
||||
document.getElementById('locationModalTitle').textContent = `${locationName} - All Scans`;
|
||||
document.getElementById('locationDetailContent').innerHTML = '<div class="loading-spinner">Loading...</div>';
|
||||
|
||||
// Show finalize or reopen button based on status
|
||||
const finalizeBtn = document.getElementById('finalizeLocationBtn');
|
||||
const reopenBtn = document.getElementById('reopenLocationBtn');
|
||||
const deleteBtn = document.getElementById('deleteLocationBtn'); // ADD THIS LINE
|
||||
|
||||
deleteBtn.style.display = 'block';
|
||||
|
||||
if (status === 'in_progress') {
|
||||
finalizeBtn.style.display = 'block';
|
||||
reopenBtn.style.display = 'none';
|
||||
} else if (status === 'completed') {
|
||||
finalizeBtn.style.display = 'none';
|
||||
reopenBtn.style.display = 'block';
|
||||
} else {
|
||||
finalizeBtn.style.display = 'none';
|
||||
reopenBtn.style.display = 'none';
|
||||
}
|
||||
|
||||
// Fetch all scans for this location
|
||||
fetch(`/location/${locationCountId}/scans`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
currentLocationData = data.scans;
|
||||
displayLocationScans(data.scans);
|
||||
} else {
|
||||
document.getElementById('locationDetailContent').innerHTML =
|
||||
`<div class="empty-state"><p>Error: ${data.message || 'Unknown error'}</p></div>`;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
document.getElementById('locationDetailContent').innerHTML =
|
||||
`<div class="empty-state"><p>Network error: ${error.message}</p></div>`;
|
||||
});
|
||||
}
|
||||
|
||||
function displayLocationScans(scans) {
|
||||
const content = document.getElementById('locationDetailContent');
|
||||
|
||||
if (!scans || scans.length === 0) {
|
||||
content.innerHTML = '<div class="empty-state"><p>No scans found for this location</p></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '<div class="detail-table-container"><table class="detail-table"><thead><tr>';
|
||||
html += `
|
||||
<th colspan="4" class="section-header section-counted">COUNTED</th>
|
||||
<th colspan="2" class="section-header section-expected">EXPECTED (MASTER)</th>
|
||||
<th colspan="2" class="section-header section-current">CURRENT</th>
|
||||
<th colspan="2" class="section-header section-counted">INFO</th>
|
||||
</tr><tr>
|
||||
<th class="col-counted">LOT #</th>
|
||||
<th class="col-counted">SKU #</th>
|
||||
<th class="col-counted">Counted Bin</th>
|
||||
<th class="col-counted">Weight</th>
|
||||
<th class="col-expected">E Bin</th>
|
||||
<th class="col-expected">E Weight</th>
|
||||
<th class="col-current">C Bin</th>
|
||||
<th class="col-current">C Weight</th>
|
||||
<th class="col-counted">Status</th>
|
||||
<th class="col-counted">Scanned At</th>
|
||||
`;
|
||||
|
||||
html += '</tr></thead><tbody>';
|
||||
|
||||
scans.forEach(scan => {
|
||||
// Determine status badge
|
||||
let statusBadge = '';
|
||||
if (scan.duplicate_status === '01' || scan.duplicate_status === '04') {
|
||||
statusBadge = '🔵 Duplicate';
|
||||
} else if (scan.duplicate_status === '03') {
|
||||
statusBadge = '🟠 Dup (Other)';
|
||||
} else if (scan.master_status === 'match' && Math.abs(scan.actual_weight - (scan.master_expected_weight || 0)) >= 0.01) {
|
||||
statusBadge = '⚖️ Weight Off';
|
||||
} else if (scan.master_status === 'match') {
|
||||
statusBadge = '✓ Match';
|
||||
} else if (scan.master_status === 'wrong_location') {
|
||||
statusBadge = '⚠ Wrong Loc';
|
||||
} else if (scan.master_status === 'ghost_lot') {
|
||||
statusBadge = '🟣 Ghost';
|
||||
}
|
||||
|
||||
html += '<tr>';
|
||||
html += `
|
||||
<td class="col-counted"><strong>${scan.lot_number}</strong></td>
|
||||
<td class="col-counted">${scan.item || '-'}</td>
|
||||
<td class="col-counted">${scan.scanned_location || '-'}</td>
|
||||
<td class="col-counted">${scan.actual_weight || '-'} lbs</td>
|
||||
<td class="col-expected">${scan.master_expected_location || '-'}</td>
|
||||
<td class="col-expected">${scan.master_expected_weight ? scan.master_expected_weight + ' lbs' : '-'}</td>
|
||||
<td class="col-current">${scan.current_system_location || '-'}</td>
|
||||
<td class="col-current">${scan.current_system_weight ? scan.current_system_weight + ' lbs' : '-'}</td>
|
||||
<td class="col-counted">${statusBadge}</td>
|
||||
<td class="col-counted">${scan.scan_timestamp ? scan.scan_timestamp.substring(0, 19) : '-'}</td>
|
||||
`;
|
||||
html += '</tr>';
|
||||
});
|
||||
|
||||
html += '</tbody></table></div>';
|
||||
content.innerHTML = html;
|
||||
}
|
||||
|
||||
function closeLocationModal() {
|
||||
document.getElementById('locationModal').style.display = 'none';
|
||||
currentLocationId = null;
|
||||
currentLocationData = null;
|
||||
}
|
||||
|
||||
function exportLocationToCSV() {
|
||||
if (!currentLocationData || currentLocationData.length === 0) {
|
||||
alert('No data to export');
|
||||
return;
|
||||
}
|
||||
|
||||
let csv = 'LOT #,SKU #,Counted Bin,Weight,E Bin,E Weight,C Bin,C Weight,Status,Scanned At\n';
|
||||
|
||||
currentLocationData.forEach(scan => {
|
||||
let status = '';
|
||||
if (scan.duplicate_status === '01' || scan.duplicate_status === '04') {
|
||||
status = 'Duplicate';
|
||||
} else if (scan.duplicate_status === '03') {
|
||||
status = 'Dup (Other)';
|
||||
} else if (scan.master_status === 'match' && Math.abs(scan.actual_weight - (scan.master_expected_weight || 0)) >= 0.01) {
|
||||
status = 'Weight Off';
|
||||
} else if (scan.master_status === 'match') {
|
||||
status = 'Match';
|
||||
} else if (scan.master_status === 'wrong_location') {
|
||||
status = 'Wrong Loc';
|
||||
} else if (scan.master_status === 'ghost_lot') {
|
||||
status = 'Ghost';
|
||||
}
|
||||
|
||||
csv += `"${scan.lot_number}",`;
|
||||
csv += `"${scan.item || ''}",`;
|
||||
csv += `"${scan.scanned_location || ''}",`;
|
||||
csv += `"${scan.actual_weight || ''} lbs",`;
|
||||
csv += `"${scan.master_expected_location || ''}",`;
|
||||
csv += `"${scan.master_expected_weight ? scan.master_expected_weight + ' lbs' : ''}",`;
|
||||
csv += `"${scan.current_system_location || ''}",`;
|
||||
csv += `"${scan.current_system_weight ? scan.current_system_weight + ' lbs' : ''}",`;
|
||||
csv += `"${status}",`;
|
||||
csv += `"${scan.scan_timestamp ? scan.scan_timestamp.substring(0, 19) : ''}"\n`;
|
||||
});
|
||||
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
const link = document.createElement('a');
|
||||
const url = URL.createObjectURL(blob);
|
||||
const timestamp = new Date().toISOString().slice(0, 19).replace(/[:.]/g, '-');
|
||||
link.setAttribute('href', url);
|
||||
link.setAttribute('download', `${currentLocationName}_${timestamp}.csv`);
|
||||
link.style.visibility = 'hidden';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
function showFinalizeConfirm() {
|
||||
document.getElementById('finalizeBinName').textContent = currentLocationName;
|
||||
document.getElementById('finalizeConfirmModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeFinalizeConfirm() {
|
||||
document.getElementById('finalizeConfirmModal').style.display = 'none';
|
||||
}
|
||||
|
||||
function confirmFinalize() {
|
||||
// Correctly points to the /finish route to trigger Missing Lot calculations
|
||||
fetch(`/count/${CURRENT_SESSION_ID}/location/${currentLocationId}/finish`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
closeFinalizeConfirm();
|
||||
closeLocationModal();
|
||||
location.reload(); // Reload to show updated status and Missing counts
|
||||
} else {
|
||||
alert(data.message || 'Error finalizing location');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Finalize Error:', error);
|
||||
alert('Error: ' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function showReopenConfirm() {
|
||||
document.getElementById('reopenBinName').textContent = currentLocationName;
|
||||
document.getElementById('reopenConfirmModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeReopenConfirm() {
|
||||
document.getElementById('reopenConfirmModal').style.display = 'none';
|
||||
}
|
||||
|
||||
function confirmReopen() {
|
||||
// Note: The /reopen endpoint is handled by blueprints/admin_locations.py
|
||||
fetch(`/location/${currentLocationId}/reopen`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
closeReopenConfirm();
|
||||
closeLocationModal();
|
||||
location.reload(); // Reload to show updated status
|
||||
} else {
|
||||
alert(data.message || 'Error reopening location');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error: ' + error.message);
|
||||
});
|
||||
}
|
||||
|
||||
// Close modal on escape
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') {
|
||||
closeStatusModal();
|
||||
closeLocationModal();
|
||||
closeFinalizeConfirm();
|
||||
closeReopenConfirm();
|
||||
}
|
||||
});
|
||||
function archiveSession() {
|
||||
if (!confirm('Archive this session? It will be hidden from the main dashboard but can be reactivated later.')) return;
|
||||
|
||||
fetch('{{ url_for("sessions.archive_session", session_id=count_session.session_id) }}', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
window.location.href = '{{ url_for("admin_dashboard") }}';
|
||||
} else {
|
||||
alert(data.message || 'Error archiving session');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function activateSession() {
|
||||
if (!confirm('Reactivate this session? It will appear on the main dashboard again.')) return;
|
||||
|
||||
fetch('{{ url_for("sessions.activate_session", session_id=count_session.session_id) }}', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message || 'Error activating session');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showFinalizeAllConfirm() {
|
||||
if (confirm("⚠️ WARNING: This will finalize ALL open bins in this session and calculate missing items. This cannot be undone. Are you sure?")) {
|
||||
fetch(`/session/${CURRENT_SESSION_ID}/finalize-all`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert(data.message);
|
||||
location.reload();
|
||||
} else {
|
||||
alert("Error: " + data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function showDeleteBinConfirm() {
|
||||
if (confirm(`⚠️ DANGER: Are you sure you want to delete ALL data for ${currentLocationName}? This will hide the bin from staff and wipe any missing lot flags.`)) {
|
||||
fetch(`/location/${currentLocationId}/delete`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
closeLocationModal();
|
||||
location.reload();
|
||||
} else {
|
||||
alert(data.message || 'Error deleting bin');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error: ' + error.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function refreshDashboardStats() {
|
||||
const sessionId = CURRENT_SESSION_ID;
|
||||
|
||||
fetch(`/session/${sessionId}/get_stats`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const s = data.stats;
|
||||
// These IDs must match your HTML and the keys must match sessions.py
|
||||
if (document.getElementById('count-matched')) document.getElementById('count-matched').innerText = s.matched;
|
||||
if (document.getElementById('count-duplicates')) document.getElementById('count-duplicates').innerText = s.duplicates;
|
||||
if (document.getElementById('count-discrepancy')) document.getElementById('count-discrepancy').innerText = s.discrepancy;
|
||||
if (document.getElementById('count-wrong')) document.getElementById('count-wrong').innerText = s.wrong_location; // Fixed
|
||||
if (document.getElementById('count-ghost')) document.getElementById('count-ghost').innerText = s.ghost_lots; // Fixed
|
||||
if (document.getElementById('count-missing')) document.getElementById('count-missing').innerText = s.missing;
|
||||
}
|
||||
})
|
||||
.catch(err => console.error('Error refreshing stats:', err));
|
||||
|
||||
fetch(`/session/${sessionId}/active-counters-fragment`)
|
||||
.then(response => response.text())
|
||||
.then(html => {
|
||||
const container = document.getElementById('active-counters-container');
|
||||
if (container) container.innerHTML = html;
|
||||
})
|
||||
.catch(err => console.error('Error refreshing counters:', err));
|
||||
}
|
||||
|
||||
// This tells the browser: "Run the refresh function every 30 seconds"
|
||||
setInterval(refreshDashboardStats, 30000);
|
||||
|
||||
// This runs it IMMEDIATELY once so you don't wait 30 seconds for the first update
|
||||
refreshDashboardStats();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,48 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Staff Dashboard - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<!-- Mode Selector (only for admins) -->
|
||||
{% if session.role in ['owner', 'admin'] %}
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('admin_dashboard') }}" class="mode-btn">
|
||||
👔 Admin Console
|
||||
</a>
|
||||
<button class="mode-btn mode-btn-active">
|
||||
📦 Scanning Mode
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="dashboard-header">
|
||||
<a href="{{ url_for('home') }}" class="btn btn-secondary btn-sm" style="margin-bottom: var(--space-md);">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Home
|
||||
</a>
|
||||
<h1 class="page-title">Select Count Session</h1>
|
||||
</div>
|
||||
|
||||
{% if sessions %}
|
||||
<div class="sessions-list">
|
||||
{% for s in sessions %}
|
||||
<a href="{{ url_for('counting.count_session', session_id=s.session_id) }}" class="session-list-item">
|
||||
<div class="session-list-info">
|
||||
<h3 class="session-list-name">{{ s.session_name }}</h3>
|
||||
<span class="session-list-type">{{ 'Full Physical' if s.session_type == 'full_physical' else 'Cycle Count' }}</span>
|
||||
</div>
|
||||
<div class="session-list-action">
|
||||
<span class="arrow-icon">→</span>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">📋</div>
|
||||
<h2 class="empty-title">No Active Sessions</h2>
|
||||
<p class="empty-text">No count sessions are currently active. Please contact your administrator.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -22,7 +22,7 @@
|
||||
{% if modules %}
|
||||
<div class="module-grid">
|
||||
{% for m in modules %}
|
||||
<a href="{{ url_for(m.module_key + '.index') }}" class="module-card">
|
||||
<a href="/{{ m.module_key }}" class="module-card">
|
||||
<div class="module-icon">
|
||||
<i class="fa-solid {{ m.icon }}"></i>
|
||||
</div>
|
||||
|
||||
182
templates/module_manager.html
Normal file
182
templates/module_manager.html
Normal file
@@ -0,0 +1,182 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Module Manager - ScanLook{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container mt-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1><i class="fas fa-puzzle-piece"></i> Module Manager</h1>
|
||||
<a href="{{ url_for('home') }}" class="btn btn-secondary">
|
||||
<i class="fas fa-arrow-left"></i> Back to Home
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<p class="lead">Install, uninstall, and manage ScanLook modules</p>
|
||||
|
||||
<div class="row">
|
||||
{% for module in modules %}
|
||||
<div class="col-md-6 col-lg-4 mb-4">
|
||||
<div class="card h-100 {% if module.is_active %}border-success{% elif module.is_installed %}border-warning{% endif %}">
|
||||
<div class="card-header {% if module.is_active %}bg-success text-white{% elif module.is_installed %}bg-warning text-dark{% else %}bg-light{% endif %}">
|
||||
<h5 class="mb-0">
|
||||
<i class="fas fa-cube"></i> {{ module.name }}
|
||||
<span class="badge badge-secondary float-right">v{{ module.version }}</span>
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">{{ module.description }}</p>
|
||||
|
||||
<p class="mb-2">
|
||||
<small class="text-muted">
|
||||
<strong>Author:</strong> {{ module.author }}<br>
|
||||
<strong>Module Key:</strong> <code>{{ module.module_key }}</code>
|
||||
</small>
|
||||
</p>
|
||||
|
||||
<div class="mt-3">
|
||||
{% if module.is_installed and module.is_active %}
|
||||
<span class="badge badge-success mb-2">
|
||||
<i class="fas fa-check-circle"></i> Active
|
||||
</span>
|
||||
{% elif module.is_installed %}
|
||||
<span class="badge badge-warning mb-2">
|
||||
<i class="fas fa-pause-circle"></i> Installed (Inactive)
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="badge badge-secondary mb-2">
|
||||
<i class="fas fa-times-circle"></i> Not Installed
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer bg-light">
|
||||
{% if not module.is_installed %}
|
||||
<button class="btn btn-primary btn-sm btn-block" onclick="installModule('{{ module.module_key }}')">
|
||||
<i class="fas fa-download"></i> Install
|
||||
</button>
|
||||
{% elif module.is_active %}
|
||||
<button class="btn btn-warning btn-sm btn-block mb-2" onclick="deactivateModule('{{ module.module_key }}')">
|
||||
<i class="fas fa-pause"></i> Deactivate
|
||||
</button>
|
||||
<button class="btn btn-danger btn-sm btn-block" onclick="uninstallModule('{{ module.module_key }}')">
|
||||
<i class="fas fa-trash"></i> Uninstall
|
||||
</button>
|
||||
{% else %}
|
||||
<button class="btn btn-success btn-sm btn-block mb-2" onclick="activateModule('{{ module.module_key }}')">
|
||||
<i class="fas fa-play"></i> Activate
|
||||
</button>
|
||||
<button class="btn btn-danger btn-sm btn-block" onclick="uninstallModule('{{ module.module_key }}')">
|
||||
<i class="fas fa-trash"></i> Uninstall
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if not modules %}
|
||||
<div class="alert alert-info">
|
||||
<i class="fas fa-info-circle"></i> No modules found in the <code>/modules</code> directory.
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function installModule(moduleKey) {
|
||||
if (!confirm(`Install module "${moduleKey}"?\n\nThis will create database tables and activate the module.`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/admin/modules/${moduleKey}/install`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert(`✅ ${data.message}\n\nPlease reload the page.`);
|
||||
location.reload();
|
||||
} else {
|
||||
alert(`❌ ${data.message}`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert(`❌ Error: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
function uninstallModule(moduleKey) {
|
||||
if (!confirm(`⚠️ UNINSTALL module "${moduleKey}"?\n\nThis will DELETE all module data and cannot be undone!`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/admin/modules/${moduleKey}/uninstall`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert(`✅ ${data.message}\n\nPlease reload the page.`);
|
||||
location.reload();
|
||||
} else {
|
||||
alert(`❌ ${data.message}`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert(`❌ Error: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
function activateModule(moduleKey) {
|
||||
fetch(`/admin/modules/${moduleKey}/activate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert(`✅ ${data.message}\n\nPlease reload the page.`);
|
||||
location.reload();
|
||||
} else {
|
||||
alert(`❌ ${data.message}`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert(`❌ Error: ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
function deactivateModule(moduleKey) {
|
||||
if (!confirm(`Deactivate module "${moduleKey}"?\n\nUsers will lose access until reactivated.`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(`/admin/modules/${moduleKey}/deactivate`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
alert(`✅ ${data.message}\n\nPlease reload the page.`);
|
||||
location.reload();
|
||||
} else {
|
||||
alert(`❌ ${data.message}`);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert(`❌ Error: ${error}`);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user