<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Statistical_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/statistical_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');
        
        $data['month_list'] = $this->month_list();
        if((!empty($this->input->post('submit'))) && ($this->input->post('submit') == 'Get Summary Data' || $this->input->post('submit') == 'Get Details Data' || $this->input->post('submit') == 'Print Summary Data' || $this->input->post('submit') == 'XLS Summary Data' || $this->input->post('submit') == 'Print Details Data' || $this->input->post('submit') == 'XLS Details Data' )) {
            
            $start_month = $this->input->post('start_month');
            $start_year = $this->input->post('start_year');
            $end_month = $this->input->post('end_month');
            $end_year = $this->input->post('end_year');
            $mobile = $this->input->post('mobile_no');
            $top = $this->input->post('top');
            $hidden_id = 1;
            $data_type = $this->input->post('submit');
        } else {
            $start_month = date('m');
            $start_year = date('Y');
            $end_month = date('m');
            $end_year = date('Y');
            $mobile = '';
            $top = '';
            $hidden_id = '';
            $data_type = 'Get Summary Data';
        }
        $start_date = '01-' . $start_month . '-'. $start_year;
        $end_date = '31-' . $end_month . '-'. $end_year;
        
        $data['results'] = $this->statistical_report_model->devotee_list($mobile,$top);
        
        $monthYear = array();
        if(!empty($this->input->post('month_years'))) {
            foreach($this->input->post('month_years') as $key=>$value) {
                array_push($monthYear,$this->input->post($value));
            } 
        }
        $data['monthYear'] = array_filter($monthYear);
        
        $data['start_month'] = $start_month;
        $data['start_year']  = $start_year;
        $data['end_month']   = $end_month;
        $data['end_year']    = $end_year;
        $data['mobile']      = $mobile;
        $data['top']         = $top;
        $data['hidden_id']   = $hidden_id;
        $data['data_type']   = $data_type;
        $data['form_action'] = 'statistical_report';
        $data['title'] = 'Statistical Report';
        
		  if($this->input->post('submit') == 'Print Summary Data' || $this->input->post('submit') == 'Print Details Data' || $this->input->post('submit') == 'XLS Summary Data' || $this->input->post('submit') == 'XLS Details Data' )
		{
			$data['dataType'] = $this->input->post('submit');
        if($this->input->post('submit') == 'Print Summary Data' || $this->input->post('submit') == 'Print Details Data' ){
           $data['dataType'] = $this->input->post('submit');
            if( IS_KSK ) :
                $html = $this->load->view('reports/statistical/pdf', $data, TRUE);
                print_rec($html);
                redirect('daily_summary_report','refresh');
            else :
                $this->render($data, 'reports/statistical/pdf');
            endif;
			} 
		else{
              $this->load->view('reports/statistical/statistical_excel', $data); 
           }
        } elseif($this->input->post('print') == 'Print') {
           redirect('kiosk/index/bill','refresh');
        }else {
            $this->render($data, 'reports/statistical/list');
        }
       
    }
    
    public function month_list() {
        $month_arr = array(
            '01' => 'Jan',
            '02' => 'Feb',
            '03' => 'Mar',
            '04' => 'Apr',
            '05' => 'May',
            '06' => 'Jun',
            '07' => 'Jul',
            '08' => 'Agu',
            '09' => 'Sep',
            '10' => 'Oct',
            '11' => 'Nov',
            '12' => 'Dec'
        );
        return $month_arr;
        
    }
   
} ?>

