2008-10-03 06:04:15 +04:00
|
|
|
{-|
|
|
|
|
|
2008-10-15 10:00:10 +04:00
|
|
|
A 'TimeLog' is a parsed timelog file (see timeclock.el or the command-line
|
|
|
|
version) containing zero or more 'TimeLogEntry's. It can be converted to a
|
2008-10-03 17:41:27 +04:00
|
|
|
'RawLedger' for querying.
|
2008-10-03 06:04:15 +04:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
2008-10-03 04:40:06 +04:00
|
|
|
module Ledger.TimeLog
|
2007-03-12 10:40:33 +03:00
|
|
|
where
|
2008-10-03 04:05:16 +04:00
|
|
|
import Ledger.Utils
|
2008-10-03 04:12:59 +04:00
|
|
|
import Ledger.Types
|
2008-11-27 03:35:00 +03:00
|
|
|
import Ledger.Dates
|
2008-10-13 01:52:48 +04:00
|
|
|
import Ledger.Commodity
|
2008-10-03 04:40:06 +04:00
|
|
|
import Ledger.Amount
|
2008-12-11 04:35:07 +03:00
|
|
|
import Ledger.Entry
|
2007-03-12 10:40:33 +03:00
|
|
|
|
|
|
|
instance Show TimeLogEntry where
|
2008-11-11 15:34:05 +03:00
|
|
|
show t = printf "%s %s %s" (show $ tlcode t) (show $ tldatetime t) (tlcomment t)
|
2007-03-12 10:40:33 +03:00
|
|
|
|
|
|
|
instance Show TimeLog where
|
|
|
|
show tl = printf "TimeLog with %d entries" $ length $ timelog_entries tl
|
|
|
|
|
2008-10-08 21:00:22 +04:00
|
|
|
-- | Convert time log entries to ledger entries.
|
2008-10-03 06:37:19 +04:00
|
|
|
entriesFromTimeLogEntries :: [TimeLogEntry] -> [Entry]
|
2008-10-09 01:08:42 +04:00
|
|
|
entriesFromTimeLogEntries [] = []
|
|
|
|
entriesFromTimeLogEntries [i] = entriesFromTimeLogEntries [i, clockoutFor i]
|
|
|
|
entriesFromTimeLogEntries (i:o:rest) = [entryFromTimeLogInOut i o] ++ entriesFromTimeLogEntries rest
|
2007-03-12 10:40:33 +03:00
|
|
|
|
2008-10-08 21:00:22 +04:00
|
|
|
-- | When there is a trailing clockin entry, provide the missing clockout.
|
2008-10-15 10:00:10 +04:00
|
|
|
-- An entry for now is what we want but this requires IO so for now use
|
|
|
|
-- the clockin time, ie don't count the current clocked-in period.
|
|
|
|
clockoutFor :: TimeLogEntry -> TimeLogEntry
|
2008-10-09 01:08:42 +04:00
|
|
|
clockoutFor (TimeLogEntry _ t _) = TimeLogEntry 'o' t ""
|
2007-03-12 10:40:33 +03:00
|
|
|
|
2008-10-09 01:08:42 +04:00
|
|
|
-- | Convert a timelog clockin and clockout entry to an equivalent ledger
|
2008-10-15 23:11:06 +04:00
|
|
|
-- entry, representing the time expenditure. Note this entry is not balanced,
|
|
|
|
-- since we omit the \"assets:time\" transaction for simpler output.
|
2008-10-09 01:08:42 +04:00
|
|
|
entryFromTimeLogInOut :: TimeLogEntry -> TimeLogEntry -> Entry
|
2008-12-11 04:35:07 +03:00
|
|
|
entryFromTimeLogInOut i o
|
|
|
|
| outtime >= intime = e
|
|
|
|
| otherwise =
|
|
|
|
error $ "clock-out time less than clock-in time in:\n" ++ showEntry e
|
2007-03-12 10:40:33 +03:00
|
|
|
where
|
2008-12-11 04:35:07 +03:00
|
|
|
e = Entry {
|
|
|
|
edate = outdate, -- like ledger
|
|
|
|
estatus = True,
|
|
|
|
ecode = "",
|
|
|
|
edescription = showtime intime ++ " - " ++ showtime outtime,
|
|
|
|
ecomment = "",
|
|
|
|
etransactions = txns,
|
|
|
|
epreceding_comment_lines=""
|
|
|
|
}
|
|
|
|
showtime = show . timeToTimeOfDay . utctDayTime
|
2008-10-09 01:08:42 +04:00
|
|
|
acctname = tlcomment i
|
2008-11-27 07:01:07 +03:00
|
|
|
indate = utctDay intime
|
|
|
|
outdate = utctDay outtime
|
2008-11-11 15:34:05 +03:00
|
|
|
intime = tldatetime i
|
|
|
|
outtime = tldatetime o
|
|
|
|
amount = Mixed [hours $ elapsedSeconds outtime intime / 3600]
|
2008-10-16 10:00:46 +04:00
|
|
|
txns = [RawTransaction acctname amount "" RegularTransaction
|
|
|
|
--,RawTransaction "assets:time" (-amount) "" RegularTransaction
|
2008-10-15 23:11:06 +04:00
|
|
|
]
|