<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sysumconv extends CI_Model{
	
	public function sysumconv_all(){
		$this->db->select('a.*');
		$this->db->select('b.desc as fromUM');
		$this->db->select('c.desc as toUM');
		$this->db->from('_sys_um_conv a');
		$this->db->join('_sys_um b', 'b.fldid = a.from_um', 'left outer');	
		$this->db->join('_sys_um c', 'c.fldid = a.to_um', 'left outer');	
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}

	public function sysumconv_insert($newdept){
		$sql = $this->db->insert_string('_sys_um_conv', $newdept);
		$query = $this->db->query($sql);
		if($query === TRUE){
			return TRUE;
		} else {
			$last_query = $this->db->last_query();
			return $last_query;
		}
	}

	public function sysumconv_edit($updatedept, $fldid){
		$this->db->where('fldid', $fldid);
		$query = $this->db->update('_sys_um_conv', $updatedept); 
		if($query === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}

	public function sysumconv_id($id){
		$query = $this->db->get_where('_sys_um_conv', array('fldid'=>$id), 1);		
		if($query->num_rows() == 1){
			return $query->result();
		}else{
			return false;
		}
	}
	
	public function sysumconv_save($fldid, $data){
		$this->db->where('fldid', $fldid);
		$query = $this->db->update('_sys_um_conv', $data); 
		if($query === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}
	public function sysumconv_delete($fldid){
		$this->db->where('fldid', $fldid);
		$query = $this->db->delete('_sys_um_conv'); 
		if($query === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}

}