<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cash_log_report extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('reports/cash_log_report_model', '', TRUE);
        $this->uri_key_index = 0;
    }
    
    public function index() {
        $data = array();
        #echo '<pre>';print_r($_POST);exit;
        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 Data' || $this->input->post('submit') == 'Print Data')) {
            $start_date = $this->input->post('start_date');
            $end_date = $this->input->post('end_date');
            $hidden_id = 1;
        } else {
            $start_date = '';
            $end_date = '';
            $hidden_id = '';
        }
        $data['results'] = $this->cash_log_report_model->get_data($start_date,$end_date);
        $data['start_date'] = $start_date;
        $data['end_date'] = $end_date;
        $data['types'] = $this->cash_log_report_model->list_payment_type();
        $data['hidden_id'] = $hidden_id;
        $pay_type = array();
        if(!empty($this->input->post('payment_type'))) {
            foreach($this->input->post('payment_type') as $key=>$value) {
                array_push($pay_type,$this->input->post($value));
            } 
        }
        $data['pay_type'] = array_filter($pay_type);
        $actions = $this->actions();
        $data['form_action'] = 'cash_log_report';
        $data['title'] = 'Cashlog Report';
        if($this->input->post('submit') == 'Print Data'){
            if( IS_KSK ) :
                $html = $this->load->view('reports/cash_log/pdf', $data, TRUE);
                print_rec($html);
                redirect('cash_log_report','refresh');
            else :
                $this->render($data, 'reports/cash_log/pdf');
            endif;
        } else {
            $this->render($data, 'reports/cash_log/list');
        }
    }
   
} ?>

