Skip to content

Commit

Permalink
Statistics (#118)
Browse files Browse the repository at this point in the history
* dark mode & product stats

* statistics

* Some fixes

* Fix contrast

* fixes

---------

Co-authored-by: Aiq0 <[email protected]>
  • Loading branch information
Stanko2 and Aiq0 authored Dec 18, 2024
1 parent 6439011 commit 1fc154a
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 82 deletions.
10 changes: 5 additions & 5 deletions sortiment/store/templates/products/_search.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% load icon %}
{% if not product %}
<form action="{% url 'store:product_search' %}" method="get" autocomplete="off" data-turbo-frame="product-search">
<input type="search" class="input" name="q" placeholder="Zadaj čiarový kód / názov produktu..." autofocus />
<input type="search" class="input dark:bg-gray-900 dark:border-gray-700" name="q" placeholder="Zadaj čiarový kód / názov produktu..." autofocus />

<turbo-frame id="product-search" target="_top">
<div class="mt-4 bg-gray-50 p-2 rounded-md space-y-2">
<a href="{% url 'store:add_product' %}" class="flex items-center gap-2 hover:bg-gray-100 rounded p-2" >
<div class="mt-4 bg-gray-50 dark:bg-gray-950 p-2 rounded-md space-y-2">
<a href="{% url 'store:add_product' %}" class="flex items-center gap-2 hover:bg-gray-100 dark:hover:bg-gray-900 rounded p-2" >
<div class="w-12 h-12 bg-green-500 rounded text-white flex items-center justify-center">
{% icon "plus" %}
</div>
Expand All @@ -15,7 +15,7 @@

{% if query %}
{% for product in products %}
<a href="?product={{ product.id }}" class="flex items-center gap-2 hover:bg-gray-100 rounded p-2">
<a href="?product={{ product.id }}" class="flex items-center gap-2 hover:bg-gray-100 dark:hover:bg-gray-900 rounded p-2">
<div class="w-12">
{% include "store/_item_image.html" %}
</div>
Expand All @@ -31,7 +31,7 @@
</turbo-frame>
</form>
{% else %}
<div class="flex items-center gap-2 p-4 bg-gray-100 rounded mb-4">
<div class="flex items-center gap-2 p-4 dark:bg-gray-900 bg-gray-100 rounded mb-4">
<div class="w-12">
{% include "store/_item_image.html" %}
</div>
Expand Down
24 changes: 12 additions & 12 deletions sortiment/store/templates/products/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
{% block setting %}
<h1 class="font-bold text-3xl text-center mb-6 mt-4">Správa sortimentu</h1>

<div class="overflow-hidden rounded-md border divide-y mx-auto max-w-md">
<a href="{% url 'store:product_edit' %}" class="block p-3 hover:bg-gray-100">
<div class="overflow-hidden rounded-md border dark:border-gray-700 dark:*:border-gray-700 divide-y mx-auto max-w-md">
<a href="{% url 'store:product_edit' %}" class="block p-3 hover:bg-gray-100 dark:hover:bg-gray-800">
<div>Úprava produktov</div>
<div class="text-xs text-gray-600">Pridanie nového produktu, úprava informácií o existujúcom produkte</div>
<div class="text-xs text-gray-600 dark:text-gray-400">Pridanie nového produktu, úprava informácií o existujúcom produkte</div>
</a>
<a href="{% url 'store:product_import' %}" class="block p-3 hover:bg-gray-100">
<a href="{% url 'store:product_import' %}" class="block p-3 hover:bg-gray-100 dark:hover:bg-gray-800">
<div>Príjem tovaru</div>
<div class="text-xs text-gray-600">Nahodenie kúpených produktov do bufetu</div>
<div class="text-xs text-gray-600 dark:text-gray-400">Nahodenie kúpených produktov do bufetu</div>
</a>
<a href="{% url 'store:product_transfer' %}" class="block p-3 hover:bg-gray-100">
<a href="{% url 'store:product_transfer' %}" class="block p-3 hover:bg-gray-100 dark:hover:bg-gray-800">
<div>Presun tovaru medzi skladmi</div>
</a>
<a href="{% url 'store:correction' %}" class="block p-3 hover:bg-gray-100">
<a href="{% url 'store:correction' %}" class="block p-3 hover:bg-gray-100 dark:hover:bg-gray-800">
<div>Korekcia skladu</div>
<div class="text-xs text-gray-600">Úprava chýb pri príjme tovaru</div>
<div class="text-xs text-gray-600 dark:text-gray-400">Úprava chýb pri príjme tovaru</div>
</a>
<a href="{% url 'store:product_discard' %}" class="block p-3 hover:bg-gray-100">
<a href="{% url 'store:product_discard' %}" class="block p-3 hover:bg-gray-100 dark:hover:bg-gray-800">
<div>Vyradenie tovaru</div>
<div class="text-xs text-gray-600">Vyhodenie tovaru po záruke</div>
<div class="text-xs text-gray-600 dark:text-gray-400">Vyhodenie tovaru po záruke</div>
</a>
<a href="{% url 'store:inventory' %}" class="block p-3 hover:bg-gray-100">Inventúra</a>
<a href="{% url 'store:reset' %}" class="block p-3 hover:bg-red-100 text-red-700 font-bold">RESET skladu</a>
<a href="{% url 'store:inventory' %}" class="block p-3 hover:bg-gray-100 dark:hover:bg-gray-800">Inventúra</a>
<a href="{% url 'store:reset' %}" class="block p-3 hover:bg-red-100 dark:hover:bg-red-950 text-red-700 font-bold">RESET skladu</a>
</div>
{% endblock %}
8 changes: 4 additions & 4 deletions sortiment/store/templates/store/_button_style.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% if color == "blue" %}
{% if page_name == request.path %}
"btn bg-blue-500 text-gray-100 hover:bg-blue-600 hover:text-gray-200"
"btn bg-blue-500 dark:bg-blue-600 text-gray-100 hover:bg-blue-600 hover:text-gray-200"
{% else %}
"btn bg-blue-100 text-gray-700 hover:bg-blue-300 hover:text-gray-900"
"btn bg-blue-100 dark:bg-blue-900 text-gray-700 dark:text-gray-300 hover:bg-blue-300 dark:hover:bg-blue-500 hover:text-gray-900"
{% endif %}
{% elif color == "red" %}
{% if page_name == request.path %}
"btn bg-red-500 text-red-100 hover:bg-red-600 hover:text-red-200"
"btn bg-red-500 text-red-100 dark:text-red-900 hover:bg-red-600 hover:text-red-200"
{% else %}
"btn bg-red-100 text-red-700 hover:bg-red-300 hover:text-red-900"
"btn bg-red-100 dark:bg-red-900 text-red-700 dark:text-red-300 hover:bg-red-300 dark:hover:bg-red-500 hover:text-red-900"
{% endif %}
{% else %}
{% if page_name == request.path %}
Expand Down
6 changes: 3 additions & 3 deletions sortiment/store/templates/store/_cart.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load icon %}

<turbo-frame class="flex flex-col flex-1 min-h-0 border-t" id="turbo-cart">
<turbo-frame class="flex flex-col flex-1 min-h-0 border-t dark:border-gray-700" id="turbo-cart">
<div class="pl-3 pr-2 py-2 overflow-y-auto">
<div class="font-bold">Môj nákup</div>

Expand All @@ -15,7 +15,7 @@
<div class="text-xs">{{ item.quantity }} × {{ item.product.price }} €</div>
</div>

<div class="text-blue-700 text-sm ml-auto shrink-0">{{ item.total_price|floatformat:2 }} €</div>
<div class="text-blue-700 dark:text-blue-500 text-sm ml-auto shrink-0">{{ item.total_price|floatformat:2 }} €</div>
<a class="hover:bg-red-400/20 text-red-700 p-3 -m-2 rounded-full shrink-0 -ml-3 cursor-pointer" role="button" href="{% url 'store:cart_remove' item.product.id %}" data-turbo-method="post">
{% icon "x" class="w-6 h-6" %}
</a>
Expand All @@ -24,7 +24,7 @@
</div>
</div>

