<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Inventory_settings extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('inventory_settings_model', '', TRUE);
    }
    
    public function index() {
        $data = array();
        if (!empty($this->session->flashdata('success'))) 
            $data['success'] = $this->session->flashdata('success');
        else 
            $data['error'] = $this->session->flashdata('error');
        
        $data['setting'] = $this->inventory_settings_model->list_all();
        $data['statue_setting'] = $this->inventory_settings_model->statue_list();
        $actions = $this->actions();
        $data['form_action'] = $actions['update'];
        $data['view_link'] = $actions['view'];
        $data['edit_link'] = $actions['index'];
        
        $this->render($data, 'inventory_settings/edit');
    }
    
    public function update() {
        $inventory_id = $this->input->post('inventory_name');
        $inventory_id = (!empty($inventory_id)) ? $inventory_id : array();
        foreach($inventory_id as $key=>$id){
            $update = array (
                'status' => 1,
                'updated_on' => date('Y-m-d H:i:s'),
                'updated_by' => $this->user_data['user_id']
            );
            $this->inventory_settings_model->update($update,$id);
        }
        $setting = $this->inventory_settings_model->get_data($inventory_id);
        foreach($setting as $key=>$value){
            $update = array (
                'status' => 0,
                'updated_on' => date('Y-m-d H:i:s'),
                'updated_by' => $this->user_data['user_id']
            );
            $this->inventory_settings_model->update($update,$value->id);
        }
        
        /* $actions = $this->actions();
        $service_menu_id = 6; //Inventory Settings      
        add_login_details($args = array( 'page_type_id' => '2', 'service_menu_id' => $service_menu_id, 'menu_type' => '2', 'auto_id' => '')); */
        
        redirect('inventory_settings', 'refresh');
        
    }
}
?>