<?php
/*	
 *	Author 	: Wahyu
 *	Tanggal : 24-11-2014	
 *	Revisi 	: 
 */
 
class M_payment_lebih extends CI_Model {
    
	// deklarasi nama table
	public $table	= "at_cashpayment";
	public $detail	= "at_cpaydetail";
	public $account = "at_compaccountgl";
	
	// Function View	
	
	// Function get
	function get_all(){
		$param = $this->input->post('param');
		
		$CPayNumber		= isset($param['txt_IDNumber']) ? $param['txt_IDNumber'] : '';
		$CPayDesc		= isset($param['txt_Description']) ? $param['txt_Description'] : '';
		$CPayDateFrom	= isset($param['txt_DateFrom']) ? $param['txt_DateFrom'] : '';
		$CPayDateTo		= isset($param['txt_DateTo']) ? $param['txt_DateTo'] : '';
		$TransStatus	= isset($param['chk_TransStatus']) ? $param['chk_TransStatus'] : '';

		$this->db->select('at_cashpayment.BranchCode as cpay_branch,am_accountgl.AccountName,at_cashpayment.CPayNumber,
			at_cashpayment.CPayDate,at_cashpayment.CPayTotalAmount,at_cashpayment.TransStatus as PaymentStatus,
			at_cashpayment.CPayDesc,am_branch.BranchName' );
		$this->db->from($this->table);
		$this->db->join('am_branch','am_branch.BranchCode = at_cashpayment.BranchCode');
		$this->db->join('am_accountgl','am_accountgl.AccountNumber = '.$this->table.'.BankPayment');
		
		if($CPayNumber!=''){ $this->db->like($this->table.'.CPayNumber', $CPayNumber); }
		if($CPayDesc!=''){ $this->db->like($this->table.'.CPayDesc', $CPayDesc); }
		
		if($CPayDateFrom!='' && $CPayDateTo!='' && $CPayDateFrom < $CPayDateTo){
			$this->db->where('at_cashpayment.CPayDate >=', date("Y-m-d", strtotime($CPayDateFrom)));
			$this->db->where('at_cashpayment.CPayDate <=', date("Y-m-d", strtotime($CPayDateTo)));
		}
		
		if($TransStatus!=''){ $this->db->where_in($this->table.'.TransStatus', $TransStatus); }
		
		$query = $this->db->get();
		return $query->result();
    }
	
	function count_pay_number($bulan, $cek_tahun, $BranchCode){
	    $this->db->select('*');
		$this->db->from('at_cashpayment');
		$this->db->where('MONTH(CPayDate)', $bulan);
		$this->db->where('YEAR(CPayDate)', $cek_tahun);
		$this->db->where('BranchCode', $BranchCode);
		return $this->db->get()->num_rows();
	}
	
	function get_last_pay_number($BranchCode){
		$qty="SELECT MAX(CPayNumber) as CPayNumber FROM at_cashpayment WHERE BranchCode='$BranchCode'";
		return $this->db->query($qty)->result();
	}
	
	function get_accountgl(){
        $this->db->select('at_compaccountgl.AccountNumber as NumberAccount,am_accountsubtype.AccountTypeName');
        $this->db->from('at_compaccountgl');
        $this->db->join('am_accountgl','am_accountgl.AccountNumber = at_compaccountgl.AccountNumber','INNER');
        $this->db->join('am_accountsubtype','am_accountsubtype.AccountSubTypeID = am_accountgl.AccountSubTypeID','INNER');
        $this->db->where('at_compaccountgl.CompanyCode', $this->session->userdata('company'));
		$this->db->where('am_accountgl.TransStatus', 2);
        $this->db->where('am_accountsubtype.AccountTypeName', 'Petty Cash');
        $this->db->or_where('am_accountsubtype.AccountSubTypeID', 5);
		$query	= $this->db->get();
        return $query->result();
    }
	
	function get_petty_cash($CompanyCode){
		$this->db->select('*');
		$this->db->from($this->account);
		$this->db->join('am_accountgl','at_compaccountgl.AccountNumber=am_accountgl.AccountNumber');
		//$this->db->join('am_branch','at_compaccountgl.BranchCode=am_branch.BranchCode');
		$this->db->where('at_compaccountgl.CompanyCode', $CompanyCode);
		$this->db->where('am_accountgl.AccountSubTypeID', 5);
		$this->db->where('am_accountgl.AccountChild', 1);
		$this->db->where('am_accountgl.TransStatus', 2);
		//$this->db->where('am_branch.BranchStatus', 0);
		$query = $this->db->get();
		
		$result=$query->result();
		return json_encode($result);
	}
	
	

	
	
	
	
	
}