<?php

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

class Index_biaya_bayar_dimuka extends CI_Controller {
    public $menu_model  = array('m_index_to_report','m_index_cash_bank', 'm_index_biaya_bayar_dimuka','m_index_sales', 'file/m_new_company', 'setup/m_branchinfo','custom/m_custom');
    public $menu_id_biaya_byr_dmuka_list           = 343;
    public $menu_id_depreciation_biaya_byr_dmuka   = 344;
    
    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 biaya_bayar_dimuka_list_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_biaya_byr_dmuka_list);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_biaya_byr_dmuka_list, $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_biaya_byr_dmuka_list);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_biaya_byr_dmuka_list, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/biaya_bayar_dimuka_report/v_biaya_bayar_dimuka_list_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }
    
    public function ajax_reloadDataBiayaBayarDimukaList(){        
        $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"){
            $data['company']    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
        }else{
            $data['company']    = $this->m_index_cash_bank->get_company_name($CompCode);
        }
        //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        
        $resultData = $this->m_index_biaya_bayar_dimuka->get_all_biaya_bayar_dimuka_list();
        //echo $this->db->last_query();
        if(count($resultData)>0){
            //print_r($resultData);die();
           
        }else{
            $resultData=[0];
        }
            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$data['company'],'branch'=>$BranchCode);
        echo json_encode($callBack);
    } 
            
    public function depreciation_biaya_bayar_dimuka_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_depreciation_biaya_byr_dmuka);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_depreciation_biaya_byr_dmuka, $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_depreciation_biaya_byr_dmuka);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_depreciation_biaya_byr_dmuka, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/biaya_bayar_dimuka_report/v_depreciation_biaya_bayar_dimuka_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }
    
    public function ajax_reloadDataDepreciationBiayaBayarDimukaList(){        
        $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"){
            $data['company']    = $this->m_index_cash_bank->get_company_by_branch($BranchCode);
        }else{
            $data['company']    = $this->m_index_cash_bank->get_company_name($CompCode);
        }
        //=======END Menyiapkan nama Company dan Branch utk ditampilkan di halaman =============//
        
        $resultData = $this->m_index_biaya_bayar_dimuka->get_all_depreciation_biaya_bayar_dimuka();
        //echo $this->db->last_query();
        if(count($resultData)>0){
            //print_r($resultData);die();
           
        }else{
            $resultData=[0];
        }
            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$data['company'],'branch'=>$BranchCode);
        echo json_encode($callBack);
    } 
    
    public function ajax_testSP(){        
        $resultData = $this->m_index_biaya_bayar_dimuka->get_all_testSP();
        echo json_encode($resultData);
    } 
    
}
?>
