<?php
set_time_limit(0);
ini_set('memory_limit', -1);
ini_set('post_max_size', '2000M');

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Monthly_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/monthly_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 Summary Data'  || $this->input->post('submit') == 'Print Summary Data' || $this->input->post('submit') == 'Get Details Data' || $this->input->post('submit') == 'Print Details Data')) {
            $start_date = $this->input->post('start_date');
            $end_date = $this->input->post('end_date');
            $data_type = $this->input->post('submit');
            $result_data = $this->monthly_model->get_monthly_data_details($start_date,$end_date,$data_type);
            
        }else  {
            $start_date = '';
            $end_date = '';
            $data_type = 'Get Summary Data';
            $result_data = $this->monthly_model->get_monthly_data_details($start_date = '',$end_date = '',$data_type);
        }
        $data['results'] = $result_data;
       
        
        $data['start_date'] = $start_date;
        $data['end_date'] = $end_date;
        $data['type'] = $data_type;
        $data['mode'] = $this->monthly_model->payment_type_list();
        $actions = $this->actions();
        $data['form_action'] = 'monthly_report';
        $data['title'] = 'Monthly Summary 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 Summary Data' || $this->input->post('submit') == 'Print Details Data' ){
            $data['dataType'] = $this->input->post('submit');
            if( IS_KSK ) :
                $html = $this->load->view('reports/monthly/pdf', $data, TRUE);
                print_rec_monthly($html);
                redirect('monthly_report','refresh');
            else :
                $this->render($data, 'reports/monthly/pdf');
            endif;
        } else {
            $this->render($data, 'reports/monthly/list');
        }
    }
   
} 
?>