blob: 54d106eeb24dc0b90d6698665c9f0a364dc43bcb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
try:
import cx_Oracle as db_driver
except:
from maconomy import mssql as db_driver
from datetime import date
from maconomy.models import Timesheet
from maconomy.utils import previous_monday
def create_db(config):
user = config.get("db", "user")
pw = config.get("db", "password")
server = config.get("db", "server")
return db_driver.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):
period_start = previous_monday().strftime("%Y.%m.%d")
today = date.today().strftime("%Y.%m.%d")
query = """SELECT e.EMPLOYEENUMBER,e.NAME1,e.ELECTRONICMAILADDRESS, t.WEEKNUMBER, t.SUBMITTED, t.APPROVED, e.SUPERIOREMPLOYEE from EMPLOYEE e
LEFT OUTER JOIN TIMESHEETHEADER t
ON e.EMPLOYEENUMBER = t.EMPLOYEENUMBER
and t.PERIODSTART='{period_start}'
WHERE e.blocked=0
and (e.DATEENDEMPLOYMENT >= '{today}' or e.DATEENDEMPLOYMENT = ' ')
and e.employeenumber <> '99'
and e.MUSTUSETIMESHEETS=1
ORDER BY e.employeenumber
""".format(period_start=period_start, today=today)
res = self.cursor.execute(query)
rows = res.fetchall()
return [Timesheet.from_result(r) for r in rows]
|