124 lines
4.1 KiB
PHP
124 lines
4.1 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
class KaryawanModel extends CI_Model
|
|
{
|
|
public function create($table, $data, $batch = false)
|
|
{
|
|
if ($batch === false) {
|
|
$insert = $this->db->insert($table, $data);
|
|
} else {
|
|
$insert = $this->db->insert_batch($table, $data);
|
|
}
|
|
return $insert;
|
|
}
|
|
|
|
public function update($table, $data, $pk, $id = null, $batch = false)
|
|
{
|
|
if ($batch === false) {
|
|
$insert = $this->db->update($table, $data, array($pk => $id));
|
|
} else {
|
|
$insert = $this->db->update_batch($table, $data, $pk);
|
|
}
|
|
return $insert;
|
|
}
|
|
|
|
public function delete($table, $data, $pk)
|
|
{
|
|
$this->db->where_in($pk, $data);
|
|
return $this->db->delete($table);
|
|
}
|
|
|
|
public function getDataKaryawan($id = null)
|
|
{
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b', 'b.ID_JABATAN=a.JABATAN_ID');
|
|
$this->db->join('cabang c', 'c.KODE_CABANG=b.CABANG_KODE');
|
|
$this->db->order_by('a.STATUS_KARYAWAN DESC');
|
|
$this->db->order_by('a.ID_KARYAWAN ASC ');
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b', 'b.ID_JABATAN=a.JABATAN_ID');
|
|
$this->db->join('cabang c', 'c.KODE_CABANG=b.CABANG_KODE');
|
|
$this->db->where(['ID_KARYAWAN' => $id]);
|
|
$this->db->order_by('a.STATUS_KARYAWAN DESC');
|
|
$this->db->order_by('a.ID_KARYAWAN ASC ');
|
|
}
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
public function getDataKaryawan_Cabang_Kode($kode)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b', 'b.ID_JABATAN=a.JABATAN_ID');
|
|
$this->db->join('cabang c', 'c.KODE_CABANG=b.CABANG_KODE');
|
|
$this->db->where(['b.CABANG_KODE' => $kode]);
|
|
$this->db->order_by('a.STATUS_KARYAWAN DESC');
|
|
$this->db->order_by('a.ID_KARYAWAN ASC ');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getDataKaryawan1()
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan ');
|
|
|
|
$this->db->where(['JABATAN_ID' => null]);
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function cekPass($id, $pass)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan');
|
|
$this->db->where(['ID_KARYAWAN' => $id]);
|
|
$this->db->where(['PASSWORD' => $pass]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
public function getDataCabang()
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('cabang');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
public function getKodeCabangByIdKaryawan($id)
|
|
{
|
|
$this->db->select('b.CABANG_KODE');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b', 'b.ID_JABATAN=a.JABATAN_ID');
|
|
$this->db->where(['ID_KARYAWAN' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
public function getDataKaryawanByKodeCabang($kode)
|
|
{
|
|
$this->db->select('a.ID_KARYAWAN, a.NAMA_KARYAWAN');
|
|
$this->db->from('karyawan a');
|
|
$this->db->join('jabatan b', 'b.ID_JABATAN=a.JABATAN_ID');
|
|
$this->db->join('cabang c', 'c.KODE_CABANG=a.CABANG_KODE');
|
|
$this->db->where(['c.KODE_CABANG' => $kode]);
|
|
$this->db->where(['a.STATUS_KARYAWAN' => 1]);
|
|
$this->db->order_by('a.ID_KARYAWAN ASC ');
|
|
return $this->db->get()->result_array();
|
|
}
|
|
public function getIdKaryawanTerakhir($cabang)
|
|
{
|
|
$this->db->select('ID_KARYAWAN');
|
|
$this->db->from('karyawan');
|
|
$this->db->like('ID_KARYAWAN', $cabang, 'after');
|
|
$this->db->order_by('IK DESC');
|
|
$this->db->limit(1);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
public function getUsername($username)
|
|
{
|
|
$this->db->select('*');
|
|
$this->db->from('karyawan');
|
|
$this->db->where(['USERNAME' => $username]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
}
|