diff --git a/Handler/Common.hs b/Handler/Common.hs index 91fb2f8..0d653a2 100644 --- a/Handler/Common.hs +++ b/Handler/Common.hs @@ -8,6 +8,7 @@ import qualified Data.Text.Read as R import Yesod.Form.Functions import Text.Shakespeare.Text import Network.Mail.Mime +import Text.Printf import Import -- These handlers embed files in the executable at compile time to avoid a @@ -120,3 +121,9 @@ prependZero t0 = if T.null t1 else t1 where t1 = T.dropWhile ((==) ' ') t0 + +formatFloat :: Double -> Text +formatFloat = T.pack . (printf "%.2f") + +formatIntCurrency :: Int -> Text +formatIntCurrency x = formatFloat $ ((fromIntegral x) / 100) diff --git a/Handler/Summary.hs b/Handler/Summary.hs index 8ddee2b..2a08b9a 100644 --- a/Handler/Summary.hs +++ b/Handler/Summary.hs @@ -2,6 +2,7 @@ module Handler.Summary where import Import import Data.List as L +import Handler.Common getSummaryR :: Handler Html getSummaryR = do diff --git a/templates/buy.hamlet b/templates/buy.hamlet index 288a787..0f3e570 100644 --- a/templates/buy.hamlet +++ b/templates/buy.hamlet @@ -3,7 +3,7 @@ $doctype 5

Kauf von #{beverageIdent bev}

- Preis pro Einheit: #{show ((fromIntegral (beveragePrice bev)) / 100)} #{appCurrency $ appSettings master} + Preis pro Einheit: #{formatIntCurrency (beveragePrice bev)} #{appCurrency $ appSettings master}

^{buyWidget} diff --git a/templates/buyCash.hamlet b/templates/buyCash.hamlet index d42e5a7..dff8077 100644 --- a/templates/buyCash.hamlet +++ b/templates/buyCash.hamlet @@ -3,7 +3,7 @@ $doctype 5

Kauf von #{beverageIdent bev}

- Preis pro Einheit: #{show ((fromIntegral (beveragePrice bev + 50)) / 100)} #{appCurrency $ appSettings master} + Preis pro Einheit: #{formatIntCurrency (beveragePrice bev + 50)} #{appCurrency $ appSettings master} ^{buyCashWidget} diff --git a/templates/journal.hamlet b/templates/journal.hamlet index 8b74aa6..978a756 100644 --- a/templates/journal.hamlet +++ b/templates/journal.hamlet @@ -13,13 +13,13 @@ $if not $ L.null entries #{formatTime defaultTimeLocale "%A %F %H:%M" $ transactionTime entry} #{transactionDescription entry} - #{show ((fromIntegral (transactionAmount entry)) / 100)} #{appCurrency $ appSettings master} + #{formatIntCurrency (transactionAmount entry)} #{appCurrency $ appSettings master} Gesamtbetrag: - #{show ((fromIntegral total) / 100)} #{appCurrency $ appSettings master} + #{formatIntCurrency (fromIntegral total)} #{appCurrency $ appSettings master}

- Kassenbestand: #{show ((fromIntegral cashBalance) / 100)} #{appCurrency $ appSettings master} + Kassenbestand: #{formatIntCurrency (fromIntegral cashBalance)} #{appCurrency $ appSettings master}

diff --git a/templates/recharge.hamlet b/templates/recharge.hamlet index 39fd06e..bd7f94f 100644 --- a/templates/recharge.hamlet +++ b/templates/recharge.hamlet @@ -4,7 +4,7 @@ $doctype 5 Guthaben aufladen

- aktuelles Guthaben: #{show ((fromIntegral $ userBalance user) / 100)} + aktuelles Guthaben: #{formatIntCurrency (userBalance user)} ^{rechargeWidget} diff --git a/templates/select.hamlet b/templates/select.hamlet index 1c35b2e..22ad89c 100644 --- a/templates/select.hamlet +++ b/templates/select.hamlet @@ -3,7 +3,7 @@ $doctype 5