added volume info

This commit is contained in:
nek0 2015-04-24 12:28:45 +02:00
parent 28e2ac1a3f
commit f62f76a52b
11 changed files with 31 additions and 3 deletions

View file

@ -110,3 +110,6 @@ sendMail to subject body =
, partContent = E.encodeUtf8 body , partContent = E.encodeUtf8 body
}]] }]]
} }
formatIntVolume :: Int -> Text
formatIntVolume x = formatFloat $ ((fromIntegral x) / 1000)

View file

@ -28,6 +28,7 @@ postModifyR bId = do
, BeveragePrice =. beveragePrice nBev , BeveragePrice =. beveragePrice nBev
, BeverageAmount =. beverageAmount nBev , BeverageAmount =. beverageAmount nBev
, BeverageAlertAmount =. beverageAlertAmount nBev , BeverageAlertAmount =. beverageAlertAmount nBev
, BeverageMl =. beverageMl nBev
, BeverageAvatar =. beverageAvatar nBev , BeverageAvatar =. beverageAvatar nBev
] ]
setMessageI MsgEditSuccess setMessageI MsgEditSuccess
@ -45,6 +46,7 @@ modifyForm bev = renderDivs $ Beverage
<*> areq currencyField (fieldSettingsLabel MsgPrice) (Just $ beveragePrice bev) <*> areq currencyField (fieldSettingsLabel MsgPrice) (Just $ beveragePrice bev)
<*> areq amountField (fieldSettingsLabel MsgCurrentStock) (Just $ beverageAmount bev) <*> areq amountField (fieldSettingsLabel MsgCurrentStock) (Just $ beverageAmount bev)
<*> areq amountField (fieldSettingsLabel MsgAnnouncedStock) (Just $ beverageAlertAmount bev) <*> areq amountField (fieldSettingsLabel MsgAnnouncedStock) (Just $ beverageAlertAmount bev)
<*> areq currencyField (fieldSettingsLabel MsgVolume) (Just $ beverageMl bev)
<*> aopt (selectField avatars) (fieldSettingsLabel MsgSelectAvatar) (Just $ beverageAvatar bev) <*> aopt (selectField avatars) (fieldSettingsLabel MsgSelectAvatar) (Just $ beverageAvatar bev)
where where
avatars = do avatars = do

View file

@ -72,6 +72,7 @@ newArticleForm = renderDivs $ Beverage
<*> areq currencyField (fieldSettingsLabel MsgPrice) (Just 100) <*> areq currencyField (fieldSettingsLabel MsgPrice) (Just 100)
<*> areq amountField (fieldSettingsLabel MsgAmount) (Just 0) <*> areq amountField (fieldSettingsLabel MsgAmount) (Just 0)
<*> areq amountField (fieldSettingsLabel MsgAmountWarning) (Just 0) <*> areq amountField (fieldSettingsLabel MsgAmountWarning) (Just 0)
<*> areq currencyField (fieldSettingsLabel MsgVolume) (Just 500)
<*> aopt (selectField avatars) (fieldSettingsLabel MsgSelectAvatar) Nothing <*> aopt (selectField avatars) (fieldSettingsLabel MsgSelectAvatar) Nothing
where where
avatars = do avatars = do

View file

@ -4,6 +4,7 @@ import Import as I
import qualified Data.List as L import qualified Data.List as L
import Data.Aeson import Data.Aeson
import Data.Conduit.Binary import Data.Conduit.Binary
import Handler.Common
getSummaryR :: Handler Html getSummaryR :: Handler Html
getSummaryR = do getSummaryR = do
@ -21,6 +22,7 @@ getSummaryJsonR = do
map (\(Entity _ bev) -> map (\(Entity _ bev) ->
object [ "name" .= beverageIdent bev object [ "name" .= beverageIdent bev
, "value" .= beverageAmount bev , "value" .= beverageAmount bev
, "volume" .= ((fromIntegral (beverageMl bev)) / 1000 :: Double)
, "price" .= ((fromIntegral (beveragePrice bev)) / 100 :: Double) , "price" .= ((fromIntegral (beveragePrice bev)) / 100 :: Double)
, "currency" .= appCurrency (appSettings master) , "currency" .= appCurrency (appSettings master)
] ]
@ -31,15 +33,17 @@ data BevStore = BevStore
, bevStorePrice :: Int , bevStorePrice :: Int
, bevStoreAmount :: Int , bevStoreAmount :: Int
, bevStoreAlertAmount :: Int , bevStoreAlertAmount :: Int
, bevStoreMl :: Int
} }
instance ToJSON BevStore where instance ToJSON BevStore where
toJSON (BevStore ident price amount alertAmount) = toJSON (BevStore ident price amount alertAmount ml) =
object object
[ "name" .= ident [ "name" .= ident
, "price" .= price , "price" .= price
, "amount" .= amount , "amount" .= amount
, "alertAt" .= alertAmount , "alertAt" .= alertAmount
, "ml" .= ml
] ]
instance FromJSON BevStore where instance FromJSON BevStore where
@ -48,6 +52,7 @@ instance FromJSON BevStore where
<*> o .: "price" <*> o .: "price"
<*> o .: "amount" <*> o .: "amount"
<*> o .: "alertAt" <*> o .: "alertAt"
<*> o .: "ml"
-- For errors -- For errors
parseJSON _ = mzero parseJSON _ = mzero
@ -61,6 +66,7 @@ getInventoryJsonR = do
(beveragePrice bev) (beveragePrice bev)
(beverageAmount bev) (beverageAmount bev)
(beverageAlertAmount bev) (beverageAlertAmount bev)
(beverageMl bev)
) bevs ) bevs
getUploadInventoryJsonR :: Handler Html getUploadInventoryJsonR :: Handler Html
@ -101,6 +107,7 @@ insOrUpd bev = do
[ BeveragePrice =. bevStorePrice bev [ BeveragePrice =. bevStorePrice bev
, BeverageAmount =. bevStoreAmount bev , BeverageAmount =. bevStoreAmount bev
, BeverageAlertAmount =. bevStoreAlertAmount bev , BeverageAlertAmount =. bevStoreAlertAmount bev
, BeverageMl =. bevStoreMl bev
] ]
Nothing -> do Nothing -> do
runDB $ insert_ $ Beverage runDB $ insert_ $ Beverage
@ -108,4 +115,5 @@ insOrUpd bev = do
(bevStorePrice bev) (bevStorePrice bev)
(bevStoreAmount bev) (bevStoreAmount bev)
(bevStoreAlertAmount bev) (bevStoreAlertAmount bev)
(bevStoreMl bev)
Nothing Nothing

