add total bought counter

This commit is contained in:
Jörg Thalheim 2017-02-04 02:05:57 +01:00
parent 13f2257d8c
commit 5d67e874ef
No known key found for this signature in database
GPG key ID: CA4106B8D7CC79FA
4 changed files with 10 additions and 1 deletions

View file

@ -49,6 +49,7 @@ postBuyR uId bId = do
update uId [UserTimestamp =. today]
update uId [UserBalance -=. price]
update bId [BeverageAmount -=. quant]
update bId [BeverageTotalBought +=. 1]
checkAlert bId
master <- getYesod
liftIO $ notifyUser user bev quant price master

View file

@ -91,6 +91,7 @@ postNewArticleR = do
(modBevAvatar nBev)
(modBevSupp nBev)
(modBevMaxAmount nBev)
0
(modBevPC nBev)
(modBevArtNr nBev)
(modBevPricePC nBev)

View file

@ -49,6 +49,7 @@ data BevStore = BevStore
, bevStoreAmount :: Int
, bevStoreLostAmount :: Int
, bevStoreMaxAmount :: Int
, bevStoreTotalBought :: Int
, bevStorePerCrate :: Maybe Int
, bevStoreAlertAmount :: Int
, bevStoreMl :: Int
@ -57,7 +58,7 @@ data BevStore = BevStore
}
instance ToJSON BevStore where
toJSON (BevStore ident price amount loss maxAmount perCrate alertAmount ml artNr ppc) =
toJSON (BevStore ident price amount loss maxAmount totalBought perCrate alertAmount ml artNr ppc) =
object
[ "name" .= ident
, "price" .= price
@ -65,6 +66,7 @@ instance ToJSON BevStore where
, "lost_amount" .= loss
, "alertAt" .= alertAmount
, "max" .= maxAmount
, "totalBought" .= totalBought
, "perCrate" .= perCrate
, "ml" .= ml
, "artNr" .= artNr
@ -78,6 +80,7 @@ instance FromJSON BevStore where
<*> o .: "amount"
<*> o .: "lost_amount"
<*> o .: "max"
<*> o .: "totalBought"
<*> o .:? "perCrate"
<*> o .: "alertAt"
<*> o .: "ml"
@ -97,6 +100,7 @@ getInventoryJsonR = do
(beverageAmount bev)
(beverageCorrectedAmount bev)
(beverageMaxAmount bev)
(beverageTotalBought bev)
(beveragePerCrate bev)
(beverageAlertAmount bev)
(beverageMl bev)
@ -147,6 +151,7 @@ insOrUpd bev = do
Nothing
Nothing
(bevStoreMaxAmount bev)
(bevStoreTotalBought bev)
(bevStorePerCrate bev)
(bevStoreArtNr bev)
(bevStorePricePerCrate bev)
@ -158,6 +163,7 @@ insOrUpd bev = do
, BeverageAlertAmount =. bevStoreAlertAmount bev
, BeverageMl =. bevStoreMl bev
, BeverageMaxAmount =. bevStoreMaxAmount bev
, BeverageTotalBought =. bevStoreTotalBought bev
, BeveragePerCrate =. bevStorePerCrate bev
, BeverageArtNr =. bevStoreArtNr bev
, BeveragePricePerCrate =. bevStorePricePerCrate bev

View file

@ -17,6 +17,7 @@ Beverage
avatar AvatarId Maybe
supplier SupplierId Maybe
maxAmount Int default=0
totalBought Int default=0
perCrate Int Maybe
artNr Text Maybe
pricePerCrate Int Maybe