remove description string from journal entries
This commit is contained in:
parent
173eecf811
commit
4629910b4c
4 changed files with 53 additions and 34 deletions
|
@ -52,7 +52,8 @@ buy auth pds = do
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
void $ insertNewJournalEntry
|
void $ insertNewJournalEntry
|
||||||
(JournalSubmit
|
(JournalSubmit
|
||||||
("Cash purchase")
|
Nothing
|
||||||
|
BuyCash
|
||||||
price
|
price
|
||||||
)
|
)
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -92,8 +92,8 @@ userRecharge (Just (auid, _)) (UserRecharge amount) = do
|
||||||
ud <- userDetailsSelect auid conn
|
ud <- userDetailsSelect auid conn
|
||||||
void $ insertNewJournalEntry
|
void $ insertNewJournalEntry
|
||||||
(JournalSubmit
|
(JournalSubmit
|
||||||
("User \"" <> userDetailsIdent ud <> "\" recharged " <>
|
(Just $ userDetailsId ud)
|
||||||
T.pack (show (fromIntegral amount / 100 :: Double)))
|
Recharge
|
||||||
amount
|
amount
|
||||||
)
|
)
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -30,9 +30,10 @@ initJournal = mconcat
|
||||||
[ "CREATE TABLE IF NOT EXISTS \"journal\" ("
|
[ "CREATE TABLE IF NOT EXISTS \"journal\" ("
|
||||||
, "journal_id SERIAL NOT NULL,"
|
, "journal_id SERIAL NOT NULL,"
|
||||||
, "journal_timestamp TIMESTAMPTZ NOT NULL,"
|
, "journal_timestamp TIMESTAMPTZ NOT NULL,"
|
||||||
, "journal_description TEXT NOT NULL,"
|
, "journal_user INTEGER,"
|
||||||
|
, "journal_action INTEGER NOT NULL,"
|
||||||
, "journal_total_amount INTEGER NOT NULL,"
|
, "journal_total_amount INTEGER NOT NULL,"
|
||||||
, "journal_entry_is_check BOOLEAN NOT NULL,"
|
-- , "journal_entry_is_check BOOLEAN NOT NULL,"
|
||||||
, "PRIMARY KEY (journal_id)"
|
, "PRIMARY KEY (journal_id)"
|
||||||
, ")"
|
, ")"
|
||||||
]
|
]
|
||||||
|
@ -40,23 +41,26 @@ initJournal = mconcat
|
||||||
journalTable :: Table
|
journalTable :: Table
|
||||||
( Maybe (Field SqlInt4)
|
( Maybe (Field SqlInt4)
|
||||||
, Field SqlTimestamptz
|
, Field SqlTimestamptz
|
||||||
, Field SqlText
|
, FieldNullable SqlInt4
|
||||||
, Field SqlInt4
|
, Field SqlInt4
|
||||||
, Field SqlBool
|
, Field SqlInt4
|
||||||
|
-- , Field SqlBool
|
||||||
)
|
)
|
||||||
( Field SqlInt4
|
( Field SqlInt4
|
||||||
, Field SqlTimestamptz
|
, Field SqlTimestamptz
|
||||||
, Field SqlText
|
, FieldNullable SqlInt4
|
||||||
, Field SqlInt4
|
, Field SqlInt4
|
||||||
, Field SqlBool
|
, Field SqlInt4
|
||||||
|
-- , Field SqlBool
|
||||||
)
|
)
|
||||||
journalTable = table "journal" (
|
journalTable = table "journal" (
|
||||||
p5
|
p5
|
||||||
( tableField "journal_id"
|
( tableField "journal_id"
|
||||||
, tableField "journal_timestamp"
|
, tableField "journal_timestamp"
|
||||||
, tableField "journal_description"
|
, tableField "journal_user"
|
||||||
|
, tableField "journal_action"
|
||||||
, tableField "journal_total_amount"
|
, tableField "journal_total_amount"
|
||||||
, tableField "journal_entry_is_check"
|
-- , tableField "journal_entry_is_check"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -81,14 +85,14 @@ selectJournalEntries mlimit moffset conn = liftIO $ do
|
||||||
) :: IO
|
) :: IO
|
||||||
[ ( Int
|
[ ( Int
|
||||||
, UTCTime
|
, UTCTime
|
||||||
, T.Text
|
, Maybe Int
|
||||||
|
, Int
|
||||||
, Int
|
, Int
|
||||||
, Bool
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
return $ fst $ foldr
|
return $ fst $ foldr
|
||||||
(\(id_, ts, descr, tot, check) (fin, before)->
|
(\(id_, ts, user, action, tot) (fin, before)->
|
||||||
(JournalEntry id_ descr ts (tot - before) tot check : fin, tot)
|
(JournalEntry id_ ts user (toEnum action) (tot - before) tot : fin, tot)
|
||||||
)
|
)
|
||||||
( []
|
( []
|
||||||
, if isJust mlimit && length entries > fromJust mlimit
|
, if isJust mlimit && length entries > fromJust mlimit
|
||||||
|
@ -112,16 +116,16 @@ selectLatestJournalEntry conn = liftIO $ do
|
||||||
) :: IO
|
) :: IO
|
||||||
[ ( Int
|
[ ( Int
|
||||||
, UTCTime
|
, UTCTime
|
||||||
, T.Text
|
, Maybe Int
|
||||||
|
, Int
|
||||||
, Int
|
, Int
|
||||||
, Bool
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
if not (null lastTwoEntries)
|
if not (null lastTwoEntries)
|
||||||
then do
|
then do
|
||||||
let diff = foldl (\acc (_, _, _, tot, _) -> tot - acc) 0 lastTwoEntries
|
let diff = foldl (\acc (_, _, _, _, tot) -> tot - acc) 0 lastTwoEntries
|
||||||
(jid, ts, descr, total, check) = head lastTwoEntries
|
(jid, ts, user, action, total) = head lastTwoEntries
|
||||||
return $ Just $ JournalEntry jid descr ts diff total check
|
return $ Just $ JournalEntry jid ts user (toEnum action) diff total
|
||||||
else
|
else
|
||||||
return Nothing
|
return Nothing
|
||||||
|
|
||||||
|
@ -130,7 +134,7 @@ insertNewJournalEntry
|
||||||
:: JournalSubmit
|
:: JournalSubmit
|
||||||
-> PGS.Connection
|
-> PGS.Connection
|
||||||
-> MateHandler Int
|
-> MateHandler Int
|
||||||
insertNewJournalEntry (JournalSubmit descr amount) conn = do
|
insertNewJournalEntry (JournalSubmit user action amount) conn = do
|
||||||
lastTotal <- (\case
|
lastTotal <- (\case
|
||||||
Just j -> journalEntryTotalAmount j
|
Just j -> journalEntryTotalAmount j
|
||||||
Nothing -> 0
|
Nothing -> 0
|
||||||
|
@ -143,9 +147,9 @@ insertNewJournalEntry (JournalSubmit descr amount) conn = do
|
||||||
[
|
[
|
||||||
( C.constant (Nothing :: Maybe Int)
|
( C.constant (Nothing :: Maybe Int)
|
||||||
, C.constant now
|
, C.constant now
|
||||||
, C.constant descr
|
, C.constant user
|
||||||
|
, C.constant (fromEnum action)
|
||||||
, C.constant (lastTotal + amount)
|
, C.constant (lastTotal + amount)
|
||||||
, C.constant False
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
, iReturning = rReturning (\(id_, _, _, _, _) -> id_)
|
, iReturning = rReturning (\(id_, _, _, _, _) -> id_)
|
||||||
|
@ -156,7 +160,7 @@ insertNewCashCheck
|
||||||
:: JournalCashCheck
|
:: JournalCashCheck
|
||||||
-> PGS.Connection
|
-> PGS.Connection
|
||||||
-> MateHandler Int
|
-> MateHandler Int
|
||||||
insertNewCashCheck (JournalCashCheck amount) conn =
|
insertNewCashCheck (JournalCashCheck user amount) conn =
|
||||||
-- lastTotal <- (\case
|
-- lastTotal <- (\case
|
||||||
-- Just j -> journalEntryTotalAmount j
|
-- Just j -> journalEntryTotalAmount j
|
||||||
-- Nothing -> 0
|
-- Nothing -> 0
|
||||||
|
@ -169,9 +173,9 @@ insertNewCashCheck (JournalCashCheck amount) conn =
|
||||||
[
|
[
|
||||||
( C.constant (Nothing :: Maybe Int)
|
( C.constant (Nothing :: Maybe Int)
|
||||||
, C.constant now
|
, C.constant now
|
||||||
, C.constant ("Cash check" :: String)
|
, C.constant (Just user)
|
||||||
|
, C.constant (fromEnum CashCheck)
|
||||||
, C.constant amount
|
, C.constant amount
|
||||||
, C.constant True
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
, iReturning = rReturning (\(id_, _, _, _, _) -> id_)
|
, iReturning = rReturning (\(id_, _, _, _, _) -> id_)
|
||||||
|
|
|
@ -4,19 +4,18 @@ module Types.Journal where
|
||||||
|
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
|
|
||||||
import qualified Data.Text as T (Text)
|
|
||||||
|
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
|
|
||||||
import Data.Time (UTCTime)
|
import Data.Time (UTCTime)
|
||||||
|
|
||||||
data JournalEntry = JournalEntry
|
data JournalEntry = JournalEntry
|
||||||
{ journalEntryId :: Int
|
{ journalEntryId :: Int
|
||||||
, journalEntryDescription :: T.Text
|
|
||||||
, journalEntryTimestamp :: UTCTime
|
, journalEntryTimestamp :: UTCTime
|
||||||
|
, journalEntryUser :: Maybe Int
|
||||||
|
, journalEntryAction :: JournalAction
|
||||||
, journalEntryAmount :: Int
|
, journalEntryAmount :: Int
|
||||||
, journalEntryTotalAmount :: Int
|
, journalEntryTotalAmount :: Int
|
||||||
, journalEntryIsCheck :: Bool
|
-- , journalEntryIsCheck :: Bool
|
||||||
}
|
}
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
|
|
||||||
|
@ -27,8 +26,9 @@ instance FromJSON JournalEntry
|
||||||
|
|
||||||
|
|
||||||
data JournalSubmit = JournalSubmit
|
data JournalSubmit = JournalSubmit
|
||||||
{ journalSubmitDescription :: T.Text
|
{ journalSubmitUser :: Maybe Int
|
||||||
, journalSubmitAmount :: Int
|
, journalSubmitAction :: JournalAction
|
||||||
|
, journalSubmitAmount :: Int
|
||||||
}
|
}
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
|
|
||||||
|
@ -38,8 +38,9 @@ instance ToJSON JournalSubmit where
|
||||||
instance FromJSON JournalSubmit
|
instance FromJSON JournalSubmit
|
||||||
|
|
||||||
|
|
||||||
newtype JournalCashCheck = JournalCashCheck
|
data JournalCashCheck = JournalCashCheck
|
||||||
{ journalCashCheckTotalAmount :: Int
|
{ journalCashCheckUser :: Int
|
||||||
|
, journalCashCheckTotalAmount :: Int
|
||||||
}
|
}
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
|
|
||||||
|
@ -47,3 +48,16 @@ instance ToJSON JournalCashCheck where
|
||||||
toEncoding = genericToEncoding defaultOptions
|
toEncoding = genericToEncoding defaultOptions
|
||||||
|
|
||||||
instance FromJSON JournalCashCheck
|
instance FromJSON JournalCashCheck
|
||||||
|
|
||||||
|
data JournalAction
|
||||||
|
= CashCheck
|
||||||
|
| Recharge
|
||||||
|
| BuyCash
|
||||||
|
| PayBill
|
||||||
|
| PayOut
|
||||||
|
deriving (Generic, Show, Enum, Eq)
|
||||||
|
|
||||||
|
instance ToJSON JournalAction where
|
||||||
|
toEncoding = genericToEncoding defaultOptions
|
||||||
|
|
||||||
|
instance FromJSON JournalAction
|
||||||
|
|
Loading…
Reference in a new issue