updated to set boxes , and updated to fill boxes
This commit is contained in:
@@ -217,6 +217,74 @@ def get_db_connection():
|
||||
database=settings['database_name']
|
||||
)
|
||||
|
||||
def ensure_scanfg_orders_table():
|
||||
"""Ensure scanfg_orders table exists with proper structure and trigger"""
|
||||
try:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if table exists
|
||||
cursor.execute("SHOW TABLES LIKE 'scanfg_orders'")
|
||||
if cursor.fetchone():
|
||||
conn.close()
|
||||
return # Table already exists
|
||||
|
||||
print("Creating scanfg_orders table...")
|
||||
|
||||
# Create table
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS scanfg_orders (
|
||||
Id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
operator_code VARCHAR(50),
|
||||
CP_base_code VARCHAR(10),
|
||||
CP_full_code VARCHAR(15),
|
||||
OC1_code VARCHAR(50),
|
||||
OC2_code VARCHAR(50),
|
||||
quality_code INT,
|
||||
date DATE,
|
||||
time TIME,
|
||||
approved_quantity INT DEFAULT 0,
|
||||
rejected_quantity INT DEFAULT 0,
|
||||
INDEX idx_cp_base (CP_base_code),
|
||||
INDEX idx_date (date),
|
||||
INDEX idx_quality (quality_code)
|
||||
)
|
||||
""")
|
||||
|
||||
# Create trigger
|
||||
cursor.execute("DROP TRIGGER IF EXISTS set_quantities_fg")
|
||||
cursor.execute("""
|
||||
CREATE TRIGGER set_quantities_fg
|
||||
BEFORE INSERT ON scanfg_orders
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
SET @cp_base = SUBSTRING(NEW.CP_full_code, 1, 10);
|
||||
SET @approved = (SELECT COUNT(*) FROM scanfg_orders
|
||||
WHERE SUBSTRING(CP_full_code, 1, 10) = @cp_base
|
||||
AND quality_code = 0);
|
||||
SET @rejected = (SELECT COUNT(*) FROM scanfg_orders
|
||||
WHERE SUBSTRING(CP_full_code, 1, 10) = @cp_base
|
||||
AND quality_code != 0);
|
||||
|
||||
IF NEW.quality_code = 0 THEN
|
||||
SET NEW.approved_quantity = @approved + 1;
|
||||
SET NEW.rejected_quantity = @rejected;
|
||||
ELSE
|
||||
SET NEW.approved_quantity = @approved;
|
||||
SET NEW.rejected_quantity = @rejected + 1;
|
||||
END IF;
|
||||
|
||||
SET NEW.CP_base_code = @cp_base;
|
||||
END
|
||||
""")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print("✅ scanfg_orders table and trigger created successfully")
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(f"Error creating scanfg_orders table: {e}")
|
||||
|
||||
@bp.route('/dashboard')
|
||||
def dashboard():
|
||||
print("Session user:", session.get('user'), session.get('role'))
|
||||
@@ -589,6 +657,8 @@ def logout():
|
||||
@bp.route('/fg_scan', methods=['GET', 'POST'])
|
||||
@requires_quality_module
|
||||
def fg_scan():
|
||||
# Ensure scanfg_orders table exists
|
||||
ensure_scanfg_orders_table()
|
||||
|
||||
if request.method == 'POST':
|
||||
# Handle form submission
|
||||
@@ -637,6 +707,14 @@ def fg_scan():
|
||||
except mariadb.Error as e:
|
||||
print(f"Error saving finish goods scan data: {e}")
|
||||
flash(f"Error saving scan data: {e}")
|
||||
|
||||
# Check if this is an AJAX request (for scan-to-boxes feature)
|
||||
if request.headers.get('X-Requested-With') == 'XMLHttpRequest' or request.accept_mimetypes.best == 'application/json':
|
||||
# For AJAX requests, return JSON response without redirect
|
||||
return jsonify({'success': True, 'message': 'Scan recorded successfully'})
|
||||
|
||||
# For normal form submissions, redirect to prevent form resubmission (POST-Redirect-GET pattern)
|
||||
return redirect(url_for('main.fg_scan'))
|
||||
|
||||
# Fetch the latest scan data for display from scanfg_orders
|
||||
scan_data = []
|
||||
@@ -1336,7 +1414,7 @@ def get_fg_report_data():
|
||||
cursor.execute("""
|
||||
SELECT Id, operator_code, CP_base_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||
FROM scanfg_orders
|
||||
WHERE date = ?
|
||||
WHERE date = %s
|
||||
ORDER BY date DESC, time DESC
|
||||
""", (today,))
|
||||
rows = cursor.fetchall()
|
||||
@@ -1351,7 +1429,7 @@ def get_fg_report_data():
|
||||
cursor.execute("""
|
||||
SELECT Id, operator_code, CP_base_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||
FROM scanfg_orders
|
||||
WHERE date >= ?
|
||||
WHERE date >= %s
|
||||
ORDER BY date DESC, time DESC
|
||||
""", (start_date,))
|
||||
rows = cursor.fetchall()
|
||||
@@ -1365,7 +1443,7 @@ def get_fg_report_data():
|
||||
cursor.execute("""
|
||||
SELECT Id, operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||
FROM scanfg_orders
|
||||
WHERE date = ? AND quality_code != 0
|
||||
WHERE date = %s AND quality_code != 0
|
||||
ORDER BY date DESC, time DESC
|
||||
""", (today,))
|
||||
rows = cursor.fetchall()
|
||||
@@ -1380,7 +1458,7 @@ def get_fg_report_data():
|
||||
cursor.execute("""
|
||||
SELECT Id, operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||
FROM scanfg_orders
|
||||
WHERE date >= ? AND quality_code != 0
|
||||
WHERE date >= %s AND quality_code != 0
|
||||
ORDER BY date DESC, time DESC
|
||||
""", (start_date,))
|
||||
rows = cursor.fetchall()
|
||||
@@ -3947,6 +4025,20 @@ def manage_boxes():
|
||||
return manage_boxes_handler()
|
||||
|
||||
|
||||
@warehouse_bp.route('/assign_cp_to_box', methods=['POST'])
|
||||
@requires_warehouse_module
|
||||
def assign_cp_to_box():
|
||||
from app.warehouse import assign_cp_to_box_handler
|
||||
return assign_cp_to_box_handler()
|
||||
|
||||
|
||||
@warehouse_bp.route('/inventory', methods=['GET'])
|
||||
@requires_warehouse_module
|
||||
def warehouse_inventory():
|
||||
from app.warehouse import view_warehouse_inventory_handler
|
||||
return view_warehouse_inventory_handler()
|
||||
|
||||
|
||||
# Daily Mirror Route Redirects for Backward Compatibility
|
||||
@bp.route('/daily_mirror_main')
|
||||
def daily_mirror_main_route():
|
||||
|
||||
Reference in New Issue
Block a user