<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Inventory_sale_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/inventory_sale_report_model', '', TRUE);
        $this->uri_key_index = 0;
    }
    
    public function index() {
        $actions = $this->actions();
        $post = $this->input->post();
        
        $data = array(
            'title'     => 'General Inventory Report',
            'form_action'=> 'inventory_sale_report',
            'start_date'=> $post['start_date'],
            'end_date'  => $post['end_date'],
            'item_id'   => $post['item_id'],
            'date_type' => $post['date_type'],
            'success'   => $this->session->flashdata('success'),
            'error'     => $this->session->flashdata('error'),
        );
       
        $return = $this->inventory_sale_report_model->get_all();
        $data['results']    = $return['results'];
        $data['inv_items']  = $return['inv_items'];        

        $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/inventory_sale/pdf', $data, TRUE);
                print_rec($html);
                redirect('inventory_sale_report','refresh');
            else :
                $this->render($data, 'reports/inventory_sale/pdf');
            endif;
        } else {
            $this->render($data, 'reports/inventory_sale/list');
        }
    }
   
} ?>

