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

class M_terms extends CI_Model {
	
	public $table = "am_termspayment";	
	
	function get_all(){
	    //$this->db->select("*,(case when TransStatus=0 then 'Aktif' else 'Suspended' end) as Status");
        $Code = $this->input->post('NetDueIn') ? $this->input->post('NetDueIn') : '';
        $Name = $this->input->post('TermDesc') ? $this->input->post('TermDesc') : '';
		    
        $this->db->where_in('am_termspayment.TransStatus',array(0,1));
		$this->db->like('am_termspayment.NetDueIn',$Code); 
		$this->db->like('am_termspayment.TermDesc',$Name); 
		
		$query 		 = $this->db->get($this->table);
                
        return $query->result();
    }
	
	function get_detail($id){
        $query = $this->db->get_where($this->table, array('TermspaymentID' => $id));
        if($query->num_rows()>0){
			return $query->row();
		}
		else{
			return false;
		}  
    }

	function insert($data) {
//		$this->db->trans_begin();
		$this->db->insert($this->table, $data);
//		
//		if ($this->db->trans_status() === FALSE) {
//			$this->db->trans_rollback();
//			return 0;
//		}
//		else {
//			$this->db->trans_commit();
//			return 1;
//		}
	}
	
	function update($data, $id) {
//		$this->db->trans_begin();
        $this->db->update($this->table, $data, array('TermspaymentID' => $id));
//		
//		if ($this->db->trans_status() === FALSE) {
//			$this->db->trans_rollback();
//			return 0;
//		}
//		else {
//			$this->db->trans_commit();
//			return 1;
//		}
	}
	
	function delete($id) {
//		$this->db->trans_begin();
        $this->db->delete($this->table, array('TermspaymentID' => $id));
//		
//		if ($this->db->trans_status() === FALSE) {
//			$this->db->trans_rollback();
//			return 0;
//		}
//		else {
//			$this->db->trans_commit();
//			return 1;
//		}
	}
	function check_code_exist($TermDesc) {
		$query = $this->db->get_where($this->table, array('TermDesc' => $TermDesc), 1, 0);
		
		if ($query->num_rows() > 0) {
			return TRUE;
		}
		else {
			return FALSE;
		}	
	}
    
    //============= DHIDHIK, 28 Maret 2016 ===================================//
    function datasend_term_insert($dataSend){         
        $this->db->trans_start();  
        $this->insert($dataSend['data_term']);
        $this->db->trans_complete();
        if($this->db->trans_status() == FALSE){
            $result  = false;
        }else{
            $result = true;
        }
        return $result;
    }   
    function datasend_term_update($dataSend){         
        $this->db->trans_start(); 
        $this->update($dataSend['data_term'], $dataSend['idcode']);
        $this->db->trans_complete();
        if($this->db->trans_status() == FALSE){
            $result  = false;
        }else{
            $result = true;
        }
        return $result;
    }
    function datasend_term_delete($dataSend){         
        $this->db->trans_start();
        $this->update($dataSend['data_terms'], $dataSend['idcode']);
        $this->db->trans_complete();
        if($this->db->trans_status() == FALSE){
            $result  = false;
        }else{
            $result = true;
        }
        return $result;
    }
    function datasend_term_suspend($dataSend){         
        $this->db->trans_start();
        $this->update($dataSend['data_terms'], $dataSend['idcode']);
        $this->db->trans_complete();
        if($this->db->trans_status() == FALSE){
            $result  = false;
        }else{
            $result = true;
        }
        return $result;
    }
    //============= End DHIDHIK, 28 Maret 2016 ===============================//
}

/* End of file m_terms.php */
/* Location: ./application/modules_core/list/models/m_tems.php */