Added Customer and Inventory views

parent a4ae609e
......@@ -53,13 +53,18 @@ class OrderItem(models.Model):
import products.models as product_model
inventory = product_model.Inventory.objects.all()
product = product_model.Product.objects.all()
check = False
for prod in inventory:
if(prod.item_id == self.item_id):
check = True
if(prod.item_id == self.item_id and prod.color == self.item_color):
if(prod.stock < self.quantity):
self.is_successful = False
else:
prod.stock -= self.quantity
prod.save()
if(check == False):
self.is_successful = False
if(self.is_successful):
self.discount_price = self.item_id.price * \
(1 - (self.discount/100))
......
......@@ -493,6 +493,52 @@ footer a {
font-size: 3.5em;
}
#inventory-btn{
grid-column-start: 11 ;
grid-column-end: end;
grid-row-start: 1;
grid-row-end: 1;
align-self: center;
z-index: 10;
height: 8vh;
width: 10vw;
border-radius: 10px;
background-color: #eee;
border-color: #2aabe4;
opacity: 0.5;
color: #2aabe4;
font-family: inherit;
font-size: 18px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease-in-out;
opacity: 0.65;
margin-bottom: 20px;
padding: 0;
}
#inventory-btn button{
grid-column-start: 11 ;
grid-column-end: end;
grid-row-start: 1;
grid-row-end: 1;
align-self: center;
z-index: 10;
height: 8vh;
width: 10vw;
padding: 5px 0;
border-radius: 10px;
background-color: #eee;
border-color: #2aabe4;
opacity: 0.5;
color: #2aabe4;
font-family: inherit;
font-size: 18px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease-in-out;
opacity: 0.65;
margin-bottom: 20px;
}
#folderList {
grid-area: 2/1/3/5;
}
......@@ -505,7 +551,7 @@ footer a {
grid-area: 2/9/3/13;
}
.collection{
#productList .collection{
padding: 2vw;
background-color: #d1d7d7;
border-radius: 1vw;
......@@ -533,6 +579,7 @@ footer a {
#productDetailsArea {
min-height: 88vh;
padding: 2.5vw;
padding-top: 3.5vw;
display: grid;
......@@ -591,4 +638,32 @@ footer a {
padding-left: 2em;
}
/* This is for inventory views */
.inventory{
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
}
.inventory h1{
font-size: 40px;
}
.inventory table {
font-family: arial, sans-serif;
border-collapse: collapse;
font-size: larger;
width: 100%;
}
.inventory td, .inventory th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
.inventory tr:nth-child(even) {
background-color: #dddddd;
}
{% extends 'base.html' %} {% block content-header %}
<li><a href="/admin-pd/agents">Agents</a></li>
<li><a href="/admin-pd/customers">Customers</a></li>
<li><a href="/admin-pd/products/catalog">Products</a></li>
<li><a href="/admin-pd/orders">Orders</a></li>
{% endblock %} {% block content %}
<section class="inventory">
<div class="inventory-wrapper">
<h1>Inventory</h1>
<table>
<tr>
<th>Item</th>
<th>Red</th>
<th>Orange</th>
<th>Yellow</th>
<th>Green</th>
<th>Blue</th>
<th>Purple</th>
<th>Pink</th>
<th>Black</th>
</tr>
{% for product in product_list %}
<tr>
<th>{{product.item_name}}</th>
<th>
{% for inventory in inventory_list %}
{% if inventory.item_id.item_name == product.item_name and inventory.color == "RED" %}
{{inventory.stock}}
{% endif %}
{% endfor %}
</th>
<th>
{% for inventory in inventory_list %}
{% if inventory.item_id.item_name == product.item_name and inventory.color == "ORANGE" %}
{{inventory.stock}}
{% endif %}
{% endfor %}
</th>
<th>
{% for inventory in inventory_list %}
{% if inventory.item_id.item_name == product.item_name and inventory.color == "YELLOW" %}
{{inventory.stock}}
{% endif %}
{% endfor %}
</th>
<th>
{% for inventory in inventory_list %}
{% if inventory.item_id.item_name == product.item_name and inventory.color == "GREEN" %}
{{inventory.stock}}
{% endif %}
{% endfor %}
</th>
<th>
{% for inventory in inventory_list %}
{% if inventory.item_id.item_name == product.item_name and inventory.color == "BLUE" %}
{{inventory.stock}}
{% endif %}
{% endfor %}
</th>
<th>
{% for inventory in inventory_list %}
{% if inventory.item_id.item_name == product.item_name and inventory.color == "PURPLE" %}
{{inventory.stock}}
{% endif %}
{% endfor %}
</th>
<th>
{% for inventory in inventory_list %}
{% if inventory.item_id.item_name == product.item_name and inventory.color == "PINK" %}
{{inventory.stock}}
{% endif %}
{% endfor %}
</th>
<th>
{% for inventory in inventory_list %}
{% if inventory.item_id.item_name == product.item_name and inventory.color == "BLACK" %}
{{inventory.stock}}
{% endif %}
{% endfor %}
</th>
</tr>
{% endfor %}
</table>
</div>
</section>
{% endblock %}
......@@ -8,6 +8,7 @@
{% block content %}
<main id="productList">
<h1 id="productListTitle">Product Catalog</h1>
<a href="/admin-pd/products/inventory" id="inventory-btn"><button>Inventory</button></a>
<div class="collection" id="folderList">
<h2 class="collectionName">Folders</h2>
......
from django.urls import path
from . import views
from .views import (
ProductsDetailView,
ProductsListView,
......@@ -8,7 +9,8 @@ appname = "products"
urlpatterns = [
path('catalog', ProductsListView.as_view(), name='products-list'),
path('catalog/<int:pk>/details', ProductsDetailView.as_view(),
name='products-detail')
name='products-detail'),
path('inventory', views.inventory, name='inventory'),
]
app_name = 'products'
from django.shortcuts import render
from .models import Product, Folder, PenOrganizer, Planner, Description
from .models import Product, Folder, PenOrganizer, Planner, Description, Inventory
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
......@@ -26,3 +26,9 @@ class ProductsDetailView(DetailView):
description_list = Description.objects.all()
return render(request, 'products/products_detail.html',
{'product': product, 'description_list': description_list})
def inventory(request):
inventory_list = Inventory.objects.all()
product_list = Product.objects.all()
return render(request, "products/inventory.html", {"inventory_list":inventory_list, "product_list":product_list})
{% extends 'base.html' %} {% block content-header %}
<li><a href="/admin-pd/agents">Agents</a></li>
<li><a href="/admin-pd/customers">Customers</a></li>
<li><a href="/admin-pd/products/catalog">Products</a></li>
<li><a href="/admin-pd/orders">Orders</a></li>
{% endblock %} {% block content %}
<section class="agent-details">
<br><br><br><br>
<div class="agent-info">
<div class="image-wrapper">
<img src="https://randomuser.me/api/portraits/men/{{customer.customer_id}}.jpg" alt="profile pic">
</div>
<div class="agent-content">
<p>First Name: &nbsp;&nbsp;&nbsp;{{customer.first_name}}</p>
<p>Last Name: &nbsp;&nbsp;&nbsp;&nbsp;{{customer.last_name}}</p>
<p>Customer Id: &nbsp;{{customer.customer_id|stringformat:"06d"}}</p>
<p>Agent: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{customer.agent_id.first_name}} {{customer.agent_id.last_name}} </p>
</div>
</div>
</section>
<hr>
<section class="agent-transactions details">
<h2>Customer Transactions</h2>
<table>
<tr>
<th>Date</th>
<th>Items</th>
<th>Order No.</th>
<th>Total Amount</th>
</tr>
{% for order in order_list %}
<tr>
<th>{{order.order_date}}</th>
<th>
{%for order_item in order_item_list%}
<ul>
{% if order.order_id == order_item.order_id.order_id%}
<li>
{{order_item.quantity}}pcs. of {{ order_item.item_color|lower}} {{order_item.item_id.item_name}}
</li>
{% endif %}
</ul>
{% endfor %}
</th>
<th>{{order.order_no|stringformat:"08d"}}</th>
<th>{{order.amount_due}}</th>
</tr>
{% endfor %}
</table>
<br><br>
<h2>Custom Query?</h2>
<br>
<form action="/admin-pd/customer/{{customer.customer_id}}/details/">
<label for="start-date">Start date</label>
<input type="date" name="start-date" id="start-date" required>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<label for="end-date">End date</label>
<input type="date" name="end-date" id="end-date" required>
<br> <br>
<input type="submit">
</form>
</section>
{% endblock %}
{% extends 'base.html' %} {% block content-header %}
<li><a href="/admin-pd/agents">Agents</a></li>
<li><a href="/admin-pd/customers">Customers</a></li>
<li><a href="/admin-pd/products/catalog">Products</a></li>
<li><a href="/admin-pd/orders">Orders</a></li>
{% endblock %} {% block content %}
<section class="main-agents">
<div class="agent-list-wrapper">
<h1>Customers</h1>
{% for customer in customer_list %}
<a href="customer/{{ customer.customer_id }}/details">{{ customer.first_name }} {{ customer.last_name }}</a>
{% endfor %}
</div>
</section>
{% endblock %}
......@@ -8,5 +8,6 @@ urlpatterns = [
path('agents/agent-transaction', views.agent_transactions, name="agents-transactions"),
path('agents/agent-transaction/custom', views.agent_transactions_custom, name="agents-transactions-custom"),
path('agents/<int:agent_id>/details/', views.agent_details, name ="agent-detail"),
path('customers', views.customers, name="customers"),
path('customer/<int:customer_id>/details/', views.customer_details, name ="customer-detail"),
]
\ No newline at end of file
......@@ -2,7 +2,7 @@ from django.shortcuts import render
from django.http import HttpResponse, Http404
from products.models import Product, Folder, PenOrganizer, Planner, Description
from users.models import SalesAgent, Customer
from orders.models import Order
from orders.models import Order, OrderItem
# Create your views here.
def index(request):
......@@ -45,4 +45,21 @@ def agent_transactions_custom(request):
return render(request, "users/agent_transactions_custom.html" ,{"order_list":order_list})
def customers(request):
customer_list = Customer.objects.order_by("first_name")
return render(request, "users/customers.html", {"customer_list":customer_list})
def customer_details(request, customer_id):
try:
customer = Customer.objects.get(pk=customer_id)
except Customer.DoesNotExist:
raise Http404("Customer does not exist")
customer_list = Customer.objects.filter(customer_id=customer_id)
start_date = request.GET.get('start-date', '2000-01-01')
end_date = request.GET.get('end-date', '2100-01-01')
order_list = Order.objects.filter(customer_id__in=customer_list, order_date__range=[start_date, end_date])
order_item_list = OrderItem.objects.filter(order_no__in=order_list)
return render(request, "users/customer_details.html",{"customer": customer, "order_list":order_list, "order_item_list":order_item_list})
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