public function overtimeAction() { // 返回值数组 $result = array('success' => true, 'info' => '提交成功'); // 请求参数 $request = $this->getRequest()->getParams(); // 操作类型 $operate = array('new' => '新建', 'edit' => '编辑', 'delete' => '删除'); // 操作类别(新建、更新、删除) $operate_type = isset($request['operate']) ? $request['operate'] : ''; $overtime = new Hra_Model_Attendance_Overtime(); if ($operate_type == 'new_hra' || $operate_type == 'new' || $operate_type == 'edit') { $time_from = str_replace('T', ' ', $request['time_from']); $time_to = str_replace('T', ' ', $request['time_to']); if (date('Y-m', strtotime($time_from)) != date('Y-m', strtotime($time_to))) { $result['success'] = false; $request['info'] = '不允许跨月申请,请重新填写时间!'; echo Zend_Json::encode($result); exit; } // 获取加班人员的用工形式(0:弹性,1:非弹性) $user = new Application_Model_User(); $userInfo = $user->getEmployeeInfoById($request['apply_user']); $userType = $userInfo['employment_type']; $workday = new Hra_Model_Workday(); // 获取请假区间包含的工作日天数 $overtimeInfo = $workday->getOvertimeQtyByTimeRange($userType, $request['time_from'], $request['time_to']); $overtimeQty = $overtimeInfo['qty']; $overtimeQty_hours = $overtimeInfo['qty_hours']; /* echo $overtimeQty; exit; */ // 加班类别按起始日期获取 $overtimeType = $workday->getWorkdayType($userType, date('Y-m-d', strtotime($request['time_from']))); if ($overtimeType == 0) { $result['success'] = false; $request['info'] = '工作日设置错误,请检查工作日设置!'; echo Zend_Json::encode($result); exit; } // 当编辑请假申请时,检查时间是否重叠需要过滤当前加班申请ID $filter_id = null; if ($operate_type == 'edit') { $filter_id = $request['id']; } // 检查加班时间范围是否正确 if ($overtimeQty > 0) { // 检查加班时间范围是否跟已有申请(包括已审核和审核中的申请)重叠 if ($overtime->checkTimeOverlap($request['apply_user'], $request['time_from'], $request['time_to'], $filter_id)) { $result['success'] = false; $result['info'] = '时间设置错误,加班时间重叠,请优先处理未审申请。'; } else { $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; // 当前申请为代申请时,获取申请人真实部门主管 if ($request['apply_user'] != $user_id) { // 获取部门主管 $manager = $user->getManagerUser($request['apply_user']); $request['review_user_1'] = $manager[0]['id']; } if ($request['review_user_1'] >= 0) { $data = array('type' => $overtimeType, 'apply_user' => $request['apply_user'], 'review_user_1' => $request['review_user_1'], 'time_from' => $request['time_from'], 'time_to' => $request['time_to'], 'qty' => $overtimeQty, 'qty_hours' => $overtimeQty_hours, 'reason' => $request['reason'], 'remark' => $request['remark'], 'update_time' => $now, 'update_user' => $user_id); /* echo '<pre>'; print_r($data); exit; */ if ($operate_type == 'new_hra') { // HRA手动添加 $data['state'] = 3; $data['create_time'] = $now; $data['create_user'] = $user_id; $data['review_info'] = $now . ': ' . $user_session->user_info['user_name'] . ' [手动添加]'; try { $overtime_id = $overtime->insert($data); echo Zend_Json::encode($result); exit; } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } } else { if ($operate_type == 'new') { $data['create_time'] = $now; $data['create_user'] = $user_id; $data['review_info'] = $now . ': ' . $user_session->user_info['user_name'] . ' [新建]'; try { $overtime_id = $overtime->insert($data); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } } else { $overtime_id = $request['id']; $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [修改]'; $overtimeData = $overtime->getData(null, $overtime_id); $data['review_info'] = $overtimeData['review_info'] . '<br>' . $review_info; $data['state'] = 0; $data['review_time_1'] = null; //$data['review_time_2'] = null; $data['release_time'] = null; try { $overtime->update($data, "id = " . $overtime_id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } } } $overtimeData = $overtime->getData(null, $overtime_id); $review = new Dcc_Model_Review(); $user = new Application_Model_User(); $help = new Application_Model_Helpers(); // 记录审核日志:审核人1 $apply_user_info = $user->getEmployeeInfoById($request['apply_user']); $review_user_1_info = $user->getEmployeeInfoById($request['review_user_1']); $reviewData = array('type' => 'attendance_overtime', 'file_id' => $overtime_id, 'step_name' => '审核人1', 'plan_user' => $overtimeData['review_employee_1_id'], 'method' => 1, 'return' => 1); $review->insert($reviewData); // 如果存在审核人2记录审核日志:审核人2 /* if($request['review_user_2']){ $review_user_2_info = $user->getEmployeeInfoById($request['review_user_2']); $reviewData = array( 'type' => 'attendance_overtime', 'file_id' => $overtime_id, 'step_name' => '审核人2', 'plan_user' => $overtimeData['review_employee_2_id'], 'method' => 1, 'return' => 1 ); $review->insert($reviewData); } */ // 记录审核日志:人事主管 $member = new Admin_Model_Member(); $hraAdminUserArr = $member->getMemberWithNoManagerByName('人事主管'); $hraEmployeeIdArr = array(); foreach ($hraAdminUserArr as $hra) { $hra_info = $user->getEmployeeInfoById($hra['user_id']); array_push($hraEmployeeIdArr, $hra_info['id']); } $hraIds = implode(',', $hraEmployeeIdArr); $reviewData = array('type' => 'attendance_overtime', 'file_id' => $overtime_id, 'step_name' => '人事审核', 'plan_user' => $hraIds, 'method' => 1, 'return' => 1); $review->insert($reviewData); // 向审核人1发送邮件 $mailContent = '<div>你有一个新的加班申请等待审核,请登录系统查看:</div> <div> <p><b>申请人:</b><a style="color:#008B00;font-weight: bold;">' . $overtimeData['apply_user_name'] . '</a></p> <p><b>加班时间:</b><a style="color:#008B00;font-weight: bold;">' . $overtimeData['time_from'] . '</a> 至 <a style="color:#008B00;font-weight: bold;">' . $overtimeData['time_to'] . '</a></p> <p><b>事由:</b>' . $overtimeData['reason'] . '</p> <p><b>备注:</b>' . $overtimeData['remark'] . '</p> <p><b>创建人:</b>' . $overtimeData['creater'] . '</p> <p><b>申请时间:</b>' . $overtimeData['create_time'] . '</p> <hr> <p><b>审核日志:</b></p><p>' . $data['review_info'] . '</p> </div>'; $mailData = array('type' => '消息', 'subject' => '加班申请-新申请', 'cc' => $user_session->user_info['user_email'], 'content' => $mailContent, 'add_date' => $now); $result = $help->sendMailToStep(array($review_user_1_info['id']), $mailData); } else { $result['success'] = false; $result['info'] = '申请失败,当前申请人未设置部门主管。'; } } } else { $result['success'] = false; $result['info'] = '时间设置错误,请确认时间范围是否正确。'; } } else { if ($operate_type == 'delete') { if (isset($request['id']) && count(Zend_Json::decode($request['id'])) > 0) { $ids = Zend_Json::decode($request['id']); // 多条申请逐条删除 foreach ($ids as $id) { try { $review = new Dcc_Model_Review(); // 删除审核日志 $review->delete("type = 'attendance_overtime' and file_id = " . $id); $overtime->delete("id = " . $id); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); } } } else { $result['success'] = false; $result['info'] = '参数错误,没有删除对象。'; } } else { $result['success'] = false; $result['info'] = '参数错误,没有操作类别。'; } } echo Zend_Json::encode($result); exit; }
public function getStatisticsList($condition = array()) { $data = array(); $employee = new Hra_Model_Employee(); $sql = $employee->select()->setIntegrityCheck(false)->from(array('t1' => $this->_dbprefix . 'employee'))->joinLeft(array('t2' => $this->_dbprefix . 'employee_dept'), "t2.id = t1.dept_id", array('dept_name' => 'name'))->joinLeft(array('t3' => $this->_dbprefix . 'employee_post'), "t3.id = t1.post_id", array('post_name' => 'name'))->joinLeft(array('t4' => $this->_dbprefix . 'user'), "t4.employee_id = t1.id", array('user_id' => 'id'))->joinLeft(array('t5' => $this->_dbprefix . 'employee_type'), "t1.employment_type = t5.id", array('employment_type' => 'name'))->where("(t1.leave_date is null or (t1.leave_date is not null and t1.leave_date >= '" . $condition['date_from'] . "' and t1.leave_date <= '" . $condition['date_to'] . "'))")->order(array("t1.employment_type", "t1.number")); if ($condition['employment_type'] != '') { $sql->where("employment_type = " . $condition['employment_type']); } if ($condition['key']) { $sql->where("t1.ename like '" . $condition['key'] . "' or t1.cname like '" . $condition['key'] . "' or t1.number like '" . $condition['key'] . "'"); } $total = $employee->fetchAll($sql)->count(); if ($condition['type'] != 'csv') { $sql->limitPage($condition['page'], $condition['limit']); } $data = $employee->fetchAll($sql)->toArray(); $workday = new Hra_Model_Workday(); $vacation = new Hra_Model_Attendance_Vacation(); $overtime = new Hra_Model_Attendance_Overtime(); // 员工工作日设置(目前均按弹性员工工作日设置处理) $workdaySetting = $workday->getDayQtyBase(1, 1, $condition['date_from'], $condition['date_to']); $holidaySetting = $workday->getDayQtyBase(3, 1, $condition['date_from'], $condition['date_to']); for ($i = 0; $i < count($data); $i++) { $data[$i]['workday_qty'] = $workdaySetting['day']; $data[$i]['workhour_qty'] = $workdaySetting['hour']; $data[$i]['holiday_qty'] = $holidaySetting['day']; $data[$i]['attendance_qty'] = null; $data[$i]['attendance_hour_qty'] = 0; $data[$i]['v_personal_qty'] = null; $data[$i]['v_vacation_qty'] = null; $data[$i]['v_sick_qty'] = null; $data[$i]['v_marriage_qty'] = null; $data[$i]['v_funeral_qty'] = null; $data[$i]['v_childbirth_qty'] = null; $data[$i]['v_childbirth_with_qty'] = null; $data[$i]['v_other_qty'] = null; $data[$i]['o_workday_qty'] = null; $data[$i]['o_restday_qty'] = null; $data[$i]['o_holiday_qty'] = null; $data[$i]['late_qty'] = null; $data[$i]['leave_early_qty'] = null; $data[$i]['absence_halfday_qty'] = null; $data[$i]['absence_qty'] = null; if ($data[$i]['user_id']) { // 出勤天数 $sql = $this->select()->from($this->_name)->where("number = '" . $data[$i]['number'] . "' and clock_in >= '" . $condition['date_from'] . " 00:00:00' and clock_out <= '" . $condition['date_to'] . " 23:59:59'")->group("date_format(clock_in, '%Y-%m-%d')"); $aData = $this->fetchAll($sql)->toArray(); foreach ($aData as $a) { $data[$i]['attendance_hour_qty'] += $a['clock_hours']; } $data[$i]['attendance_qty'] = count($aData); // 请假天数 $data[$i]['v_personal_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 1, $condition['date_from'], $condition['date_to']); $data[$i]['v_vacation_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 2, $condition['date_from'], $condition['date_to']); $data[$i]['v_sick_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 3, $condition['date_from'], $condition['date_to']); $data[$i]['v_marriage_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 4, $condition['date_from'], $condition['date_to']); $data[$i]['v_funeral_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 5, $condition['date_from'], $condition['date_to']); $data[$i]['v_childbirth_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 6, $condition['date_from'], $condition['date_to']); $data[$i]['v_childbirth_with_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 7, $condition['date_from'], $condition['date_to']); $data[$i]['v_other_qty'] = $vacation->getVacationQty($data[$i]['user_id'], 8, $condition['date_from'], $condition['date_to']); // 加班天数 $data[$i]['o_workday_qty'] = $overtime->getOvertimeQty($data[$i]['user_id'], 1, $condition['date_from'], $condition['date_to']); $data[$i]['o_restday_qty'] = $overtime->getOvertimeQty($data[$i]['user_id'], 2, $condition['date_from'], $condition['date_to']); $data[$i]['o_holiday_qty'] = $overtime->getOvertimeQty($data[$i]['user_id'], 3, $condition['date_from'], $condition['date_to']); //其它统计(迟到、早退、旷工次数) $other = $this->getAbsenceQty($data[$i]['number'], $condition['date_from'], $condition['date_to']); $data[$i]['late_qty'] = $other[1]; $data[$i]['leave_early_qty'] = $other[2]; $data[$i]['absence_halfday_qty'] = $other[3]; $data[$i]['absence_qty'] = $other[4]; } } if ($condition['type'] == 'csv') { $data_csv = array(); $title = array('cnt' => '#', 'employment_type' => '用工形式', 'number' => '工号', 'cname' => '中文名', 'ename' => '英文名', 'dept_name' => '部门', 'post_name' => '职位', 'active' => '状态', 'attendance' => '出勤/考勤 [天]', 'holiday_qty' => '法定假日', 'v_personal_qty' => '事假', 'v_vacation_qty' => '年假', 'v_sick_qty' => '病假', 'v_marriage_qty' => '婚假', 'v_funeral_qty' => '丧假', 'v_childbirth_qty' => '产假', 'v_childbirth_with_qty' => '陪产假', 'v_other_qty' => '调休', 'o_workday_qty' => '工作日加班', 'o_restday_qty' => '休息日加班', 'o_holiday_qty' => '法定假日加班', 'late_qty' => '迟到', 'leave_early_qty' => '早退', 'absence_halfday_qty' => '旷工半天', 'absence_qty' => '旷工一天'); array_push($data_csv, $title); $i = 0; foreach ($data as $d) { $i++; $info = array('cnt' => $i, 'employment_type' => $d['employment_type'] == 0 ? '弹性' : '非弹性', 'number' => $d['number'], 'cname' => $d['cname'], 'ename' => $d['ename'], 'dept_name' => $d['dept_name'], 'post_name' => $d['post_name'], 'active' => $d['active'] == 1 ? '在职' : '离职', 'attendance' => $d['workday_qty'] . ' { ' . $d['attendance_qty'] . ' }', 'attendance_hours' => $d['workhour_qty'] . ' { ' . $d['attendance_hour_qty'] . ' }', 'holiday_qty' => $d['holiday_qty'], 'v_personal_qty' => $d['v_personal_qty'], 'v_vacation_qty' => $d['v_vacation_qty'], 'v_sick_qty' => $d['v_sick_qty'], 'v_marriage_qty' => $d['v_marriage_qty'], 'v_funeral_qty' => $d['v_funeral_qty'], 'v_childbirth_qty' => $d['v_childbirth_qty'], 'v_childbirth_with_qty' => $d['v_childbirth_with_qty'], 'v_other_qty' => $d['v_other_qty'], 'o_workday_qty' => $d['o_workday_qty'], 'o_restday_qty' => $d['o_restday_qty'], 'o_holiday_qty' => $d['o_holiday_qty'], 'late_qty' => $d['late_qty'], 'leave_early_qty' => $d['leave_early_qty'], 'absence_halfday_qty' => $d['absence_halfday_qty'], 'absence_qty' => $d['absence_qty']); array_push($data_csv, $info); } return $data_csv; } return array('total' => $total, 'rows' => $data); }
public function testAction() { $workday = new Hra_Model_Workday(); $workdaySetting = $workday->getDayQtyBase(1, 0, '2014-07-01', '2014-07-31'); echo '<pre>'; print_r($workdaySetting); exit; }