First draft of elm frontend
This will probably be scrapped or rewritten
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
SELECT
|
||||
group_id,
|
||||
group_name
|
||||
group_id AS id,
|
||||
group_name AS name
|
||||
FROM garfield.inventory_item_groups
|
||||
ORDER BY
|
||||
group_name ASC
|
||||
@@ -0,0 +1,4 @@
|
||||
SELECT
|
||||
location_id AS id,
|
||||
location_name AS name
|
||||
FROM garfield.locations
|
||||
@@ -0,0 +1,9 @@
|
||||
SELECT
|
||||
tax_group_id AS id,
|
||||
description,
|
||||
tax_percentage :: float AS percentage,
|
||||
tax_description AS description
|
||||
FROM garfield.tax_groups,
|
||||
LATERAL garfield.tax_find(tax_group_id, NOW() :: date) AS tax_id
|
||||
LEFT JOIN garfield.taxes USING (tax_id)
|
||||
WHERE active
|
||||
@@ -0,0 +1,18 @@
|
||||
SELECT
|
||||
item_barcode,
|
||||
name,
|
||||
unit_price :: float,
|
||||
TO_CHAR(bought, 'YYYY-MM-DD') AS bought,
|
||||
sales_units,
|
||||
available,
|
||||
location_name,
|
||||
location_id,
|
||||
group_name,
|
||||
item_group AS group_id,
|
||||
tax_group AS tax_group_id
|
||||
FROM garfield.inventory_items
|
||||
LEFT JOIN garfield.locations ON location = location_id
|
||||
LEFT JOIN garfield.inventory_item_groups ON item_group = group_id
|
||||
WHERE (%(location_id)s IS NULL OR location = %(location_id)s)
|
||||
AND (name ILIKE CONCAT('%%', %(search_term)s, '%%') OR item_barcode = %(search_term)s)
|
||||
ORDER BY bought DESC
|
||||
+32
-5
@@ -1,9 +1,6 @@
|
||||
import datetime
|
||||
import zoneinfo
|
||||
|
||||
|
||||
from flask import Blueprint, redirect, render_template, request, session
|
||||
|
||||
|
||||
from . import db
|
||||
|
||||
|
||||
@@ -12,4 +9,34 @@ bp = Blueprint("entry", __name__, url_prefix="/entry")
|
||||
|
||||
@bp.get("/")
|
||||
def index():
|
||||
return render_template("entry/index.html")
|
||||
with db.run_query("entry/get_groups.sql") as cursor:
|
||||
groups = cursor.fetchall()
|
||||
|
||||
with db.run_query("entry/get_locations.sql") as cursor:
|
||||
locations = cursor.fetchall()
|
||||
|
||||
with db.run_query("entry/get_tax_groups.sql") as cursor:
|
||||
tax_groups = cursor.fetchall()
|
||||
|
||||
return render_template("entry/index.html", **{
|
||||
"locations": locations,
|
||||
"groups": groups,
|
||||
"tax_groups": tax_groups
|
||||
})
|
||||
|
||||
@bp.get("/api/search-items")
|
||||
def api_search_items():
|
||||
try:
|
||||
search_term = request.args["search-term"]
|
||||
except:
|
||||
return {"error": "Missing query parameter `search-term`"}, 400
|
||||
|
||||
location = session.get("location", None)
|
||||
|
||||
with db.run_query("search_items.sql", {
|
||||
"location_id": None if location is None else location["location_id"],
|
||||
"search_term": search_term
|
||||
}) as cursor:
|
||||
items = cursor.fetchall()
|
||||
|
||||
return items
|
||||
|
||||
+12011
File diff suppressed because it is too large
Load Diff
+3
-14
@@ -1,4 +1,4 @@
|
||||
import datetime
|
||||
import json
|
||||
|
||||
|
||||
def format_currency(x):
|
||||
@@ -15,16 +15,5 @@ def format_bool(x):
|
||||
return "✅" if x else "❌"
|
||||
|
||||
|
||||
def now():
|
||||
return datetime.datetime.now()
|
||||
|
||||
|
||||
def get_garfield_price(net_unit_price, tax_group_id):
|
||||
if tax_group_id == 1:
|
||||
tax_factor = 1.19
|
||||
elif tax_group_id == 2:
|
||||
tax_factor = 1.07
|
||||
else:
|
||||
raise Error("Unknown tax group ID")
|
||||
|
||||
return net_unit_price * tax_factor + 0.01
|
||||
def to_json(x):
|
||||
return json.dumps(x)
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<a href="/entry/edit-item-data">Neuer Eintrag</a>
|
||||
<div class="entry-app"></div>
|
||||
<script src="{{ url_for('static', filename='entry.js') }}"></script>
|
||||
<script>
|
||||
Elm.Entry.init({
|
||||
node: document.querySelector('.entry-app'),
|
||||
flags: {
|
||||
locations: {{ to_json(locations) | safe }},
|
||||
groups: {{ to_json(groups) | safe }},
|
||||
taxGroups: {{ to_json(tax_groups) | safe }}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user