Compare commits

...

2 Commits

5 changed files with 130 additions and 44 deletions

View File

@ -200,7 +200,7 @@ suggestedGrossPrice netPrice percentage =
view { globals, state } = case state of
ItemSearch model ->
fieldset []
[ legend [] [ text "Vorlage für neuen Inventareintrag" ]
[ legend [] [ text "Vorlage für Auftrag wählen" ]
, Html.form [ onSubmit SubmitSearch ]
[ div [ class "form-input" ]
[ label [ for "search-term", title "Barcode oder Name" ] [ text "Suchbegriff" ]
@ -210,19 +210,19 @@ view { globals, state } = case state of
]
]
ItemEditor model ->
Html.form [ method "POST", action "/entry/add-to-cart" ]
Html.form [ method "POST" ]
[ fieldset []
[ legend [] [ text "Neuer Inventareintrag" ]
, div [ class "form-input" ]
[ label [ for "barcode" ] [ text "Barcode" ]
, input [ onInput SetBarcode, value model.barcode, disabled True, name "barcode", id "barcode" ] []
, input [ onInput SetBarcode, value model.barcode, name "barcode", id "barcode" ] []
]
, div [ class "form-input" ]
[ label [ for "name" ] [ text "Name" ]
, input [ onInput SetName, value model.name, name "name", id "name" ] []
]
, div [ class "form-input" ]
[ label [ for "sales-units" ] [ text "Stückzahl" ]
[ label [ for "sales-units" ] [ text "Eingekauft" ]
, input [ onInput SetSalesUnits, value <| NumberInput.show model.salesUnits, name "sales-units", id "sales-units", type_ "number" ] []
]
, div [ class "form-input" ]
@ -264,7 +264,7 @@ view { globals, state } = case state of
[]
, viewSetSuggestedPriceButton model
]
, button [] [ text "In den Warenkorb" ]
, button [] [ text "Auftrag anlegen" ]
]
]

View File

@ -7,8 +7,59 @@ from . import db
bp = Blueprint("entry", __name__, url_prefix="/entry")
@bp.get("/")
@bp.route("/", methods=["GET", "POST"])
def index():
cart = session.get("cart", default=[])
return render_template(
"entry/index.html",
cart=cart
)
@bp.post("/delete-order")
def delete_order():
try:
order_index = int(request.form["order-index"])
except:
return f"Incomplete or mistyped form", 400
cart = session.get("cart", default=[])
del cart[order_index]
session["cart"] = cart
return redirect(request.referrer)
@bp.route("/new-order", methods=["GET", "POST"])
def new_order():
if request.method == "POST":
try:
barcode = request.form["barcode"]
name = request.form["name"]
sales_units = int(request.form["sales-units"])
group_id = int(request.form["group"])
location_id = int(request.form["location"])
tax_group_id = int(request.form["tax-group"])
net_unit_price = float(request.form["net-unit-price"])
gross_unit_price = float(request.form["gross-unit-price"])
except:
return f"Incomplete or mistyped form", 400
cart = session.get("cart", default=[])
print(cart)
cart.append({
"barcode": barcode,
"name": name,
"sales_units": sales_units,
"group_id": group_id,
"location_id": location_id,
"tax_group_id": tax_group_id,
"net_unit_price": net_unit_price,
"gross_unit_price": gross_unit_price
})
session["cart"] = cart
return redirect("/entry")
with db.run_query("entry/get_groups.sql") as cursor:
groups = cursor.fetchall()
@ -18,11 +69,17 @@ def index():
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
})
return render_template(
"entry/new-order.html",
groups=groups,
locations=locations,
tax_groups=tax_groups
)
# API routes for interactive JS stuff
@bp.get("/api/search-items")
def api_search_items():

View File

@ -11458,21 +11458,6 @@ var $author$project$Entry$SetTaxGroup = function (a) {
return {$: 'SetTaxGroup', a: a};
};
var $author$project$Entry$SubmitSearch = {$: 'SubmitSearch'};
var $elm$html$Html$Attributes$action = function (uri) {
return A2(
$elm$html$Html$Attributes$stringProperty,
'action',
_VirtualDom_noJavaScriptUri(uri));
};
var $elm$json$Json$Encode$bool = _Json_wrap;
var $elm$html$Html$Attributes$boolProperty = F2(
function (key, bool) {
return A2(
_VirtualDom_property,
key,
$elm$json$Json$Encode$bool(bool));
});
var $elm$html$Html$Attributes$disabled = $elm$html$Html$Attributes$boolProperty('disabled');
var $elm$html$Html$fieldset = _VirtualDom_node('fieldset');
var $elm$html$Html$Attributes$for = $elm$html$Html$Attributes$stringProperty('htmlFor');
var $elm$html$Html$form = _VirtualDom_node('form');
@ -11586,6 +11571,15 @@ var $author$project$Calculator$SetBundleSize = function (a) {
var $author$project$Calculator$SetTax = function (a) {
return {$: 'SetTax', a: a};
};
var $elm$json$Json$Encode$bool = _Json_wrap;
var $elm$html$Html$Attributes$boolProperty = F2(
function (key, bool) {
return A2(
_VirtualDom_property,
key,
$elm$json$Json$Encode$bool(bool));
});
var $elm$html$Html$Attributes$disabled = $elm$html$Html$Attributes$boolProperty('disabled');
var $author$project$NumberInput$get = function ($) {
return $.value;
};
@ -11955,7 +11949,7 @@ var $author$project$Entry$view = function (_v0) {
_List_Nil,
_List_fromArray(
[
$elm$html$Html$text('Vorlage für neuen Inventareintrag')
$elm$html$Html$text('Vorlage für Auftrag wählen')
])),
A2(
$elm$html$Html$form,
@ -12009,8 +12003,7 @@ var $author$project$Entry$view = function (_v0) {
$elm$html$Html$form,
_List_fromArray(
[
$elm$html$Html$Attributes$method('POST'),
$elm$html$Html$Attributes$action('/entry/add-to-cart')
$elm$html$Html$Attributes$method('POST')
]),
_List_fromArray(
[
@ -12050,7 +12043,6 @@ var $author$project$Entry$view = function (_v0) {
[
$elm$html$Html$Events$onInput($author$project$Entry$SetBarcode),
$elm$html$Html$Attributes$value(model.barcode),
$elm$html$Html$Attributes$disabled(true),
$elm$html$Html$Attributes$name('barcode'),
$elm$html$Html$Attributes$id('barcode')
]),
@ -12101,7 +12093,7 @@ var $author$project$Entry$view = function (_v0) {
]),
_List_fromArray(
[
$elm$html$Html$text('Stückzahl')
$elm$html$Html$text('Eingekauft')
])),
A2(
$elm$html$Html$input,
@ -12278,7 +12270,7 @@ var $author$project$Entry$view = function (_v0) {
_List_Nil,
_List_fromArray(
[
$elm$html$Html$text('In den Warenkorb')
$elm$html$Html$text('Auftrag anlegen')
]))
]))
]));

View File

@ -1,16 +1,37 @@
{% extends "base.html" %}
{% block content %}
<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>
<a href="/entry/new-order">Neuer Auftrag</a>
<h2>Aufträge</h2>
<table>
<tr>
<th>Barcode</th>
<th>Name</th>
<th>Eingekauft</th>
<th>Gruppen-ID</th>
<th>Raum-ID</th>
<th>Steuergruppen-ID</th>
<th>EK-Preis (Netto)</th>
<th>VK-Preis (Brutto)</th>
<th>Aktionen</th>
</tr>
{% for cart_item in cart %}
<tr>
<td><code>{{ cart_item.barcode }}</code></td>
<td>{{ cart_item.name }}</td>
<td class="--align-right">{{ cart_item.sales_units }}</td>
<td class="--align-right">{{ cart_item.group_id }}</td>
<td class="--align-right">{{ cart_item.location_id }}</td>
<td class="--align-right">{{ cart_item.tax_group_id }}</td>
<td class="--align-right">{{ format_currency(cart_item.net_unit_price) }}</td>
<td class="--align-right">{{ format_currency(cart_item.gross_unit_price) }}</td>
<td>
<form method="POST" action="/entry/delete-order">
<input type="hidden" name="order-index" value="{{ loop.index0 }}">
<button>Löschen</button>
</form>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block content %}
<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 %}