module Ledger.TimeLog
where
import Ledger.Utils
import Ledger.Types
import Ledger.Commodity
import Ledger.Amount
instance Show TimeLogEntry where
show t = printf "%s %s %s" (show $ tlcode t) (show $ tldatetime t) (tlcomment t)
instance Show TimeLog where
show tl = printf "TimeLog with %d entries" $ length $ timelog_entries tl
ledgerFromTimeLog :: TimeLog -> RawLedger
ledgerFromTimeLog tl = RawLedger [] [] (entriesFromTimeLogEntries $ timelog_entries tl) ""
entriesFromTimeLogEntries :: [TimeLogEntry] -> [Entry]
entriesFromTimeLogEntries [] = []
entriesFromTimeLogEntries [i] = entriesFromTimeLogEntries [i, clockoutFor i]
entriesFromTimeLogEntries (i:o:rest) = [entryFromTimeLogInOut i o] ++ entriesFromTimeLogEntries rest
clockoutFor :: TimeLogEntry -> TimeLogEntry
clockoutFor (TimeLogEntry _ t _) = TimeLogEntry 'o' t ""
entryFromTimeLogInOut :: TimeLogEntry -> TimeLogEntry -> Entry
entryFromTimeLogInOut i o =
Entry {
edate = indate,
estatus = True,
ecode = "",
edescription = "",
ecomment = "",
etransactions = txns,
epreceding_comment_lines=""
}
where
acctname = tlcomment i
indate = datetimeToDate intime
outdate = datetimeToDate outtime
intime = tldatetime i
outtime = tldatetime o
amount = Mixed [hours $ elapsedSeconds outtime intime / 3600]
txns = [RawTransaction acctname amount "" RegularTransaction
]