Skip to content

Instantly share code, notes, and snippets.

@paulobunga
Created October 30, 2018 20:26
Show Gist options
  • Save paulobunga/674857af131fc9853dc56d37a50de37c to your computer and use it in GitHub Desktop.
Save paulobunga/674857af131fc9853dc56d37a50de37c to your computer and use it in GitHub Desktop.
Copy and paste
public function clock_user($fingerprint, $stimestamp, $facilityId) {
$query = $this->db->get_where('fingerprints', array('fingerprint' => $fingerprint, 'facilityId'=> $facilityId));
$result = $query->row();
if($query->num_rows() > 0) {
// return $result->ihris_pid;
$timestamp = strtotime($stimestamp);
$date = date('d-m-Y', $timestamp);
$time = date('H:i:s', $timestamp);
$this->db->select("*");
$this->db->from("time_log");
$this->db->where("date", $date);
$this->db->where("ihris_pid", $result->ihris_pid);
$query = $this->db->get();
if($query->num_rows() > 0) {
$entry_id = $facilityId . $result->ihris_pid;
$this->db->update('time_log', array('time_out'=> $time, 'date'=> $date, 'status'=> 'clocked_out'), array('entry_id' => $entry_id));
return ($this->db->affected_rows() > 0);
} else {
$data = array(
'entry_id'=> $facilityId . $result->ihris_pid,
'ihris_pid'=> $result->ihris_pid,
'facility_id'=> $facilityId,
'time_in'=>$time,
'time_out'=> '',
'status'=>'clocked_in',
'date'=>$date
);
$this->db->insert('time_log', $data);
return ($this->db->affected_rows() > 0);
}
} else {
return false;
}
}
public function enroll_user($fingerprint, $ihrispid, $facilityId) {
$entry_id = $facilityId . 'person|' . $ihrispid;
$this->db->select('entry_id');
$this->db->from('fingerprints');
$this->db->where('entry_id', $entry_id);
$query = $this->db->get();
if($query->num_rows() > 0) {
return false;
} else {
$this->db->insert('fingerprints', array(
'entry_id' => $entry_id,
'fingerprint' => $fingerprint,
'ihris_pid' => 'person|' . $ihrispid,
'facilityId' => $facilityId
));
return ($this->db->affected_rows() > 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment