<?php
	class Umum_model extends CI_Model {
		function __construct()
		{
			parent::__construct();
			
			// DETERMINE DB
			//$this->dbhost=$this->load->database('hospistar', TRUE);
			//$this->nm_db = array('1' => 'jobs', 'db_hro', '');
			//$this->user_admin = 'user_admin';
		}	
		
		function getIdBarang()
		{
			$q=$this->db->query("SELECT IF (LENGTH(COALESCE(MAX(RIGHT(kd_brg,3))+1,'1'))= 1, CONCAT(REPLACE(MID(DATE(NOW()),3,5),'-',''),'00',COALESCE(MAX(RIGHT(kd_brg,3))+1,'1')),
IF (LENGTH(COALESCE(MAX(RIGHT(kd_brg,3))+1,'1'))= 2, CONCAT(REPLACE(MID(DATE(NOW()),3,5),'-',''),'0',COALESCE(MAX(RIGHT(kd_brg,3))+1,'1')),
CONCAT(REPLACE(MID(DATE(NOW()),3,5),'-',''),COALESCE(MAX(RIGHT(kd_brg,3))+1,'1')))) AS idbrg 
FROM `umum_barang` WHERE LEFT(kd_brg,4)=REPLACE(MID(DATE(NOW()),3,5),'-','');");
			return $q->result();
		}
		
		function getDataBarang()
		{
			
			$q=$this->db
				->select('a.*, b.jenis, c.merk')
				->from('`umum_barang` AS a')
				->join('umum_jenis AS b','a.`id_jenis`=b.`id_jenis`','left')
				->join('umum_merk AS c','a.`id_merk`=c.`id_merk`','left')
				//->where_in('a.NurseStation', $stat)
				//->order_by('a.`id_poli`')
				->get();
			return $q->result();
		}
		
		function getJenis()
		{
			 $q = $this->db->get_where('umum_jenis');
			 return $q->result();
		}
		
		function getMerk()
		{
			 $q = $this->db->get_where('umum_merk');
			 return $q->result();
		}
		
		function getLokasi()
		{
			 $q = $this->db->get_where('umum_lokasi');
			 return $q->result();
		}
		
		function getPekerjaan()
		{
			 $q = $this->db->get_where('umum_pekerjaan');
			 return $q->result();
		}
		
		function getPelaksana()
		{
			 $q = $this->db->get_where('umum_pelaksana');
			 return $q->result();
		}
	}
