Compare commits
13 Commits
f7e25c8d1f
...
refactor/c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6d8767c28 | ||
|
|
d6e9f20757 | ||
|
|
674a8f8a0c | ||
|
|
5097ceb82f | ||
|
|
3ec00613ca | ||
|
|
d955a13f3d | ||
|
|
b11421a8f5 | ||
|
|
ac73045ef2 | ||
|
|
21671d6bee | ||
|
|
cbd7e535e6 | ||
|
|
38212653f4 | ||
|
|
136fe03e07 | ||
|
|
ff577a6cbf |
@@ -29,6 +29,10 @@ Long-term goal: evolve into a WMS, but right now focus on making this workflow r
|
|||||||
5) **Keep it to the point.** Default to short answers. Only explain more if I ask.
|
5) **Keep it to the point.** Default to short answers. Only explain more if I ask.
|
||||||
6) **Verify safety.** Warn me before destructive actions (delete/overwrite/migrations). Offer a safer alternative.
|
6) **Verify safety.** Warn me before destructive actions (delete/overwrite/migrations). Offer a safer alternative.
|
||||||
7) **Evidence-based debugging.** Ask for exact error text/logs and versions before guessing.
|
7) **Evidence-based debugging.** Ask for exact error text/logs and versions before guessing.
|
||||||
|
8) **CSS changes:** Ask which device(s) the change is for (desktop/mobile/scanner) before editing. Each has its own file.
|
||||||
|
9) **Docker deployment:** Production runs in Docker on Linux (PortainerVM). Volume mounts only /app/database to preserve data between updates.
|
||||||
|
10) Database changes: Never tell user to "manually run SQL". Always add changes to migrations.py so they auto-apply on deployment.
|
||||||
|
|
||||||
|
|
||||||
## How you should respond
|
## How you should respond
|
||||||
- Start by confirming which mode we’re working on: Cycle Count or Physical Inventory.
|
- Start by confirming which mode we’re working on: Cycle Count or Physical Inventory.
|
||||||
@@ -37,10 +41,68 @@ Long-term goal: evolve into a WMS, but right now focus on making this workflow r
|
|||||||
- When writing SQL: be explicit about constraints/indexes that matter for lots/bins/sessions.
|
- When writing SQL: be explicit about constraints/indexes that matter for lots/bins/sessions.
|
||||||
- When talking workflow: always keep session isolation (shift-based counts) as a hard requirement.
|
- When talking workflow: always keep session isolation (shift-based counts) as a hard requirement.
|
||||||
|
|
||||||
## First response checklist (every new task)
|
## Scanlook (current product summary)
|
||||||
Ask for:
|
Scanlook is a web app for warehouse counting workflows built with Flask + SQLite.
|
||||||
- DB type (SQLite/Postgres/MySQL) + ORM (SQLAlchemy?) or raw SQL
|
|
||||||
- Current data model (tables or SQLAlchemy models) for: count_session, bin/location, expected_lines, scans
|
**Current Version:** 0.13.0
|
||||||
- How the Master Inventory list is formatted (CSV columns)
|
|
||||||
- What “Finalize BIN” should do exactly (lock? allow reopen? who can override?)
|
**Tech Stack:**
|
||||||
Then proceed one step at a time.
|
- Backend: Python/Flask, raw SQL (no ORM), openpyxl (Excel file generation)
|
||||||
|
- Database: SQLite (located in /database/scanlook.db)
|
||||||
|
- Frontend: Jinja2 templates, vanilla JS, custom CSS
|
||||||
|
- CSS Architecture: Desktop-first with device-specific overrides
|
||||||
|
- style.css (base/desktop)
|
||||||
|
- mobile.css (phones, 360-767px)
|
||||||
|
- scanner.css (MC9300 scanners, max-width 359px)
|
||||||
|
- Deployment: Docker container, Gitea for version control + container registry
|
||||||
|
|
||||||
|
**Project Structure:**
|
||||||
|
- app.py (main Flask app, routes for auth + dashboard)
|
||||||
|
- /blueprints/ (modular routes: counting.py, sessions.py, users.py, data_imports.py, admin_locations.py)
|
||||||
|
- /templates/ (Jinja2 HTML templates)
|
||||||
|
- /static/css/ (style.css, mobile.css, scanner.css)
|
||||||
|
- /database/ (scanlook.db, init_db.py)
|
||||||
|
- db.py (database helper functions: query_db, execute_db)
|
||||||
|
- utils.py (decorators: login_required, role_required)
|
||||||
|
- migrations.py (database migration system)
|
||||||
|
|
||||||
|
**Key Features (implemented):**
|
||||||
|
- Count Sessions with archive/activate functionality
|
||||||
|
- Master baseline upload (CSV)
|
||||||
|
- Current baseline upload (optional, for comparison)
|
||||||
|
- Staff scanning interface optimized for MC9300 Zebra scanners
|
||||||
|
- Scan statuses: Match, Duplicate, Wrong Location, Ghost Lot, Weight Discrepancy
|
||||||
|
- Location/BIN workflow with Expected → Scanned flow
|
||||||
|
- Session isolation (archived sessions blocked from access)
|
||||||
|
- Role-based access: owner, admin, staff
|
||||||
|
- Auto-initialize database on first run
|
||||||
|
- Consumption Sheets module (production lot tracking with Excel export)
|
||||||
|
- Database migration system (auto-applies schema changes on startup)
|
||||||
|
|
||||||
|
**Two count types:**
|
||||||
|
1. Cycle Count: shows Expected list for the BIN
|
||||||
|
2. Physical Inventory: blind count (no Expected list shown)
|
||||||
|
|
||||||
|
**Long-term goal:** Modular WMS with future modules for Shipping, Receiving, Transfers, Production.
|
||||||
|
|
||||||
|
**Module System (v0.13.0):**
|
||||||
|
- Modules table defines available modules (module_key used for routing)
|
||||||
|
- UserModules table tracks per-user access
|
||||||
|
- Home page (/home) shows module cards based on user's access
|
||||||
|
- Each module needs: database entry, route with access check, home page card
|
||||||
|
- New modules should go in /modules/{module_name}/ with:
|
||||||
|
- __init__.py (blueprint registration)
|
||||||
|
- routes.py (all routes)
|
||||||
|
- templates/ (module-specific templates)
|
||||||
|
- Current modules:
|
||||||
|
- Inventory Counts (counting)
|
||||||
|
- Consumption Sheets (cons_sheets)
|
||||||
|
|
||||||
|
|
||||||
|
## Quick Reference
|
||||||
|
- Database: SQLite at /database/scanlook.db
|
||||||
|
- Scanner viewport: 320px wide (MC9300)
|
||||||
|
- Mobile breakpoint: 360-767px
|
||||||
|
- Desktop: 768px+
|
||||||
|
- Git remote: http://10.44.44.33:3000/stuff/ScanLook.git
|
||||||
|
- Docker registry: 10.44.44.33:3000/stuff/scanlook
|
||||||
219
README.md
219
README.md
@@ -17,7 +17,7 @@ pip install flask werkzeug --break-system-packages
|
|||||||
### 2. Initialize Database
|
### 2. Initialize Database
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /home/claude/scanlook
|
cd /path/to/scanlook
|
||||||
python database/init_db.py
|
python database/init_db.py
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ Access at: **http://localhost:5000**
|
|||||||
|
|
||||||
## 📱 Accessing from Scanner Devices
|
## 📱 Accessing from Scanner Devices
|
||||||
|
|
||||||
For Zebra Android scanners or tablets on the same network:
|
For Zebra MC9300 scanners or tablets on the same network:
|
||||||
|
|
||||||
1. Find your server's IP address:
|
1. Find your server's IP address:
|
||||||
```bash
|
```bash
|
||||||
@@ -55,11 +55,32 @@ For Zebra Android scanners or tablets on the same network:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 🏗️ Modular Architecture
|
||||||
|
|
||||||
|
ScanLook uses a modular system designed to grow into a full WMS. Modules can be enabled/disabled per user.
|
||||||
|
|
||||||
|
### Current Modules:
|
||||||
|
- **Counts** - Cycle Counts and Physical Inventory
|
||||||
|
|
||||||
|
### Planned Modules:
|
||||||
|
- Shipping
|
||||||
|
- Receiving
|
||||||
|
- Transfers
|
||||||
|
- Production
|
||||||
|
|
||||||
|
### Module Access
|
||||||
|
- Admins assign modules to users via User Management
|
||||||
|
- Users only see modules they have access to on the home screen
|
||||||
|
- Route guards prevent URL bypassing
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 👥 User Roles
|
## 👥 User Roles
|
||||||
|
|
||||||
### Owner (Level 1)
|
### Owner (Level 1)
|
||||||
- Super admin privileges
|
- Super admin privileges
|
||||||
- Manage all admins
|
- Manage all users (admins and staff)
|
||||||
|
- Access to all modules
|
||||||
- View all sessions across branches
|
- View all sessions across branches
|
||||||
|
|
||||||
### Admin (Level 2)
|
### Admin (Level 2)
|
||||||
@@ -68,9 +89,10 @@ For Zebra Android scanners or tablets on the same network:
|
|||||||
- Upload CURRENT baseline (refresh anytime)
|
- Upload CURRENT baseline (refresh anytime)
|
||||||
- View real-time dashboard
|
- View real-time dashboard
|
||||||
- Export variance reports
|
- Export variance reports
|
||||||
- Manage staff users
|
- Manage staff users and module assignments
|
||||||
|
|
||||||
### Staff/Counter (Level 3)
|
### Staff/Counter (Level 3)
|
||||||
|
- Access assigned modules only
|
||||||
- Select active count session
|
- Select active count session
|
||||||
- Scan locations and lots
|
- Scan locations and lots
|
||||||
- Enter weights
|
- Enter weights
|
||||||
@@ -79,36 +101,36 @@ For Zebra Android scanners or tablets on the same network:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔄 Core Workflow
|
## 🔄 Core Workflow (Counts Module)
|
||||||
|
|
||||||
### Phase 1: Session Setup (Admin)
|
### Phase 1: Session Setup (Admin)
|
||||||
|
|
||||||
1. **Log in as admin**
|
1. **Log in as admin**
|
||||||
2. **Create new count session**:
|
2. **Navigate to Admin Console**
|
||||||
|
3. **Create new count session**:
|
||||||
- Session name: "January 17, 2026 - Daily Cycle Count"
|
- Session name: "January 17, 2026 - Daily Cycle Count"
|
||||||
- Type: Cycle Count OR Full Physical Inventory
|
- Type: Cycle Count OR Full Physical Inventory
|
||||||
3. **Upload MASTER baseline** CSV from NetSuite:
|
4. **Upload MASTER baseline** CSV from NetSuite:
|
||||||
- Format: `Item, Description, Lot Number, Location, Bin Number, On Hand`
|
- Format: `Item, Description, Lot Number, Location, Bin Number, On Hand`
|
||||||
- Creates baseline version 1
|
5. Session status: **Active**
|
||||||
4. Session status: **Active**
|
6. Counters can now begin
|
||||||
5. Counters can now begin
|
|
||||||
|
|
||||||
### Phase 2: Counting (Staff)
|
### Phase 2: Counting (Staff)
|
||||||
|
|
||||||
1. **Log in as staff**
|
1. **Log in as staff**
|
||||||
2. **Select active session**
|
2. **Select Counts module** from home screen
|
||||||
3. **Scan location barcode** (e.g., R903B)
|
3. **Select active session**
|
||||||
- System marks location "in progress"
|
4. **Start a new bin** - scan or enter bin number
|
||||||
- Shows: "Counting R903B"
|
5. **Scan lot barcode**
|
||||||
4. **Scan lot barcode**
|
6. System checks lot against MASTER baseline:
|
||||||
5. System checks lot against MASTER baseline:
|
|
||||||
- ✅ **MATCH**: Expected here, location correct
|
- ✅ **MATCH**: Expected here, location correct
|
||||||
- ⚠️ **WRONG LOCATION**: Lot exists but system says different location
|
- ⚠️ **WRONG LOCATION**: Lot exists but system says different location
|
||||||
- ❌ **GHOST LOT**: Not in system at all
|
- ❌ **GHOST LOT**: Not in system at all
|
||||||
6. **Enter weight**
|
- 🔵 **DUPLICATE**: Lot already scanned (same or different location)
|
||||||
7. Save → returns to scan input (autofocus)
|
7. **Enter weight**
|
||||||
8. Repeat for all lots in location
|
8. Save → returns to scan input (autofocus)
|
||||||
9. Click **"Finish Location"**
|
9. Repeat for all lots in bin
|
||||||
|
10. Click **"Finish Location"** to finalize
|
||||||
|
|
||||||
### Phase 3: Admin Monitoring
|
### Phase 3: Admin Monitoring
|
||||||
|
|
||||||
@@ -155,8 +177,9 @@ Item,Description,Lot Number,Location,Bin Number,On Hand
|
|||||||
- What counters validate against
|
- What counters validate against
|
||||||
- Represents "what should have been there when we started"
|
- Represents "what should have been there when we started"
|
||||||
|
|
||||||
**CURRENT Baseline**:
|
**CURRENT Baseline** (Global):
|
||||||
- Admin can refresh unlimited times
|
- Admin can refresh unlimited times
|
||||||
|
- Shared across all sessions
|
||||||
- Only affects admin dashboard/reporting
|
- Only affects admin dashboard/reporting
|
||||||
- Counters never see it
|
- Counters never see it
|
||||||
- Shows "where is it in the system NOW"
|
- Shows "where is it in the system NOW"
|
||||||
@@ -170,16 +193,29 @@ Item,Description,Lot Number,Location,Bin Number,On Hand
|
|||||||
- **Ghost Lot**: Scanned but not in baseline at all
|
- **Ghost Lot**: Scanned but not in baseline at all
|
||||||
- **Missing/Phantom**: In baseline but not found during count
|
- **Missing/Phantom**: In baseline but not found during count
|
||||||
|
|
||||||
### Blind Counting
|
### Duplicate Detection
|
||||||
|
|
||||||
- Counters don't see expected quantities
|
- **Status 00**: First scan of lot (no duplicate)
|
||||||
- Prevents bias
|
- **Status 01**: Duplicate in same location by same user
|
||||||
- Ensures honest count
|
- **Status 03**: Found in different location
|
||||||
|
- **Status 04**: Both same location duplicate AND different location
|
||||||
|
|
||||||
|
### Count Types
|
||||||
|
|
||||||
|
**Cycle Count:**
|
||||||
|
- Shows expected lots for the bin
|
||||||
|
- Staff can see what should be there
|
||||||
|
- Good for regular inventory checks
|
||||||
|
|
||||||
|
**Full Physical Inventory:**
|
||||||
|
- Blind count (no expected list shown)
|
||||||
|
- Staff only sees what they've scanned
|
||||||
|
- Missing lots determined after finalization
|
||||||
|
|
||||||
### Real-Time Dashboard
|
### Real-Time Dashboard
|
||||||
|
|
||||||
- Active counters with current location
|
- Active sessions with progress stats
|
||||||
- Progress by location
|
- Location completion tracking
|
||||||
- Variance counts updating live
|
- Variance counts updating live
|
||||||
- Dual view (MASTER vs CURRENT) after refresh
|
- Dual view (MASTER vs CURRENT) after refresh
|
||||||
|
|
||||||
@@ -188,32 +224,38 @@ Item,Description,Lot Number,Location,Bin Number,On Hand
|
|||||||
- Every scan timestamped with user
|
- Every scan timestamped with user
|
||||||
- Soft deletes tracked
|
- Soft deletes tracked
|
||||||
- Edits tracked with modified timestamp
|
- Edits tracked with modified timestamp
|
||||||
- Baseline version tracking
|
- Session archival (archived sessions are read-only)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🗂️ Database Schema
|
## 🗂️ Database Schema
|
||||||
|
|
||||||
### Tables:
|
### Core Tables:
|
||||||
- **Users**: Authentication and role management
|
- **Users**: Authentication and role management
|
||||||
|
- **Modules**: Available system modules
|
||||||
|
- **UserModules**: Per-user module access
|
||||||
- **CountSessions**: Count session metadata
|
- **CountSessions**: Count session metadata
|
||||||
- **BaselineInventory_Master**: Morning baseline (never changes)
|
- **BaselineInventory_Master**: Session-specific baseline (immutable)
|
||||||
- **BaselineInventory_Current**: Refreshable baseline (soft delete)
|
- **BaselineInventory_Current**: Global refreshable baseline
|
||||||
- **LocationCounts**: Location-by-location progress
|
- **LocationCounts**: Bin-by-bin progress tracking
|
||||||
- **ScanEntries**: Every lot scan with dual status tracking
|
- **ScanEntries**: Every lot scan with status tracking
|
||||||
- **MissingLots**: Expected lots not found
|
- **MissingLots**: Expected lots not found after finalization
|
||||||
|
|
||||||
### Indexes:
|
### Key Relationships:
|
||||||
Optimized for fast lookups on lot numbers, locations, and statuses.
|
- Users → UserModules → Modules (many-to-many)
|
||||||
|
- CountSessions → BaselineInventory_Master (one-to-many)
|
||||||
|
- CountSessions → LocationCounts → ScanEntries (hierarchical)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔧 Technology Stack
|
## 🔧 Technology Stack
|
||||||
|
|
||||||
- **Backend**: Python 3.13 + Flask
|
- **Backend**: Python 3.13 + Flask
|
||||||
- **Database**: SQLite
|
- **Database**: SQLite (auto-initializes on first run)
|
||||||
- **Frontend**: HTML5 + CSS3 + Vanilla JavaScript
|
- **Frontend**: HTML5 + CSS3 + Vanilla JavaScript
|
||||||
- **Templates**: Jinja2
|
- **Templates**: Jinja2
|
||||||
|
- **Icons**: Font Awesome 6.5
|
||||||
|
- **Deployment**: Docker (Linux)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -221,23 +263,37 @@ Optimized for fast lookups on lot numbers, locations, and statuses.
|
|||||||
|
|
||||||
```
|
```
|
||||||
scanlook/
|
scanlook/
|
||||||
├── app.py # Main Flask application
|
├── app.py # Main Flask application & routes
|
||||||
|
├── db.py # Database helper functions
|
||||||
|
├── utils.py # Decorators (login_required, role_required)
|
||||||
|
├── blueprints/
|
||||||
|
│ ├── counting.py # Counts module routes
|
||||||
|
│ ├── sessions.py # Session management routes
|
||||||
|
│ ├── users.py # User management routes
|
||||||
|
│ ├── data_imports.py # CSV upload routes
|
||||||
|
│ └── admin_locations.py # Admin location management
|
||||||
├── database/
|
├── database/
|
||||||
│ ├── init_db.py # Database initialization
|
│ ├── init_db.py # Database initialization & schema
|
||||||
│ └── scanlook.db # SQLite database (created)
|
│ └── scanlook.db # SQLite database (created at runtime)
|
||||||
├── static/
|
├── static/
|
||||||
│ ├── css/
|
│ ├── css/
|
||||||
│ │ └── style.css # Main stylesheet
|
│ │ ├── style.css # Base/desktop styles
|
||||||
│ └── js/
|
│ │ ├── mobile.css # Mobile overrides (360-767px)
|
||||||
│ └── main.js # Client-side JavaScript
|
│ │ └── scanner.css # MC9300 scanner overrides (<360px)
|
||||||
|
│ ├── js/
|
||||||
|
│ │ └── main.js # Client-side JavaScript
|
||||||
|
│ ├── manifest.json # PWA manifest
|
||||||
|
│ └── sw.js # Service worker
|
||||||
└── templates/
|
└── templates/
|
||||||
├── base.html # Base template
|
├── base.html # Base template with navbar
|
||||||
├── login.html # Login page
|
├── login.html # Login page
|
||||||
|
├── home.html # Module selection (landing page)
|
||||||
├── admin_dashboard.html
|
├── admin_dashboard.html
|
||||||
├── staff_dashboard.html
|
├── staff_dashboard.html
|
||||||
|
├── manage_users.html
|
||||||
├── create_session.html
|
├── create_session.html
|
||||||
├── session_detail.html
|
├── session_detail.html
|
||||||
├── count_session.html
|
├── my_counts.html
|
||||||
└── count_location.html
|
└── count_location.html
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -245,7 +301,7 @@ scanlook/
|
|||||||
|
|
||||||
## 🎨 Design Philosophy
|
## 🎨 Design Philosophy
|
||||||
|
|
||||||
**Mobile-First, Warehouse-Optimized:**
|
**Desktop-First, Multi-Device Optimized:**
|
||||||
- High contrast dark theme for warehouse lighting
|
- High contrast dark theme for warehouse lighting
|
||||||
- Large touch targets (44px minimum)
|
- Large touch targets (44px minimum)
|
||||||
- Autofocus on scan inputs
|
- Autofocus on scan inputs
|
||||||
@@ -253,52 +309,47 @@ scanlook/
|
|||||||
- Visual feedback with color-coded statuses
|
- Visual feedback with color-coded statuses
|
||||||
- Minimal typing required
|
- Minimal typing required
|
||||||
|
|
||||||
|
**CSS Architecture:**
|
||||||
|
- `style.css` - Base/desktop styles (768px+)
|
||||||
|
- `mobile.css` - Phone overrides (360-767px)
|
||||||
|
- `scanner.css` - MC9300 scanner overrides (<360px)
|
||||||
|
|
||||||
**Color Coding:**
|
**Color Coding:**
|
||||||
- ✅ Green: Perfect match
|
- ✅ Green (`--color-success`): Perfect match
|
||||||
- ⚠️ Yellow: Wrong location
|
- ⚠️ Yellow (`--color-warning`): Wrong location / Expected
|
||||||
- ❌ Red: Missing or ghost lot
|
- ❌ Red (`--color-danger`): Missing or ghost lot
|
||||||
- 🔵 Blue: Weight variance
|
- 🔵 Blue (`--color-duplicate`): Duplicate scan
|
||||||
|
- 🟠 Orange (`--color-orange`): Weight variance
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🚧 Current Status: Phase 1 Complete (MVP)
|
## 🐳 Docker Deployment
|
||||||
|
|
||||||
### ✅ Implemented:
|
```bash
|
||||||
- User authentication (3 roles)
|
# Build
|
||||||
- Session creation
|
docker build -t scanlook .
|
||||||
- MASTER baseline upload
|
|
||||||
- Location scanning
|
|
||||||
- Lot scanning with MASTER status
|
|
||||||
- Weight entry
|
|
||||||
- Basic dashboard
|
|
||||||
- Real-time progress tracking
|
|
||||||
- Mobile-optimized UI
|
|
||||||
|
|
||||||
### 🔜 Next Phases:
|
# Run (preserves database between updates)
|
||||||
- **Phase 2**: CURRENT baseline refresh & dual status recalculation
|
docker run -d \
|
||||||
- **Phase 3**: Missing lot detection, enhanced dashboard
|
-p 5000:5000 \
|
||||||
- **Phase 4**: Excel export with multiple tabs
|
-v /path/to/data:/app/database \
|
||||||
- **Phase 5**: Data retention automation, user management
|
-e SCANLOOK_SECRET_KEY=your-secret-key \
|
||||||
- **Phase 6**: Docker deployment
|
scanlook
|
||||||
|
```
|
||||||
|
|
||||||
|
**Important:** Only `/app/database` is volume-mounted to preserve data between container updates.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📝 Development Notes
|
## 🔐 Security Considerations
|
||||||
|
|
||||||
### Default Accounts (Testing)
|
- Passwords hashed with Werkzeug
|
||||||
All passwords should be changed in production!
|
|
||||||
|
|
||||||
### Security Considerations
|
|
||||||
- Passwords are hashed with Werkzeug
|
|
||||||
- Session management via Flask sessions
|
- Session management via Flask sessions
|
||||||
- SQL injection prevention (parameterized queries)
|
- SQL injection prevention (parameterized queries)
|
||||||
|
- Role-based access control
|
||||||
|
- Module-based access control with route guards
|
||||||
- Soft deletes preserve audit trail
|
- Soft deletes preserve audit trail
|
||||||
|
|
||||||
### Data Retention
|
|
||||||
- Plan: Keep data for 30 days
|
|
||||||
- Nightly cleanup job (to be implemented)
|
|
||||||
- Archive old sessions
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🎯 Success Metrics
|
## 🎯 Success Metrics
|
||||||
@@ -319,6 +370,7 @@ All passwords should be changed in production!
|
|||||||
|
|
||||||
## 💡 Future Enhancements
|
## 💡 Future Enhancements
|
||||||
|
|
||||||
|
- Additional WMS modules (Shipping, Receiving, Transfers, Production)
|
||||||
- Multi-branch support
|
- Multi-branch support
|
||||||
- Direct NetSuite API integration
|
- Direct NetSuite API integration
|
||||||
- Photo capture for variance proof
|
- Photo capture for variance proof
|
||||||
@@ -328,7 +380,16 @@ All passwords should be changed in production!
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 📧 Support
|
## 📝 Version History
|
||||||
|
|
||||||
|
- **v0.12.0** - Modular architecture with user-based module access
|
||||||
|
- **v0.11.x** - CSS refactoring, multi-device support, duplicate detection
|
||||||
|
- **v0.10.x** - Global CURRENT baseline, session archival
|
||||||
|
- **v0.9.x** - Core counting workflow, dual baseline system
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 Support
|
||||||
|
|
||||||
This is a custom internal tool. Contact your system administrator for support.
|
This is a custom internal tool. Contact your system administrator for support.
|
||||||
|
|
||||||
|
|||||||
75
app.py
75
app.py
@@ -17,7 +17,8 @@ from blueprints.data_imports import data_imports_bp
|
|||||||
from blueprints.users import users_bp
|
from blueprints.users import users_bp
|
||||||
from blueprints.sessions import sessions_bp
|
from blueprints.sessions import sessions_bp
|
||||||
from blueprints.admin_locations import admin_locations_bp
|
from blueprints.admin_locations import admin_locations_bp
|
||||||
from blueprints.counting import counting_bp # Add this import
|
from blueprints.counting import counting_bp
|
||||||
|
from blueprints.cons_sheets import cons_sheets_bp
|
||||||
from utils import login_required
|
from utils import login_required
|
||||||
|
|
||||||
# Register Blueprints
|
# Register Blueprints
|
||||||
@@ -25,7 +26,8 @@ app.register_blueprint(data_imports_bp)
|
|||||||
app.register_blueprint(users_bp)
|
app.register_blueprint(users_bp)
|
||||||
app.register_blueprint(sessions_bp)
|
app.register_blueprint(sessions_bp)
|
||||||
app.register_blueprint(admin_locations_bp)
|
app.register_blueprint(admin_locations_bp)
|
||||||
app.register_blueprint(counting_bp) # Add this registration
|
app.register_blueprint(counting_bp)
|
||||||
|
app.register_blueprint(cons_sheets_bp)
|
||||||
|
|
||||||
# V1.0: Use environment variable for production, fallback to demo key for development
|
# V1.0: Use environment variable for production, fallback to demo key for development
|
||||||
app.secret_key = os.environ.get('SCANLOOK_SECRET_KEY', 'scanlook-demo-key-replace-for-production')
|
app.secret_key = os.environ.get('SCANLOOK_SECRET_KEY', 'scanlook-demo-key-replace-for-production')
|
||||||
@@ -36,20 +38,34 @@ app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=1)
|
|||||||
|
|
||||||
|
|
||||||
# 1. Define the version
|
# 1. Define the version
|
||||||
APP_VERSION = '0.10.0'
|
APP_VERSION = '0.13.2'
|
||||||
|
|
||||||
# 2. Inject it into all templates automatically
|
# 2. Inject it into all templates automatically
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_version():
|
def inject_version():
|
||||||
return dict(version=APP_VERSION)
|
return dict(version=APP_VERSION)
|
||||||
|
|
||||||
|
# Auto-initialize database if it doesn't exist
|
||||||
|
db_path = os.path.join(os.path.dirname(__file__), 'database', 'scanlook.db')
|
||||||
|
if not os.path.exists(db_path):
|
||||||
|
print("Database not found, initializing...")
|
||||||
|
from database.init_db import init_database, create_default_users
|
||||||
|
init_database()
|
||||||
|
create_default_users()
|
||||||
|
print("Database initialized!")
|
||||||
|
|
||||||
|
# Run migrations to apply any pending database changes
|
||||||
|
from migrations import run_migrations
|
||||||
|
run_migrations()
|
||||||
|
|
||||||
|
|
||||||
# ==================== ROUTES: AUTHENTICATION ====================
|
# ==================== ROUTES: AUTHENTICATION ====================
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
"""Landing page - redirect based on login status"""
|
"""Landing page - redirect based on login status"""
|
||||||
if 'user_id' in session:
|
if 'user_id' in session:
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('home'))
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
|
|
||||||
@@ -69,7 +85,7 @@ def login():
|
|||||||
session['full_name'] = user['full_name']
|
session['full_name'] = user['full_name']
|
||||||
session['role'] = user['role']
|
session['role'] = user['role']
|
||||||
flash(f'Welcome back, {user["full_name"]}!', 'success')
|
flash(f'Welcome back, {user["full_name"]}!', 'success')
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('home'))
|
||||||
else:
|
else:
|
||||||
flash('Invalid username or password', 'danger')
|
flash('Invalid username or password', 'danger')
|
||||||
|
|
||||||
@@ -84,11 +100,30 @@ def logout():
|
|||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
|
|
||||||
|
# ==================== ROUTES: HOME ====================
|
||||||
|
@app.route('/home')
|
||||||
|
@login_required
|
||||||
|
def home():
|
||||||
|
"""Module selection landing page"""
|
||||||
|
user_id = session.get('user_id')
|
||||||
|
|
||||||
|
# Get modules this user has access to
|
||||||
|
modules = query_db('''
|
||||||
|
SELECT m.module_id, m.module_name, m.module_key, m.description, m.icon
|
||||||
|
FROM Modules m
|
||||||
|
JOIN UserModules um ON m.module_id = um.module_id
|
||||||
|
WHERE um.user_id = ? AND m.is_active = 1
|
||||||
|
ORDER BY m.display_order
|
||||||
|
''', [user_id])
|
||||||
|
|
||||||
|
return render_template('home.html', modules=modules)
|
||||||
|
|
||||||
|
|
||||||
# ==================== ROUTES: DASHBOARD ====================
|
# ==================== ROUTES: DASHBOARD ====================
|
||||||
|
|
||||||
@app.route('/dashboard')
|
@app.route('/admin')
|
||||||
@login_required
|
@login_required
|
||||||
def dashboard():
|
def admin_dashboard():
|
||||||
"""Main dashboard - different views for admin vs staff"""
|
"""Main dashboard - different views for admin vs staff"""
|
||||||
role = session.get('role')
|
role = session.get('role')
|
||||||
|
|
||||||
@@ -127,32 +162,6 @@ def dashboard():
|
|||||||
|
|
||||||
return render_template('admin_dashboard.html', sessions=sessions_list, show_archived=show_archived)
|
return render_template('admin_dashboard.html', sessions=sessions_list, show_archived=show_archived)
|
||||||
|
|
||||||
else:
|
|
||||||
# Staff dashboard
|
|
||||||
active_sessions = query_db('''
|
|
||||||
SELECT session_id, session_name, session_type, created_timestamp
|
|
||||||
FROM CountSessions
|
|
||||||
WHERE status = 'active'
|
|
||||||
ORDER BY created_timestamp DESC
|
|
||||||
''')
|
|
||||||
|
|
||||||
return render_template('staff_dashboard.html', sessions=active_sessions)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/staff-mode')
|
|
||||||
@login_required
|
|
||||||
def staff_mode():
|
|
||||||
"""Allow admin/owner to switch to staff view for scanning"""
|
|
||||||
# Show staff dashboard view regardless of role
|
|
||||||
active_sessions = query_db('''
|
|
||||||
SELECT session_id, session_name, session_type, created_timestamp
|
|
||||||
FROM CountSessions
|
|
||||||
WHERE status = 'active'
|
|
||||||
ORDER BY created_timestamp DESC
|
|
||||||
''')
|
|
||||||
|
|
||||||
return render_template('staff_dashboard.html', sessions=active_sessions, is_admin_mode=True)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ==================== PWA SUPPORT ROUTES ====================
|
# ==================== PWA SUPPORT ROUTES ====================
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1120
blueprints/cons_sheets.py
Normal file
1120
blueprints/cons_sheets.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,76 @@ def get_active_session(session_id):
|
|||||||
return None
|
return None
|
||||||
return sess
|
return sess
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@counting_bp.route('/counts/admin')
|
||||||
|
@login_required
|
||||||
|
def admin_dashboard():
|
||||||
|
"""Admin dashboard for Counts module"""
|
||||||
|
# Security check: Ensure user is admin/owner
|
||||||
|
if session.get('role') not in ['owner', 'admin']:
|
||||||
|
flash('Access denied. Admin role required.', 'danger')
|
||||||
|
return redirect(url_for('counting.index'))
|
||||||
|
|
||||||
|
show_archived = request.args.get('show_archived', '0') == '1'
|
||||||
|
|
||||||
|
# This SQL was moved from app.py
|
||||||
|
if show_archived:
|
||||||
|
sessions_list = query_db('''
|
||||||
|
SELECT s.*, u.full_name as created_by_name,
|
||||||
|
COUNT(DISTINCT lc.location_count_id) as total_locations,
|
||||||
|
SUM(CASE WHEN lc.status = 'completed' THEN 1 ELSE 0 END) as completed_locations,
|
||||||
|
SUM(CASE WHEN lc.status = 'in_progress' THEN 1 ELSE 0 END) as in_progress_locations
|
||||||
|
FROM CountSessions s
|
||||||
|
LEFT JOIN Users u ON s.created_by = u.user_id
|
||||||
|
LEFT JOIN LocationCounts lc ON s.session_id = lc.session_id
|
||||||
|
WHERE s.status IN ('active', 'archived')
|
||||||
|
GROUP BY s.session_id
|
||||||
|
ORDER BY s.status ASC, s.created_timestamp DESC
|
||||||
|
''')
|
||||||
|
else:
|
||||||
|
sessions_list = query_db('''
|
||||||
|
SELECT s.*, u.full_name as created_by_name,
|
||||||
|
COUNT(DISTINCT lc.location_count_id) as total_locations,
|
||||||
|
SUM(CASE WHEN lc.status = 'completed' THEN 1 ELSE 0 END) as completed_locations,
|
||||||
|
SUM(CASE WHEN lc.status = 'in_progress' THEN 1 ELSE 0 END) as in_progress_locations
|
||||||
|
FROM CountSessions s
|
||||||
|
LEFT JOIN Users u ON s.created_by = u.user_id
|
||||||
|
LEFT JOIN LocationCounts lc ON s.session_id = lc.session_id
|
||||||
|
WHERE s.status = 'active'
|
||||||
|
GROUP BY s.session_id
|
||||||
|
ORDER BY s.created_timestamp DESC
|
||||||
|
''')
|
||||||
|
|
||||||
|
return render_template('counts/admin_dashboard.html', sessions=sessions_list, show_archived=show_archived)
|
||||||
|
|
||||||
|
|
||||||
|
@counting_bp.route('/counts')
|
||||||
|
@login_required
|
||||||
|
def index():
|
||||||
|
"""Counts module landing - show active sessions"""
|
||||||
|
# Check if user has access to this module
|
||||||
|
user_id = session.get('user_id')
|
||||||
|
has_access = query_db('''
|
||||||
|
SELECT 1 FROM UserModules um
|
||||||
|
JOIN Modules m ON um.module_id = m.module_id
|
||||||
|
WHERE um.user_id = ? AND m.module_key = 'counting' AND m.is_active = 1
|
||||||
|
''', [user_id], one=True)
|
||||||
|
|
||||||
|
if not has_access:
|
||||||
|
flash('You do not have access to this module', 'danger')
|
||||||
|
return redirect(url_for('home'))
|
||||||
|
|
||||||
|
active_sessions = query_db('''
|
||||||
|
SELECT session_id, session_name, session_type, created_timestamp
|
||||||
|
FROM CountSessions
|
||||||
|
WHERE status = 'active'
|
||||||
|
ORDER BY created_timestamp DESC
|
||||||
|
''')
|
||||||
|
|
||||||
|
return render_template('counts/staff_dashboard.html', sessions=active_sessions)
|
||||||
|
|
||||||
|
|
||||||
@counting_bp.route('/count/<int:session_id>')
|
@counting_bp.route('/count/<int:session_id>')
|
||||||
@login_required
|
@login_required
|
||||||
def count_session(session_id):
|
def count_session(session_id):
|
||||||
@@ -19,7 +89,7 @@ def count_session(session_id):
|
|||||||
|
|
||||||
if not sess:
|
if not sess:
|
||||||
flash('Session not found or not active', 'danger')
|
flash('Session not found or not active', 'danger')
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('counting.index'))
|
||||||
|
|
||||||
# Redirect to my_counts page (staff can manage multiple bins)
|
# Redirect to my_counts page (staff can manage multiple bins)
|
||||||
return redirect(url_for('counting.my_counts', session_id=session_id))
|
return redirect(url_for('counting.my_counts', session_id=session_id))
|
||||||
@@ -33,11 +103,11 @@ def my_counts(session_id):
|
|||||||
|
|
||||||
if not sess:
|
if not sess:
|
||||||
flash('Session not found', 'danger')
|
flash('Session not found', 'danger')
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('counting.index'))
|
||||||
|
|
||||||
if sess['status'] == 'archived':
|
if sess['status'] == 'archived':
|
||||||
flash('This session has been archived', 'warning')
|
flash('This session has been archived', 'warning')
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('counting.index'))
|
||||||
|
|
||||||
# Get this user's active bins
|
# Get this user's active bins
|
||||||
active_bins = query_db('''
|
active_bins = query_db('''
|
||||||
@@ -65,7 +135,7 @@ def my_counts(session_id):
|
|||||||
ORDER BY lc.end_timestamp DESC
|
ORDER BY lc.end_timestamp DESC
|
||||||
''', [session_id, session['user_id']])
|
''', [session_id, session['user_id']])
|
||||||
|
|
||||||
return render_template('my_counts.html',
|
return render_template('counts/my_counts.html',
|
||||||
count_session=sess,
|
count_session=sess,
|
||||||
active_bins=active_bins,
|
active_bins=active_bins,
|
||||||
completed_bins=completed_bins)
|
completed_bins=completed_bins)
|
||||||
@@ -78,7 +148,10 @@ def start_bin_count(session_id):
|
|||||||
sess = get_active_session(session_id)
|
sess = get_active_session(session_id)
|
||||||
if not sess:
|
if not sess:
|
||||||
flash('Session not found or archived', 'warning')
|
flash('Session not found or archived', 'warning')
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('counting.index'))
|
||||||
|
if not sess['master_baseline_timestamp']:
|
||||||
|
flash('Master File not uploaded. Please upload it before starting bins.', 'warning')
|
||||||
|
return redirect(url_for('counting.my_counts', session_id=session_id))
|
||||||
|
|
||||||
location_name = request.form.get('location_name', '').strip().upper()
|
location_name = request.form.get('location_name', '').strip().upper()
|
||||||
|
|
||||||
@@ -143,7 +216,10 @@ def count_location(session_id, location_count_id):
|
|||||||
sess = get_active_session(session_id)
|
sess = get_active_session(session_id)
|
||||||
if not sess:
|
if not sess:
|
||||||
flash('Session not found or archived', 'warning')
|
flash('Session not found or archived', 'warning')
|
||||||
return redirect(url_for('dashboard'))
|
return redirect(url_for('counting.index'))
|
||||||
|
if not sess['master_baseline_timestamp']:
|
||||||
|
flash('Master File not uploaded. Please upload it before starting bins.', 'warning')
|
||||||
|
return redirect(url_for('counting.my_counts', session_id=session_id))
|
||||||
|
|
||||||
location = query_db('''
|
location = query_db('''
|
||||||
SELECT * FROM LocationCounts
|
SELECT * FROM LocationCounts
|
||||||
@@ -187,7 +263,7 @@ def count_location(session_id, location_count_id):
|
|||||||
ORDER BY lot_number
|
ORDER BY lot_number
|
||||||
''', [session_id, location['location_name'], location_count_id])
|
''', [session_id, location['location_name'], location_count_id])
|
||||||
|
|
||||||
return render_template('count_location.html',
|
return render_template('counts/count_location.html',
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
location=location,
|
location=location,
|
||||||
scans=scans,
|
scans=scans,
|
||||||
@@ -304,8 +380,14 @@ def scan_lot(session_id, location_count_id):
|
|||||||
|
|
||||||
# Check against MASTER baseline
|
# Check against MASTER baseline
|
||||||
master = query_db('''
|
master = query_db('''
|
||||||
SELECT * FROM BaselineInventory_Master
|
SELECT
|
||||||
|
system_bin,
|
||||||
|
SUM(system_quantity) as system_quantity,
|
||||||
|
MAX(item) as item,
|
||||||
|
MAX(description) as description
|
||||||
|
FROM BaselineInventory_Master
|
||||||
WHERE session_id = ? AND lot_number = ? AND system_bin = ?
|
WHERE session_id = ? AND lot_number = ? AND system_bin = ?
|
||||||
|
GROUP BY system_bin
|
||||||
''', [session_id, lot_number, location['location_name']], one=True)
|
''', [session_id, lot_number, location['location_name']], one=True)
|
||||||
|
|
||||||
# Determine master_status (only if not a duplicate issue)
|
# Determine master_status (only if not a duplicate issue)
|
||||||
@@ -322,8 +404,16 @@ def scan_lot(session_id, location_count_id):
|
|||||||
else:
|
else:
|
||||||
# Check if lot exists in different location
|
# Check if lot exists in different location
|
||||||
master_other = query_db('''
|
master_other = query_db('''
|
||||||
SELECT * FROM BaselineInventory_Master
|
SELECT
|
||||||
|
system_bin,
|
||||||
|
SUM(system_quantity) as system_quantity,
|
||||||
|
MAX(item) as item,
|
||||||
|
MAX(description) as description
|
||||||
|
FROM BaselineInventory_Master
|
||||||
WHERE session_id = ? AND lot_number = ?
|
WHERE session_id = ? AND lot_number = ?
|
||||||
|
GROUP BY system_bin
|
||||||
|
ORDER BY system_bin
|
||||||
|
LIMIT 1
|
||||||
''', [session_id, lot_number], one=True)
|
''', [session_id, lot_number], one=True)
|
||||||
|
|
||||||
if master_other:
|
if master_other:
|
||||||
@@ -340,8 +430,16 @@ def scan_lot(session_id, location_count_id):
|
|||||||
# For duplicates, still check baseline for item info
|
# For duplicates, still check baseline for item info
|
||||||
if not master:
|
if not master:
|
||||||
master = query_db('''
|
master = query_db('''
|
||||||
SELECT * FROM BaselineInventory_Master
|
SELECT
|
||||||
|
system_bin,
|
||||||
|
SUM(system_quantity) as system_quantity,
|
||||||
|
MAX(item) as item,
|
||||||
|
MAX(description) as description
|
||||||
|
FROM BaselineInventory_Master
|
||||||
WHERE session_id = ? AND lot_number = ?
|
WHERE session_id = ? AND lot_number = ?
|
||||||
|
GROUP BY system_bin
|
||||||
|
ORDER BY system_bin
|
||||||
|
LIMIT 1
|
||||||
''', [session_id, lot_number], one=True)
|
''', [session_id, lot_number], one=True)
|
||||||
master_status = 'match' # Don't override with wrong_location for duplicates
|
master_status = 'match' # Don't override with wrong_location for duplicates
|
||||||
variance_lbs = None
|
variance_lbs = None
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ def upload_master(session_id):
|
|||||||
|
|
||||||
conn = get_db()
|
conn = get_db()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('DELETE FROM BaselineInventory_Master WHERE session_id = ?', [session_id])
|
||||||
try:
|
try:
|
||||||
stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
|
stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)
|
||||||
csv_reader = csv.DictReader(stream)
|
csv_reader = csv.DictReader(stream)
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ def manage_users():
|
|||||||
# Admins can only see staff
|
# Admins can only see staff
|
||||||
users = query_db("SELECT * FROM Users WHERE role = 'staff' ORDER BY full_name")
|
users = query_db("SELECT * FROM Users WHERE role = 'staff' ORDER BY full_name")
|
||||||
|
|
||||||
return render_template('manage_users.html', users=users)
|
# Get all active modules
|
||||||
|
modules = query_db('SELECT * FROM Modules WHERE is_active = 1 ORDER BY display_order')
|
||||||
|
|
||||||
|
return render_template('manage_users.html', users=users, modules=modules)
|
||||||
|
|
||||||
|
|
||||||
@users_bp.route('/settings/users/add', methods=['POST'])
|
@users_bp.route('/settings/users/add', methods=['POST'])
|
||||||
@@ -192,3 +195,43 @@ def delete_user(user_id):
|
|||||||
return jsonify({'success': True, 'message': 'User deleted successfully'})
|
return jsonify({'success': True, 'message': 'User deleted successfully'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'success': False, 'message': f'Error deleting user: {str(e)}'})
|
return jsonify({'success': False, 'message': f'Error deleting user: {str(e)}'})
|
||||||
|
|
||||||
|
|
||||||
|
@users_bp.route('/settings/users/<int:user_id>/modules', methods=['GET'])
|
||||||
|
@role_required('owner', 'admin')
|
||||||
|
def get_user_modules(user_id):
|
||||||
|
"""Get modules assigned to a user"""
|
||||||
|
modules = query_db('''
|
||||||
|
SELECT module_id FROM UserModules WHERE user_id = ?
|
||||||
|
''', [user_id])
|
||||||
|
|
||||||
|
module_ids = [m['module_id'] for m in modules]
|
||||||
|
return jsonify({'success': True, 'module_ids': module_ids})
|
||||||
|
|
||||||
|
|
||||||
|
@users_bp.route('/settings/users/<int:user_id>/modules', methods=['POST'])
|
||||||
|
@role_required('owner', 'admin')
|
||||||
|
def update_user_modules(user_id):
|
||||||
|
"""Update modules assigned to a user"""
|
||||||
|
data = request.get_json()
|
||||||
|
module_ids = data.get('module_ids', [])
|
||||||
|
|
||||||
|
# Verify user exists
|
||||||
|
user = query_db('SELECT user_id FROM Users WHERE user_id = ?', [user_id], one=True)
|
||||||
|
if not user:
|
||||||
|
return jsonify({'success': False, 'message': 'User not found'})
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Remove all current assignments
|
||||||
|
execute_db('DELETE FROM UserModules WHERE user_id = ?', [user_id])
|
||||||
|
|
||||||
|
# Add new assignments
|
||||||
|
for module_id in module_ids:
|
||||||
|
execute_db('''
|
||||||
|
INSERT INTO UserModules (user_id, module_id, granted_by)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
''', [user_id, module_id, session['user_id']])
|
||||||
|
|
||||||
|
return jsonify({'success': True, 'message': 'Modules updated'})
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({'success': False, 'message': str(e)})
|
||||||
@@ -166,6 +166,109 @@ def init_database():
|
|||||||
)
|
)
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# MODULE SYSTEM TABLES
|
||||||
|
# ============================================
|
||||||
|
|
||||||
|
# Modules Table - Available feature modules
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS Modules (
|
||||||
|
module_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
module_name TEXT NOT NULL,
|
||||||
|
module_key TEXT UNIQUE NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
icon TEXT,
|
||||||
|
is_active INTEGER DEFAULT 1,
|
||||||
|
display_order INTEGER DEFAULT 0
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
# UserModules Table - Module access per user
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS UserModules (
|
||||||
|
user_module_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
module_id INTEGER NOT NULL,
|
||||||
|
granted_by INTEGER,
|
||||||
|
granted_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES Users(user_id),
|
||||||
|
FOREIGN KEY (module_id) REFERENCES Modules(module_id),
|
||||||
|
FOREIGN KEY (granted_by) REFERENCES Users(user_id),
|
||||||
|
UNIQUE(user_id, module_id)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# CONSUMPTION SHEETS MODULE TABLES
|
||||||
|
# ============================================
|
||||||
|
|
||||||
|
# cons_processes - Master list of consumption sheet process types
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS cons_processes (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
process_key TEXT UNIQUE NOT NULL,
|
||||||
|
process_name TEXT NOT NULL,
|
||||||
|
template_file BLOB,
|
||||||
|
template_filename TEXT,
|
||||||
|
rows_per_page INTEGER DEFAULT 30,
|
||||||
|
detail_start_row INTEGER DEFAULT 10,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
created_by INTEGER NOT NULL,
|
||||||
|
is_active INTEGER DEFAULT 1,
|
||||||
|
FOREIGN KEY (created_by) REFERENCES Users(user_id)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
# cons_process_fields - Custom field definitions for each process
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS cons_process_fields (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
process_id INTEGER NOT NULL,
|
||||||
|
table_type TEXT NOT NULL CHECK(table_type IN ('header', 'detail')),
|
||||||
|
field_name TEXT NOT NULL,
|
||||||
|
field_label TEXT NOT NULL,
|
||||||
|
field_type TEXT NOT NULL CHECK(field_type IN ('TEXT', 'INTEGER', 'REAL', 'DATE', 'DATETIME')),
|
||||||
|
max_length INTEGER,
|
||||||
|
is_required INTEGER DEFAULT 0,
|
||||||
|
is_duplicate_key INTEGER DEFAULT 0,
|
||||||
|
is_active INTEGER DEFAULT 1,
|
||||||
|
sort_order INTEGER DEFAULT 0,
|
||||||
|
excel_cell TEXT,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (process_id) REFERENCES cons_processes(id)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
# cons_sessions - Staff scanning sessions
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS cons_sessions (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
process_id INTEGER NOT NULL,
|
||||||
|
created_by INTEGER NOT NULL,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
status TEXT DEFAULT 'active' CHECK(status IN ('active', 'archived')),
|
||||||
|
FOREIGN KEY (process_id) REFERENCES cons_processes(id),
|
||||||
|
FOREIGN KEY (created_by) REFERENCES Users(user_id)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
# Note: Header values still use flexible key-value storage
|
||||||
|
# cons_session_header_values - Flexible storage for header field values
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS cons_session_header_values (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
session_id INTEGER NOT NULL,
|
||||||
|
field_id INTEGER NOT NULL,
|
||||||
|
field_value TEXT,
|
||||||
|
FOREIGN KEY (session_id) REFERENCES cons_sessions(id),
|
||||||
|
FOREIGN KEY (field_id) REFERENCES cons_process_fields(id)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
# Note: Detail tables are created dynamically per process as cons_proc_{process_key}_details
|
||||||
|
# They include system columns (id, session_id, scanned_by, scanned_at, duplicate_status,
|
||||||
|
# duplicate_info, comment, is_deleted) plus custom fields defined in cons_process_fields
|
||||||
|
|
||||||
# Create Indexes
|
# Create Indexes
|
||||||
# MASTER baseline indexes
|
# MASTER baseline indexes
|
||||||
cursor.execute('CREATE INDEX IF NOT EXISTS idx_baseline_master_lot ON BaselineInventory_Master(session_id, lot_number)')
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_baseline_master_lot ON BaselineInventory_Master(session_id, lot_number)')
|
||||||
@@ -182,6 +285,13 @@ def init_database():
|
|||||||
|
|
||||||
# Note: No indexes on BaselineInventory_Current needed - UNIQUE constraint handles lookups
|
# Note: No indexes on BaselineInventory_Current needed - UNIQUE constraint handles lookups
|
||||||
|
|
||||||
|
# Consumption Sheets indexes
|
||||||
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_process_fields_process ON cons_process_fields(process_id, table_type)')
|
||||||
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_process_fields_active ON cons_process_fields(process_id, is_active)')
|
||||||
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_sessions_process ON cons_sessions(process_id, status)')
|
||||||
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_cons_sessions_user ON cons_sessions(created_by, status)')
|
||||||
|
# Note: Detail table indexes are created dynamically when process tables are created
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
print(f"✅ Database initialized at: {DB_PATH}")
|
print(f"✅ Database initialized at: {DB_PATH}")
|
||||||
@@ -217,6 +327,52 @@ def create_default_users():
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def create_default_modules():
|
||||||
|
"""Create default modules and assign to admin users"""
|
||||||
|
conn = sqlite3.connect(DB_PATH)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Define default modules
|
||||||
|
default_modules = [
|
||||||
|
('Inventory Counts', 'counting', 'Cycle counts and physical inventory', 'fa-clipboard-check', 1, 1),
|
||||||
|
('Consumption Sheets', 'cons_sheets', 'Production consumption tracking', 'fa-clipboard-list', 1, 2),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Insert modules (ignore if already exist)
|
||||||
|
for module in default_modules:
|
||||||
|
try:
|
||||||
|
cursor.execute('''
|
||||||
|
INSERT INTO Modules (module_name, module_key, description, icon, is_active, display_order)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
|
''', module)
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
pass # Module already exists
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Auto-assign all modules to owner and admin users
|
||||||
|
cursor.execute('SELECT user_id FROM Users WHERE role IN ("owner", "admin")')
|
||||||
|
admin_users = cursor.fetchall()
|
||||||
|
|
||||||
|
cursor.execute('SELECT module_id FROM Modules')
|
||||||
|
all_modules = cursor.fetchall()
|
||||||
|
|
||||||
|
for user in admin_users:
|
||||||
|
for module in all_modules:
|
||||||
|
try:
|
||||||
|
cursor.execute('''
|
||||||
|
INSERT INTO UserModules (user_id, module_id)
|
||||||
|
VALUES (?, ?)
|
||||||
|
''', (user[0], module[0]))
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
pass # Assignment already exists
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
print("✅ Default modules created and assigned to admin users")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
init_database()
|
init_database()
|
||||||
create_default_users()
|
create_default_users()
|
||||||
|
create_default_modules()
|
||||||
245
migrations.py
Normal file
245
migrations.py
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
"""
|
||||||
|
ScanLook Database Migration System
|
||||||
|
|
||||||
|
Simple migration system that tracks and applies database changes.
|
||||||
|
Each migration has a version number and an up() function.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
from migrations import run_migrations
|
||||||
|
run_migrations() # Call on app startup
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
|
||||||
|
DB_PATH = os.path.join(os.path.dirname(__file__), 'database', 'scanlook.db')
|
||||||
|
|
||||||
|
|
||||||
|
def get_db():
|
||||||
|
"""Get database connection"""
|
||||||
|
conn = sqlite3.connect(DB_PATH)
|
||||||
|
conn.row_factory = sqlite3.Row
|
||||||
|
return conn
|
||||||
|
|
||||||
|
|
||||||
|
def init_migrations_table():
|
||||||
|
"""Create the migrations tracking table if it doesn't exist"""
|
||||||
|
conn = get_db()
|
||||||
|
conn.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||||
|
version INTEGER PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
applied_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def get_applied_migrations():
|
||||||
|
"""Get list of already-applied migration versions"""
|
||||||
|
conn = get_db()
|
||||||
|
try:
|
||||||
|
rows = conn.execute('SELECT version FROM schema_migrations ORDER BY version').fetchall()
|
||||||
|
return [row['version'] for row in rows]
|
||||||
|
except:
|
||||||
|
return []
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def record_migration(version, name):
|
||||||
|
"""Record that a migration was applied"""
|
||||||
|
conn = get_db()
|
||||||
|
conn.execute('INSERT INTO schema_migrations (version, name) VALUES (?, ?)', [version, name])
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def column_exists(table, column):
|
||||||
|
"""Check if a column exists in a table"""
|
||||||
|
conn = get_db()
|
||||||
|
cursor = conn.execute(f'PRAGMA table_info({table})')
|
||||||
|
columns = [row[1] for row in cursor.fetchall()]
|
||||||
|
conn.close()
|
||||||
|
return column in columns
|
||||||
|
|
||||||
|
|
||||||
|
def table_exists(table):
|
||||||
|
"""Check if a table exists"""
|
||||||
|
conn = get_db()
|
||||||
|
cursor = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?", [table])
|
||||||
|
exists = cursor.fetchone() is not None
|
||||||
|
conn.close()
|
||||||
|
return exists
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# MIGRATIONS
|
||||||
|
# ============================================
|
||||||
|
# Add new migrations to this list.
|
||||||
|
# Each migration is a tuple: (version, name, up_function)
|
||||||
|
#
|
||||||
|
# RULES:
|
||||||
|
# - Never modify an existing migration
|
||||||
|
# - Always add new migrations at the end with the next version number
|
||||||
|
# - Check if changes are needed before applying (idempotent)
|
||||||
|
# ============================================
|
||||||
|
|
||||||
|
def migration_001_add_modules_tables():
|
||||||
|
"""Add Modules and UserModules tables"""
|
||||||
|
conn = get_db()
|
||||||
|
|
||||||
|
if not table_exists('Modules'):
|
||||||
|
conn.execute('''
|
||||||
|
CREATE TABLE Modules (
|
||||||
|
module_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
module_name TEXT NOT NULL,
|
||||||
|
module_key TEXT UNIQUE NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
icon TEXT,
|
||||||
|
is_active INTEGER DEFAULT 1,
|
||||||
|
display_order INTEGER DEFAULT 0
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
print(" Created Modules table")
|
||||||
|
|
||||||
|
if not table_exists('UserModules'):
|
||||||
|
conn.execute('''
|
||||||
|
CREATE TABLE UserModules (
|
||||||
|
user_module_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
module_id INTEGER NOT NULL,
|
||||||
|
granted_by INTEGER,
|
||||||
|
granted_timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES Users(user_id),
|
||||||
|
FOREIGN KEY (module_id) REFERENCES Modules(module_id),
|
||||||
|
FOREIGN KEY (granted_by) REFERENCES Users(user_id),
|
||||||
|
UNIQUE(user_id, module_id)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
print(" Created UserModules table")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def migration_002_add_usermodules_granted_columns():
|
||||||
|
"""Add granted_by and granted_timestamp to UserModules if missing"""
|
||||||
|
conn = get_db()
|
||||||
|
|
||||||
|
if table_exists('UserModules'):
|
||||||
|
if not column_exists('UserModules', 'granted_by'):
|
||||||
|
conn.execute('ALTER TABLE UserModules ADD COLUMN granted_by INTEGER')
|
||||||
|
print(" Added granted_by column to UserModules")
|
||||||
|
|
||||||
|
if not column_exists('UserModules', 'granted_timestamp'):
|
||||||
|
conn.execute('ALTER TABLE UserModules ADD COLUMN granted_timestamp DATETIME')
|
||||||
|
print(" Added granted_timestamp column to UserModules")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def migration_003_add_default_modules():
|
||||||
|
"""Add default modules if they don't exist"""
|
||||||
|
conn = get_db()
|
||||||
|
|
||||||
|
# Check if modules exist
|
||||||
|
existing = conn.execute('SELECT COUNT(*) as cnt FROM Modules').fetchone()
|
||||||
|
|
||||||
|
if existing['cnt'] == 0:
|
||||||
|
conn.execute('''
|
||||||
|
INSERT INTO Modules (module_name, module_key, description, icon, is_active, display_order)
|
||||||
|
VALUES ('Inventory Counts', 'counting', 'Cycle counts and physical inventory', 'fa-clipboard-check', 1, 1)
|
||||||
|
''')
|
||||||
|
conn.execute('''
|
||||||
|
INSERT INTO Modules (module_name, module_key, description, icon, is_active, display_order)
|
||||||
|
VALUES ('Consumption Sheets', 'cons_sheets', 'Production consumption tracking', 'fa-clipboard-list', 1, 2)
|
||||||
|
''')
|
||||||
|
print(" Added default modules")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def migration_004_assign_modules_to_admins():
|
||||||
|
"""Auto-assign all modules to owner and admin users"""
|
||||||
|
conn = get_db()
|
||||||
|
|
||||||
|
# Get admin users
|
||||||
|
admins = conn.execute('SELECT user_id FROM Users WHERE role IN ("owner", "admin")').fetchall()
|
||||||
|
modules = conn.execute('SELECT module_id FROM Modules').fetchall()
|
||||||
|
|
||||||
|
for user in admins:
|
||||||
|
for module in modules:
|
||||||
|
try:
|
||||||
|
conn.execute('''
|
||||||
|
INSERT INTO UserModules (user_id, module_id)
|
||||||
|
VALUES (?, ?)
|
||||||
|
''', [user['user_id'], module['module_id']])
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
pass # Already assigned
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
print(" Assigned modules to admin users")
|
||||||
|
|
||||||
|
|
||||||
|
def migration_005_add_cons_process_fields_duplicate_key():
|
||||||
|
"""Add is_duplicate_key column to cons_process_fields if missing"""
|
||||||
|
conn = get_db()
|
||||||
|
|
||||||
|
if table_exists('cons_process_fields'):
|
||||||
|
if not column_exists('cons_process_fields', 'is_duplicate_key'):
|
||||||
|
conn.execute('ALTER TABLE cons_process_fields ADD COLUMN is_duplicate_key INTEGER DEFAULT 0')
|
||||||
|
print(" Added is_duplicate_key column to cons_process_fields")
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
# List of all migrations in order
|
||||||
|
MIGRATIONS = [
|
||||||
|
(1, 'add_modules_tables', migration_001_add_modules_tables),
|
||||||
|
(2, 'add_usermodules_granted_columns', migration_002_add_usermodules_granted_columns),
|
||||||
|
(3, 'add_default_modules', migration_003_add_default_modules),
|
||||||
|
(4, 'assign_modules_to_admins', migration_004_assign_modules_to_admins),
|
||||||
|
(5, 'add_cons_process_fields_duplicate_key', migration_005_add_cons_process_fields_duplicate_key),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def run_migrations():
|
||||||
|
"""Run all pending migrations"""
|
||||||
|
print("🔄 Checking database migrations...")
|
||||||
|
|
||||||
|
# Make sure migrations table exists
|
||||||
|
init_migrations_table()
|
||||||
|
|
||||||
|
# Get already-applied migrations
|
||||||
|
applied = get_applied_migrations()
|
||||||
|
|
||||||
|
# Run pending migrations
|
||||||
|
pending = [(v, n, f) for v, n, f in MIGRATIONS if v not in applied]
|
||||||
|
|
||||||
|
if not pending:
|
||||||
|
print("✅ Database is up to date")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"📦 Running {len(pending)} migration(s)...")
|
||||||
|
|
||||||
|
for version, name, func in pending:
|
||||||
|
print(f"\n Migration {version}: {name}")
|
||||||
|
try:
|
||||||
|
func()
|
||||||
|
record_migration(version, name)
|
||||||
|
print(f" ✅ Migration {version} complete")
|
||||||
|
except Exception as e:
|
||||||
|
print(f" ❌ Migration {version} failed: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
print("\n✅ All migrations complete")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run_migrations()
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
Flask==3.1.2
|
Flask==3.1.2
|
||||||
Werkzeug==3.1.5
|
Werkzeug==3.1.5
|
||||||
|
openpyxl
|
||||||
@@ -2152,3 +2152,134 @@ body {
|
|||||||
.session-actions-header {
|
.session-actions-header {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ==================== MODULE GRID (Home Page) ==================== */
|
||||||
|
|
||||||
|
.module-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||||
|
gap: var(--space-xl);
|
||||||
|
margin-top: var(--space-xl);
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-card {
|
||||||
|
background: var(--color-surface);
|
||||||
|
border: 2px solid var(--color-border);
|
||||||
|
border-radius: var(--radius-xl);
|
||||||
|
padding: var(--space-2xl) var(--space-xl);
|
||||||
|
text-decoration: none;
|
||||||
|
text-align: center;
|
||||||
|
transition: var(--transition);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-md);
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-card:hover {
|
||||||
|
border-color: var(--color-primary);
|
||||||
|
transform: translateY(-4px);
|
||||||
|
box-shadow: var(--shadow-glow), var(--shadow-lg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-icon {
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
background: var(--color-primary-glow);
|
||||||
|
border: 2px solid var(--color-primary);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 2.5rem;
|
||||||
|
color: var(--color-primary);
|
||||||
|
transition: var(--transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-card:hover .module-icon {
|
||||||
|
background: var(--color-primary);
|
||||||
|
color: var(--color-bg);
|
||||||
|
box-shadow: 0 0 30px var(--color-primary-glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-name {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-text);
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-desc {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
margin: 0;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
/* ==================== MODAL SCROLL FIX ==================== */
|
||||||
|
|
||||||
|
.modal {
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: var(--space-xl) 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-content {
|
||||||
|
max-height: none;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==================== ADMIN MODULES SECTION ==================== */
|
||||||
|
|
||||||
|
.modules-section {
|
||||||
|
margin-bottom: var(--space-2xl);
|
||||||
|
padding-bottom: var(--space-xl);
|
||||||
|
border-bottom: 2px solid var(--color-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-title {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
margin-bottom: var(--space-lg);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modules-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||||
|
gap: var(--space-lg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-card-link {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modules-grid .module-card {
|
||||||
|
padding: var(--space-lg);
|
||||||
|
border-radius: var(--radius-lg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modules-grid .module-icon {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modules-grid .module-name {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modules-grid .module-desc {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-card-active {
|
||||||
|
border-color: var(--color-primary);
|
||||||
|
background: var(--color-primary-glow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.module-card-active .module-icon {
|
||||||
|
background: var(--color-primary);
|
||||||
|
color: var(--color-bg);
|
||||||
|
}
|
||||||
@@ -4,101 +4,28 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="dashboard-container">
|
<div class="dashboard-container">
|
||||||
<!-- Mode Selector -->
|
<div class="dashboard-header" style="margin-top: var(--space-lg);">
|
||||||
<div class="mode-selector">
|
<div class="header-left" style="display: flex; align-items: center; gap: var(--space-md);">
|
||||||
<button class="mode-btn mode-btn-active" data-href="{{ url_for('dashboard') }}">
|
<a href="{{ url_for('home') }}" class="btn btn-secondary btn-sm">
|
||||||
👔 Admin Console
|
<i class="fa-solid fa-arrow-left"></i> Back to Home
|
||||||
</button>
|
|
||||||
<button class="mode-btn" data-href="{{ url_for('staff_mode') }}">
|
|
||||||
📦 Scanning Mode
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
document.querySelectorAll('.mode-selector button').forEach(btn => {
|
|
||||||
btn.addEventListener('click', function() {
|
|
||||||
window.location.href = this.getAttribute('data-href');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class="dashboard-header">
|
|
||||||
<div class="header-left">
|
|
||||||
<h1 class="page-title">Admin Dashboard</h1>
|
|
||||||
<label class="filter-toggle">
|
|
||||||
<input type="checkbox" id="showArchived" {% if show_archived %}checked{% endif %} onchange="toggleArchived()">
|
|
||||||
<span class="filter-label">Show Archived</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<a href="{{ url_for('sessions.create_session') }}" class="btn btn-primary">
|
|
||||||
<span class="btn-icon">+</span> New Session
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
<h1 class="page-title" style="margin-bottom: 0;">Admin Dashboard</h1>
|
||||||
|
|
||||||
<script>
|
|
||||||
function toggleArchived() {
|
|
||||||
const checked = document.getElementById('showArchived').checked;
|
|
||||||
window.location.href = '{{ url_for("dashboard") }}' + (checked ? '?show_archived=1' : '');
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{% 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>
|
</div>
|
||||||
|
|
||||||
<div class="session-meta">
|
<div class="modules-section">
|
||||||
<div class="meta-item">
|
<h2 class="section-title">Modules</h2>
|
||||||
<span class="meta-label">Created:</span>
|
<div class="modules-grid">
|
||||||
<span class="meta-value">{{ session.created_timestamp[:16] }}</span>
|
<a href="{{ url_for('counting.admin_dashboard') }}" class="module-card">
|
||||||
</div>
|
<div class="module-icon">📊</div> <h3 class="module-name">Counts</h3>
|
||||||
<div class="meta-item">
|
<p class="module-desc">Cycle counts & physical inventory</p>
|
||||||
<span class="meta-label">By:</span>
|
</a>
|
||||||
<span class="meta-value">{{ session.created_by_name }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="session-actions">
|
<a href="{{ url_for('cons_sheets.admin_processes') }}" class="module-card module-card-link">
|
||||||
<a href="{{ url_for('sessions.session_detail', session_id=session.session_id) }}" class="btn btn-secondary btn-block">
|
<div class="module-icon">📝</div> <h3 class="module-name">Consumption Sheets</h3>
|
||||||
View Details
|
<p class="module-desc">Production consumption tracking</p>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
|
||||||
<a href="{{ url_for('sessions.create_session') }}" class="btn btn-primary">
|
|
||||||
Create First Session
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/mobile.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/mobile.css') }}">
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/scanner.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/scanner.css') }}">
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||||
|
|
||||||
{% block extra_css %}{% endblock %}
|
{% block extra_css %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
<nav class="navbar">
|
<nav class="navbar">
|
||||||
<div class="nav-content">
|
<div class="nav-content">
|
||||||
<div class="nav-left">
|
<div class="nav-left">
|
||||||
<a href="{{ url_for('dashboard') }}" class="logo">
|
<a href="{{ url_for('home') }}" class="logo">
|
||||||
<span class="logo-scan">SCAN</span><span class="logo-look">LOOK</span>
|
<span class="logo-scan">SCAN</span><span class="logo-look">LOOK</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
81
templates/cons_sheets/add_field.html
Normal file
81
templates/cons_sheets/add_field.html
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{% 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 %}
|
||||||
73
templates/cons_sheets/admin_processes.html
Normal file
73
templates/cons_sheets/admin_processes.html
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Consumption Sheets - Admin - ScanLook{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="dashboard-container">
|
||||||
|
<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('admin_dashboard') }}" class="btn btn-secondary btn-sm">
|
||||||
|
<i class="fa-solid fa-arrow-left"></i> Back to Admin
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1 class="page-title" style="margin-bottom: 0;">Consumption Sheets</h1>
|
||||||
|
<p class="page-subtitle" style="margin-bottom: 0;">Manage process types and templates</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a href="{{ url_for('cons_sheets.create_process') }}" class="btn btn-primary">
|
||||||
|
<span class="btn-icon">+</span> New Process
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if processes %}
|
||||||
|
<div class="sessions-grid">
|
||||||
|
{% for process in processes %}
|
||||||
|
<div class="session-card">
|
||||||
|
<div class="session-card-header">
|
||||||
|
<h3 class="session-name">{{ process.process_name }}</h3>
|
||||||
|
<span class="session-type-badge">
|
||||||
|
{{ process.field_count or 0 }} fields
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="session-meta">
|
||||||
|
<div class="meta-item">
|
||||||
|
<span class="meta-label">Key:</span>
|
||||||
|
<span class="meta-value" style="font-family: var(--font-mono);">{{ process.process_key }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="meta-item">
|
||||||
|
<span class="meta-label">Created:</span>
|
||||||
|
<span class="meta-value">{{ process.created_at[:16] if process.created_at else 'N/A' }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="meta-item">
|
||||||
|
<span class="meta-label">By:</span>
|
||||||
|
<span class="meta-value">{{ process.created_by_name or 'Unknown' }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="meta-item">
|
||||||
|
<span class="meta-label">Template:</span>
|
||||||
|
<span class="meta-value">{{ '✅ Uploaded' if process.template_file else '❌ None' }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="session-actions">
|
||||||
|
<a href="{{ url_for('cons_sheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-block">
|
||||||
|
Configure
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="empty-state">
|
||||||
|
<div class="empty-icon">📝</div>
|
||||||
|
<h2 class="empty-title">No Processes Defined</h2>
|
||||||
|
<p class="empty-text">Create a process type to get started (e.g., "AD WIP")</p>
|
||||||
|
<a href="{{ url_for('cons_sheets.create_process') }}" class="btn btn-primary">
|
||||||
|
Create First Process
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
36
templates/cons_sheets/create_process.html
Normal file
36
templates/cons_sheets/create_process.html
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{% 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 %}
|
||||||
80
templates/cons_sheets/edit_field.html
Normal file
80
templates/cons_sheets/edit_field.html
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
{% 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 %}
|
||||||
99
templates/cons_sheets/new_session.html
Normal file
99
templates/cons_sheets/new_session.html
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
{% 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 %}
|
||||||
245
templates/cons_sheets/process_detail.html
Normal file
245
templates/cons_sheets/process_detail.html
Normal file
@@ -0,0 +1,245 @@
|
|||||||
|
{% 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 %}
|
||||||
173
templates/cons_sheets/process_fields.html
Normal file
173
templates/cons_sheets/process_fields.html
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
{% 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 %}
|
||||||
269
templates/cons_sheets/process_template.html
Normal file
269
templates/cons_sheets/process_template.html
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
{% 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</label>
|
||||||
|
<input type="number" id="rows_per_page" name="rows_per_page"
|
||||||
|
value="{{ process.rows_per_page or 30 }}" min="1" max="500" class="form-input">
|
||||||
|
<p class="form-hint">Max detail rows before starting a new page</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="500" 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 %}
|
||||||
417
templates/cons_sheets/scan_session.html
Normal file
417
templates/cons_sheets/scan_session.html
Normal file
@@ -0,0 +1,417 @@
|
|||||||
|
{% 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 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>
|
||||||
|
|
||||||
|
<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 %}
|
||||||
166
templates/cons_sheets/staff_index.html
Normal file
166
templates/cons_sheets/staff_index.html
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
{% 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 %}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="count-container">
|
<div class="count-container">
|
||||||
<div class="count-header">
|
<div class="count-header">
|
||||||
<a href="{{ url_for('dashboard') }}" class="breadcrumb">← Back</a>
|
<a href="{{ url_for('admin_dashboard') }}" class="breadcrumb">← Back</a>
|
||||||
<h1 class="page-title">{{ session.session_name }}</h1>
|
<h1 class="page-title">{{ session.session_name }}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
102
templates/counts/admin_dashboard.html
Normal file
102
templates/counts/admin_dashboard.html
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
{% 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 %}
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
onclick="openScanDetail('{{ scan.entry_id }}')">
|
onclick="openScanDetail('{{ scan.entry_id }}')">
|
||||||
<div class="scan-row-lot">{{ scan.lot_number }}</div>
|
<div class="scan-row-lot">{{ scan.lot_number }}</div>
|
||||||
<div class="scan-row-item">{{ scan.item or 'N/A' }}</div>
|
<div class="scan-row-item">{{ scan.item or 'N/A' }}</div>
|
||||||
<div class="scan-row-weight">{{ scan.actual_weight }} lbs</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">
|
<div class="scan-row-status">
|
||||||
{% if scan.duplicate_status == '01' or scan.duplicate_status == '04' %}
|
{% if scan.duplicate_status == '01' or scan.duplicate_status == '04' %}
|
||||||
<span class="status-dot status-dot-blue"></span> Duplicate
|
<span class="status-dot status-dot-blue"></span> Duplicate
|
||||||
@@ -185,6 +185,23 @@ let currentLotNumber = '';
|
|||||||
let isDuplicateConfirmed = false;
|
let isDuplicateConfirmed = false;
|
||||||
let isProcessing = 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
|
// Lot scan handler
|
||||||
document.getElementById('lotScanForm').addEventListener('submit', function(e) {
|
document.getElementById('lotScanForm').addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -388,7 +405,7 @@ function addScanToList(data, weight) {
|
|||||||
statusDot = 'orange';
|
statusDot = 'orange';
|
||||||
}
|
}
|
||||||
} else if (data.master_status === 'match') {
|
} else if (data.master_status === 'match') {
|
||||||
if (data.master_expected_weight && Math.abs(weight - data.master_expected_weight) >= 0.01) {
|
if (data.master_expected_weight && weightsDiffer(weight, data.master_expected_weight)) {
|
||||||
statusClass = 'weight_discrepancy';
|
statusClass = 'weight_discrepancy';
|
||||||
statusText = 'Weight Off';
|
statusText = 'Weight Off';
|
||||||
statusDot = 'orange';
|
statusDot = 'orange';
|
||||||
@@ -414,7 +431,7 @@ function addScanToList(data, weight) {
|
|||||||
scanRow.innerHTML = `
|
scanRow.innerHTML = `
|
||||||
<div class="scan-row-lot">${currentLotNumber}</div>
|
<div class="scan-row-lot">${currentLotNumber}</div>
|
||||||
<div class="scan-row-item">${data.item || 'N/A'}</div>
|
<div class="scan-row-item">${data.item || 'N/A'}</div>
|
||||||
<div class="scan-row-weight">${weight} lbs</div>
|
<div class="scan-row-weight">${formatWeight(weight)} lbs</div>
|
||||||
<div class="scan-row-status">
|
<div class="scan-row-status">
|
||||||
<span class="status-dot status-dot-${statusDot}"></span> ${statusText}
|
<span class="status-dot status-dot-${statusDot}"></span> ${statusText}
|
||||||
</div>
|
</div>
|
||||||
@@ -451,7 +468,7 @@ function displayScanDetail(scan) {
|
|||||||
// Check for weight discrepancy (Tolerance 0.01)
|
// Check for weight discrepancy (Tolerance 0.01)
|
||||||
let isWeightOff = false;
|
let isWeightOff = false;
|
||||||
if (scan.master_status === 'match' && scan.master_expected_weight) {
|
if (scan.master_status === 'match' && scan.master_expected_weight) {
|
||||||
if (Math.abs(scan.actual_weight - scan.master_expected_weight) >= 0.01) {
|
if (weightsDiffer(scan.actual_weight, scan.master_expected_weight)) {
|
||||||
isWeightOff = true;
|
isWeightOff = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,7 +519,7 @@ function displayScanDetail(scan) {
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label">Weight (lbs)</label>
|
<label class="form-label">Weight (lbs)</label>
|
||||||
<input type="number" id="editWeight" class="form-input" value="${scan.actual_weight}" step="0.01" min="0" inputmode="decimal">
|
<input type="number" id="editWeight" class="form-input" value="${formatWeight(scan.actual_weight)}" step="0.01" min="0" inputmode="decimal">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label">Comment</label>
|
<label class="form-label">Comment</label>
|
||||||
@@ -6,13 +6,22 @@
|
|||||||
<div class="dashboard-container">
|
<div class="dashboard-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url_for('dashboard') }}" class="breadcrumb">← Back to Dashboard</a>
|
<a href="{{ url_for('counting.index') }}" class="breadcrumb">← Back to Sessions</a>
|
||||||
<h1 class="page-title">My Active Counts</h1>
|
<h1 class="page-title">My Active Counts</h1>
|
||||||
<p class="page-subtitle">{{ count_session.session_name }}</p>
|
<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>
|
</div>
|
||||||
|
{% if count_session.master_baseline_timestamp %}
|
||||||
<button class="btn btn-primary" onclick="showStartBinModal()">
|
<button class="btn btn-primary" onclick="showStartBinModal()">
|
||||||
<span class="btn-icon">+</span> Start New Bin
|
<span class="btn-icon">+</span> Start New Bin
|
||||||
</button>
|
</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>
|
</div>
|
||||||
|
|
||||||
<!-- Active Bins -->
|
<!-- Active Bins -->
|
||||||
@@ -7,16 +7,19 @@
|
|||||||
<!-- Mode Selector (only for admins) -->
|
<!-- Mode Selector (only for admins) -->
|
||||||
{% if session.role in ['owner', 'admin'] %}
|
{% if session.role in ['owner', 'admin'] %}
|
||||||
<div class="mode-selector">
|
<div class="mode-selector">
|
||||||
<a href="{{ url_for('dashboard') }}" class="mode-btn">
|
<a href="{{ url_for('admin_dashboard') }}" class="mode-btn">
|
||||||
Admin Console
|
👔 Admin Console
|
||||||
</a>
|
</a>
|
||||||
<button class="mode-btn mode-btn-active">
|
<button class="mode-btn mode-btn-active">
|
||||||
Scanning Mode
|
📦 Scanning Mode
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="dashboard-header">
|
<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>
|
<h1 class="page-title">Select Count Session</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<a href="{{ url_for('dashboard') }}" class="btn btn-secondary">Cancel</a>
|
<a href="{{ url_for('admin_dashboard') }}" class="btn btn-secondary">Cancel</a>
|
||||||
<button type="submit" class="btn btn-primary">Create Session</button>
|
<button type="submit" class="btn btn-primary">Create Session</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
42
templates/home.html
Normal file
42
templates/home.html
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Home - ScanLook{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="dashboard-container">
|
||||||
|
|
||||||
|
<!-- Admin Button (only for admins/owners) -->
|
||||||
|
{% if session.role in ['owner', 'admin'] %}
|
||||||
|
<div class="mode-selector">
|
||||||
|
<a href="{{ url_for('admin_dashboard') }}" class="mode-btn">
|
||||||
|
👔 Admin Console
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="dashboard-header">
|
||||||
|
<h1 class="page-title">Welcome, {{ session.full_name }}</h1>
|
||||||
|
<p class="page-subtitle">Select a module to get started</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% if modules %}
|
||||||
|
<div class="module-grid">
|
||||||
|
{% for m in modules %}
|
||||||
|
<a href="{{ url_for(m.module_key + '.index') }}" class="module-card">
|
||||||
|
<div class="module-icon">
|
||||||
|
<i class="fa-solid {{ m.icon }}"></i>
|
||||||
|
</div>
|
||||||
|
<h3 class="module-name">{{ m.module_name }}</h3>
|
||||||
|
<p class="module-desc">{{ m.description }}</p>
|
||||||
|
</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="empty-state">
|
||||||
|
<div class="empty-icon">🔒</div>
|
||||||
|
<h2 class="empty-title">No Modules Available</h2>
|
||||||
|
<p class="empty-text">You don't have access to any modules. Please contact your administrator.</p>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -129,6 +129,18 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">Module Access</label>
|
||||||
|
<div class="module-checkboxes" id="moduleCheckboxes">
|
||||||
|
{% for module in modules %}
|
||||||
|
<label class="checkbox-label">
|
||||||
|
<input type="checkbox" name="modules" value="{{ module.module_id }}" class="module-checkbox">
|
||||||
|
{{ module.module_name }}
|
||||||
|
</label>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="modal-actions">
|
<div class="modal-actions">
|
||||||
<button type="button" class="btn btn-secondary" onclick="closeUserModal()">Cancel</button>
|
<button type="button" class="btn btn-secondary" onclick="closeUserModal()">Cancel</button>
|
||||||
<button type="submit" class="btn btn-primary">Save User</button>
|
<button type="submit" class="btn btn-primary">Save User</button>
|
||||||
@@ -162,9 +174,10 @@ function openAddUser() {
|
|||||||
document.getElementById('passwordOptional').style.display = 'none';
|
document.getElementById('passwordOptional').style.display = 'none';
|
||||||
document.getElementById('password').required = true;
|
document.getElementById('password').required = true;
|
||||||
document.getElementById('activeToggleGroup').style.display = 'none';
|
document.getElementById('activeToggleGroup').style.display = 'none';
|
||||||
|
// Uncheck all modules for new user
|
||||||
|
document.querySelectorAll('.module-checkbox').forEach(cb => cb.checked = false);
|
||||||
document.getElementById('userModal').style.display = 'flex';
|
document.getElementById('userModal').style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEditUser(userId) {
|
function openEditUser(userId) {
|
||||||
editingUserId = userId;
|
editingUserId = userId;
|
||||||
document.getElementById('modalTitle').textContent = 'Edit User';
|
document.getElementById('modalTitle').textContent = 'Edit User';
|
||||||
@@ -191,7 +204,22 @@ function openEditUser(userId) {
|
|||||||
const isEditingSelf = user.user_id === {{ session.user_id }};
|
const isEditingSelf = user.user_id === {{ session.user_id }};
|
||||||
document.getElementById('role').disabled = isEditingSelf;
|
document.getElementById('role').disabled = isEditingSelf;
|
||||||
|
|
||||||
|
// Load user's modules
|
||||||
|
fetch('/settings/users/' + userId + '/modules')
|
||||||
|
.then(resp => resp.json())
|
||||||
|
.then(moduleData => {
|
||||||
|
// Uncheck all first
|
||||||
|
document.querySelectorAll('.module-checkbox').forEach(cb => cb.checked = false);
|
||||||
|
// Check assigned modules
|
||||||
|
if (moduleData.success) {
|
||||||
|
moduleData.module_ids.forEach(id => {
|
||||||
|
const cb = document.querySelector(`.module-checkbox[value="${id}"]`);
|
||||||
|
if (cb) cb.checked = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Show modal after modules are loaded
|
||||||
document.getElementById('userModal').style.display = 'flex';
|
document.getElementById('userModal').style.display = 'flex';
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
alert(data.message);
|
alert(data.message);
|
||||||
}
|
}
|
||||||
@@ -201,7 +229,6 @@ function openEditUser(userId) {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeUserModal() {
|
function closeUserModal() {
|
||||||
document.getElementById('userModal').style.display = 'none';
|
document.getElementById('userModal').style.display = 'none';
|
||||||
document.getElementById('userForm').reset();
|
document.getElementById('userForm').reset();
|
||||||
@@ -234,8 +261,23 @@ document.getElementById('userForm').addEventListener('submit', function(e) {
|
|||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
|
// Save modules if editing existing user
|
||||||
|
if (userId) {
|
||||||
|
const moduleIds = Array.from(document.querySelectorAll('.module-checkbox:checked'))
|
||||||
|
.map(cb => parseInt(cb.value));
|
||||||
|
|
||||||
|
fetch(`/settings/users/${userId}/modules`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ module_ids: moduleIds })
|
||||||
|
}).then(() => {
|
||||||
closeUserModal();
|
closeUserModal();
|
||||||
location.reload();
|
location.reload();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
closeUserModal();
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
alert(data.message);
|
alert(data.message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<div class="session-detail-container">
|
<div class="session-detail-container">
|
||||||
<div class="session-detail-header">
|
<div class="session-detail-header">
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url_for('dashboard') }}{% if count_session.status == 'archived' %}?show_archived=1{% endif %}" class="breadcrumb">← Back to Dashboard</a>
|
<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">
|
<h1 class="page-title">
|
||||||
{{ count_session.session_name }}
|
{{ count_session.session_name }}
|
||||||
{% if count_session.status == 'archived' %}<span class="archived-badge">ARCHIVED</span>{% endif %}
|
{% if count_session.status == 'archived' %}<span class="archived-badge">ARCHIVED</span>{% endif %}
|
||||||
@@ -694,7 +694,7 @@ function archiveSession() {
|
|||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
window.location.href = '{{ url_for("dashboard") }}';
|
window.location.href = '{{ url_for("admin_dashboard") }}';
|
||||||
} else {
|
} else {
|
||||||
alert(data.message || 'Error archiving session');
|
alert(data.message || 'Error archiving session');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user