<?php

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

class Index_inventory extends CI_Controller {
    public $menu_model  = array('m_index_to_report','m_index_cash_bank', 'm_index_inventory','m_index_sales', 'file/m_new_company', 'setup/m_branchinfo','custom/m_custom');
    public $menu_id_inventory_qty_list     = 335;
    public $menu_id_inventory_qty_cogs_list= 401;
    
    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 inventory_quantity_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_inventory_qty_list);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_inventory_qty_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_inventory_qty_list);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_inventory_qty_list, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/inventory_report/v_inventory_qty_list_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }
    public function pre_ajax_reloadDataInventoryQtyList(){   
        $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_inventory->pre_get_all_inventory_qty_list();
        count($resultData)>0?null:$resultData=[0];
            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    } 
    public function ajax_reloadDataInventoryQtyList(){    
        $resultData = $this->m_index_inventory->get_all_inventory_qty_list();
        count($resultData)>0?null:$resultData=[0];
            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    } 
            
    public function inventory_quantity_cogs_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_inventory_qty_cogs_list);
            if(!empty($arr_group_id)){
                $data['available_menu'] = array_unique($arr_group_id);
                if(!in_array($this->menu_id_inventory_qty_cogs_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_inventory_qty_cogs_list);
                    //panggil model hak akses untuk autoriti
                    $data['group_user'] = $this->m_menu->group_user_autority($this->menu_id_inventory_qty_cogs_list, $group_menu);
                    $this->load->view('v_header');
                    $this->load->view('report/inventory_report/v_inventory_qty_cogs_list_report', $data);
                    $this->load->view('v_footer');		
                }
            }else{
                redirect(base_url() . 'error', 'refresh');
            }
        }
        else {
            redirect(base_url() . 'login', 'refresh');
        }                    
    }
    public function pre_ajax_reloadDataInventoryQtyCogsList(){   
        $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_inventory->pre_get_all_inventory_qty_cogs_list();
        count($resultData)>0?null:$resultData=[0];
            
        $callBack =array('datas'=>$resultData, 'startdate'=>$txt_DateFrom,'enddate'=>$txt_DateTo, 'company'=>$companyName,'branch'=>$BranchCode);
        echo json_encode($callBack);
    } 
    public function ajax_reloadDataInventoryQtyCogsList(){    
        $resultData = $this->m_index_inventory->get_all_inventory_qty_cogs_list();
        count($resultData)>0?null:$resultData=[0];
            
        $callBack =array('datas'=>$resultData);
        echo json_encode($callBack);
    } 
    public function get_items(){        
        $CompanyCode    = $this->uri->segment(4);
        $BranchCode     = $this->uri->segment(5);
        $list_bank      = $this->m_inventory->get_items($CompanyCode,$BranchCode);
        //$list_bank      = json_decode($list_bank);
        $list_bank[]    = array("ItemCode"=>"All","ItemDesc"=>"All");
        echo json_encode($list_bank);
    }
}
?>
