Rewrite some of the grossUnitPrice stuff
This commit is contained in:
parent
4715a758a3
commit
f15a20589b
@ -135,11 +135,11 @@ updateState msg globals state = case state of
|
|||||||
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
|
||||||
, netUnitPrice = NumberInput.fromFloat searchResult.netUnitPrice
|
, netUnitPrice = NumberInput.fromFloat searchResult.netUnitPrice
|
||||||
, grossUnitPrice = NumberInput.fromFloat <| calculateGarfieldPrice searchResult.netUnitPrice taxGroup.percentage
|
, grossUnitPrice = NumberInput.fromFloat 0
|
||||||
, 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
|
||||||
@ -175,7 +175,7 @@ updateState msg globals state = case state of
|
|||||||
|
|
||||||
updateGrossUnitPrice model =
|
updateGrossUnitPrice model =
|
||||||
{ model
|
{ model
|
||||||
| grossUnitPrice = NumberInput.fromFloat <| calculateGarfieldPrice (NumberInput.get model.netUnitPrice) (Select.get model.taxGroup).percentage
|
| grossUnitPrice = Maybe.withDefault model.grossUnitPrice <| Maybe.map NumberInput.fromFloat <| calculateGarfieldPrice model
|
||||||
}
|
}
|
||||||
|
|
||||||
-- View stuff
|
-- View stuff
|
||||||
@ -238,15 +238,23 @@ view { globals, state } = case state of
|
|||||||
[ label [ for "snack-name" ] [ text "Name" ]
|
[ label [ for "snack-name" ] [ text "Name" ]
|
||||||
, input [ value model.name, disabled True, id "snack-name" ] []
|
, input [ value model.name, disabled True, id "snack-name" ] []
|
||||||
]
|
]
|
||||||
, div [ class "form-input" ]
|
, viewGrossUnitPriceInput model
|
||||||
[ label [ for "gross-unit-price" ]
|
|
||||||
[ text <| "Stückpreis (Brutto), Vorschlag: " ++ String.fromFloat (calculateGarfieldPrice (NumberInput.get model.netUnitPrice) (Select.get model.taxGroup).percentage)
|
|
||||||
]
|
|
||||||
, input [ onInput SetGrossUnitPrice, value <| NumberInput.show model.grossUnitPrice, id "gross-unit-price", type_ "number", step "0.01" ] []
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
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" ] []
|
||||||
|
]
|
||||||
|
|
||||||
searchResultHeaders =
|
searchResultHeaders =
|
||||||
tr []
|
tr []
|
||||||
[ th [] [ text "Barcode" ]
|
[ th [] [ text "Barcode" ]
|
||||||
@ -275,8 +283,10 @@ viewSearchResult model =
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
calculateGarfieldPrice netUnitPrice taxPercentage =
|
calculateGarfieldPrice model =
|
||||||
roundTo 2 <| netUnitPrice * (1 + taxPercentage) + 0.01
|
NumberInput.get model.netUnitPrice |> Maybe.map (\netUnitPrice ->
|
||||||
|
roundTo 2 <| netUnitPrice * (1 + (Select.get model.taxGroup).percentage) + 0.01
|
||||||
|
)
|
||||||
|
|
||||||
roundTo places x = toFloat (round <| x * 10 ^ places) / 10 ^ places
|
roundTo places x = toFloat (round <| x * 10 ^ places) / 10 ^ places
|
||||||
|
|
||||||
|
@ -1,25 +1,29 @@
|
|||||||
module NumberInput exposing (..)
|
module NumberInput exposing (..)
|
||||||
|
|
||||||
type alias Model a =
|
type alias Model a =
|
||||||
{ value : a
|
{ value : Maybe a
|
||||||
, original : String
|
, original : String
|
||||||
, convert : String -> Maybe a
|
, convert : String -> Maybe a
|
||||||
}
|
}
|
||||||
|
|
||||||
fromFloat : Float -> Model Float
|
fromFloat : Float -> Model Float
|
||||||
fromFloat x = Model x (String.fromFloat x) String.toFloat
|
fromFloat x = Model (Just x) (String.fromFloat x) String.toFloat
|
||||||
|
|
||||||
fromInt : Int -> Model Int
|
fromInt : Int -> Model Int
|
||||||
fromInt x = Model x (String.fromInt x) String.toInt
|
fromInt x = Model (Just x) (String.fromInt x) String.toInt
|
||||||
|
|
||||||
get : Model a -> a
|
get : Model a -> Maybe a
|
||||||
get = .value
|
get = .value
|
||||||
|
|
||||||
|
withDefault : a -> Model a -> a
|
||||||
|
withDefault d = Maybe.withDefault d << get
|
||||||
|
|
||||||
|
isValid : Model a -> Bool
|
||||||
|
isValid model = model.value /= Nothing
|
||||||
|
|
||||||
update : String -> Model a -> Model a
|
update : String -> Model a -> Model a
|
||||||
update str model =
|
update str model =
|
||||||
case model.convert str of
|
{ model | value = model.convert str, original = str }
|
||||||
Nothing -> model
|
|
||||||
Just value -> { model | value = value, original = str }
|
|
||||||
|
|
||||||
show : Model a -> String
|
show : Model a -> String
|
||||||
show = .original
|
show = .original
|
||||||
|
@ -10745,17 +10745,6 @@ var $author$project$Entry$ItemEditor = function (a) {
|
|||||||
var $author$project$Entry$ReceiveSearchResults = function (a) {
|
var $author$project$Entry$ReceiveSearchResults = function (a) {
|
||||||
return {$: 'ReceiveSearchResults', a: a};
|
return {$: 'ReceiveSearchResults', a: a};
|
||||||
};
|
};
|
||||||
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 = F2(
|
|
||||||
function (netUnitPrice, taxPercentage) {
|
|
||||||
return A2($author$project$Entry$roundTo, 2, (netUnitPrice * (1 + taxPercentage)) + 0.01);
|
|
||||||
});
|
|
||||||
var $elm$http$Http$BadStatus_ = F2(
|
var $elm$http$Http$BadStatus_ = F2(
|
||||||
function (a, b) {
|
function (a, b) {
|
||||||
return {$: 'BadStatus_', a: a, b: b};
|
return {$: 'BadStatus_', a: a, b: b};
|
||||||
@ -10882,14 +10871,14 @@ var $elm$core$String$toFloat = _String_toFloat;
|
|||||||
var $author$project$NumberInput$fromFloat = function (x) {
|
var $author$project$NumberInput$fromFloat = function (x) {
|
||||||
return A3(
|
return A3(
|
||||||
$author$project$NumberInput$Model,
|
$author$project$NumberInput$Model,
|
||||||
x,
|
$elm$core$Maybe$Just(x),
|
||||||
$elm$core$String$fromFloat(x),
|
$elm$core$String$fromFloat(x),
|
||||||
$elm$core$String$toFloat);
|
$elm$core$String$toFloat);
|
||||||
};
|
};
|
||||||
var $author$project$NumberInput$fromInt = function (x) {
|
var $author$project$NumberInput$fromInt = function (x) {
|
||||||
return A3(
|
return A3(
|
||||||
$author$project$NumberInput$Model,
|
$author$project$NumberInput$Model,
|
||||||
x,
|
$elm$core$Maybe$Just(x),
|
||||||
$elm$core$String$fromInt(x),
|
$elm$core$String$fromInt(x),
|
||||||
$elm$core$String$toInt);
|
$elm$core$String$toInt);
|
||||||
};
|
};
|
||||||
@ -11132,15 +11121,12 @@ var $author$project$Entry$searchResultDecoder = A3(
|
|||||||
$elm$json$Json$Decode$succeed($author$project$Entry$SearchResult))))))))))));
|
$elm$json$Json$Decode$succeed($author$project$Entry$SearchResult))))))))))));
|
||||||
var $author$project$NumberInput$update = F2(
|
var $author$project$NumberInput$update = F2(
|
||||||
function (str, model) {
|
function (str, model) {
|
||||||
var _v0 = model.convert(str);
|
return _Utils_update(
|
||||||
if (_v0.$ === 'Nothing') {
|
model,
|
||||||
return model;
|
{
|
||||||
} else {
|
original: str,
|
||||||
var value = _v0.a;
|
value: model.convert(str)
|
||||||
return _Utils_update(
|
});
|
||||||
model,
|
|
||||||
{original: str, value: value});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
var $author$project$Select$find = F2(
|
var $author$project$Select$find = F2(
|
||||||
function (pred, xs) {
|
function (pred, xs) {
|
||||||
@ -11172,15 +11158,45 @@ var $author$project$NumberInput$get = function ($) {
|
|||||||
var $author$project$Select$get = function ($) {
|
var $author$project$Select$get = function ($) {
|
||||||
return $.selected;
|
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 $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) {
|
var $author$project$Entry$updateGrossUnitPrice = function (model) {
|
||||||
return _Utils_update(
|
return _Utils_update(
|
||||||
model,
|
model,
|
||||||
{
|
{
|
||||||
grossUnitPrice: $author$project$NumberInput$fromFloat(
|
grossUnitPrice: A2(
|
||||||
|
$elm$core$Maybe$withDefault,
|
||||||
|
model.grossUnitPrice,
|
||||||
A2(
|
A2(
|
||||||
$author$project$Entry$calculateGarfieldPrice,
|
$elm$core$Maybe$map,
|
||||||
$author$project$NumberInput$get(model.netUnitPrice),
|
$author$project$NumberInput$fromFloat,
|
||||||
$author$project$Select$get(model.taxGroup).percentage))
|
$author$project$Entry$calculateGarfieldPrice(model)))
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var $author$project$Entry$updateState = F3(
|
var $author$project$Entry$updateState = F3(
|
||||||
@ -11235,53 +11251,53 @@ var $author$project$Entry$updateState = F3(
|
|||||||
var taxGroup = _v2.a;
|
var taxGroup = _v2.a;
|
||||||
return _Utils_Tuple2(
|
return _Utils_Tuple2(
|
||||||
$author$project$Entry$ItemEditor(
|
$author$project$Entry$ItemEditor(
|
||||||
{
|
$author$project$Entry$updateGrossUnitPrice(
|
||||||
barcode: searchResult.barcode,
|
{
|
||||||
grossUnitPrice: $author$project$NumberInput$fromFloat(
|
barcode: searchResult.barcode,
|
||||||
A2($author$project$Entry$calculateGarfieldPrice, searchResult.netUnitPrice, taxGroup.percentage)),
|
grossUnitPrice: $author$project$NumberInput$fromFloat(0),
|
||||||
group: A4(
|
group: A4(
|
||||||
$author$project$Select$init,
|
$author$project$Select$init,
|
||||||
A2(
|
A2(
|
||||||
$elm$core$Basics$composeR,
|
$elm$core$Basics$composeR,
|
||||||
|
function ($) {
|
||||||
|
return $.id;
|
||||||
|
},
|
||||||
|
$elm$core$String$fromInt),
|
||||||
function ($) {
|
function ($) {
|
||||||
return $.id;
|
return $.name;
|
||||||
},
|
},
|
||||||
$elm$core$String$fromInt),
|
{id: searchResult.groupId, name: searchResult.groupName},
|
||||||
function ($) {
|
globals.groups),
|
||||||
return $.name;
|
location: A4(
|
||||||
},
|
$author$project$Select$init,
|
||||||
{id: searchResult.groupId, name: searchResult.groupName},
|
A2(
|
||||||
globals.groups),
|
$elm$core$Basics$composeR,
|
||||||
location: A4(
|
function ($) {
|
||||||
$author$project$Select$init,
|
return $.id;
|
||||||
A2(
|
},
|
||||||
$elm$core$Basics$composeR,
|
$elm$core$String$fromInt),
|
||||||
function ($) {
|
function ($) {
|
||||||
return $.id;
|
return $.name;
|
||||||
},
|
},
|
||||||
$elm$core$String$fromInt),
|
{id: searchResult.locationId, name: searchResult.locationName},
|
||||||
function ($) {
|
globals.locations),
|
||||||
return $.name;
|
name: searchResult.name,
|
||||||
},
|
netUnitPrice: $author$project$NumberInput$fromFloat(searchResult.netUnitPrice),
|
||||||
{id: searchResult.locationId, name: searchResult.locationName},
|
salesUnits: $author$project$NumberInput$fromInt(searchResult.salesUnits),
|
||||||
globals.locations),
|
taxGroup: A4(
|
||||||
name: searchResult.name,
|
$author$project$Select$init,
|
||||||
netUnitPrice: $author$project$NumberInput$fromFloat(searchResult.netUnitPrice),
|
A2(
|
||||||
salesUnits: $author$project$NumberInput$fromInt(searchResult.salesUnits),
|
$elm$core$Basics$composeR,
|
||||||
taxGroup: A4(
|
function ($) {
|
||||||
$author$project$Select$init,
|
return $.id;
|
||||||
A2(
|
},
|
||||||
$elm$core$Basics$composeR,
|
$elm$core$String$fromInt),
|
||||||
function ($) {
|
function ($) {
|
||||||
return $.id;
|
return $.description;
|
||||||
},
|
},
|
||||||
$elm$core$String$fromInt),
|
taxGroup,
|
||||||
function ($) {
|
globals.taxGroups)
|
||||||
return $.description;
|
})),
|
||||||
},
|
|
||||||
taxGroup,
|
|
||||||
globals.taxGroups)
|
|
||||||
}),
|
|
||||||
$elm$core$Platform$Cmd$none);
|
$elm$core$Platform$Cmd$none);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -11389,9 +11405,6 @@ var $author$project$Entry$update = F2(
|
|||||||
var $author$project$Entry$SetBarcode = function (a) {
|
var $author$project$Entry$SetBarcode = function (a) {
|
||||||
return {$: 'SetBarcode', a: a};
|
return {$: 'SetBarcode', a: a};
|
||||||
};
|
};
|
||||||
var $author$project$Entry$SetGrossUnitPrice = function (a) {
|
|
||||||
return {$: 'SetGrossUnitPrice', a: a};
|
|
||||||
};
|
|
||||||
var $author$project$Entry$SetGroup = function (a) {
|
var $author$project$Entry$SetGroup = function (a) {
|
||||||
return {$: 'SetGroup', a: a};
|
return {$: 'SetGroup', a: a};
|
||||||
};
|
};
|
||||||
@ -11553,6 +11566,51 @@ var $author$project$Select$view = F2(
|
|||||||
]),
|
]),
|
||||||
A2($elm$core$List$map, viewOption, model.options));
|
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(
|
||||||
|
[
|
||||||
|
$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)
|
||||||
|
])),
|
||||||
|
A2(
|
||||||
|
$elm$html$Html$input,
|
||||||
|
_List_fromArray(
|
||||||
|
[
|
||||||
|
$elm$html$Html$Events$onInput($author$project$Entry$SetGrossUnitPrice),
|
||||||
|
$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')
|
||||||
|
]),
|
||||||
|
_List_Nil)
|
||||||
|
]));
|
||||||
|
};
|
||||||
var $author$project$Entry$GotoItemEditor = function (a) {
|
var $author$project$Entry$GotoItemEditor = function (a) {
|
||||||
return {$: 'GotoItemEditor', a: a};
|
return {$: 'GotoItemEditor', a: a};
|
||||||
};
|
};
|
||||||
@ -11955,42 +12013,7 @@ var $author$project$Entry$view = function (_v0) {
|
|||||||
]),
|
]),
|
||||||
_List_Nil)
|
_List_Nil)
|
||||||
])),
|
])),
|
||||||
A2(
|
$author$project$Entry$viewGrossUnitPriceInput(model)
|
||||||
$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('gross-unit-price')
|
|
||||||
]),
|
|
||||||
_List_fromArray(
|
|
||||||
[
|
|
||||||
$elm$html$Html$text(
|
|
||||||
'Stückpreis (Brutto), Vorschlag: ' + $elm$core$String$fromFloat(
|
|
||||||
A2(
|
|
||||||
$author$project$Entry$calculateGarfieldPrice,
|
|
||||||
$author$project$NumberInput$get(model.netUnitPrice),
|
|
||||||
$author$project$Select$get(model.taxGroup).percentage)))
|
|
||||||
])),
|
|
||||||
A2(
|
|
||||||
$elm$html$Html$input,
|
|
||||||
_List_fromArray(
|
|
||||||
[
|
|
||||||
$elm$html$Html$Events$onInput($author$project$Entry$SetGrossUnitPrice),
|
|
||||||
$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')
|
|
||||||
]),
|
|
||||||
_List_Nil)
|
|
||||||
]))
|
|
||||||
]))
|
]))
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user