Skip to content

Commit

Permalink
updated admin dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
nyashaChiza committed Aug 28, 2024
1 parent 8597c03 commit 94d177a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 62 deletions.
42 changes: 32 additions & 10 deletions dashboard/helpers/dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,45 @@ def get_all_sites_monthly_sales(self):


def get_all_sites_remaining_stock(self):
return {}

data = []
sites = self.user.company.sites.all()

def get_all_sites_total_stock_sales(self):
return {}
for site in sites:
remaining_stock = Stock.objects.filter(site=site).aggregate(Sum('quantity'))['quantity__sum'] or 0
data.append({'site':site, 'remaining_stock':f"{remaining_stock}/{site.capacity}", 'remaining_stock_percentage':round(remaining_stock/site.capacity*100)})
return data


def get_all_sites_requisitions(self):
def get_all_sites_sales_bar_graph_totals(self):
return {}


def get_alll_sites_sales_totals(self):
def get_all_site_sales_line_graph_monthly_totals(self):
return {}

def get_company_data(self):
total_sales = 0
sites = self.user.company.sites.all()
for site in sites:
total_sales += Transaction.objects.filter(site=site).aggregate(
total_sales=Sum(F('quantity') * F('unit_cost'))
)['total_sales'] * site.stock.first().price or 0

return {
'company': self.user.company,
'capacity': sum(site.capacity for site in self.user.company.sites.all())
'capacity': sum(site.capacity for site in self.user.company.sites.all()),
'total_sales': total_sales,
'monthly_average':total_sales / 12,
'weekly_average':total_sales / 52,
'daily_average':total_sales / 365,
}



def get_company_site_stats(self):
sites = self.user.company.sites.all()
data = []
total_quantity = 0
for site in sites:
total_quantity += Transaction.objects.filter(site=site).aggregate(
total_quantity=Sum(F('quantity') * F('unit_cost'))
)['total_quantity']
data.append({'site':site, 'total_requisitions':site.requisitions.all().count(),'total_sales':total_quantity* site.stock.first().price or 0, 'total_quantity':total_quantity })
return data
2 changes: 1 addition & 1 deletion dashboard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

urlpatterns = [
path('', DashboardView.as_view(), name='dashboard'),
path('/admin-dash', AdminDashboardView.as_view(), name='admin_dashboard'),
path('admin-dash', AdminDashboardView.as_view(), name='admin_dashboard'),
path('reports/', generate_reports, name='report_create'),
]
2 changes: 1 addition & 1 deletion stock/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __str__(self):
return f"{self.name}"

class Reciept(models.Model):
site = models.ForeignKey('accounts.Site', on_delete=models.SET_NULL, null=True, blank=True)
site = models.ForeignKey('accounts.Site', on_delete=models.SET_NULL, null=True, blank=True, related_name='requisitions')
quantity = models.PositiveIntegerField()
stock = models.ForeignKey(Stock, related_name='reciepts', on_delete=models.SET_NULL, null=True, blank=True)
description = models.TextField(blank=True, null=True)
Expand Down
71 changes: 21 additions & 50 deletions templates/dashboard/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,54 +48,25 @@ <h6 class="title">Site Remaining Stock</h6>
</div>
<div class="card-inner pt-0">
<ul class="gy-4">
{% for data in dashboard_data.get_all_sites_remaining_stock %}
<li class="border-bottom border-0 border-dashed">
<div class="mb-1">
<span class="fs-2 lh-1 mb-1 text-head">85.6kg</span>
<span class="fs-2 lh-1 mb-1 text-head">{{ data.remaining_stock }}kg</span>

</div>
<div class="align-center">
<div class="small text-primary me-2">54%</div>
<div class="small text-primary me-2">{{ data.remaining_stock_percentage }}%</div>
<div class="progress progress-md rounded-pill w-100 bg-primary-dim">
<div class="progress-bar bg-success rounded-pill" data-progress="54" style="width: 54%;"></div>
<div class="progress-bar bg-{% if data.remaining_stock_percentage > 50%}success{% else %}warning{% endif %} rounded-pill" data-progress="{{ data.remaining_stock_percentage }}" style="width: {{ data.remaining_stock_percentage }}%;"></div>
</div>
<div class="dropdown ms-3">
<span class=" sub-text" >Site Name</span>
<span class=" sub-text" >{{ data.site }}</span>

</div>
</div>
</li>
<li class="border-bottom border-0 border-dashed">
<div class="mb-1">
<span class="fs-2 lh-1 mb-1 text-head">85.6kg</span>