<div class="p-3 mt-auto border-t flex space-x-2 justify-between">
<div class="p-3 mt-auto border-t dark:border-gray-700 flex space-x-2 justify-between">
{% if cart.total_price > user.credit and not user.is_guest %}
<div class="w-full bg-red-600 btn text-lg cursor-not-allowed text-white">Nedostatok kreditu</div>
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion sortiment/store/templates/store/_item_image.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load icon %}
<div class="w-full flex items-center justify-center aspect-square rounded-md bg-white border overflow-hidden">
<div class="w-full flex items-center justify-center aspect-square rounded-md bg-white border dark:border-gray-700 overflow-hidden">
{% if product.image %}
<img class="max-w-full max-h-full" src="{{ product.image.url }}" loading="lazy">
{% else %}
Expand Down
4 changes: 2 additions & 2 deletions sortiment/store/templates/store/_products_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-6 gap-4 p-6">
{% for p in products %}
{% cache 3600 "product_detail" p.product.id p.global_quantity %}
<a class="hover:bg-gray-50 p-2 rounded-lg cursor-pointer {% if not p.product.is_unlimited and p.local_quantity <= 0 %} opacity-30 grayscale hover:opacity-100 {% endif %}" role="button" href="{% url 'store:cart_add' p.product.id %}" data-turbo-method="post" data-turbo-frame="turbo-cart" {% if forloop.first %}data-barcode-target="firstProduct"{% endif %}
<a class="hover:bg-gray-50 dark:hover:bg-gray-800 p-2 rounded-lg cursor-pointer {% if not p.product.is_unlimited and p.local_quantity <= 0 %} opacity-30 grayscale hover:opacity-100 {% endif %}" role="button" href="{% url 'store:cart_add' p.product.id %}" data-turbo-method="post" data-turbo-frame="turbo-cart" {% if forloop.first %}data-barcode-target="firstProduct"{% endif %}
{% if request.GET.query == p.product.barcode %}data-exact-match="1"{% endif %}>
{% include "store/_item_image.html" with product=p.product %}
<h2 class="text-lg font-bold mt-1">{{ p.product.name }}</h2>

<div class="flex text-sm text-gray-700">
<div class="flex text-sm text-gray-700 dark:text-gray-400">
<div>{{ p.product.price }}&nbsp;&euro;</div>
<div class="ml-auto">
{% if p.product.is_unlimited %}
Expand Down
6 changes: 3 additions & 3 deletions sortiment/store/templates/store/cart_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

{% block content %}
<div class="w-full h-screen flex" data-controller="menu-toggle" data-menu-toggle-toggle-class="hidden">
<div class="w-full hidden flex fixed inset-0 sm:relative sm:w-72 bg-gray-100 z-20 sm:shrink-0 h-screen max-h-screen border-r sm:flex flex-col"
<div class="w-full hidden flex fixed inset-0 sm:relative sm:w-72 bg-gray-100 dark:bg-gray-800 dark:text-gray-100 z-20 sm:shrink-0 h-screen max-h-screen border-r dark:border-gray-700 sm:flex flex-col"
data-menu-toggle-target="menu">
<div class="bg-blue-600 text-white font-bold text-xl p-3 flex items-center">
<div class="bg-blue-600 dark:bg-blue-800 text-white dark:text-gray-300 font-bold text-xl p-3 flex items-center">
<span>Sortiment</span>
<button class="sm:hidden ml-auto hover:bg-black/20 p-2 text-blue-200 -m-2 rounded-full shrink-0" data-action="menu-toggle#toggleMenu">
{% icon "x" class="w-6 h-6" %}
Expand All @@ -31,7 +31,7 @@
{% include "store/_cart.html" %}
</div>
<div class="overflow-y-auto max-h-screen flex-1">
<div class="bg-blue-600 text-white font-bold text-xl p-3 flex items-center sm:hidden">
<div class="bg-blue-600 dark:bg-blue-800 text-white font-bold text-xl p-3 flex items-center sm:hidden">
<span>Sortiment</span>
<button class="sm:hidden ml-auto hover:bg-black/20 p-2 text-blue-200 -m-2 rounded-full shrink-0" data-action="menu-toggle#toggleMenu">
{% icon "menu" class="w-6 h-6" %}
Expand Down
6 changes: 3 additions & 3 deletions sortiment/store/templates/store/products.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

