<?php
class M_pelayanan extends CI_Model
{
	function list_data($id_jenis="")
	{
		$q = "SELECT p.id, p.nama, p.id_jenis_pelayanan, jp.nama nama_jenis_pelayanan, p.created_at, p.updated_at FROM pelayanan p
			LEFT JOIN jenis_pelayanan jp ON p.id_jenis_pelayanan = jp.id
			WHERE p.id is not null 
		";
		if ($id_jenis!="") {
			$q .= " AND p.id_jenis_pelayanan = '$id_jenis' ";
		}
		$q .= " ORDER BY p.created_at DESC";

		$query= $this->db->query($q);
		return $query;
	}

	function get_all()
	{
		$this->db->select('id, nama');
		$this->db->from('pelayanan');
		$this->db->order_by("nama", "asc");
		return $this->db->get();
	}

	function get_detail($id){
		$query= $this->db->get_where('pelayanan', array('id' => $id));
		return $query;
	}

	function alpha(){
		$query= $this->db->get_where('alpha', array('id_alpha' => 1));
		return $query;
	}

	function insert($data, $table)
	{
		$this->db->insert($table, $data);
	}

	function delete($where, $table)
	{
		$this->db->where($where);
		$this->db->delete($table);
	}

	function edit($where, $table)
	{
		return $this->db->get_where($table, $where);
	}

	function update($where, $data, $table)
	{
		$this->db->where($where);
		$this->db->update($table, $data);
	}
}
