<?php
class M_jenis_pelayanan extends CI_Model
{
	function __construct()
	{
		parent::__construct();
	}

	function kode_user()
	{
		return $this->session->userdata("kode_user");
	}

	function data_jenis_pelayanan()
	{
		$sql = "SELECT * FROM tb_jenis_pelayanan WHERE is_deleted = 0 ";
		return $this->db->query($sql);
	}

	public function get_all()
	{
		$this->db->where('is_deleted', 0);
		return $this->db->get('tb_jenis_pelayanan')->result();
	}

	function simpan_jenis_pelayanan($data)
	{
		$kode_user = $this->kode_user();
		$sql = "INSERT INTO `tb_jenis_pelayanan`  (`nama`, `created_at`, `created_by`) 
                VALUES ('$data[nama]',NOW(),'$kode_user')";
		return $this->db->query($sql);
	}

	function ambil_jenis_pelayanan($data)
	{
		$sql = "SELECT * FROM tb_jenis_pelayanan WHERE id_jenis_pelayanan = '$data[id_jenis_pelayanan]'";
		return $this->db->query($sql);
	}

	function update_jenis_pelayanan($data)
	{
		$kode_user = $this->kode_user();
		$sql = "UPDATE `tb_jenis_pelayanan` SET `nama`='$data[nama]', `updated_at`=NOW(),`updated_by`='$kode_user' WHERE id_jenis_pelayanan = '$data[id_jenis_pelayanan]'";
		return $this->db->query($sql);
	}

	function hapus_jenis_pelayanan($data)
	{
		$sql = "UPDATE `tb_jenis_pelayanan` SET `is_deleted`='1' WHERE id_jenis_pelayanan = '$data[id_jenis_pelayanan]'";
		return $this->db->query($sql);
	}
}
