', methods=['POST'])
+def mark_completed(do_id):
+ if 'store_id' not in session:
+ return redirect(url_for('auth.login'))
+
+ do = DeliveryOrder.query.get_or_404(do_id)
+
+ # Ensure only the final destination can mark complete
+ if session['store_id'] != do.final_location:
+ flash("You are not authorized to mark this DO as completed.", "danger")
+ return redirect(url_for('main.track_do'))
+
+ do.status = "Completed"
+ db.session.commit()
+ flash("DO marked as completed.", "success")
+ return redirect(url_for('main.track_do'))
diff --git a/app/templates/track_do.html b/app/templates/track_do.html
index ab4beda..b17fe31 100644
--- a/app/templates/track_do.html
+++ b/app/templates/track_do.html
@@ -19,6 +19,11 @@
Final Destination: {{ do.final_location }}
Collected By: {{ do.collected_by if do.collected_by else "Not collected yet" }}
Created: {{ do.created_at }}
+{% if do.status != "Completed" and session['store_id'] == do.final_location %}
+
+{% endif %}
Movement History:
{% if movements %}