<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class M_pegawai extends CI_Model
	{
		function __construct()
		{
			parent::__construct();
		}
		
		function login($email,$password)
		{
			$this->db->select('*');
			$this->db->from('pegawai');
			$this->db->where('email',$email);
			$this->db->where('password',$password);
			return $this->db->get();
		}
		
		function checkPassword($id_pegawai,$password)
		{
			$this->db->select('*');
			$this->db->from('pegawai');
			$this->db->where('id_pegawai',$id_pegawai);
			$this->db->where('password',$password);
			return $this->db->get();
		}
		
		function getPegawai($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('pegawai');
			$this->db->where('id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPegawaiAll()
		{
			$this->db->select('pegawai.id_pegawai,pegawai.no_pegawai,pegawai.nama,pegawai.gelar_depan,pegawai.gelar_belakang,unit_kerja.unit_kerja,pegawai.email,pegawai.nohp');
			$this->db->from('pegawai');
			$this->db->join('kepegawaian', 'pegawai.id_pegawai = kepegawaian.id_pegawai', 'left');
			$this->db->join('unit_kerja', 'kepegawaian.id_unit_kerja = unit_kerja.id_unit_kerja', 'left');
			$this->db->join('status_kepegawaian', 'kepegawaian.id_status_kepegawaian = status_kepegawaian.id_status_kepegawaian', 'left');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPegawaiAllDetail()
		{
			$this->db->select('pegawai.no_pegawai,pegawai.nama,pegawai.gelar_depan,pegawai.gelar_belakang,pegawai.alamat,pegawai.jenkel,pegawai.email,pegawai.nohp,pegawai.tempat_lahir,pegawai.tanggal_lahir,pegawai.gol_darah,kepegawaian.tahun_masuk,unit_kerja.unit_kerja,status_kepegawaian.status_kepegawaian');
			$this->db->from('pegawai');
			$this->db->join('kepegawaian', 'pegawai.id_pegawai = kepegawaian.id_pegawai', 'left');
			$this->db->join('unit_kerja', 'kepegawaian.id_unit_kerja = unit_kerja.id_unit_kerja', 'left');
			$this->db->join('status_kepegawaian', 'kepegawaian.id_status_kepegawaian = status_kepegawaian.id_status_kepegawaian', 'left');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getKepegawaian($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('kepegawaian');
			$this->db->join('pegawai', 'kepegawaian.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->join('unit_kerja', 'kepegawaian.id_unit_kerja = unit_kerja.id_unit_kerja', 'left');
			$this->db->join('status_kepegawaian', 'kepegawaian.id_status_kepegawaian = status_kepegawaian.id_status_kepegawaian', 'left');
			$this->db->where('kepegawaian.id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function getGajiPegawai($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('gaji');
			$this->db->join('pegawai', 'gaji.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->where('gaji.id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getUnitKerja()
		{
			$this->db->select('*');
			$this->db->from('unit_kerja');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getStatusKepegawaian()
		{
			$this->db->select('*');
			$this->db->from('status_kepegawaian');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getKeluarga($id_pegawai)
		{
			$this->db->select('keluarga_pegawai.nama,keluarga_pegawai.hubungan,pekerjaan_suami_istri.pekerjaan_suami_istri,keluarga_pegawai.tanggal_lahir,keluarga_pegawai.id_keluarga_pegawai');
			$this->db->from('keluarga_pegawai');
			$this->db->join('pegawai', 'keluarga_pegawai.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->join('pekerjaan_suami_istri', 'keluarga_pegawai.profesi = pekerjaan_suami_istri.id_pekerjaan_suami_istri', 'left');
			$this->db->where('keluarga_pegawai.id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getKeluargaDetail($id_keluarga_pegawai)
		{
			$this->db->select('keluarga_pegawai.nama,keluarga_pegawai.hubungan,pekerjaan_suami_istri.pekerjaan_suami_istri,pekerjaan_suami_istri.id_pekerjaan_suami_istri,keluarga_pegawai.tanggal_lahir,keluarga_pegawai.id_keluarga_pegawai');
			$this->db->from('keluarga_pegawai');
			$this->db->join('pegawai', 'keluarga_pegawai.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->join('pekerjaan_suami_istri', 'keluarga_pegawai.profesi = pekerjaan_suami_istri.id_pekerjaan_suami_istri', 'left');
			$this->db->where('keluarga_pegawai.id_keluarga_pegawai',$id_keluarga_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();
			}
			else
			{
				return array();	
			}
		}
		
		function getPekerjaanSuamiIstri()
		{
			$this->db->select('*');
			$this->db->from('pekerjaan_suami_istri');
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPenyakit($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('penyakit');
			$this->db->join('pegawai', 'penyakit.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->where('penyakit.id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPenyakitDetail($id_penyakit)
		{
			$this->db->select('*');
			$this->db->from('penyakit');
			$this->db->join('pegawai', 'penyakit.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->where('id_penyakit',$id_penyakit);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updatePegawai($id_pegawai,$data)
		{
			$this->db->where('id_pegawai',$id_pegawai);
			return $this->db->update('pegawai',$data);
		}
		
		function addKepegawaian($data)
		{
			return $this->db->insert('kepegawaian',$data);
		}
		
		function updateKepegawaian($id_pegawai,$data)
		{
			$this->db->where('id_pegawai',$id_pegawai);
			return $this->db->update('kepegawaian',$data);
		}
		
		function updateKeluarga($id_keluarga_pegawai,$data)
		{
			$this->db->where('id_keluarga_pegawai',$id_keluarga_pegawai);
			return $this->db->update('keluarga_pegawai',$data);
		}
		
		function deleteKeluarga($id_keluarga_pegawai)
		{
			$this->db->where('id_keluarga_pegawai',$id_keluarga_pegawai);
			return $this->db->delete('keluarga_pegawai');
		}
		
		function addKeluarga($data)
		{
			return $this->db->insert('keluarga_pegawai',$data);
		}
		
		function addGaji($data)
		{
			return $this->db->insert('gaji',$data);
		}
		
		function addPegawai($data)
		{
			return $this->db->insert('pegawai',$data);
		}
		
		function deletePegawai($id_pegawai)
		{
			$this->db->where('id_pegawai',$id_pegawai);
			return $this->db->delete('pegawai');
		}
		
		function addKesehatan($data)
		{
			return $this->db->insert('penyakit',$data);
		}
		
		function updateKesehatan($id_penyakit,$data)
		{
			$this->db->where('id_penyakit',$id_penyakit);
			return $this->db->update('penyakit',$data);
		}
		
		function deleteKesehatan($id_penyakit)
		{
			$this->db->where('id_penyakit',$id_penyakit);
			return $this->db->delete('penyakit');
		}
		
		function getPendidikan($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('pendidikan');
			$this->db->where('id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPendidikanDetail($id_pendidikan)
		{
			$this->db->select('*');
			$this->db->from('pendidikan');
			$this->db->join('pegawai', 'pendidikan.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->where('id_pendidikan',$id_pendidikan);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPelatihan($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('pelatihan');
			$this->db->where('id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getPrestasi($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('prestasi');
			$this->db->where('id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function getJabatan($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('jabatan');
			$this->db->join('unit_kerja', 'jabatan.id_unit_kerja = unit_kerja.id_unit_kerja', 'left');
			$this->db->where('id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addJabatan($data)
		{
			return $this->db->insert('jabatan',$data);
		}
		
		function getJabatanDetail($id_jabatan)
		{
			$this->db->select('*');
			$this->db->from('jabatan');
			$this->db->join('unit_kerja', 'unit_kerja.id_unit_kerja = jabatan.id_unit_kerja', 'left');
			$this->db->where('id_jabatan',$id_jabatan);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updateJabatan($id_jabatan,$data)
		{
			$this->db->where('id_jabatan',$id_jabatan);
			return $this->db->update('jabatan',$data);
		}
		
		function deleteJabatan($id_jabatan)
		{
			$this->db->where('id_jabatan',$id_jabatan);
			return $this->db->delete('jabatan');
		}
		
		function getRiwayatSK($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('riwayat_sk');
			$this->db->join('status_kepegawaian', 'riwayat_sk.id_status_kepegawaian = status_kepegawaian.id_status_kepegawaian', 'left');
			$this->db->where('id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addRiwayatSK($data)
		{
			return $this->db->insert('riwayat_sk',$data);
		}
		
		function getRiwayatSKDetail($id_riwayat_sk)
		{
			$this->db->select('*');
			$this->db->from('riwayat_sk');
			$this->db->join('status_kepegawaian', 'riwayat_sk.id_status_kepegawaian = status_kepegawaian.id_status_kepegawaian', 'left');
			$this->db->where('id_riwayat_sk',$id_riwayat_sk);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updateRiwayatSK($id_riwayat_sk,$data)
		{
			$this->db->where('id_riwayat_sk',$id_riwayat_sk);
			return $this->db->update('riwayat_sk',$data);
		}
		
		function deleteRiwayatSK($id_riwayat_sk)
		{
			$this->db->where('id_riwayat_sk',$id_riwayat_sk);
			return $this->db->delete('riwayat_sk');
		}
		
		function getNilai($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('nilai_pegawai');
			$this->db->where('id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addNilai($data)
		{
			return $this->db->insert('nilai_pegawai',$data);
		}
		
		function getNilaiDetail($id_nilai_pegawai)
		{
			$this->db->select('*');
			$this->db->from('nilai_pegawai');
			$this->db->where('id_nilai_pegawai',$id_nilai_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updateNilai($id_nilai_pegawai,$data)
		{
			$this->db->where('id_nilai_pegawai',$id_nilai_pegawai);
			return $this->db->update('nilai_pegawai',$data);
		}
		
		function deleteNilai($id_nilai_pegawai)
		{
			$this->db->where('id_nilai_pegawai',$id_nilai_pegawai);
			return $this->db->delete('nilai_pegawai');
		}
		
		function getPembinaan($id_pegawai)
		{
			$this->db->select('*');
			$this->db->from('riwayat_pembinaan');
			$this->db->where('id_pegawai',$id_pegawai);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->result_array();	
			}
			else
			{
				return array();	
			}
		}
		
		function addPembinaan($data)
		{
			return $this->db->insert('riwayat_pembinaan',$data);
		}
		
		function getPembinaanDetail($id_riwayat_pembinaan)
		{
			$this->db->select('*');
			$this->db->from('riwayat_pembinaan');
			$this->db->where('id_riwayat_pembinaan',$id_riwayat_pembinaan);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updatePembinaan($id_riwayat_pembinaan,$data)
		{
			$this->db->where('id_riwayat_pembinaan',$id_riwayat_pembinaan);
			return $this->db->update('riwayat_pembinaan',$data);
		}
		
		function deletePembinaan($id_riwayat_pembinaan)
		{
			$this->db->where('id_riwayat_pembinaan',$id_riwayat_pembinaan);
			return $this->db->delete('riwayat_pembinaan');
		}
		
		function addPelatihan($data)
		{
			return $this->db->insert('pelatihan',$data);
		}
		
		function addPendidikan($data)
		{
			return $this->db->insert('pendidikan',$data);
		}
		
		function getPelatihanDetail($id_pelatihan)
		{
			$this->db->select('*');
			$this->db->from('pelatihan');
			$this->db->join('pegawai', 'pelatihan.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->where('id_pelatihan',$id_pelatihan);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updatePelatihan($id_pelatihan,$data)
		{
			$this->db->where('id_pelatihan',$id_pelatihan);
			return $this->db->update('pelatihan',$data);
		}
		
		function updatePendidikan($id_pendidikan,$data)
		{
			$this->db->where('id_pendidikan',$id_pendidikan);
			return $this->db->update('pendidikan',$data);
		}
		
		function deletePelatihan($id_pelatihan)
		{
			$this->db->where('id_pelatihan',$id_pelatihan);
			return $this->db->delete('pelatihan');
		}
		
		function deletePendidikan($id_pendidikan)
		{
			$this->db->where('id_pendidikan',$id_pendidikan);
			return $this->db->delete('pendidikan');
		}
		
		function addPrestasi($data)
		{
			return $this->db->insert('prestasi',$data);
		}
		
		function getPrestasiDetail($id_prestasi)
		{
			$this->db->select('*');
			$this->db->from('prestasi');
			$this->db->join('pegawai', 'prestasi.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->where('id_prestasi',$id_prestasi);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updatePrestasi($id_prestasi,$data)
		{
			$this->db->where('id_prestasi',$id_prestasi);
			return $this->db->update('prestasi',$data);
		}
		
		function deletePrestasi($id_prestasi)
		{
			$this->db->where('id_prestasi',$id_prestasi);
			return $this->db->delete('prestasi');
		}
		
		function getGajiDetail($id_gaji)
		{
			$this->db->select('*');
			$this->db->from('gaji');
			$this->db->join('pegawai', 'gaji.id_pegawai = pegawai.id_pegawai', 'left');
			$this->db->where('id_gaji',$id_gaji);
			$result = $this->db->get();
			if ($result->num_rows() > 0 )
			{
				return $result->row();	
			}
			else
			{
				return array();	
			}
		}
		
		function updateGaji($id_gaji,$data)
		{
			$this->db->where('id_gaji',$id_gaji);
			return $this->db->update('gaji',$data);
		}
		
		function deleteGaji($id_gaji)
		{
			$this->db->where('id_gaji',$id_gaji);
			return $this->db->delete('gaji');
		}
	}
