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

/*      Author 	: Ladur / Tanggal : 21-07-2014	
 *	Revisi 	: Ferry / Tanggal : 31-01-2015 */

header('Content-Type: text/json');
ob_clean();
flush(); 
		
class Get_data extends CI_Controller {
    public function __construct() {
        parent::__construct();	
        $this->load->model('m_custom');	
    }	
	
    function baru() {
        echo "[]";
    }

    function department() {
        $data = $this->load->m_custom->get_department();
        echo json_encode($data);
    }
    
    function jobtitle() {
        $data = $this->load->m_custom->get_jobtitle();      
        echo json_encode($data);
    }
	
    function jobtitlestatus() {
        $data = $this->load->m_custom->get_jobtitlestatus();      
        echo json_encode($data);
    }
	
    function city() {
        $data = $this->load->m_custom->get_city();
        echo json_encode($data);
    }

    function state() {
        $data = $this->load->m_custom->get_state();
        echo json_encode($data);
    }

    function country() {
        $data = $this->load->m_custom->get_country();
        echo json_encode($data);
    }
	
    function termspayment(){
        $data = $this->load->m_custom->get_termspayment();
        echo json_encode($data);
    }
	
    function currency(){
        $data = $this->load->m_custom->get_currency();
        echo json_encode($data);
    }
	
    function taxes(){
        $data = $this->load->m_custom->get_taxes();
        echo json_encode($data);
    }
	
    function taxtype(){
       $data = $this->load->m_custom->get_taxtype();
        echo json_encode($data);
    }
    
    function region(){
        $data = $this->load->m_custom->get_region();
        echo json_encode($data);
    }
	
    function item(){
        $data = $this->load->m_custom->get_item();
        echo json_encode($data);
    }
	
    function persedian_barang_dalam_proses(){
        $data = $this->load->m_custom->get_brg_dlm_proses();
        echo json_encode($data);
    }
	
    function inventory(){
        $data = $this->load->m_custom->get_inventory();
        echo json_encode($data);
    }
	
    function itemtype(){
        $data = $this->load->m_custom->get_itemtype();
	//	echo $this->db->last_query();
        echo json_encode($data);
    }
	
	function itemtype_master_edit($nilai_item){
        $data = $this->load->m_custom->get_itemtype_aset_edit($nilai_item);
	//	echo $this->db->last_query();
        echo json_encode($data);
    }
	
	function itemtype_master_inventori(){
        $data = $this->load->m_custom->get_itemtype_inventori();
	//	echo $this->db->last_query();
        echo json_encode($data);
    }
	
	function itemtype_master_fix_asset($nilai){
        $data = $this->load->m_custom->get_itemtype_fix_aset($nilai);
	//	echo $this->db->last_query();
        echo json_encode($data);
    }
	
	/* function itemtype_master_1(){
        $data = $this->load->m_custom->get_itemtype_aset_1();
	//	echo $this->db->last_query();
        echo json_encode($data);
    }
	
	function itemtype_master_2($nilai){
        $data = $this->load->m_custom->get_itemtype_aset_2($nilai);
	//	echo $this->db->last_query();
        echo json_encode($data);
    } */
	
	/*============================get item kategori all kategori=========================================*/
    function itemcategory(){
        $data = $this->load->m_custom->get_itemcategory();
		$hasil[] = array(
			'ItemCategoryID' 	=>	"All",
			'ItemCategoryName' 	=>	"All"
		);
		
		foreach($data as $row){
			$hasil[] = array(
				'ItemCategoryID' 	=>	$row->ItemCategoryID,
				'ItemCategoryName' 	=>	$row->ItemCategoryName,
				'InitialCategory' 	=>	$row->InitialCategory,
				'AssetStatus' 		=>	$row->AssetStatus
			);
		}
		
		
		if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
//        echo $this->db->last_query(); die();
    }
	/*======================================end================================================================*/
	
	function fob(){
        $hasil[] = array(
			'FobID' 	=>	"1",
			'FobName' 	=>	"Shipping Point"
		);
		
		$hasil[] = array(
			'FobID' 	=>	"2",
			'FobName' 	=>	"Destination"
		);
		
		
		if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
//        echo $this->db->last_query(); die();
    }
	
	function itemcategory_add(){
        $data = $this->load->m_custom->get_itemcategory_for_add();
		foreach($data as $row){
			$hasil[] = array(
				'ItemCategoryID' 	=>	$row->ItemCategoryID,
				'ItemCategoryName' 	=>	$row->ItemCategoryName,
				'InitialCategory' 	=>	$row->InitialCategory,
				'AssetStatus' 		=>	$row->AssetStatus
			);
		}
		
		
		if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
//        echo $this->db->last_query(); die();
    }
	
