<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*	
 * Author   : Wahyu /Tanggal : 22-07-2014	
 * Revisi   : Ferry
 */
 
class Preference_approval extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->model('m_preference');
        $this->load->helper('regex');
        $this->load->helper('message');
        $this->load->helper('status');
	}

    public function index(){
        $this->load->view('v_header');
        $this->load->view('preference/view_sales_approval_limit');
        $this->load->view('v_footer');
    }
	
    function list_approval_limit(){
        echo $this->m_preference->get_all_list_approval_limit();
    }

    //PROCESS POST DATA    
    function proses_post_data_approval_limit(){
        try{
            $dataSend   = [];
            $dataSend['data_approval_limit']   = [];
            
            $company_code       = $this->session->userdata('company');

            $jobtitle           = $this->input->post('jobtitle');
            $LimitBegin_angka   = $this->input->post('LimitBegin_angka');
            $LimitEnd_angka     = $this->input->post('LimitEnd_angka');

            $dataSend['data_approval_limit'][] = array(
                'CompanyCode'   => $company_code,
                'JobTitleCode'  => $jobtitle, 
                'LimitBegin'    => $LimitBegin_angka,
                'LimitEnd'      => $LimitEnd_angka,
                'LastUser'      => $this->session->userdata('username')
            );
//            $this->m_preference->insert_approval_limit($data_approval_limit); 

            $rstDataSend = $this->m_preference->data_send_preference_approval_insert($dataSend);//tinggal di model
            if($rstDataSend){
                $result['status'] 	= true;
                $result['message']	= get_notification('insert', 1);                
            }else{
                $result['status'] 	= false;
                $result['message']	= get_notification('insert', 0);
            }
            echo json_encode($result);
        }catch (Exception $e){            
            $result['status']   = false;
            $result['message']  = $e->getMessage();
            echo json_encode($result);
        }
    }
    function proses_post_data_approval_limit_LAMA(){
        $company_code       = $this->session->userdata('company');
        
        $jobtitle           = $this->input->post('jobtitle');
        $LimitBegin_angka   = $this->input->post('LimitBegin_angka');
        $LimitEnd_angka     = $this->input->post('LimitEnd_angka');
		
        $data_approval_limit = array(
                                'CompanyCode'   => $company_code,
                                'JobTitleCode'  => $jobtitle, 
                                'LimitBegin'    => $LimitBegin_angka,
                                'LimitEnd'      => $LimitEnd_angka,
                                'LastUser'      => $this->session->userdata('username')
                                );
		
        $this->m_preference->insert_approval_limit($data_approval_limit);
    }
	
    
    function edit_data_approval_limit(){
        try{
            $dataSend   = [];
            $dataSend['data_approval_limit']   = [];
            
            $jobtitle_edit          = $this->input->post('jobtitle_edit');
            $LimitBegin_angka_edit  = str_replace(array('.',',00'),'',$this->input->post('LimitBegin_angka_edit'));
            $LimitEnd_angka_edit    = str_replace(array('.',',00'),'',$this->input->post('LimitEnd_angka_edit'));
            $dataSend['data_approval_limit'] = array(
                'LimitBegin'    => $LimitBegin_angka_edit,
                'LimitEnd'      => $LimitEnd_angka_edit,
                'jobtitle_edit' => $jobtitle_edit
            );
           // $this->m_preference->update_approval_limit($data_approval_limit, $jobtitle_edit);
            
            $rstDataSend = $this->m_preference->data_send_preference_approval_update($dataSend);//tinggal di model
            if($rstDataSend){
                $result['status'] 	= true;
                $result['message']	= get_notification('insert', 1);                
            }else{
                $result['status'] 	= false;
                $result['message']	= get_notification('insert', 0);
            }
            echo json_encode($result);
        }catch (Exception $e){            
            $result['status']   = false;
            $result['message']  = $e->getMessage();
            echo json_encode($result);
        }
    }
    function edit_data_approval_limit_LAMA(){
        $jobtitle_edit          = $this->input->post('jobtitle_edit');
        $LimitBegin_angka_edit  = str_replace(array('.',',00'),'',$this->input->post('LimitBegin_angka_edit'));
        $LimitEnd_angka_edit    = str_replace(array('.',',00'),'',$this->input->post('LimitEnd_angka_edit'));
		
        $data_approval_limit = array(
                                'LimitBegin'    => $LimitBegin_angka_edit,
                                'LimitEnd'      => $LimitEnd_angka_edit
                                );

        $this->m_preference->update_approval_limit($data_approval_limit, $jobtitle_edit);
    }
	
    function delete_approval_limit(){
        try{
            $id = $this->input->post('id');
            $dataSend   = [];
            $dataSend['idcode'] = $id;

            //$this->m_preference->delete_approval_limit($id);
            
            $rstDataSend = $this->m_preference->data_send_preference_approval_delete($dataSend);
            if($rstDataSend){
                $result['status'] 	= true;
                $result['message']	= get_notification('delete', 1);                
            }else{
                $result['status'] 	= false;
                $result['message']	= get_notification('delete', 0);
            }
            echo json_encode($result);
        }catch (Exception $e){            
            $result['status']   = false;
            $result['message']  = $e->getMessage();
            echo json_encode($result);
        }
    }
    function delete_approval_limit_LAMA(){
        $id = $this->input->post('id');
        $this->m_preference->delete_approval_limit($id);
    }
}

/* End of file Preference_approval.php */
/* Location: ./application/controllers/Preference_approval.php */