{% block cartright %}
<div data-controller="barcode">
<div class="sticky top-0 bg-white p-6 border-b z-10">
<div class="sticky top-0 bg-white dark:bg-gray-950 p-6 border-b dark:border-gray-700 z-10">
<form action="{% url "store:product_list" %}" autocomplete="off"
data-barcode-target="form" data-turbo-stream data-turbo-frame="turbo-products">
<input type="search" class="input" name="query"
<input type="search" class="input dark:bg-gray-700 dark:border-0 dark:text-gray-100" name="query"
placeholder="Načítaj čiarový kód alebo vyhladávaj podľa názvu (pridaj prvé do košíka s ENTERom)"
value="{{ request.GET.query }}"
data-barcode-target="field"
Expand All @@ -17,7 +17,7 @@

<div class="mt-2 w-full flex flex-row gap-2">
{% for tag in tags %}
<a href="?{% if tag.name != request.GET.tag %}tag={{ tag.name }}{% endif %}" class="rounded-md {% if tag.name == request.GET.tag %}bg-blue-600 text-white font-bold{% else %}bg-gray-200 text-gray-700{% endif %} px-2 py-1 text-sm">
<a href="?{% if tag.name != request.GET.tag %}tag={{ tag.name }}{% endif %}" class="rounded-md {% if tag.name == request.GET.tag %}bg-blue-600 dark:bg-blue-800 text-white font-bold{% else %}bg-gray-200 dark:bg-gray-800 text-gray-700 dark:text-gray-300{% endif %} px-2 py-1 text-sm">
#{{ tag.name }}
</a>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion sortiment/store/templates/store/purchase_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h2 class="font-bold text-2xl text-center mb-4 mt-6">História nákupov</h2>
</div>
{% else %}
<div class="flex items-center gap-2">
<div class="w-12 h-12 shrink-0 flex items-center justify-center rounded-md bg-gray-300">
<div class="w-12 h-12 shrink-0 flex items-center justify-center rounded-md bg-gray-300 dark:bg-gray-700">
{% icon "dollar-sign" class="w-1/2 h-1/2 text-white" %}
</div>
<div>
Expand Down
74 changes: 58 additions & 16 deletions sortiment/store/templates/store/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,107 @@
{% block title %}Štatistiky{% endblock %}

{% block content %}
<div class="w-full min-h-screen bg-blue-600 p-8">
<div class="bg-white p-8 rounded-md shadow-xl">
<div class="w-full min-h-screen bg-blue-600 dark:bg-blue-800 p-8">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script>
<div class="bg-white dark:bg-gray-950 p-8 rounded-md shadow-xl">

<a class='px-4 py-2 rounded bg-gray-200 hover:bg-gray-600 hover:text-white text-xl' href="{% url 'user_list' %}">Späť</a>
<a class='px-4 py-2 rounded bg-gray-200 dark:bg-gray-800 hover:bg-gray-600 hover:text-white text-xl' href="{% url 'user_list' %}">Späť</a>

<h1 class="font-bold text-3xl text-center m-6">Štatistiky</h1>

<h1 class="font-bold text-xl text-center m-6">Hodnota tovaru</h1>

<table class="mx-auto">
<table class="mx-auto rounded">
<thead>
<tr class="bg-blue-100">
<tr class="bg-blue-100 dark:bg-blue-900">
<th></th>
<th class="text-center p-4">Lokálne</th>
<th class="text-center p-4">Celkovo</th>
</tr>
</thead>
<tbody>
<tr>
<th class="text-center p-4 bg-blue-100">Nákupná:</th>
<th class="text-center p-4 bg-blue-100 dark:bg-blue-900">Nákupná:</th>
<td class="text-center p-2">{{ local_price_when_buy }}€</td>
<td class="text-center p-2">{{ total_price_when_buy }}€</td>
</tr>
<tr>
<th class="text-center p-4 bg-blue-100">Predajná:</th>
<th class="text-center p-4 bg-blue-100 dark:bg-blue-900">Predajná:</th>
<td class="text-center p-2">{{ local_price_for_sale }}€</td>
<td class="text-center p-2">{{ total_price_for_sale }}€</td>
</tr>
<tr>
<th class="text-center p-4 bg-blue-100">Zisk:</th>
<th class="text-center p-4 bg-blue-100 dark:bg-blue-900">Zisk:</th>
<td class="text-center p-2
{% if local_profit >= 0 %}
bg-green-200
dark:bg-green-800
{% else %}
bg-red-200
dark:bg-red-800
{% endif %}
">{{ local_profit }}€</td>
<td class="text-center p-2
{% if total_profit >= 0 %}
bg-green-200
dark:bg-green-800
{% else %}
bg-red-200
dark:bg-red-800
{% endif %}
">{{ total_profit }}€</td>
</tr>
</tbody>
</table>

<h2 class="font-bold text-xl text-center m-3">Suma kreditov: {{ credit_sum }}€</h2>

<h2 class="font-bold text-3xl text-center m-3">Najväčší kreditori</h2>

<div class="mx-auto text-xl text-center mx-auto m-3 space-y-2">
{% for creditor in top_creditors %}
<div class="">
{{ forloop.counter }}. {{ creditor.username }}
<hr class="dark:bg-gray-700" />
<div class="flex flex-wrap">
<div class="w-1/2">
<h2 class="font-bold text-3xl text-center m-3">Najväčší kreditori</h2>
<div class="text-xl text-center mx-auto m-3 space-y-2">
{% for creditor in top_creditors %}
<div class="">
{{ forloop.counter }}. {{ creditor.username }}
</div>
{% endfor %}
</div>
{% endfor %}
</div>
<div class="w-1/2">
<h2 class="font-bold text-3xl text-center m-3">Najlepšie produkty</h2>
<h4>Posledný mesiac</h4>
<canvas class="text-xl text-center graph w-full" id="products_lastmonth">
</canvas>
<h4>Celý čas</h4>
<canvas class="text-xl text-center graph w-full" id="products_alltime">
</canvas>
</div>
<div class="w-1/2">
<h2 class="font-bold text-3xl text-center m-3">Najväčší míňači</h2>
<canvas class="text-xl text-center graph w-full" id="users_spending">
</canvas>
</div>
</div>
</div>

<script>
document.addEventListener("DOMContentLoaded", async ()=> {
for (const graph of document.getElementsByClassName("graph")) {
const res = await (await fetch("/store/stats/" + graph.id + "/data")).json()
new Chart(graph, {
type: res.type ?? 'bar',
data: {
labels: res['data'].map(row => row.label),
datasets: [
{
label: res['title'],
data: res['data'].map(row => row.value)
}
]
}
})
}
})
</script>
</div>
{% endblock %}
3 changes: 3 additions & 0 deletions sortiment/store/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"purchases/", storefront.PurchaseHistoryView.as_view(), name="purchase_history"
),
path("stats/", storefront.StatsView.as_view(), name="stats"),
path(
"stats/<str:graph>/data", storefront.StatsDataView.as_view(), name="stats_data"
),
path("checkout/", storefront.CheckoutView.as_view(), name="checkout"),
path(
"cart/<int:product>/remove/",
Expand Down
Loading

0 comments on commit 1fc154a

Please sign in to comment.