aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Income/Model.elm
diff options
context:
space:
mode:
authorJoris2016-04-05 13:39:48 +0200
committerJoris2016-04-05 13:39:48 +0200
commitedca79a7e2bfed1a08de780cc6ab7eac430ef950 (patch)
tree02f794910924f1ca0114d08a254deed98388c70f /src/client/elm/LoggedIn/Income/Model.elm
parentd19b69eeeb0c24ee7e4a75b0da32eefba1d43928 (diff)
downloadbudget-edca79a7e2bfed1a08de780cc6ab7eac430ef950.tar.gz
budget-edca79a7e2bfed1a08de780cc6ab7eac430ef950.tar.bz2
budget-edca79a7e2bfed1a08de780cc6ab7eac430ef950.zip
Add a statistics empty page
Diffstat (limited to 'src/client/elm/LoggedIn/Income/Model.elm')
-rw-r--r--src/client/elm/LoggedIn/Income/Model.elm46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/client/elm/LoggedIn/Income/Model.elm b/src/client/elm/LoggedIn/Income/Model.elm
new file mode 100644
index 0000000..fdfb964
--- /dev/null
+++ b/src/client/elm/LoggedIn/Income/Model.elm
@@ -0,0 +1,46 @@
+module LoggedIn.Income.Model
+ ( Model
+ , AddIncome
+ , init
+ ) where
+
+import String exposing (toInt, split)
+import Date exposing (Date)
+import Date.Utils exposing (dateFromFields)
+import Utils.Date exposing (numToMonth)
+
+import Form exposing (Form)
+import Form.Validate as Validate exposing (..)
+import Form.Error exposing (Error(InvalidString))
+
+type alias Model =
+ { addIncome : Form () AddIncome
+ }
+
+type alias AddIncome =
+ { creation : Date
+ , amount : Int
+ }
+
+init : Model
+init =
+ { addIncome = Form.initial [] validate
+ }
+
+validate : Validation () AddIncome
+validate =
+ form2 AddIncome
+ (get "creation" dateValidation)
+ (get "amount" (int `andThen` (minInt 1)))
+
+dateValidation : Validation () Date
+dateValidation =
+ customValidation string (\str ->
+ case split "/" str of
+ [day, month, year] ->
+ case (toInt day, toInt month, toInt year) of
+ (Ok dayNum, Ok monthNum, Ok yearNum) ->
+ Ok (dateFromFields yearNum (numToMonth monthNum) dayNum 0 0 0 0)
+ _ -> Err InvalidString
+ _ -> Err InvalidString
+ )