<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Weekly_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/weekly_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->weekly_model->get_abishegam_data($start_date,$end_date,$data_type);
            $festival = $this->weekly_model->get_festival_data($start_date,$end_date,$data_type);
            $ubayam = $this->weekly_model->get_ubayam_data($start_date,$end_date,$data_type);
            $mega = $this->weekly_model->get_mega_data($start_date,$end_date,$data_type);
            $other = $this->weekly_model->get_other_service_data($start_date,$end_date,$data_type);
            $gold_silver = $this->weekly_model->get_gold_silver_data($start_date,$end_date,$data_type);
            $temple = $this->weekly_model->get_temple_activity_data($start_date,$end_date,$data_type);
            $member_subscripe = $this->weekly_model->get_member_subscribe_data($start_date,$end_date,$data_type);
            $building_fund  = $this->weekly_model->get_building_fund_data($start_date,$end_date,$data_type);
            $outdoor = $this->weekly_model->get_outdoor_data($start_date,$end_date,$data_type);
            $prasadam = $this->weekly_model->get_prasadam_data($start_date,$end_date,$data_type);
            $madappalli = $this->weekly_model->get_madappalli_data($start_date,$end_date,$data_type);
            $donation = $this->weekly_model->get_donation_data($start_date,$end_date,$data_type);
            $hall_booking = $this->weekly_model->get_hall_booking_data($start_date,$end_date,$data_type);
            $wedding_hall = $this->weekly_model->get_wed_hall_booking_data($start_date,$end_date,$data_type);
            $archanai = $this->weekly_model->get_archanai_data($start_date,$end_date,$data_type);
            $kattalai = $this->weekly_model->get_kattalai_data($start_date,$end_date,$data_type);
            $membership = $this->weekly_model->get_membership_data($start_date,$end_date,$data_type);
            $card_topup = $this->weekly_model->get_membership_card_topup_data($start_date,$end_date,$data_type);
            $temple_shop = $this->weekly_model->get_temple_shop_data($start_date,$end_date,$data_type);
        }else  {
            $start_date = '';
            $end_date = '';
            $data_type = 'Get Summary Data';
            $abishegam = $this->weekly_model->get_abishegam_data($start_date = '',$end_date = '',$data_type);
            $festival = $this->weekly_model->get_festival_data($start_date = '',$end_date = '',$data_type);
            $ubayam = $this->weekly_model->get_ubayam_data($start_date = '',$end_date = '',$data_type);
            $mega = $this->weekly_model->get_mega_data($start_date = '',$end_date = '',$data_type);
            $other = $this->weekly_model->get_other_service_data($start_date = '',$end_date = '',$data_type);
            $gold_silver = $this->weekly_model->get_gold_silver_data($start_date = '',$end_date = '',$data_type);
            $temple = $this->weekly_model->get_temple_activity_data($start_date = '',$end_date = '',$data_type);
            $member_subscripe = $this->weekly_model->get_member_subscribe_data($start_date = '',$end_date = '',$data_type);
            $building_fund  = $this->weekly_model->get_building_fund_data($start_date = '',$end_date = '',$data_type);
            $outdoor = $this->weekly_model->get_outdoor_data($start_date = '',$end_date = '',$data_type);
            $prasadam = $this->weekly_model->get_prasadam_data($start_date = '',$end_date = '',$data_type);
            $madappalli = $this->weekly_model->get_madappalli_data($start_date = '',$end_date = '',$data_type);
            $donation = $this->weekly_model->get_donation_data($start_date = '',$end_date = '',$data_type);
            $hall_booking = $this->weekly_model->get_hall_booking_data($start_date = '',$end_date = '',$data_type);
            $wedding_hall = $this->weekly_model->get_wed_hall_booking_data($start_date = '',$end_date = '',$data_type);
            $archanai = $this->weekly_model->get_archanai_data($start_date = '',$end_date = '',$data_type);
            $kattalai = $this->weekly_model->get_kattalai_data($start_date = '' ,$end_date = '',$data_type);
            $membership = $this->weekly_model->get_membership_data($start_date = '',$end_date = '',$data_type);
            $card_topup = $this->weekly_model->get_membership_card_topup_data($start_date = '',$end_date = '',$data_type);
            $temple_shop = $this->weekly_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->weekly_model->payment_type_list();
        $actions = $this->actions();
        $data['form_action'] = 'weekly_report';
        $data['title'] = 'Weekly 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/weekly/pdf', $data, TRUE);
                print_rec($html);
                redirect('weekly_report','refresh');
            else :
                $this->render($data, 'reports/weekly/pdf');
            endif;
        } else {
            $this->render($data, 'reports/weekly/list');
        }
    }
   
} ?>

