diff --git a/py_app/app/__pycache__/order_labels.cpython-312.pyc b/py_app/app/__pycache__/order_labels.cpython-312.pyc index 07c1241..e547fba 100644 Binary files a/py_app/app/__pycache__/order_labels.cpython-312.pyc and b/py_app/app/__pycache__/order_labels.cpython-312.pyc differ diff --git a/py_app/app/order_labels.py b/py_app/app/order_labels.py index 9ff0bf0..3dc557c 100644 --- a/py_app/app/order_labels.py +++ b/py_app/app/order_labels.py @@ -68,6 +68,22 @@ def validate_order_row(row_data): except ValueError: errors.append(f"{field} must be a valid number") + # Validate data_livrare (optional date field) + data_livrare = row_data.get('data_livrare', '').strip() + if data_livrare: + try: + # Try to parse common date formats + for date_format in ['%Y-%m-%d', '%d/%m/%Y', '%m/%d/%Y', '%d.%m.%Y']: + try: + datetime.strptime(data_livrare, date_format) + break + except ValueError: + continue + else: + errors.append("data_livrare must be a valid date (YYYY-MM-DD, DD/MM/YYYY, MM/DD/YYYY, or DD.MM.YYYY)") + except Exception: + errors.append("data_livrare date format error") + # Validate string length limits field_limits = { 'comanda_productie': 15, @@ -96,11 +112,29 @@ def add_order_to_database(order_data): cursor = conn.cursor() # Prepare data with proper types and limits + # Handle date conversion for data_livrare + data_livrare_value = None + data_livrare_str = order_data.get('data_livrare', '').strip() + if data_livrare_str: + try: + # Try to parse common date formats and convert to YYYY-MM-DD + for date_format in ['%Y-%m-%d', '%d/%m/%Y', '%m/%d/%Y', '%d.%m.%Y']: + try: + parsed_date = datetime.strptime(data_livrare_str, date_format) + data_livrare_value = parsed_date.strftime('%Y-%m-%d') + break + except ValueError: + continue + except Exception: + pass # Leave as None if parsing fails + insert_data = { 'comanda_productie': order_data.get('comanda_productie', '').strip()[:15], 'cod_articol': order_data.get('cod_articol', '').strip()[:15] or None, 'descr_com_prod': order_data.get('descr_com_prod', '').strip()[:50], 'cantitate': int(order_data.get('cantitate', 0)), + 'data_livrare': data_livrare_value, + 'dimensiune': order_data.get('dimensiune', '').strip()[:10] or None, 'com_achiz_client': order_data.get('com_achiz_client', '').strip()[:25] or None, 'nr_linie_com_client': int(order_data.get('nr_linie_com_client', 0)) if order_data.get('nr_linie_com_client', '').strip() else None, 'customer_name': order_data.get('customer_name', '').strip()[:50] or None, @@ -111,10 +145,10 @@ def add_order_to_database(order_data): sql = """ INSERT INTO order_for_labels - (comanda_productie, cod_articol, descr_com_prod, cantitate, + (comanda_productie, cod_articol, descr_com_prod, cantitate, data_livrare, dimensiune, com_achiz_client, nr_linie_com_client, customer_name, customer_article_number, open_for_order, line_number, printed_labels) - VALUES (%(comanda_productie)s, %(cod_articol)s, %(descr_com_prod)s, %(cantitate)s, + VALUES (%(comanda_productie)s, %(cod_articol)s, %(descr_com_prod)s, %(cantitate)s, %(data_livrare)s, %(dimensiune)s, %(com_achiz_client)s, %(nr_linie_com_client)s, %(customer_name)s, %(customer_article_number)s, %(open_for_order)s, %(line_number)s, 0) """ @@ -156,6 +190,9 @@ def process_csv_file(file_path): 'cod articol': 'cod_articol', 'descr. com. prod': 'descr_com_prod', 'cantitate': 'cantitate', + 'datalivrare': 'data_livrare', + 'data livrare': 'data_livrare', + 'dimensiune': 'dimensiune', 'com.achiz.client': 'com_achiz_client', 'nr. linie com. client': 'nr_linie_com_client', 'customer name': 'customer_name', @@ -279,7 +316,7 @@ def upload_orders_handler(): flash(report, "success" if failed_count == 0 else "warning") - return redirect(url_for('main.upload_orders') + '#imported') + return redirect(url_for('main.view_orders')) # Load data from session if available elif 'orders_csv_data' in session: @@ -304,7 +341,7 @@ def get_orders_from_database(limit=100): cursor.execute(""" SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate, - com_achiz_client, nr_linie_com_client, customer_name, + data_livrare, dimensiune, com_achiz_client, nr_linie_com_client, customer_name, customer_article_number, open_for_order, line_number, printed_labels, created_at, updated_at FROM order_for_labels @@ -320,15 +357,17 @@ def get_orders_from_database(limit=100): 'cod_articol': row[2], 'descr_com_prod': row[3], 'cantitate': row[4], - 'com_achiz_client': row[5], - 'nr_linie_com_client': row[6], - 'customer_name': row[7], - 'customer_article_number': row[8], - 'open_for_order': row[9], - 'line_number': row[10], - 'printed_labels': row[11], - 'created_at': row[12], - 'updated_at': row[13] + 'data_livrare': row[5], + 'dimensiune': row[6], + 'com_achiz_client': row[7], + 'nr_linie_com_client': row[8], + 'customer_name': row[9], + 'customer_article_number': row[10], + 'open_for_order': row[11], + 'line_number': row[12], + 'printed_labels': row[13], + 'created_at': row[14], + 'updated_at': row[15] }) conn.close() diff --git a/py_app/app/print_module.py b/py_app/app/print_module.py index 62f35e5..0052b3d 100644 --- a/py_app/app/print_module.py +++ b/py_app/app/print_module.py @@ -34,7 +34,7 @@ def get_unprinted_orders_data(limit=100): # Use printed_labels column cursor.execute(""" SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate, - com_achiz_client, nr_linie_com_client, customer_name, + data_livrare, dimensiune, com_achiz_client, nr_linie_com_client, customer_name, customer_article_number, open_for_order, line_number, printed_labels, created_at, updated_at FROM order_for_labels @@ -46,7 +46,7 @@ def get_unprinted_orders_data(limit=100): # Fallback: get all orders if no printed_labels column cursor.execute(""" SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate, - com_achiz_client, nr_linie_com_client, customer_name, + data_livrare, dimensiune, com_achiz_client, nr_linie_com_client, customer_name, customer_article_number, open_for_order, line_number, created_at, updated_at FROM order_for_labels @@ -63,15 +63,17 @@ def get_unprinted_orders_data(limit=100): 'cod_articol': row[2], 'descr_com_prod': row[3], 'cantitate': row[4], - 'com_achiz_client': row[5], - 'nr_linie_com_client': row[6], - 'customer_name': row[7], - 'customer_article_number': row[8], - 'open_for_order': row[9], - 'line_number': row[10], - 'printed_labels': row[11], - 'created_at': row[12], - 'updated_at': row[13] + 'data_livrare': row[5], + 'dimensiune': row[6], + 'com_achiz_client': row[7], + 'nr_linie_com_client': row[8], + 'customer_name': row[9], + 'customer_article_number': row[10], + 'open_for_order': row[11], + 'line_number': row[12], + 'printed_labels': row[13], + 'created_at': row[14], + 'updated_at': row[15] }) else: orders.append({ @@ -80,15 +82,17 @@ def get_unprinted_orders_data(limit=100): 'cod_articol': row[2], 'descr_com_prod': row[3], 'cantitate': row[4], - 'com_achiz_client': row[5], - 'nr_linie_com_client': row[6], - 'customer_name': row[7], - 'customer_article_number': row[8], - 'open_for_order': row[9], - 'line_number': row[10], + 'data_livrare': row[5], + 'dimensiune': row[6], + 'com_achiz_client': row[7], + 'nr_linie_com_client': row[8], + 'customer_name': row[9], + 'customer_article_number': row[10], + 'open_for_order': row[11], + 'line_number': row[12], 'printed_labels': 0, # Default to not printed - 'created_at': row[11], - 'updated_at': row[12] + 'created_at': row[13], + 'updated_at': row[14] }) conn.close() diff --git a/py_app/app/templates/main_page_etichete.html b/py_app/app/templates/main_page_etichete.html index cdfd254..dc2ddb2 100644 --- a/py_app/app/templates/main_page_etichete.html +++ b/py_app/app/templates/main_page_etichete.html @@ -12,8 +12,11 @@

