diff options
author | Markus Krogh <markus@nordu.net> | 2016-03-08 18:51:12 +0000 |
---|---|---|
committer | Markus Krogh <markus@nordu.net> | 2016-03-08 18:51:12 +0000 |
commit | c00e57756336358e9800fc8fc89392253dbf4ed8 (patch) | |
tree | b005152d9bd390c3e2a8912247fff43dfbbbfde6 /maconomy/repositories.py | |
parent | 5c365f875986ffb38345e789a450639b1b833b24 (diff) |
Initial commmit, still needs wireing for email
Diffstat (limited to 'maconomy/repositories.py')
-rw-r--r-- | maconomy/repositories.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/maconomy/repositories.py b/maconomy/repositories.py new file mode 100644 index 0000000..fb143e8 --- /dev/null +++ b/maconomy/repositories.py @@ -0,0 +1,35 @@ +import cx_Oracle +from maconomy.models import Employee, Timesheet + +def create_db(config): + user = config.get("db", "user") + pw = config.get("db", "password") + server = config.get("db", "server") + return cx_Oracle.connect(user, pw, server) + +class DBRepository: + def __init__(self, dbcon): + self.db = dbcon + self.cursor = dbcon.cursor() + + def close(self): + self.cursor.close() + +class TimeRegistrationRepository(DBRepository): + def all_active(self): + query = """SELECT e.EMPLOYEENUMBER,e.NAME1,e.ELECTRONICMAILADDRESS, t.WEEKNUMBER, t.SUBMITTED, t.APPROVED from EMPLOYEE e + LEFT OUTER JOIN TIMESHEETHEADER t + ON e.EMPLOYEENUMBER = t.EMPLOYEENUMBER + and t.PERIODSTART=to_char(trunc(sysdate-7, 'IW'),'YYYY.MM.DD') + WHERE e.blocked=0 + and (e.DATEENDEMPLOYMENT >= to_char(sysdate,'YYYY.MM.DD') or e.DATEENDEMPLOYMENT = ' ') + and e.employeenumber <> '99' + and e.MUSTUSETIMESHEETS=1 + ORDER BY e.employeenumber + """ + + res = self.cursor.execute(query) + rows = res.fetchall() + + return [(Employee(r), Timesheet(r[3:])) for r in rows] + |