@@ -138,6 +147,7 @@
-
+
+
\ No newline at end of file
diff --git a/app/routes.py b/app/routes.py
index 671e56c..5e15e44 100644
--- a/app/routes.py
+++ b/app/routes.py
@@ -29,3 +29,108 @@ def store_dashboard():
Track DOs (coming soon)
"""
+from flask import request
+from .models import DeliveryOrder, Store
+from . import db
+
+@main.route('/store/do-entry', methods=['GET', 'POST'])
+def do_entry():
+ if 'store_id' not in session:
+ return redirect(url_for('auth.login'))
+
+ stores = Store.query.order_by(Store.name).all()
+
+ if request.method == 'POST':
+ do_number = request.form.get('do_number')
+ delivery_number = request.form.get('delivery_number')
+ final_location = int(request.form.get('final_location'))
+ created_by = session.get('store_name')
+
+ # Prevent duplicate DO numbers
+ existing = DeliveryOrder.query.filter_by(do_number=do_number).first()
+ if existing:
+ flash("DO already exists!", "danger")
+ return redirect(url_for('main.do_entry'))
+
+ new_do = DeliveryOrder(
+ do_number=do_number,
+ delivery_number=delivery_number,
+ final_location=final_location,
+ created_by=created_by,
+ status="Ready for Collection"
+ )
+
+ db.session.add(new_do)
+ db.session.commit()
+ flash("DO created successfully.", "success")
+ return redirect(url_for('main.store_dashboard'))
+
+ return render_template("do_entry.html", stores=stores)
+@main.route('/store/track', methods=['GET', 'POST'])
+def track_do():
+ if 'store_id' not in session:
+ return redirect(url_for('auth.login'))
+
+ do = None
+ movements = []
+
+ if request.method == 'POST':
+ search = request.form.get('search')
+ do = DeliveryOrder.query.filter(
+ (DeliveryOrder.do_number == search) |
+ (DeliveryOrder.delivery_number == search)
+ ).first()
+
+ if do:
+ movements = do.movements
+
+ return render_template('track_do.html', do=do, movements=movements)
+from datetime import datetime
+from .models import Movement
+
+@main.route('/store/move', methods=['GET', 'POST'])
+def move_do():
+ if 'store_id' not in session:
+ return redirect(url_for('auth.login'))
+
+ message = None
+ if request.method == 'POST':
+ search = request.form.get('do_search')
+ do = DeliveryOrder.query.filter(
+ (DeliveryOrder.do_number == search) |
+ (DeliveryOrder.delivery_number == search)
+ ).first()
+
+ if not do:
+ flash("DO not found", "danger")
+ return redirect(url_for('main.move_do'))
+
+ handled_by = request.form.get('handled_by')
+ comment = request.form.get('comment')
+ mark_departed = request.form.get('departed')
+
+ branch_id = session.get('store_id')
+
+ # Check if this store has already logged a movement
+ existing = Movement.query.filter_by(do_id=do.id, branch_id=branch_id).first()
+
+ if not existing:
+ # First time it arrived at this store
+ move = Movement(
+ do_id=do.id,
+ branch_id=branch_id,
+ handled_by=handled_by,
+ comment=comment
+ )
+ db.session.add(move)
+ else:
+ # Already exists → optionally mark departure
+ if mark_departed == "on" and not existing.departed_at:
+ existing.departed_at = datetime.utcnow()
+ existing.comment = (existing.comment or '') + f" | {comment}"
+
+ db.session.commit()
+ flash("Movement updated successfully.", "success")
+ return redirect(url_for('main.track_do'))
+
+ return render_template("move_do.html")
diff --git a/app/templates/do_entry.html b/app/templates/do_entry.html
new file mode 100644
index 0000000..d9a25fc
--- /dev/null
+++ b/app/templates/do_entry.html
@@ -0,0 +1,34 @@
+
+
+
+ New DO Entry
+
+
+ Enter a New Delivery Order
+
+
+
+ Back to Dashboard
+
+ {% with messages = get_flashed_messages(with_categories=true) %}
+ {% for category, message in messages %}
+ {{ message }}
+ {% endfor %}
+ {% endwith %}
+
+
diff --git a/app/templates/move_do.html b/app/templates/move_do.html
new file mode 100644
index 0000000..2300aa3
--- /dev/null
+++ b/app/templates/move_do.html
@@ -0,0 +1,35 @@
+
+
+
+ Mark DO Movement
+
+
+ Mark Arrival/Departure
+
+
+
+ Back to Dashboard
+
+ {% with messages = get_flashed_messages(with_categories=true) %}
+ {% for category, message in messages %}
+ {{ message }}
+ {% endfor %}
+ {% endwith %}
+
+
diff --git a/app/templates/track_do.html b/app/templates/track_do.html
new file mode 100644
index 0000000..ab4beda
--- /dev/null
+++ b/app/templates/track_do.html
@@ -0,0 +1,41 @@
+
+
+
+ Track Delivery Order
+
+
+ Track a Delivery Order
+
+
+
+ {% if do %}
+ DO: {{ do.do_number }} / {{ do.delivery_number }}
+ Status: {{ do.status }}
+ Created by: {{ do.created_by }}
+ Final Destination: {{ do.final_location }}
+ Collected By: {{ do.collected_by if do.collected_by else "Not collected yet" }}
+ Created: {{ do.created_at }}
+
+ Movement History:
+ {% if movements %}
+
+ {% for m in movements %}
+ -
+ 📍 {{ m.branch_id }} | Handled by {{ m.handled_by }} | Arrived: {{ m.arrived_at }}
+ {% if m.departed_at %}| Departed: {{ m.departed_at }}{% endif %}
+ {% if m.comment %}
📝 {{ m.comment }}{% endif %}
+
+ {% endfor %}
+
+ {% else %}
+ No movement data yet.
+ {% endif %}
+ {% endif %}
+
+ Back to Dashboard
+
+