<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Donation_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/donation_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 Summary Data' || $this->input->post('submit') == 'Print Summary Data' || $this->input->post('submit') == 'Get Pledge Data' || $this->input->post('submit') == 'Print Pledge Data')) {
            $start_date = $this->input->post('start_date');
            $end_date = $this->input->post('end_date');
            $type_id = $this->input->post('type_id');
            $mobile_no = $this->input->post('mobile_no');
            $pledge = $this->input->post('pledge');
            $pledge_type = $this->input->post('pledge_type');
            $data_type = $this->input->post('submit');
        } else {
            $start_date = '';
            $end_date = '';
            $type_id = '';
            $mobile_no = '';
            $pledge = '';
            $pledge_type = '';
            $data_type = 'Get Summary Data';
        }
        
        if($pledge == 2) {
            $data['results'] = $this->donation_report_model->get_data($start_date,$end_date,$type_id,$mobile_no,$pledge,$pledge_type);
        } else{
            $data['results'] = $this->donation_report_model->get_pledge_data($start_date,$end_date,$type_id,$mobile_no,$pledge,$pledge_type);
        }
        
        $data['start_date'] = $start_date;
        $data['end_date'] = $end_date;
        $data['type_id'] = $type_id;
        $data['mobile_no'] = $mobile_no;
        $data['pledge'] = $pledge;
        $data['pledge_type'] = $pledge_type;
        $data['types'] = $this->donation_report_model->list_service_type();
        $data['data_type'] = $data_type;
        $actions = $this->actions();
        $data['form_action'] = 'donation_report';
        $data['title'] = 'Donation Report';
        $data['hidden_print'] = 1;
        
        $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 Pledge Data'){
            if( IS_KSK ) :
                $html = $this->load->view('reports/donation/pdf', $data, TRUE);
                print_rec($html);
                redirect('donation_report','refresh');
            else :
                $this->render($data, 'reports/donation/pdf');
            endif;
        } else {
            $this->render($data, 'reports/donation/list');
        }
    }
   
} ?>