	/*============================get item kategori not fix asset=========================================*/
	function itemcategory_no_asset(){
        $data = $this->load->m_custom->get_itemcategory_no_asset();
		$hasil[] = array(
			'ItemCategoryID' 	=>	"All",
			'ItemCategoryName' 	=>	"All"
		);
		
		foreach($data as $row){
			$hasil[] = array(
				'ItemCategoryID' 	=>	$row->ItemCategoryID,
				'ItemCategoryName' 	=>	$row->ItemCategoryName
			);
		}
		
		
		if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
//        echo $this->db->last_query(); die();
    }
	/*======================================end================================================================*/
	
	/*============================get item kategori =========================================*/
	function itemcategory_adjustment($acc_number){
		
		$replace_number = str_replace("_","-", $acc_number);
		
        $data = $this->load->m_custom->get_itemcategory_adjust($replace_number);
		
		
		foreach($data as $row){
			$hasil[] = array(
				'ItemCategoryID' 	=>	$row->ItemCategoryID,
				'ItemCategoryName' 	=>	$row->ItemCategoryName
			);
		}
		
		
		if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
//        echo $this->db->last_query(); die();
    }
	/*======================================end================================================================*/
	
    function itemprice(){
        $data = $this->load->m_custom->get_itemprice();
        echo json_encode($data);
    }
	
    function itempricelist(){
        $data = $this->load->m_custom->get_itempricelist();
        echo json_encode($data);
    }
	
	
    function vendor_code_by_branch($branch_code){
		$str_branch_code 	= str_replace("_","-",$branch_code);
        $data 				= $this->load->m_custom->get_vendor_code($str_branch_code);
		
		foreach($data as $row){
			$hasil[] = array(
				'VendorCode' 	=>	$row->VendorCode,
				'VendorName' 	=>	$row->VendorName
			);
		}
		
		if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
    }
	
    function vendor(){
        $branch_code = $this->input->get('BranchCode');

        if($branch_code == null || $branch_code == '') {
            $branch_code = $this->session->userdata('branch');
        }
        
        $data = $this->load->m_custom->get_vendor($branch_code);
        echo json_encode($data);
    }
	
	function vendor_new_by_branch_filter(){
        $branch_code = $this->input->get('BranchCode');
		$company_code = $this->input->get('CompanyCode');

        if($branch_code == null || $branch_code == '') {
            $branch_code = $this->session->userdata('branch');
			$company_code = $this->session->userdata('company');
        }
        
        $data = $this->load->m_custom->get_vendor_new_filter($branch_code, $company_code);
        echo json_encode($data);
    }
	
	function vendor_new_by_branch(){
        $branch_code = $this->input->get('BranchCode');
		$company_code = $this->input->get('CompanyCode');

        if($branch_code == null || $branch_code == '') {
            $branch_code = $this->session->userdata('branch');
			$company_code = $this->session->userdata('company');
        }
        
        $data = $this->load->m_custom->get_vendor_new($branch_code, $company_code);
        echo json_encode($data);
    }
    
    function shipment(){
        $data = $this->load->m_custom->get_shipment();
        echo json_encode($data);
    }
	
    function branch(){
        $data = $this->load->m_custom->get_branch();
        echo json_encode($data);
    }
	
	function branch_no_filter(){
        $data = $this->load->m_custom->get_branch_no_filter();
        echo json_encode($data);
    }
	
    function warehouse(){
        $data = $this->load->m_custom->get_warehouse();
        echo json_encode($data);
    }
	
    function bank(){
        $data = $this->load->m_custom->get_bank();
        echo json_encode($data);        
    }

    function bank_coa(){
        $branch_code = $this->input->post('Branch_Code');
        $bank_code = $this->input->post('Bank_Code');
        
        $data = $this->load->m_custom->get_bank_coa($branch_code, $bank_code);
        echo json_encode($data);
    }
        
    function bank_by_branch($branch_code){
        $data = $this->load->m_custom->get_bank_by_branch($branch_code);
        echo json_encode($data);
    }
	
	function bank_by_branch_new(){
        $data = $this->load->m_custom->get_bank_by_branch($this->session->userdata('branch'));
        echo json_encode($data);
    }

    function accounttype(){
        $data = $this->load->m_custom->get_accounttype();
        echo json_encode($data);
    }
	
    function accountsubtype(){
        $data = $this->load->m_custom->get_accountsubtype();
        echo json_encode($data);
    }

    function accountgl(){
        $data = $this->load->m_custom->get_accountgl();
        echo json_encode($data);
    }
	
    function company(){
        $data = $this->load->m_custom->get_company();
        echo json_encode($data);
    }
	
	//get company for fine master
	function company_find_master(){
        $data = $this->load->m_custom->get_company_find();
        echo json_encode($data);
    }
	
    function company_branch(){
        $data = $this->load->m_custom->get_company_branch();
        echo json_encode($data);
        
//        echo $this->db->last_query(); die();
    }
        
    function branch_by_session(){
        $data = $this->load->m_custom->get_branch();
        echo json_encode($data);
        
//        echo $this->db->last_query(); die();
    }
	
//    function company_branch(){
//        $data = $this->load->m_custom->get_branch();
//        echo json_encode($data);
//        
////        echo $this->db->last_query(); die();
//    }
    
