Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c7bb1042c | ||
|
|
c30ae58829 | ||
|
|
b30ee53e9d | ||
|
|
2d1c086e12 |
@@ -5,4 +5,3 @@ jon/config.json
|
|||||||
elm-stuff/
|
elm-stuff/
|
||||||
venv/
|
venv/
|
||||||
.venv/
|
.venv/
|
||||||
jon/static/*.js
|
|
||||||
|
|||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
FROM debian:latest as builder
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get upgrade -y
|
|
||||||
RUN apt-get install -y elm-compiler make ca-certificates
|
|
||||||
|
|
||||||
COPY . /app
|
|
||||||
WORKDIR /app
|
|
||||||
RUN rm -rf .venv venv
|
|
||||||
|
|
||||||
RUN make frontend
|
|
||||||
|
|
||||||
|
|
||||||
FROM python:3.11-alpine as runner
|
|
||||||
COPY --from=builder /app /app
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
RUN pip install -r requirements.txt
|
|
||||||
RUN pip install gunicorn
|
|
||||||
|
|
||||||
EXPOSE 5000
|
|
||||||
ENV JON_DB_CONNECTION_STRING="host=fsmi-db.fsmi.org dbname=garfield"
|
|
||||||
ENV JON_SECRET_KEY="changeme"
|
|
||||||
|
|
||||||
CMD ["sh", "-c", "gunicorn -b '0.0.0.0:5000' --chdir /app 'jon:create_app()'"]
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
.PHONY: frontend
|
|
||||||
|
|
||||||
frontend: jon/static/entry.js
|
|
||||||
|
|
||||||
jon/static/entry.js: $(shell find frontend -name '*.elm')
|
|
||||||
elm make --optimize frontend/Entry.elm --output $@
|
|
||||||
@@ -4,11 +4,6 @@
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
`jon` is a Python WSGI application written using Flask.
|
|
||||||
This means you'll have to install a bunch of Python packages to get up and running.
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
```
|
```
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
@@ -16,27 +11,6 @@ pip install -r requirements.txt
|
|||||||
You should probably use a virtualenv for that.
|
You should probably use a virtualenv for that.
|
||||||
I develop `jon` using Python 3.10 but it should work with older versions as well.
|
I develop `jon` using Python 3.10 but it should work with older versions as well.
|
||||||
|
|
||||||
#### Arch Linux
|
|
||||||
|
|
||||||
If you're on Arch, these packages are required for running the server:
|
|
||||||
|
|
||||||
```
|
|
||||||
python python-flask python-flask-login python-psycopg2
|
|
||||||
```
|
|
||||||
|
|
||||||
### Building Frontend JS
|
|
||||||
|
|
||||||
Most of jon works without JS but there are some features that require it.
|
|
||||||
The frontend code lives in `./frontend` and is written using Elm, a functional language that compiles to JS.
|
|
||||||
To compile the Elm code to `.js` files, first make sure that the Elm compiler is installed:
|
|
||||||
|
|
||||||
```
|
|
||||||
elm --version
|
|
||||||
# 0.19.1
|
|
||||||
```
|
|
||||||
|
|
||||||
Then run `make frontend`.
|
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -45,20 +19,6 @@ flask --app jon run --debug
|
|||||||
|
|
||||||
`--debug` restarts the server when a source file changes.
|
`--debug` restarts the server when a source file changes.
|
||||||
|
|
||||||
## Running with docker
|
|
||||||
When you prefer running the application using docker you can just use
|
|
||||||
```
|
|
||||||
docker compose up
|
|
||||||
```
|
|
||||||
|
|
||||||
In case your local username does not line up with your FSMI-username, you need to specify your FSMI-username
|
|
||||||
using `USER=<username>`, e.g.:
|
|
||||||
```
|
|
||||||
USER=shirkanesi docker compose up
|
|
||||||
```
|
|
||||||
|
|
||||||
This can also be persisted by following the instructions in the docker-compose.yml
|
|
||||||
|
|
||||||
## fsmi-db forward
|
## fsmi-db forward
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -67,19 +27,12 @@ ssh -nNTvL 5432:fsmi-db.fsmi.org:5432 fsmi-login.fsmi.uni-karlsruhe.de
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
|
- [ ] Implement item and snack entry as Elm application
|
||||||
|
- [ ] Needs good documentation for maintainability
|
||||||
- [ ] Implement and document report generation
|
- [ ] Implement and document report generation
|
||||||
- [ ] How many days will the item last?
|
- [ ] How many days will the item last?
|
||||||
- [ ] How many do we need to last X months?
|
- [ ] How many do we need to last X months?
|
||||||
- [ ] etc.
|
- [ ] etc.
|
||||||
- [ ] Make it print nicely
|
- [ ] Make it print nicely
|
||||||
- [ ] Make it possible to edit entries
|
- [ ] Make it possible to edit entries
|
||||||
- [ ] Fix unsafe client-side sessions, either:
|
|
||||||
- [ ] Use `flask-session` for file-backed sessions
|
|
||||||
- [ ] Use `flask-login` with a single user stored in memory
|
|
||||||
- [ ] Improve project structure
|
- [ ] Improve project structure
|
||||||
- [ ] Use `flask.flash` for error messages
|
|
||||||
- [x] Implement item and snack entry as Elm application
|
|
||||||
- [x] Figure out/Add documentation about building `entry.js`
|
|
||||||
- [ ] Clean up the code a little and add some comments
|
|
||||||
- [ ] Needs good documentation for maintainability
|
|
||||||
- [ ] Use cool new function for deactivating items
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
version: '3.7'
|
|
||||||
|
|
||||||
services:
|
|
||||||
jon:
|
|
||||||
container_name: jon
|
|
||||||
build: .
|
|
||||||
ports:
|
|
||||||
- "5000:5000"
|
|
||||||
volumes:
|
|
||||||
- ~/.pgpass:/root/.pgpass:ro
|
|
||||||
dns:
|
|
||||||
- 1.1.1.1
|
|
||||||
- 8.8.8.8
|
|
||||||
network_mode: bridge
|
|
||||||
environment:
|
|
||||||
# If your local user is different from your fsmi user, change $USER here!
|
|
||||||
- JON_DB_CONNECTION_STRING="host=fsmi-db.fsmi.org dbname=garfield user=$USER"
|
|
||||||
- JON_SECRET_KEY="changemetosomethingsuperrandomandsecure"
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
module Calculator exposing (..)
|
|
||||||
|
|
||||||
import Html exposing (..)
|
|
||||||
import Html.Attributes exposing (..)
|
|
||||||
import Html.Events exposing (..)
|
|
||||||
|
|
||||||
import NumberInput
|
|
||||||
import Select
|
|
||||||
|
|
||||||
type Tax = Net | Gross
|
|
||||||
|
|
||||||
-- Duplicated from Entry.elm but too lazy to sandwich this out
|
|
||||||
type alias TaxGroup =
|
|
||||||
{ id : Int
|
|
||||||
, description : String
|
|
||||||
, percentage : Float
|
|
||||||
}
|
|
||||||
|
|
||||||
showTax : Tax -> String
|
|
||||||
showTax tax = case tax of
|
|
||||||
Gross -> "Brutto"
|
|
||||||
Net -> "Netto"
|
|
||||||
|
|
||||||
type alias Model =
|
|
||||||
{ tax : Select.Model Tax
|
|
||||||
, bundlePrice : NumberInput.Model Float
|
|
||||||
, bundleSize : NumberInput.Model Int
|
|
||||||
}
|
|
||||||
|
|
||||||
init : Float -> Model
|
|
||||||
init bundlePrice = Model
|
|
||||||
(Select.init showTax showTax Net [Net, Gross])
|
|
||||||
(NumberInput.fromFloat bundlePrice)
|
|
||||||
(NumberInput.fromInt 1)
|
|
||||||
|
|
||||||
getResult : Model -> TaxGroup -> Maybe Float
|
|
||||||
getResult model taxGroup =
|
|
||||||
case (NumberInput.get model.bundlePrice, NumberInput.get model.bundleSize) of
|
|
||||||
(Just bundlePrice, Just bundleSize) ->
|
|
||||||
Just <| roundTo 2 <|
|
|
||||||
if Select.get model.tax == Gross then
|
|
||||||
(bundlePrice / toFloat bundleSize) / (1 + taxGroup.percentage)
|
|
||||||
else
|
|
||||||
bundlePrice / toFloat bundleSize
|
|
||||||
_ ->
|
|
||||||
Nothing
|
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
|
||||||
= SetTax String
|
|
||||||
| SetBundlePrice String
|
|
||||||
| SetBundleSize String
|
|
||||||
|
|
||||||
update : Msg -> Model -> Model
|
|
||||||
update msg model = case msg of
|
|
||||||
SetTax key ->
|
|
||||||
{ model | tax = Select.update key model.tax }
|
|
||||||
SetBundlePrice str ->
|
|
||||||
{ model | bundlePrice = NumberInput.update str model.bundlePrice }
|
|
||||||
SetBundleSize str ->
|
|
||||||
{ model | bundleSize = NumberInput.update str model.bundleSize }
|
|
||||||
|
|
||||||
view : Model -> TaxGroup -> Html Msg
|
|
||||||
view model taxGroup =
|
|
||||||
let
|
|
||||||
mainPart =
|
|
||||||
[ text "("
|
|
||||||
, div [ class "form-input --inline" ]
|
|
||||||
[ label [ for "bundle-price" ] [ text "Gebindepreis" ]
|
|
||||||
, input
|
|
||||||
[ placeholder "Gebindepreis"
|
|
||||||
, value <| NumberInput.show model.bundlePrice
|
|
||||||
, onInput SetBundlePrice
|
|
||||||
, id "bundle-price"
|
|
||||||
, type_ "number"
|
|
||||||
, step "0.01"
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
]
|
|
||||||
, text " ÷ "
|
|
||||||
, div [ class "form-input --inline" ]
|
|
||||||
[ label [ for "bundle-size" ] [ text "Gebindegröße" ]
|
|
||||||
, input
|
|
||||||
[ placeholder "Gebindegröße"
|
|
||||||
, value <| NumberInput.show model.bundleSize
|
|
||||||
, onInput SetBundleSize
|
|
||||||
, id "bundle-size"
|
|
||||||
, type_ "number"
|
|
||||||
, step "1"
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
]
|
|
||||||
, text ") "
|
|
||||||
]
|
|
||||||
taxPart =
|
|
||||||
[ text " ÷ "
|
|
||||||
, div [ class "form-input --inline" ]
|
|
||||||
[ label [ for "tax" ] [ text "Steuer" ]
|
|
||||||
, input
|
|
||||||
[ value <| String.fromFloat <| 1 + taxGroup.percentage
|
|
||||||
, id "tax"
|
|
||||||
, type_ "number"
|
|
||||||
, step "0.01"
|
|
||||||
, disabled True
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
resultPart =
|
|
||||||
[ text " = "
|
|
||||||
, text <| Maybe.withDefault "?" <| Maybe.map String.fromFloat <| getResult model taxGroup
|
|
||||||
]
|
|
||||||
in
|
|
||||||
fieldset []
|
|
||||||
[ legend [] [ text "Preisrechner" ]
|
|
||||||
, div [] <| List.concat <| List.filterMap identity
|
|
||||||
[ Just mainPart
|
|
||||||
, if Select.get model.tax == Gross then Just taxPart else Nothing
|
|
||||||
, Just resultPart
|
|
||||||
]
|
|
||||||
, div [ class "form-input" ]
|
|
||||||
[ label [ for "calculator-tax" ] [ text "Gebindepreis ist" ]
|
|
||||||
, Select.view [] SetTax model.tax
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
roundTo : Int -> Float -> Float
|
|
||||||
roundTo places x = toFloat (round <| x * 10 ^ toFloat places) / 10 ^ toFloat places
|
|
||||||
+52
-188
@@ -10,54 +10,9 @@ import Html exposing (..)
|
|||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
|
|
||||||
import Calculator
|
|
||||||
import NumberInput
|
import NumberInput
|
||||||
import Select
|
import Select
|
||||||
|
|
||||||
{-
|
|
||||||
Elm forces us to use the Elm architecture:
|
|
||||||
|
|
||||||
┌──────┐
|
|
||||||
┌─────Model──► view ├──Html───────┐
|
|
||||||
│ └──────┘ │
|
|
||||||
│ │
|
|
||||||
┌┴─────────────────────────────────▼┐
|
|
||||||
│ Elm runtime │
|
|
||||||
└▲─────────────────────────────────┬┘
|
|
||||||
│ │
|
|
||||||
│ ┌──────┐ │
|
|
||||||
└─Model+Cmd──┤update◄──Msg+Model──┘
|
|
||||||
└──────┘
|
|
||||||
|
|
||||||
This architecture is similar to what React does but its implementation
|
|
||||||
in Elm is a bit special since it's purely functional and side effects
|
|
||||||
are isolated into the runtime system.
|
|
||||||
|
|
||||||
An Elm component is usually centered around two types, Model and Msg.
|
|
||||||
Model contains all data the application is concerned with, including the state
|
|
||||||
of UI elements. Msg encodes all updates to Model that the application supports.
|
|
||||||
|
|
||||||
In addition to Msg and Model, we have to provide two functions, view and update.
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
|
||||||
update : Msg -> Model -> (Model, Cmd Msg)
|
|
||||||
|
|
||||||
view maps a Model to a DOM tree. Events in this DOM tree create Msg values.
|
|
||||||
update maps a Msg and a Model to a new Model. In addition, update can create
|
|
||||||
a command. Commands are used to make the runtime do side effects, which in
|
|
||||||
turn create new Msg values.
|
|
||||||
|
|
||||||
For example, we have a SetSearchTerm message which simply updates the searchTerm
|
|
||||||
property in the model. This message is triggered every time the search box input
|
|
||||||
is changed. Submitting the search box form triggers a SubmitSearch event.
|
|
||||||
This event leaves the model unchanged but issues a command that sends the search
|
|
||||||
term to a JSON endpoint. When the request successfully resolves, the runtime
|
|
||||||
triggers a ReceiveSearchResults messages which updates the list of search results
|
|
||||||
in the model.
|
|
||||||
|
|
||||||
See Calculator.elm for a simpler example of this architecture.
|
|
||||||
-}
|
|
||||||
|
|
||||||
main = Browser.element
|
main = Browser.element
|
||||||
{ init = \globals ->
|
{ init = \globals ->
|
||||||
( Context globals <| ItemSearch { searchTerm = "", searchResults = [] }
|
( Context globals <| ItemSearch { searchTerm = "", searchResults = [] }
|
||||||
@@ -82,7 +37,6 @@ type alias SearchResult =
|
|||||||
, groupName : String
|
, groupName : String
|
||||||
, groupId : Int
|
, groupId : Int
|
||||||
, taxGroupId : Int
|
, taxGroupId : Int
|
||||||
, unitsLeft : Int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
searchResultDecoder =
|
searchResultDecoder =
|
||||||
@@ -98,7 +52,6 @@ searchResultDecoder =
|
|||||||
|> P.required "group_name" D.string
|
|> P.required "group_name" D.string
|
||||||
|> P.required "group_id" D.int
|
|> P.required "group_id" D.int
|
||||||
|> P.required "tax_group_id" D.int
|
|> P.required "tax_group_id" D.int
|
||||||
|> P.required "units_left" D.int
|
|
||||||
|
|
||||||
type alias Location =
|
type alias Location =
|
||||||
{ id : Int
|
{ id : Int
|
||||||
@@ -116,16 +69,6 @@ type alias TaxGroup =
|
|||||||
, percentage : Float
|
, percentage : Float
|
||||||
}
|
}
|
||||||
|
|
||||||
type alias NewItem =
|
|
||||||
{ barcode : String
|
|
||||||
, name : String
|
|
||||||
, salesUnits : Int
|
|
||||||
, group : Group
|
|
||||||
, location : Location
|
|
||||||
, netUnitPrice : Float
|
|
||||||
, taxGroup : TaxGroup
|
|
||||||
}
|
|
||||||
|
|
||||||
type alias Context =
|
type alias Context =
|
||||||
{ globals : Globals
|
{ globals : Globals
|
||||||
, state : State
|
, state : State
|
||||||
@@ -133,11 +76,8 @@ type alias Context =
|
|||||||
|
|
||||||
type alias Globals =
|
type alias Globals =
|
||||||
{ locations : List Location
|
{ locations : List Location
|
||||||
, defaultLocation : Location
|
|
||||||
, groups : List Group
|
, groups : List Group
|
||||||
, defaultGroup : Group
|
|
||||||
, taxGroups : List TaxGroup
|
, taxGroups : List TaxGroup
|
||||||
, defaultTaxGroup : TaxGroup
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type State
|
type State
|
||||||
@@ -149,7 +89,6 @@ type State
|
|||||||
{ barcode : String
|
{ barcode : String
|
||||||
, name : String
|
, name : String
|
||||||
, salesUnits : NumberInput.Model Int
|
, salesUnits : NumberInput.Model Int
|
||||||
, calculator : Calculator.Model
|
|
||||||
, netUnitPrice : NumberInput.Model Float
|
, netUnitPrice : NumberInput.Model Float
|
||||||
, grossUnitPrice : NumberInput.Model Float
|
, grossUnitPrice : NumberInput.Model Float
|
||||||
, group : Select.Model Group
|
, group : Select.Model Group
|
||||||
@@ -161,21 +100,16 @@ type Msg
|
|||||||
= SetSearchTerm String
|
= SetSearchTerm String
|
||||||
| SubmitSearch
|
| SubmitSearch
|
||||||
| ReceiveSearchResults (Result Http.Error (List SearchResult))
|
| ReceiveSearchResults (Result Http.Error (List SearchResult))
|
||||||
| GotoItemEditor IEInit
|
| GotoItemEditor SearchResult
|
||||||
| SetBarcode String
|
| SetBarcode String
|
||||||
| SetName String
|
| SetName String
|
||||||
| SetSalesUnits String
|
| SetSalesUnits String
|
||||||
| CalculatorMsg Calculator.Msg
|
|
||||||
| SetNetUnitPrice String
|
| SetNetUnitPrice String
|
||||||
| SetGrossUnitPrice String
|
| SetGrossUnitPrice String
|
||||||
| SetGroup String
|
| SetGroup String
|
||||||
| SetLocation String
|
| SetLocation String
|
||||||
| SetTaxGroup String
|
| SetTaxGroup String
|
||||||
|
|
||||||
type IEInit
|
|
||||||
= IEInitBarcode String
|
|
||||||
| IEInitSearchResult SearchResult
|
|
||||||
|
|
||||||
-- Update logic: State machine etc.
|
-- Update logic: State machine etc.
|
||||||
|
|
||||||
update msg { globals, state } =
|
update msg { globals, state } =
|
||||||
@@ -197,31 +131,15 @@ updateState msg globals state = case state of
|
|||||||
)
|
)
|
||||||
ReceiveSearchResults (Ok searchResults) ->
|
ReceiveSearchResults (Ok searchResults) ->
|
||||||
(ItemSearch { model | searchResults = searchResults }, Cmd.none)
|
(ItemSearch { model | searchResults = searchResults }, Cmd.none)
|
||||||
GotoItemEditor (IEInitBarcode barcode) ->
|
GotoItemEditor searchResult ->
|
||||||
( ItemEditor
|
|
||||||
{ barcode = barcode
|
|
||||||
, name = ""
|
|
||||||
, calculator = Calculator.init 0
|
|
||||||
, netUnitPrice = NumberInput.fromFloat 0
|
|
||||||
, grossUnitPrice = NumberInput.fromFloat 0
|
|
||||||
, salesUnits = NumberInput.fromInt 0
|
|
||||||
, group = Select.init (.id >> String.fromInt) (.name) globals.defaultGroup globals.groups
|
|
||||||
, location = Select.init (.id >> String.fromInt) (.name) globals.defaultLocation globals.locations
|
|
||||||
, taxGroup = Select.init (.id >> String.fromInt) (.description) globals.defaultTaxGroup globals.taxGroups
|
|
||||||
}
|
|
||||||
, Cmd.none
|
|
||||||
)
|
|
||||||
GotoItemEditor (IEInitSearchResult searchResult) ->
|
|
||||||
case find (\tg -> tg.id == searchResult.taxGroupId) globals.taxGroups of
|
case find (\tg -> tg.id == searchResult.taxGroupId) globals.taxGroups of
|
||||||
Nothing -> (state, Cmd.none)
|
Nothing -> (state, Cmd.none)
|
||||||
Just taxGroup ->
|
Just taxGroup ->
|
||||||
( ItemEditor
|
( ItemEditor <| updateGrossUnitPrice
|
||||||
{ barcode = searchResult.barcode
|
{ barcode = searchResult.barcode
|
||||||
, name = searchResult.name
|
, name = searchResult.name
|
||||||
, calculator = Calculator.init searchResult.netUnitPrice
|
|
||||||
, netUnitPrice = NumberInput.fromFloat searchResult.netUnitPrice
|
, netUnitPrice = NumberInput.fromFloat searchResult.netUnitPrice
|
||||||
, grossUnitPrice = NumberInput.fromFloat
|
, grossUnitPrice = NumberInput.fromFloat 0
|
||||||
(suggestedGrossPrice searchResult.netUnitPrice taxGroup.percentage)
|
|
||||||
, salesUnits = NumberInput.fromInt searchResult.salesUnits
|
, salesUnits = NumberInput.fromInt searchResult.salesUnits
|
||||||
, group = Select.init (.id >> String.fromInt) (.name) { id = searchResult.groupId, name = searchResult.groupName } globals.groups
|
, group = Select.init (.id >> String.fromInt) (.name) { id = searchResult.groupId, name = searchResult.groupName } globals.groups
|
||||||
, location = Select.init (.id >> String.fromInt) (.name) { id = searchResult.locationId, name = searchResult.locationName } globals.locations
|
, location = Select.init (.id >> String.fromInt) (.name) { id = searchResult.locationId, name = searchResult.locationName } globals.locations
|
||||||
@@ -238,156 +156,104 @@ updateState msg globals state = case state of
|
|||||||
(ItemEditor { model | name = name }, Cmd.none)
|
(ItemEditor { model | name = name }, Cmd.none)
|
||||||
SetSalesUnits str ->
|
SetSalesUnits str ->
|
||||||
(ItemEditor { model | salesUnits = NumberInput.update str model.salesUnits }, Cmd.none)
|
(ItemEditor { model | salesUnits = NumberInput.update str model.salesUnits }, Cmd.none)
|
||||||
CalculatorMsg msg_ ->
|
|
||||||
(ItemEditor { model | calculator = Calculator.update msg_ model.calculator }, Cmd.none)
|
|
||||||
SetNetUnitPrice str ->
|
SetNetUnitPrice str ->
|
||||||
( ItemEditor { model | netUnitPrice = NumberInput.update str model.netUnitPrice }
|
( ItemEditor <| updateGrossUnitPrice { model | netUnitPrice = NumberInput.update str model.netUnitPrice }
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
SetGrossUnitPrice str ->
|
SetGrossUnitPrice str ->
|
||||||
( ItemEditor { model | grossUnitPrice = NumberInput.update str model.grossUnitPrice }
|
(ItemEditor { model | grossUnitPrice = NumberInput.update str model.grossUnitPrice }, Cmd.none)
|
||||||
, Cmd.none
|
|
||||||
)
|
|
||||||
SetGroup key ->
|
SetGroup key ->
|
||||||
(ItemEditor { model | group = Select.update key model.group }, Cmd.none)
|
(ItemEditor { model | group = Select.update key model.group }, Cmd.none)
|
||||||
SetLocation key ->
|
SetLocation key ->
|
||||||
(ItemEditor { model | location = Select.update key model.location }, Cmd.none)
|
(ItemEditor { model | location = Select.update key model.location }, Cmd.none)
|
||||||
SetTaxGroup key ->
|
SetTaxGroup key ->
|
||||||
( ItemEditor { model | taxGroup = Select.update key model.taxGroup }
|
( ItemEditor <| updateGrossUnitPrice { model | taxGroup = Select.update key model.taxGroup }
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
_ ->
|
_ ->
|
||||||
(state, Cmd.none)
|
(state, Cmd.none)
|
||||||
|
|
||||||
suggestedGrossPrice netPrice percentage =
|
updateGrossUnitPrice model =
|
||||||
roundTo 2 <| netPrice * (1 + percentage) + 0.01
|
{ model
|
||||||
|
| grossUnitPrice = Maybe.withDefault model.grossUnitPrice <| Maybe.map NumberInput.fromFloat <| calculateGarfieldPrice model
|
||||||
|
}
|
||||||
|
|
||||||
-- View stuff
|
-- View stuff
|
||||||
|
|
||||||
view { globals, state } = case state of
|
view { globals, state } = case state of
|
||||||
ItemSearch model ->
|
ItemSearch model ->
|
||||||
div []
|
fieldset []
|
||||||
[ div []
|
[ legend [] [ text "Vorlage für neuen Inventareintrag" ]
|
||||||
[ if model.searchTerm == ""
|
, Html.form [ onSubmit SubmitSearch ]
|
||||||
then button [ disabled True ] [ text "Neuer Artikel" ]
|
[ div [ class "form-input" ]
|
||||||
else button [ onClick <| GotoItemEditor <| IEInitBarcode model.searchTerm ] [ text <| "Neuer Artikel mit Barcode " ++ model.searchTerm ]
|
[ label [ for "search-term", title "Barcode oder Name" ] [ text "Suchbegriff" ]
|
||||||
]
|
, input [ onInput SetSearchTerm, value model.searchTerm, id "search-term" ] []
|
||||||
, fieldset []
|
|
||||||
[ 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" ]
|
|
||||||
, input [ onInput SetSearchTerm, value model.searchTerm, id "search-term" ] []
|
|
||||||
]
|
|
||||||
, table [] <| searchResultHeaders :: List.map viewSearchResult model.searchResults
|
|
||||||
]
|
]
|
||||||
|
, table [] <| searchResultHeaders :: List.map viewSearchResult model.searchResults
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
ItemEditor model ->
|
ItemEditor model ->
|
||||||
Html.form [ method "POST" ]
|
Html.form []
|
||||||
[ fieldset []
|
[ fieldset []
|
||||||
[ legend [] [ text "Neuer Inventareintrag" ]
|
[ legend [] [ text "Neuer Inventareintrag" ]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "barcode" ] [ text "Barcode" ]
|
[ label [ for "barcode" ] [ text "Barcode" ]
|
||||||
, input [ onInput SetBarcode, value model.barcode, name "barcode", id "barcode" ] []
|
, input [ onInput SetBarcode, value model.barcode, disabled True, id "barcode" ] []
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "name" ] [ text "Name" ]
|
[ label [ for "name" ] [ text "Name" ]
|
||||||
, input [ onInput SetName, value model.name, name "name", id "name" ] []
|
, input [ onInput SetName, value model.name, id "name" ] []
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "sales-units" ] [ text "Eingekauft" ]
|
[ label [ for "sales-units" ] [ text "Stückzahl" ]
|
||||||
, input [ onInput SetSalesUnits, value <| NumberInput.show model.salesUnits, name "sales-units", id "sales-units", type_ "number" ] []
|
, input [ onInput SetSalesUnits, value <| NumberInput.show model.salesUnits, id "sales-units", type_ "number" ] []
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "group" ] [ text "Gruppe" ]
|
[ label [ for "group" ] [ text "Gruppe" ]
|
||||||
, Select.view [ name "group-id", id "group" ] SetGroup model.group
|
, Select.view SetGroup model.group
|
||||||
, input
|
|
||||||
[ type_ "hidden"
|
|
||||||
, name "group-name"
|
|
||||||
, value <| (Select.get model.group).name
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "location" ] [ text "Raum" ]
|
[ label [ for "location" ] [ text "Raum" ]
|
||||||
, Select.view [ name "location-id", id "location" ] SetLocation model.location
|
, Select.view SetLocation model.location
|
||||||
|
]
|
||||||
|
, div [ class "form-input" ]
|
||||||
|
[ label [ for "net-unit-price" ] [ text "Stückpreis (Netto)" ]
|
||||||
, input
|
, input
|
||||||
[ type_ "hidden"
|
[ value <| NumberInput.show model.netUnitPrice
|
||||||
, name "location-name"
|
, onInput SetNetUnitPrice
|
||||||
, value <| (Select.get model.location).name
|
, type_ "number"
|
||||||
|
, id "net-unit-price"
|
||||||
|
, step "0.01"
|
||||||
]
|
]
|
||||||
[]
|
[]
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "tax-group" ] [ text "Steuergruppe" ]
|
[ label [ for "tax-group" ] [ text "Steuergruppe" ]
|
||||||
, Select.view [ name "tax-group-id", id "tax-group" ] SetTaxGroup model.taxGroup
|
, Select.view SetTaxGroup model.taxGroup
|
||||||
, input
|
|
||||||
[ type_ "hidden"
|
|
||||||
, name "tax-group-description"
|
|
||||||
, value <| (Select.get model.taxGroup).description
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
]
|
]
|
||||||
, Html.map CalculatorMsg <| Calculator.view model.calculator (Select.get model.taxGroup)
|
]
|
||||||
|
, fieldset []
|
||||||
|
[ legend [] [ text "Neuer Snackeintrag" ]
|
||||||
, div [ class "form-input" ]
|
, div [ class "form-input" ]
|
||||||
[ label [ for "net-unit-price" ] [ text "Einkaufspreis (Netto)" ]
|
[ label [ for "snack-name" ] [ text "Name" ]
|
||||||
, input
|
, input [ value model.name, disabled True, id "snack-name" ] []
|
||||||
[ value <| NumberInput.show model.netUnitPrice
|
|
||||||
, onInput SetNetUnitPrice
|
|
||||||
, type_ "number"
|
|
||||||
, name "net-unit-price"
|
|
||||||
, id "net-unit-price"
|
|
||||||
, step "0.01"
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
, viewSetCalculatedPriceButton model
|
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, viewGrossUnitPriceInput model
|
||||||
[ label [ for "gross-unit-price" ] [ text "Verkaufspreis (Brutto)" ]
|
|
||||||
, input
|
|
||||||
[ value <| NumberInput.show model.grossUnitPrice
|
|
||||||
, onInput SetGrossUnitPrice
|
|
||||||
, type_ "number"
|
|
||||||
, name "gross-unit-price"
|
|
||||||
, id "gross-unit-price"
|
|
||||||
, step "0.01"
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
, viewSetSuggestedPriceButton model
|
|
||||||
]
|
|
||||||
, button [] [ text "Auftrag anlegen" ]
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
viewSetCalculatedPriceButton model =
|
viewGrossUnitPriceInput model =
|
||||||
case Calculator.getResult model.calculator (Select.get model.taxGroup) of
|
let
|
||||||
Nothing ->
|
suggestedPriceStr = case calculateGarfieldPrice model of
|
||||||
button [ disabled True ] [ text "Auf ? setzen" ]
|
Nothing -> "?"
|
||||||
Just calculatedPrice ->
|
Just suggestedPrice -> String.fromFloat suggestedPrice
|
||||||
button
|
in
|
||||||
[ onClick <| SetNetUnitPrice <| String.fromFloat calculatedPrice
|
div [ class "form-input" ]
|
||||||
-- Prevent submitting the form
|
[ label [ for "gross-unit-price" ]
|
||||||
, type_ "button"
|
[ text <| "Stückpreis (Brutto), Vorschlag: " ++ suggestedPriceStr
|
||||||
]
|
]
|
||||||
[ text <| "Auf " ++ String.fromFloat calculatedPrice ++ " setzen"
|
, input [ onInput SetGrossUnitPrice, value <| NumberInput.show model.grossUnitPrice, id "gross-unit-price", type_ "number", step "0.01" ] []
|
||||||
]
|
]
|
||||||
|
|
||||||
viewSetSuggestedPriceButton model =
|
|
||||||
case NumberInput.get model.netUnitPrice of
|
|
||||||
Nothing ->
|
|
||||||
button [ disabled True ] [ text "Auf ? setzen" ]
|
|
||||||
Just netUnitPrice ->
|
|
||||||
let
|
|
||||||
grossUnitPrice = suggestedGrossPrice netUnitPrice (Select.get model.taxGroup).percentage
|
|
||||||
in
|
|
||||||
button
|
|
||||||
[ onClick <| SetGrossUnitPrice <| String.fromFloat grossUnitPrice
|
|
||||||
-- Prevent submitting the form
|
|
||||||
, type_ "button"
|
|
||||||
]
|
|
||||||
[ text <| "Auf " ++ String.fromFloat grossUnitPrice ++ " setzen"
|
|
||||||
]
|
|
||||||
|
|
||||||
searchResultHeaders =
|
searchResultHeaders =
|
||||||
tr []
|
tr []
|
||||||
@@ -413,9 +279,7 @@ viewSearchResult model =
|
|||||||
, td [] [ text model.locationName ]
|
, td [] [ text model.locationName ]
|
||||||
, td [] [ text <| showBool model.available ]
|
, td [] [ text <| showBool model.available ]
|
||||||
, td []
|
, td []
|
||||||
[ Html.form [ onSubmit <| GotoItemEditor <| IEInitSearchResult model ]
|
[ button [ onClick <| GotoItemEditor model ] [ text "Als Vorlage verwenden" ]
|
||||||
[ button [] [ text "Als Vorlage verwenden" ]
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
module Select exposing (..)
|
module Select exposing (..)
|
||||||
|
|
||||||
import Html exposing (Attribute, Html, option, select, text)
|
import Html exposing (Html, option, select, text)
|
||||||
import Html.Attributes exposing (selected, value)
|
import Html.Attributes exposing (selected, value)
|
||||||
import Html.Events exposing (onInput)
|
import Html.Events exposing (onInput)
|
||||||
|
|
||||||
@@ -20,15 +20,15 @@ update key model =
|
|||||||
Nothing -> model
|
Nothing -> model
|
||||||
Just x -> { model | selected = x }
|
Just x -> { model | selected = x }
|
||||||
|
|
||||||
view : List (Attribute m) -> (String -> m) -> Model a -> Html m
|
view : (String -> m) -> Model a -> Html m
|
||||||
view attributes msg model =
|
view msg model =
|
||||||
let
|
let
|
||||||
viewOption x =
|
viewOption x =
|
||||||
option
|
option
|
||||||
[ selected <| model.identify model.selected == model.identify x, value <| model.identify x ]
|
[ selected <| model.identify model.selected == model.identify x, value <| model.identify x ]
|
||||||
[ text <| model.show x ]
|
[ text <| model.show x ]
|
||||||
in
|
in
|
||||||
select ([ onInput msg ] ++ attributes) <| List.map viewOption model.options
|
select [ onInput msg ] <| List.map viewOption model.options
|
||||||
|
|
||||||
get : Model a -> a
|
get : Model a -> a
|
||||||
get = .selected
|
get = .selected
|
||||||
|
|||||||
+6
-4
@@ -20,10 +20,14 @@ def create_app():
|
|||||||
# You don't need a config.json. If you don't provide one, default-config.json
|
# You don't need a config.json. If you don't provide one, default-config.json
|
||||||
# is used.
|
# is used.
|
||||||
app.config.from_file("config.json", load=json.load, silent=True)
|
app.config.from_file("config.json", load=json.load, silent=True)
|
||||||
app.config.from_prefixed_env(prefix="JON")
|
|
||||||
|
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
auth.init_app(app)
|
|
||||||
|
# This function denies every request until `auth.ACCESS_TOKEN`
|
||||||
|
# is passed using `?token=` to authenticate the session.
|
||||||
|
@app.before_request
|
||||||
|
def before_req_fun():
|
||||||
|
return auth.before_request()
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def utility_processor():
|
def utility_processor():
|
||||||
@@ -39,7 +43,5 @@ def create_app():
|
|||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
print(f"Jon started. Token: {auth.ACCESS_TOKEN}", file=sys.stderr)
|
print(f"Jon started. Token: {auth.ACCESS_TOKEN}", file=sys.stderr)
|
||||||
# TODO: Get host and port from config
|
|
||||||
print(f"http://localhost:5000/?token={auth.ACCESS_TOKEN}", file=sys.stderr)
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|||||||
+20
-63
@@ -1,15 +1,12 @@
|
|||||||
import secrets
|
import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from flask import Blueprint, request, redirect, render_template
|
from flask import Blueprint, request, redirect, render_template, session
|
||||||
from flask_login import current_user, login_user, logout_user, LoginManager
|
|
||||||
from typing import Any, Dict, List, Optional
|
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint("auth", __name__, url_prefix="/auth")
|
bp = Blueprint("auth", __name__, url_prefix="/auth")
|
||||||
|
|
||||||
|
|
||||||
ACCESS_TOKEN = "".join(secrets.choice(string.ascii_lowercase) for i in range(64))
|
ACCESS_TOKEN = "".join(random.choice(string.ascii_lowercase) for i in range(64))
|
||||||
|
|
||||||
|
|
||||||
ALLOWED_PATHS = [
|
ALLOWED_PATHS = [
|
||||||
@@ -18,67 +15,27 @@ ALLOWED_PATHS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# A poor man's replacement for memory-backed session solution.
|
def before_request():
|
||||||
# We keep exactly one User (and the corresponding UserData) in
|
"""
|
||||||
# memory and use that to store session data.
|
If the correct token query parameter is passed along with any request,
|
||||||
class UserData:
|
we mark this session authenticated by setting `session["authenticated"]`.
|
||||||
location: Optional[Dict[str, Any]]
|
Unless the session is authenticated, all requests result in a 403 FORBIDDEN.
|
||||||
orders: List[Dict[str, Any]]
|
"""
|
||||||
|
if "token" in request.args:
|
||||||
|
if request.args["token"] == ACCESS_TOKEN:
|
||||||
|
session["authenticated"] = ()
|
||||||
|
# Reload the page without query parameters
|
||||||
|
return redirect(request.path)
|
||||||
|
|
||||||
def __init__(self):
|
# Don't deny any paths in `ALLOWED_PATHS`
|
||||||
self.location = None
|
if request.path in ALLOWED_PATHS:
|
||||||
self.orders = []
|
return
|
||||||
|
|
||||||
|
if not "authenticated" in session:
|
||||||
class User:
|
return render_template("auth/denied.html"), 403
|
||||||
is_authenticated: bool
|
|
||||||
is_active: bool
|
|
||||||
is_anonymous: bool
|
|
||||||
|
|
||||||
data: UserData
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.is_authenticated = True
|
|
||||||
self.is_active = True
|
|
||||||
self.is_anonymous = False
|
|
||||||
|
|
||||||
self.data = UserData()
|
|
||||||
|
|
||||||
def get_id(self) -> str:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
def init_app(app):
|
|
||||||
login_manager = LoginManager(app)
|
|
||||||
the_one_and_only_user = User()
|
|
||||||
|
|
||||||
@login_manager.user_loader
|
|
||||||
def load_user(user_id: str) -> User:
|
|
||||||
assert user_id == ""
|
|
||||||
return the_one_and_only_user
|
|
||||||
|
|
||||||
# This function denies every request until `auth.ACCESS_TOKEN`
|
|
||||||
# is passed using `?token=` to authenticate the user.
|
|
||||||
# We use this instead of @login_required because otherwise we'd have
|
|
||||||
# to add that annotation to all routes.
|
|
||||||
# See also: https://flask-login.readthedocs.io/en/latest/#flask_login.login_required
|
|
||||||
@app.before_request
|
|
||||||
def before_request():
|
|
||||||
if "token" in request.args:
|
|
||||||
if request.args["token"] == ACCESS_TOKEN:
|
|
||||||
login_user(the_one_and_only_user)
|
|
||||||
# Reload the page without query parameters
|
|
||||||
return redirect(request.path)
|
|
||||||
|
|
||||||
# Never deny any paths in `ALLOWED_PATHS`
|
|
||||||
if request.path in ALLOWED_PATHS:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not current_user.is_authenticated:
|
|
||||||
return render_template("auth/denied.html"), 403
|
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/logout")
|
@bp.get("/logout")
|
||||||
def logout():
|
def logout():
|
||||||
logout_user()
|
session.pop("authenticated", None)
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ from psycopg2.extras import RealDictCursor
|
|||||||
|
|
||||||
def get_db():
|
def get_db():
|
||||||
if "db" not in g:
|
if "db" not in g:
|
||||||
|
# TODO: Make this configurable and use a default that works
|
||||||
|
# on the pool computers.
|
||||||
g.db = psycopg2.connect(current_app.config["DB_CONNECTION_STRING"])
|
g.db = psycopg2.connect(current_app.config["DB_CONNECTION_STRING"])
|
||||||
run_query_on(g.db, "add_views.sql", None)
|
run_query_on(g.db, "add_views.sql", None)
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ SELECT
|
|||||||
inventory_items.available,
|
inventory_items.available,
|
||||||
inventory_items.item_group,
|
inventory_items.item_group,
|
||||||
inventory_items.location,
|
inventory_items.location,
|
||||||
inventory_items.tax_group,
|
|
||||||
inventory_item_groups.group_name,
|
inventory_item_groups.group_name,
|
||||||
COALESCE(b.sales::numeric, 0::numeric) - COALESCE(cancel.count::numeric, 0::numeric) AS sales,
|
COALESCE(b.sales::numeric, 0::numeric) - COALESCE(cancel.count::numeric, 0::numeric) AS sales,
|
||||||
inventory_items.sales_units::numeric - COALESCE(b.sales, 0::bigint)::numeric + COALESCE(c.delta, 0::numeric) + COALESCE(cancel.count::numeric, 0::numeric) AS units_left,
|
inventory_items.sales_units::numeric - COALESCE(b.sales, 0::bigint)::numeric + COALESCE(c.delta, 0::numeric) + COALESCE(cancel.count::numeric, 0::numeric) AS units_left,
|
||||||
@@ -58,56 +57,3 @@ FROM garfield.inventory_items
|
|||||||
) m USING (item_id)
|
) m USING (item_id)
|
||||||
ORDER BY inventory_items.name;
|
ORDER BY inventory_items.name;
|
||||||
|
|
||||||
-- How many *other* active inventory lines exist with the same barcode in the same location that are newer?
|
|
||||||
CREATE TEMPORARY VIEW more_recent_inventory_lines_with_same_barcode AS
|
|
||||||
SELECT
|
|
||||||
a.item_id,
|
|
||||||
-- It's important not to count(*) here because item_id is NULL
|
|
||||||
-- when no other inventory lines exist.
|
|
||||||
count(b.item_id) AS other_lines_count
|
|
||||||
FROM garfield.inventory_items AS a
|
|
||||||
LEFT JOIN garfield.inventory_items AS b
|
|
||||||
ON a.item_barcode = b.item_barcode
|
|
||||||
AND a.item_id != b.item_id
|
|
||||||
AND a.location = b.location
|
|
||||||
AND b.available
|
|
||||||
AND b.bought > a.bought
|
|
||||||
GROUP BY a.item_id;
|
|
||||||
|
|
||||||
-- We need to create this table so that we can put an index on it
|
|
||||||
-- Otherwise the join in the consumption graph query becomes much slower
|
|
||||||
-- Perhaps it would be nicer to use a materialized view instead
|
|
||||||
DROP TABLE IF EXISTS last_n_days;
|
|
||||||
CREATE TEMPORARY TABLE last_n_days AS (
|
|
||||||
SELECT
|
|
||||||
generate_series(now() - interval '14 days', now(), interval '1 day')::date AS sale_date
|
|
||||||
);
|
|
||||||
CREATE UNIQUE INDEX last_n_days_sale_date ON last_n_days (sale_date);
|
|
||||||
|
|
||||||
-- Get an array of how often items were sold over the last 14 days
|
|
||||||
CREATE TEMPORARY VIEW inventory_last_n_days_sales AS
|
|
||||||
WITH
|
|
||||||
sales_by_date AS (
|
|
||||||
SELECT
|
|
||||||
inventory_line AS item_id,
|
|
||||||
date_trunc('day', snack_sales_log_timestamp AT TIME ZONE 'UTC+1') AS sale_date,
|
|
||||||
count(*)::int AS sales
|
|
||||||
FROM garfield.snack_sales_log
|
|
||||||
GROUP BY item_id, sale_date
|
|
||||||
),
|
|
||||||
beeg AS (
|
|
||||||
SELECT item_id, sale_date, count(snack_sales_log_timestamp)::int AS sales
|
|
||||||
FROM garfield.inventory_items
|
|
||||||
CROSS JOIN last_n_days
|
|
||||||
LEFT JOIN garfield.snack_sales_log
|
|
||||||
ON inventory_line = item_id
|
|
||||||
-- snack_sales_log has an index on snack_sales_log_timestamp to speed up this query
|
|
||||||
-- If that index doesn't exist the query takes much longer.
|
|
||||||
AND sale_date = date_trunc('day', snack_sales_log_timestamp AT TIME ZONE 'UTC+1')
|
|
||||||
WHERE available
|
|
||||||
GROUP BY item_id, sale_date
|
|
||||||
ORDER BY item_id, sale_date
|
|
||||||
)
|
|
||||||
SELECT item_id, array_agg(sales) AS last_n_days_sales
|
|
||||||
FROM beeg
|
|
||||||
GROUP BY item_id
|
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
DO $$
|
|
||||||
DECLARE new_item_id integer;
|
|
||||||
DECLARE new_snack_id integer;
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
-- Create a new inventory line
|
|
||||||
INSERT INTO garfield.inventory_items
|
|
||||||
(item_barcode, name, item_group, location, tax_group, sales_units, unit_price)
|
|
||||||
VALUES
|
|
||||||
(%(barcode)s, %(name)s, %(group_id)s, %(location_id)s, %(tax_group_id)s, %(sales_units)s, %(net_unit_price)s)
|
|
||||||
RETURNING item_id INTO new_item_id;
|
|
||||||
|
|
||||||
-- Delete (i.e. mark as inactive) any old snacks with the same barcode in the given location
|
|
||||||
PERFORM garfield.snack_delete(snack_id)
|
|
||||||
FROM garfield.snacks
|
|
||||||
WHERE snack_barcode = %(barcode)s
|
|
||||||
AND location_id = %(location_id)s;
|
|
||||||
|
|
||||||
-- Create a new snack entry...
|
|
||||||
SELECT garfield.snack_create(%(name)s, %(barcode)s, %(gross_unit_price)s, %(tax_group_id)s, %(location_id)s)
|
|
||||||
INTO new_snack_id;
|
|
||||||
|
|
||||||
-- ... and map it to the new inventory line
|
|
||||||
PERFORM garfield.inventory_map_snack(new_snack_id, new_item_id);
|
|
||||||
|
|
||||||
END$$
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
FROM all_inventory_item_overview
|
FROM all_inventory_item_overview
|
||||||
LEFT JOIN more_recent_inventory_lines_with_same_barcode USING (item_id)
|
|
||||||
LEFT JOIN inventory_last_n_days_sales USING (item_id)
|
|
||||||
WHERE (%(location_id)s IS NULL OR location = %(location_id)s)
|
WHERE (%(location_id)s IS NULL OR location = %(location_id)s)
|
||||||
AND available
|
AND available
|
||||||
ORDER BY
|
ORDER BY
|
||||||
|
|||||||
@@ -1,43 +1,49 @@
|
|||||||
-- parameters:
|
|
||||||
--
|
|
||||||
-- location_id: Location to generate the report for
|
|
||||||
|
|
||||||
WITH
|
WITH
|
||||||
sales_by_item_id AS (
|
most_recent_sales AS (
|
||||||
SELECT
|
SELECT DISTINCT ON (inventory_line)
|
||||||
inventory_line AS item_id,
|
inventory_line, snack_sales_log_id, snack_sales_log_timestamp AS most_recent_sale
|
||||||
max(snack_sales_log_timestamp) AS last_sold,
|
|
||||||
count(*)::int AS units_sold
|
|
||||||
FROM garfield.snack_sales_log
|
FROM garfield.snack_sales_log
|
||||||
WHERE type_id = 'SNACK_BUY'
|
ORDER BY inventory_line ASC, snack_sales_log_timestamp DESC
|
||||||
AND inventory_line IS NOT NULL
|
|
||||||
AND snack_sales_log_timestamp > NOW() - INTERVAL '120 days'
|
|
||||||
AND location_id = %(location_id)s
|
|
||||||
GROUP BY item_id
|
|
||||||
),
|
),
|
||||||
sales_by_barcode AS (
|
enhanced_overview1 AS (
|
||||||
SELECT
|
SELECT
|
||||||
item_barcode,
|
inventory_items.item_id,
|
||||||
max(name) AS name,
|
inventory_items.item_barcode,
|
||||||
sum(units_sold) AS units_sold,
|
inventory_items.name,
|
||||||
round(avg((units_sold / extract(epoch FROM (CASE WHEN available THEN now() ELSE last_sold END) - bought)) * 86400)::numeric, 2) AS sold_per_day
|
units_left,
|
||||||
FROM sales_by_item_id
|
inventory_items.sales_units,
|
||||||
|
correction_delta,
|
||||||
|
location_name,
|
||||||
|
location,
|
||||||
|
CASE
|
||||||
|
WHEN snack_sales_log_id IS NULL THEN 0
|
||||||
|
ELSE sales / (EXTRACT(EPOCH FROM (
|
||||||
|
CASE
|
||||||
|
WHEN units_left <= 0 THEN most_recent_sale
|
||||||
|
ELSE NOW()
|
||||||
|
END
|
||||||
|
)) - EXTRACT(EPOCH FROM bought)) * 24 * 3600
|
||||||
|
END AS per_day
|
||||||
|
FROM garfield.inventory_item_overview
|
||||||
LEFT JOIN garfield.inventory_items USING (item_id)
|
LEFT JOIN garfield.inventory_items USING (item_id)
|
||||||
GROUP BY item_barcode
|
LEFT JOIN most_recent_sales ON item_id = inventory_line
|
||||||
),
|
),
|
||||||
current_inventory AS (
|
enhanced_overview2 AS (
|
||||||
SELECT
|
SELECT
|
||||||
item_barcode,
|
*,
|
||||||
sum(units_left)::int AS units_left
|
CASE
|
||||||
FROM all_inventory_item_overview
|
WHEN per_day = 0 THEN NULL
|
||||||
WHERE available
|
ELSE GREATEST(0, units_left / per_day)
|
||||||
AND location = %(location_id)s
|
END AS days_left
|
||||||
GROUP BY item_barcode
|
FROM enhanced_overview1
|
||||||
)
|
)
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
sales_by_barcode.*,
|
*,
|
||||||
COALESCE(current_inventory.units_left, 0)::int AS units_left
|
CASE
|
||||||
FROM sales_by_barcode
|
WHEN days_left IS NULL THEN NULL
|
||||||
LEFT JOIN current_inventory USING (item_barcode)
|
ELSE GREATEST(0, (60 - days_left) * per_day)
|
||||||
ORDER BY units_sold DESC
|
END AS for_two_months
|
||||||
|
FROM enhanced_overview2
|
||||||
|
WHERE (%(location_id)s IS NULL OR location = %(location_id)s)
|
||||||
|
ORDER BY days_left ASC, per_day DESC
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ SELECT
|
|||||||
sales_units,
|
sales_units,
|
||||||
available,
|
available,
|
||||||
location_name,
|
location_name,
|
||||||
location as location_id,
|
location_id,
|
||||||
group_name,
|
group_name,
|
||||||
item_group AS group_id,
|
item_group AS group_id,
|
||||||
tax_group AS tax_group_id,
|
tax_group AS tax_group_id
|
||||||
units_left :: integer
|
FROM garfield.inventory_items
|
||||||
FROM all_inventory_item_overview
|
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)
|
WHERE (%(location_id)s IS NULL OR location = %(location_id)s)
|
||||||
AND (name ILIKE CONCAT('%%', %(search_term)s, '%%') OR item_barcode = %(search_term)s)
|
AND (name ILIKE CONCAT('%%', %(search_term)s, '%%') OR item_barcode = %(search_term)s)
|
||||||
ORDER BY bought DESC
|
ORDER BY bought DESC
|
||||||
|
|||||||
+11
-95
@@ -1,5 +1,5 @@
|
|||||||
from flask import Blueprint, flash, redirect, render_template, request
|
from flask import Blueprint, redirect, render_template, request, session
|
||||||
from flask_login import current_user
|
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
@@ -7,84 +7,8 @@ from . import db
|
|||||||
bp = Blueprint("entry", __name__, url_prefix="/entry")
|
bp = Blueprint("entry", __name__, url_prefix="/entry")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/", methods=["GET", "POST"])
|
@bp.get("/")
|
||||||
def index():
|
def index():
|
||||||
return render_template(
|
|
||||||
"entry/index.html"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.post("/add-new-items")
|
|
||||||
def add_new_entries():
|
|
||||||
i_know_what_im_doing = "i-know-what-im-doing" in request.form
|
|
||||||
if not i_know_what_im_doing:
|
|
||||||
return "Du weißt nicht was du tust", 400
|
|
||||||
|
|
||||||
orders = current_user.data.orders
|
|
||||||
if not orders:
|
|
||||||
return "Keine Aufträge", 404
|
|
||||||
|
|
||||||
# I'm aware of execute_many and extras.execute_values but we don't need to
|
|
||||||
# optimize here (yet?). This way it's a bit easier to use anyways.
|
|
||||||
for order in orders:
|
|
||||||
with db.run_query("entry/add_item_and_snack_entry.sql", order) as cursor:
|
|
||||||
pass
|
|
||||||
db.get_db().commit()
|
|
||||||
|
|
||||||
# Reset the cart
|
|
||||||
current_user.data.orders = []
|
|
||||||
|
|
||||||
return redirect(request.referrer)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.post("/delete-order")
|
|
||||||
def delete_order():
|
|
||||||
try:
|
|
||||||
order_index = int(request.form["order-index"])
|
|
||||||
except:
|
|
||||||
return "Incomplete or mistyped form", 400
|
|
||||||
|
|
||||||
del current_user.data.orders[order_index]
|
|
||||||
|
|
||||||
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-id"])
|
|
||||||
# group_name, location_name and tax_group_description are not
|
|
||||||
# necessarily needed here but storing them makes it easier to
|
|
||||||
# render the list of orders.
|
|
||||||
group_name = request.form["group-name"]
|
|
||||||
location_id = int(request.form["location-id"])
|
|
||||||
location_name = request.form["location-name"]
|
|
||||||
tax_group_id = int(request.form["tax-group-id"])
|
|
||||||
tax_group_description = request.form["tax-group-description"]
|
|
||||||
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
|
|
||||||
|
|
||||||
current_user.data.orders.append({
|
|
||||||
"barcode": barcode,
|
|
||||||
"name": name,
|
|
||||||
"sales_units": sales_units,
|
|
||||||
"group_id": group_id,
|
|
||||||
"group_name": group_name,
|
|
||||||
"location_id": location_id,
|
|
||||||
"location_name": location_name,
|
|
||||||
"tax_group_id": tax_group_id,
|
|
||||||
"tax_group_description": tax_group_description,
|
|
||||||
"net_unit_price": net_unit_price,
|
|
||||||
"gross_unit_price": gross_unit_price
|
|
||||||
})
|
|
||||||
return redirect("/entry")
|
|
||||||
|
|
||||||
with db.run_query("entry/get_groups.sql") as cursor:
|
with db.run_query("entry/get_groups.sql") as cursor:
|
||||||
groups = cursor.fetchall()
|
groups = cursor.fetchall()
|
||||||
|
|
||||||
@@ -94,20 +18,11 @@ def new_order():
|
|||||||
with db.run_query("entry/get_tax_groups.sql") as cursor:
|
with db.run_query("entry/get_tax_groups.sql") as cursor:
|
||||||
tax_groups = cursor.fetchall()
|
tax_groups = cursor.fetchall()
|
||||||
|
|
||||||
selected_location = current_user.data.location
|
return render_template("entry/index.html", **{
|
||||||
|
"locations": locations,
|
||||||
return render_template(
|
"groups": groups,
|
||||||
"entry/new-order.html",
|
"tax_groups": tax_groups
|
||||||
groups=groups,
|
})
|
||||||
locations=locations,
|
|
||||||
default_location=next(location for location in locations if location["id"] == selected_location["location_id"]) if selected_location is not None else locations[0],
|
|
||||||
tax_groups=tax_groups
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# API routes for interactive JS stuff
|
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/api/search-items")
|
@bp.get("/api/search-items")
|
||||||
def api_search_items():
|
def api_search_items():
|
||||||
@@ -116,9 +31,10 @@ def api_search_items():
|
|||||||
except:
|
except:
|
||||||
return {"error": "Missing query parameter `search-term`"}, 400
|
return {"error": "Missing query parameter `search-term`"}, 400
|
||||||
|
|
||||||
location = current_user.data.location
|
location = session.get("location", None)
|
||||||
|
|
||||||
with db.run_query("search_items.sql", {
|
with db.run_query("search_items.sql", {
|
||||||
"location_id": location["location_id"] if location else None,
|
"location_id": None if location is None else location["location_id"],
|
||||||
"search_term": search_term
|
"search_term": search_term
|
||||||
}) as cursor:
|
}) as cursor:
|
||||||
items = cursor.fetchall()
|
items = cursor.fetchall()
|
||||||
|
|||||||
+4
-11
@@ -1,5 +1,4 @@
|
|||||||
from flask import Blueprint, redirect, render_template, request
|
from flask import Blueprint, redirect, render_template, request, session
|
||||||
from flask_login import current_user
|
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
@@ -9,7 +8,7 @@ bp = Blueprint("inventory", __name__, url_prefix="/inventory")
|
|||||||
|
|
||||||
@bp.get("/")
|
@bp.get("/")
|
||||||
def index():
|
def index():
|
||||||
location = current_user.data.location
|
location = session.get("location", None)
|
||||||
items = db.run_query("get_inventory_overview.sql", {
|
items = db.run_query("get_inventory_overview.sql", {
|
||||||
"location_id": None if location is None else location["location_id"]
|
"location_id": None if location is None else location["location_id"]
|
||||||
}).fetchall()
|
}).fetchall()
|
||||||
@@ -21,18 +20,12 @@ def index():
|
|||||||
|
|
||||||
@bp.get("/report")
|
@bp.get("/report")
|
||||||
def read_report():
|
def read_report():
|
||||||
location = current_user.data.location
|
location = session.get("location", None)
|
||||||
|
|
||||||
if location is None:
|
|
||||||
# TODO: Error handling
|
|
||||||
return "please select a location in order to generate a report", 400
|
|
||||||
|
|
||||||
items = db.run_query("get_inventory_report.sql", {
|
items = db.run_query("get_inventory_report.sql", {
|
||||||
"location_id": location["location_id"]
|
"location_id": None if location is None else location["location_id"]
|
||||||
}).fetchall()
|
}).fetchall()
|
||||||
|
|
||||||
return render_template("inventory/read_report.html", **{
|
return render_template("inventory/read_report.html", **{
|
||||||
"location": location,
|
|
||||||
"items": items
|
"items": items
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -1,5 +1,4 @@
|
|||||||
from flask import Blueprint, render_template, request
|
from flask import Blueprint, render_template, request, session
|
||||||
from flask_login import current_user
|
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
@@ -12,12 +11,13 @@ def index():
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
location_id = request.form.get("location_id", "")
|
location_id = request.form.get("location_id", "")
|
||||||
if location_id == "":
|
if location_id == "":
|
||||||
current_user.data.location = None
|
session.pop("location", None)
|
||||||
else:
|
else:
|
||||||
location = db.run_query("get_location_by_id.sql", {
|
location = db.run_query("get_location_by_id.sql", {
|
||||||
"location_id": location_id
|
"location_id": location_id}
|
||||||
}).fetchone()
|
).fetchone()
|
||||||
current_user.data.location = location
|
session["location"] = location
|
||||||
|
|
||||||
|
|
||||||
locations = db.run_query("get_locations.sql").fetchall()
|
locations = db.run_query("get_locations.sql").fetchall()
|
||||||
|
|
||||||
|
|||||||
+12105
File diff suppressed because it is too large
Load Diff
@@ -40,9 +40,6 @@ nav > ul > li + li:before {
|
|||||||
.--centered {
|
.--centered {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.--not-important {
|
|
||||||
color: #aaa;
|
|
||||||
}
|
|
||||||
@keyframes wiggle {
|
@keyframes wiggle {
|
||||||
0%, 100% { margin-top: 0; }
|
0%, 100% { margin-top: 0; }
|
||||||
50% { margin-top: -0.5em; }
|
50% { margin-top: -0.5em; }
|
||||||
@@ -58,10 +55,6 @@ th {
|
|||||||
body {
|
body {
|
||||||
font-size: 8px;
|
font-size: 8px;
|
||||||
}
|
}
|
||||||
/* hide the menu when printing */
|
|
||||||
header {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.form-input > label {
|
.form-input > label {
|
||||||
font-size: .8em;
|
font-size: .8em;
|
||||||
@@ -70,18 +63,3 @@ th {
|
|||||||
.form-input > select {
|
.form-input > select {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
.form-input.--inline {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
.form-input.--inline > input:not([type=radio]),
|
|
||||||
.form-input.--inline > select {
|
|
||||||
display: block;
|
|
||||||
width: 8em;
|
|
||||||
}
|
|
||||||
details {
|
|
||||||
font-size: 0.8em;
|
|
||||||
}
|
|
||||||
.consumption-graph {
|
|
||||||
display: block;
|
|
||||||
height: 1em;
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-13
@@ -12,14 +12,13 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li{{ " class=current-page" if request.path == "/" else "" }}><a href="/">Home</a></li>
|
<li{{ " class=current-page" if request.path == "/" else "" }}><a href="/">Home</a></li>
|
||||||
<li{{ " class=current-page" if request.path.startswith("/inventory") else "" }}><a href="/inventory">Inventar</a></li>
|
<li{{ " class=current-page" if request.path.startswith("/inventory") else "" }}><a href="/inventory">Inventar</a></li>
|
||||||
<li><a href="/inventory/report">Einkäuferbericht</a></li>
|
|
||||||
<li{{ " class=current-page" if request.path.startswith("/entry") else "" }}><a href="/entry">Eintragen</a></li>
|
<li{{ " class=current-page" if request.path.startswith("/entry") else "" }}><a href="/entry">Eintragen</a></li>
|
||||||
<li{{ " class=current-page" if request.path.startswith("/location") else "" }}>
|
<li{{ " class=current-page" if request.path.startswith("/location") else "" }}>
|
||||||
<a href="/location">
|
<a href="/location">
|
||||||
{% if not current_user.data.location %}
|
{% if "location" not in session %}
|
||||||
Raum wählen
|
Raum wählen
|
||||||
{% else %}
|
{% else %}
|
||||||
Raum: {{ current_user.data.location.location_name }}
|
Raum: {{ session.location.location_name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -31,16 +30,6 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary><code>config</code></summary>
|
<summary><code>config</code></summary>
|
||||||
<pre>{% for key, value in config.items() %}{{ key }} = {{ value }}
|
<pre>{% for key, value in config.items() %}{{ key }} = {{ value }}
|
||||||
{% endfor %}</pre>
|
|
||||||
</details>
|
|
||||||
<details>
|
|
||||||
<summary><code>session</code></summary>
|
|
||||||
<pre>{% for key, value in session.items() %}{{ key }} = {{ value }}
|
|
||||||
{% endfor %}</pre>
|
|
||||||
</details>
|
|
||||||
<details>
|
|
||||||
<summary><code>current_user.data</code></summary>
|
|
||||||
<pre>{% for key, value in current_user.data.__dict__.items() %}{{ key }} = {{ value }}
|
|
||||||
{% endfor %}</pre>
|
{% endfor %}</pre>
|
||||||
</details>
|
</details>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -1,42 +1,16 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<a href="/entry/new-order">Neuer Auftrag</a>
|
<div class="entry-app"></div>
|
||||||
<h2>Aufträge</h2>
|
<script src="{{ url_for('static', filename='entry.js') }}"></script>
|
||||||
<table>
|
<script>
|
||||||
<tr>
|
Elm.Entry.init({
|
||||||
<th>Barcode</th>
|
node: document.querySelector('.entry-app'),
|
||||||
<th>Name</th>
|
flags: {
|
||||||
<th>Eingekauft</th>
|
locations: {{ to_json(locations) | safe }},
|
||||||
<th>Gruppe</th>
|
groups: {{ to_json(groups) | safe }},
|
||||||
<th>Raum</th>
|
taxGroups: {{ to_json(tax_groups) | safe }}
|
||||||
<th>Steuergruppe</th>
|
}
|
||||||
<th>EK-Preis (Netto)</th>
|
});
|
||||||
<th>VK-Preis (Brutto)</th>
|
</script>
|
||||||
<th>Aktionen</th>
|
|
||||||
</tr>
|
|
||||||
{% for cart_item in current_user.data.orders %}
|
|
||||||
<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_name }} ({{ cart_item.group_id }})</td>
|
|
||||||
<td class="--align-right">{{ cart_item.location_name }} ({{ cart_item.location_id }})</td>
|
|
||||||
<td class="--align-right">{{ cart_item.tax_group_description }} ({{ 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>
|
|
||||||
<form method="POST" action="/entry/add-new-items">
|
|
||||||
<input type="checkbox" name="i-know-what-im-doing" id="i-know-what-im-doing">
|
|
||||||
<label for="i-know-what-im-doing">I weiß, was ich tue</label>
|
|
||||||
<button>Neue Einträge anlegen</button>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
{% 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 }},
|
|
||||||
defaultLocation: {{ to_json(default_location) | safe }},
|
|
||||||
groups: {{ to_json(groups) | safe }},
|
|
||||||
defaultGroup: {{ to_json(groups[0]) | safe }},
|
|
||||||
taxGroups: {{ to_json(tax_groups) | safe }},
|
|
||||||
defaultTaxGroup: {{ to_json(tax_groups[0]) | safe }},
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,34 +1,9 @@
|
|||||||
{% macro consumption_graph_svg(values) -%}
|
|
||||||
{% set stroke_width = 8 %}
|
|
||||||
{% set width = 300 %}
|
|
||||||
{% set height = 100 %}
|
|
||||||
{% set padding = 4 %}
|
|
||||||
{% set dx = (width - 2 * padding) / ((values | length) + 1) %}
|
|
||||||
{% set dy = (height - 2 * padding) / ((values + [1]) | max) %}
|
|
||||||
<svg viewBox="0 0 {{ width }} {{ height }}" role="img" class="consumption-graph">
|
|
||||||
<polyline
|
|
||||||
points="
|
|
||||||
{% for value in values %}
|
|
||||||
{{ padding + loop.index * dx }}, {{ height - padding - value * dy }}
|
|
||||||
{% endfor %}
|
|
||||||
"
|
|
||||||
stroke="green"
|
|
||||||
stroke-width="{{ stroke_width }}"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
fill="none"
|
|
||||||
>
|
|
||||||
</svg>
|
|
||||||
{% endmacro -%}
|
|
||||||
|
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Stat</th>
|
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Graph</th>
|
|
||||||
<th>Barcode</th>
|
<th>Barcode</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Preis (Netto)</th>
|
<th>Preis (Netto)</th>
|
||||||
@@ -42,12 +17,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
|
||||||
{% if item.units_left == 0 %}<span title="Leerer aktiver Inventareintrag">🅾️</span>{% endif %}
|
|
||||||
{% if item.other_lines_count != 0 %}<span title="{% if item.other_lines_count == 1 %}Neuerer Eintrag mit demselben Barcode ist aktiv{% else %}{{ item.other_lines_count }} Einträge mit demselben Barcode sind aktiv{% endif %}">🔄</span>{% endif %}
|
|
||||||
</td>
|
|
||||||
<td><a href="/inventory/item/{{ item.item_id }}">{{ item.item_id }}</a></td>
|
<td><a href="/inventory/item/{{ item.item_id }}">{{ item.item_id }}</a></td>
|
||||||
<td>{{ consumption_graph_svg(item.last_n_days_sales) }}</td>
|
|
||||||
<td><code>{{ item.item_barcode }}</code></td>
|
<td><code>{{ item.item_barcode }}</code></td>
|
||||||
<td>{{ item.name }}</td>
|
<td>{{ item.name }}</td>
|
||||||
<td class="--align-right">{{ format_currency(item.unit_price) }}</td>
|
<td class="--align-right">{{ format_currency(item.unit_price) }}</td>
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Einkäuferbericht für {{ location.location_name }}</h2>
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
<th>Barcode</th>
|
<th>Barcode</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Inventar</th>
|
<th>Inventar</th>
|
||||||
<th title="In den letzten 4 Monaten verkauft">Verkauft</th>
|
<th>Gesamt</th>
|
||||||
|
<th>Raum</th>
|
||||||
<th>Verbrauch [1/d]</th>
|
<th>Verbrauch [1/d]</th>
|
||||||
<th>Verbrauch [1/60d]</th>
|
|
||||||
<!--
|
|
||||||
<th title="Estimated Time Until Empty">ETUE [d]</th>
|
<th title="Estimated Time Until Empty">ETUE [d]</th>
|
||||||
<th>Für 2m</th>
|
<th>Für 2m</th>
|
||||||
-->
|
|
||||||
</tr>
|
</tr>
|
||||||
{% for item in items %}
|
{% for item in items %}
|
||||||
<tr{% if item.units_left >= item.units_sold %} class="--not-important"{% endif %}>
|
<tr>
|
||||||
|
<td><a href="/inventory/item/{{ item.item_id }}">{{ item.item_id }}</a></td>
|
||||||
<td><code>{{ item.item_barcode }}</code></td>
|
<td><code>{{ item.item_barcode }}</code></td>
|
||||||
<td>{{ item.name }}</td>
|
<td>{{ item.name }}</td>
|
||||||
<td class="--align-right">{{ item.units_left }}</td>
|
<td class="--align-right">{{ item.units_left }}</td>
|
||||||
<td class="--align-right">{{ item.units_sold }}</td>
|
<td class="--align-right">{{ item.sales_units + item.correction_delta }}</td>
|
||||||
<td class="--align-right">{{ item.sold_per_day }}</td>
|
<td>{{ item.location_name }}</td>
|
||||||
<td class="--align-right">{{ item.sold_per_day * 60 }}</td>
|
<td class="--align-right">{{ item.per_day|round(2) }}</td>
|
||||||
|
<td class="--align-right">{% if item.days_left != None %}{{ item.days_left|round(1) }}{% endif %}</td>
|
||||||
|
<td class="--align-right">{% if item.for_two_months %}{{ item.for_two_months|round(1) }}{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<select name="location_id">
|
<select name="location_id">
|
||||||
<option value="" {{ "selected" if not current_user.data.location else ""}}>-</option>
|
<option value="" {{ "selected" if "location" not in session else ""}}>-</option>
|
||||||
{% for location in locations %}
|
{% for location in locations %}
|
||||||
<option value="{{ location.location_id }}" {{ "selected" if current_user.data.location.location_id == location.location_id else "" }}>{{ location.location_name }}</option>
|
<option value="{{ location.location_id }}" {{ "selected" if "location" in session and session.location.location_id == location.location_id else "" }}>{{ location.location_name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
blinker==1.6.2
|
blinker==1.6.2
|
||||||
click==8.1.3
|
click==8.1.3
|
||||||
Flask==2.3.2
|
Flask==2.3.2
|
||||||
Flask-Login==0.6.2
|
|
||||||
itsdangerous==2.1.2
|
itsdangerous==2.1.2
|
||||||
Jinja2==3.1.2
|
Jinja2==3.1.2
|
||||||
MarkupSafe==2.1.2
|
MarkupSafe==2.1.2
|
||||||
|
|||||||
Reference in New Issue
Block a user