Example #1
0
 /**
  * 根据工号获取员工剩余年假天数
  * @param unknown $number
  * @return number
  */
 public function getVacationQty($number)
 {
     $result = array('qty' => 0, 'qty_used' => 0, 'in_year_qty' => 0);
     $res = $this->fetchAll("number = '" . $number . "'", "in_year_qty desc");
     if ($res->count() > 0) {
         $data = $res->toArray();
         $result['qty_used'] = $data[0]['qty_used'];
         $result['qty'] = $data[0]['qty'];
         $result['in_year_qty'] = $data[0]['in_year_qty'];
         $employee = new Hra_Model_Employee();
         $user_id = $employee->getUserIdByNumber($number);
         $vacation = new Hra_Model_Attendance_Vacation();
         // 员工剩余可使用年假天数需要扣除已提交但未发布的请假申请
         $vRes = $vacation->fetchAll("apply_user = "******" and type = 2 and state != 3 and state != 1");
         if ($vRes->count() > 0) {
             $vData = $vRes->toArray();
             foreach ($vData as $v) {
                 $result['qty_used'] += $v['qty'];
             }
         }
         $result['qty'] -= $result['qty_used'];
     }
     /* echo '<pre>';
        print_r($result);
        exit; */
     return $result;
 }
Example #2
0
 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);
 }