View file

@ -11,6 +11,7 @@ Beverage
price Int price Int
amount Int amount Int
alertAmount Int alertAmount Int
ml Int default=500
avatar AvatarId Maybe avatar AvatarId Maybe
UniqueBeverage ident UniqueBeverage ident
deriving Typeable Show deriving Typeable Show

View file

@ -99,3 +99,4 @@ AvatarUploadSuccessfull: Avatar úspěšně nahrán
DeleteAvatar: Smazat avatar DeleteAvatar: Smazat avatar
AvatarDeleted: Avatar úspěšně smazán AvatarDeleted: Avatar úspěšně smazán
AvatarInUseError: Avatar nelze smazat dokud je v užitku AvatarInUseError: Avatar nelze smazat dokud je v užitku
Volume: Objem v l

View file

@ -99,3 +99,4 @@ AvatarUploadSuccessfull: Avatar erfolgreich hochgeladen
DeleteAvatar: Diesen Avatar löschen DeleteAvatar: Diesen Avatar löschen
AvatarDeleted: Avatar gelöscht AvatarDeleted: Avatar gelöscht
AvatarInUseError: Avatare können nicht gelöscht werden, solange sie in Benutzung sind. AvatarInUseError: Avatare können nicht gelöscht werden, solange sie in Benutzung sind.
Volume: Volumen in l

View file

@ -99,3 +99,4 @@ AvatarUploadSuccessfull: Avatar upload successfull
DeleteAvatar: Delete avatar DeleteAvatar: Delete avatar
AvatarDeleted: Avatar successfully deleted AvatarDeleted: Avatar successfully deleted
AvatarInUseError: You can not delete avatars that are currently in use AvatarInUseError: You can not delete avatars that are currently in use
Volume: Volume in l

View file

@ -3,7 +3,11 @@ $doctype 5
<h3>_{MsgPurchaseOf $ beverageIdent bev} <h3>_{MsgPurchaseOf $ beverageIdent bev}
<p> <p>
_{MsgPricePerUnit (beveragePrice bev) (appCurrency $ appSettings master)} <ul>
<li>
_{MsgPricePerUnit (beveragePrice bev) (appCurrency $ appSettings master)}
<li>
_{MsgVolume}: #{formatIntVolume (beverageMl bev)}
<form method=post enctype=#{enctype}> <form method=post enctype=#{enctype}>
^{buyWidget} ^{buyWidget}

View file

@ -3,7 +3,11 @@ $doctype 5
<h3>_{MsgPurchaseOf $ beverageIdent bev} <h3>_{MsgPurchaseOf $ beverageIdent bev}
<p> <p>
_{MsgPricePerUnit (beveragePrice bev + 50) (appCurrency $ appSettings master)} <ul>
<li>
_{MsgPricePerUnit (beveragePrice bev + 50) (appCurrency $ appSettings master)}
<li>
_{MsgVolume}: #{formatIntVolume (beverageMl bev)}
<form method=post enctype=#{enctype}> <form method=post enctype=#{enctype}>
^{buyCashWidget} ^{buyCashWidget}

View file

@ -7,6 +7,7 @@ $if not $ L.null bevs
<thead> <thead>
<tr> <tr>
<th>_{MsgName} <th>_{MsgName}
<th>_{MsgVolume}
<th>_{MsgCurrentAmount} <th>_{MsgCurrentAmount}
<th>_{MsgAnnouncedStock} <th>_{MsgAnnouncedStock}
<th>_{MsgValueIn $ appCurrency $ appSettings master} <th>_{MsgValueIn $ appCurrency $ appSettings master}
@ -14,6 +15,7 @@ $if not $ L.null bevs
$forall (Entity bId bev) <- bevs $forall (Entity bId bev) <- bevs
<tr> <tr>
<td>#{beverageIdent bev} <td>#{beverageIdent bev}
<td>#{formatIntVolume (beverageMl bev)}
<td>#{beverageAmount bev} <td>#{beverageAmount bev}
<td>#{beverageAlertAmount bev} <td>#{beverageAlertAmount bev}
<td>#{formatIntCurrency (beveragePrice bev)} #{appCurrency $ appSettings master} <td>#{formatIntCurrency (beveragePrice bev)} #{appCurrency $ appSettings master}