module TimeLog where import Utils import Types import Currency import Amount import LedgerTransaction import LedgerEntry import LedgerFile instance Show TimeLogEntry where show t = printf "%s %s %s" (show $ tcode t) (tdatetime t) (tcomment t) instance Show TimeLog where show tl = printf "TimeLog with %d entries" $ length $ timelog_entries tl ledgerFromTimeLog :: TimeLog -> LedgerFile ledgerFromTimeLog tl = LedgerFile [] [] (entriesFromTimeLogEntries $ timelog_entries tl) entriesFromTimeLogEntries :: [TimeLogEntry] -> [LedgerEntry] entriesFromTimeLogEntries [clockin] = entriesFromTimeLogEntries [clockin, clockoutNowEntry] entriesFromTimeLogEntries [clockin,clockout] = [ LedgerEntry { edate = indate, estatus = True, ecode = "", edescription = accountname, etransactions = [ LedgerTransaction accountname amount, LedgerTransaction "TIME" (-amount) ]} ] where accountname = tcomment clockin intime = tdatetime clockin indate = dateFrom $ tdatetime clockin outtime = tdatetime clockout amount = hours 0 -- read $ outtime - intime entriesFromTimeLogEntries many = (entriesFromTimeLogEntries $ take 2 many) ++ (entriesFromTimeLogEntries $ drop 2 many) clockoutNowEntry = TimeLogEntry ' ' "" "" dateFrom = id