</div>
<div class="align-center">
<div class="small text-primary me-2">54%</div>
<div class="progress progress-md rounded-pill w-100 bg-primary-dim">
<div class="progress-bar bg-success rounded-pill" data-progress="54" style="width: 54%;"></div>
</div>
<div class="dropdown ms-3">
<span class=" sub-text" >Site Name</span>

</div>
</div>
</li>
<li class="border-bottom border-0 border-dashed">
<div class="mb-1">
<span class="fs-2 lh-1 mb-1 text-head">85.6kg</span>

</div>
<div class="align-center">
<div class="small text-primary me-2">54%</div>
<div class="progress progress-md rounded-pill w-100 bg-primary-dim">
<div class="progress-bar bg-success rounded-pill" data-progress="54" style="width: 54%;"></div>
</div>
<div class="dropdown ms-3">
<span class=" sub-text" >Site Name</span>

</div>
</div>
</li><!-- li -->
{% endfor %}
<!-- li -->
</ul>
</div>
</div><!-- .card -->
Expand All @@ -111,33 +82,33 @@ <h6 class="title">Total Sales Per Site</h6>
</div>
</div>
<div class="nk-tb-list is-loose">
{% for data in dashboard_data.get_company_site_stats %}
<div class="nk-tb-item nk-tb-head">
<div class="nk-tb-col"><span>Site</span></div>
<div class="nk-tb-col text-end"><span>Requisitions</span></div>
<div class="nk-tb-col text-end"><span>Quantity</span></div>
<div class="nk-tb-col"><span>Users</span></div>
<div class="nk-tb-col tb-col-sm text-end"><span>Amount</span></div>
</div><!-- .nk-tb-head -->
<div class="nk-tb-item">
<div class="nk-tb-col">
<div class="icon-text">
<em class="icon ni ni-map-pin"></em>
<span class="tb-lead">Google Chrome</span>
<span class="tb-lead">{{ data.site }}</span>
</div>
</div>
<div class="nk-tb-col text-end">
<span class="tb-sub tb-amount"><span>1,641</span></span>
<span class="tb-sub tb-amount"><span>{{ data.total_requisitions }}</span></span>
</div>
<div class="nk-tb-col">
<div class="progress progress-md progress-alt bg-transparent">
<div class="progress-bar" data-progress="72.84" style="width: 72.84%;"></div>
<div class="progress-amount">72.84%</div>
</div>

<div class="nk-tb-col text-end">
<span class="tb-sub tb-amount"><span>{{ data.total_quantity }}kg</span></span>
</div>

<div class="nk-tb-col tb-col-sm text-end">
<span class="tb-sub">22.62%</span>
<span class="tb-sub">${{ data.total_sales }}</span>
</div>
</div><!-- .nk-tb-item -->

{% endfor %}
</div><!-- .nk-tb-list -->
</div><!-- .card -->
</div><!-- .col -->
Expand Down Expand Up @@ -170,7 +141,7 @@ <h6 class="title">Organisation Statistics</h6>
<li class="item">
<div class="info">
<div class="title">Total Sales</div>
<div class="count">{{ dashboard_data.get_stock_data.total_requisitions }}</div>
<div class="count">${{ dashboard_data.get_company_data.total_sales }}</div>
</div>
<em class="icon bg-purple-dim ni ni-truck"></em>
</li>
Expand Down Expand Up @@ -209,17 +180,17 @@ <h6 class="title">Total Sales Per Month</h6>
<div class="data-group">
<div class="data">
<div class="title">Monthly</div>
<div class="amount amount-sm">${{ dashboard_data.get_sales_plot_data.monthly_average|format_amount }}</div>
<div class="amount amount-sm">${{ dashboard_data.get_company_data.monthly_average|format_amount }}</div>

</div>
<div class="data">
<div class="title">Weekly</div>
<div class="amount amount-sm">${{ dashboard_data.get_sales_plot_data.weekly_average|format_amount }}</div>
<div class="amount amount-sm">${{ dashboard_data.get_company_data.weekly_average|format_amount }}</div>

</div>
<div class="data">
<div class="title">Daily (Avg)</div>
<div class="amount amount-sm">${{ dashboard_data.get_sales_plot_data.daily_average|format_amount }}</div>
<div class="amount amount-sm">${{ dashboard_data.get_company_data.daily_average|format_amount }}</div>

</div>
</div>
Expand Down

0 comments on commit 94d177a

Please sign in to comment.