Example #3
0
 public function vacationAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '提交成功');
     // 请求参数
     $request = $this->getRequest()->getParams();
     // 操作类型
     $operate = array('new' => '新建', 'edit' => '编辑', 'delete' => '删除');
     // 操作类别(新建、更新、删除)
     $operate_type = isset($request['operate']) ? $request['operate'] : '';
     $vacation = new Hra_Model_Attendance_Vacation();
     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();
         // 获取请假区间包含的工作日天数
         $vacationInfo = $workday->getWorkdayQtyByTimeRange($userType, $request['time_from'], $request['time_to']);
         $vacationQty = $vacationInfo['qty'];
         $vacationQty_hours = $vacationInfo['qty_hours'];
         // 当编辑请假申请时,检查时间是否重叠需要过滤当前请假申请ID
         $filter_id = null;
         if ($operate_type == 'edit') {
             $filter_id = $request['id'];
         }
         // 检查请假时间范围是否包含工作日
         if ($vacationQty > 0) {
             $overtimeQty = 0;
             if ($request['exchange_overtime_ids'] != '') {
                 $overtimeQty = $this->getOvertimeQty(explode(',', $request['exchange_overtime_ids']));
             }
             $vStorage = new Hra_Model_Vacationstorage();
             //获取员工最近一年的剩余年假以及对于入司年数
             $vStorageQty = $vStorage->getVacationQty($userInfo['number']);
             if (round($vStorageQty['qty'], 1) == round($vacationQty, 1)) {
                 $vacationQty = $vStorageQty['qty'];
             }
             // 检查请假时间范围是否跟已有申请(包括已审核和审核中的申请)重叠
             if ($vacation->checkTimeOverlap($request['apply_user'], $request['time_from'], $request['time_to'], $filter_id)) {
                 $result['success'] = false;
                 $result['info'] = '时间设置错误,请假时间重叠,请优先处理未审申请。';
             } else {
                 if ($request['type'] == 2 && round($vStorageQty['qty'], 1) < round($vacationQty, 1)) {
                     // 当员工请假类别为年假时,检查年假剩余天数是否充足
                     $result['success'] = false;
                     $result['info'] = '时间设置错误,剩余年假天数不足。';
                 } else {
                     if ($request['type'] == 8 && round($overtimeQty, 1) < round($vacationQty, 1)) {
                         // 当员工请假类别为调休时,检查调休可用天数是否充足
                         $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) {
                             // 当员工请假类别是“年假”时,记录员工可用年假对应的入司年数(均以最近一年的年假对应入司年数为准)
                             $in_year_qty = $request['type'] == 2 ? $vStorageQty['in_year_qty'] : null;
                             $data = array('type' => $request['type'], 'in_year_qty' => $in_year_qty, 'qty' => $vacationQty, 'qty_hours' => $vacationQty_hours, 'apply_user' => $request['apply_user'], 'review_user_1' => $request['review_user_1'], 'time_from' => $request['time_from'], 'time_to' => $request['time_to'], 'reason' => $request['reason'], 'work' => $request['work'], 'remark' => $request['remark'], 'exchange_overtime_ids' => $request['exchange_overtime_ids'], 'agent' => $request['agent'], 'update_time' => $now, 'update_user' => $user_id);
                             /* echo '<pre>';
                                print_r($data);
                                exit; */
                             $vacation_id = 0;
                             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 {
                                     $vacation_id = $vacation->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 {
                                         $vacation_id = $vacation->insert($data);
                                     } catch (Exception $e) {
                                         $result['success'] = false;
                                         $result['info'] = $e->getMessage();
                                     }
                                 } else {
                                     $vacation_id = $request['id'];
                                     $review_info = $now . ': ' . $user_session->user_info['user_name'] . ' [修改]';
                                     $vacationData = $vacation->getData(null, $vacation_id);
                                     $data['review_info'] = $vacationData['review_info'] . '<br>' . $review_info;
                                     $data['state'] = 0;
                                     $data['review_time_1'] = null;
                                     //$data['review_time_2'] = null;
                                     $data['release_time'] = null;
                                     try {
                                         $vacation->update($data, "id = " . $vacation_id);
                                     } catch (Exception $e) {
                                         $result['success'] = false;
                                         $result['info'] = $e->getMessage();
                                     }
                                 }
                             }
                             if ($request['type'] == 8) {
                                 $overtime = new Hra_Model_Attendance_Overtime();
                                 $overtime_id_arr = explode(',', $request['exchange_overtime_ids']);
                                 foreach ($overtime_id_arr as $overtime_id) {
                                     $overtime->update(array('exchange' => 1, 'exchange_vacation_id' => $vacation_id), "id = " . $overtime_id);
                                 }
                             }
                             if ($vacation_id > 0) {
                                 $vacationData = $vacation->getData(null, $vacation_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']);
                                 //$agent_info = $user->getEmployeeInfoById($request['agent']);
                                 $reviewData = array('type' => 'attendance_vacation', 'file_id' => $vacation_id, 'step_name' => '审核人1', 'plan_user' => $vacationData['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_vacation',
                                                'file_id'   => $vacation_id,
                                                'step_name' => '审核人2',
                                                'plan_user' => $vacationData['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_vacation', 'file_id' => $vacation_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;">' . $vacationData['apply_user_name'] . '</a></p>
                                         <p><b>请假类别:</b><a style="color:#008B00;font-weight: bold;">' . $vacationData['type_name'] . '</a></p>
                                         <p><b>请假时间:</b><a style="color:#008B00;font-weight: bold;">' . $vacationData['time_from'] . '</a> 至 <a style="color:#008B00;font-weight: bold;">' . $vacationData['time_to'] . '</a></p>
                                         <p><b>代理人:</b>' . $vacationData['agent_name'] . '</p>
                                         <p><b>事由:</b>' . $vacationData['reason'] . '</p>
                                         <p><b>工作交接:</b>' . $vacationData['work'] . '</p>
                                         <p><b>备注:</b>' . $vacationData['remark'] . '</p>
                                         <p><b>创建人:</b>' . $vacationData['creater'] . '</p>
                                         <p><b>申请时间:</b>' . $vacationData['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 {
             $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_vacation' and file_id = " . $id);
                         $vacation->delete("id = " . $id);
                         $overtime = new Hra_Model_Attendance_Overtime();
                         $overtime->update(array('exchange' => 0, 'exchange_vacation_id' => 0), "exchange_vacation_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;
 }