<?php
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');
            $abishegam = $this->monthly_model->get_abishegam_data($start_date,$end_date,$data_type);
            $festival = $this->monthly_model->get_festival_data($start_date,$end_date,$data_type);
            $ubayam = $this->monthly_model->get_ubayam_data($start_date,$end_date,$data_type);
            $mega = $this->monthly_model->get_mega_data($start_date,$end_date,$data_type);
            $other = $this->monthly_model->get_other_service_data($start_date,$end_date,$data_type);
            $gold_silver = $this->monthly_model->get_gold_silver_data($start_date,$end_date,$data_type);
            $temple = $this->monthly_model->get_temple_activity_data($start_date,$end_date,$data_type);
            $member_subscripe = $this->monthly_model->get_member_subscribe_data($start_date,$end_date,$data_type);
            $building_fund  = $this->monthly_model->get_building_fund_data($start_date,$end_date,$data_type);
            $outdoor = $this->monthly_model->get_outdoor_data($start_date,$end_date,$data_type);
            $prasadam = $this->monthly_model->get_prasadam_data($start_date,$end_date,$data_type);
            $madappalli = $this->monthly_model->get_madappalli_data($start_date,$end_date,$data_type);
            $donation = $this->monthly_model->get_donation_data($start_date,$end_date,$data_type);
            $hall_booking = $this->monthly_model->get_hall_booking_data($start_date,$end_date,$data_type);
            $wedding_hall = $this->monthly_model->get_wed_hall_booking_data($start_date,$end_date,$data_type);
            $archanai = $this->monthly_model->get_archanai_data($start_date,$end_date,$data_type);
            $kattalai = $this->monthly_model->get_kattalai_data($start_date,$end_date,$data_type);
            $membership = $this->monthly_model->get_membership_data($start_date,$end_date,$data_type);
            $card_topup = $this->monthly_model->get_membership_card_topup_data($start_date,$end_date,$data_type);
            $temple_shop = $this->monthly_model->get_temple_shop_data($start_date,$end_date,$data_type);
        }else  {
            $start_date = '';
            $end_date = '';
            $data_type = 'Get Summary Data';
            $abishegam = $this->monthly_model->get_abishegam_data($start_date = '',$end_date = '',$data_type);
            $festival = $this->monthly_model->get_festival_data($start_date = '',$end_date = '',$data_type);
            $ubayam = $this->monthly_model->get_ubayam_data($start_date = '',$end_date = '',$data_type);
            $mega = $this->monthly_model->get_mega_data($start_date = '',$end_date = '',$data_type);
            $other = $this->monthly_model->get_other_service_data($start_date = '',$end_date = '',$data_type);
            $gold_silver = $this->monthly_model->get_gold_silver_data($start_date = '',$end_date = '',$data_type);
            $temple = $this->monthly_model->get_temple_activity_data($start_date = '',$end_date = '',$data_type);
            $member_subscripe = $this->monthly_model->get_member_subscribe_data($start_date = '',$end_date = '',$data_type);
            $building_fund  = $this->monthly_model->get_building_fund_data($start_date = '',$end_date = '',$data_type);
            $outdoor = $this->monthly_model->get_outdoor_data($start_date = '',$end_date = '',$data_type);
            $prasadam = $this->monthly_model->get_prasadam_data($start_date = '',$end_date = '',$data_type);
            $madappalli = $this->monthly_model->get_madappalli_data($start_date = '',$end_date = '',$data_type);
            $donation = $this->monthly_model->get_donation_data($start_date = '',$end_date = '',$data_type);
            $hall_booking = $this->monthly_model->get_hall_booking_data($start_date = '',$end_date = '',$data_type);
            $wedding_hall = $this->monthly_model->get_wed_hall_booking_data($start_date = '',$end_date = '',$data_type);
            $archanai = $this->monthly_model->get_archanai_data($start_date = '',$end_date = '',$data_type);
            $kattalai = $this->monthly_model->get_kattalai_data($start_date = '',$end_date = '',$data_type);
            $membership = $this->monthly_model->get_membership_data($start_date = '',$end_date = '',$data_type);
            $card_topup = $this->monthly_model->get_membership_card_topup_data($start_date = '',$end_date = '',$data_type);
            $temple_shop = $this->monthly_model->get_temple_shop_data($start_date = '',$end_date = '',$data_type);
        }
        #echo '<pre>';print_r($abishegam);die;
        $data['results'] = array_merge($abishegam,$archanai,$building_fund,$donation,$festival,$gold_silver,$hall_booking,$kattalai,$madappalli,$mega,$member_subscripe,$membership,$card_topup,$outdoor,$other,$prasadam,$temple,$temple_shop,$ubayam,$wedding_hall); //--
        #echo '<pre>';print_r($data['results']);exit;
        $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($html);
                redirect('monthly_report','refresh');
            else :
                $this->render($data, 'reports/monthly/pdf');
            endif;
        } else {
            $this->render($data, 'reports/monthly/list');
        }
    }
   
} ?>

