Initial commit: Product Slip Manager
This commit is contained in:
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.egg-info/
|
||||
dist/
|
||||
build/
|
||||
*.egg
|
||||
|
||||
# Virtual environment
|
||||
venv/
|
||||
.venv/
|
||||
|
||||
# Django
|
||||
*.sqlite3
|
||||
db.sqlite3
|
||||
staticfiles/
|
||||
media/
|
||||
|
||||
# Environment
|
||||
.env
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Docker
|
||||
data/
|
||||
|
||||
# LibreOffice lock files
|
||||
.~lock.*
|
||||
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy project
|
||||
COPY . .
|
||||
|
||||
# Collect static files
|
||||
RUN python manage.py collectstatic --noinput
|
||||
|
||||
# Create data directory for SQLite
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["sh", "-c", "python manage.py migrate --noinput && python manage.py seed_products --skip-existing && gunicorn config.wsgi:application --bind 0.0.0.0:8000 --workers 2 --timeout 120"]
|
||||
BIN
ETICHETTE PER INKS(دون خط 4 تایی).xlsx
Normal file
BIN
ETICHETTE PER INKS(دون خط 4 تایی).xlsx
Normal file
Binary file not shown.
252
PLAN.md
Normal file
252
PLAN.md
Normal file
@@ -0,0 +1,252 @@
|
||||
# Product Slip Printing App — Implementation Plan
|
||||
|
||||
## 1. Overview
|
||||
|
||||
Web app for printing variable data onto pre-printed ink canister labels.
|
||||
Two users on the same LAN: one enters orders, another prints slips.
|
||||
|
||||
**Stack**: Django Ninja + SQLite + Docker (Gunicorn + Nginx)
|
||||
|
||||
---
|
||||
|
||||
## 2. Excel Analysis
|
||||
|
||||
File: `ETICHETTE PER INKS(دون خط 4 تایی).xlsx` — 5 sheets, one per product.
|
||||
|
||||
### Products Found
|
||||
|
||||
| Sheet | Code | Description | Default Net Weight |
|
||||
|-------|------|-------------|--------------------|
|
||||
| ICJ408 | ICJ/408 | DIGITAL INK RED BROWN | 5 kg |
|
||||
| ICJ407 | ICJ/407 | DIGITAL INK RED BROWN | 5 kg |
|
||||
| ICJ309 | ICJ/309 | DIGITAL INK CYAN | 10 kg |
|
||||
| ICJ630 | ICJ/EH630 | DIGITAL INK BLACK | 5 kg |
|
||||
| ICJ308 | ICJ/308 | DIGITAL INK BLUE | 20 kg |
|
||||
|
||||
### A4 Page Layout — 4 Slips per Page (2×2 Grid)
|
||||
|
||||
```
|
||||
┌──────────────────────┬──────────────────────┐
|
||||
│ SLIP 1 (Cols A-I) │ SLIP 2 (Cols K-S) │
|
||||
│ Rows 9-39 │ Rows 9-39 │
|
||||
├──────────────────────┼──────────────────────┤
|
||||
│ SLIP 3 (Cols A-I) │ SLIP 4 (Cols K-S) │
|
||||
│ Rows 53-83 │ Rows 53-83 │
|
||||
└──────────────────────┴──────────────────────┘
|
||||
```
|
||||
|
||||
### What We Print (4 variable fields only)
|
||||
|
||||
The physical labels come pre-printed with company info, product code,
|
||||
description, and all fixed text. We only overprint these values:
|
||||
|
||||
| Field | Cell Position (Slip 1) | Example |
|
||||
|-------|----------------------|---------|
|
||||
| Batch# | C18 | 1028/26 |
|
||||
| Date | G18 | 05/05/2026 |
|
||||
| Net Weight | C20 | 20 |
|
||||
| Next Control Date | F19 | 05/11/2026 |
|
||||
|
||||
Page: A4 portrait, ~1cm margins all sides, paperSize=9.
|
||||
|
||||
---
|
||||
|
||||
## 3. Architecture
|
||||
|
||||
```
|
||||
LAN
|
||||
├── Machine A (Data Entry) ──→ http://server/entry
|
||||
├── Machine B (Printer) ──→ http://server/print
|
||||
│
|
||||
└── Server (Docker)
|
||||
├── nginx:alpine (port 80) ──→ reverse proxy
|
||||
└── python:3.12-slim (port 8000)
|
||||
├── Django Ninja (API + Views)
|
||||
├── Gunicorn (WSGI)
|
||||
├── WhiteNoise (static files)
|
||||
└── SQLite (/app/data/db.sqlite3)
|
||||
```
|
||||
|
||||
**Framework Choice: Django Ninja** (over Flask and plain Django)
|
||||
- Django ORM + built-in migrations + free admin panel
|
||||
- FastAPI-style Pydantic schemas for clean API validation
|
||||
- Auto-generated Swagger docs at `/api/docs`
|
||||
- Less boilerplate than Flask+SQLAlchemy+Marshmallow
|
||||
|
||||
---
|
||||
|
||||
## 4. Database Schema
|
||||
|
||||
```sql
|
||||
CREATE TABLE products (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
code TEXT NOT NULL UNIQUE,
|
||||
description TEXT NOT NULL,
|
||||
default_net_weight REAL DEFAULT 5.0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE orders (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
product_id INTEGER NOT NULL REFERENCES products(id),
|
||||
batch_number TEXT NOT NULL,
|
||||
production_date DATE NOT NULL,
|
||||
next_control_date DATE NOT NULL,
|
||||
net_weight REAL NOT NULL,
|
||||
canister_count INTEGER NOT NULL,
|
||||
pages_needed INTEGER NOT NULL,
|
||||
status TEXT DEFAULT 'pending',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
printed_at TIMESTAMP NULL
|
||||
);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. API Endpoints (Django Ninja)
|
||||
|
||||
| Method | Endpoint | Purpose |
|
||||
|--------|----------|---------|
|
||||
| GET | `/` | Redirect to `/entry` |
|
||||
| GET | `/entry` | Data entry panel |
|
||||
| GET | `/print` | Print queue panel |
|
||||
| GET | `/calibrate` | Calibration page |
|
||||
| GET | `/api/products` | List products |
|
||||
| POST | `/api/products` | Add new product |
|
||||
| GET | `/api/orders` | List orders (?status=pending) |
|
||||
| POST | `/api/orders` | Create order |
|
||||
| PATCH | `/api/orders/{id}` | Update status |
|
||||
| DELETE | `/api/orders/{id}` | Delete order |
|
||||
| GET | `/print-page/{id}` | Printable slip page |
|
||||
| GET | `/api/docs` | Auto Swagger UI |
|
||||
| GET | `/admin/` | Django admin panel |
|
||||
|
||||
---
|
||||
|
||||
## 6. Frontend Panels
|
||||
|
||||
### Data Entry (`/entry`)
|
||||
- Product dropdown (from catalog) + "Add New Product"
|
||||
- Batch # input
|
||||
- Date picker (default: today)
|
||||
- Next control date (auto: date + 6 months, editable)
|
||||
- Net weight (auto from product default, editable)
|
||||
- Canister count → auto-calculates pages = ceil(count/4)
|
||||
- Submit → adds to print queue
|
||||
- Recent orders table with status
|
||||
|
||||
### Print Queue (`/print`)
|
||||
- Pending orders list (auto-refreshes every 10s)
|
||||
- Print button → opens printable page → browser print dialog
|
||||
- Mark Done button
|
||||
- Print history table
|
||||
|
||||
### Print Page (`/print-page/{id}`)
|
||||
- CSS @media print with absolute positioning
|
||||
- Only prints 4 variable values at exact positions
|
||||
- Multiple pages if order needs > 1 page (4 slips/page)
|
||||
|
||||
### Calibration (`/calibrate`)
|
||||
- Cross-hair markers at field positions
|
||||
- Print on blank paper, overlay on pre-printed label to check alignment
|
||||
|
||||
---
|
||||
|
||||
## 7. i18n (English / Persian LTR)
|
||||
|
||||
| Key | English | Persian |
|
||||
|-----|---------|---------|
|
||||
| app_title | Product Slip Manager | مدیریت برچسب محصول |
|
||||
| new_order | New Order | سفارش جدید |
|
||||
| product | Product | محصول |
|
||||
| batch_number | Batch # | شماره بچ |
|
||||
| date | Date | تاریخ |
|
||||
| next_control | Next Control Date | تاریخ کنترل بعدی |
|
||||
| net_weight | Net Weight (kg) | وزن خالص (کیلوگرم) |
|
||||
| canisters | Canisters | تعداد قوطی |
|
||||
| pages_needed | Pages Needed | تعداد صفحات |
|
||||
| add_to_queue | Add to Print Queue | افزودن به صف چاپ |
|
||||
| print_queue | Print Queue | صف چاپ |
|
||||
| pending | Pending | در انتظار |
|
||||
| done | Done | انجام شده |
|
||||
| print | Print | چاپ |
|
||||
| mark_done | Mark as Done | تایید چاپ |
|
||||
| cancel | Cancel | لغو |
|
||||
|
||||
Persian text direction: LTR (as requested).
|
||||
|
||||
---
|
||||
|
||||
## 8. UI Design
|
||||
|
||||
- **Theme**: Dark navy (#0f172a) with glassmorphism panels
|
||||
- **Accent**: Blue gradient (#3b82f6 → #60a5fa)
|
||||
- **Font**: Inter (Google Fonts), JetBrains Mono for data values
|
||||
- **Effects**: backdrop-filter blur, smooth transitions, pulse on pending badges
|
||||
- **Status colors**: amber=pending, green=done, red=cancelled
|
||||
|
||||
---
|
||||
|
||||
## 9. File Structure
|
||||
|
||||
```
|
||||
product-slip/
|
||||
├── docker-compose.yml ✅ created
|
||||
├── Dockerfile ✅ created
|
||||
├── nginx.conf ✅ created
|
||||
├── requirements.txt ✅ created
|
||||
├── manage.py ✅ created
|
||||
├── .gitignore ✅ created
|
||||
├── config/ ✅ created
|
||||
│ ├── __init__.py
|
||||
│ ├── settings.py
|
||||
│ ├── urls.py
|
||||
│ └── wsgi.py
|
||||
├── slips/ ⬜ TODO
|
||||
│ ├── __init__.py
|
||||
│ ├── models.py
|
||||
│ ├── admin.py
|
||||
│ ├── schemas.py
|
||||
│ ├── api.py
|
||||
│ ├── views.py
|
||||
│ ├── management/
|
||||
│ │ └── commands/
|
||||
│ │ └── seed_products.py
|
||||
│ ├── templates/slips/
|
||||
│ │ ├── base.html
|
||||
│ │ ├── entry.html
|
||||
│ │ ├── print.html
|
||||
│ │ ├── print_page.html
|
||||
│ │ └── calibrate.html
|
||||
│ └── static/slips/
|
||||
│ ├── css/style.css
|
||||
│ └── js/
|
||||
│ ├── i18n.js
|
||||
│ ├── entry.js
|
||||
│ └── print.js
|
||||
└── data/ (Docker volume, gitignored)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 10. Docker Stack
|
||||
|
||||
```yaml
|
||||
services:
|
||||
app: # Django + Gunicorn on port 8000
|
||||
nginx: # Reverse proxy on port 80
|
||||
volumes:
|
||||
db_data: # SQLite persistence
|
||||
```
|
||||
|
||||
Startup: migrate → seed products → gunicorn
|
||||
|
||||
---
|
||||
|
||||
## 11. Defaults & Assumptions
|
||||
|
||||
- Date format: DD/MM/YYYY (European, matching Excel)
|
||||
- Products: pre-defined dropdown + "Add New" option
|
||||
- Quantity: user enters canister count, app calculates pages = ceil(n/4)
|
||||
- Net weight: auto-fills from product, editable per order
|
||||
- Next control: auto-calculated as date + 6 months, editable
|
||||
77
README.md
Normal file
77
README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Product Slip Manager
|
||||
|
||||
A self-hosted web application for tracking production orders and generating pixel-perfect labels for canisters and boxes.
|
||||
|
||||
## Features
|
||||
- **Fast Data Entry**: Instantly calculate the required number of canister and box labels based on total order weight.
|
||||
- **Dynamic Print Layouts**: Automatically generate print-ready A4 pages correctly formatted for pre-printed sticker sheets.
|
||||
- **Print Queue**: Manage and track pending label batches with real-time updates.
|
||||
- **Bilingual Interface**: Seamlessly switch between English and Persian (LTR).
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Installation & Deployment
|
||||
|
||||
The application is fully containerized using Docker, meaning it can be deployed on any machine with Docker installed.
|
||||
|
||||
### Prerequisites
|
||||
1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) (Windows/Mac) or Docker Engine (Linux).
|
||||
2. Ensure you have the project source code downloaded and extracted.
|
||||
|
||||
### Starting the Server
|
||||
1. Open a terminal or command prompt and navigate to the project directory:
|
||||
```bash
|
||||
cd path/to/product-slip
|
||||
```
|
||||
2. Start the application stack using Docker Compose:
|
||||
```bash
|
||||
docker compose up -d --build
|
||||
```
|
||||
3. The server is now running! You can access the application from any device on the same local network:
|
||||
- If you are on the same machine: Open your browser and go to `http://localhost`
|
||||
- If you are on a different machine on the same network: Find the host computer's local IP address (e.g., `192.168.1.15`) and go to `http://192.168.1.15`
|
||||
|
||||
### Stopping the Server
|
||||
To safely stop the application without losing data:
|
||||
```bash
|
||||
docker compose down
|
||||
```
|
||||
*(Note: Your database is stored safely in the `./data` folder and will persist between restarts).*
|
||||
|
||||
---
|
||||
|
||||
## 🖨️ Printer Calibration Guide
|
||||
|
||||
Because the application prints dynamic text directly over your physical, pre-printed A4 label sheets, the printer's alignment must be exact. Different browsers and physical printers feed paper with slight millimeter variances.
|
||||
|
||||
Follow these steps to calibrate the alignment for your specific printer:
|
||||
|
||||
### 1. Print the Calibration Sheet
|
||||
1. Open the application and navigate to the **Calibrate** tab in the top menu.
|
||||
2. Load a **blank** piece of A4 paper into your printer.
|
||||
3. Click the "Print Calibration Sheet" button to print it out.
|
||||
|
||||
### 2. Check the Alignment
|
||||
1. Take your printed blank calibration sheet.
|
||||
2. Place it perfectly behind one of your **actual pre-printed label sheets**.
|
||||
3. Hold them both up to a light source (like a window or lamp).
|
||||
4. Look for the crosshairs (`┼`). They should align perfectly inside the target boxes (Batch, Date, Next Control, and Weight).
|
||||
|
||||
### 3. Adjusting the Millimeters (If Necessary)
|
||||
If the text is printing slightly too high, too low, or too far to a side, you can adjust the CSS margins in the codebase to shift the text.
|
||||
|
||||
1. Open the file: `slips/templates/slips/print_page.html`
|
||||
2. Scroll to the `<style>` block at the top, and find the `.var-field` CSS section.
|
||||
3. You will see absolute positioning values in millimeters (`mm`), for example:
|
||||
```css
|
||||
.val-batch { top: 15mm; left: 40mm; }
|
||||
```
|
||||
4. **Adjust the numbers**:
|
||||
- To move text **DOWN**: Increase the `top` value (e.g., `15mm` -> `17mm`).
|
||||
- To move text **RIGHT**: Increase the `left` value (e.g., `40mm` -> `42mm`).
|
||||
5. Save the file.
|
||||
6. Restart the Docker container so the changes take effect:
|
||||
```bash
|
||||
docker compose restart app
|
||||
```
|
||||
7. Print a new calibration sheet and test again until perfect!
|
||||
1
config/__init__.py
Normal file
1
config/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# config package
|
||||
77
config/settings.py
Normal file
77
config/settings.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'dev-secret-key-change-in-production')
|
||||
|
||||
DEBUG = os.environ.get('DJANGO_DEBUG', '1') == '1'
|
||||
|
||||
ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', '*').split(',')
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'slips',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'config.urls'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
'DIRS': [],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'config.wsgi.application'
|
||||
|
||||
# Database - SQLite, stored in /app/data/ for Docker volume persistence
|
||||
db_path = os.environ.get('DB_PATH', str(BASE_DIR / 'data' / 'db.sqlite3'))
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': db_path,
|
||||
}
|
||||
}
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = []
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
TIME_ZONE = 'Asia/Tehran'
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||
STORAGES = {
|
||||
'staticfiles': {
|
||||
'BACKEND': 'whitenoise.storage.CompressedManifestStaticFilesStorage',
|
||||
},
|
||||
}
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
14
config/urls.py
Normal file
14
config/urls.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from slips.api import api
|
||||
from slips import views
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('api/', api.urls),
|
||||
path('', views.index, name='index'),
|
||||
path('entry/', views.entry, name='entry'),
|
||||
path('print/', views.print_queue, name='print_queue'),
|
||||
path('print-page/<int:order_id>/', views.print_page, name='print_page'),
|
||||
path('calibrate/', views.calibrate, name='calibrate'),
|
||||
]
|
||||
5
config/wsgi.py
Normal file
5
config/wsgi.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import os
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
application = get_wsgi_application()
|
||||
30
docker-compose.yml
Normal file
30
docker-compose.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- db_data:/app/data
|
||||
environment:
|
||||
- DJANGO_SECRET_KEY=change-me-in-production-use-a-real-secret
|
||||
- DJANGO_DEBUG=0
|
||||
- DJANGO_ALLOWED_HOSTS=*
|
||||
networks:
|
||||
- web
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "80:80"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
depends_on:
|
||||
- app
|
||||
networks:
|
||||
- web
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
|
||||
networks:
|
||||
web:
|
||||
22
manage.py
Normal file
22
manage.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
13
nginx.conf
Normal file
13
nginx.conf
Normal file
@@ -0,0 +1,13 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
client_max_body_size 10M;
|
||||
|
||||
location / {
|
||||
proxy_pass http://app:8000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
django>=5.1,<5.3
|
||||
django-ninja>=1.7,<2.0
|
||||
gunicorn>=22.0,<24.0
|
||||
whitenoise>=6.7,<7.0
|
||||
2
slips/__init__.py
Normal file
2
slips/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# slips app
|
||||
default_app_config = 'slips.apps.SlipsConfig'
|
||||
17
slips/admin.py
Normal file
17
slips/admin.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from django.contrib import admin
|
||||
from .models import Product, Order
|
||||
|
||||
|
||||
@admin.register(Product)
|
||||
class ProductAdmin(admin.ModelAdmin):
|
||||
list_display = ['code', 'description', 'default_net_weight', 'created_at']
|
||||
search_fields = ['code', 'description']
|
||||
|
||||
|
||||
@admin.register(Order)
|
||||
class OrderAdmin(admin.ModelAdmin):
|
||||
list_display = ['id', 'product', 'batch_number', 'total_weight', 'canister_count',
|
||||
'box_count', 'status', 'created_at']
|
||||
list_filter = ['status', 'product']
|
||||
search_fields = ['batch_number', 'product__code']
|
||||
readonly_fields = ['canister_count', 'box_count', 'canister_pages', 'box_pages']
|
||||
65
slips/api.py
Normal file
65
slips/api.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from typing import List, Optional
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils import timezone
|
||||
from ninja import NinjaAPI, Query
|
||||
|
||||
from .models import Product, Order
|
||||
from .schemas import ProductOut, ProductIn, OrderOut, OrderIn, OrderStatusIn
|
||||
|
||||
api = NinjaAPI(title='Product Slip API', version='1.0.0', urls_namespace='slips_api')
|
||||
|
||||
|
||||
# ─── Products ────────────────────────────────────────────
|
||||
|
||||
@api.get('/products', response=List[ProductOut], tags=['Products'])
|
||||
def list_products(request):
|
||||
return Product.objects.all()
|
||||
|
||||
|
||||
@api.post('/products', response={201: ProductOut}, tags=['Products'])
|
||||
def create_product(request, payload: ProductIn):
|
||||
product = Product.objects.create(**payload.dict())
|
||||
return 201, product
|
||||
|
||||
|
||||
# ─── Orders ──────────────────────────────────────────────
|
||||
|
||||
@api.get('/orders', response=List[OrderOut], tags=['Orders'])
|
||||
def list_orders(request, status: Optional[str] = Query(None)):
|
||||
qs = Order.objects.select_related('product').all()
|
||||
if status:
|
||||
qs = qs.filter(status=status)
|
||||
return qs
|
||||
|
||||
|
||||
@api.post('/orders', response={201: OrderOut}, tags=['Orders'])
|
||||
def create_order(request, payload: OrderIn):
|
||||
product = get_object_or_404(Product, id=payload.product_id)
|
||||
order = Order(
|
||||
product=product,
|
||||
batch_number=payload.batch_number,
|
||||
production_date=payload.production_date,
|
||||
next_control_date=payload.next_control_date,
|
||||
total_weight=payload.total_weight,
|
||||
canister_weight=payload.canister_weight,
|
||||
canisters_per_box=payload.canisters_per_box,
|
||||
)
|
||||
order.save()
|
||||
return 201, order
|
||||
|
||||
|
||||
@api.patch('/orders/{order_id}', response=OrderOut, tags=['Orders'])
|
||||
def update_order_status(request, order_id: int, payload: OrderStatusIn):
|
||||
order = get_object_or_404(Order, id=order_id)
|
||||
order.status = payload.status
|
||||
if payload.status == 'done':
|
||||
order.printed_at = timezone.now()
|
||||
order.save()
|
||||
return order
|
||||
|
||||
|
||||
@api.delete('/orders/{order_id}', response={204: None}, tags=['Orders'])
|
||||
def delete_order(request, order_id: int):
|
||||
order = get_object_or_404(Order, id=order_id)
|
||||
order.delete()
|
||||
return 204, None
|
||||
7
slips/apps.py
Normal file
7
slips/apps.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SlipsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'slips'
|
||||
verbose_name = 'Product Slips'
|
||||
1
slips/management/__init__.py
Normal file
1
slips/management/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# management package
|
||||
1
slips/management/commands/__init__.py
Normal file
1
slips/management/commands/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# commands package
|
||||
43
slips/management/commands/seed_products.py
Normal file
43
slips/management/commands/seed_products.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from slips.models import Product
|
||||
|
||||
|
||||
SEED_PRODUCTS = [
|
||||
{'code': 'ICJ/408', 'description': 'DIGITAL INK RED BROWN', 'default_net_weight': 5},
|
||||
{'code': 'ICJ/407', 'description': 'DIGITAL INK RED BROWN', 'default_net_weight': 5},
|
||||
{'code': 'ICJ/309', 'description': 'DIGITAL INK CYAN', 'default_net_weight': 10},
|
||||
{'code': 'ICJ/EH630', 'description': 'DIGITAL INK BLACK', 'default_net_weight': 5},
|
||||
{'code': 'ICJ/308', 'description': 'DIGITAL INK BLUE', 'default_net_weight': 20},
|
||||
]
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Seed the database with initial product data from Excel'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--skip-existing',
|
||||
action='store_true',
|
||||
help='Skip products that already exist',
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
created_count = 0
|
||||
for product_data in SEED_PRODUCTS:
|
||||
if options['skip_existing']:
|
||||
_, created = Product.objects.get_or_create(
|
||||
code=product_data['code'],
|
||||
defaults=product_data,
|
||||
)
|
||||
else:
|
||||
Product.objects.update_or_create(
|
||||
code=product_data['code'],
|
||||
defaults=product_data,
|
||||
)
|
||||
created = True
|
||||
if created:
|
||||
created_count += 1
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f'Seeded {created_count} products ({len(SEED_PRODUCTS)} total)')
|
||||
)
|
||||
48
slips/migrations/0001_initial.py
Normal file
48
slips/migrations/0001_initial.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# Generated by Django 5.2.17 on 2026-09-30 06:38
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Product',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('code', models.CharField(max_length=50, unique=True)),
|
||||
('description', models.CharField(max_length=200)),
|
||||
('default_net_weight', models.FloatField(default=5.0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['code'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Order',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('batch_number', models.CharField(max_length=50)),
|
||||
('production_date', models.DateField(default=django.utils.timezone.now)),
|
||||
('next_control_date', models.DateField()),
|
||||
('net_weight', models.FloatField()),
|
||||
('canister_count', models.PositiveIntegerField()),
|
||||
('pages_needed', models.PositiveIntegerField(editable=False)),
|
||||
('status', models.CharField(choices=[('pending', 'Pending'), ('printing', 'Printing'), ('done', 'Done'), ('cancelled', 'Cancelled')], default='pending', max_length=20)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('printed_at', models.DateTimeField(blank=True, null=True)),
|
||||
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to='slips.product')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['-created_at'],
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,56 @@
|
||||
# Generated by Django 5.2.17 on 2026-09-30 09:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('slips', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='order',
|
||||
name='net_weight',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='order',
|
||||
name='pages_needed',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='box_count',
|
||||
field=models.PositiveIntegerField(default=0, editable=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='box_pages',
|
||||
field=models.PositiveIntegerField(default=0, editable=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='canister_pages',
|
||||
field=models.PositiveIntegerField(default=0, editable=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='canister_weight',
|
||||
field=models.FloatField(default=5),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='canisters_per_box',
|
||||
field=models.PositiveIntegerField(default=4),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='total_weight',
|
||||
field=models.FloatField(default=0),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='order',
|
||||
name='canister_count',
|
||||
field=models.PositiveIntegerField(default=0, editable=False),
|
||||
),
|
||||
]
|
||||
0
slips/migrations/__init__.py
Normal file
0
slips/migrations/__init__.py
Normal file
56
slips/models.py
Normal file
56
slips/models.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import math
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
class Product(models.Model):
|
||||
code = models.CharField(max_length=50, unique=True)
|
||||
description = models.CharField(max_length=200)
|
||||
default_net_weight = models.FloatField(default=5.0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['code']
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.code} — {self.description}"
|
||||
|
||||
|
||||
class Order(models.Model):
|
||||
STATUS_CHOICES = [
|
||||
('pending', 'Pending'),
|
||||
('printing', 'Printing'),
|
||||
('done', 'Done'),
|
||||
('cancelled', 'Cancelled'),
|
||||
]
|
||||
|
||||
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='orders')
|
||||
batch_number = models.CharField(max_length=50)
|
||||
production_date = models.DateField(default=timezone.now)
|
||||
next_control_date = models.DateField()
|
||||
total_weight = models.FloatField(default=0)
|
||||
canister_weight = models.FloatField(default=5)
|
||||
canisters_per_box = models.PositiveIntegerField(default=4)
|
||||
|
||||
# Calculated fields
|
||||
canister_count = models.PositiveIntegerField(editable=False, default=0)
|
||||
box_count = models.PositiveIntegerField(editable=False, default=0)
|
||||
canister_pages = models.PositiveIntegerField(editable=False, default=0)
|
||||
box_pages = models.PositiveIntegerField(editable=False, default=0)
|
||||
|
||||
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
printed_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
|
||||
def __str__(self):
|
||||
return f"Order #{self.id} — {self.product.code} — {self.batch_number}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.canister_count = math.ceil(self.total_weight / self.canister_weight)
|
||||
self.box_count = math.ceil(self.canister_count / self.canisters_per_box)
|
||||
self.canister_pages = math.ceil(self.canister_count / 4)
|
||||
self.box_pages = math.ceil(self.box_count / 4)
|
||||
super().save(*args, **kwargs)
|
||||
68
slips/schemas.py
Normal file
68
slips/schemas.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from datetime import date
|
||||
from typing import Optional
|
||||
from ninja import Schema
|
||||
|
||||
|
||||
class ProductOut(Schema):
|
||||
id: int
|
||||
code: str
|
||||
description: str
|
||||
default_net_weight: float
|
||||
|
||||
|
||||
class ProductIn(Schema):
|
||||
code: str
|
||||
description: str
|
||||
default_net_weight: float = 5.0
|
||||
|
||||
|
||||
class OrderIn(Schema):
|
||||
product_id: int
|
||||
batch_number: str
|
||||
production_date: date
|
||||
next_control_date: date
|
||||
total_weight: float
|
||||
canister_weight: float
|
||||
canisters_per_box: int
|
||||
|
||||
|
||||
class OrderOut(Schema):
|
||||
id: int
|
||||
product_id: int
|
||||
product_code: str
|
||||
product_description: str
|
||||
batch_number: str
|
||||
production_date: date
|
||||
next_control_date: date
|
||||
total_weight: float
|
||||
canister_weight: float
|
||||
canisters_per_box: int
|
||||
canister_count: int
|
||||
box_count: int
|
||||
canister_pages: int
|
||||
box_pages: int
|
||||
status: str
|
||||
created_at: str
|
||||
printed_at: Optional[str] = None
|
||||
|
||||
@staticmethod
|
||||
def resolve_product_code(obj):
|
||||
return obj.product.code
|
||||
|
||||
@staticmethod
|
||||
def resolve_product_description(obj):
|
||||
return obj.product.description
|
||||
|
||||
@staticmethod
|
||||
def resolve_created_at(obj):
|
||||
return obj.created_at.strftime('%d/%m/%Y %H:%M')
|
||||
|
||||
@staticmethod
|
||||
def resolve_printed_at(obj):
|
||||
if obj.printed_at:
|
||||
return obj.printed_at.strftime('%d/%m/%Y %H:%M')
|
||||
return None
|
||||
|
||||
|
||||
class OrderStatusIn(Schema):
|
||||
status: str
|
||||
433
slips/static/slips/css/style.css
Normal file
433
slips/static/slips/css/style.css
Normal file
@@ -0,0 +1,433 @@
|
||||
/* Base Variables */
|
||||
:root {
|
||||
--bg-primary: #0f172a;
|
||||
--bg-secondary: #1e293b;
|
||||
--bg-glass: rgba(30, 41, 59, 0.7);
|
||||
--accent: #3b82f6;
|
||||
--accent-glow: #60a5fa;
|
||||
--success: #10b981;
|
||||
--warning: #f59e0b;
|
||||
--danger: #ef4444;
|
||||
--text-primary: #f1f5f9;
|
||||
--text-secondary: #94a3b8;
|
||||
--border: rgba(148, 163, 184, 0.1);
|
||||
|
||||
--font-sans: 'Inter', sans-serif;
|
||||
--font-mono: 'JetBrains Mono', monospace;
|
||||
}
|
||||
|
||||
/* Reset & Base */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-sans);
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
line-height: 1.5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
/* Navigation */
|
||||
.navbar {
|
||||
background: var(--bg-glass);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
border-bottom: 1px solid var(--border);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.nav-container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 1rem 2rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.nav-logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
text-decoration: none;
|
||||
color: var(--text-primary);
|
||||
font-weight: 700;
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.nav-links {
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: var(--text-secondary);
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
transition: color 0.2s;
|
||||
padding: 0.5rem 0;
|
||||
}
|
||||
|
||||
.nav-link:hover, .nav-link.active {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.nav-link.active {
|
||||
border-bottom: 2px solid var(--accent);
|
||||
}
|
||||
|
||||
/* Layout */
|
||||
.main-content {
|
||||
max-width: 1200px;
|
||||
margin: 2rem auto;
|
||||
padding: 0 2rem;
|
||||
}
|
||||
|
||||
.page-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1.5fr;
|
||||
gap: 2rem;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
/* Print queue spans full width */
|
||||
.print-queue-layout {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
/* Cards & Glassmorphism */
|
||||
.card {
|
||||
background: var(--bg-secondary);
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--border);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.glass-card {
|
||||
background: var(--bg-glass);
|
||||
backdrop-filter: blur(16px);
|
||||
-webkit-backdrop-filter: blur(16px);
|
||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
padding: 1.5rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Forms */
|
||||
form {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.form-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
input, select {
|
||||
background: rgba(15, 23, 42, 0.5);
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text-primary);
|
||||
padding: 0.75rem 1rem;
|
||||
border-radius: 6px;
|
||||
font-family: inherit;
|
||||
font-size: 1rem;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
input:focus, select:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
||||
}
|
||||
|
||||
.computed-value {
|
||||
padding: 0.75rem 1rem;
|
||||
background: rgba(59, 130, 246, 0.1);
|
||||
border-radius: 6px;
|
||||
color: var(--accent-glow);
|
||||
font-weight: 600;
|
||||
font-family: var(--font-mono);
|
||||
}
|
||||
|
||||
.sub-panel {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
padding: 1rem;
|
||||
border-radius: 8px;
|
||||
margin-top: 0.5rem;
|
||||
border-left: 2px solid var(--accent);
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
border: none;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 0.5rem 1rem;
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 1rem 2rem;
|
||||
font-size: 1.125rem;
|
||||
}
|
||||
|
||||
.btn-accent {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-accent:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.btn-glow {
|
||||
box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
|
||||
}
|
||||
|
||||
.btn-glow:hover {
|
||||
box-shadow: 0 0 25px rgba(59, 130, 246, 0.6);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
background: transparent;
|
||||
color: var(--text-secondary);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.btn-ghost:hover {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
color: var(--danger);
|
||||
border-color: rgba(239, 68, 68, 0.3);
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
.table-wrap {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.data-table th, .data-table td {
|
||||
padding: 1rem 1.5rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.875rem;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.data-table tbody tr {
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.data-table tbody tr:hover {
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
color: var(--text-secondary);
|
||||
padding: 3rem !important;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Badges */
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.badge-pending { background: rgba(245, 158, 11, 0.1); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
|
||||
.badge-done { background: rgba(16, 185, 129, 0.1); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
|
||||
.badge-cancelled { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }
|
||||
.badge-accent { background: rgba(59, 130, 246, 0.1); color: var(--accent-glow); border: 1px solid rgba(59, 130, 246, 0.2); }
|
||||
.badge-neutral { background: rgba(255, 255, 255, 0.05); color: var(--text-secondary); border: 1px solid var(--border); }
|
||||
|
||||
.card-badge {
|
||||
background: rgba(0,0,0,0.3);
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Print Queue Grid */
|
||||
.queue-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||
gap: 1.5rem;
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.queue-item {
|
||||
background: rgba(15, 23, 42, 0.4);
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.queue-item:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
|
||||
border-color: rgba(59, 130, 246, 0.3);
|
||||
}
|
||||
|
||||
.queue-item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 1rem 1.5rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.queue-item-body {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.product-title {
|
||||
font-size: 1.125rem;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.order-details-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.detail-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.detail-col .label {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.detail-col .value {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.print-meta {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-top: 1rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.queue-item-actions {
|
||||
padding: 1rem 1.5rem;
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
border-top: 1px solid var(--border);
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.queue-item-actions .btn {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Toast */
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 2rem;
|
||||
right: 2rem;
|
||||
background: var(--bg-secondary);
|
||||
color: white;
|
||||
padding: 1rem 1.5rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
|
||||
border-left: 4px solid var(--accent);
|
||||
transform: translateY(150%);
|
||||
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
border-left-color: var(--danger);
|
||||
}
|
||||
|
||||
/* RTL Support for Persian */
|
||||
html[dir="rtl"] {
|
||||
/* Kept LTR as requested by user, but framework is ready if they change their mind */
|
||||
}
|
||||
151
slips/static/slips/js/entry.js
Normal file
151
slips/static/slips/js/entry.js
Normal file
@@ -0,0 +1,151 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const productSelect = document.getElementById('product');
|
||||
const totalWeightInput = document.getElementById('total-weight');
|
||||
const canisterWeightInput = document.getElementById('canister-weight');
|
||||
const canistersPerBoxInput = document.getElementById('canisters-per-box');
|
||||
const previewDisplay = document.getElementById('preview-display');
|
||||
const form = document.getElementById('order-form');
|
||||
|
||||
// Default dates
|
||||
const today = new Date();
|
||||
dateInput.valueAsDate = today;
|
||||
|
||||
// Auto calculate +6 months
|
||||
function updateNextControl() {
|
||||
const d = new Date(dateInput.value);
|
||||
if (isNaN(d)) return;
|
||||
d.setMonth(d.getMonth() + 6);
|
||||
nextControlInput.valueAsDate = d;
|
||||
}
|
||||
updateNextControl();
|
||||
dateInput.addEventListener('change', updateNextControl);
|
||||
|
||||
// Auto calculate previews
|
||||
function updatePreview() {
|
||||
const tw = parseFloat(totalWeightInput.value) || 0;
|
||||
const cw = parseFloat(canisterWeightInput.value) || 1;
|
||||
const cpb = parseInt(canistersPerBoxInput.value) || 1;
|
||||
|
||||
const cc = Math.ceil(tw / cw);
|
||||
const cp = Math.ceil(cc / 4);
|
||||
|
||||
const bc = Math.ceil(cc / cpb);
|
||||
const bp = Math.ceil(bc / 4);
|
||||
|
||||
previewDisplay.textContent = `Canisters: ${cc} (${cp} pages) | Boxes: ${bc} (${bp} pages)`;
|
||||
}
|
||||
|
||||
// Listeners for updates
|
||||
totalWeightInput.addEventListener('input', updatePreview);
|
||||
canisterWeightInput.addEventListener('input', updatePreview);
|
||||
canistersPerBoxInput.addEventListener('input', updatePreview);
|
||||
updatePreview();
|
||||
|
||||
// Auto weight from product selection
|
||||
productSelect.addEventListener('change', (e) => {
|
||||
const opt = e.target.options[e.target.selectedIndex];
|
||||
if (opt && opt.dataset.weight) {
|
||||
canisterWeightInput.value = opt.dataset.weight;
|
||||
updatePreview();
|
||||
}
|
||||
});
|
||||
|
||||
// Submit new order
|
||||
form.addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const payload = {
|
||||
product_id: parseInt(productSelect.value),
|
||||
batch_number: document.getElementById('batch').value,
|
||||
production_date: dateInput.value,
|
||||
next_control_date: nextControlInput.value,
|
||||
total_weight: parseFloat(totalWeightInput.value),
|
||||
canister_weight: parseFloat(canisterWeightInput.value),
|
||||
canisters_per_box: parseInt(canistersPerBoxInput.value)
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/orders', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
showToast(currentLang === 'fa' ? 'سفارش به صف چاپ اضافه شد' : 'Order added to print queue!');
|
||||
form.reset();
|
||||
dateInput.valueAsDate = today;
|
||||
updateNextControl();
|
||||
updatePreview();
|
||||
setTimeout(() => window.location.reload(), 1000);
|
||||
} else {
|
||||
const err = await res.json();
|
||||
console.error(err);
|
||||
showToast('Error creating order', true);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('Network error', true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Inline Product addition
|
||||
function showAddProduct() {
|
||||
document.getElementById('add-product-panel').style.display = 'block';
|
||||
}
|
||||
|
||||
function hideAddProduct() {
|
||||
document.getElementById('add-product-panel').style.display = 'none';
|
||||
}
|
||||
|
||||
async function addProduct() {
|
||||
const code = document.getElementById('new-code').value;
|
||||
const desc = document.getElementById('new-desc').value;
|
||||
const weight = parseFloat(document.getElementById('new-weight').value);
|
||||
|
||||
if (!code || !desc) {
|
||||
showToast('Code and Description are required', true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/products', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ code, description: desc, default_net_weight: weight })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const p = await res.json();
|
||||
const select = document.getElementById('product');
|
||||
const opt = document.createElement('option');
|
||||
opt.value = p.id;
|
||||
opt.dataset.weight = p.default_net_weight;
|
||||
opt.textContent = `${p.code} — ${p.description}`;
|
||||
select.appendChild(opt);
|
||||
select.value = p.id;
|
||||
document.getElementById('canister-weight').value = p.default_net_weight;
|
||||
updatePreview();
|
||||
|
||||
hideAddProduct();
|
||||
showToast('Product added');
|
||||
} else {
|
||||
showToast('Error adding product', true);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('Network error', true);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteOrder(id) {
|
||||
if (!confirm('Cancel this order?')) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/orders/${id}`, { method: 'DELETE' });
|
||||
if (res.ok) {
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('Error', true);
|
||||
}
|
||||
}
|
||||
120
slips/static/slips/js/i18n.js
Normal file
120
slips/static/slips/js/i18n.js
Normal file
@@ -0,0 +1,120 @@
|
||||
const translations = {
|
||||
'en': {
|
||||
'app_title': 'Product Slip Manager',
|
||||
'data_entry': 'Data Entry',
|
||||
'print_queue': 'Print Queue',
|
||||
'calibrate': 'Calibrate',
|
||||
'new_order': 'New Order',
|
||||
'product': 'Product',
|
||||
'add_product': '+ Add New Product',
|
||||
'product_code': 'Product Code',
|
||||
'description': 'Description',
|
||||
'default_weight': 'Default Weight',
|
||||
'save': 'Save',
|
||||
'cancel': 'Cancel',
|
||||
'batch_number': 'Batch #',
|
||||
'date': 'Date',
|
||||
'next_control': 'Next Control Date',
|
||||
'net_weight': 'Net Weight (kg)',
|
||||
'total_weight': 'Total Weight (kg)',
|
||||
'canister_weight': 'Canister Weight (kg)',
|
||||
'canisters_per_box': 'Canisters per Box',
|
||||
'labels_preview': 'Labels Generated',
|
||||
'canisters': 'Canisters',
|
||||
'boxes': 'Boxes',
|
||||
'pages_needed': 'Pages Needed',
|
||||
'total_pages': 'Pages',
|
||||
'add_to_queue': 'Add to Print Queue',
|
||||
'recent_orders': 'Recent Orders',
|
||||
'status': 'Status',
|
||||
'no_orders': 'No orders yet',
|
||||
'no_pending_orders': 'No pending orders to print.',
|
||||
'print': 'Print',
|
||||
'mark_done': 'Mark Done',
|
||||
'print_history': 'Print History',
|
||||
'printed_at': 'Printed At',
|
||||
'no_history': 'No print history'
|
||||
},
|
||||
'fa': {
|
||||
'app_title': 'مدیریت برچسب محصول',
|
||||
'data_entry': 'ثبت اطلاعات',
|
||||
'print_queue': 'صف چاپ',
|
||||
'calibrate': 'کالیبراسیون',
|
||||
'new_order': 'سفارش جدید',
|
||||
'product': 'محصول',
|
||||
'add_product': '+ افزودن محصول جدید',
|
||||
'product_code': 'کد محصول',
|
||||
'description': 'شرح',
|
||||
'default_weight': 'وزن پیشفرض',
|
||||
'save': 'ذخیره',
|
||||
'cancel': 'لغو',
|
||||
'batch_number': 'شماره بچ',
|
||||
'date': 'تاریخ',
|
||||
'next_control': 'تاریخ کنترل بعدی',
|
||||
'net_weight': 'وزن خالص (کیلوگرم)',
|
||||
'total_weight': 'وزن کل (کیلوگرم)',
|
||||
'canister_weight': 'وزن قوطی (کیلوگرم)',
|
||||
'canisters_per_box': 'تعداد قوطی در هر کارتن',
|
||||
'labels_preview': 'برچسبهای تولیدی',
|
||||
'canisters': 'تعداد قوطی',
|
||||
'boxes': 'تعداد کارتن',
|
||||
'pages_needed': 'تعداد صفحات',
|
||||
'total_pages': 'صفحات',
|
||||
'add_to_queue': 'افزودن به صف چاپ',
|
||||
'recent_orders': 'سفارشات اخیر',
|
||||
'status': 'وضعیت',
|
||||
'no_orders': 'سفارشی ثبت نشده',
|
||||
'no_pending_orders': 'سفارشی در انتظار چاپ نیست.',
|
||||
'print': 'چاپ',
|
||||
'mark_done': 'تایید چاپ',
|
||||
'print_history': 'سابقه چاپ',
|
||||
'printed_at': 'زمان چاپ',
|
||||
'no_history': 'سابقهای وجود ندارد'
|
||||
}
|
||||
};
|
||||
|
||||
let currentLang = localStorage.getItem('slip_lang') || 'en';
|
||||
|
||||
function applyLanguage(lang) {
|
||||
document.querySelectorAll('[data-i18n]').forEach(el => {
|
||||
const key = el.getAttribute('data-i18n');
|
||||
if (translations[lang][key]) {
|
||||
el.textContent = translations[lang][key];
|
||||
}
|
||||
});
|
||||
|
||||
const toggleBtn = document.getElementById('lang-label');
|
||||
if (toggleBtn) {
|
||||
toggleBtn.textContent = lang === 'en' ? '🇮🇷 FA' : '🇬🇧 EN';
|
||||
}
|
||||
|
||||
// User requested Persian to be LTR, so we don't change the dir attribute
|
||||
// document.documentElement.dir = lang === 'fa' ? 'rtl' : 'ltr';
|
||||
}
|
||||
|
||||
function toggleLanguage() {
|
||||
currentLang = currentLang === 'en' ? 'fa' : 'en';
|
||||
localStorage.setItem('slip_lang', currentLang);
|
||||
applyLanguage(currentLang);
|
||||
}
|
||||
|
||||
// Common Toast notification
|
||||
function showToast(message, isError = false) {
|
||||
const toast = document.getElementById('toast');
|
||||
if (!toast) return;
|
||||
|
||||
toast.textContent = message;
|
||||
if (isError) {
|
||||
toast.classList.add('error');
|
||||
} else {
|
||||
toast.classList.remove('error');
|
||||
}
|
||||
|
||||
toast.classList.add('show');
|
||||
setTimeout(() => toast.classList.remove('show'), 3000);
|
||||
}
|
||||
|
||||
// Initialize on load
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
applyLanguage(currentLang);
|
||||
});
|
||||
52
slips/static/slips/js/print.js
Normal file
52
slips/static/slips/js/print.js
Normal file
@@ -0,0 +1,52 @@
|
||||
function printOrder(id) {
|
||||
// Open the print page in a new window/tab
|
||||
const win = window.open(`/print-page/${id}/`, '_blank');
|
||||
if (win) {
|
||||
win.focus();
|
||||
} else {
|
||||
showToast('Please allow popups to print', true);
|
||||
}
|
||||
}
|
||||
|
||||
async function markDone(id) {
|
||||
try {
|
||||
const res = await fetch(`/api/orders/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status: 'done' })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
showToast('Order marked as done');
|
||||
document.getElementById(`order-${id}`).style.display = 'none';
|
||||
// Reload after brief delay to update history table
|
||||
setTimeout(() => window.location.reload(), 1500);
|
||||
} else {
|
||||
showToast('Error updating status', true);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('Network error', true);
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-refresh pending queue every 10 seconds
|
||||
setInterval(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/orders?status=pending');
|
||||
if (res.ok) {
|
||||
const orders = await res.json();
|
||||
document.getElementById('pending-count').textContent = orders.length;
|
||||
|
||||
// Simple approach: if count changes, just reload to get clean state
|
||||
// In a larger app, we'd do smart DOM updates here
|
||||
const currentItems = document.querySelectorAll('.queue-item:not([style*="display: none"])').length;
|
||||
if (orders.length > currentItems) {
|
||||
// New order arrived!
|
||||
showToast(currentLang === 'fa' ? 'سفارش جدید دریافت شد!' : 'New order arrived!');
|
||||
setTimeout(() => window.location.reload(), 2000);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('Refresh failed silently');
|
||||
}
|
||||
}, 10000);
|
||||
41
slips/templates/slips/base.html
Normal file
41
slips/templates/slips/base.html
Normal file
@@ -0,0 +1,41 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Product Slip Manager{% endblock %}</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="{% static 'slips/css/style.css' %}">
|
||||
{% block extra_head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar">
|
||||
<div class="nav-container">
|
||||
<a href="{% url 'entry' %}" class="nav-logo">
|
||||
<span class="logo-icon">🏭</span>
|
||||
<span class="logo-text" data-i18n="app_title">Product Slip Manager</span>
|
||||
</a>
|
||||
<div class="nav-links">
|
||||
<a href="{% url 'entry' %}" class="nav-link {% block nav_entry_active %}{% endblock %}" data-i18n="data_entry">Data Entry</a>
|
||||
<a href="{% url 'print_queue' %}" class="nav-link {% block nav_print_active %}{% endblock %}" data-i18n="print_queue">Print Queue</a>
|
||||
<a href="{% url 'calibrate' %}" class="nav-link" data-i18n="calibrate">Calibrate</a>
|
||||
</div>
|
||||
<div class="nav-actions">
|
||||
<button id="lang-toggle" class="btn btn-ghost" onclick="toggleLanguage()">
|
||||
<span id="lang-label">🇬🇧 EN</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="main-content">
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
|
||||
<script src="{% static 'slips/js/i18n.js' %}"></script>
|
||||
{% block extra_scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
84
slips/templates/slips/calibrate.html
Normal file
84
slips/templates/slips/calibrate.html
Normal file
@@ -0,0 +1,84 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Calibration Page</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body { font-family: Arial, sans-serif; background-color: #f0f0f0; }
|
||||
|
||||
.preview-controls {
|
||||
background: #1e293b; color: #fff; padding: 1rem; text-align: center;
|
||||
position: fixed; top: 0; left: 0; right: 0; z-index: 100;
|
||||
}
|
||||
.preview-controls button {
|
||||
background: #3b82f6; color: white; border: none; padding: 10px 20px;
|
||||
font-size: 16px; border-radius: 6px; cursor: pointer; font-weight: bold;
|
||||
}
|
||||
|
||||
.page-wrapper { margin-top: 80px; display: flex; justify-content: center; padding-bottom: 40px; }
|
||||
|
||||
.a4-page {
|
||||
width: 210mm; height: 297mm; background: white; position: relative;
|
||||
box-shadow: 0 10px 25px rgba(0,0,0,0.15); overflow: hidden;
|
||||
background-image:
|
||||
linear-gradient(to right, #e2e8f0 1px, transparent 1px),
|
||||
linear-gradient(to bottom, #e2e8f0 1px, transparent 1px);
|
||||
background-size: 10mm 10mm;
|
||||
}
|
||||
|
||||
.slip-grid {
|
||||
display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
|
||||
width: 100%; height: 100%;
|
||||
}
|
||||
|
||||
.slip-quadrant { position: relative; width: 105mm; height: 148.5mm; border: 1px dashed #cbd5e1; }
|
||||
|
||||
.var-field {
|
||||
position: absolute; font-family: Arial, sans-serif; font-weight: bold;
|
||||
color: red; /* Red for visibility during calibration */
|
||||
}
|
||||
|
||||
.crosshair::before {
|
||||
content: "┼"; position: absolute; left: -10px; top: -5px; color: blue; font-size: 20px;
|
||||
}
|
||||
|
||||
.val-batch { font-size: 15pt; top: 65mm; left: 20mm; }
|
||||
.val-date { font-size: 13pt; top: 65mm; left: 60mm; }
|
||||
.val-next { font-size: 15pt; top: 72mm; left: 50mm; }
|
||||
.val-weight { font-size: 15pt; top: 80mm; left: 20mm; }
|
||||
|
||||
@media print {
|
||||
@page { size: A4 portrait; margin: 0; }
|
||||
body { background: none; margin: 0; }
|
||||
.preview-controls { display: none; }
|
||||
.page-wrapper { margin: 0; padding: 0; display: block; }
|
||||
.a4-page { box-shadow: none; width: 100%; height: 100vh; background-image: none; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="preview-controls">
|
||||
<p style="margin-bottom: 10px;">Calibration Sheet. Print this on blank paper and overlay on a pre-printed label against light.</p>
|
||||
<button onclick="window.print()">🖨️ Print Calibration</button>
|
||||
<button onclick="window.close()" style="background:#64748b; margin-left: 10px;">Close</button>
|
||||
</div>
|
||||
|
||||
<div class="page-wrapper">
|
||||
<div class="a4-page">
|
||||
<div class="slip-grid">
|
||||
{% for i in "1234" %}
|
||||
<div class="slip-quadrant">
|
||||
<div class="var-field crosshair val-batch">[Batch#]</div>
|
||||
<div class="var-field crosshair val-date">[Date]</div>
|
||||
<div class="var-field crosshair val-next">[Next Control]</div>
|
||||
<div class="var-field crosshair val-weight">[Weight]</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
145
slips/templates/slips/entry.html
Normal file
145
slips/templates/slips/entry.html
Normal file
@@ -0,0 +1,145 @@
|
||||
{% extends 'slips/base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Data Entry — Product Slip Manager{% endblock %}
|
||||
{% block nav_entry_active %}active{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-grid">
|
||||
<!-- New Order Form -->
|
||||
<section class="card glass-card">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title" data-i18n="new_order">New Order</h2>
|
||||
<span class="card-badge badge-accent">📋</span>
|
||||
</div>
|
||||
<form id="order-form" class="form-stack">
|
||||
<div class="form-group">
|
||||
<label for="product" data-i18n="product">Product</label>
|
||||
<select id="product" required>
|
||||
<option value="">— Select —</option>
|
||||
{% for p in products %}
|
||||
<option value="{{ p.id }}" data-weight="{{ p.default_net_weight }}">
|
||||
{{ p.code }} — {{ p.description }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button type="button" class="btn btn-sm btn-ghost" onclick="showAddProduct()" data-i18n="add_product">+ Add New Product</button>
|
||||
</div>
|
||||
|
||||
<!-- Add Product Inline (hidden) -->
|
||||
<div id="add-product-panel" class="sub-panel" style="display:none;">
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="new-code" data-i18n="product_code">Product Code</label>
|
||||
<input type="text" id="new-code" placeholder="ICJ/000">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="new-desc" data-i18n="description">Description</label>
|
||||
<input type="text" id="new-desc" placeholder="DIGITAL INK ...">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="new-weight" data-i18n="default_weight">Default Weight</label>
|
||||
<input type="number" id="new-weight" value="5" step="0.1" min="0.1">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions-inline">
|
||||
<button type="button" class="btn btn-accent btn-sm" onclick="addProduct()" data-i18n="save">Save</button>
|
||||
<button type="button" class="btn btn-ghost btn-sm" onclick="hideAddProduct()" data-i18n="cancel">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="batch" data-i18n="batch_number">Batch #</label>
|
||||
<input type="text" id="batch" required placeholder="1028/26">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="prod-date" data-i18n="date">Date</label>
|
||||
<input type="date" id="prod-date" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="next-control" data-i18n="next_control">Next Control Date</label>
|
||||
<input type="date" id="next-control" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="total-weight" data-i18n="total_weight">Total Weight (kg)</label>
|
||||
<input type="number" id="total-weight" required step="0.1" min="0.1" value="100">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="canister-weight" data-i18n="canister_weight">Canister Weight (kg)</label>
|
||||
<input type="number" id="canister-weight" required step="0.1" min="0.1" value="5">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="canisters-per-box" data-i18n="canisters_per_box">Canisters per Box</label>
|
||||
<input type="number" id="canisters-per-box" required min="1" value="4">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label data-i18n="labels_preview">Labels Generated</label>
|
||||
<div class="computed-value" style="font-size: 0.9em" id="preview-display">
|
||||
Canisters: - ( - pages ) | Boxes: - ( - pages )
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-accent btn-lg btn-glow">
|
||||
<span data-i18n="add_to_queue">Add to Print Queue</span>
|
||||
<span class="btn-icon">✨</span>
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<!-- Recent Orders -->
|
||||
<section class="card glass-card">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title" data-i18n="recent_orders">Recent Orders</h2>
|
||||
<span class="card-badge badge-muted" id="order-count">{{ orders|length }}</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table class="data-table" id="orders-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th data-i18n="product">Product</th>
|
||||
<th data-i18n="batch_number">Batch</th>
|
||||
<th data-i18n="canisters">Canisters</th>
|
||||
<th data-i18n="boxes">Boxes</th>
|
||||
<th data-i18n="status">Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="orders-body">
|
||||
{% for o in orders %}
|
||||
<tr>
|
||||
<td class="mono">{{ o.id }}</td>
|
||||
<td>{{ o.product.code }}</td>
|
||||
<td class="mono">{{ o.batch_number }}</td>
|
||||
<td>{{ o.canister_count }}</td>
|
||||
<td>{{ o.box_count }}</td>
|
||||
<td><span class="badge badge-{{ o.status }}">{{ o.get_status_display }}</span></td>
|
||||
<td>
|
||||
{% if o.status == 'pending' %}
|
||||
<button class="btn btn-ghost btn-sm btn-danger" onclick="deleteOrder({{ o.id }})" data-i18n="cancel">Cancel</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td colspan="7" class="empty-state" data-i18n="no_orders">No orders yet</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- Toast notification -->
|
||||
<div id="toast" class="toast"></div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_scripts %}
|
||||
<script src="{% static 'slips/js/entry.js' %}"></script>
|
||||
{% endblock %}
|
||||
110
slips/templates/slips/print.html
Normal file
110
slips/templates/slips/print.html
Normal file
@@ -0,0 +1,110 @@
|
||||
{% extends 'slips/base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Print Queue — Product Slip Manager{% endblock %}
|
||||
{% block nav_print_active %}active{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-grid print-queue-layout">
|
||||
<!-- Print Queue -->
|
||||
<section class="card glass-card span-col">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title" data-i18n="print_queue">Print Queue (Pending)</h2>
|
||||
<div class="card-actions">
|
||||
<span class="refresh-indicator" id="refresh-icon">↻</span>
|
||||
<span class="card-badge badge-warning" id="pending-count">{{ pending_orders|length }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="queue-grid" id="queue-container">
|
||||
{% for o in pending_orders %}
|
||||
<div class="queue-item card" id="order-{{ o.id }}">
|
||||
<div class="queue-item-header">
|
||||
<span class="order-id mono">#{{ o.id }}</span>
|
||||
<span class="badge badge-pending">⏳ Pending</span>
|
||||
</div>
|
||||
<div class="queue-item-body">
|
||||
<h3 class="product-title">{{ o.product.code }} — {{ o.product.description }}</h3>
|
||||
<div class="order-details-grid">
|
||||
<div class="detail-col">
|
||||
<span class="label" data-i18n="batch_number">Batch:</span>
|
||||
<span class="value mono">{{ o.batch_number }}</span>
|
||||
</div>
|
||||
<div class="detail-col">
|
||||
<span class="label" data-i18n="date">Date:</span>
|
||||
<span class="value">{{ o.production_date|date:"d/m/Y" }}</span>
|
||||
</div>
|
||||
<div class="detail-col">
|
||||
<span class="label" data-i18n="total_weight">Total:</span>
|
||||
<span class="value">{{ o.total_weight }} kg</span>
|
||||
</div>
|
||||
<div class="detail-col">
|
||||
<span class="label" data-i18n="next_control">Next:</span>
|
||||
<span class="value">{{ o.next_control_date|date:"d/m/Y" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="print-meta">
|
||||
<span class="badge badge-neutral">{{ o.canister_count }} Canisters | {{ o.box_count }} Boxes</span>
|
||||
<span class="badge badge-accent">{{ o.canister_pages|add:o.box_pages }} Page(s)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="queue-item-actions">
|
||||
<button class="btn btn-accent btn-print" onclick="printOrder({{ o.id }})">
|
||||
<span class="btn-icon">🖨️</span>
|
||||
<span data-i18n="print">Print</span>
|
||||
</button>
|
||||
<button class="btn btn-success btn-ghost btn-done" onclick="markDone({{ o.id }})">
|
||||
<span class="btn-icon">✅</span>
|
||||
<span data-i18n="mark_done">Mark Done</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="empty-state" id="queue-empty" data-i18n="no_pending_orders">
|
||||
No pending orders to print.
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Print History -->
|
||||
<section class="card glass-card span-col">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title" data-i18n="print_history">Print History</h2>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<table class="data-table" id="history-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th data-i18n="product">Product</th>
|
||||
<th data-i18n="batch_number">Batch</th>
|
||||
<th data-i18n="total_pages">Pages</th>
|
||||
<th data-i18n="printed_at">Printed At</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="history-body">
|
||||
{% for o in history_orders %}
|
||||
<tr>
|
||||
<td class="mono">{{ o.id }}</td>
|
||||
<td>{{ o.product.code }}</td>
|
||||
<td class="mono">{{ o.batch_number }}</td>
|
||||
<td>{{ o.canister_pages|add:o.box_pages }}</td>
|
||||
<td>{{ o.printed_at|date:"d/m/Y H:i" }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td colspan="5" class="empty-state" data-i18n="no_history">No print history</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- Toast notification -->
|
||||
<div id="toast" class="toast"></div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_scripts %}
|
||||
<script src="{% static 'slips/js/print.js' %}"></script>
|
||||
{% endblock %}
|
||||
222
slips/templates/slips/print_page.html
Normal file
222
slips/templates/slips/print_page.html
Normal file
@@ -0,0 +1,222 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Print Order #{{ order.id }}</title>
|
||||
<style>
|
||||
/* Base reset and print-specific settings */
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f0f0f0;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
/* Screen-only styling for the preview container */
|
||||
.preview-controls {
|
||||
background: #1e293b;
|
||||
color: #fff;
|
||||
padding: 1rem;
|
||||
text-align: center;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.preview-controls button {
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.preview-controls button:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
|
||||
.page-wrapper {
|
||||
margin-top: 80px; /* Space for controls */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
/* The physical A4 page representation */
|
||||
.a4-page {
|
||||
width: 210mm;
|
||||
height: 297mm;
|
||||
background: white;
|
||||
position: relative;
|
||||
box-shadow: 0 10px 25px rgba(0,0,0,0.15);
|
||||
/* Important: Keep overflow visible for printing */
|
||||
overflow: hidden;
|
||||
page-break-after: always;
|
||||
}
|
||||
|
||||
/* CSS Grid for the 4 slips */
|
||||
.slip-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
grid-template-rows: 1fr 1fr;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.slip-quadrant {
|
||||
position: relative;
|
||||
width: 105mm; /* Half width */
|
||||
height: 148.5mm; /* Half height */
|
||||
}
|
||||
|
||||
/*
|
||||
* EXACT POSITIONING CALIBRATION
|
||||
* These values map to the Excel cells:
|
||||
* Batch: C18
|
||||
* Date: G18
|
||||
* Weight: C20
|
||||
* Next Control: F19
|
||||
*/
|
||||
|
||||
.var-field {
|
||||
position: absolute;
|
||||
font-family: Arial, sans-serif;
|
||||
font-weight: bold;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.val-batch {
|
||||
font-size: 15pt;
|
||||
top: 65mm;
|
||||
left: 20mm;
|
||||
}
|
||||
|
||||
.val-date {
|
||||
font-size: 13pt;
|
||||
top: 65mm;
|
||||
left: 60mm;
|
||||
}
|
||||
|
||||
.val-next {
|
||||
font-size: 15pt;
|
||||
top: 72mm;
|
||||
left: 50mm;
|
||||
}
|
||||
|
||||
.val-weight {
|
||||
font-size: 15pt;
|
||||
top: 80mm;
|
||||
left: 20mm;
|
||||
}
|
||||
|
||||
/* Print Media Query */
|
||||
@media print {
|
||||
@page {
|
||||
size: A4 portrait;
|
||||
margin: 0; /* Zero margin to allow absolute positioning from edges */
|
||||
}
|
||||
|
||||
body {
|
||||
background: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.preview-controls {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.page-wrapper {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
gap: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.a4-page {
|
||||
box-shadow: none;
|
||||
width: 100%;
|
||||
height: 100vh; /* Fill printed page */
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="preview-controls">
|
||||
<p style="margin-bottom: 10px; font-family: sans-serif;">
|
||||
Order #{{ order.id }} — {{ order.product.code }} <br>
|
||||
{{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
|
||||
{{ order.box_count }} Boxes ({{ order.box_pages }} Pages)
|
||||
</p>
|
||||
<button onclick="window.print()">🖨️ Print Now</button>
|
||||
<button onclick="window.close()" style="background:#64748b; margin-left: 10px;">Close</button>
|
||||
</div>
|
||||
|
||||
<div class="page-wrapper">
|
||||
{% for page in pages %}
|
||||
<div class="a4-page">
|
||||
<div class="slip-grid">
|
||||
<!-- Top Left -->
|
||||
<div class="slip-quadrant">
|
||||
{% if 0 in page.slips %}
|
||||
<div class="var-field val-batch">{{ order.batch_number }}</div>
|
||||
<div class="var-field val-date">{{ date_formatted }}</div>
|
||||
<div class="var-field val-next">{{ next_control_formatted }}</div>
|
||||
<div class="var-field val-weight">{{ page.weight }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Top Right -->
|
||||
<div class="slip-quadrant">
|
||||
{% if 1 in page.slips %}
|
||||
<div class="var-field val-batch">{{ order.batch_number }}</div>
|
||||
<div class="var-field val-date">{{ date_formatted }}</div>
|
||||
<div class="var-field val-next">{{ next_control_formatted }}</div>
|
||||
<div class="var-field val-weight">{{ page.weight }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Bottom Left -->
|
||||
<div class="slip-quadrant">
|
||||
{% if 2 in page.slips %}
|
||||
<div class="var-field val-batch">{{ order.batch_number }}</div>
|
||||
<div class="var-field val-date">{{ date_formatted }}</div>
|
||||
<div class="var-field val-next">{{ next_control_formatted }}</div>
|
||||
<div class="var-field val-weight">{{ page.weight }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Bottom Right -->
|
||||
<div class="slip-quadrant">
|
||||
{% if 3 in page.slips %}
|
||||
<div class="var-field val-batch">{{ order.batch_number }}</div>
|
||||
<div class="var-field val-date">{{ date_formatted }}</div>
|
||||
<div class="var-field val-next">{{ next_control_formatted }}</div>
|
||||
<div class="var-field val-weight">{{ page.weight }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Optional: auto-trigger print dialog when opened
|
||||
// window.onload = function() { window.print(); }
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
65
slips/views.py
Normal file
65
slips/views.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import math
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from .models import Product, Order
|
||||
|
||||
|
||||
def index(request):
|
||||
return redirect('entry')
|
||||
|
||||
|
||||
def entry(request):
|
||||
products = Product.objects.all()
|
||||
orders = Order.objects.select_related('product').all()[:20]
|
||||
return render(request, 'slips/entry.html', {
|
||||
'products': products,
|
||||
'orders': orders,
|
||||
})
|
||||
|
||||
|
||||
def print_queue(request):
|
||||
pending = Order.objects.select_related('product').filter(status='pending')
|
||||
history = Order.objects.select_related('product').filter(status='done').order_by('-printed_at')[:20]
|
||||
return render(request, 'slips/print.html', {
|
||||
'pending_orders': pending,
|
||||
'history_orders': history,
|
||||
})
|
||||
|
||||
|
||||
def print_page(request, order_id):
|
||||
order = get_object_or_404(Order.objects.select_related('product'), id=order_id)
|
||||
|
||||
pages = []
|
||||
|
||||
# 1. Canister Labels
|
||||
remaining_canisters = order.canister_count
|
||||
for _ in range(order.canister_pages):
|
||||
slips_on_page = min(4, remaining_canisters)
|
||||
pages.append({
|
||||
'type': 'Canister',
|
||||
'weight': order.canister_weight,
|
||||
'slips': range(slips_on_page),
|
||||
})
|
||||
remaining_canisters -= slips_on_page
|
||||
|
||||
# 2. Box Labels
|
||||
remaining_boxes = order.box_count
|
||||
box_weight = order.canister_weight * order.canisters_per_box
|
||||
for _ in range(order.box_pages):
|
||||
slips_on_page = min(4, remaining_boxes)
|
||||
pages.append({
|
||||
'type': 'Box',
|
||||
'weight': box_weight,
|
||||
'slips': range(slips_on_page),
|
||||
})
|
||||
remaining_boxes -= slips_on_page
|
||||
|
||||
return render(request, 'slips/print_page.html', {
|
||||
'order': order,
|
||||
'pages': pages,
|
||||
'date_formatted': order.production_date.strftime('%d/%m/%Y'),
|
||||
'next_control_formatted': order.next_control_date.strftime('%d/%m/%Y'),
|
||||
})
|
||||
|
||||
|
||||
def calibrate(request):
|
||||
return render(request, 'slips/calibrate.html')
|
||||
Reference in New Issue
Block a user