def getLeaveRequest(self, date): cursor = self.conn.cursor(as_dict=True) firstDay = MyCalendar.get_1st_of_this_month(date).strftime('%Y-%m-%d') lastDay = MyCalendar.get_last_date(date).strftime('%Y-%m-%d') sql = """select r.lastname,r.workcode, f.id,f.requestId,f.liush,f.shenqr,f.bum,f.zhiw,f.shenqrq,f.qingjlb,f.qingjsy,f.xiangglc,f.xianggfj,f.kaisrq, f.jiesrq,f.kaissj,f.jiessj,f.qingjrqt,f.nj1,f.nj2,f.kxnjts from dbo.formtable_main_32 f join dbo.HRMResource r on f.shenqr=r.id where f.kaisrq BETWEEN '%s' and '%s' or f.jiesrq BETWEEN '%s' and '%s' """ % (firstDay, lastDay, firstDay, lastDay) self.logger.info(u"查询请假:%s", sql) l = cursor.execute(sql) self.logger.info(u"装载oa 请假记录,共计:%s 条, sql:%s", l, sql) map_all = {} for row in cursor.fetchall(): record = LeaveRequest() record.init(row) logging.debug(u"装载到请假记录:%s", record) logging.debug(u"开始日期:%s %s %s %s", record.kaisrq, type(record.kaisrq), record.kaissj, type(record.kaissj)) if record.workcode in map_all: map_all.get(record.workcode).append(record) else: map_all[record.workcode] = [record] cursor.close() return map_all
def getAllSalaryAdjustRecords(self , fn , firstDate): wb = load_workbook(os.path.expandvars(fn)) ws = wb.active all_map = {} firstDate = MyCalendar.get_1st_of_this_month(firstDate) lastDate = MyCalendar.get_last_date(firstDate) for row_idx in xrange(2,ws.max_row+1): r =SalaryAdjustRecord() r.init(ws,row_idx) if r.effectDate and r.effectDate <=lastDate: all_map[r.workcode] = r return all_map
def __init__(self, year, month): # 双休的周六工作日 self.sat_of_double_rest_work_days = set([ datetime.date(2017, 12, 9) + datetime.timedelta(days=i) for i in range(0, 1000, 14) ]) # 第一天日期 self.firstdate = datetime.date(year, month, 1) self.lastdate = MyCalendar.get_last_date(self.firstdate) adate = datetime.date(year, month, 1) # 周六的天数 self.saturday_day_count = 0 # 周日的天数 self.sunday_day_count = 0 # 双休工作制的工作天数 self.workdayCountOfNormal = 0 # 单休工作制的工作天数 self.workdayCountOfSingleRest = 0 while (adate <= self.lastdate): if adate.weekday() == Const.WeekSaturday: self.saturday_day_count += 1 if adate.weekday() == Const.WeekSunday: self.sunday_day_count += 1 # 大小周的工作天数 if adate in self.sat_of_double_rest_work_days \ or MyCalendar.is_workday(adate.weekday()): self.workdayCountOfNormal += 1 adate += datetime.timedelta(days=1) pass # 单休的休息天数 self.restDayCountOfSingle = max(self.sunday_day_count, self.saturday_day_count) # 单休的工作天数 self.workdayCountOfSingleRest = self.lastdate.day - self.restDayCountOfSingle pass
def __init__(self, year, month): self.year = year self.month = month self.firstDate = datetime.date(year, month, 1) self.lastDate = MyCalendar.get_last_date(self.firstDate) self.oaDao = OaDao() self.zktecoDao = ZktecoDao() self.salaryAdjustDao = SalaryAdjustDao() self.workDay = WorkDay(year, month) logger.info(u"准备计算薪资,年:%s-%s", year, month)
def getAllChecklogMapWorkcode(self, firstDay): cursor = self.conn.cursor(as_dict=True) sql = "SELECT TOP 100 * FROM dbo.checkinout where checktime between '%s' and '%s'"%\ (firstDay.strftime("%Y-%m-%d") , MyCalendar.get_1st_of_next_month(firstDay).strftime("%Y-%m-%d")) l = cursor.execute(sql) self.logger.info(u"装载月份:%s的所有打卡记录,共计:%s 条, sql:%s", firstDay.strftime("%Y-%m"), l, sql) map_all = {} for row in cursor.fetchall(): record = Checkinout(row) logging.info(u"装载到打卡记录:%s", record) if record.workcode in map_all: map_all.get(record.workcode).append(record) else: map_all[record.workcode] = [record] cursor.close() return map_all
else: #双休的处理 if self.workDay.isShouldWork(adate): if one_day_checklog_lst: #有打卡记录 one_day_checklog_lst = sorted(one_day_checklog_lst) log0 = one_day_checklog_lst[0] on_time = log0.checktime if log0.checktime > datetime.time(18, 30): pass pass else: #无打卡记录 pass else: #计算加班工资 pass pass #下一天 adate = adate + datetime.timedelta(days=1) pass if __name__ == '__main__': lastDay = MyCalendar.get_last_date_of_last_month(datetime.date.today()) logger.info("start calc") salary = Salary(lastDay.year, lastDay.month) salary.start()
def isShouldWork(self, adate): "大小周工作制的,是否这一天应该上班" return adate in self.sat_of_double_rest_work_days \ or MyCalendar.is_workday(adate.weekday())