Пример #1
0
 public function setClock($number, $employment_type, $from, $to, $remark)
 {
     $from_date = date('Y-m-d', strtotime($from));
     $to_date = date('Y-m-d', strtotime($to));
     $now = date('Y-m-d H:i:s');
     $user_session = new Zend_Session_Namespace('user');
     $user_id = $user_session->user_info['user_id'];
     $workday = new Hra_Model_Workday();
     $worktime = new Hra_Model_Worktime();
     $attendance = new Hra_Model_Attendance();
     $vacationWorkDayInfo = $workday->getWorkdayQtyByTimeRange($employment_type, $from, $to);
     $vacationWorkDayArr = $vacationWorkDayInfo['work_day'];
     // 根据时间范围覆盖的工作日范围记录对应工号员工的打卡时间
     for ($i = 0; $i < count($vacationWorkDayArr); $i++) {
         $d = $vacationWorkDayArr[$i];
         $worktimeRange = $worktime->getWroktimeRange($employment_type, $d);
         // 打卡时间
         $time_on = $d . ' ' . $worktimeRange['from'];
         $time_off = $d . ' ' . $worktimeRange['to'];
         if ($i == 0 && $d == $from_date) {
             // 当起始日期和覆盖的工作日范围第一天一致时,判断起始时间是否 > 当天设定的上班打卡时间,是的话记录上班打卡时间为起始时间,否则记录上班打卡时间为系统设定时间
             if (strtotime($from > strtotime($d . ' ' . $worktimeRange['from']))) {
                 $time_on = $from;
             }
         } else {
             if ($i == count($vacationWorkDayArr) - 1 && $d == $to_date) {
                 // 当截止日期和覆盖的工作日范围最后一天一致时,判断截止时间是否 < 当天设定的下班打卡时间,是的话记录下班打卡时间为截止时间,否则记录上班打卡时间为系统设定时间
                 if (strtotime($to < strtotime($d . ' ' . $worktimeRange['to']))) {
                     $time_off = $to;
                 }
             }
         }
         // 记录上班时间
         $data = array('number' => $number, 'time' => $time_on, 'type' => 1, 'remark' => $remark, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now);
         $attendance->insert($data);
         // 记录下班时间
         $data = array('number' => $number, 'time' => $time_off, 'type' => 2, 'remark' => $remark, 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now);
         $attendance->insert($data);
     }
 }
Пример #2
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;
 }