Compare commits
2 Commits
428df2a50d
...
72f15d09f4
| Author | SHA1 | Date | |
|---|---|---|---|
| 72f15d09f4 | |||
| 330f0d5a87 |
@@ -12,8 +12,9 @@ def create_app():
|
|||||||
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
|
|
||||||
from app.routes import bp as main_bp
|
from app.routes import bp as main_bp, warehouse_bp
|
||||||
app.register_blueprint(main_bp, url_prefix='/')
|
app.register_blueprint(main_bp, url_prefix='/')
|
||||||
|
app.register_blueprint(warehouse_bp)
|
||||||
|
|
||||||
# Add 'now' function to Jinja2 globals
|
# Add 'now' function to Jinja2 globals
|
||||||
app.jinja_env.globals['now'] = datetime.now
|
app.jinja_env.globals['now'] = datetime.now
|
||||||
|
|||||||
@@ -6,8 +6,20 @@ from .models import User
|
|||||||
from . import db
|
from . import db
|
||||||
from reportlab.lib.pagesizes import letter
|
from reportlab.lib.pagesizes import letter
|
||||||
from reportlab.pdfgen import canvas
|
from reportlab.pdfgen import canvas
|
||||||
|
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
||||||
|
import csv
|
||||||
|
from .warehouse import add_location
|
||||||
|
|
||||||
bp = Blueprint('main', __name__)
|
bp = Blueprint('main', __name__)
|
||||||
|
warehouse_bp = Blueprint('warehouse', __name__)
|
||||||
|
|
||||||
|
@bp.route('/store_articles')
|
||||||
|
def store_articles():
|
||||||
|
return render_template('store_articles.html')
|
||||||
|
|
||||||
|
@bp.route('/warehouse_reports')
|
||||||
|
def warehouse_reports():
|
||||||
|
return render_template('warehouse_reports.html')
|
||||||
|
|
||||||
def get_db_connection():
|
def get_db_connection():
|
||||||
"""Reads the external_server.conf file and returns a MariaDB database connection."""
|
"""Reads the external_server.conf file and returns a MariaDB database connection."""
|
||||||
@@ -83,7 +95,7 @@ def warehouse():
|
|||||||
if 'role' not in session or session['role'] not in ['superadmin', 'warehouse']:
|
if 'role' not in session or session['role'] not in ['superadmin', 'warehouse']:
|
||||||
flash('Access denied: Warehouse users only.')
|
flash('Access denied: Warehouse users only.')
|
||||||
return redirect(url_for('main.dashboard'))
|
return redirect(url_for('main.dashboard'))
|
||||||
return render_template('warehouse.html')
|
return render_template('main_page_warehouse.html')
|
||||||
|
|
||||||
@bp.route('/scan', methods=['GET', 'POST'])
|
@bp.route('/scan', methods=['GET', 'POST'])
|
||||||
def scan():
|
def scan():
|
||||||
@@ -307,7 +319,7 @@ def get_report_data():
|
|||||||
elif report == "4": # Logic for the report with non-zero quality_code (5 days)
|
elif report == "4": # Logic for the report with non-zero quality_code (5 days)
|
||||||
five_days_ago = datetime.now() - timedelta(days=5)
|
five_days_ago = datetime.now() - timedelta(days=5)
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT Id, operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
SELECT Id, operator_code, CP_full_code, OC1_code, OC2 Code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||||
FROM scan1_orders
|
FROM scan1_orders
|
||||||
WHERE date >= ? AND quality_code != 0
|
WHERE date >= ? AND quality_code != 0
|
||||||
ORDER BY date DESC, time DESC
|
ORDER BY date DESC, time DESC
|
||||||
@@ -420,4 +432,14 @@ def generate_pdf():
|
|||||||
# Save the PDF
|
# Save the PDF
|
||||||
c.save()
|
c.save()
|
||||||
|
|
||||||
return jsonify({'message': 'PDF generated successfully!', 'pdf_path': f'/static/label_templates/label_template.pdf'})
|
return jsonify({'message': 'PDF generated successfully!', 'pdf_path': f'/static/label_templates/label_template.pdf'})
|
||||||
|
|
||||||
|
@warehouse_bp.route('/create_locations', methods=['GET', 'POST'])
|
||||||
|
def create_locations():
|
||||||
|
from app.warehouse import create_locations_handler
|
||||||
|
return create_locations_handler()
|
||||||
|
|
||||||
|
@warehouse_bp.route('/import_locations_csv', methods=['GET', 'POST'])
|
||||||
|
def import_locations_csv():
|
||||||
|
from app.warehouse import import_locations_csv_handler
|
||||||
|
return import_locations_csv_handler()
|
||||||
54
py_app/app/templates/create_locations.html
Normal file
54
py_app/app/templates/create_locations.html
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Create Warehouse Locations{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="scan-container">
|
||||||
|
<!-- Add Warehouse Location Card -->
|
||||||
|
<div class="card scan-form-card">
|
||||||
|
<h3>Add Warehouse Location</h3>
|
||||||
|
{% if message %}
|
||||||
|
<div class="form-message">{{ message }}</div>
|
||||||
|
{% endif %}
|
||||||
|
<form method="POST" class="form-centered">
|
||||||
|
<label>Location Code:</label>
|
||||||
|
<input type="text" name="location_code" maxlength="12" required><br>
|
||||||
|
<label>Size:</label>
|
||||||
|
<input type="number" name="size"><br>
|
||||||
|
<label>Description:</label>
|
||||||
|
<input type="text" name="description" maxlength="250"><br>
|
||||||
|
<button type="submit" class="btn">Add Location</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<!-- Locations Table Card -->
|
||||||
|
<div class="card scan-table-card">
|
||||||
|
<h3>Warehouse Locations</h3>
|
||||||
|
<table class="scan-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>Location Code</th>
|
||||||
|
<th>Size</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for loc in locations %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ loc[0] }}</td>
|
||||||
|
<td>{{ loc[1] }}</td>
|
||||||
|
<td>{{ loc[2] }}</td>
|
||||||
|
<td>{{ loc[3] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!-- Import Locations from CSV Card (original size, last position) -->
|
||||||
|
<div class="card scan-form-card" style="margin-top: 24px;">
|
||||||
|
<h3>Import Locations from CSV</h3>
|
||||||
|
<div style="display: flex; flex-direction: row; gap: 16px; align-items: center;">
|
||||||
|
<span>Bulk import warehouse locations using a CSV file.</span>
|
||||||
|
<a href="{{ url_for('warehouse.import_locations_csv') }}" class="btn">Go to Import Page</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
<div class="dashboard-card">
|
<div class="dashboard-card">
|
||||||
<h3>Accesare modul magazie</h3>
|
<h3>Accesare modul magazie</h3>
|
||||||
<p>Modul pentru managementul magaziei</p>
|
<p>Acceseaza functionalitatile modulului de magazie.</p>
|
||||||
<a href="{{ url_for('main.warehouse') }}" class="btn">Lansare modul Magazie</a>
|
<a href="{{ url_for('main.warehouse') }}" class="btn" id="launch-warehouse">Deschide magazie</a>
|
||||||
</div>
|
</div>
|
||||||
<!-- New Card: Accesare modul Etichete -->
|
<!-- New Card: Accesare modul Etichete -->
|
||||||
<div class="dashboard-card">
|
<div class="dashboard-card">
|
||||||
|
|||||||
71
py_app/app/templates/import_locations_csv.html
Normal file
71
py_app/app/templates/import_locations_csv.html
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Import Warehouse Locations from CSV{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="scan-container">
|
||||||
|
<!-- Import Locations from CSV Card (first) -->
|
||||||
|
<div class="card scan-form-card" style="margin-bottom: 24px;">
|
||||||
|
<h3>Import Locations from CSV</h3>
|
||||||
|
<form method="POST" enctype="multipart/form-data" class="form-centered">
|
||||||
|
<label for="csv_file">Choose CSV file:</label>
|
||||||
|
<input type="file" name="csv_file" accept=".csv" required><br>
|
||||||
|
<button type="submit" class="btn">Upload & Preview</button>
|
||||||
|
{% if locations %}
|
||||||
|
<button type="submit" name="create_locations" value="1" class="btn" style="margin-left: 12px;">Create Locations</button>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<!-- Preview Table Card (always visible) -->
|
||||||
|
<div class="card scan-table-card" style="margin-bottom: 24px;">
|
||||||
|
<h3>Preview Table</h3>
|
||||||
|
<table class="scan-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Location Code</th>
|
||||||
|
<th>Size</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% if locations %}
|
||||||
|
{% for loc in locations %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ loc[0] }}</td>
|
||||||
|
<td>{{ loc[1] }}</td>
|
||||||
|
<td>{{ loc[2] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
<tr><td colspan="3" style="text-align:center;">No CSV file uploaded yet.</td></tr>
|
||||||
|
{% endif %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% if report %}
|
||||||
|
<div class="card" style="margin-bottom: 24px;">
|
||||||
|
<h4>Import Report</h4>
|
||||||
|
<p>{{ report }}</p>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<!-- CSV File Format Card (last) -->
|
||||||
|
<div class="card scan-form-card" style="margin-bottom: 24px;">
|
||||||
|
<h3>CSV File Format</h3>
|
||||||
|
<label style="margin-bottom: 8px; display: block;">Fisierul CSV trebuie sa aiba urmatorul format:</label>
|
||||||
|
<table class="scan-table" style="width: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Location Code</th>
|
||||||
|
<th>Size</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>EX123</td>
|
||||||
|
<td>100</td>
|
||||||
|
<td>Zona depozitare A</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
112
py_app/app/warehouse.py
Normal file
112
py_app/app/warehouse.py
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
import mariadb
|
||||||
|
from flask import current_app, request, render_template
|
||||||
|
import csv
|
||||||
|
|
||||||
|
def get_db_connection():
|
||||||
|
settings_file = current_app.instance_path + '/external_server.conf'
|
||||||
|
settings = {}
|
||||||
|
with open(settings_file, 'r') as f:
|
||||||
|
for line in f:
|
||||||
|
key, value = line.strip().split('=', 1)
|
||||||
|
settings[key] = value
|
||||||
|
return mariadb.connect(
|
||||||
|
user=settings['username'],
|
||||||
|
password=settings['password'],
|
||||||
|
host=settings['server_domain'],
|
||||||
|
port=int(settings['port']),
|
||||||
|
database=settings['database_name']
|
||||||
|
)
|
||||||
|
|
||||||
|
def ensure_warehouse_locations_table():
|
||||||
|
try:
|
||||||
|
conn = get_db_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SHOW TABLES LIKE 'warehouse_locations'")
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if not result:
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS warehouse_locations (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
location_code VARCHAR(12) NOT NULL,
|
||||||
|
size INT,
|
||||||
|
description VARCHAR(250)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error ensuring warehouse_locations table: {e}")
|
||||||
|
|
||||||
|
# Add warehouse-specific functions below
|
||||||
|
def add_location(location_code, size, description):
|
||||||
|
conn = get_db_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
try:
|
||||||
|
cursor.execute(
|
||||||
|
"INSERT INTO warehouse_locations (location_code, size, description) VALUES (?, ?, ?)",
|
||||||
|
(location_code, size if size else None, description)
|
||||||
|
)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return "Location added successfully."
|
||||||
|
except mariadb.IntegrityError:
|
||||||
|
conn.close()
|
||||||
|
return "Failed: Location code already exists."
|
||||||
|
|
||||||
|
def get_locations():
|
||||||
|
conn = get_db_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT id, location_code, size, description FROM warehouse_locations ORDER BY id DESC")
|
||||||
|
locations = cursor.fetchall()
|
||||||
|
conn.close()
|
||||||
|
return locations
|
||||||
|
|
||||||
|
def recreate_warehouse_locations_table():
|
||||||
|
conn = get_db_connection()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("DROP TABLE IF EXISTS warehouse_locations")
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE TABLE warehouse_locations (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
location_code VARCHAR(12) UNIQUE NOT NULL,
|
||||||
|
size INT,
|
||||||
|
description VARCHAR(250)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def create_locations_handler():
|
||||||
|
message = None
|
||||||
|
if request.method == "POST":
|
||||||
|
location_code = request.form.get("location_code")
|
||||||
|
size = request.form.get("size")
|
||||||
|
description = request.form.get("description")
|
||||||
|
message = add_location(location_code, size, description)
|
||||||
|
locations = get_locations()
|
||||||
|
return render_template("create_locations.html", locations=locations, message=message)
|
||||||
|
|
||||||
|
def import_locations_csv_handler():
|
||||||
|
report = None
|
||||||
|
locations = []
|
||||||
|
errors = []
|
||||||
|
if request.method == 'POST':
|
||||||
|
file = request.files.get('csv_file')
|
||||||
|
if file and file.filename.endswith('.csv'):
|
||||||
|
content = file.read().decode('utf-8').splitlines()
|
||||||
|
reader = csv.DictReader(content)
|
||||||
|
locations = [(row.get('location_code'), row.get('size'), row.get('description')) for row in reader]
|
||||||
|
if request.form.get('create_locations'):
|
||||||
|
added = 0
|
||||||
|
failed = 0
|
||||||
|
errors = []
|
||||||
|
for loc in locations:
|
||||||
|
location_code, size, description = loc
|
||||||
|
result = add_location(location_code, size, description)
|
||||||
|
if result and 'success' in result.lower():
|
||||||
|
added += 1
|
||||||
|
else:
|
||||||
|
failed += 1
|
||||||
|
errors.append(location_code)
|
||||||
|
report = f"{added} locations were added to warehouse_locations table. {failed} locations failed: {', '.join(errors)}"
|
||||||
|
return render_template('import_locations_csv.html', report=report, locations=locations)
|
||||||
Reference in New Issue
Block a user