generate-display/finddates.py

54 lines
2.0 KiB
Python
Raw Normal View History

import fredmssql
def get_birthdays(start, thru):
db = fredmssql.FredDB(DATABASE_USER, DATABASE_PASS, DATABASE_NAME)
s = (" SELECT e.EmpUID, e.LastName, e.FirstName, e.BirthDate "
" FROM Employee e "
"LEFT JOIN EmpCstFV c ON e.EmpUID = c.EmpUID AND c.CstID = 105 "
" WHERE e.CompanyID = 6 "
" AND e.TermDate IS NULL "
"AND DATEADD(year, %s - YEAR(e.BirthDate), e.BirthDate) "
" >= CONVERT(datetime, %s, 120) "
"AND DATEADD(year, %s - YEAR(e.BirthDate), e.BirthDate) "
" <= CONVERT(datetime, %s, 120)"
" AND CASE WHEN c.EmpGCstF1 = 0 THEN 0 ELSE 1 END = 1 "
"ORDER BY e.LastName, e.FirstName"
)
result = db.execute(s, (start.year,
start.strftime('%Y-%m-%d'),
thru.year,
thru.strftime('%Y-%m-%d')
))
db.close()
return result
def get_anniversary(start, thru):
db = fredmssql.FredDB(DATABASE_USER, DATABASE_PASS, DATABASE_NAME)
s = (" SELECT e.EmpUID, e.LastName, e.FirstName, e.HireDate "
" FROM Employee e "
"LEFT JOIN EmpCstFV c ON e.EmpUID = c.EmpUID AND c.CstID = 105 "
" WHERE e.CompanyID = 6 "
" AND e.TermDate IS NULL "
"AND DATEADD(year, %s - YEAR(e.HireDate), e.HireDate) "
" >= CONVERT(datetime, %s, 120) "
"AND DATEADD(year, %s - YEAR(e.HireDate), e.HireDate) "
" <= CONVERT(datetime, %s, 120)"
" AND CASE WHEN c.EmpGCstF1 = 0 THEN 0 ELSE 1 END = 1 "
"ORDER BY e.LastName, e.FirstName"
)
result = db.execute(s, (start.year,
start.strftime('%Y-%m-%d'),
thru.year,
thru.strftime('%Y-%m-%d')
))
db.close()
return result
if __name__ == "__main__":
pass