Added Sales Agent views & removed Discount entity

parent 7a26904f
# Generated by Django 3.2.12 on 2022-11-22 03:24
# Generated by Django 3.2.12 on 2022-12-01 10:08
import django.core.validators
from django.db import migrations, models
......@@ -39,7 +39,7 @@ class Migration(migrations.Migration):
('quantity', models.IntegerField(default=1, validators=[django.core.validators.MaxValueValidator(99), django.core.validators.MinValueValidator(0)])),
('personalization', models.CharField(max_length=254)),
('discount', models.IntegerField(default=0, editable=False)),
('discount_price', models.DecimalField(decimal_places=2, default=0, editable=False, max_digits=12)),
('discount_price', models.DecimalField(decimal_places=2, default=0, max_digits=12)),
('sub_total', models.DecimalField(decimal_places=2, default=0, editable=False, max_digits=12)),
('is_successful', models.BooleanField(default=True, editable=False)),
('item_id', models.ForeignKey(db_column='item_id', on_delete=django.db.models.deletion.CASCADE, to='products.product')),
......
......@@ -29,7 +29,7 @@ class OrderItem(models.Model):
quantity = models.IntegerField(default=1, validators=[MaxValueValidator(99), MinValueValidator(0)])
personalization = models.CharField(max_length=254)
discount = models.IntegerField(default=0, editable=False)
discount_price = models.DecimalField(default=0, editable=False, decimal_places=2, max_digits=12)
discount_price = models.DecimalField(default=0, decimal_places=2, max_digits=12)
sub_total = models.DecimalField(default=0, editable=False, decimal_places=2, max_digits=12)
is_successful = models.BooleanField(default=True, editable=False)
def save(self, *args, **kwargs):
......
......@@ -303,6 +303,151 @@ footer a {
}
/* This is for agents views */
.main-agents{
min-height: 100vh;
height: wrap;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
}
.agent-list-wrapper{
display: block;
}
.main-agents a{
color: #000;
display: block;
}
.main-agents a:hover {
font-size: 20px;
font-weight: bolder;
transition: all 0.3s ease-in-out;
}
.agent-details{
min-height: 20vh;
height: wrap;
width: 100vw;
}
.agent-info{
height: 20vh;
width: 100vw;
display: flex;
padding: 20px;
}
.image-wrapper{
border-radius: 50%;
object-fit: cover;
height: 100%;
width: 20vh;
overflow: hidden;
justify-content: center;
align-items: center;
}
.image-wrapper img{
border-radius: 50%;
object-fit: cover;
height: 100%;
width: 100%;
}
.agent-content{
align-items: left;
text-align: left;
padding-left: 20px;
}
.agent-transactions{
min-height: 100vh;
height: wrap;
width: 100vw;
}
.agent-transactions table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
.agent-transactions td, .agent-transactions th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
.agent-transactions tr:nth-child(even) {
background-color: #dddddd;
}
.agent-transactions form{
display: block;
}
.agent-transactions.details{
min-height: 60vh;
}
.agent-transactions input[type=submit] {
height: fit-content;
width: 12vw;
padding: 5px 0;
border-radius: 10px;
background-color: #eee;
border-color: #2aabe4;
opacity: 0.5;
color: #2aabe4;
font-family: inherit;
font-size: 24px;
z-index: 10;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease-in-out;
opacity: 0.65;
margin-bottom: 20px;
}
.main-agents button{
height: 10vh;
width: 20vw;
padding: 5px 0;
border-radius: 10px;
background-color: #eee;
border-color: #2aabe4;
opacity: 0.5;
color: #2aabe4;
font-family: inherit;
font-size: 18px;
z-index: 10;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease-in-out;
opacity: 0.65;
margin-bottom: 20px;
}
.agent-transactions input[type=submit]:hover, .main-agents button:hover {
opacity: 1;
color: #2aabe4;
font-weight: bolder;
}
.agent-transactions input[type=submit]:active, .main-agents button:active {
transform: scale(0.98);
}
.agent-transactions input[type=submit]:focus, .main-agents button:focus {
outline: none;
}
@media (max-width: 1200px) {
header a {
......
from django.contrib import admin
from django.db.models.functions import Lower
from .models import Product, Feature, Folder, PenOrganizer, Planner, Description, Inventory, Discount
from .models import Product, Feature, Folder, PenOrganizer, Planner, Description, Inventory
# Register your models here.
class ProductAdmin(admin.ModelAdmin):
......@@ -25,13 +25,9 @@ class InventoryAdmin(admin.ModelAdmin):
model = Inventory
list_display = ('quantity', 'item_id', 'color', )
class DiscountAdmin(admin.ModelAdmin):
model = Discount
admin.site.register(Feature, FeatureAdmin)
admin.site.register(Folder, FolderAdmin)
admin.site.register(PenOrganizer, PenOrganizerAdmin)
admin.site.register(Planner, PlannerAdmin)
admin.site.register(Description, DescriptionAdmin)
admin.site.register(Inventory, InventoryAdmin)
\ No newline at end of file
admin.site.register(Discount, DiscountAdmin)
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-11-22 02:10
# Generated by Django 3.2.12 on 2022-12-01 10:07
import django.core.validators
from django.db import migrations, models
......@@ -8,17 +8,17 @@ def populate_products(apps, schema_editor):
Folder = apps.get_model('products', 'Folder')
PenOrganizer = apps.get_model('products', 'PenOrganizer')
Planner = apps.get_model('products', 'Planner')
obj = Folder(item_name="Flipper", price=745, personalization=8, length=13.5, width=10.25, thickness=0.75)
obj = Folder(item_name="Flipper", price=745, personalization_limit=8, length=13.5, width=10.25, thickness=0.75)
obj.save()
obj = Folder(item_name="Filer", price=995, personalization=8, length=14, width=11, thickness=1.5)
obj = Folder(item_name="Filer", price=995, personalization_limit=8, length=14, width=11, thickness=1.5)
obj.save()
obj = PenOrganizer(item_name="Slinger", price=95, personalization=5, slots=6)
obj = PenOrganizer(item_name="Slinger", price=95, personalization_limit=5, slots=6)
obj.save()
obj = PenOrganizer(item_name="Shifter", price=295, personalization=8, slots=15)
obj = PenOrganizer(item_name="Shifter", price=295, personalization_limit=8, slots=15)
obj.save()
obj = Planner(item_name="Doodler", price=595, personalization=8, length=8, width=6, thickness=0.75)
obj = Planner(item_name="Doodler", price=595, personalization_limit=8, length=8, width=6, thickness=0.75)
obj.save()
obj = Planner(item_name="Scribler", price=595, personalization=8, length=8, width=6, thickness=0.75)
obj = Planner(item_name="Scribler", price=595, personalization_limit=8, length=8, width=6, thickness=0.75)
obj.save()
feature_model = apps.get_model('products', 'Feature')
......@@ -99,7 +99,7 @@ class Migration(migrations.Migration):
('item_id', models.AutoField(primary_key=True, serialize=False)),
('item_name', models.CharField(max_length=50)),
('price', models.PositiveIntegerField(help_text='in pesos')),
('personalization', models.PositiveIntegerField(help_text='up how many letters?')),
('personalization_limit', models.PositiveIntegerField(help_text='up how many letters?')),
],
options={
'db_table': 'product',
......@@ -168,19 +168,6 @@ class Migration(migrations.Migration):
'db_table': 'feature',
},
),
migrations.CreateModel(
name='Discount',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('discount_percent', models.PositiveIntegerField(default=0, validators=[django.core.validators.MaxValueValidator(100), django.core.validators.MinValueValidator(0)])),
('start_date', models.DateField()),
('end_date', models.DateField()),
('item_id', models.ForeignKey(db_column='item_id', on_delete=django.db.models.deletion.CASCADE, to='products.product')),
],
options={
'db_table': 'Discount',
},
),
migrations.AddField(
model_name='description',
name='feature_id',
......
# Generated by Django 3.2.12 on 2022-11-27 12:46
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('products', '0001_initial'),
]
operations = [
migrations.AlterModelTable(
name='penorganizer',
table='penorganizer',
),
]
# Generated by Django 3.2.12 on 2022-11-27 12:47
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('products', '0002_alter_penorganizer_table'),
]
operations = [
migrations.AlterModelTable(
name='penorganizer',
table='pen_organizer',
),
]
......@@ -6,7 +6,7 @@ class Product(models.Model):
item_id = models.AutoField(primary_key=True)
item_name = models.CharField(max_length=50)
price = models.PositiveIntegerField(help_text='in pesos')
personalization = models.PositiveIntegerField(help_text='up how many letters?')
personalization_limit = models.PositiveIntegerField(help_text='up how many letters?')
def __str__(self):
return "#" + str(self.item_id) + " (" + self.item_name + ")"
class Meta:
......@@ -62,12 +62,3 @@ class Inventory(models.Model):
class Meta:
db_table = "Inventory"
\ No newline at end of file
class Discount(models.Model):
item_id = models.ForeignKey(Product, on_delete=models.CASCADE, db_column='item_id')
discount_percent = models.PositiveIntegerField(default=0, validators=[MaxValueValidator(100), MinValueValidator(0)])
start_date = models.DateField()
end_date = models.DateField()
def __str__(self):
return str(self.discount_percent) + "% discount applied on item " + str(self.item_id) + " valid from " + str(self.start_date) + " till " + str(self.end_date)
class Meta:
db_table = "Discount"
# Generated by Django 3.2.12 on 2022-11-20 02:03
# Generated by Django 3.2.12 on 2022-12-01 10:08
from django.db import migrations, models
import django.db.models.deletion
......
{% 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/{{agent.agent_id}}.jpg" alt="">
</div>
<div class="agent-content">
<p>First Name: &nbsp;{{agent.first_name}}</p>
<p>Last Name: &nbsp;{{agent.last_name}}</p>
<p>Agent Id: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{agent.agent_id|stringformat:"06d"}}</p>
<p>Number of Customers Assigned: {{agent.customer_served}}</p>
</div>
</div>
</section>
<hr>
<section class="agent-transactions details">
<h2>Agent Transactions</h2>
<table>
<tr>
<th>Date</th>
<th>Customer</th>
<th>Order No.</th>
<th>Total Amount</th>
</tr>
{% for order in order_list %}
<tr>
<th>{{order.order_date}}</th>
<th>{{order.customer_id.first_name}} {{order.customer_id.last_name}}</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/agents/{{agent.agent_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="agent-transactions">
<br><br><br><br>
<h2>Agent Transactions</h2>
<table>
<tr>
<th>Date</th>
<th>Agent</th>
<th>Customer</th>
<th>Order No.</th>
<th>Total Amount</th>
</tr>
{% for order in order_list %}
<tr>
<th>{{order.order_date}}</th>
<th>{{order.customer_id.agent_id.first_name}} {{order.customer_id.agent_id.last_name}}</th>
<th>{{order.customer_id.first_name}} {{order.customer_id.last_name}}</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/agents/agent-transaction/custom">
<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="agent-transactions">
<br><br><br><br>
<h2>Agent Transactions</h2>
<table>
<tr>
<th>Date</th>
<th>Agent</th>
<th>Customer</th>
<th>Order No.</th>
<th>Total Amount</th>
</tr>
{% for order in order_list %}
<tr>
<th>{{order.order_date}}</th>
<th>{{order.customer_id.agent_id.first_name}} {{order.customer_id.agent_id.last_name}}</th>
<th>{{order.customer_id.first_name}} {{order.customer_id.last_name}}</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="">
<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>Agents</h1>
{% for agent in agent_list %}
<a href="agents/{{ agent.agent_id }}/details">{{ agent.first_name }} {{ agent.last_name }}</a>
{% endfor %}
<br><br>
<a href="agents/agent-transaction"><button>All Agent transactions</button></a>
</div>
</section>
{% endblock %}
......@@ -18,9 +18,7 @@
<div class="wrapper">
{% for folder in folder_list %}
<div class="card">
<div class="img_wrapper"><img
src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80"
alt="product"></div>
<div class="img_wrapper"><img src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="product"></div>
<div class="card-content">
<div class="card-content-main">
<div class="item_name">{{ folder.item_name }}</div>
......@@ -28,7 +26,7 @@
</div>
<ul>
{% for description in description_list %}
{% if folder.item_id == description.item_id%}
{% if folder.item_id == description.item_id.item_id%}
<li>{{ description.feature_id.feature }}</li>
{% endif %}
{% endfor %}
......@@ -43,9 +41,7 @@
<div class="wrapper">
{% for pen_organizer in pen_organizer_list %}
<div class="card">
<div class="img_wrapper"><img
src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80"
alt="product"></div>
<div class="img_wrapper"><img src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="product"></div>
<div class="card-content">
<div class="card-content-main">
<div class="item_name">{{ pen_organizer.item_name }}</div>
......@@ -68,9 +64,7 @@
<div class="wrapper">
{% for planner in planner_list %}
<div class="card">
<div class="img_wrapper"><img
src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80"
alt="product"></div>
<div class="img_wrapper"><img src="https://images.unsplash.com/photo-1615485737442-7d6ab9f64db9?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="product"></div>
<div class="card-content">
<div class="card-content-main">
<div class="item_name">{{ planner.item_name }}</div>
......
{% 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">Products</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="hero">
......
......@@ -4,4 +4,9 @@ from . import views
appname = "users"
urlpatterns = [
path('', views.index, name="index"),
path('agents', views.agents, name="agents"),
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"),
]
\ No newline at end of file
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
# Create your views here.
def index(request):
return render(request, "users/users.html")
def homepage(request):
product_list = Product.objects.all()
folder_list = Folder.objects.all().values('item_name', 'price').distinct()
folder_list = Folder.objects.all()
pen_organizer_list = PenOrganizer.objects.all()
planner_list = Planner.objects.all()
description_list = Description.objects.all()
return render(request, "users/homepage.html", {"product_list":product_list, "folder_list":folder_list,
"pen_organizer_list":pen_organizer_list, "planner_list":planner_list,
"description_list":description_list})
def agents(request):
agent_list = SalesAgent.objects.order_by("first_name")
return render(request, "users/agents.html", {"agent_list":agent_list})
def agent_details(request, agent_id):
try:
agent = SalesAgent.objects.get(pk=agent_id)
except SalesAgent.DoesNotExist:
raise Http404("Agent does not exist")
customer_list = Customer.objects.filter(agent_id=agent_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])
return render(request, "users/agent_details.html",{"agent": agent, "order_list":order_list, "customer_list":customer_list})
def agent_transactions(request):
order_list = Order.objects.all()
return render(request, "users/agent_transactions.html" ,{"order_list":order_list})
def agent_transactions_custom(request):
start_date = request.GET.get('start-date', 'not found')
end_date = request.GET.get('end-date', 'not found')
order_list = Order.objects.filter(order_date__range=[start_date, end_date])
return render(request, "users/agent_transactions_custom.html" ,{"order_list":order_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