commit 0af10dde9da8cfb039802089a8acf6ad7f51a27a Author: diaco Date: Wed Sep 30 14:17:30 2026 +0330 Initial commit: Product Slip Manager diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2c1821 --- /dev/null +++ b/.gitignore @@ -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.* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f6f678d --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/ETICHETTE PER INKS(دون خط 4 تایی).xlsx b/ETICHETTE PER INKS(دون خط 4 تایی).xlsx new file mode 100644 index 0000000..8ccca26 Binary files /dev/null and b/ETICHETTE PER INKS(دون خط 4 تایی).xlsx differ diff --git a/PLAN.md b/PLAN.md new file mode 100644 index 0000000..fcc03c7 --- /dev/null +++ b/PLAN.md @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..6fb77fe --- /dev/null +++ b/README.md @@ -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 ` + + +
+

Calibration Sheet. Print this on blank paper and overlay on a pre-printed label against light.

+ + +
+ +
+
+
+ {% for i in "1234" %} +
+
[Batch#]
+
[Date]
+
[Next Control]
+
[Weight]
+
+ {% endfor %} +
+
+
+ + diff --git a/slips/templates/slips/entry.html b/slips/templates/slips/entry.html new file mode 100644 index 0000000..e342614 --- /dev/null +++ b/slips/templates/slips/entry.html @@ -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 %} +
+ +
+
+

New Order

+ 📋 +
+
+
+ + + +
+ + + + +
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ Canisters: - ( - pages ) | Boxes: - ( - pages ) +
+
+ + +
+
+ + +
+
+

Recent Orders

+ {{ orders|length }} +
+
+ + + + + + + + + + + + + + {% for o in orders %} + + + + + + + + + + {% empty %} + + {% endfor %} + +
#ProductBatchCanistersBoxesStatus
{{ o.id }}{{ o.product.code }}{{ o.batch_number }}{{ o.canister_count }}{{ o.box_count }}{{ o.get_status_display }} + {% if o.status == 'pending' %} + + {% endif %} +
No orders yet
+
+
+
+ + +
+{% endblock %} + +{% block extra_scripts %} + +{% endblock %} diff --git a/slips/templates/slips/print.html b/slips/templates/slips/print.html new file mode 100644 index 0000000..656e3a4 --- /dev/null +++ b/slips/templates/slips/print.html @@ -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 %} + + + +
+{% endblock %} + +{% block extra_scripts %} + +{% endblock %} diff --git a/slips/templates/slips/print_page.html b/slips/templates/slips/print_page.html new file mode 100644 index 0000000..5160c9b --- /dev/null +++ b/slips/templates/slips/print_page.html @@ -0,0 +1,222 @@ +{% load static %} + + + + + + Print Order #{{ order.id }} + + + +
+

+ Order #{{ order.id }} — {{ order.product.code }}
+ {{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) | + {{ order.box_count }} Boxes ({{ order.box_pages }} Pages) +

+ + +
+ +
+ {% for page in pages %} +
+
+ +
+ {% if 0 in page.slips %} +
{{ order.batch_number }}
+
{{ date_formatted }}
+
{{ next_control_formatted }}
+
{{ page.weight }}
+ {% endif %} +
+ + +
+ {% if 1 in page.slips %} +
{{ order.batch_number }}
+
{{ date_formatted }}
+
{{ next_control_formatted }}
+
{{ page.weight }}
+ {% endif %} +
+ + +
+ {% if 2 in page.slips %} +
{{ order.batch_number }}
+
{{ date_formatted }}
+
{{ next_control_formatted }}
+
{{ page.weight }}
+ {% endif %} +
+ + +
+ {% if 3 in page.slips %} +
{{ order.batch_number }}
+
{{ date_formatted }}
+
{{ next_control_formatted }}
+
{{ page.weight }}
+ {% endif %} +
+
+
+ {% endfor %} +
+ + + + diff --git a/slips/views.py b/slips/views.py new file mode 100644 index 0000000..9c00fb4 --- /dev/null +++ b/slips/views.py @@ -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')