'LAPTOP-SVULBV9J\SQLEXPRESS', 'username' => 'sa', 'password' => '123', 'dbname' => 'dbtemp_absen' ); $params_hrd = array( 'host' => 'LAPTOP-SVULBV9J\SQLEXPRESS', 'username' => 'sa', 'password' => '123', 'dbname' => 'hrd' ); * */ $params = array( 'host' => '202.145.11.232', 'username' => 'bozz', 'password' => 'w3bd3v.cipdev', 'dbname' => 'dbtemp_absen' ); $params_hrd = array( 'host' => '13.76.184.138', 'username' => 'webappsdb', 'password' => '$bu5w4yP@ssw0rd', 'dbname' => 'hrd' ); $this->sh = $sh_; $this->t_absenlog = $this->get_t_absenlog_name(); $this->db_absen = sqlsrv_connect($params['host'], array("Database" => 'dbtemp_absen', "UID" => $params['username'], "PWD" => $params['password'])); if ($this->db_absen === false) { die(print_r(sqlsrv_errors(), true)); } else { echo "success connection to database $this->db_absen sql server
"; } $this->db_hrd = sqlsrv_connect($params_hrd['host'], array("Database" => 'hrd', "UID" => $params_hrd['username'], "PWD" => $params_hrd['password'])); if ($this->db_hrd === false) { die(print_r(sqlsrv_errors(), true)); } else { echo "success connection to database $this->db_hrd sql server
"; } } public function get_t_absenlog_name() { $sh = $this->sh; if($sh == 'sh3a'){ $tbl = 't_absenlog_sh3a'; } else if($sh == 'sh3a_mcj'){ $tbl = 't_absenlog_sh3a_mcj'; } else if($sh == 'sh3a_hcs'){ $tbl = 't_absenlog_sh3a'; } else if($sh == 'sh3a_pkc'){ $tbl = 't_absenlog_sh3a_pkc'; } else if($sh == 'sh3a_ci' || $sh == 'sh3a_citradream'){ $tbl = 't_absenlog_'.$sh; } else if($sh == 'sh3b'){ $tbl = 't_absenlog_sh3b'; } else if($sh == 'sh1b'){ $tbl = 't_absenlog_sh1b'; } else if($sh == 'sh1a'){ $tbl = 't_absenlog_citragarden'; } else { $tbl = 't_absenlog'; } return $tbl; } /* Untuk SH3A MCJ dan WUM */ function set_project_pt() { $sql = " SELECT * FROM ".$this->t_absenlog." WHERE (transfer = 0 or transfer is null) and (project_id is null or project_id = 0) and (pt_id is null or pt_id = 0)"; $exec = sqlsrv_query($this->db_absen, $sql); //echo $sql; $array = Array(); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $array[] = $row; } sqlsrv_free_stmt($exec); if (is_array($array) && count($array) > 0) { $result = $array; if($result){ foreach ($result as $key => $value) { $nik = $value['nik']; $project_pt = $this->get_project_pt_from_nik($nik, $this->sh); if($project_pt){ foreach ($project_pt as $key2 => $value2) { $project_id = $value2['project_id']; $pt_id = $value2['pt_id']; $sql = "UPDATE ".$this->t_absenlog." SET project_id = $project_id, pt_id = $pt_id " . "WHERE nik = '$nik' and (project_id is null or project_id = 0) and (pt_id is null or pt_id = 0)"; $exec = sqlsrv_query($this->db_absen, $sql); sqlsrv_free_stmt($exec); } } else { $sql = "UPDATE ".$this->t_absenlog." SET project_id = 0, pt_id = 0, notes = 'nik not found', transfer = 1 " . "WHERE nik = '$nik' and (project_id is null or project_id = 0) and (pt_id is null or pt_id = 0)"; $exec = sqlsrv_query($this->db_absen, $sql); sqlsrv_free_stmt($exec); } } } /* $project_id = 6; $pt_id = 40; $this->proses_transfer($project_id, $pt_id); $project_id = 4057; $pt_id = 78; $this->proses_transfer($project_id, $pt_id); */ } else { echo "No Data Found"; } $array_project_pt = $this->project_pt_absent(); if($array_project_pt != null){ foreach ($array_project_pt as $key => $value) { $project_id = $value['project_id']; $pt_id = $value['pt_id']; if($this->sh == 'sh3a_pkc'){ $this->proses_transfer($project_id, $pt_id); } else { $this->proses_transfer_v2($project_id, $pt_id); // membaca lembur different day } } } } public function transfer_by_sh() { $array_project_pt = $this->project_pt_absent(); if($array_project_pt != null){ foreach ($array_project_pt as $key => $value) { $project_id = $value['project_id']; $pt_id = $value['pt_id']; if($this->sh == 'sh3a_pkc' || $this->sh == 'sh3a_citradream'){ $this->proses_transfer($project_id, $pt_id); } else { $this->proses_transfer_v2($project_id, $pt_id); // membaca lembur different day } } } } public function proses_transfer($projectId, $ptId) { $date_field = 'date'; if($this->sh == 'sh3a_mcj'){ $date_field = 'date_ymd'; } $sql = " SELECT min(".$date_field.") as date_from, max(".$date_field.") as date_to FROM dbtemp_absen.dbo.".$this->t_absenlog." WHERE project_id=".$projectId." and pt_id=".$ptId." and nik != '' and (transfer = 0 or transfer is null) and ".$date_field." is not null "; $exec = sqlsrv_query($this->db_absen, $sql); if(!$exec){ die( print_r( sqlsrv_errors(), true)); } $arData_range = array(); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $arData_range[] = $row; } $from = ''; $to = ''; foreach ($arData_range as $row) { if($row['date_from'] != null){ $from = $row['date_from']->format('Y-m-d'); $to = $row['date_to']->format('Y-m-d'); } } sqlsrv_free_stmt($exec); if($from != '' && $to != ''){ /* kurang 1 hari */ $from_yesterday = date('Y-m-d', strtotime("-1 day", strtotime($from))); /* tambah 1 hari */ $to = date('Y-m-d', strtotime($to . "+1 days")); $sql = " SELECT distinct nik, ".$date_field." as date FROM dbtemp_absen.dbo.".$this->t_absenlog." WHERE project_id=$projectId and pt_id=$ptId and nik != '' and (transfer = 0 or transfer is null) ORDER BY nik, ".$date_field." ASC"; $exec = sqlsrv_query($this->db_absen, $sql); if(!$exec){ die( print_r( sqlsrv_errors(), true)); } $arData_date = array(); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $arData_date[] = $row; } sqlsrv_free_stmt($exec); /*and (transfer = 0 or transfer is null)*/ $sql = " SELECT distinct nik, ".$date_field." as date, time, project_id, pt_id FROM dbtemp_absen.dbo.".$this->t_absenlog." WHERE project_id=$projectId and pt_id=$ptId and nik != '' and [".$date_field."] between '" . $from_yesterday . "' and '" . $to . "' ORDER BY nik, ".$date_field.", time ASC"; $exec = sqlsrv_query($this->db_absen, $sql); if(!$exec){ die( print_r( sqlsrv_errors(), true)); } $arData = array(); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $arData[] = $row; } sqlsrv_free_stmt($exec); $arData_shift = $this->get_cek_shift($projectId, $ptId, $from, $to); foreach ($arData_date as $row) { $nomorKaryawan = $row['nik']; $tanggal = $row['date']->format('Y-m-d'); $holiday = 0; foreach ($arData_shift as $row_shift) { $dt = $row_shift['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row_shift['fingerprintcode'] && $row_shift['holyday'] == 1){ $holiday = 1; } } if($holiday == 0){ $time_in_hari_ini = $this->get_timein($arData, $tanggal, $nomorKaryawan, $arData_shift); $time_out_hari_ini = $this->get_timeout($arData, $tanggal, $nomorKaryawan, $arData_shift); if($time_in_hari_ini == '00:00:00' || $time_in_hari_ini == NULL){ $time_in_hari_ini = $this->get_timein_normal($arData, $tanggal, $nomorKaryawan); } if($time_out_hari_ini == '00:00:00' || $time_out_hari_ini == NULL){ $time_out_hari_ini = $this->get_timeout_normal($arData, $tanggal, $nomorKaryawan); } } else { $time_in_hari_ini = $this->get_timein_normal($arData, $tanggal, $nomorKaryawan); $time_out_hari_ini = $this->get_timeout_normal($arData, $tanggal, $nomorKaryawan); } if($time_in_hari_ini == $time_out_hari_ini){ $time_out_hari_ini = NULL; } $return = $this->sp_fingerprinttransfer_create_v2($projectId, $ptId, $nomorKaryawan, $tanggal, $time_in_hari_ini, $time_out_hari_ini); if($return){ $this->set_transfered($nomorKaryawan, $tanggal, $projectId, $ptId); } } } } // membaca lembur different day public function proses_transfer_v2($projectId, $ptId) { // mysql $sh = $this->checkSH($projectId); $sh = $sh[0]; $configintranet = $sh['dbintranet_name']; $config = $this->getConfigdata($configintranet); //var_dump($config); $mysqlcon = new mysqli( $config['host'], $config['user'], $config['password'], $config['database'], $config['port'] ); $date_field = 'date'; if($this->sh == 'sh3a_mcj'){ $date_field = 'date_ymd'; } $sql = " SELECT min(".$date_field.") as date_from, max(".$date_field.") as date_to FROM dbtemp_absen.dbo.".$this->t_absenlog." WHERE project_id=".$projectId." and pt_id=".$ptId." and nik != '' and (transfer = 0 or transfer is null) and ".$date_field." is not null "; $exec = sqlsrv_query($this->db_absen, $sql); if(!$exec){ die( print_r( sqlsrv_errors(), true)); } $arData_range = array(); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $arData_range[] = $row; } $from = ''; $to = ''; foreach ($arData_range as $row) { if($row['date_from'] != null){ $from = $row['date_from']->format('Y-m-d'); $to = $row['date_to']->format('Y-m-d'); } } sqlsrv_free_stmt($exec); if($from != '' && $to != ''){ /* kurang 1 hari */ $from_yesterday = date('Y-m-d', strtotime("-1 day", strtotime($from))); /* tambah 1 hari */ $to = date('Y-m-d', strtotime($to . "+1 days")); $sql = " SELECT distinct nik, ".$date_field." as date FROM dbtemp_absen.dbo.".$this->t_absenlog." WHERE project_id=$projectId and pt_id=$ptId and nik != '' and (transfer = 0 or transfer is null) ORDER BY nik, ".$date_field." ASC"; $exec = sqlsrv_query($this->db_absen, $sql); if(!$exec){ die( print_r( sqlsrv_errors(), true)); } $arData_date = array(); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $arData_date[] = $row; } sqlsrv_free_stmt($exec); //and transfer = 0 $sql = " SELECT distinct nik, ".$date_field." as date, time, project_id, pt_id FROM dbtemp_absen.dbo.".$this->t_absenlog." WHERE project_id=$projectId and pt_id=$ptId and nik != '' and [".$date_field."] between '" . $from_yesterday . "' and '" . $to . "' ORDER BY nik, ".$date_field.", time ASC"; $exec = sqlsrv_query($this->db_absen, $sql); if(!$exec){ die( print_r( sqlsrv_errors(), true)); } $arData = array(); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $arData[] = $row; } sqlsrv_free_stmt($exec); $arData_shift = $this->get_cek_shift($projectId, $ptId, $from, $to); foreach ($arData_date as $row) { $nomorKaryawan = $row['nik']; $tanggal = $row['date']->format('Y-m-d'); $holiday = 0; foreach ($arData_shift as $row_shift) { $dt = $row_shift['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row_shift['fingerprintcode'] && $row_shift['holyday'] == 1){ $holiday = 1; } } if($holiday == 0){ /////* 19 - 04 -2021 comment by wulan (bugs di a.n Djono Susanto, agus triyono (absensi 14 dan 15 april 2021 jadi salah in out nya) $time_in_hari_ini = $this->get_timein($arData, $tanggal, $nomorKaryawan, $arData_shift); // kalau ada lembur if ($configintranet) { $empid = $this->get_employee_id($projectId, $ptId, $nomorKaryawan); $sql = "SELECT * FROM th_lembur WHERE is_deleted=0 and status IN ('OPEN', 'CLOSED', 'SUBMIT') and different_day_out = 1 and assign_to = ".$empid." and lembur_dari like '".$tanggal."%'"; $mysqlquery = mysqli_query($mysqlcon, $sql); $mysqlcount = mysqli_num_rows($mysqlquery); if($mysqlcount > 0){ $tanggal_besok = date('Y-m-d', strtotime("+1 day", strtotime($tanggal))); $time_out_hari_ini = $this->get_timeout_difday($arData, $tanggal_besok, $nomorKaryawan); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal_besok == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_out_hari_ini){ unset($arData[$index]); } $index++; } } else { $time_out_hari_ini = $this->get_timeout($arData, $tanggal, $nomorKaryawan, $arData_shift); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_out_hari_ini){ unset($arData[$index]); } $index++; } } $sql = "SELECT * FROM th_lembur WHERE is_deleted=0 and status IN ('OPEN', 'CLOSED', 'SUBMIT') and different_day_in = 1 and assign_to = ".$empid." and lembur_dari like '".$tanggal."%'"; $mysqlquery = mysqli_query($mysqlcon, $sql); $mysqlcount = mysqli_num_rows($mysqlquery); if($mysqlcount > 0){ $tanggal_kemarin = date('Y-m-d', strtotime("-1 day", strtotime($tanggal))); $time_in_hari_ini = $this->get_time_paling_malam($arData, $tanggal_kemarin, $nomorKaryawan);; $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal_kemarin == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_in_hari_ini){ unset($arData[$index]); } $index++; } // kalau ada lembur yang in nya kemarin maka cari out di paling malam hari ini $time_out_hari_ini = $this->get_time_paling_malam($arData, $tanggal, $nomorKaryawan); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_out_hari_ini){ unset($arData[$index]); } $index++; } } } else { $time_out_hari_ini = $this->get_timeout($arData, $tanggal, $nomorKaryawan, $arData_shift); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_out_hari_ini){ unset($arData[$index]); } $index++; } } if($time_in_hari_ini == '00:00:00' || $time_in_hari_ini == NULL){ $time_in_hari_ini = $this->get_timein_normal($arData, $tanggal, $nomorKaryawan); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_in_hari_ini){ unset($arData[$index]); } $index++; } } if($time_out_hari_ini == '00:00:00' || $time_out_hari_ini == NULL){ $time_out_hari_ini = $this->get_timeout_normal($arData, $tanggal, $nomorKaryawan); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_out_hari_ini){ unset($arData[$index]); } $index++; } } /*$time_in_hari_ini = $this->get_timein_normal($arData, $tanggal, $nomorKaryawan); $time_out_hari_ini = $this->get_timeout_normal($arData, $tanggal, $nomorKaryawan);*/ } else { $time_in_hari_ini = $this->get_timein_normal($arData, $tanggal, $nomorKaryawan); $time_out_hari_ini = $this->get_timeout_normal($arData, $tanggal, $nomorKaryawan); // kalau ada lembur if ($configintranet) { $empid = $this->get_employee_id($projectId, $ptId, $nomorKaryawan); $sql = "SELECT * FROM th_lembur WHERE is_deleted=0 and status IN ('OPEN', 'CLOSED', 'SUBMIT') and different_day_out = 1 and assign_to = ".$empid." and lembur_dari like '".$tanggal."%'"; $mysqlquery = mysqli_query($mysqlcon, $sql); $mysqlcount = mysqli_num_rows($mysqlquery); if($mysqlcount > 0){ $tanggal_besok = date('Y-m-d', strtotime("+1 day", strtotime($tanggal))); $time_out_hari_ini = $this->get_timeout_difday($arData, $tanggal_besok, $nomorKaryawan); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal_besok == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_out_hari_ini){ unset($arData[$index]); } $index++; } } $sql = "SELECT * FROM th_lembur WHERE is_deleted=0 and status IN ('OPEN', 'CLOSED', 'SUBMIT') and different_day_in = 1 and assign_to = ".$empid." and lembur_dari like '".$tanggal."%'"; $mysqlquery = mysqli_query($mysqlcon, $sql); $mysqlcount = mysqli_num_rows($mysqlquery); if($mysqlcount > 0){ $tanggal_kemarin = date('Y-m-d', strtotime("-1 day", strtotime($tanggal))); $time_in_hari_ini = $this->get_time_paling_malam($arData, $tanggal_kemarin, $nomorKaryawan); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal_kemarin == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_in_hari_ini){ unset($arData[$index]); } $index++; } // kalau ada lembur yang in nya kemarin maka cari out di paling malam hari ini $time_out_hari_ini = $this->get_time_paling_malam($arData, $tanggal, $nomorKaryawan); $index = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik'] && $row2['time']->format('H:i:s') == $time_out_hari_ini){ unset($arData[$index]); } $index++; } } } } if($time_in_hari_ini == $time_out_hari_ini){ $time_out_hari_ini = NULL; } $return = $this->sp_fingerprinttransfer_create_v2($projectId, $ptId, $nomorKaryawan, $tanggal, $time_in_hari_ini, $time_out_hari_ini); if($return){ $this->set_transfered($nomorKaryawan, $tanggal, $projectId, $ptId); } } } } function get_timein_normal($arData, $tanggal, $nomorKaryawan){ foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik']){ $time = $row2['time']->format('H:i:s'); // paling pagi hari ini return $time; exit; } } return null; } function get_timein_difday($arData, $tanggal, $nomorKaryawan){ $i = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik']){ $i++; if($i == 2){ $time_in_hari_ini = $row2['time']->format('H:i:s'); return $time_in_hari_ini; exit; } } } return null; } function get_timeout_normal($arData, $tanggal, $nomorKaryawan){ /* $i = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik']){ $i++; if($i == 2){ $time_out_hari_ini = $row2['time']->format('H:i:s'); return $time_out_hari_ini; exit; } } } return null; */ $i = 0; $time = null; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik']){ $time = $row2['time']->format('H:i:s'); } } return $time; } function get_timeout_difday($arData, $tanggal_besok, $nomorKaryawan){ $i = 0; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal_besok == $dt && $nomorKaryawan == $row2['nik']){ $i++; if($i == 1){ $time_out_hari_ini = $row2['time']->format('H:i:s'); return $time_out_hari_ini; exit; } } } return null; } // cari paling malam function get_time_paling_malam($arData, $tanggal, $nomorKaryawan){ $i = 0; $time = null; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row2['nik']){ $time = $row2['time']->format('H:i:s'); } } return $time; } public function get_cek_shift($projectId, $ptId, $tanggal_from, $tanggal_to) { $sql = " SELECT c.different_day, a.shifttype_id, c.in_time, c.out_time, a.date, d.fingerprintcode, c.holyday FROM td_absentdetail as a LEFT JOIN th_absent as b on b.absent_id = a.absent_id LEFT JOIN m_shifttype as c on a.shifttype_id = c.shifttype_id LEFT JOIN m_employee as d on b.employee_id = d.employee_id WHERE a.deleted=0 AND b.deleted=0 AND a.date between '".$tanggal_from."' and '".$tanggal_to."' AND b.project_id = ".$projectId." AND b.pt_id = ".$ptId; $array = array(); $exec = sqlsrv_query($this->db_hrd, $sql); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $array[] = $row; } sqlsrv_free_stmt($exec); return $array; } function get_timein($arData, $tanggal, $nomorKaryawan, $arData_shift){ $shift_in_time = ''; foreach ($arData_shift as $row_shift) { $dt = $row_shift['date']->format('Y-m-d'); if($tanggal == $dt && $nomorKaryawan == $row_shift['fingerprintcode']){ if($row_shift['in_time'] != null){ $shift_in_time = $dt . ' ' . $row_shift['in_time']->format('H:i:s'); } else { $shift_in_time = ''; } break; } } $min_time = ''; if($shift_in_time != ''){ //echo $shift_in_time.'
'; // cari jam paling pagi antara 3 jam sebelum dan 4 jam sesudah time in shift $shift_range1 = date('Y-m-d H:i:s', strtotime('-6 hour', strtotime($shift_in_time))); $shift_range2 = date('Y-m-d H:i:s', strtotime('+6 hour', strtotime($shift_in_time))); //echo $shift_range1 . ' s.d '. $shift_range2 . '
'; $i = 0; $min_time = ''; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($nomorKaryawan == $row2['nik']){ $time = $dt . ' ' . $row2['time']->format('H:i:s'); if($time >= $shift_range1 && $time <= $shift_range2){ if($min_time == '' || $time < $min_time){ $min_time = $time; } } } } } if($min_time == ''){ return NULL; } else { $min_time = date("H:i:s", strtotime($min_time)); return $min_time; } } function get_timeout($arData, $tanggal, $nomorKaryawan, $arData_shift){ $shift_out_time = ''; foreach ($arData_shift as $row_shift) { $dt = $row_shift['date']->format('Y-m-d'); if($row_shift['out_time'] != null && $tanggal == $dt && $nomorKaryawan == $row_shift['fingerprintcode']){ $shift_out_time = $dt . ' ' . $row_shift['out_time']->format('H:i:s'); $different_day = $row_shift['different_day']; if($different_day){ $shift_out_time = date('Y-m-d H:i:s', strtotime('+1 day', strtotime($shift_out_time))); } break; } } //echo 'out ' . $shift_out_time . '
'; // cari jam paling malam antara 1 jam sebelum out shift dan 7 jam sesudah time out shift $shift_range1 = date('Y-m-d H:i:s', strtotime('-6 hour', strtotime($shift_out_time))); $shift_range2 = date('Y-m-d H:i:s', strtotime('+7 hour', strtotime($shift_out_time))); //echo $shift_range1 . ' s.d '. $shift_range2 . '
'; $i = 0; $max_time = ''; foreach ($arData as $row2) { $dt = $row2['date']->format('Y-m-d'); if($nomorKaryawan == $row2['nik']){ $time = $dt . ' ' .$row2['time']->format('H:i:s'); //echo "$time >= $shift_range1 && $time <= $shift_range2
"; if($time >= $shift_range1 && $time <= $shift_range2){ if($max_time == '' || $time > $max_time){ $max_time = $time; } } } } if($max_time == ''){ return NULL; } else { $max_time = date("H:i:s", strtotime($max_time)); return $max_time; } } public function get_project_pt_from_nik($nik) { $sh = $this->sh; // cari project_id dan pt_id dari sh3a kecuali : // hotel ciputra semarang, mall ciputra semarang, mall ciputra jakarta, warna usaha mandiri, CIPUTRA WORLD 1 JAKARTA (OPERATIONAL) // karena hotel ciputra semarang dan mall ciputra semarang tidak unik dan kiriman dari sana sudah ada project pt id // karena mall ciputra jakarta dan warna usaha mandiri kemungkinan tidak unik, maka dibuat function baru // karena CIPUTRA WORLD 1 JAKARTA (OPERATIONAL) (1002) kemungkinan tidak unik, maka dibuat function baru if($sh == 'sh3a'){ $sql = " select distinct a.project_id, a.pt_id from m_employee a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and employee_active = 1 and a.deleted = 0 and a.project_id not in (7, 4052, 6, 4057, 1002) and fingerprintcode = '$nik'"; } else if($sh == 'sh3a_mcj'){ // cari project_id dan pt_id mall ciputra jakarta dan warna usaha mandiri $sql = " select distinct a.project_id, a.pt_id from m_employee a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and employee_active = 1 and a.deleted = 0 and a.project_id in (6, 4057) and fingerprintcode = '$nik' "; } else if($sh == 'sh3a_pkc'){ // cari project_id dan pt_id CIPUTRA WORLD 1 JAKARTA (OPERATIONAL) $sql = " select distinct a.project_id, a.pt_id from m_employee a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and employee_active = 1 and a.deleted = 0 and a.project_id in (1002) and a.pt_id in (4225) and fingerprintcode = '$nik' "; } else if($sh == 'sh3a_ci'){ // cari project_id dan pt_id Ciputra Internasional (Operational) - PT CPT dan PKC $sql = " select distinct a.project_id, a.pt_id from m_employee a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and employee_active = 1 and a.deleted = 0 and a.project_id in (4047) and a.pt_id in (4225, 3165) and fingerprintcode = '$nik' "; } else if($sh == 'sh3a_citradream'){ // cari project_id dan pt_id Citradream $sql = " select distinct a.project_id, a.pt_id from m_employee a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and employee_active = 1 and a.deleted = 0 and a.project_id in (4049) and a.pt_id in (3186) and fingerprintcode = '$nik' "; } /* Dari mesin finger sudah ada project pt else if($sh == 'sh3a_hcs'){ // cari project_id dan pt_id mall ciputra jakarta dan warna usaha mandiri $sql = " select distinct a.project_id, a.pt_id from m_employee a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and employee_active = 1 and a.deleted = 0 and a.project_id in (7, 4052) and fingerprintcode = '$nik' "; }*/ //echo $sql; exit; $exec = sqlsrv_query($this->db_hrd, $sql); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $array[] = $row; } sqlsrv_free_stmt($exec); if(isset($array)){ if (is_array($array) && count($array) > 0) { return $array; } else { return null; } } else { return null; } } public function sp_fingerprinttransfer_create_v2($project_id, $pt_id, $nik, $date, $timein, $timeout) { $sql = " SELECT * FROM td_absentfingerprint WHERE date = '$date' and psnno = '$nik' and project_id = $project_id and pt_id = $pt_id"; // echo $sql; exit; $fingerprintprocess_id = 0; $exec = sqlsrv_query($this->db_hrd, $sql); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $fingerprintprocess_id = $row['fingerprintprocess_id']; } if($fingerprintprocess_id != 0){ $sql_2 = " update td_absentfingerprint set time_in = '$timein', time_out = '$timeout', modion = GETDATE(), modiby = 99 where fingerprintprocess_id = $fingerprintprocess_id;"; } else { $sql_2 = " insert into td_absentfingerprint (psnno,psnname,time_in,time_out,date,addon,addby,project_id,pt_id) values('$nik', '', '$timein', '$timeout', '$date', GETDATE(), 99, $project_id, $pt_id);"; } //echo $sql_2.'
'; //exit; $exec = sqlsrv_query($this->db_hrd, $sql_2); if(!$exec){ $this->create_log_fp($sql_2); } else { $this->update_absentdetail_inout($project_id, $pt_id, $nik, $date, $timein, $timeout); // lebih cepat //$this->update_absentdetail_inout_v2($project_id, $pt_id, $nik, $date, $timein, $timeout); } return $exec; } public function update_absentdetail_inout($project_id, $pt_id, $nik, $date, $timein, $timeout) { $employee_id = 0; $sql = " select employee_id from m_employee where fingerprintcode = '$nik' and project_id = '$project_id' and pt_id = '$pt_id' and deleted = 0 and employee_active=1"; $exec = sqlsrv_query($this->db_hrd, $sql); $row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC); $employee_id = $row['employee_id']; $absent_id = 0; $exp = explode('-', $date); $m = $exp[1]; $y = $exp[0]; $sql = " select absent_id from th_absent where employee_id = '$employee_id' and project_id = '$project_id' and pt_id = '$pt_id' and deleted = 0 and month = '$m' and year = '$y'"; $exec = sqlsrv_query($this->db_hrd, $sql); $row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC); $absent_id = $row['absent_id']; $absentdetail_id = 0; $sql = " select absentdetail_id from td_absentdetail where absent_id = '$absent_id' and deleted = 0 and date = '$date'"; $exec = sqlsrv_query($this->db_hrd, $sql); $row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC); $absentdetail_id = $row['absentdetail_id']; $sql_2 = " update td_absentdetail set time_in = '$timein', time_out = '$timeout', modion = GETDATE(), modiby = 99 where (user_edit = 0 or user_edit is null) and absentdetail_id = $absentdetail_id"; //echo $sql_2; exit; $exec = sqlsrv_query($this->db_hrd, $sql_2); //echo date('H:i:s').'
'; } public function update_absentdetail_inout_v2($project_id, $pt_id, $nik, $date, $timein, $timeout) { $sql = " select absentdetail_id from td_absentdetail where deleted = 0 and date = '$date' and absent_id in ( select top 1 absent_id from th_absent where employee_id in (select top 1 employee_id from m_employee where fingerprintcode = '$nik' and project_id = '$project_id' and pt_id = '$pt_id') and month = month('$date') and year = year('$date') and deleted = 0 )"; $exec = sqlsrv_query($this->sqlsrv_hrd, $sql); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $absentdetail_id = $row['absentdetail_id']; $sql_2 = " update td_absentdetail set time_in = '$timein', time_out = '$timeout', modion = GETDATE(), modiby = 99 where (user_edit = 0 or user_edit is null) and absentdetail_id = $absentdetail_id"; //echo $sql_2; exit; $exec = sqlsrv_query($this->sqlsrv_hrd, $sql_2); } //echo date('H:i:s').'
'; } public function set_transfered($nik, $date, $project_id, $pt_id) { $sh = $this->sh; if($sh == 'sh3a_mcj'){ $sql = " UPDATE ".$this->t_absenlog." SET transfer = 1 WHERE nik = '$nik' and date_ymd = '$date' and project_id = '$project_id' and pt_id = '$pt_id' "; } else { $sql = " UPDATE ".$this->t_absenlog." SET transfer = 1 WHERE nik = '$nik' and date = '$date' and project_id = '$project_id' and pt_id = '$pt_id' "; } //echo $sql.'
'; // exit; $exec = sqlsrv_query($this->db_absen, $sql); sqlsrv_free_stmt($exec); return 1; } public function create_log_fp($message) { $log = "User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a") . PHP_EOL . "Attempt: " . $message . PHP_EOL . "-------------------------" . PHP_EOL; //Save string to log, use FILE_APPEND to append. file_put_contents('logs_hrd_transfer/log_fingerprint_' . date("Ymd") . '.txt', $log, FILE_APPEND); } /* Proses tombol Absent di absent Record*/ public function project_pt_absent() { $sh = $this->sh; if($sh == 'sh3a'){ $sql = " select distinct a.project_id, a.pt_id from t_absenlog_sh3a a where a.project_id not in (6, 4057, 7, 4052)"; } else if($sh == 'sh3a_mcj'){ $sql = " select distinct a.project_id, a.pt_id from t_absenlog_sh3a_mcj a where a.project_id in (6, 4057)"; } else if($sh == 'sh3a_pkc'){ $sql = " select distinct a.project_id, a.pt_id from t_absenlog_sh3a_pkc a where a.project_id = 1002 and a.pt_id = 4225"; } else if($sh == 'sh3a_hcs'){ $sql = " select distinct a.project_id, a.pt_id from t_absenlog_sh3a a where a.project_id in (7, 4052)"; } else if($sh == 'kp'){ $sql = " select distinct a.project_id, a.pt_id from t_absenlog a where a.project_id in (1)"; } else if($sh == 'sh3b' || $sh == 'sh3a_ci' || $sh == 'sh3a_citradream' || $sh == 'sh3a_cw2' || $sh == 'sh3a_newton1'){ $sql = " select distinct a.project_id, a.pt_id from ".$this->t_absenlog." a"; } else if($sh == 'sh1a'){ $sql = " select distinct a.project_id, a.pt_id from t_absenlog_citragarden a"; } $array = array(); $exec = sqlsrv_query($this->db_absen, $sql); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $array[] = $row; } sqlsrv_free_stmt($exec); if (is_array($array) && count($array) > 0) { return $array; } else { return null; } } public function project_pt_my_absent() { $sh = $this->sh; $end = date('Y-m-d'); // hari ini $start = date('Y-m-d', strtotime(date('Y-m-01') .' -1 months')); // tanggal 1 bulan lalu if($sh == 'sh3a'){ $sql = " select distinct a.project_id, a.pt_id, month, year from hrd.dbo.th_absent a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and datefromparts(a.year, a.month, 01) between '$start' and '$end' and a.project_id not in (6, 4057, 4052) order by a.year, a.month desc"; } else if($sh == 'sh3a_mcj'){ $sql = " select distinct a.project_id, a.pt_id, a.month, a.year from hrd.dbo.th_absent a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and datefromparts(a.year, a.month, 01) between '$start' and '$end' and a.project_id in (6, 4057) order by a.year, a.month desc"; } else if($sh == 'sh3a_pkc'){ $sql = " select distinct a.project_id, a.pt_id, a.month, a.year from hrd.dbo.th_absent a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and datefromparts(a.year, a.month, 01) between '$start' and '$end' and a.project_id in (1002) and a.pt_id in (4225) order by a.year, a.month desc"; } else if($sh == 'sh3a_hcs'){ $sql = " select distinct a.project_id, a.pt_id, a.month, a.year from hrd.dbo.th_absent a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 3 and datefromparts(a.year, a.month, 01) between '$start' and '$end' and a.project_id in (4052, 7) order by a.year, a.month desc"; } else if($sh == 'kp'){ $sql = " select distinct a.project_id, a.pt_id, a.month, a.year from hrd.dbo.th_absent a join dbmaster.dbo.m_project b on a.project_id = b.project_id where datefromparts(a.year, a.month, 01) between '$start' and '$end' and a.project_id in (1) order by a.year, a.month desc"; } else if($sh == 'sh3b'){ $sql = " select distinct a.project_id, a.pt_id, a.month, a.year from hrd.dbo.th_absent a join dbmaster.dbo.m_project b on a.project_id = b.project_id where (b.subholding_id = 4 or b.project_id = 69) and datefromparts(a.year, a.month, 01) between '$start' and '$end' order by a.year, a.month desc"; } else if($sh == 'sh1a'){ $sql = " select distinct a.project_id, a.pt_id, a.month, a.year from hrd.dbo.th_absent a join dbmaster.dbo.m_project b on a.project_id = b.project_id where b.subholding_id = 1 and b.subholding_subname = 'sh1a' and datefromparts(a.year, a.month, 01) between '$start' and '$end' order by a.year, a.month desc"; } $array = array(); $exec = sqlsrv_query($this->db_hrd, $sql); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $array[] = $row; } sqlsrv_free_stmt($exec); if (is_array($array) && count($array) > 0) { return $array; } else { return null; } } public function get_employee_id($projectId, $ptId, $no) { $sql = " SELECT employee_id FROM m_employee as a WHERE a.deleted = 0 AND a.employee_active = 1 AND a.fingerprintcode = '".$no."' AND a.project_id = ".$projectId." AND a.pt_id = ".$ptId; $employee_id = 0; $array = array(); $exec = sqlsrv_query($this->db_hrd, $sql); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $employee_id = $row['employee_id']; } sqlsrv_free_stmt($exec); return $employee_id; } function getConfigdata($config) { $paramconfig = $this->getfileConfig($config); if($paramconfig !==0){ $data['host'] = $paramconfig['intranet_host']; $data['user'] = $paramconfig['intranet_username']; $data['password'] = $paramconfig['intranet_password']; $data['port'] = $paramconfig['intranet_port']; $data['database_sec'] = $paramconfig['database_sec']; $data['database_master'] = $paramconfig['database_master']; $data['database'] = $paramconfig['intranet_database']; }else{ $data['host'] = null; $data['user'] = null; $data['password'] = null; $data['port'] = null; $data['database_sec'] = null; $data['database_master'] = null; $data['database'] = null; } return $data; } function getfileConfig($config) { $base = getcwd() . '/configs/' . $config . '.ini'; //get common config $checkfile = file_exists($base); //check file exist or not yet if ($checkfile > 0) { $file_contents = fopen($base, "r"); //read file file .ini $dataconfig = array(); while (!feof($file_contents)) { //loop all text in main.ini $line_of_text = fgets($file_contents); //loop one line from file .ini /* start db intranet config */ if (stripos($line_of_text, "dbintranet.host") !== false) { $string = preg_replace('/\s+/', '', $line_of_text); //remove space $dataconfig['intranet_host'] = str_replace("dbintranet.host=", "", $string); //remove text } if (stripos($line_of_text, "dbintranet.username") !== false) { $string = preg_replace('/\s+/', '', $line_of_text); //remove space $dataconfig['intranet_username'] = str_replace("dbintranet.username=", "", $string); //remove text } if (stripos($line_of_text, "dbintranet.password") !== false) { $string = preg_replace('/\s+/', '', $line_of_text); //remove space $dataconfig['intranet_password'] = str_replace("dbintranet.password=", "", $string); //remove text } if (stripos($line_of_text, "dbintranet.dbname") !== false) { $string = preg_replace('/\s+/', '', $line_of_text); //remove space $dataconfig['intranet_database'] = str_replace("dbintranet.dbname=", "", $string); //remove text } if (stripos($line_of_text, "dbintranet.port") !== false) { $string = preg_replace('/\s+/', '', $line_of_text); //remove space $dataconfig['intranet_port'] = str_replace("dbintranet.port=", "", $string); //remove text } /* end db intranet config */ if (stripos($line_of_text, "dbwebsec.dbname") !== false) { $string = preg_replace('/\s+/', '', $line_of_text); //remove space $dataconfig['database_sec'] = str_replace("dbwebsec.dbname=", "", $string); //remove text } if (stripos($line_of_text, "dbmaster.dbname") !== false) { $string = preg_replace('/\s+/', '', $line_of_text); //remove space $dataconfig['database_master'] = str_replace("dbmaster.dbname=", "", $string); //remove text } } return $dataconfig; //set configuration from file .ini fclose($file_contents); }else{ return 0; } } function checkSH($project_id) { $sql = " SELECT a.subholding_id, b.code, a.subholding_subname, a.dbintranet_name FROM dbmaster.dbo.m_project a JOIN dbmaster.dbo.m_subholding b on a.subholding_id = b.subholding_id WHERE project_id = $project_id"; $array = array(); $exec = sqlsrv_query($this->db_hrd, $sql); while ($row = sqlsrv_fetch_array($exec, SQLSRV_FETCH_ASSOC)) { $array[] = $row; } sqlsrv_free_stmt($exec); if (is_array($array) && count($array) > 0) { return $array; } else { return null; } } function absent() { session_start(); $array = $this->project_pt_my_absent(); if($array){ $_SESSION['sess_projectpt_absent_sh3a'] = $array; $url = $_SERVER['SERVER_NAME'].':8080' . dirname($_SERVER['REQUEST_URI']).'/hrd/public/absentrecord/cronabsent'; header("Location: http://".$url); die(); } else{ echo "No Data Found"; } } /* added by wulan 27 okt 2020, untuk kebutuhan MCS */ function mcs_temp_proses() { $sql = "EXEC dbtemp_absen.dbo.sp_sh3a_mcs_temp_proses"; sqlsrv_query($this->db_absen, $sql); } }