<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Uniformstatement extends Admin_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library(['form_validation', 'session']);
    }

   function unifstatement() {
       	 if (!$this->rbac->hasPrivilege('class', 'can_view')) {access_denied();}
		 
				$this->session->set_userdata('top_menu', 'Uniform Statement');
				$this->session->set_userdata('sub_menu', 'uniformstatement/unifstatement');
             
				$this->form_validation->set_rules('name', 'Student From', 'required');
				$this->form_validation->set_rules('nameto', 'Student Name', 'required');
				$this->form_validation->set_rules('from', 'Start Date', 'required');
				$this->form_validation->set_rules('to', 'End Date', 'required');

				if ($this->form_validation->run() == FALSE) {
					
									$data['students']=$this->uniformpos_model->selectstds();
									$this->load->view('layout/header', $data);
									$this->load->view('uniformpos/uniformstatement', $data);
									$this->load->view('layout/footer', $data);
					
				} else {			
                        $nameto = $this->input->post('nameto');
						$name = $this->input->post('name');
						$from = $this->input->post('from');
						$to = $this->input->post('to');
						$search = $this->input->post('search');
												
					if (isset($search)) {

							$resultlist = $this->uniformpos_model->customer_search($name,$nameto, $from, $to);
							$data['customer_results'] = $resultlist;
							
						$data['students']=$this->uniformpos_model->selectstds();
						$data['name']=$name;
						$data['nameto']=$nameto;
						$data['from']=$from;
						$data['to']=$to;						
						$this->load->view('layout/header', $data);
						$this->load->view('uniformpos/uniformstatement', $data);
						$this->load->view('layout/footer', $data);
					}
					else{
						  echo "PLEASE NOTHING HAS BEEN SUBMITTED TO CASH BOOK FORM";
					}
				}          
    }	
function printUniformStatement() {
		if (!$this->rbac->hasPrivilege('class', 'can_view')) { access_denied(); }
	
		$setting_result = $this->setting_model->get();
		$data['settinglist'] = $setting_result;
	
		// Retrieve POST data
		$name = $this->input->post('name');
		$nameto = $this->input->post('nameto');
		$from = $this->input->post('from');
		$to = $this->input->post('to');
	
		// Call model function to fetch results
		$resultlist = $this->uniformpos_model->customer_search($name, $nameto, $from, $to);
	
		$data['customer_results'] = $resultlist;
		$data['students'] = $this->uniformpos_model->selectstds();
	
		$data['name'] = $name;
		$data['nameto'] = $nameto;
		$data['from'] = $from;
		$data['to'] = $to;
	
		// Debug - Ensure data is passed correctly to the view
		log_message('debug', 'Data passed to view: '.json_encode($data));
	
		// Load the print view
		$this->load->view('print/printUniformstatement', $data);
	}
	
	
}
?>