    function employee(){
        $data = $this->load->m_custom->get_employee();
        echo json_encode($data);
    }
	
    function customer(){
        $branch_code = $this->input->get('BranchCode');

        if($branch_code == null || $branch_code == '') {
            $branch_code = $this->session->userdata('branch');
        }

        $data = $this->load->m_custom->get_customer($branch_code);
        echo json_encode($data);
    }
	
	function customer_with_rate(){
        $BranchCode = $this->input->get('BranchCode');

        if($BranchCode == null || $BranchCode == '') {
            $BranchCode = $this->session->userdata('branch');
        }
		
        $data = $this->load->m_custom->get_customer_with_rate($BranchCode);
        echo json_encode($data);
    }
	
	function vendor_with_rate(){
        $BranchCode = $this->input->get('BranchCode');

        if($BranchCode == null || $BranchCode == '') {
            $BranchCode = $this->session->userdata('branch');
        }
		
        $data = $this->load->m_custom->get_vendor_with_rate($BranchCode);
        echo json_encode($data);
    }
	
	function accountsubtype_with_bsstatus(){
        $data = $this->load->m_custom->get_accountsubtype();
		
		$hasil[] = array(
			'AccountSubTypeID' 	=>	"All",
			'AccountTypeName' 	=>	"All"
		);
		
		foreach($data as $row){
			$hasil[] = array(
				'AccountSubTypeID' 	=>	$row->AccountSubTypeID,
				'AccountTypeName' 	=>	$row->AccountTypeName
			);
		}
        if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
    }
//    function customer_address(){
//        $hasil_customer = "";
//        $hasil_branch = "";
//		
//        $data_customer = $this->load->m_custom->get_customer_address();
//        
//        foreach($data_customer as $row) {	
//            $hasil_customer[] = array(
//				'BranchCode' => $row->BranchCode,
//				'SaldoBalance' => $row->SaldoBalance,
//				'SaldoDP' => $row->SaldoDP, 
//				'TaxIncludedStatus' => $row->TaxIncludedStatus,
//				'CustomerCode' => $row->CustomerCode,
//				'CustomerName' => $row->CustomerName,
//				'CustomerAddress' => $row->CustomerAddress,
//				'CustCity' => $row->CustCity,
//				'CustState' => $row->CustState,
//				'CustCountry' => $row->CustCountry
//			);
//        }	
//		
//		// $data_branch = $this->load->m_custom->get_branch_address();
//		
//		// foreach($data_branch as $row) {	
//			// $hasil_branch[] = array(
//				// 'SaldoBalance' => 0,
//				// 'TaxIncludedStatus' => 0,
//				// 'CustomerCode' => $row->BranchCode,
//				// 'CustomerName' => $row->BranchName,
//				// 'CustomerAddress' => $row->BranchAddress,
//				// 'CustCity' => $row->CustCity,
//				// 'CustState' => $row->CustState,
//				// 'CustCountry' => $row->CustCountry
//			// );	
//		// }
//		
//        if($hasil_customer != "" && $hasil_branch != "") {
//            $result = array_merge($hasil_customer, $hasil_branch);
//        }	
//        else if($hasil_customer == "" && $hasil_branch != "") {
//            $result = array_merge($hasil_branch);
//        }	
//        else if($hasil_customer != "" && $hasil_branch == "") {
//            $result = array_merge($hasil_customer);
//        }
//        else {
//            $result = null;	
//        }
//		
//        if($result == null) {
//            echo '[]';
//        }
//        else {
//            foreach($result as $row) {
//                $hasil[] = array(
//                        'SaldoBalance' => $row['SaldoBalance'],
//						'SaldoDP' => $row['SaldoDP'], 
//                        'TaxIncludedStatus' => $row['TaxIncludedStatus'],
//                        'CustomerCode' => $row['CustomerCode'],
//                        'CustomerName' => $row['CustomerName'],
//                        'CustomerAddress' => $row['CustomerAddress'],
//                        'CustCity' => $row['CustCity'],
//                        'CustState' => $row['CustState'],
//                        'CustCountry' => $row['CustCountry']
//                        );
//            }			
//            
//            echo json_encode($hasil);
//        }
//    }
	
	/*============================get item kategori all kategori=========================================*/
    function payment_status(){
		$hasil[] = array(
			'PaymentCode' 	=>	"All",
			'PaymentName' 	=>	"All"
		);
		$hasil[] = array(
			'PaymentCode' 	=>	"0",
			'PaymentName' 	=>	"Purchase Payment"
		);
		$hasil[] = array(
			'PaymentCode' 	=>	"1",
			'PaymentName' 	=>	"Purchase Journal"
		);
		if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
//        echo $this->db->last_query(); die();
    }
	/*======================================end================================================================*/
	
    function warehouse_type(){
        $data = $this->load->m_custom->get_warehouse_type();
        echo json_encode($data);
    }
	
    function sales(){
        $data = $this->load->m_custom->get_sales();
        echo json_encode($data);
    }
	