View Orders

-

View uploaded orders and manage label data for printing.

- View Orders +

Upload new orders or view existing orders and manage label data for printing.

+
+ Upload Orders + View Orders +
diff --git a/py_app/app/templates/print_module.html b/py_app/app/templates/print_module.html index 4eabcbb..a56c8e4 100644 --- a/py_app/app/templates/print_module.html +++ b/py_app/app/templates/print_module.html @@ -23,55 +23,82 @@ INNOFA RROMANIA SRL - +
- +
-
-
-
-
- -
-
+
+
+
+
+ +
+ +
+ +
+ -
+
Quantity ordered
-
+
- -
- -
-
+
Customer order
+
+ +
-
+
Delivery date
-
+
-
+
Description
-
+
+ + +
+ Size +
+
+ +
+ + +
+ Article Code +
+
+ +
+ + +
+ Prod Order +
+
+ +
@@ -90,6 +117,8 @@ Cod Articol Descr. Com. Prod Cantitate + Data
Livrare + Dimensiune Com.Achiz.Client Nr. Linie Customer Name @@ -123,6 +152,10 @@ document.getElementById('check-db-btn').addEventListener('click', function() { ${order.cod_articol || '-'} ${order.descr_com_prod} ${order.cantitate} + + ${order.data_livrare ? new Date(order.data_livrare).toLocaleDateString() : '-'} + + ${order.dimensiune || '-'} ${order.com_achiz_client || '-'} ${order.nr_linie_com_client || '-'} ${order.customer_name || '-'} @@ -156,19 +189,36 @@ document.getElementById('check-db-btn').addEventListener('click', function() { const clientOrderInfo = comAchizClient && nrLinie ? `${comAchizClient}-${nrLinie}` : 'N/A'; document.getElementById('client-order-info').textContent = clientOrderInfo; - // Update delivery date (using created_at as placeholder since delivery_date column doesn't exist) - const deliveryDate = data[0].created_at ? new Date(data[0].created_at).toLocaleDateString() : 'N/A'; + // Update delivery date (using data_livrare column) + const deliveryDate = data[0].data_livrare ? new Date(data[0].data_livrare).toLocaleDateString() : 'N/A'; document.getElementById('delivery-date-value').textContent = deliveryDate; + // Update size (using dimensiune column) + const size = data[0].dimensiune || 'N/A'; + document.getElementById('size-value').textContent = size; + // Update description (Descr. Com. Prod) const description = data[0].descr_com_prod || 'N/A'; document.getElementById('description-value').textContent = description; + + // Update article code (using customer_article_number column) + const articleCode = data[0].customer_article_number || 'N/A'; + document.getElementById('article-code-value').textContent = articleCode; + + // Update prod order (comanda_productie - cantitate) + const comandaProductie = data[0].comanda_productie || ''; + const cantitate = data[0].cantitate || ''; + const prodOrder = comandaProductie && cantitate ? `${comandaProductie}-${cantitate}` : 'N/A'; + document.getElementById('prod-order-value').textContent = prodOrder; } else { document.getElementById('customer-name-row').textContent = 'No data available'; document.getElementById('quantity-ordered-value').textContent = '0'; document.getElementById('client-order-info').textContent = 'N/A'; document.getElementById('delivery-date-value').textContent = 'N/A'; + document.getElementById('size-value').textContent = 'N/A'; document.getElementById('description-value').textContent = 'N/A'; + document.getElementById('article-code-value').textContent = 'N/A'; + document.getElementById('prod-order-value').textContent = 'N/A'; } }) .catch(error => { @@ -177,7 +227,10 @@ document.getElementById('check-db-btn').addEventListener('click', function() { document.getElementById('quantity-ordered-value').textContent = 'Error'; document.getElementById('client-order-info').textContent = 'Error'; document.getElementById('delivery-date-value').textContent = 'Error'; + document.getElementById('size-value').textContent = 'Error'; document.getElementById('description-value').textContent = 'Error'; + document.getElementById('article-code-value').textContent = 'Error'; + document.getElementById('prod-order-value').textContent = 'Error'; }); }); diff --git a/py_app/app/templates/upload_orders.html b/py_app/app/templates/upload_orders.html index d5b72d4..33b89f4 100644 --- a/py_app/app/templates/upload_orders.html +++ b/py_app/app/templates/upload_orders.html @@ -1,5 +1,136 @@ {% extends "base.html" %} {% block title %}Upload Order Data for Labels{% endblock %} + +{% block head %} + +{% endblock %} + {% block content %}
@@ -48,29 +179,34 @@

Preview Table

- +
- - - + + + - - - - - + + + + + + + {% if orders %} {% for order in orders %} + {% if order and (order.get('comanda_productie', '') or order.get('descr_com_prod', '')) %} + + @@ -78,9 +214,10 @@ + {% endif %} {% endfor %} {% else %} - + {% endif %}
Comanda ProductieCod ArticolDescr. Com. ProdComanda
Productie
Cod
Articol
Descr. Com.
Prod
CantitateCom.Achiz.ClientNr. Linie com. ClientCustomer NameCustomer Article NumberOpen for orderData
Livrare
DimensiuneCom.Achiz.
Client
Nr. Linie com.
Client
Customer
Name
Customer Article
Number
Open for
order
Line
{{ order.get('comanda_productie', '') }} {{ order.get('cod_articol', '') }} {{ order.get('descr_com_prod', '') }} {{ order.get('cantitate', '') }}{{ order.get('data_livrare', '') }}{{ order.get('dimensiune', '') }} {{ order.get('com_achiz_client', '') }} {{ order.get('nr_linie_com_client', '') }} {{ order.get('customer_name', '') }}{{ order.get('open_for_order', '') }} {{ order.get('line_number', '') }}
No CSV file uploaded yet.
No CSV file uploaded yet.
@@ -123,115 +260,78 @@
+{% endblock %} + {% block content %}
@@ -46,19 +136,21 @@
{% if orders %} - +
- - - + + + - - - - - + + + + + + + @@ -72,6 +164,14 @@ + +
IDComanda ProductieCod ArticolDescr. Com. ProdComanda
Productie
Cod
Articol
Descr. Com.
Prod
CantitateCom.Achiz.ClientNr. LinieCustomer NameCustomer Art. Nr.Open OrderData
Livrare
DimensiuneCom.Achiz.
Client
Nr.
Linie
Customer
Name
Customer
Art. Nr.
Open
Order
Line Printed Created{{ order.cod_articol or '-' }} {{ order.descr_com_prod }} {{ order.cantitate }} + {% if order.data_livrare %} + {{ order.data_livrare.strftime('%Y-%m-%d') if order.data_livrare is not string else order.data_livrare }} + {% else %} + - + {% endif %} + {{ order.dimensiune or '-' }} {{ order.com_achiz_client or '-' }} {{ order.nr_linie_com_client or '-' }} {{ order.customer_name or '-' }}