Move around gross unit price input
This commit is contained in:
+46
-28
@@ -69,6 +69,16 @@ type alias TaxGroup =
|
||||
, percentage : Float
|
||||
}
|
||||
|
||||
type alias NewItem =
|
||||
{ barcode : String
|
||||
, name : String
|
||||
, salesUnits : Int
|
||||
, group : Group
|
||||
, location : Location
|
||||
, netUnitPrice : Float
|
||||
, taxGroup : TaxGroup
|
||||
}
|
||||
|
||||
type alias Context =
|
||||
{ globals : Globals
|
||||
, state : State
|
||||
@@ -135,11 +145,12 @@ updateState msg globals state = case state of
|
||||
case find (\tg -> tg.id == searchResult.taxGroupId) globals.taxGroups of
|
||||
Nothing -> (state, Cmd.none)
|
||||
Just taxGroup ->
|
||||
( ItemEditor <| updateGrossUnitPrice
|
||||
( ItemEditor
|
||||
{ barcode = searchResult.barcode
|
||||
, name = searchResult.name
|
||||
, netUnitPrice = NumberInput.fromFloat searchResult.netUnitPrice
|
||||
, grossUnitPrice = NumberInput.fromFloat 0
|
||||
, grossUnitPrice = NumberInput.fromFloat
|
||||
(suggestedGrossPrice searchResult.netUnitPrice taxGroup.percentage)
|
||||
, salesUnits = NumberInput.fromInt searchResult.salesUnits
|
||||
, 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
|
||||
@@ -157,26 +168,26 @@ updateState msg globals state = case state of
|
||||
SetSalesUnits str ->
|
||||
(ItemEditor { model | salesUnits = NumberInput.update str model.salesUnits }, Cmd.none)
|
||||
SetNetUnitPrice str ->
|
||||
( ItemEditor <| updateGrossUnitPrice { model | netUnitPrice = NumberInput.update str model.netUnitPrice }
|
||||
( ItemEditor { model | netUnitPrice = NumberInput.update str model.netUnitPrice }
|
||||
, Cmd.none
|
||||
)
|
||||
SetGrossUnitPrice str ->
|
||||
(ItemEditor { model | grossUnitPrice = NumberInput.update str model.grossUnitPrice }, Cmd.none)
|
||||
( ItemEditor { model | grossUnitPrice = NumberInput.update str model.grossUnitPrice }
|
||||
, Cmd.none
|
||||
)
|
||||
SetGroup key ->
|
||||
(ItemEditor { model | group = Select.update key model.group }, Cmd.none)
|
||||
SetLocation key ->
|
||||
(ItemEditor { model | location = Select.update key model.location }, Cmd.none)
|
||||
SetTaxGroup key ->
|
||||
( ItemEditor <| updateGrossUnitPrice { model | taxGroup = Select.update key model.taxGroup }
|
||||
( ItemEditor { model | taxGroup = Select.update key model.taxGroup }
|
||||
, Cmd.none
|
||||
)
|
||||
_ ->
|
||||
(state, Cmd.none)
|
||||
|
||||
updateGrossUnitPrice model =
|
||||
{ model
|
||||
| grossUnitPrice = Maybe.withDefault model.grossUnitPrice <| Maybe.map NumberInput.fromFloat <| calculateGarfieldPrice model
|
||||
}
|
||||
suggestedGrossPrice netPrice percentage =
|
||||
roundTo 2 <| netPrice * (1 + percentage) + 0.01
|
||||
|
||||
-- View stuff
|
||||
|
||||
@@ -217,7 +228,7 @@ view { globals, state } = case state of
|
||||
, Select.view SetLocation model.location
|
||||
]
|
||||
, div [ class "form-input" ]
|
||||
[ label [ for "net-unit-price" ] [ text "Stückpreis (Netto)" ]
|
||||
[ label [ for "net-unit-price" ] [ text "Einkaufspreis (Netto)" ]
|
||||
, input
|
||||
[ value <| NumberInput.show model.netUnitPrice
|
||||
, onInput SetNetUnitPrice
|
||||
@@ -231,29 +242,36 @@ view { globals, state } = case state of
|
||||
[ label [ for "tax-group" ] [ text "Steuergruppe" ]
|
||||
, Select.view SetTaxGroup model.taxGroup
|
||||
]
|
||||
]
|
||||
, fieldset []
|
||||
[ legend [] [ text "Neuer Snackeintrag" ]
|
||||
, div [ class "form-input" ]
|
||||
[ label [ for "snack-name" ] [ text "Name" ]
|
||||
, input [ value model.name, disabled True, id "snack-name" ] []
|
||||
[ label [ for "gross-unit-price" ] [ text "Verkaufspreis (Brutto)" ]
|
||||
, input
|
||||
[ value <| NumberInput.show model.grossUnitPrice
|
||||
, onInput SetGrossUnitPrice
|
||||
, type_ "number"
|
||||
, id "gross-unit-price"
|
||||
, step "0.01"
|
||||
]
|
||||
[]
|
||||
, viewSetSuggestedPriceButton model
|
||||
]
|
||||
, viewGrossUnitPriceInput model
|
||||
]
|
||||
]
|
||||
|
||||
viewGrossUnitPriceInput model =
|
||||
let
|
||||
suggestedPriceStr = case calculateGarfieldPrice model of
|
||||
Nothing -> "?"
|
||||
Just suggestedPrice -> String.fromFloat suggestedPrice
|
||||
in
|
||||
div [ class "form-input" ]
|
||||
[ label [ for "gross-unit-price" ]
|
||||
[ text <| "Stückpreis (Brutto), Vorschlag: " ++ suggestedPriceStr
|
||||
]
|
||||
, 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 =
|
||||
tr []
|
||||
|
||||
Reference in New Issue
Block a user