    function fixedassettype(){
        $data = $this->load->m_custom->get_fixedassettype();
        echo json_encode($data);
    }
	
    function depreciatemethod(){
        $data = $this->load->m_custom->get_depreciatemethod();
        echo json_encode($data);
    }
	
    function depreciate_method() {
        echo '[{"DepreciateID":"1","DepreciateName":"Non Depreciable Method"}, {"DepreciateID":"2","DepreciateName":"Straight Line Method"}, {"DepreciateID":"3","DepreciateName":"Double Declining Method"}]';
    }
	
	function search_item(){
		$page			= ($this->input->post('page')) ? intval($this->input->post('page')) : 1;
		$rows			= ($this->input->post('rows')) ? intval($this->input->post('rows')) : 150;
		$hasil 			= array();
		
		/*=================================post dari find di atas pop up====================================================*/
		$param 				= $this->input->post('param');
		$ItemCategoryID		= isset($param['cmb_ItemCategoryID']) ? $param['cmb_ItemCategoryID'] : '';
		$ItemCode			= isset($param['txt_ItemCode']) ? $param['txt_ItemCode'] : '';
		$ItemDesc			= isset($param['txt_ItemDesc']) ? $param['txt_ItemDesc'] : '';
		/*============================================end============================================================*/
		
		/*===========================count data tabel job costing==================================*/
		//$this->db->where('BranchCode', $this->session->userdata('branch'));
		$this->db->where_in('am_item.TransStatus', array(0,1));
		
		if($ItemCategoryID != ""){
			if($ItemCategoryID == "All"){
				
			}else{
				$this->db->where('am_item.ItemCategoryID', $ItemCategoryID);
			}
		}
		if($ItemCode != ""){$this->db->like('am_item.ItemCode', $ItemCode);}
		if($ItemDesc != ""){$this->db->like('am_item.ItemDesc', $ItemDesc);}
		
		$this->db->join('am_item', 'am_item.ItemCategoryID = am_itemcategory.ItemCategoryID', 'inner');
		$count_data = $this->db->count_all_results('am_itemcategory');
		/*======================================end================================================*/
		
		$offset 	= $count_data - ($rows * $page);
		if($offset > 0){
			$rows 	= $rows;
		}
		else{
			$rows 	= $count_data - ($rows*($page-1));
		}
		
		/*===============ambil data dari model search_job_costing============================*/
		$result 	= $this->m_custom->search_item();
		
		/*======================end=================================*/
		
		for($i=0; $i<=($rows-1); $i++){
			
			$hasil[] = array(
				'ItemCode' 			=>	$result[$i]->ItemCode,
				'ItemDesc' 			=>	$result[$i]->ItemDesc,
				'ItemUnit' 			=>	$result[$i]->ItemUnit,
				'ItemCategoryID' 	=>	$result[$i]->ItemCategoryID,
				'ItemTypeID' 		=>	$result[$i]->ItemTypeID,
				'ItemPPhType' 		=>	$result[$i]->ItemPPhType,
				'ItemPPh22Status' 	=> 	$result[$i]->ItemPPh22Status,
				'ItemPPh23Status' 	=> 	$result[$i]->ItemPPh23Status,
				'ItemAdvNetDueIn' 	=> 	$result[$i]->ItemAdvNetDueIn,
				'ItemCategoryCode' 	=> 	$result[$i]->ItemCategoryCode,
				'ItemStatus' 		=> 	$result[$i]->ItemStatus
			);
		}
		/*===================jika kondisi kosong dari array $hasil=======================*/
		if(empty($hasil)){
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
		else{
			$result = array();
			$result['total'] = $count_data;
			$result['rows'] = $hasil;
			echo json_encode($result);
		}
		/*==============================end===========================================*/
    }
	
//
//			
//    function search_item(){
//        echo json_encode($this->m_custom->search_item());
////        echo $this->db->last_query(); die();
//    }
	
	function search_service(){
		$page			= ($this->input->post('page')) ? intval($this->input->post('page')) : 1;
		$rows			= ($this->input->post('rows')) ? intval($this->input->post('rows')) : 150;
		$hasil 			= array();
		
		/*=================================post dari find di atas pop up====================================================*/
		$param 				= $this->input->post('param');
		$ItemCategoryID		= isset($param['cmb_ItemCategoryID']) ? $param['cmb_ItemCategoryID'] : '';
		$SvcDetailName		= isset($param['txt_ItemCode_Servis']) ? $param['txt_ItemCode_Servis'] : '';
		$SvcDetailDesc		= isset($param['txt_ItemDesc_Servis']) ? $param['txt_ItemDesc_Servis'] : '';
		/*============================================end============================================================*/
		
		/*===========================count data tabel job costing==================================*/
		$this->db->where('sc.CompanyCode', $this->session->userdata('company'));
		
		if($SvcDetailName != ""){$this->db->like('sys_servicedetail.SvcDetailName', $SvcDetailName);}
		if($SvcDetailDesc != ""){$this->db->like('sys_servicedetail.SvcDetailDesc', $SvcDetailDesc);}
		
		$this->db->join('sys_servicecategory as sc', 'sc.SvcCategoryID = sys_servicedetail.SvcCategoryID', 'INNER');
		$count_data = $this->db->count_all_results('sys_servicedetail');
		/*======================================end================================================*/
		
		$offset 	= $count_data - ($rows * $page);
		if($offset > 0){
			$rows 	= $rows;
		}
		else{
			$rows 	= $count_data - ($rows*($page-1));
		}
		
		/*===============ambil data dari model search_job_costing============================*/
		$result 	= $this->m_custom->search_service();
		/*======================end=================================*/
		
		for($i=0; $i<=($rows-1); $i++){
			
			$hasil[] = array(
				'ItemCode' 			=>	$result[$i]->ItemCode,
				'ItemDesc' 			=>	$result[$i]->ItemDesc,
				'ItemUnit' 			=>	$result[$i]->ItemUnit,
				'ItemCategoryID' 	=>	$result[$i]->ItemCategoryID,
				'ItemCategoryName' 	=> $result[$i]->ItemCategoryName,
				'ItemCategoryCode' 	=>	$result[$i]->ItemCategoryCode,
				'ItemStatus' 		=>	$result[$i]->ItemStatus,
				'ItemPPh22Status' 	=>	$result[$i]->ItemPPh22Status,
				'ItemPPh23Status' 	=>	$result[$i]->ItemPPh23Status,
				'ItemAdvNetDueIn' 	=>	$result[$i]->ItemAdvNetDueIn
			);
		}
		/*===================jika kondisi kosong dari array $hasil=======================*/
		if(empty($hasil)){
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
		else{
			$result = array();
			$result['total'] = $count_data;
			$result['rows'] = $hasil;
			echo json_encode($result);
		}
		/*==============================end===========================================*/
    }
	/*====================================end==============================================================================*/
    
    function search_advance(){
        $page			= ($this->input->post('page')) ? intval($this->input->post('page')) : 1;
		$rows			= ($this->input->post('rows')) ? intval($this->input->post('rows')) : 150;
		$hasil 			= array();
		
		/*=================================post dari find di atas pop up====================================================*/
		$param 				= $this->input->post('param');
		$ItemCategoryID		= isset($param['cmb_ItemCategoryID']) ? $param['cmb_ItemCategoryID'] : '';
		$AdVDetailName		= isset($param['txt_ItemCode_Adv']) ? $param['txt_ItemCode_Adv'] : '';
		$AdVDetailDesc		= isset($param['txt_ItemDesc_Adv']) ? $param['txt_ItemDesc_Adv'] : '';
		/*============================================end============================================================*/
		
		/*===========================count data tabel job costing==================================*/
		$this->db->where('ac.CompanyCode', $this->session->userdata('company'));
		
		if($AdVDetailName != ""){$this->db->like('sys_advancedetail.AdvDetailName', $AdVDetailName);}
		if($AdVDetailDesc != ""){$this->db->like('sys_advancedetail.AdvDetailDesc', $AdVDetailDesc);}
		
		$this->db->join('sys_advancecategory as ac', 'ac.AdvCategoryID = sys_advancedetail.AdvCategoryID', 'INNER');
		$count_data = $this->db->count_all_results('sys_advancedetail');
		/*======================================end================================================*/
		
		$offset 	= $count_data - ($rows * $page);
		if($offset > 0){
			$rows 	= $rows;
		}
		else{
			$rows 	= $count_data - ($rows*($page-1));
		}
		
		/*===============ambil data dari model search_job_costing============================*/
		$result 	= $this->m_custom->search_advance();
		/*======================end=================================*/
		
		for($i=0; $i<=($rows-1); $i++){
			
			$hasil[] = array(
				'ItemCode' 			=>	$result[$i]->ItemCode,
				'ItemDesc' 			=>	$result[$i]->ItemDesc,
				'ItemUnit' 			=>	$result[$i]->ItemUnit,
				'ItemCategoryID' 	=>	$result[$i]->ItemCategoryID,
				'ItemCategoryCode' 	=>	$result[$i]->ItemCategoryCode,
				'ItemStatus' 		=>	$result[$i]->ItemStatus,
				'ItemPPh22Status' 	=>	$result[$i]->ItemPPh22Status,
				'ItemPPh23Status' 	=>	$result[$i]->ItemPPh23Status,
				'ItemAdvNetDueIn' 	=>	$result[$i]->ItemAdvNetDueIn
			);
		}
		/*===================jika kondisi kosong dari array $hasil=======================*/
		if(empty($hasil)){
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
		else{
			$result = array();
			$result['total'] = $count_data;
			$result['rows'] = $hasil;
			echo json_encode($result);
		}
		/*==============================end===========================================*/
    }
    
    function search_item_with_category_item(){
        echo json_encode($this->m_custom->search_item_with_category_item());
    }
	
    function search_inventory(){
        echo json_encode($this->m_custom->search_inventory());
    }
	
	//------------------creat by fahri 15/04/2015--------------------
    function search_production(){
		echo json_encode($this->m_custom->search_production());
    }
	
	function search_production_not_in(){
		echo json_encode($this->m_custom->search_not_in_production());
    }
	
	function search_job_costing(){
        $result = $this->m_custom->search_job_costing();
		//echo $this->db->last_query();
		$hasil = '';
		foreach($result as $row){
			if($row->IsLock == 1){
				$Status = "Item Lock";
			}else{
				$Status = "Item UnLock";
			}
			$hasil[] = array(
				'ItemCode' 			=>	$row->ItemCode,
				'ItemDesc' 			=>	$row->ItemDesc,
				'ItemUnit' 			=>	$row->ItemUnit,
				'ItemAverage' 			=>	$row->ItemAverage,
				'ItemCategoryID' 	=>	$row->ItemCategoryID,
				'ItemQty' 			=>	$row->ItemQty,
				'IsLock' 			=>	$Status,
				'ItemLockId' 		=>	$row->IsLock
			);
		}
		echo json_encode($hasil);
    }
	//end fahri--------------------------------------------------------------
	
//    function search_expense_account(){
//        echo json_encode($this->m_custom->search_expense_account());
//    }
	
    function branch_by_company(){
        echo json_encode($this->m_custom->get_branch_by_company());
    }
	
	function branch_by_company_new($company_code){
		$result = $this->m_custom->get_branch_by_company_new($company_code);

		/*$result[] = array('BranchCode' => 'All',
						  'BranchName' => 'All');*/

		 echo json_encode($result);
    }
	
	function branch_by_company_new_all($company_code){
        $data 	 = $this->load->m_custom->get_branch_by_company_new($company_code);
		$hasil[] = array(
			'BranchCode' 	=>	"All",
			'BranchName' 	=>	"All"
		);
		
		foreach($data as $row){
			$hasil[] = array(
				'BranchCode' 	=>	$row->BranchCode,
				'BranchName' 	=>	$row->BranchName
			);
		}
		
		
		if(!empty($hasil)){
			echo json_encode($hasil);
		}
		else{
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
//        echo $this->db->last_query(); die();
    }
	
    function branch_active_by_company(){
        echo json_encode($this->m_custom->get_branch_active_by_company());
    }

    function bank_join_currency(){
        $data = $this->load->m_custom->bank_join_currency();
        echo json_encode($data);
    }
	
    function join_bank_account(){		
        echo json_encode($this->m_custom->join_bank_account());
    }
    	
    function yes_no() {
        echo '[{"status_code":"0","status_name":"No"}, {"status_code":"1","status_name":"Yes"}]';
    }
	
	function currency_new($AccountAutoStatus = ''){
        $data = $this->load->m_custom->get_currency_new($AccountAutoStatus);
		//	echo $this->db->last_query();
        echo json_encode($data);
    }
	
	/*============================pencarian dari all item by kategori and all kategori waktu pop up=======================================*/
	/*
		baru dipake di modul job costing
	*/
	function search_all_item(){
		$page			= ($this->input->post('page')) ? intval($this->input->post('page')) : 1;
		$rows			= ($this->input->post('rows')) ? intval($this->input->post('rows')) : 150;
		$hasil 			= array();
		
		/*=================================post dari find di atas pop up====================================================*/
		$param 				= $this->input->post('param');
		$ItemCategoryID		= isset($param['cmb_ItemCategoryID']) ? $param['cmb_ItemCategoryID'] : '';
		$ItemCode			= isset($param['txt_ItemCode']) ? $param['txt_ItemCode'] : '';
		$ItemDesc			= isset($param['txt_ItemDesc']) ? $param['txt_ItemDesc'] : '';
		/*============================================end============================================================*/
		
		/*===========================count data tabel job costing==================================*/
		$this->db->where('BranchCode', $this->session->userdata('branch'));
		$this->db->where('am_itemcategory.AssetStatus', 0);
		$this->db->where_in('am_item.TransStatus', array(0,1));
		
		if($ItemCategoryID != ""){
			if($ItemCategoryID == "All"){
				
			}else{
				$this->db->like('am_item.ItemCategoryID', $ItemCategoryID);
			}
		}
		if($ItemCode != ""){$this->db->like('am_item.ItemCode', $ItemCode);}
		if($ItemDesc != ""){$this->db->like('am_item.ItemDesc', $ItemDesc);}
		
		$this->db->join('am_item', 'am_item.ItemCategoryID = am_itemcategory.ItemCategoryID', 'inner');
		$this->db->join('at_inventories', 'at_inventories.ItemCode = am_item.ItemCode', 'inner');
		$count_data = $this->db->count_all_results('am_itemcategory');
		/*======================================end================================================*/
		
		$offset 	= $count_data - ($rows * $page);
		if($offset > 0){
			$rows 	= $rows;
		}
		else{
			$rows 	= $count_data - ($rows*($page-1));
		}
		
		/*===============ambil data dari model search_job_costing============================*/
		$result 	= $this->m_custom->search_all_item_sq();
		/*======================end=================================*/
		
		for($i=0; $i<=($rows-1); $i++){
			if($result[$i]->IsLock == 1){
				$Status = "Item Lock";
			}else{
				$Status = "Item UnLock";
			}
			
			if($result[$i]->ItemTypeID == 1){
				$ItemStatus = 1;
			}
			else{
				$ItemStatus = 0;
			}
			
			$hasil[] = array(
				'ItemCode' 			=>	$result[$i]->ItemCode,
				'ItemDesc' 			=>	$result[$i]->ItemDesc,
				'ItemUnit' 			=>	$result[$i]->ItemUnit,
				'ItemAverage' 		=>	$result[$i]->ItemAverage,
				'ItemValue' 		=>	$result[$i]->ItemValue,
				'ItemCategoryID' 	=>	$result[$i]->ItemCategoryID,
				'ItemQty' 			=>	$result[$i]->ItemQty,
				'IsLock' 			=>	$Status,
				'ItemLockId' 		=>	$result[$i]->IsLock,
				'ItemCategoryCode' 	=>	$result[$i]->ItemCategoryCode,
				'ItemStatus' 		=>	$result[$i]->ItemStatus,
				'ItemCategoryName' 	=> 	$result[$i]->ItemCategoryName,
				'ItemTypeID' => $ItemStatus
			);
		}
		/*===================jika kondisi kosong dari array $hasil=======================*/
		if(empty($hasil)){
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
		else{
			$result = array();
			$result['total'] = $count_data;
			$result['rows'] = $hasil;
			echo json_encode($result);
		}
		/*==============================end===========================================*/
    }
	/*====================================end==============================================================================*/
	
	
	/*============================pencarian dari all item by kategori and all kategori kecuali fix asset waktu pop up=======================================*/
	/*
		baru dipake di modul adjustment
	*/
	function search_all_item_no_asset(){
		$page			= ($this->input->post('page')) ? intval($this->input->post('page')) : 1;
		$rows			= ($this->input->post('rows')) ? intval($this->input->post('rows')) : 150;
		$hasil 			= array();
		
		/*=================================post dari find di atas pop up====================================================*/
		$param 				= $this->input->post('param');
		$ItemCategoryID		= isset($param['cmb_ItemCategoryID']) ? $param['cmb_ItemCategoryID'] : '';
		$ItemCode			= isset($param['txt_ItemCode']) ? $param['txt_ItemCode'] : '';
		$ItemDesc			= isset($param['txt_ItemDesc']) ? $param['txt_ItemDesc'] : '';
		$Akun_search		= isset($param['akun_number']) ? $param['akun_number'] : '';
		
		$AccounNumber 		= $this->input->post('AccounNumber');
		/*============================================end============================================================*/
		
		/*===========================count data tabel job costing==================================*/
		$this->db->where('BranchCode', $this->session->userdata('branch'));
		$this->db->where_in('am_item.TransStatus', array(0,1));
		$this->db->where('am_itemcategory.AssetStatus', 0);
		
		if($Akun_search != ""){
			$this->db->where_in('sys_itemaccount.AccountNumber', $Akun_search);
		}
		else{
			$this->db->where_in('sys_itemaccount.AccountNumber', $AccounNumber);
		}
		
		$this->db->where('sys_itemcategory.CompanyCode', $this->session->userdata('company'));
		
		if($ItemCategoryID != ""){
			if($ItemCategoryID == "All"){
				
			}else{
				$this->db->like('am_item.ItemCategoryID', $ItemCategoryID);
			}
		}
		if($ItemCode != ""){$this->db->like('am_item.ItemCode', $ItemCode);}
		if($ItemDesc != ""){$this->db->like('am_item.ItemDesc', $ItemDesc);}
		
		$this->db->join('am_item', 'am_item.ItemCategoryID = am_itemcategory.ItemCategoryID', 'inner');
		$this->db->join('at_inventories', 'at_inventories.ItemCode = am_item.ItemCode', 'inner');
		$this->db->join('sys_itemcategory', 'sys_itemcategory.ItemCategoryID = am_itemcategory.ItemCategoryID', 'inner');
		$this->db->join('sys_itemaccount', 'sys_itemaccount.SysItemCategoryID = sys_itemcategory.SysItemCategoryID', 'inner');
		
		$count_data = $this->db->count_all_results('am_itemcategory');
		/*======================================end================================================*/
		
		$offset 	= $count_data - ($rows * $page);
		if($offset > 0){
			$rows 	= $rows;
		}
		else{
			$rows 	= $count_data - ($rows*($page-1));
		}
		
		/*===============ambil data dari model search_job_costing============================*/
		$result 	= $this->m_custom->search_all_item_by_kategori_no_asset();
		/*======================end=================================*/
		
		for($i=0; $i<=($rows-1); $i++){
			if($result[$i]->IsLock == 1){
				$Status = "Item Lock";
			}else{
				$Status = "Item UnLock";
			}
			$hasil[] = array(
				'ItemCode' 			=>	$result[$i]->ItemCode,
				'ItemDesc' 			=>	$result[$i]->ItemDesc,
				'ItemUnit' 			=>	$result[$i]->ItemUnit,
				'ItemAverage' 		=>	$result[$i]->ItemAverage,
				'ItemValue' 		=>	$result[$i]->ItemValue,
				'ItemCategoryID' 	=>	$result[$i]->ItemCategoryID,
				'ItemQty' 			=>	$result[$i]->ItemQty,
				'IsLock' 			=>	$Status,
				'ItemLockId' 		=>	$result[$i]->IsLock,
				'ItemCategoryName' 	=>	$result[$i]->ItemCategoryName
			);
		}
		/*===================jika kondisi kosong dari array $hasil=======================*/
		if(empty($hasil)){
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
		else{
			$result = array();
			$result['total'] = $count_data;
			$result['rows'] = $hasil;
			echo json_encode($result);
		}
		/*==============================end===========================================*/
    }
	/*====================================end==============================================================================*/
	
	/*============================pencarian dari master item by kategori and all kategori waktu pop up=======================================*/
	/*
		baru dipake di modul inventori initial amount
	*/
	function search_all_item_master(){
		$page			= ($this->input->post('page')) ? intval($this->input->post('page')) : 1;
		$rows			= ($this->input->post('rows')) ? intval($this->input->post('rows')) : 150;
		$hasil 			= array();
		
		/*=================================post dari find di atas pop up====================================================*/
		$param 				= $this->input->post('param');
		$ItemCategoryID		= isset($param['cmb_ItemCategoryID']) ? $param['cmb_ItemCategoryID'] : '';
		$ItemCode			= isset($param['txt_ItemCode']) ? $param['txt_ItemCode'] : '';
		$ItemDesc			= isset($param['txt_ItemDesc']) ? $param['txt_ItemDesc'] : '';
		/*============================================end============================================================*/
		
		/*===========================count data tabel job costing==================================*/
		//$this->db->where('BranchCode', $this->session->userdata('branch'));
		$this->db->where_in('am_item.TransStatus', array(0,1));
		
		if($ItemCategoryID != ""){
			if($ItemCategoryID == "All"){
				
			}else{
				$this->db->like('am_item.ItemCategoryID', $ItemCategoryID);
			}
		}
		if($ItemCode != ""){$this->db->like('am_item.ItemCode', $ItemCode);}
		if($ItemDesc != ""){$this->db->like('am_item.ItemDesc', $ItemDesc);}
		
		$this->db->join('am_item', 'am_item.ItemCategoryID = am_itemcategory.ItemCategoryID', 'inner');
		$count_data = $this->db->count_all_results('am_itemcategory');
		/*======================================end================================================*/
		
		$offset 	= $count_data - ($rows * $page);
		if($offset > 0){
			$rows 	= $rows;
		}
		else{
			$rows 	= $count_data - ($rows*($page-1));
		}
		
		/*===============ambil data dari model search_job_costing============================*/
		$result 	= $this->m_custom->search_all_item_master_by_kategori();
		
		/*======================end=================================*/
		
		for($i=0; $i<=($rows-1); $i++){
			if($result[$i]->IsLock == 1){
				$Status = "Item Lock";
			}else{
				$Status = "Item UnLock";
			}
			$hasil[] = array(
				'ItemCode' 			=>	$result[$i]->ItemCode,
				'ItemDesc' 			=>	$result[$i]->ItemDesc,
				'ItemUnit' 			=>	$result[$i]->ItemUnit,
				'ItemCategoryID' 	=>	$result[$i]->ItemCategoryID
			);
		}
		/*===================jika kondisi kosong dari array $hasil=======================*/
		if(empty($hasil)){
			$emptyVar = array();
			echo json_encode($emptyVar);
		}
		else{
			$result = array();
			$result['total'] = $count_data;
			$result['rows'] = $hasil;
			echo json_encode($result);
		}
		/*==============================end===========================================*/
    }
	/*====================================end==============================================================================*/
	
	function check_period_end_custom(){
		$datebox_value     = $this->input->post('datebox_value');
		
		$get_periode_end   = $this->m_custom->check_period_end_custom_date($datebox_value);
		$get_company_date   = $this->m_custom->check_company_date($datebox_value);
		//echo $this->db->last_query();
		
		if($get_periode_end == false){
			if($get_company_date == false){
				$return = array('message'=>false,'value'=>false,'CompDate' => false);
			}
			else{
				$return = array('message'=>true,'value'=>false,'CompDate' => $get_company_date->CompanyDate);
			}
        }else{
            if($get_company_date == false){
				$return = array('message'=>false,'value'=>$get_periode_end->PeriodEnd,'CompDate' => false);
			}
			else{
				$return = array('message'=>true,'value'=>$get_periode_end->PeriodEnd,'CompDate' => $get_company_date->CompanyDate);
			}
			
        }
		
        echo json_encode($return);
	}
}