/** * Determines if we have a DB connection. * * @return boolean */ public function hasDB() { if (!isset($this->db)) { try { $this->db = !!\DB::connection()->getDatabaseName(); } catch (\Exception $e) { $this->db = false; } } return $this->db; }
public function processWorkTime($emp_mx_id, $punch_date) { $total_work_time = 0; $in_times = []; $out_times = []; $difference = 0; $total_out_time = 0; $total_work_time = \DB::select(" SELECT\n TIMESTAMPDIFF(MINUTE, MIN(punch_trg_datetime), MAX(punch_trg_datetime)) total_time\n FROM tik_tok_attendance\n WHERE emp_mx_id = '{$emp_mx_id}' AND\n punch_trg_date = '{$punch_date}' AND DATE_FORMAT(punch_trg_datetime , '%H') >= 8 ;\n ")[0]->total_time; //Latha and Alex if ($emp_mx_id != 'MX057' || $emp_mx_id != 'MX076') { $all_in_time_array = \DB::select("SELECT punch_trg_datetime FROM tik_tok_attendance WHERE punch_trg_date = '{$punch_date}' AND emp_mx_id = '{$emp_mx_id}' AND punch_type = 'In' AND DATE_FORMAT(punch_trg_datetime , '%H') >= 8 ORDER BY punch_trg_datetime,punch_trg_id ASC ;"); $all_out_time_array = \DB::select("SELECT punch_trg_datetime FROM tik_tok_attendance WHERE punch_trg_date = '{$punch_date}' AND emp_mx_id = '{$emp_mx_id}' AND punch_type = 'Out' AND DATE_FORMAT(punch_trg_datetime , '%H') >= 8 ORDER BY punch_trg_datetime,punch_trg_id ASC ;"); foreach ($all_in_time_array as $all_in_time_array_item) { $in_times[] = $all_in_time_array_item->punch_trg_datetime; } foreach ($all_out_time_array as $all_out_time_array_item) { $out_times[] = $all_out_time_array_item->punch_trg_datetime; } $in_time_count = count($in_times); $out_time_count = count($out_times); if ($in_time_count == $out_time_count) { foreach ($out_times as $key => $out_time_value) { if (!empty($in_times[$key + 1])) { $num_temp = $key + 1; $difference = \DB::connection('mysql_dummy')->select(" SELECT TIMESTAMPDIFF(MINUTE, '{$in_times[$num_temp]}', '{$out_time_value}' ) difference ; ")[0]; $total_work_time += $difference->difference; $total_out_time += abs($difference->difference); } } } else { if ($in_time_count > $out_time_count) { $evaluate_date = new \DateTime($in_times[$in_time_count - 1]); $num_temp = $in_time_count - 1; if (intval($evaluate_date->format('H')) < 19) { } $difference = \DB::connection('mysql_dummy')->select(" SELECT TIMESTAMPDIFF(MINUTE, '{$in_times[$num_temp]}', '{$punch_date} 19:30:00' ) difference ; ")[0]; $total_work_time += $difference->difference; } } } return "{$total_work_time},{$total_out_time}"; }