<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Member_card_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/member_card_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 Topup Details' || $this->input->post('submit') == 'Print Topup Details')) {
            $start_date = $this->input->post('start_date');
            $end_date = $this->input->post('end_date');
            $card_no = $this->input->post('card_no');
            $data_type = $this->input->post('submit');
            $data['results'] = $this->member_card_report_model->get_data($start_date,$end_date,$card_no);
            
        } elseif($this->input->post('submit') == 'Get Receipt Log Details' || $this->input->post('submit') == 'Print Receipt Log Details') {
            $start_date = $this->input->post('start_date');
            $end_date = $this->input->post('end_date');
            $card_no = $this->input->post('card_no');
            $data_type = $this->input->post('submit');
            
        } else {
            $start_date = '';
            $end_date = '';
            $card_no = '';
            $data_type = 'Get Topup Details';
            $data['results'] = $this->member_card_report_model->get_data($start_date,$end_date,$card_no);
        }
        
        $data['start_date'] = $start_date;
        $data['end_date'] = $end_date;
        $data['card_no'] = $card_no;
        $data['data_type'] = $data_type;
        $actions = $this->actions();
        $data['form_action'] = 'member_card_report';
        $data['title'] = 'Memebership Card Details 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 Topup Details' || $this->input->post('submit') == 'Print Receipt Log Details'){
            $data['dataType'] = $this->input->post('submit');
            if( IS_KSK ) :
                $html = $this->load->view('reports/member_card/pdf', $data, TRUE);
                print_rec($html);
                redirect('member_card_report','refresh');
            else :
                $this->render($data, 'reports/member_card/pdf');
            endif;
        } else {
            $this->render($data, 'reports/member_card/list');
        }
    }
   
} ?>

