function initializeData($context, $page) { $data['assets'] = asset_url(); $data['main_url'] = main_url(); $data['flash'] = ''; $data['page'] = 'Records'; $data['username'] = getUsername($context); $data['uxid'] = getUserId($context); $data['timeunit'] = getEmployeeTimeUnit($context); $data['uxrl'] = getRole($context); $data['title_here'] = $page; return $data; }
function getLeaveBalanceOfEmployee($employee_id) { $emp = $employee_id; $tu = getEmployeeTimeUnit($this); $tunit = $tu; $val = 0; $sCondition = ''; if (getEmployeeTimeUnit($this) == 'd') { $sCondition = "and is_base = true"; } $sYear = getSchoolYear($this); if ($tunit == 'h') { $query = $this->db->query("select employment.units as units from employment\r\n where employment.employee_id = {$employee_id}"); $query2 = $this->db->query("select l.end_time,l.start_time from leave_transactions l, employment\r\n where employment.employee_id = {$employee_id} and l.employment_id = employment.id and l.status = 'Approved' and l.schoolyear = '{$sYear}'"); $unit = $query->result(); $val = $unit[0]->units; if ($query2->num_rows() > 0) { $units = $unit[0]->units; $total = 0; $res = objectToArray($query2->result()); $diff = 0; $total = 0; foreach ($res as $key => $value) { if (!empty($value['td'])) { $parsed = date_parse($value['td']); } $time1 = strtotime($value['start_time']); $time2 = strtotime($value['end_time']); $diff = $time2 - $time1; $total = $total + $diff; } $val = $units * 3600 - $total; $val = $val / 3600; } return array('value' => $val, 'unit' => ' h'); } else { if ($tunit == 'd') { if (!empty($employee_id)) { $employee_id = "and e.id = {$employee_id}"; } $query = $this->db->query("\r\n select \r\n sum(\r\n (datediff(g.end_date,g.start_date)) + (g.end_date_hw + g.start_date_hw)+ 1\r\n ) as days\r\n from \r\n leave_transactions g, \r\n employees e,\r\n employment em,\r\n leave_credits lc\r\n where (\r\n g.employment_id = em.id and \r\n em.employee_id = e.id \r\n {$employee_id} and \r\n g.status = 'Approved' and \r\n g.leave_credits_id = lc.id and \r\n lc.is_base = 1) and \r\n g.schoolyear = '{$sYear}'"); $days = $query->result(); $est = $this->getEmpTypesStatByEmployee($emp); $q = $this->db->query("select lc.days \r\n from leave_credits lc, employment e where e.employee_id = {$emp} and lc.emp_types_stat_id = {$est[0]->id} {$sCondition}"); $value = $q->result(); return array('value' => $value[0]->days - $days[0]->days, 'unit' => ' d'); } } }