Commit aa6e6b06 authored by Matthew Dizon's avatar Matthew Dizon

add order functionality

parent 79898797
Pipeline #1925 canceled with stages
{% extends 'Kiosk/base.html' %}
{% load static %}
{% block content %}
<div class="card w-75">
<div class="card-header">
Enter Order Details:
</div>
<form method="POST" action="{% url 'add_order' %}">{% csrf_token %}
<div class="form-group">
<label for="name"> Food: </label>
<select name="food" class="form-select" style="max-width: 200px; margin-right: 75px;" required>
{% for food in foods %}
<option value="{{food.id}}">{{food.name}}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="name"> Quantity: </label>
<input type="number" class="form-control" id="qty" name="qty" value="{{order.qty}}" required>
</div>
<div class="form-group">
<label for="name"> Date of Order: </label>
<input type="date" class="form-control" id="date" name="date" value="{{order.ordered_at}}" required>
</div>
<div class="form-group">
<label for="name"> Customer: </label>
<select name="customer" class="form-select" style="max-width: 200px; margin-right: 75px;" required>
{% for customer in customers %}
<option value="{{customer.id}}">{{customer.name}}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="name"> Mode of Payment: </label>
<select name="payment_mode" class="form-select" style="max-width: 200px; margin-right: 75px;" required>
<option value="Cash">Cash</option>
<option value="Card">Card</option>
</select>
</div>
<a href="{% url 'add_order' %}"><button type="submit" class="mt-3 btn btn-primary">Add Order</button></a>
</form>
</div>
{% endblock %}
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<div class="container"> <div class="container">
<h1 class="jumbotron-heading">Orders</h1> <h1 class="jumbotron-heading">Orders</h1>
<p>A table of all orders</p> <p>A table of all orders</p>
<a href="{% url 'add_order' %}"><button class="btn btn-dark">Add Order</button></a>
</div> </div>
</section> </section>
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
<div class="form-group"> <div class="form-group">
<label for="name"> Quantity: </label> <label for="name"> Quantity: </label>
<input type="text" class="form-control" id="qty" name="qty" value="{{order.qty}}" required> <input type="number" class="form-control" id="qty" name="qty" value="{{order.qty}}" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="name"> Date of Order: </label> <label for="name"> Date of Order: </label>
<input type="text" class="form-control" id="date" name="date" value="{{order.ordered_at}}" disabled> <input type="date" class="form-control" id="date" name="date" value="{{order.ordered_at}}" disabled>
</div> </div>
<div class="form-group"> <div class="form-group">
......
...@@ -11,6 +11,7 @@ urlpatterns = [ ...@@ -11,6 +11,7 @@ urlpatterns = [
path('home', views.home, name="home"), path('home', views.home, name="home"),
path('view_order_details/<int:pk>', views.view_order_details, name="view_order_details"), path('view_order_details/<int:pk>', views.view_order_details, name="view_order_details"),
path('update_order/<int:pk>', views.update_order, name="update_order"), path('update_order/<int:pk>', views.update_order, name="update_order"),
path('add_order', views.add_order, name="add_order"),
# Path for Food Model # Path for Food Model
path('foods', views.view_foods, name="view_foods"), path('foods', views.view_foods, name="view_foods"),
path('view_food_details/<int:pk>', views.view_food_details, name="view_food_details"), path('view_food_details/<int:pk>', views.view_food_details, name="view_food_details"),
......
...@@ -75,6 +75,38 @@ def update_order(request, pk): ...@@ -75,6 +75,38 @@ def update_order(request, pk):
context = {"order": order} context = {"order": order}
return render(request, 'Kiosk/update_order.html', context) return render(request, 'Kiosk/update_order.html', context)
def add_order(request):
food_objects = Food.objects.all()
customer_objects = Customer.objects.all()
context = {"foods":food_objects, "customers":customer_objects}
if(request.method=="POST"):
qty = request.POST.get('qty')
payment_mode = request.POST.get('payment_mode')
food = request.POST.get('food')
date = request.POST.get('date')
customer = request.POST.get('customer')
try:
Order.objects.create(
food=Food.objects.get(id=food),
qty=qty,
ordered_at=date,
cust_order = Customer.objects.get(id=customer),
payment_mode = payment_mode
)
return redirect('home')
except Exception as e:
message = e
print(message)
return render(request, 'Kiosk/add_order.html', context)
else:
return render(request, 'Kiosk/add_order.html', context)
### Views for Food Model ### Views for Food Model
def view_foods(request): def view_foods(request):
foods = Food.objects.all() foods = Food.objects.all()
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment