Compare commits
4 Commits
6c7bb1042c
...
18abd38987
Author | SHA1 | Date | |
---|---|---|---|
18abd38987 | |||
8be0f0ddb7 | |||
43407d7890 | |||
902b636aba |
@ -36,3 +36,4 @@ ssh -nNTvL 5432:fsmi-db.fsmi.org:5432 fsmi-login.fsmi.uni-karlsruhe.de
|
||||
- [ ] Make it print nicely
|
||||
- [ ] Make it possible to edit entries
|
||||
- [ ] Improve project structure
|
||||
- [ ] Figure out/Add documentation about building `entry.js`
|
||||
|
103
frontend/Calculator.elm
Normal file
103
frontend/Calculator.elm
Normal file
@ -0,0 +1,103 @@
|
||||
module Calculator exposing (..)
|
||||
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (..)
|
||||
|
||||
import NumberInput
|
||||
import Select
|
||||
|
||||
type Tax = Net | Gross
|
||||
|
||||
ctShow ct = case ct of
|
||||
Gross -> "Brutto"
|
||||
Net -> "Netto"
|
||||
|
||||
type alias Model =
|
||||
{ tax : Select.Model Tax
|
||||
, bundlePrice : NumberInput.Model Float
|
||||
, bundleSize : NumberInput.Model Int
|
||||
}
|
||||
|
||||
init bundlePrice = Model
|
||||
(Select.init ctShow ctShow Net [Net, Gross])
|
||||
(NumberInput.fromFloat bundlePrice)
|
||||
(NumberInput.fromInt 1)
|
||||
|
||||
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 = 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 =
|
||||
let
|
||||
mainPart =
|
||||
[ text "("
|
||||
, input
|
||||
[ class "formula-input", placeholder "Gebindepreis"
|
||||
, value <| NumberInput.show model.bundlePrice
|
||||
, onInput SetBundlePrice
|
||||
]
|
||||
[]
|
||||
, text " ÷ "
|
||||
, input
|
||||
[ class "formula-input", placeholder "Gebindegröße"
|
||||
, value <| NumberInput.show model.bundleSize
|
||||
, onInput SetBundleSize
|
||||
]
|
||||
[]
|
||||
, text ") "
|
||||
]
|
||||
taxPart =
|
||||
[ text " ÷ "
|
||||
, input
|
||||
[ class "formula-input"
|
||||
, disabled True
|
||||
, value <| String.fromFloat <| 1 + taxGroup.percentage
|
||||
]
|
||||
[]
|
||||
]
|
||||
resultPart =
|
||||
[ text " = "
|
||||
, input
|
||||
[ class "formula-input"
|
||||
, disabled True
|
||||
, value <| 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 places x = toFloat (round <| x * 10 ^ places) / 10 ^ places
|
@ -10,6 +10,7 @@ import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (..)
|
||||
|
||||
import Calculator
|
||||
import NumberInput
|
||||
import Select
|
||||
|
||||
@ -69,6 +70,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
|
||||
@ -89,6 +100,7 @@ type State
|
||||
{ barcode : String
|
||||
, name : String
|
||||
, salesUnits : NumberInput.Model Int
|
||||
, calculator : Calculator.Model
|
||||
, netUnitPrice : NumberInput.Model Float
|
||||
, grossUnitPrice : NumberInput.Model Float
|
||||
, group : Select.Model Group
|
||||
@ -104,6 +116,7 @@ type Msg
|
||||
| SetBarcode String
|
||||
| SetName String
|
||||
| SetSalesUnits String
|
||||
| CalculatorMsg Calculator.Msg
|
||||
| SetNetUnitPrice String
|
||||
| SetGrossUnitPrice String
|
||||
| SetGroup String
|
||||
@ -135,11 +148,13 @@ 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
|
||||
, calculator = Calculator.init searchResult.netUnitPrice
|
||||
, 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
|
||||
@ -156,27 +171,29 @@ updateState msg globals state = case state of
|
||||
(ItemEditor { model | name = name }, Cmd.none)
|
||||
SetSalesUnits str ->
|
||||
(ItemEditor { model | salesUnits = NumberInput.update str model.salesUnits }, Cmd.none)
|
||||
CalculatorMsg msg_ ->
|
||||
(ItemEditor { model | calculator = Calculator.update msg_ model.calculator }, 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 +234,12 @@ 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 "tax-group" ] [ text "Steuergruppe" ]
|
||||
, Select.view SetTaxGroup model.taxGroup
|
||||
]
|
||||
, Html.map CalculatorMsg <| Calculator.view model.calculator (Select.get model.taxGroup)
|
||||
, div [ class "form-input" ]
|
||||
[ label [ for "net-unit-price" ] [ text "Einkaufspreis (Netto)" ]
|
||||
, input
|
||||
[ value <| NumberInput.show model.netUnitPrice
|
||||
, onInput SetNetUnitPrice
|
||||
@ -226,34 +248,51 @@ view { globals, state } = case state of
|
||||
, step "0.01"
|
||||
]
|
||||
[]
|
||||
, viewSetCalculatedPriceButton model
|
||||
]
|
||||
, div [ class "form-input" ]
|
||||
[ label [ for "tax-group" ] [ text "Steuergruppe" ]
|
||||
, Select.view SetTaxGroup model.taxGroup
|
||||
[ 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
|
||||
]
|
||||
]
|
||||
, fieldset []
|
||||
[ legend [] [ text "Neuer Snackeintrag" ]
|
||||
, div [ class "form-input" ]
|
||||
[ label [ for "snack-name" ] [ text "Name" ]
|
||||
, input [ value model.name, disabled True, id "snack-name" ] []
|
||||
]
|
||||
, 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
|
||||
viewSetCalculatedPriceButton model =
|
||||
case Calculator.getResult model.calculator (Select.get model.taxGroup) of
|
||||
Nothing ->
|
||||
button [ disabled True ] [ text "Auf ? setzen" ]
|
||||
Just calculatedPrice ->
|
||||
button
|
||||
[ onClick <| SetNetUnitPrice <| String.fromFloat calculatedPrice
|
||||
-- Prevent submitting the form
|
||||
, type_ "button"
|
||||
]
|
||||
, input [ onInput SetGrossUnitPrice, value <| NumberInput.show model.grossUnitPrice, id "gross-unit-price", type_ "number", step "0.01" ] []
|
||||
]
|
||||
[ text <| "Auf " ++ String.fromFloat calculatedPrice ++ " setzen"
|
||||
]
|
||||
|
||||
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 []
|
||||
|
@ -11037,11 +11037,37 @@ var $elm$http$Http$get = function (r) {
|
||||
return $elm$http$Http$request(
|
||||
{body: $elm$http$Http$emptyBody, expect: r.expect, headers: _List_Nil, method: 'GET', timeout: $elm$core$Maybe$Nothing, tracker: $elm$core$Maybe$Nothing, url: r.url});
|
||||
};
|
||||
var $author$project$Calculator$Gross = {$: 'Gross'};
|
||||
var $author$project$Calculator$Model = F3(
|
||||
function (tax, bundlePrice, bundleSize) {
|
||||
return {bundlePrice: bundlePrice, bundleSize: bundleSize, tax: tax};
|
||||
});
|
||||
var $author$project$Calculator$Net = {$: 'Net'};
|
||||
var $author$project$Calculator$ctShow = function (ct) {
|
||||
if (ct.$ === 'Gross') {
|
||||
return 'Brutto';
|
||||
} else {
|
||||
return 'Netto';
|
||||
}
|
||||
};
|
||||
var $author$project$Select$Model = F4(
|
||||
function (identify, show, selected, options) {
|
||||
return {identify: identify, options: options, selected: selected, show: show};
|
||||
});
|
||||
var $author$project$Select$init = $author$project$Select$Model;
|
||||
var $author$project$Calculator$init = function (bundlePrice) {
|
||||
return A3(
|
||||
$author$project$Calculator$Model,
|
||||
A4(
|
||||
$author$project$Select$init,
|
||||
$author$project$Calculator$ctShow,
|
||||
$author$project$Calculator$ctShow,
|
||||
$author$project$Calculator$Net,
|
||||
_List_fromArray(
|
||||
[$author$project$Calculator$Net, $author$project$Calculator$Gross])),
|
||||
$author$project$NumberInput$fromFloat(bundlePrice),
|
||||
$author$project$NumberInput$fromInt(1));
|
||||
};
|
||||
var $author$project$Entry$SearchResult = function (barcode) {
|
||||
return function (name) {
|
||||
return function (netUnitPrice) {
|
||||
@ -11119,6 +11145,17 @@ var $author$project$Entry$searchResultDecoder = A3(
|
||||
'item_barcode',
|
||||
$elm$json$Json$Decode$string,
|
||||
$elm$json$Json$Decode$succeed($author$project$Entry$SearchResult))))))))))));
|
||||
var $elm$core$Basics$pow = _Basics_pow;
|
||||
var $elm$core$Basics$round = _Basics_round;
|
||||
var $author$project$Entry$roundTo = F2(
|
||||
function (places, x) {
|
||||
return $elm$core$Basics$round(
|
||||
x * A2($elm$core$Basics$pow, 10, places)) / A2($elm$core$Basics$pow, 10, places);
|
||||
});
|
||||
var $author$project$Entry$suggestedGrossPrice = F2(
|
||||
function (netPrice, percentage) {
|
||||
return A2($author$project$Entry$roundTo, 2, (netPrice * (1 + percentage)) + 0.01);
|
||||
});
|
||||
var $author$project$NumberInput$update = F2(
|
||||
function (str, model) {
|
||||
return _Utils_update(
|
||||
@ -11152,53 +11189,32 @@ var $author$project$Select$update = F2(
|
||||
{selected: x});
|
||||
}
|
||||
});
|
||||
var $author$project$NumberInput$get = function ($) {
|
||||
return $.value;
|
||||
};
|
||||
var $author$project$Select$get = function ($) {
|
||||
return $.selected;
|
||||
};
|
||||
var $elm$core$Maybe$map = F2(
|
||||
function (f, maybe) {
|
||||
if (maybe.$ === 'Just') {
|
||||
var value = maybe.a;
|
||||
return $elm$core$Maybe$Just(
|
||||
f(value));
|
||||
} else {
|
||||
return $elm$core$Maybe$Nothing;
|
||||
var $author$project$Calculator$update = F2(
|
||||
function (msg, model) {
|
||||
switch (msg.$) {
|
||||
case 'SetTax':
|
||||
var key = msg.a;
|
||||
return _Utils_update(
|
||||
model,
|
||||
{
|
||||
tax: A2($author$project$Select$update, key, model.tax)
|
||||
});
|
||||
case 'SetBundlePrice':
|
||||
var str = msg.a;
|
||||
return _Utils_update(
|
||||
model,
|
||||
{
|
||||
bundlePrice: A2($author$project$NumberInput$update, str, model.bundlePrice)
|
||||
});
|
||||
default:
|
||||
var str = msg.a;
|
||||
return _Utils_update(
|
||||
model,
|
||||
{
|
||||
bundleSize: A2($author$project$NumberInput$update, str, model.bundleSize)
|
||||
});
|
||||
}
|
||||
});
|
||||
var $elm$core$Basics$pow = _Basics_pow;
|
||||
var $elm$core$Basics$round = _Basics_round;
|
||||
var $author$project$Entry$roundTo = F2(
|
||||
function (places, x) {
|
||||
return $elm$core$Basics$round(
|
||||
x * A2($elm$core$Basics$pow, 10, places)) / A2($elm$core$Basics$pow, 10, places);
|
||||
});
|
||||
var $author$project$Entry$calculateGarfieldPrice = function (model) {
|
||||
return A2(
|
||||
$elm$core$Maybe$map,
|
||||
function (netUnitPrice) {
|
||||
return A2(
|
||||
$author$project$Entry$roundTo,
|
||||
2,
|
||||
(netUnitPrice * (1 + $author$project$Select$get(model.taxGroup).percentage)) + 0.01);
|
||||
},
|
||||
$author$project$NumberInput$get(model.netUnitPrice));
|
||||
};
|
||||
var $author$project$Entry$updateGrossUnitPrice = function (model) {
|
||||
return _Utils_update(
|
||||
model,
|
||||
{
|
||||
grossUnitPrice: A2(
|
||||
$elm$core$Maybe$withDefault,
|
||||
model.grossUnitPrice,
|
||||
A2(
|
||||
$elm$core$Maybe$map,
|
||||
$author$project$NumberInput$fromFloat,
|
||||
$author$project$Entry$calculateGarfieldPrice(model)))
|
||||
});
|
||||
};
|
||||
var $author$project$Entry$updateState = F3(
|
||||
function (msg, globals, state) {
|
||||
if (state.$ === 'ItemSearch') {
|
||||
@ -11251,53 +11267,54 @@ var $author$project$Entry$updateState = F3(
|
||||
var taxGroup = _v2.a;
|
||||
return _Utils_Tuple2(
|
||||
$author$project$Entry$ItemEditor(
|
||||
$author$project$Entry$updateGrossUnitPrice(
|
||||
{
|
||||
barcode: searchResult.barcode,
|
||||
grossUnitPrice: $author$project$NumberInput$fromFloat(0),
|
||||
group: A4(
|
||||
$author$project$Select$init,
|
||||
A2(
|
||||
$elm$core$Basics$composeR,
|
||||
function ($) {
|
||||
return $.id;
|
||||
},
|
||||
$elm$core$String$fromInt),
|
||||
{
|
||||
barcode: searchResult.barcode,
|
||||
calculator: $author$project$Calculator$init(searchResult.netUnitPrice),
|
||||
grossUnitPrice: $author$project$NumberInput$fromFloat(
|
||||
A2($author$project$Entry$suggestedGrossPrice, searchResult.netUnitPrice, taxGroup.percentage)),
|
||||
group: A4(
|
||||
$author$project$Select$init,
|
||||
A2(
|
||||
$elm$core$Basics$composeR,
|
||||
function ($) {
|
||||
return $.name;
|
||||
return $.id;
|
||||
},
|
||||
{id: searchResult.groupId, name: searchResult.groupName},
|
||||
globals.groups),
|
||||
location: A4(
|
||||
$author$project$Select$init,
|
||||
A2(
|
||||
$elm$core$Basics$composeR,
|
||||
function ($) {
|
||||
return $.id;
|
||||
},
|
||||
$elm$core$String$fromInt),
|
||||
$elm$core$String$fromInt),
|
||||
function ($) {
|
||||
return $.name;
|
||||
},
|
||||
{id: searchResult.groupId, name: searchResult.groupName},
|
||||
globals.groups),
|
||||
location: A4(
|
||||
$author$project$Select$init,
|
||||
A2(
|
||||
$elm$core$Basics$composeR,
|
||||
function ($) {
|
||||
return $.name;
|
||||
return $.id;
|
||||
},
|
||||
{id: searchResult.locationId, name: searchResult.locationName},
|
||||
globals.locations),
|
||||
name: searchResult.name,
|
||||
netUnitPrice: $author$project$NumberInput$fromFloat(searchResult.netUnitPrice),
|
||||
salesUnits: $author$project$NumberInput$fromInt(searchResult.salesUnits),
|
||||
taxGroup: A4(
|
||||
$author$project$Select$init,
|
||||
A2(
|
||||
$elm$core$Basics$composeR,
|
||||
function ($) {
|
||||
return $.id;
|
||||
},
|
||||
$elm$core$String$fromInt),
|
||||
$elm$core$String$fromInt),
|
||||
function ($) {
|
||||
return $.name;
|
||||
},
|
||||
{id: searchResult.locationId, name: searchResult.locationName},
|
||||
globals.locations),
|
||||
name: searchResult.name,
|
||||
netUnitPrice: $author$project$NumberInput$fromFloat(searchResult.netUnitPrice),
|
||||
salesUnits: $author$project$NumberInput$fromInt(searchResult.salesUnits),
|
||||
taxGroup: A4(
|
||||
$author$project$Select$init,
|
||||
A2(
|
||||
$elm$core$Basics$composeR,
|
||||
function ($) {
|
||||
return $.description;
|
||||
return $.id;
|
||||
},
|
||||
taxGroup,
|
||||
globals.taxGroups)
|
||||
})),
|
||||
$elm$core$String$fromInt),
|
||||
function ($) {
|
||||
return $.description;
|
||||
},
|
||||
taxGroup,
|
||||
globals.taxGroups)
|
||||
}),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
}
|
||||
default:
|
||||
@ -11334,16 +11351,25 @@ var $author$project$Entry$updateState = F3(
|
||||
salesUnits: A2($author$project$NumberInput$update, str, model.salesUnits)
|
||||
})),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
case 'CalculatorMsg':
|
||||
var msg_ = msg.a;
|
||||
return _Utils_Tuple2(
|
||||
$author$project$Entry$ItemEditor(
|
||||
_Utils_update(
|
||||
model,
|
||||
{
|
||||
calculator: A2($author$project$Calculator$update, msg_, model.calculator)
|
||||
})),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
case 'SetNetUnitPrice':
|
||||
var str = msg.a;
|
||||
return _Utils_Tuple2(
|
||||
$author$project$Entry$ItemEditor(
|
||||
$author$project$Entry$updateGrossUnitPrice(
|
||||
_Utils_update(
|
||||
model,
|
||||
{
|
||||
netUnitPrice: A2($author$project$NumberInput$update, str, model.netUnitPrice)
|
||||
}))),
|
||||
_Utils_update(
|
||||
model,
|
||||
{
|
||||
netUnitPrice: A2($author$project$NumberInput$update, str, model.netUnitPrice)
|
||||
})),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
case 'SetGrossUnitPrice':
|
||||
var str = msg.a;
|
||||
@ -11379,12 +11405,11 @@ var $author$project$Entry$updateState = F3(
|
||||
var key = msg.a;
|
||||
return _Utils_Tuple2(
|
||||
$author$project$Entry$ItemEditor(
|
||||
$author$project$Entry$updateGrossUnitPrice(
|
||||
_Utils_update(
|
||||
model,
|
||||
{
|
||||
taxGroup: A2($author$project$Select$update, key, model.taxGroup)
|
||||
}))),
|
||||
_Utils_update(
|
||||
model,
|
||||
{
|
||||
taxGroup: A2($author$project$Select$update, key, model.taxGroup)
|
||||
})),
|
||||
$elm$core$Platform$Cmd$none);
|
||||
default:
|
||||
return _Utils_Tuple2(state, $elm$core$Platform$Cmd$none);
|
||||
@ -11402,9 +11427,15 @@ var $author$project$Entry$update = F2(
|
||||
{globals: globals, state: state_},
|
||||
cmd);
|
||||
});
|
||||
var $author$project$Entry$CalculatorMsg = function (a) {
|
||||
return {$: 'CalculatorMsg', a: a};
|
||||
};
|
||||
var $author$project$Entry$SetBarcode = function (a) {
|
||||
return {$: 'SetBarcode', a: a};
|
||||
};
|
||||
var $author$project$Entry$SetGrossUnitPrice = function (a) {
|
||||
return {$: 'SetGrossUnitPrice', a: a};
|
||||
};
|
||||
var $author$project$Entry$SetGroup = function (a) {
|
||||
return {$: 'SetGroup', a: a};
|
||||
};
|
||||
@ -11439,6 +11470,9 @@ var $elm$html$Html$Attributes$disabled = $elm$html$Html$Attributes$boolProperty(
|
||||
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');
|
||||
var $author$project$Select$get = function ($) {
|
||||
return $.selected;
|
||||
};
|
||||
var $elm$html$Html$label = _VirtualDom_node('label');
|
||||
var $elm$html$Html$legend = _VirtualDom_node('legend');
|
||||
var $elm$html$Html$Events$alwaysPreventDefault = function (msg) {
|
||||
@ -11535,6 +11569,53 @@ var $elm$html$Html$Attributes$step = function (n) {
|
||||
return A2($elm$html$Html$Attributes$stringProperty, 'step', n);
|
||||
};
|
||||
var $elm$html$Html$table = _VirtualDom_node('table');
|
||||
var $author$project$Calculator$SetBundlePrice = function (a) {
|
||||
return {$: 'SetBundlePrice', a: a};
|
||||
};
|
||||
var $author$project$Calculator$SetBundleSize = function (a) {
|
||||
return {$: 'SetBundleSize', a: a};
|
||||
};
|
||||
var $author$project$Calculator$SetTax = function (a) {
|
||||
return {$: 'SetTax', a: a};
|
||||
};
|
||||
var $author$project$NumberInput$get = function ($) {
|
||||
return $.value;
|
||||
};
|
||||
var $author$project$Calculator$roundTo = F2(
|
||||
function (places, x) {
|
||||
return $elm$core$Basics$round(
|
||||
x * A2($elm$core$Basics$pow, 10, places)) / A2($elm$core$Basics$pow, 10, places);
|
||||
});
|
||||
var $author$project$Calculator$getResult = F2(
|
||||
function (model, taxGroup) {
|
||||
var _v0 = _Utils_Tuple2(
|
||||
$author$project$NumberInput$get(model.bundlePrice),
|
||||
$author$project$NumberInput$get(model.bundleSize));
|
||||
if ((_v0.a.$ === 'Just') && (_v0.b.$ === 'Just')) {
|
||||
var bundlePrice = _v0.a.a;
|
||||
var bundleSize = _v0.b.a;
|
||||
return $elm$core$Maybe$Just(
|
||||
A2(
|
||||
$author$project$Calculator$roundTo,
|
||||
2,
|
||||
_Utils_eq(
|
||||
$author$project$Select$get(model.tax),
|
||||
$author$project$Calculator$Gross) ? ((bundlePrice / bundleSize) / (1 + taxGroup.percentage)) : (bundlePrice / bundleSize)));
|
||||
} else {
|
||||
return $elm$core$Maybe$Nothing;
|
||||
}
|
||||
});
|
||||
var $elm$core$Maybe$map = F2(
|
||||
function (f, maybe) {
|
||||
if (maybe.$ === 'Just') {
|
||||
var value = maybe.a;
|
||||
return $elm$core$Maybe$Just(
|
||||
f(value));
|
||||
} else {
|
||||
return $elm$core$Maybe$Nothing;
|
||||
}
|
||||
});
|
||||
var $elm$html$Html$Attributes$placeholder = $elm$html$Html$Attributes$stringProperty('placeholder');
|
||||
var $elm$html$Html$option = _VirtualDom_node('option');
|
||||
var $elm$html$Html$select = _VirtualDom_node('select');
|
||||
var $elm$html$Html$Attributes$selected = $elm$html$Html$Attributes$boolProperty('selected');
|
||||
@ -11566,51 +11647,119 @@ var $author$project$Select$view = F2(
|
||||
]),
|
||||
A2($elm$core$List$map, viewOption, model.options));
|
||||
});
|
||||
var $author$project$Entry$SetGrossUnitPrice = function (a) {
|
||||
return {$: 'SetGrossUnitPrice', a: a};
|
||||
};
|
||||
var $author$project$Entry$viewGrossUnitPriceInput = function (model) {
|
||||
var suggestedPriceStr = function () {
|
||||
var _v0 = $author$project$Entry$calculateGarfieldPrice(model);
|
||||
if (_v0.$ === 'Nothing') {
|
||||
return '?';
|
||||
} else {
|
||||
var suggestedPrice = _v0.a;
|
||||
return $elm$core$String$fromFloat(suggestedPrice);
|
||||
}
|
||||
}();
|
||||
return A2(
|
||||
$elm$html$Html$div,
|
||||
_List_fromArray(
|
||||
var $author$project$Calculator$view = F2(
|
||||
function (model, taxGroup) {
|
||||
var taxPart = _List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$class('form-input')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$html$Html$label,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$for('gross-unit-price')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Stückpreis (Brutto), Vorschlag: ' + suggestedPriceStr)
|
||||
])),
|
||||
$elm$html$Html$text(' ÷ '),
|
||||
A2(
|
||||
$elm$html$Html$input,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Events$onInput($author$project$Entry$SetGrossUnitPrice),
|
||||
$elm$html$Html$Attributes$class('formula-input'),
|
||||
$elm$html$Html$Attributes$disabled(true),
|
||||
$elm$html$Html$Attributes$value(
|
||||
$author$project$NumberInput$show(model.grossUnitPrice)),
|
||||
$elm$html$Html$Attributes$id('gross-unit-price'),
|
||||
$elm$html$Html$Attributes$type_('number'),
|
||||
$elm$html$Html$Attributes$step('0.01')
|
||||
$elm$core$String$fromFloat(1 + taxGroup.percentage))
|
||||
]),
|
||||
_List_Nil)
|
||||
]));
|
||||
};
|
||||
]);
|
||||
var resultPart = _List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text(' = '),
|
||||
A2(
|
||||
$elm$html$Html$input,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$class('formula-input'),
|
||||
$elm$html$Html$Attributes$disabled(true),
|
||||
$elm$html$Html$Attributes$value(
|
||||
A2(
|
||||
$elm$core$Maybe$withDefault,
|
||||
'?',
|
||||
A2(
|
||||
$elm$core$Maybe$map,
|
||||
$elm$core$String$fromFloat,
|
||||
A2($author$project$Calculator$getResult, model, taxGroup))))
|
||||
]),
|
||||
_List_Nil)
|
||||
]);
|
||||
var mainPart = _List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('('),
|
||||
A2(
|
||||
$elm$html$Html$input,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$class('formula-input'),
|
||||
$elm$html$Html$Attributes$placeholder('Gebindepreis'),
|
||||
$elm$html$Html$Attributes$value(
|
||||
$author$project$NumberInput$show(model.bundlePrice)),
|
||||
$elm$html$Html$Events$onInput($author$project$Calculator$SetBundlePrice)
|
||||
]),
|
||||
_List_Nil),
|
||||
$elm$html$Html$text(' ÷ '),
|
||||
A2(
|
||||
$elm$html$Html$input,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$class('formula-input'),
|
||||
$elm$html$Html$Attributes$placeholder('Gebindegröße'),
|
||||
$elm$html$Html$Attributes$value(
|
||||
$author$project$NumberInput$show(model.bundleSize)),
|
||||
$elm$html$Html$Events$onInput($author$project$Calculator$SetBundleSize)
|
||||
]),
|
||||
_List_Nil),
|
||||
$elm$html$Html$text(') ')
|
||||
]);
|
||||
return A2(
|
||||
$elm$html$Html$fieldset,
|
||||
_List_Nil,
|
||||
_List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$html$Html$legend,
|
||||
_List_Nil,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Preisrechner')
|
||||
])),
|
||||
A2(
|
||||
$elm$html$Html$div,
|
||||
_List_Nil,
|
||||
$elm$core$List$concat(
|
||||
A2(
|
||||
$elm$core$List$filterMap,
|
||||
$elm$core$Basics$identity,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$core$Maybe$Just(mainPart),
|
||||
_Utils_eq(
|
||||
$author$project$Select$get(model.tax),
|
||||
$author$project$Calculator$Gross) ? $elm$core$Maybe$Just(taxPart) : $elm$core$Maybe$Nothing,
|
||||
$elm$core$Maybe$Just(resultPart)
|
||||
])))),
|
||||
A2(
|
||||
$elm$html$Html$div,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$class('form-input')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$html$Html$label,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$for('calculator-tax')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Gebindepreis ist')
|
||||
])),
|
||||
A2($author$project$Select$view, $author$project$Calculator$SetTax, model.tax)
|
||||
]))
|
||||
]));
|
||||
});
|
||||
var $author$project$Entry$GotoItemEditor = function (a) {
|
||||
return {$: 'GotoItemEditor', a: a};
|
||||
};
|
||||
@ -11712,6 +11861,75 @@ var $author$project$Entry$viewSearchResult = function (model) {
|
||||
]))
|
||||
]));
|
||||
};
|
||||
var $author$project$Entry$viewSetCalculatedPriceButton = function (model) {
|
||||
var _v0 = A2(
|
||||
$author$project$Calculator$getResult,
|
||||
model.calculator,
|
||||
$author$project$Select$get(model.taxGroup));
|
||||
if (_v0.$ === 'Nothing') {
|
||||
return A2(
|
||||
$elm$html$Html$button,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$disabled(true)
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Auf ? setzen')
|
||||
]));
|
||||
} else {
|
||||
var calculatedPrice = _v0.a;
|
||||
return A2(
|
||||
$elm$html$Html$button,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Events$onClick(
|
||||
$author$project$Entry$SetNetUnitPrice(
|
||||
$elm$core$String$fromFloat(calculatedPrice))),
|
||||
$elm$html$Html$Attributes$type_('button')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text(
|
||||
'Auf ' + ($elm$core$String$fromFloat(calculatedPrice) + ' setzen'))
|
||||
]));
|
||||
}
|
||||
};
|
||||
var $author$project$Entry$viewSetSuggestedPriceButton = function (model) {
|
||||
var _v0 = $author$project$NumberInput$get(model.netUnitPrice);
|
||||
if (_v0.$ === 'Nothing') {
|
||||
return A2(
|
||||
$elm$html$Html$button,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$disabled(true)
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Auf ? setzen')
|
||||
]));
|
||||
} else {
|
||||
var netUnitPrice = _v0.a;
|
||||
var grossUnitPrice = A2(
|
||||
$author$project$Entry$suggestedGrossPrice,
|
||||
netUnitPrice,
|
||||
$author$project$Select$get(model.taxGroup).percentage);
|
||||
return A2(
|
||||
$elm$html$Html$button,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Events$onClick(
|
||||
$author$project$Entry$SetGrossUnitPrice(
|
||||
$elm$core$String$fromFloat(grossUnitPrice))),
|
||||
$elm$html$Html$Attributes$type_('button')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text(
|
||||
'Auf ' + ($elm$core$String$fromFloat(grossUnitPrice) + ' setzen'))
|
||||
]));
|
||||
}
|
||||
};
|
||||
var $author$project$Entry$view = function (_v0) {
|
||||
var globals = _v0.globals;
|
||||
var state = _v0.state;
|
||||
@ -11923,6 +12141,33 @@ var $author$project$Entry$view = function (_v0) {
|
||||
])),
|
||||
A2(
|
||||
$elm$html$Html$div,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$class('form-input')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$html$Html$label,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$for('tax-group')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Steuergruppe')
|
||||
])),
|
||||
A2($author$project$Select$view, $author$project$Entry$SetTaxGroup, model.taxGroup)
|
||||
])),
|
||||
A2(
|
||||
$elm$html$Html$map,
|
||||
$author$project$Entry$CalculatorMsg,
|
||||
A2(
|
||||
$author$project$Calculator$view,
|
||||
model.calculator,
|
||||
$author$project$Select$get(model.taxGroup))),
|
||||
A2(
|
||||
$elm$html$Html$div,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$class('form-input')
|
||||
@ -11937,7 +12182,7 @@ var $author$project$Entry$view = function (_v0) {
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Stückpreis (Netto)')
|
||||
$elm$html$Html$text('Einkaufspreis (Netto)')
|
||||
])),
|
||||
A2(
|
||||
$elm$html$Html$input,
|
||||
@ -11950,7 +12195,8 @@ var $author$project$Entry$view = function (_v0) {
|
||||
$elm$html$Html$Attributes$id('net-unit-price'),
|
||||
$elm$html$Html$Attributes$step('0.01')
|
||||
]),
|
||||
_List_Nil)
|
||||
_List_Nil),
|
||||
$author$project$Entry$viewSetCalculatedPriceButton(model)
|
||||
])),
|
||||
A2(
|
||||
$elm$html$Html$div,
|
||||
@ -11964,56 +12210,26 @@ var $author$project$Entry$view = function (_v0) {
|
||||
$elm$html$Html$label,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$for('tax-group')
|
||||
$elm$html$Html$Attributes$for('gross-unit-price')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Steuergruppe')
|
||||
])),
|
||||
A2($author$project$Select$view, $author$project$Entry$SetTaxGroup, model.taxGroup)
|
||||
]))
|
||||
])),
|
||||
A2(
|
||||
$elm$html$Html$fieldset,
|
||||
_List_Nil,
|
||||
_List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$html$Html$legend,
|
||||
_List_Nil,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Neuer Snackeintrag')
|
||||
])),
|
||||
A2(
|
||||
$elm$html$Html$div,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$class('form-input')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
A2(
|
||||
$elm$html$Html$label,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$for('snack-name')
|
||||
]),
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$text('Name')
|
||||
$elm$html$Html$text('Verkaufspreis (Brutto)')
|
||||
])),
|
||||
A2(
|
||||
$elm$html$Html$input,
|
||||
_List_fromArray(
|
||||
[
|
||||
$elm$html$Html$Attributes$value(model.name),
|
||||
$elm$html$Html$Attributes$disabled(true),
|
||||
$elm$html$Html$Attributes$id('snack-name')
|
||||
$elm$html$Html$Attributes$value(
|
||||
$author$project$NumberInput$show(model.grossUnitPrice)),
|
||||
$elm$html$Html$Events$onInput($author$project$Entry$SetGrossUnitPrice),
|
||||
$elm$html$Html$Attributes$type_('number'),
|
||||
$elm$html$Html$Attributes$id('gross-unit-price'),
|
||||
$elm$html$Html$Attributes$step('0.01')
|
||||
]),
|
||||
_List_Nil)
|
||||
])),
|
||||
$author$project$Entry$viewGrossUnitPriceInput(model)
|
||||
_List_Nil),
|
||||
$author$project$Entry$viewSetSuggestedPriceButton(model)
|
||||
]))
|
||||
]))
|
||||
]));
|
||||
}
|
||||
@ -12102,4 +12318,4 @@ _Platform_export({'Entry':{'init':$author$project$Entry$main(
|
||||
},
|
||||
A2($elm$json$Json$Decode$field, 'id', $elm$json$Json$Decode$int));
|
||||
},
|
||||
A2($elm$json$Json$Decode$field, 'percentage', $elm$json$Json$Decode$float))))))({"versions":{"elm":"0.19.1"},"types":{"message":"Entry.Msg","aliases":{"Entry.SearchResult":{"args":[],"type":"{ barcode : String.String, name : String.String, netUnitPrice : Basics.Float, bought : String.String, salesUnits : Basics.Int, available : Basics.Bool, locationName : String.String, locationId : Basics.Int, groupName : String.String, groupId : Basics.Int, taxGroupId : Basics.Int }"}},"unions":{"Entry.Msg":{"args":[],"tags":{"SetSearchTerm":["String.String"],"SubmitSearch":[],"ReceiveSearchResults":["Result.Result Http.Error (List.List Entry.SearchResult)"],"GotoItemEditor":["Entry.SearchResult"],"SetBarcode":["String.String"],"SetName":["String.String"],"SetSalesUnits":["String.String"],"SetNetUnitPrice":["String.String"],"SetGrossUnitPrice":["String.String"],"SetGroup":["String.String"],"SetLocation":["String.String"],"SetTaxGroup":["String.String"]}},"Basics.Bool":{"args":[],"tags":{"True":[],"False":[]}},"Http.Error":{"args":[],"tags":{"BadUrl":["String.String"],"Timeout":[],"NetworkError":[],"BadStatus":["Basics.Int"],"BadBody":["String.String"]}},"Basics.Float":{"args":[],"tags":{"Float":[]}},"Basics.Int":{"args":[],"tags":{"Int":[]}},"List.List":{"args":["a"],"tags":{}},"Result.Result":{"args":["error","value"],"tags":{"Ok":["value"],"Err":["error"]}},"String.String":{"args":[],"tags":{"String":[]}}}}})}});}(this));
|
||||
A2($elm$json$Json$Decode$field, 'percentage', $elm$json$Json$Decode$float))))))({"versions":{"elm":"0.19.1"},"types":{"message":"Entry.Msg","aliases":{"Entry.SearchResult":{"args":[],"type":"{ barcode : String.String, name : String.String, netUnitPrice : Basics.Float, bought : String.String, salesUnits : Basics.Int, available : Basics.Bool, locationName : String.String, locationId : Basics.Int, groupName : String.String, groupId : Basics.Int, taxGroupId : Basics.Int }"}},"unions":{"Entry.Msg":{"args":[],"tags":{"SetSearchTerm":["String.String"],"SubmitSearch":[],"ReceiveSearchResults":["Result.Result Http.Error (List.List Entry.SearchResult)"],"GotoItemEditor":["Entry.SearchResult"],"SetBarcode":["String.String"],"SetName":["String.String"],"SetSalesUnits":["String.String"],"CalculatorMsg":["Calculator.Msg"],"SetNetUnitPrice":["String.String"],"SetGrossUnitPrice":["String.String"],"SetGroup":["String.String"],"SetLocation":["String.String"],"SetTaxGroup":["String.String"]}},"Basics.Bool":{"args":[],"tags":{"True":[],"False":[]}},"Http.Error":{"args":[],"tags":{"BadUrl":["String.String"],"Timeout":[],"NetworkError":[],"BadStatus":["Basics.Int"],"BadBody":["String.String"]}},"Basics.Float":{"args":[],"tags":{"Float":[]}},"Basics.Int":{"args":[],"tags":{"Int":[]}},"List.List":{"args":["a"],"tags":{}},"Calculator.Msg":{"args":[],"tags":{"SetTax":["String.String"],"SetBundlePrice":["String.String"],"SetBundleSize":["String.String"]}},"Result.Result":{"args":["error","value"],"tags":{"Ok":["value"],"Err":["error"]}},"String.String":{"args":[],"tags":{"String":[]}}}}})}});}(this));
|
@ -63,3 +63,6 @@ th {
|
||||
.form-input > select {
|
||||
display: block;
|
||||
}
|
||||
.formula-input {
|
||||
width: 10em;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user