<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Statue_books_stock_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/statue_books_stock_report_model', '', TRUE);
        $this->uri_key_index = 0;
    }
    
    public function index() {
        $data = array();
       
        if (!empty($this->session->flashdata('success'))) 
            $data['success'] = $this->session->flashdata('success');
        else 
            $data['error'] = $this->session->flashdata('error');
        
        if((!empty($this->input->post('submit'))) && ($this->input->post('submit') == 'Get Data' || $this->input->post('submit') == 'Print Data')) {
            $cat_id = $this->input->post('cat_id');
            $item_id = $this->input->post('item_id');
        } else {
            $cat_id = '';
            $item_id = '';
        }
        $data['results'] = $this->statue_books_stock_report_model->get_data($cat_id,$item_id);
        $data['cat_id'] = $cat_id;
        $data['item_id'] = $item_id;
        $data['categories'] = $this->statue_books_stock_report_model->list_category();
        $data['items'] = $this->statue_books_stock_report_model->list_cat_item($cat_id);
        $actions = $this->actions();
        $data['form_action'] = 'statue_books_stock_report';
        $data['title'] = 'Statue and Books Stock Report';
        
        $filters = array();
        if(!empty($this->input->post('filter_columns'))) {
            foreach($this->input->post('filter_columns') as $key=>$value) {
                array_push($filters,$this->input->post($value));
            } 
        }
        $data['filters'] = array_filter($filters);
        
        if($this->input->post('submit') == 'Print Data'){
            if( IS_KSK ) :
                $html = $this->load->view('reports/statue_books_stock/pdf', $data, TRUE);
                print_rec($html);
                redirect('statue_books_stock_report','refresh');
            else :
                $this->render($data, 'reports/statue_books_stock/pdf');
            endif;
        } else {
            $this->render($data, 'reports/statue_books_stock/list');
        }
    }
    
    public function get_item_by_cat_id(){
        $data['items'] =  $this->statue_books_stock_report_model->list_cat_item($_POST['cat_id']);
        echo json_encode($data);
        exit(0);
    }
   
} ?>

