From 5d67e874ef8b2d83936a12dc1be19b880ee02e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 4 Feb 2017 02:05:57 +0100 Subject: [PATCH 1/4] add total bought counter --- Handler/Buy.hs | 1 + Handler/Restock.hs | 1 + Handler/Summary.hs | 8 +++++++- config/models | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Handler/Buy.hs b/Handler/Buy.hs index 240af83..4463119 100644 --- a/Handler/Buy.hs +++ b/Handler/Buy.hs @@ -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 diff --git a/Handler/Restock.hs b/Handler/Restock.hs index 1f067dc..b2a63c0 100644 --- a/Handler/Restock.hs +++ b/Handler/Restock.hs @@ -91,6 +91,7 @@ postNewArticleR = do (modBevAvatar nBev) (modBevSupp nBev) (modBevMaxAmount nBev) + 0 (modBevPC nBev) (modBevArtNr nBev) (modBevPricePC nBev) diff --git a/Handler/Summary.hs b/Handler/Summary.hs index 38af868..eba3789 100644 --- a/Handler/Summary.hs +++ b/Handler/Summary.hs @@ -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 diff --git a/config/models b/config/models index c70e1c0..3655cb0 100644 --- a/config/models +++ b/config/models @@ -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 From 93144d103e779cb63eb1c8778db189e189d109f0 Mon Sep 17 00:00:00 2001 From: rys ostrovid Date: Sat, 4 Feb 2017 18:53:06 +0100 Subject: [PATCH 2/4] Update Summary.hs use snake case for conformity --- Handler/Summary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Handler/Summary.hs b/Handler/Summary.hs index eba3789..f70684e 100644 --- a/Handler/Summary.hs +++ b/Handler/Summary.hs @@ -80,7 +80,7 @@ instance FromJSON BevStore where <*> o .: "amount" <*> o .: "lost_amount" <*> o .: "max" - <*> o .: "totalBought" + <*> o .: "total_bought" <*> o .:? "perCrate" <*> o .: "alertAt" <*> o .: "ml" From 12c9ccad69062a00305c3e5bafd9d8e7cb964c0d Mon Sep 17 00:00:00 2001 From: rys ostrovid Date: Sat, 4 Feb 2017 18:53:59 +0100 Subject: [PATCH 3/4] Update Summary.hs snake case for conformity --- Handler/Summary.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Handler/Summary.hs b/Handler/Summary.hs index f70684e..d05522b 100644 --- a/Handler/Summary.hs +++ b/Handler/Summary.hs @@ -66,7 +66,7 @@ instance ToJSON BevStore where , "lost_amount" .= loss , "alertAt" .= alertAmount , "max" .= maxAmount - , "totalBought" .= totalBought + , "total_bought" .= totalBought , "perCrate" .= perCrate , "ml" .= ml , "artNr" .= artNr From e60e58e1458b428bebaec8dbc1ca0e5b1dcd3c0e Mon Sep 17 00:00:00 2001 From: rys ostrovid Date: Sat, 4 Feb 2017 18:59:28 +0100 Subject: [PATCH 4/4] Update yammat.cabal bump version --- yammat.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yammat.cabal b/yammat.cabal index b47e349..ec7ce69 100644 --- a/yammat.cabal +++ b/yammat.cabal @@ -1,5 +1,5 @@ name: yammat -version: 0.0.5 +version: 0.0.6 cabal-version: >= 1.8 build-type: Simple license: AGPL-3