-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from nss-evening-cohort-12/completed_orders
completed orders done
- Loading branch information
Showing
4 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{% load static %} | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Reports</title> | ||
<style> | ||
td { | ||
text-align: center; | ||
padding: 5px; | ||
} | ||
|
||
th { | ||
padding: 5px; | ||
} | ||
|
||
table, | ||
th, | ||
td { | ||
border: 1px solid black; | ||
border-collapse: collapse; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>All completed orders</h1> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Id</th> | ||
<th>Name</th> | ||
<th>Payment Type</th> | ||
<th>Total Price</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for order in completed_orders %} | ||
<tr> | ||
<td>{{ order.order_id }}</td> | ||
<td>{{ order.full_name }}</td> | ||
<td>{{ order.payment_type }}</td> | ||
<td>{{ order.total_price }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from django.urls import path | ||
from .views import expensiveproduct_list, inexpensiveproduct_list | ||
from .views import expensiveproduct_list, inexpensiveproduct_list, completedorder_list | ||
|
||
urlpatterns = [ | ||
path('reports/expensiveproducts', expensiveproduct_list), | ||
path('reports/inexpensiveproducts', inexpensiveproduct_list) | ||
path('reports/inexpensiveproducts', inexpensiveproduct_list), | ||
path('reports/completedorders', completedorder_list) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .connection import Connection | ||
from .products.expensiveproducts import expensiveproduct_list | ||
from .products.inexpensiveproducts import inexpensiveproduct_list | ||
from .orders.completedorders import completedorder_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import sqlite3 | ||
from django.shortcuts import render | ||
from bangazonapi.models import Product | ||
from reports.views import Connection | ||
|
||
|
||
def completedorder_list(request): | ||
"""Function to build an HTML report of products over $1000""" | ||
if request.method == 'GET': | ||
# connect to database | ||
with sqlite3.connect(Connection.db_path) as conn: | ||
conn.row_factory = sqlite3.Row | ||
db_cursor = conn.cursor() | ||
|
||
db_cursor.execute(""" | ||
SELECT | ||
bangazonapi_order.id AS "order", | ||
auth_user.first_name || ' ' || auth_user.last_name as "full name", | ||
bangazonapi_payment.merchant_name as "payment type", | ||
SUM(price) as "total price" | ||
FROM | ||
bangazonapi_order | ||
JOIN | ||
bangazonapi_customer ON bangazonapi_order.customer_id = bangazonapi_customer.id | ||
JOIN | ||
auth_user ON auth_user.id = bangazonapi_customer.user_id | ||
JOIN | ||
bangazonapi_orderproduct ON bangazonapi_orderproduct.order_id = bangazonapi_order.id | ||
JOIN | ||
bangazonapi_product ON bangazonapi_product.id = bangazonapi_orderproduct.id | ||
JOIN | ||
bangazonapi_payment ON bangazonapi_payment.id = bangazonapi_order.payment_type_id | ||
WHERE | ||
bangazonapi_order.payment_type_id IS NOT NULL | ||
GROUP BY | ||
bangazonapi_order.id | ||
""") | ||
|
||
dataset = db_cursor.fetchall() | ||
|
||
completed_orders = [] | ||
|
||
for row in dataset: | ||
order = {} | ||
order["order_id"] = row["order"] | ||
order['full_name'] = row['full name'] | ||
order['payment_type'] = row['payment type'] | ||
order['total_price'] = row['total price'] | ||
|
||
completed_orders.append(order) | ||
|
||
template = 'orders/completed_orders.html' | ||
context = { | ||
'completed_orders': completed_orders | ||
} | ||
|
||
return render(request, template, context) |