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

class M_general_account_balance extends CI_Model {
    public $account = "at_compaccountgl";
	
	function get_by_id($id) {
		$query = $this->db->get_where('tbl_jaournal_voucher_detail', array('JournalVoucherDetailNo' => $id))->result();
        return json_encode($query);
	}
	
	function get_akun(){
		/*=========================lemparan parah dari custom.js untuk searching_data_transaksi=====================*/
		$param = $this->input->post('param');
		/*====================================end===================================================================*/
		
		/*=================================post dari find di kiri====================================================*/
		$Number			= isset($param['txt_IDNumber']) ? $param['txt_IDNumber'] : '';
		$Desc			= isset($param['txt_Description']) ? $param['txt_Description'] : '';
		$Type			= isset($param['account_type']) ? $param['account_type'] : ''; 
		/*============================================end============================================================*/
		
		/*======================================scrol view 1-150=======================================*/
		$page		= ($this->input->post('page')) ? intval($this->input->post('page')) : 1;
		$rows		= ($this->input->post('rows')) ? intval($this->input->post('rows')) : 150;
		
		$beginning 	= ($page - 1) * $rows;
		$end 		= $page * $rows;
		/*==============================================================================================*/
		
		/*==========================================by session=======================================================*/
		$sess_company		= $this->session->userdata('company');
        $sess_branch		= $this->session->userdata('branch');
        $sess_branch_status	= $this->session->userdata('branch_status');
		/*===========================================================================================================*/
		
        $this->db->select("at_compaccountgl.AccountNumber, am_accountgl.AccountName,am_accountsubtype.AccountBSStatus,at_compaccountgl.GLSaldoBSheet,
		 					at_compaccountgl.GLSaldoYears, at_compaccountgl.GLSaldoOpening,am_accountgl.AccountLevel,
							at_compaccountgl.GLSaldoBalance1,
							at_compaccountgl.GLSaldoBalance2,
							at_compaccountgl.GLSaldoBalance3,
							at_compaccountgl.GLSaldoBalance4,
							at_compaccountgl.GLSaldoBalance5,
							at_compaccountgl.GLSaldoBalance6,
							at_compaccountgl.GLSaldoBalance7,
							at_compaccountgl.GLSaldoBalance8,
							at_compaccountgl.GLSaldoBalance9,
							at_compaccountgl.GLSaldoBalance10,
							at_compaccountgl.GLSaldoBalance11,
							at_compaccountgl.GLSaldoBalance12,
							at_compaccountgl.BranchCode,
							am_branch.BranchName");
        $this->db->from($this->account);
       	$this->db->join('am_accountgl','at_compaccountgl.AccountNumber=am_accountgl.AccountNumber');
		$this->db->join('am_accountsubtype','am_accountgl.AccountSubTypeID = am_accountsubtype.AccountSubTypeID','LEFT');
		$this->db->join('am_branch','am_branch.BranchCode = at_compaccountgl.BranchCode','INNER');
		
       /*===================================find by number dan desc=========================================================*/
		if($Number != ""){$this->db->like('at_compaccountgl.AccountNumber', $Number);}
		if($Desc != ""){$this->db->like('am_accountgl.AccountName', $Desc);}
		if($Type != ""){
			if($Type == 'All'){
				
			}
			else{
				$this->db->like('am_accountgl.AccountSubTypeID', $Type);
			}
		} //change
		/*=============================================end===================================================================*/
		
		$this->db->where_in('at_compaccountgl.TransStatus',array(2)); 
		$this->db->where_in('at_compaccountgl.GLSaldoYears',date('Y')); 
		$this->db->where('at_compaccountgl.BranchCode',$sess_branch); 
		
		/*==============================================sort tabel asc==========================================================*/
		$this->db->order_by($this->account.'.TransStatus', 'ASC');
		/*===============================end=================================================================================*/
		$query  = $this->db->limit($end, $beginning);
		$query = $this->db->get();
		return $query->result();
    }
	
	function get_akun_print(){
		/*==========================================by session=======================================================*/
		$sess_company		= $this->session->userdata('company');
        $sess_branch		= $this->session->userdata('branch');
        $sess_branch_status	= $this->session->userdata('branch_status');
		/*===========================================================================================================*/
		
        $this->db->select("at_compaccountgl.AccountNumber, am_accountgl.AccountName,am_accountsubtype.AccountBSStatus,at_compaccountgl.GLSaldoBSheet,
		 					at_compaccountgl.GLSaldoYears, at_compaccountgl.GLSaldoOpening,am_accountgl.AccountLevel,
							at_compaccountgl.GLSaldoBalance1,
							at_compaccountgl.GLSaldoBalance2,
							at_compaccountgl.GLSaldoBalance3,
							at_compaccountgl.GLSaldoBalance4,
							at_compaccountgl.GLSaldoBalance5,
							at_compaccountgl.GLSaldoBalance6,
							at_compaccountgl.GLSaldoBalance7,
							at_compaccountgl.GLSaldoBalance8,
							at_compaccountgl.GLSaldoBalance9,
							at_compaccountgl.GLSaldoBalance10,
							at_compaccountgl.GLSaldoBalance11,
							at_compaccountgl.GLSaldoBalance12");
        $this->db->from($this->account);
       	$this->db->join('am_accountgl','at_compaccountgl.AccountNumber=am_accountgl.AccountNumber');
		$this->db->join('am_accountsubtype','am_accountgl.AccountSubTypeID = am_accountsubtype.AccountSubTypeID','LEFT');
		
       
		
		$this->db->where_in('at_compaccountgl.TransStatus',array(2)); 
		$this->db->where_in('at_compaccountgl.GLSaldoYears',date('Y')); 
		$this->db->where('at_compaccountgl.CompanyCode',$sess_company); 
		
		/*==============================================sort tabel asc==========================================================*/
		$this->db->order_by($this->account.'.TransStatus', 'ASC');
		/*===============================end=================================================================================*/
		$query = $this->db->get();
		return $query->result();
    }
	
	/*function get_akun($CompanyCode){
	    $year = date('Y');
	    $account_number	 = ($this->input->post('account_number')) ? $this->input->post('account_number') : '';
		$account_name	 = ($this->input->post('account_name')) ? $this->input->post('account_name') : '';
		
		$this->db->select('at_compaccountgl.AccountNumber, am_accountgl.AccountName, at_compaccountgl.GLSaldoYears, at_compaccountgl.GLSaldoActual, at_compaccountgl.GLSaldoBalance1, 
		                   at_compaccountgl.GLSaldoBalance2, at_compaccountgl.GLSaldoBalance3, at_compaccountgl.GLSaldoBalance4, at_compaccountgl.GLSaldoBalance5, 
						   at_compaccountgl.GLSaldoBalance6, at_compaccountgl.GLSaldoBalance7, at_compaccountgl.GLSaldoBalance8, at_compaccountgl.GLSaldoBalance9, 
						   at_compaccountgl.GLSaldoBalance10, at_compaccountgl.GLSaldoBalance11, at_compaccountgl.GLSaldoBalance12');
		$this->db->from($this->account);		
		$this->db->join('am_accountgl','at_compaccountgl.AccountNumber=am_accountgl.AccountNumber');
		$this->db->like('am_accountgl.AccountNumber', $account_number);
		$this->db->like('am_accountgl.AccountName', $account_name);	
		$this->db->where('at_compaccountgl.CompanyCode', $CompanyCode);
		$this->db->where('am_accountgl.AccountChild', 1);
		$this->db->where('am_accountgl.TransStatus', 2);
		$this->db->where('at_compaccountgl.GLSaldoYears', $year);

                //$this->db->limit($rows,$offset);
		//$this->db->order_by($sort,$order);
		return $this->db->get()->result();
	}*/
	
	function get_saldo_akun($CompanyCode){
	    $year = date('Y');
	    $account_number	 = ($this->input->post('account_number')) ? $this->input->post('account_number') : '';
		$account_name	 = ($this->input->post('account_name')) ? $this->input->post('account_name') : '';
		$account_type	 = ($this->input->post('account_type')) ? $this->input->post('account_type') : '';
		
		$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
		$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
		$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'at_compaccountgl.AccountNumber';
		$order = isset($_POST['order']) ? strval($_POST['order']) : 'ASC';
		$offset = ($page-1) * $rows;
		
		$result = array();
		$result['total'] = $this->db->get('at_compaccountgl')->num_rows();
		$row = array();
		
		$this->db->select('at_compaccountgl.GLSaldoActual, at_compaccountgl.GLSaldoBalance1, at_compaccountgl.GLSaldoBalance2, at_compaccountgl.GLSaldoBalance3,
		                   at_compaccountgl.GLSaldoBalance4, at_compaccountgl.GLSaldoBalance5, at_compaccountgl.GLSaldoBalance6, at_compaccountgl.GLSaldoBalance7,
						   at_compaccountgl.GLSaldoBalance8, at_compaccountgl.GLSaldoBalance9, at_compaccountgl.GLSaldoBalance10, at_compaccountgl.GLSaldoBalance11,
						   at_compaccountgl.GLSaldoBalance12');
		$this->db->from($this->account);		
		$this->db->join('am_accountgl','at_compaccountgl.AccountNumber=am_accountgl.AccountNumber');
		$this->db->like('am_accountgl.AccountNumber', $account_number);
		$this->db->like('am_accountgl.AccountName', $account_name);	
		
		$this->db->where('at_compaccountgl.CompanyCode', $CompanyCode);
		$this->db->where('am_accountgl.AccountChild', 1);
		$this->db->where('am_accountgl.TransStatus', 2);
		$this->db->where('at_compaccountgl.GLSaldoYears', $year);
		$this->db->limit($rows,$offset);
		$this->db->order_by($sort,$order);
		return $this->db->get()->result();
	}
	
	function get_all($CompanyCode){
	    $year = date('Y');
	    $account_number	 = ($this->input->post('account_number')) ? $this->input->post('account_number') : '';
		$account_name	 = ($this->input->post('account_name')) ? $this->input->post('account_name') : '';
		
		$this->db->select('at_compaccountgl.AccountNumber, am_accountgl.AccountName, at_compaccountgl.GLSaldoYears, at_compaccountgl.GLSaldoActual, at_compaccountgl.GLSaldoBalance1, 
		                   at_compaccountgl.GLSaldoBalance2, at_compaccountgl.GLSaldoBalance3, at_compaccountgl.GLSaldoBalance4, at_compaccountgl.GLSaldoBalance5, 
						   at_compaccountgl.GLSaldoBalance6, at_compaccountgl.GLSaldoBalance7, at_compaccountgl.GLSaldoBalance8, at_compaccountgl.GLSaldoBalance9, 
						   at_compaccountgl.GLSaldoBalance10, at_compaccountgl.GLSaldoBalance11, at_compaccountgl.GLSaldoBalance12');
		$this->db->from($this->account);		
		$this->db->join('am_accountgl','at_compaccountgl.AccountNumber=am_accountgl.AccountNumber');
		$this->db->like('am_accountgl.AccountNumber', $account_number);
		$this->db->like('am_accountgl.AccountName', $account_name);	
		$this->db->where('at_compaccountgl.CompanyCode', $CompanyCode);
		$this->db->where('am_accountgl.AccountChild', 1);
		$this->db->where('am_accountgl.TransStatus', 2);
		$this->db->where('at_compaccountgl.GLSaldoYears', $year);
		$this->db->order_by('at_compaccountgl.AccountNumber', 'ASC');
		return $this->db->get()->result();
	}
	
    function get_all_accounttype(){
        $this->db->select('*');
        $this->db->from('am_accounttype');
        $this->db->order_by('AccountTypeID', 'ASC');

        return $this->db->get()->result();
    }
}

/* End of file m_general_account_history.php */
/* Location: ./application/models/m_general_account_history.php */