<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Prasadam_sale_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/prasadam_sale_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')) {
            $start_date = $this->input->post('start_date');
            $end_date = $this->input->post('end_date');
            $type = $this->input->post('type');
            $god = $this->input->post('god_name');
        } else {
            $start_date = '';
            $end_date = '';
            $type = '';
            $god = '';
        }
        $data['results'] = $this->prasadam_sale_report_model->get_data($start_date,$end_date,$type,$unit);
        $data['types'] = $this->prasadam_sale_report_model->service_types();
        $data['gods'] = $this->prasadam_sale_report_model->god_list();
        $data['units'] = $this->prasadam_sale_report_model->unit_list();
        $data['start_date'] = $start_date;
        $data['end_date'] = $end_date;
        $data['type'] = $type;
        $data['god'] = $god;
        $actions = $this->actions();
        $data['form_action'] = 'prasadam_sale_report';
        $data['title'] = 'Prasadam Sale 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/prasadam_sale/pdf', $data, TRUE);
                print_rec($html);
                redirect('prasadam_sale_report','refresh');
            else :
                $this->render($data, 'reports/prasadam_sale/pdf');
            endif;
        } else {
            $this->render($data, 'reports/prasadam_sale/list');
        }
    }
   
} ?>

