/** * 刷新员工年假库 * 1、根据员工用功形式获取员工的其实年假设置; * 2、 * @param number $employee_id */ public function refreshStorage($employee_id = null, $cover = 0) { $result = array('success' => true, 'info' => '刷新成功'); $qty = 0; $employee = new Hra_Model_Employee(); $paramModel = new Hra_Model_Attendanceparams(); // 获取所有用工形式的首年年假设置天数 $vacationSet = $paramModel->getParamByType('vacation'); $employeeCond = ""; // 刷新个人或全部在职员工的最近一年的年假天数 if ($employee_id) { $employeeCond = " and id = " . $employee_id; } $data = $employee->fetchAll("active = 1" . $employeeCond)->toArray(); $now = date('Y-m-d H:i:s'); $user_session = new Zend_Session_Namespace('user'); $user_id = $user_session->user_info['user_id']; foreach ($data as $d) { // 根据转正日期 if ($d['regularization_date'] != '') { // 起始年假天数(来自基础设置) $qtyStart = $vacationSet[$d['employment_type']]; // 入司年数 $in_year_qty = 0; // 2014-10-08之后入职的员工按入职日期开始计算,否则按转正日期计算 if (strtotime($d['entry_date']) >= strtotime('2014-10-08')) { $in_year_qty = $employee->getInCompanyYearQty($d['entry_date']); //入职日期 } else { $in_year_qty = $employee->getInCompanyYearQty($d['regularization_date']); //转正日期 } $qty = 0; if ($in_year_qty > 0) { // 根据入司年数计算员工最近一年应有几天年假 $qty = $qtyStart + $in_year_qty - 1; } if ($qty >= 0) { // 当员工最近一年的年假已记录时,更新(用户选择是否覆盖)员工最近的年假天数,否则插入新数据 $oldDataRes = $this->fetchAll("number = '" . $d['number'] . "' and in_year_qty = " . $in_year_qty); if ($oldDataRes->count() > 0 && $cover == 1) { $oldData = $oldDataRes->toArray(); // 当员工当前入司年份有数据时,更新记录 $t = array('qty' => $qty, 'remark' => '刷新更新', 'update_user' => $user_id, 'update_time' => $now); try { $this->update($t, "id = " . $oldData[0]['id']); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); return $result; } } else { if ($oldDataRes->count() == 0) { // 当员工当前入司年份没有数据时,插入新记录 $t = array('number' => $d['number'], 'in_year_qty' => $in_year_qty, 'qty' => $qty, 'remark' => '刷新生成', 'create_user' => $user_id, 'create_time' => $now, 'update_user' => $user_id, 'update_time' => $now); try { $this->insert($t); } catch (Exception $e) { $result['success'] = false; $result['info'] = $e->getMessage(); return $result; } } } } } } return $result; }