<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * Author   : Dhidhik / Tanggal : 12-11-2015
 * Revisi   : 
 */

class Index_purchase extends CI_Controller {
    public $menu_model  = array('m_index_to_report','m_index_cash_bank', 'm_index_purchase','m_index_sales', 'file/m_new_company', 'setup/m_branchinfo','custom/m_custom');
    public $menu_id_purchase_requisitions_by_deptm              = 318;
    public $menu_id_purchase_requisitions_by_item               = 319;
    public $menu_id_purchase_invoice                            = 320;
    public $menu_id_purchase_amount_by_item                     = 321;
    public $menu_id_purchase_amount_by_item_ctgry               = 322;
    public $menu_id_purchase_return_by_vendor                   = 323;
    public $menu_id_purchase_return_by_item                     = 324;
    public $menu_id_purchase_return_by_item_catgry              = 325;
    
    public function __construct() {
        parent::__construct();
        $this->load->model($this->menu_model);

        $this->load->helper('convert_date_helper');
        $this->load->helper('status');
        $this->load->helper('message');
        $this->load->helper('number');

        if ($this->session->userdata("login") != TRUE) {
            redirect("login", "refresh");
            die;
        }
    }
    public function purchase_requisitions_by_departement_report() {        
        if ($this->session->userdata("login") == TRUE) { 
            $group_menu             = $this->session->userdata('group_menu');
            $arr_group_id           = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id_purchase_requisitions_by_deptm);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_purchase_requisitions_by_deptm, $data['available_menu'])) { 
                    redirect(base_url() . 'error', 'refresh');	
                }
                else{
                    $group_menu         = $this->session->userdata('group_menu');
                    $data['menu_model'] = $this->menu_model;
                    $data['menu_link'] 	= $this->m_menu->get_menulink($this->menu_id_purchase_requisitions_by_deptm);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_purchase_requisitions_by_deptm, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/purchase_report/v_purchase_requisitions_by_departement_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }    
    public function pre_ajax_reloadDataPurchaseRequisitionsByDepartement(){ 
        $txt_DateFrom   = "";
        $txt_DateTo     = "";
        $companyName    = "";
        $BranchCode     = "";
        $pages          = ($this->input->post('pages')!=null)?$this->input->post('pages'):array(pages=>1);
        if($pages['pages']<2){
            $txt_DateFrom   = $this->input->post('txt_DateFrom');
            $txt_DateTo     = $this->input->post('txt_DateTo');          
            //=======Menyiapkan nama Company dan Branch utk ditampilkan di halaman =================//
            $CompCode       = ($this->input->post('cmb_company')!=null)?$this->input->post('cmb_company'):'';
            $BranchCode     = ($this->input->post('cmb_branch')!=null)?$this->input->post('cmb_branch'):'';
            if($BranchCode!="" && $BranchCode!="All"){
                $companyName    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
            }else{
                $companyName    = $this->m_index_cash_bank->get_company_name($CompCode);
            }
            //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        }            
          
        $resultData = $this->m_index_purchase->pre_get_all_purchase_req_by_dept();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    } 
    public function ajax_reloadDataPurchaseRequisitionsByDepartement(){   
//        $resultData = $this->m_index_purchase->get_all_purchase();  
        $resultData = $this->m_index_purchase->get_all_purchase_req_by_dept();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    }   
     
    public function purchase_requisitions_by_item_report() {        
        if ($this->session->userdata("login") == TRUE) { 
            $group_menu             = $this->session->userdata('group_menu');
            $arr_group_id           = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id_purchase_requisitions_by_item);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_purchase_requisitions_by_item, $data['available_menu'])) { 
                    redirect(base_url() . 'error', 'refresh');	
                }
                else{
                    $group_menu         = $this->session->userdata('group_menu');
                    $data['menu_model'] = $this->menu_model;
                    $data['menu_link'] 	= $this->m_menu->get_menulink($this->menu_id_purchase_requisitions_by_item);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_purchase_requisitions_by_item, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/purchase_report/v_purchase_requisitions_by_item_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }
    public function pre_ajax_reloadDataPurchaseRequisitionsByItem(){ 
        $txt_DateFrom   = "";
        $txt_DateTo     = "";
        $companyName    = "";
        $BranchCode     = "";
        $pages          = ($this->input->post('pages')!=null)?$this->input->post('pages'):array(pages=>1);
        if($pages['pages']<2){
            $txt_DateFrom   = $this->input->post('txt_DateFrom');
            $txt_DateTo     = $this->input->post('txt_DateTo');          
            //=======Menyiapkan nama Company dan Branch utk ditampilkan di halaman =================//
            $CompCode       = ($this->input->post('cmb_company')!=null)?$this->input->post('cmb_company'):'';
            $BranchCode     = ($this->input->post('cmb_branch')!=null)?$this->input->post('cmb_branch'):'';
            if($BranchCode!="" && $BranchCode!="All"){
                $companyName    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
            }else{
                $companyName    = $this->m_index_cash_bank->get_company_name($CompCode);
            }
            //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        }            
          
        $resultData = $this->m_index_purchase->pre_get_all_purchase_req_by_item();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    } 
    public function ajax_reloadDataPurchaseRequisitionsByItem(){   
//        $resultData = $this->m_index_purchase->get_all_purchase();  
        $resultData = $this->m_index_purchase->get_all_purchase_req_by_item();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    }  
    
    public function purchase_invoices_report() {        
        if ($this->session->userdata("login") == TRUE) { 
            $group_menu             = $this->session->userdata('group_menu');
            $arr_group_id           = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id_purchase_invoice);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_purchase_invoice, $data['available_menu'])) { 
                    redirect(base_url() . 'error', 'refresh');	
                }
                else{
                    $group_menu         = $this->session->userdata('group_menu');
                    $data['menu_model'] = $this->menu_model;
                    $data['menu_link'] 	= $this->m_menu->get_menulink($this->menu_id_purchase_invoice);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_purchase_invoice, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/purchase_report/v_purchase_invoices_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }    
    public function pre_ajax_reloadDataPurchaseInvoices(){
        $txt_DateFrom   = "";
        $txt_DateTo     = "";
        $companyName    = "";
        $BranchCode     = "";
        $pages          = ($this->input->post('pages')!=null)?$this->input->post('pages'):array(pages=>1);
        if($pages['pages']<2){
            $txt_DateFrom   = $this->input->post('txt_DateFrom');
            $txt_DateTo     = $this->input->post('txt_DateTo');          
            //=======Menyiapkan nama Company dan Branch utk ditampilkan di halaman =================//
            $CompCode       = ($this->input->post('cmb_company')!=null)?$this->input->post('cmb_company'):'';
            $BranchCode     = ($this->input->post('cmb_branch')!=null)?$this->input->post('cmb_branch'):'';
            if($BranchCode!="" && $BranchCode!="All"){
                $companyName    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
            }else{
                $companyName    = $this->m_index_cash_bank->get_company_name($CompCode);
            }
            //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        }            
          
        $resultData = $this->m_index_purchase->pre_get_all_purchase_invoices();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    }  
    public function ajax_reloadDataPurchaseInvoices(){    
        $resultData = $this->m_index_purchase->get_all_purchase_invoices();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    }   
    
    public function purchase_amount_by_item_report() {        
        if ($this->session->userdata("login") == TRUE) { 
            $group_menu             = $this->session->userdata('group_menu');
            $arr_group_id           = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id_purchase_amount_by_item);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_purchase_amount_by_item, $data['available_menu'])) { 
                    redirect(base_url() . 'error', 'refresh');	
                }
                else{
                    $group_menu         = $this->session->userdata('group_menu');
                    $data['menu_model'] = $this->menu_model;
                    $data['menu_link'] 	= $this->m_menu->get_menulink($this->menu_id_purchase_amount_by_item);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_purchase_amount_by_item, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/purchase_report/v_purchase_amount_by_item_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }    
    public function pre_ajax_reloadDataPurchaseAmountItem(){ 
        $txt_DateFrom   = "";
        $txt_DateTo     = "";
        $companyName    = "";
        $BranchCode     = "";
        $pages          = ($this->input->post('pages')!=null)?$this->input->post('pages'):array(pages=>1);
        if($pages['pages']<2){
            $txt_DateFrom   = $this->input->post('txt_DateFrom');
            $txt_DateTo     = $this->input->post('txt_DateTo');          
            //=======Menyiapkan nama Company dan Branch utk ditampilkan di halaman =================//
            $CompCode       = ($this->input->post('cmb_company')!=null)?$this->input->post('cmb_company'):'';
            $BranchCode     = ($this->input->post('cmb_branch')!=null)?$this->input->post('cmb_branch'):'';
            if($BranchCode!="" && $BranchCode!="All"){
                $companyName    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
            }else{
                $companyName    = $this->m_index_cash_bank->get_company_name($CompCode);
            }
            //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        }            
          
        $resultData = $this->m_index_purchase->pre_get_all_purchase_amount_item();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }
            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    } 
    public function ajax_reloadDataPurchaseAmountItem(){   
        $resultData = $this->m_index_purchase->get_all_purchase_amount_item();
        if(count($resultData)>0){
//            $resultData[$indexData]->itemTransStatus = $dtResult->itemTransStatus==1?"Active":"Non Active";
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    }
    
    public function purchase_amount_by_item_category_report() {        
        if ($this->session->userdata("login") == TRUE) { 
            $group_menu             = $this->session->userdata('group_menu');
            $arr_group_id           = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id_purchase_amount_by_item_ctgry);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_purchase_amount_by_item_ctgry, $data['available_menu'])) { 
                    redirect(base_url() . 'error', 'refresh');	
                }
                else{
                    $group_menu         = $this->session->userdata('group_menu');
                    $data['menu_model'] = $this->menu_model;
                    $data['menu_link'] 	= $this->m_menu->get_menulink($this->menu_id_purchase_amount_by_item_ctgry);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_purchase_amount_by_item_ctgry, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/purchase_report/v_purchase_amount_by_item_category_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }    
    public function pre_ajax_reloadDataPurchaseAmountItemCategory(){ 
        $txt_DateFrom   = "";
        $txt_DateTo     = "";
        $companyName    = "";
        $BranchCode     = "";
        $pages          = ($this->input->post('pages')!=null)?$this->input->post('pages'):array(pages=>1);
        if($pages['pages']<2){
            $txt_DateFrom   = $this->input->post('txt_DateFrom');
            $txt_DateTo     = $this->input->post('txt_DateTo');          
            //=======Menyiapkan nama Company dan Branch utk ditampilkan di halaman =================//
            $CompCode       = ($this->input->post('cmb_company')!=null)?$this->input->post('cmb_company'):'';
            $BranchCode     = ($this->input->post('cmb_branch')!=null)?$this->input->post('cmb_branch'):'';
            if($BranchCode!="" && $BranchCode!="All"){
                $companyName    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
            }else{
                $companyName    = $this->m_index_cash_bank->get_company_name($CompCode);
            }
            //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        }            

        $resultData = $this->m_index_purchase->pre_get_all_purchase_amount_item_category();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }
            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    }
    public function ajax_reloadDataPurchaseAmountItemCategory(){   
        $resultData = $this->m_index_purchase->get_all_purchase_amount_item_category();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    }
        
    public function purchase_return_by_vendor_report() {        
        if ($this->session->userdata("login") == TRUE) { 
            $group_menu             = $this->session->userdata('group_menu');
            $arr_group_id           = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id_purchase_return_by_vendor);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_purchase_return_by_vendor, $data['available_menu'])) { 
                    redirect(base_url() . 'error', 'refresh');	
                }
                else{
                    $group_menu         = $this->session->userdata('group_menu');
                    $data['menu_model'] = $this->menu_model;
                    $data['menu_link'] 	= $this->m_menu->get_menulink($this->menu_id_purchase_return_by_vendor);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_purchase_return_by_vendor, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/purchase_report/v_purchase_return_by_vendor_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }    
    public function pre_ajax_reloadDataPurchaseReturnByVendor(){   
        $txt_DateFrom   = "";
        $txt_DateTo     = "";
        $companyName    = "";
        $BranchCode     = "";
        $pages          = ($this->input->post('pages')!=null)?$this->input->post('pages'):array(pages=>1);
        if($pages['pages']<2){
            $txt_DateFrom   = $this->input->post('txt_DateFrom');
            $txt_DateTo     = $this->input->post('txt_DateTo');          
            //=======Menyiapkan nama Company dan Branch utk ditampilkan di halaman =================//
            $CompCode       = ($this->input->post('cmb_company')!=null)?$this->input->post('cmb_company'):'';
            $BranchCode     = ($this->input->post('cmb_branch')!=null)?$this->input->post('cmb_branch'):'';
            if($BranchCode!="" && $BranchCode!="All"){
                $companyName    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
            }else{
                $companyName    = $this->m_index_cash_bank->get_company_name($CompCode);
            }
            //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        } 
        
        $resultData = $this->m_index_purchase->pre_get_all_purchase_return_by_vendor();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    }
    public function ajax_reloadDataPurchaseReturnByVendor(){   
        $resultData = $this->m_index_purchase->get_all_purchase_return_by_vendor();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }
            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    }
    
    public function purchase_return_by_item_report() {        
        if ($this->session->userdata("login") == TRUE) { 
            $group_menu             = $this->session->userdata('group_menu');
            $arr_group_id           = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id_purchase_return_by_item);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_purchase_return_by_item, $data['available_menu'])) { 
                    redirect(base_url() . 'error', 'refresh');	
                }
                else{
                    $group_menu         = $this->session->userdata('group_menu');
                    $data['menu_model'] = $this->menu_model;
                    $data['menu_link'] 	= $this->m_menu->get_menulink($this->menu_id_purchase_return_by_item);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_purchase_return_by_item, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/purchase_report/v_purchase_return_by_item_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }
    public function pre_ajax_reloadDataPurchaseReturnByItem(){   
        $txt_DateFrom   = "";
        $txt_DateTo     = "";
        $companyName    = "";
        $BranchCode     = "";
        $pages          = ($this->input->post('pages')!=null)?$this->input->post('pages'):array(pages=>1);
        if($pages['pages']<2){
            $txt_DateFrom   = $this->input->post('txt_DateFrom');
            $txt_DateTo     = $this->input->post('txt_DateTo');          
            //=======Menyiapkan nama Company dan Branch utk ditampilkan di halaman =================//
            $CompCode       = ($this->input->post('cmb_company')!=null)?$this->input->post('cmb_company'):'';
            $BranchCode     = ($this->input->post('cmb_branch')!=null)?$this->input->post('cmb_branch'):'';
            if($BranchCode!="" && $BranchCode!="All"){
                $companyName    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
            }else{
                $companyName    = $this->m_index_cash_bank->get_company_name($CompCode);
            }
            //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        } 
        
        $resultData = $this->m_index_purchase->pre_get_all_purchase_return_by_item();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    }
    public function ajax_reloadDataPurchaseReturnByItem(){   
        $resultData = $this->m_index_purchase->get_all_purchase_return_by_item();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }
            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    }
    
    public function purchase_return_by_item_category_report() {        
        if ($this->session->userdata("login") == TRUE) { 
            $group_menu             = $this->session->userdata('group_menu');
            $arr_group_id           = $this->m_menu->get_menu_by_group($group_menu, $this->menu_id_purchase_return_by_item_catgry);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_purchase_return_by_item_catgry, $data['available_menu'])) { 
                    redirect(base_url() . 'error', 'refresh');	
                }
                else{
                    $group_menu         = $this->session->userdata('group_menu');
                    $data['menu_model'] = $this->menu_model;
                    $data['menu_link'] 	= $this->m_menu->get_menulink($this->menu_id_purchase_return_by_item_catgry);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_purchase_return_by_item_catgry, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/purchase_report/v_purchase_return_by_item_category_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }
    public function pre_ajax_reloadDataPurchaseReturnByItemCategory(){
        $txt_DateFrom   = "";
        $txt_DateTo     = "";
        $companyName    = "";
        $BranchCode     = "";
        $pages          = ($this->input->post('pages')!=null)?$this->input->post('pages'):array(pages=>1);
        if($pages['pages']<2){
            $txt_DateFrom   = $this->input->post('txt_DateFrom');
            $txt_DateTo     = $this->input->post('txt_DateTo');          
            //=======Menyiapkan nama Company dan Branch utk ditampilkan di halaman =================//
            $CompCode       = ($this->input->post('cmb_company')!=null)?$this->input->post('cmb_company'):'';
            $BranchCode     = ($this->input->post('cmb_branch')!=null)?$this->input->post('cmb_branch'):'';
            if($BranchCode!="" && $BranchCode!="All"){
                $companyName    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
            }else{
                $companyName    = $this->m_index_cash_bank->get_company_name($CompCode);
            }
            //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        }            

        $resultData = $this->m_index_purchase->pre_get_all_purchase_return_by_item_category();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    }    
    public function ajax_reloadDataPurchaseReturnByItemCategory(){ 
        $resultData = $this->m_index_purchase->get_all_purchase_return_by_item_category();
        if(count($resultData)>0){
            
        }else{
            $resultData=[0];
        }            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    }
}
?>