<?php
class M_rol_over extends CI_Model {
	public $table	= "at_rollover";
	public $itemcategory 		= 'am_itemcategory';
	
	public function get_no_job_cos($branch){
		$this->db->select('at_jobcosting.JCostNumber, at_jobcosting.JCostDesc, at_jobcosting.JCostAccount, am_accountgl.AccountName
							,at_jobcosting.JCostDate, at_jobcosting.JCostDesc, at_jobcosting.JCostSubTotal');
		$this->db->from('at_jobcosting');
		$this->db->join('am_accountgl','am_accountgl.AccountNumber = at_jobcosting.JCostAccount');
		//$this->db->join('at_rollover','at_rollover.JCostNumber = at_jobcosting.JCostNumber');
		
		$this->db->where('at_jobcosting.TransStatus', 1);
		//$this->db->where('at_rollover.LockStatus !=', 1);
		$this->db->where('at_jobcosting.BranchCode',$branch);
		$this->db->order_by('at_jobcosting.JCostNumber','asc');
		
		$query	= $this->db->get();
		return $query->result();
	}
	
	public function get_persediaan_akun($branch, $company){
		$this->db->select('am_accountgl.AccountName, am_accountgl.AccountNumber');
		$this->db->from('am_accountgl');
		$this->db->join('at_compaccountgl as cg','cg.AccountNumber = am_accountgl.AccountNumber');
		$this->db->join('am_branch as br', 'br.BranchCode = cg.BranchCode', 'INNER');         
		$this->db->where('(case when br.BranchStatus = 0 then cg.PLStatus in (0, 1) else cg.PLStatus = 1 end)');            
		$this->db->where('cg.GLSaldoYears', date('Y'));
		$this->db->where('cg.BranchCode',$branch);
		$this->db->where('cg.CompanyCode',$company);
			
		$this->db->order_by('cg.AccountNumber','asc');
		
		$query	= $this->db->get();
		return $query->result();
	}
	
	function get_itemcategory(){
        $query = $this->db->where('TransStatus', 0)->order_by('ItemCategoryName', 'ASC')->get($this->itemcategory);
        return $query->result();
    }
}