aboutsummaryrefslogtreecommitdiff
path: root/server/src/Model
diff options
context:
space:
mode:
authorJoris2018-01-03 17:31:20 +0100
committerJoris2018-01-03 17:31:22 +0100
commita4acc2e84158fa822f88a1d0bdddb470708b5809 (patch)
tree3faeb0128a51b437501470bd38be62e6e871e9f3 /server/src/Model
parent49426740e8e0c59040f4f3721a658f225572582b (diff)
downloadbudget-a4acc2e84158fa822f88a1d0bdddb470708b5809.tar.gz
budget-a4acc2e84158fa822f88a1d0bdddb470708b5809.tar.bz2
budget-a4acc2e84158fa822f88a1d0bdddb470708b5809.zip
Modify weelky report and payment search interface
- Add payment balance in weekly report - Show a message and hide pages when the search results in no results - Go to page 1 when the search is updated / erased
Diffstat (limited to 'server/src/Model')
-rw-r--r--server/src/Model/Income.hs12
-rw-r--r--server/src/Model/Init.hs2
-rw-r--r--server/src/Model/Mail.hs8
-rw-r--r--server/src/Model/Payment.hs41
4 files changed, 22 insertions, 41 deletions
diff --git a/server/src/Model/Income.hs b/server/src/Model/Income.hs
index a6174bc..4938e50 100644
--- a/server/src/Model/Income.hs
+++ b/server/src/Model/Income.hs
@@ -5,12 +5,11 @@ module Model.Income
, create
, editOwn
, deleteOwn
- , modifiedDuring
) where
import Data.Maybe (listToMaybe)
import Data.Time.Calendar (Day)
-import Data.Time.Clock (UTCTime, getCurrentTime)
+import Data.Time.Clock (getCurrentTime)
import Database.SQLite.Simple (FromRow (fromRow), Only (Only))
import qualified Database.SQLite.Simple as SQLite
import Prelude hiding (id)
@@ -87,12 +86,3 @@ deleteOwn user incomeId =
Nothing ->
return False
)
-
-modifiedDuring :: UTCTime -> UTCTime -> Query [Income]
-modifiedDuring start end =
- Query (\conn ->
- SQLite.query
- conn
- "SELECT * FROM income WHERE (created_at >= ? AND created_at <= ?) OR (edited_at >= ? AND edited_at <= ?) OR (deleted_at >= ? AND deleted_at <= ?)"
- (start, end, start, end, start, end)
- )
diff --git a/server/src/Model/Init.hs b/server/src/Model/Init.hs
index be44c72..0a0ffc7 100644
--- a/server/src/Model/Init.hs
+++ b/server/src/Model/Init.hs
@@ -18,7 +18,7 @@ getInit user conf =
Init <$>
User.list <*>
(return . _user_id $ user) <*>
- Payment.list <*>
+ Payment.listActive <*>
Income.list <*>
Category.list <*>
PaymentCategory.list <*>
diff --git a/server/src/Model/Mail.hs b/server/src/Model/Mail.hs
index a19f9ae..780efcc 100644
--- a/server/src/Model/Mail.hs
+++ b/server/src/Model/Mail.hs
@@ -5,8 +5,8 @@ module Model.Mail
import Data.Text (Text)
data Mail = Mail
- { from :: Text
- , to :: [Text]
- , subject :: Text
- , plainBody :: Text
+ { from :: Text
+ , to :: [Text]
+ , subject :: Text
+ , body :: Text
} deriving (Eq, Show)
diff --git a/server/src/Model/Payment.hs b/server/src/Model/Payment.hs
index 33551e5..5b29409 100644
--- a/server/src/Model/Payment.hs
+++ b/server/src/Model/Payment.hs
@@ -3,19 +3,18 @@
module Model.Payment
( Payment(..)
, find
- , list
- , listMonthly
+ , listActive
+ , listPunctual
+ , listActiveMonthlyOrderedByName
, create
, createMany
, editOwn
, deleteOwn
- , modifiedDuring
) where
import Data.Maybe (listToMaybe)
import Data.Text (Text)
import qualified Data.Text as T
-import Data.Time (UTCTime)
import Data.Time.Calendar (Day)
import Data.Time.Clock (getCurrentTime)
import Database.SQLite.Simple (FromRow (fromRow), Only (Only),
@@ -66,14 +65,22 @@ find paymentId =
SQLite.query conn "SELECT * FROM payment WHERE id = ?" (Only paymentId)
)
-list :: Query [Payment]
-list =
+listActive :: Query [Payment]
+listActive =
Query (\conn ->
SQLite.query_ conn "SELECT * FROM payment WHERE deleted_at IS NULL"
)
-listMonthly :: Query [Payment]
-listMonthly =
+listPunctual :: Query [Payment]
+listPunctual =
+ Query (\conn ->
+ SQLite.query
+ conn
+ (SQLite.Query "SELECT * FROM payment WHERE frequency = ?")
+ (Only Punctual))
+
+listActiveMonthlyOrderedByName :: Query [Payment]
+listActiveMonthlyOrderedByName =
Query (\conn ->
SQLite.query
conn
@@ -83,8 +90,7 @@ listMonthly =
, "WHERE deleted_at IS NULL AND frequency = ?"
, "ORDER BY name DESC"
])
- (Only Monthly)
- )
+ (Only Monthly))
create :: UserId -> Text -> Int -> Day -> Frequency -> Query PaymentId
create userId paymentName paymentCost paymentDate paymentFrequency =
@@ -161,18 +167,3 @@ deleteOwn userId paymentId =
Nothing ->
return False
)
-
-modifiedDuring :: UTCTime -> UTCTime -> Query [Payment]
-modifiedDuring start end =
- Query (\conn ->
- SQLite.query
- conn
- (SQLite.Query $ T.intercalate " "
- [ "SELECT *"
- , "FROM payment"
- , "WHERE (created_at >= ? AND created_at <= ?)"
- , " OR (edited_at >= ? AND edited_at <= ?)"
- , " OR (deleted_at >= ? AND deleted_at <= ?)"
- ])
- (start, end, start, end, start, end)
- )