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

class Serviceform_temp_arep extends MY_Controller
{
	function __construct()
	{
		parent::__construct();

		if($this->logged_user = $this->session->userdata('user')){
			$this->login->checkModuleAccess(4);
			
			$this->logged_module = $this->session->userdata('module_data');
			
			$this->load->model('hr/model_form');
			$this->load->model('admin/model_company');
			$this->load->model('hr/model_service_form','model_service_form');


		}else{
			redirect(base_url());
		}

		// die(debug($this->session->userdata()));
	}

	public function serviceform_dashboard_test()
	{
		$this->load->model('hr/model_hotel');

		debug($count = $this->model_hotel->getCountHotelList(null));

		$fc_event 	= array();
		$resource 	= array();

		$bookingCalendar = $this->model_form->getBooking();

		if(!empty($bookingCalendar))
		{
			foreach ($bookingCalendar as $key => $details) 
			{
				debug($details);
				$startDate  = $details['start_date'];
				$endDate    = $details['end_date'];
				
				$tmpEvent = array();

				$tmpEvent['id'] 			= $key;
				$tmpEvent['resourceId'] 	= $details['requester_id'];
				$tmpEvent['start'] 			= $startDate;
				$tmpEvent['end'] 			= date('Y-m-d',strtotime($endDate."+1 days"));
				$tmpEvent['title'] 			= $details['department_name'];
				$tmpEvent['description']	= $details['department_name'].' request "'.$details['title'].'".';
				$tmpEvent['color']			= '#'.$details['color_code'];
				$tmpEvent['textColor']		= '#ffffff';

				array_push($fc_event, $tmpEvent);
				array_push($resource, $details);
			}
		}

		$data = array
		(
			'page_setup'		=> $this->template->pageSetup('Service Form', '', ''),
			'forms'				=> $this->model_form->getForms(),
			'booking_calendar'	=> $bookingCalendar,
			'booking_name'		=> $this->model_form->getBookingName(),
			'fc_event'			=> json_encode($fc_event),
			'resource'			=> json_encode($resource),
		);

		debug();

		$this->template->view('hr/policyprocedure/service_form2', $data);
	}

	function it_equipment_list()
	{

		$this->load->model('hr/model_av_it');

		$equipment_list = $this->model_av_it->getEquipmentList();

		$fc_res 	= array();
		$fc_event 	= array();
		$resource 	= array();

		if(!empty($equipment_list))
		{
			foreach ($equipment_list as $key => $details) 
			{
				$createdTS  = date('Y-m-d',strtotime($details['createdTS']));
				$startDate  = $details['check_in'];
				$endDate    = $details['check_out'];
				
				$tmpRes 					= array(); $tmpEvent = array();
				$tmpRes['id']  				= $details['ID'];
				$tmpRes['title'] 			= $details['dept_name'];

				$tmpEvent['id'] 			= $key;
				$tmpEvent['resourceId'] 	= $details['staff_id'];
				$tmpEvent['start'] 			= $startDate;
				$tmpEvent['end'] 			= date('Y-m-d',strtotime($endDate."+1 days"));
				$tmpEvent['title'] 			= $details['dept_name'].'/'.$details['branchName'];
				$tmpEvent['description']	= $details['dept_name'].' request "'.$details['hardware'].'" and "'.$details['software'].'".';
				$tmpEvent['color']			= 'rgba('.rand(0,255).','.rand(0,255).','.rand(100,255).',0.5)';
				$tmpEvent['textColor']		= '#ffffff';

				array_push($fc_res, $tmpRes);
				array_push($fc_event, $tmpEvent);
				array_push($resource, $details);
			}
		// debug($details);
		}


		$data = array
		(
			'page_setup' 		=> $this->template->pageSetup('Online Form', '', 'AV/IT Equipment Request List'),
			'department' 		=> $this->model_company->getDepartments(),
			'equipment_list' 	=> $this->model_av_it->getEquipmentList(),
			'count_request'		=> $this->model_av_it->getRequestByCompany(),
			'request_monthly' 	=> $this->model_av_it->getEquipmentRequestRoomByMonth(),
			'fc_res'			=> json_encode($fc_res),
			'fc_event'			=> json_encode($fc_event),
			'resource'			=> json_encode($resource),
		);

		$this->template->view('hr/policyprocedure/form/it_equipment_list', $data);
	}

	function it_equipment_form($ID = null)
	{
		$this->load->model('hr/model_av_it');

		$equipment_list = $this->model_av_it->getEquipmentList();

		$fc_res 	= array();
		$fc_event 	= array();
		$resource 	= array();

		if(!empty($equipment_list))
		{
			foreach ($equipment_list as $key => $details) 
			{
				$createdTS  = date('Y-m-d',strtotime($details['createdTS']));
				$startDate  = $details['check_in'];
				$endDate    = $details['check_out'];
				
				$tmpRes 					= array(); $tmpEvent = array();
				$tmpRes['id']  				= $details['ID'];
				$tmpRes['title'] 			= $details['dept_name'];

				$tmpEvent['id'] 			= $key;
				$tmpEvent['resourceId'] 	= $details['staff_id'];
				$tmpEvent['start'] 			= $startDate;
				$tmpEvent['end'] 			= date('Y-m-d',strtotime($endDate."+1 days"));
				$tmpEvent['title'] 			= $details['dept_name'].'/'.$details['branchName'];
				$tmpEvent['description']	= $details['dept_name'].' request "'.$details['hardware'].'" and "'.$details['software'].'".';
				$tmpEvent['color']			= 'rgba('.rand(0,255).','.rand(0,255).','.rand(100,255).',0.5)';
				$tmpEvent['textColor']		= '#ffffff';

				array_push($fc_res, $tmpRes);
				array_push($fc_event, $tmpEvent);
				array_push($resource, $details);
			}
		// debug($details);
		}

		$data = array
		(
			'page_setup' 		=> $this->template->pageSetup('Online Form', '', 'AV/IT Equipment Request Form'),
			'equipment_detail' 	=> $this->model_av_it->getEquipmentList($ID),
			'upcoming_request' 	=> $this->model_av_it->getEquipmentRequestByWeek(),
			'ID'				=> $ID,
			'fc_res'			=> json_encode($fc_res),
			'fc_event'			=> json_encode($fc_event),
			'resource'			=> json_encode($resource),
		);

		$this->template->view('hr/policyprocedure/form/it_equipment', $data);
	}

	function it_equipment_calendar()
	{
		$this->load->model('hr/model_av_it');

		$equipment_list = $this->model_av_it->getEquipmentList();

		$fc_res 	= array();
		$fc_event 	= array();
		$resource 	= array();

		if(!empty($equipment_list))
		{
			foreach ($equipment_list as $key => $details) 
			{
				$createdTS  = date('Y-m-d',strtotime($details['createdTS']));
				$startDate  = $details['check_in'];
				$endDate    = $details['check_out'];
				
				$tmpRes 					= array(); $tmpEvent = array();
				$tmpRes['id']  				= $details['ID'];
				$tmpRes['title'] 			= $details['dept_name'];

				$tmpEvent['id'] 			= $key;
				$tmpEvent['resourceId'] 	= $details['staff_id'];
				$tmpEvent['start'] 			= $startDate;
				$tmpEvent['end'] 			= date('Y-m-d',strtotime($endDate."+1 days"));
				$tmpEvent['title'] 			= $details['dept_name'].'/'.$details['branchName'];
				$tmpEvent['description']	= $details['dept_name'].' request "'.$details['hardware'].'" and "'.$details['software'].'".';
				$tmpEvent['color']			= 'rgba('.rand(0,255).','.rand(0,255).','.rand(100,255).',0.5)';
				$tmpEvent['textColor']		= '#ffffff';

				array_push($fc_res, $tmpRes);
				array_push($fc_event, $tmpEvent);
				array_push($resource, $details);
			}
		// debug($details);
		}

		$data = array
		(
			'page_setup' 		=> $this->template->pageSetup('Online Form', '', 'AV/IT Equipment Request Calendar'),
			'equipment_list' 	=> $this->model_av_it->getEquipmentList(),
			'fc_res'			=> json_encode($fc_res),
			'fc_event'			=> json_encode($fc_event),
			'resource'			=> json_encode($resource),
		);
		
		$this->template->view('hr/policyprocedure/calendar/it_equipment_calendar', $data);
	}

	function it_equipment_form_save()
	{
		//$this->load->model('hr/model_stationery','model_stationery');

		$input = $this->input->post();

		$insert = array
		(
			'borrower_id' 		=> $input['borrower_id'],
			'department_id' 	=> $input['department_id'],
			'hardware' 			=> $input['hardware'],
			'hw_reason' 		=> $input['hw_reason'],
			'software' 			=> $input['software'],
			'sw_reason' 		=> $input['sw_reason'],
			'check_in' 			=> date('Y-m-d',strtotime($input['check_out'])),
			'check_out'			=> date('Y-m-d',strtotime($input['check_in'])),
			'createdBY'			=> $this->logged_user['id'],
			'createdTS'			=> date('Y-m-d',strtotime($input['date_request']))
		);

		$new_equipment = $this->model_general->insert('sv__it__equipment',$insert);

		if($new_equipment)
		{
			print json_encode(array(
				"status" => "Success",
				"msg"	 => "Successfully request new AV/IT equipment."
			)); 
		}
		else
		{
			print json_encode(array(
				"status" => "Error",
				"msg"	 => "System failed to request new AV/IT equipment."
			));
		}

		redirect(base_url('hr/serviceform/it_equipment_form'));
	}

	function it_equipment_form_edit()
	{
		$this->load->model('hr/model_av_it');

		$input = $this->input->post();

		$sets = array
		(
			'borrower_id' 		=> $input['edit_borrower_id'],
			'department_id' 	=> $input['edit_department_id'],
			'hardware' 			=> $input['edit_hardware'],
			'hw_reason' 		=> $input['edit_hw_reason'],
			'software' 			=> $input['edit_software'],
			'sw_reason' 		=> $input['edit_sw_reason'],
			'check_in' 			=> date('Y-m-d',strtotime($input['edit_check_out'])),
			'check_out'			=> date('Y-m-d',strtotime($input['edit_check_in'])),
			'createdBY'			=> $this->logged_user['id'],
		);

		$where = array('ID' => $input['edit_equipment_id']);

		$edit_equipment = $this->model_av_it->update_av_it('sv__it__equipment',$sets,$where);

		if($edit_equipment)
		{
			print json_encode(array(
				"status" => "Success",
				"msg"	 => "Successfully edit AV/IT equipment request."
			)); 
		}
		else
		{
			print json_encode(array(
				"status" => "Error",
				"msg"	 => "System failed to edit AV/IT equipment request."
			));
		}

		redirect(base_url('hr/serviceform/it_equipment_form/'.$input['edit_equipment_id']));
	}

	function it_equipment_form_delete()
	{
		$this->load->model('hr/model_av_it');

		$input = $this->input->post();

		$sets = array
		(
			'is_delete' 		=> 1,
			'createdBY'			=> $this->logged_user['id'],
		);

		$where = array('ID' => $input['equipment_id']);

		$delete_equipment = $this->model_av_it->update_av_it('sv__it__equipment',$sets,$where);

		if($delete_equipment)
		{
			print json_encode(array(
				"status" => "Success",
				"msg"	 => "Successfully delete AV/IT equipment request."
			)); 
		}
		else
		{
			print json_encode(array(
				"status" => "Error",
				"msg"	 => "System failed to delete AV/IT equipment request."
			));
		}

		redirect(base_url('hr/serviceform/it_equipment_list'));
	}

	function get_meeting_filter()
	{
		// $userID 	= (!empty($this->input->post('user_id')) && $this->input->post('user_id') != -1)? $this->input->post('user_id'):null;
		$department	= (!empty($this->input->post('sv_room_booking_filter_dept')) && $this->input->post('sv_room_booking_filter_dept') != -1)? $this->input->post('sv_room_booking_filter_dept'):null;
		$room		= (!empty($this->input->post('sv_room_booking_filter_room')))? $this->input->post('sv_room_booking_filter_room'):null;
		$year		= (!empty($this->input->post('sv_room_booking_filter_year')))? $this->input->post('sv_room_booking_filter_year'):null;
		$month		= (!empty($this->input->post('sv_room_booking_filter_month')))? $this->input->post('sv_room_booking_filter_month'):null;

		$where = array(); 

		/* filter data */

		if($department > 0) {
			$this->session->set_userdata('sv_room_booking_filter_dept',$department);
			$where['a.department_id'] = $department; 
		} else {
			$this->session->set_userdata('sv_room_booking_filter_dept','ALL');
		}

		if($room > 0) {
			$this->session->set_userdata('sv_room_booking_filter_room',$room);
			$where['a.room_id'] = $room; 
		} else {
			$this->session->set_userdata('sv_room_booking_filter_room','ALL');
		}

		if (!empty($year) && $year > 0) {
			$this->session->set_userdata('sv_room_booking_filter_year',$year);
			$where['YEAR(a.createdTS)'] = $year;
		} else {
			$this->session->set_userdata('sv_room_booking_filter_year','ALL');
		}

		if(!empty($month) && $month > 0) {
			$this->session->set_userdata('sv_room_booking_filter_month',$month);
			$where['MONTH(a.createdTS)'] = $month; 
		} else {
			$this->session->set_userdata('sv_room_booking_filter_month','ALL');
		}

		/* filter data */

		$select = array('a.*, d.name, d.staff_id, d.email, e.room, e.color_code, a.department_id, b.name as dept_name, c.name as branchName');
		$where['a.is_delete'] = 0;
		$join = array
		(
			array('company__department b', 'b.id = a.department_id',''),
			array('company__branch c', 'c.id = b.branch_id',''),
			array('user d', 'd.id = a.requester_id',''),
			array('sv__booking_room_type e', 'e.id = a.room_id', 'left'),
		);
		$orderBy = array('a.ID asc');
		$table = $this->model_general->fetchAll('sv__booking__room a',$select, $where, $join, $orderBy);
		
		$data = array
		(
			'status' 							=> 'success',
			'message'							=> '',
			'table'								=> $table,
			'user_id' 							=> $this->input->post('user_id'),
			'sv_room_booking_filter_dept'		=> $this->input->post('sv_room_booking_filter_dept'),
			'sv_room_booking_filter_room'		=> $this->input->post('sv_room_booking_filter_room'),
			'sv_room_booking_filter_year'		=> $this->input->post('sv_room_booking_filter_year'),
			'sv_room_booking_filter_month'		=> $this->input->post('sv_room_booking_filter_month'),

		);
		$this->session->set_userdata('sv__booking__room',$data['table']);
		echo json_encode($data);
		return true;
    }

    function meeting_form_save()
	{
		$this->load->model('hr/model_booking_meeting','room');

		$input = $this->input->post();

		$existing_booking = $this->room->getBookingRoom();

		debug($input);
		debug($existing_booking);

		$temp_data = array();

		for ($i=0; $i < sizeof($existing_booking) ; $i++) 
		{ 
			if($input['room_id'] == $existing_booking[$i]['room_id'])
			{
				$roomID = "sama<br>";
				if(date('Y-m-d',strtotime($input['start_date'])) == $existing_booking[$i]['start_date']){
					$date = "date sama<br><br>";
				}else{
					$date = "date tak sama<br><br>";
				}
			}else{
				$roomID = "tak sama<br><br>";
			}
		}

		echo $roomID;
		echo $date;


		die();


		$insert = array
		(
			// 'room_id'			=> $input['']
			'requester_id'		=> $input['requester_id'],
			'department_id'		=> $input['department_id'],
			'package'			=> $input['package_id'],
			'event_title'		=> $input['event_title'],
			'client'			=> $input['client_name'],
			'start_date'		=> date('Y-m-d',strtotime($input['start_date'])),
			'start_time'		=> $input['start_time'],
			'end_date'			=> date('Y-m-d',strtotime($input['end_date'])),
			'end_time'			=> $input['end_time'],
			'pax'				=> $input['no_pax'],
			'createdTS'			=> $input['reqDate'],
			'createdBY'			=> $input['requester_id'],
		);

		if(!empty($input['other_room_id']))
		{
			$insert['room_id'] 		= 7;
			$insert['other_room'] 	= $input['other_room_id'];
		} else {
			$insert['room_id'] 		= $input['room_id'];
		}

		if(!empty($input['table_setup'])) $insert['table_setup'] = $input['table_setup'];
		// if(!empty($input['equipment_id'])) $insert['equipment'] = $input['equipment_id'];
		if(!empty($input['breakfast'])) $insert['breakfast'] = $input['breakfast'];
		if(!empty($input['lunch'])) $insert['lunch'] = $input['lunch'];
		if(!empty($input['tea'])) $insert['hi_tea'] = $input['tea'];
		if(!empty($input['other_menu'])) $insert['other_menu'] = $input['other_menu'];
		if(!empty($input['special_request'])) $insert['special_request'] = $input['special_request'];
		if(!empty($input['vip'])) $insert['vip'] = $input['vip'];
		// debug($insert);
		// die();

		$equipmentDetail = (!empty($equipment = $input['equipment_id']))?$equipment:array();
	
		$addroombooking = $this->model_general->insert('sv__booking__room', $insert);

		$equipment_add_update = $this->room->updateOrCreateNew($addroombooking,$equipmentDetail);
		
		if($addroombooking)
		{
			print json_encode(array(
				"status" 	=> "Success",
				"msg"	 	=> "Successfully booking room.",
				"redirect"	=> base_url('hr/serviceform/meeting_list')
			)); 
		}
		else
		{
			print json_encode(array(
				"status" => "Error",
				"msg"	 => "Failed to booking room. Please try again."
			));
		}
		// redirect(base_url('hr/serviceform/meeting_list'));
	}

    function meeting_edit()
	{
		$input = $this->input->post();
		// debug($input);
		// die();
		$this->load->model('hr/model_booking_meeting','room');

		$meetingID = $input['meetingID'];
		
		
		$update = array
		(
			'requester_id'		=> $input['requester_id'],
			'department_id'		=> $input['department_id'],
			'package'			=> $input['package_id'],
			'event_title'		=> $input['event_title'],
			'client'			=> $input['client_name'],
			'table_setup'		=> $input['table_setup'],
			// 'equipment'			=> $input['equipment_id'],
			'breakfast'			=> (!empty($input['breakfast']) && $input['breakfast'] != '-- Please Select --')?$input['breakfast']:'',
			'lunch'				=> (!empty($input['lunch']) && $input['lunch'] != '-- Please Select --')?$input['lunch']:'',
			'hi_tea'			=> (!empty($input['tea']) && $input['tea'] != '-- Please Select --')?$input['tea']:'',
			'other_menu'		=> $input['other_menu'],
			'special_request'	=> $input['special_request'],
			'vip'				=> $input['vip'],
			'start_date'		=> date('Y-m-d',strtotime($input['start_date'])),
			'start_time'		=> $input['start_time'],
			'end_date'			=> date('Y-m-d',strtotime($input['end_date'])),
			'end_time'			=> $input['end_time'],
			'pax'				=> $input['no_pax'],
			'updatedBY' 		=> $this->logged_user['id'],
			'updatedTS'	 		=> date('Y-m-d H:i:s'),
		);

		
		if(!empty($input['other_room_id']))
		{
			$update['room_id'] 		= 7;
			$update['other_room'] 	= $input['other_room_id'];
		} else {
			$update['room_id'] 		= $input['room_id'];
		}

		// $updateEquipment['equipment'] = $input['equipment_id'];
		$equipmentDetail = (!empty($equipment = $input['equipment_id']))?$equipment:array();
		// debug($equipmentDetail);
		$where = array
		(
			'ID' => $meetingID,
		);

		$updateroombooking = $this->room->updateBookingRoom($update, $where);
		
		$editequipment 	= $this->room->updateOrCreateNew($meetingID,$equipmentDetail);

		if($updateroombooking)
		{
			print json_encode(array(
				"status" => "Success",
				"msg"	 => "Successfully updated booking room."
			)); 
		}
		else
		{
			print json_encode(array(
				"status" => "Error",
				"msg"	 => "Failed to update booking room. Please try again."
			));
		}
		redirect(base_url('hr/serviceform/meeting_list'));
	}

	public function evaluation_test($ID=null)
	{
		$this->load->model('hr/model_training_evaluation');

		$query = $this->model_training_evaluation->getAllEvaluationDetails_new($ID);

		debug($query);

		foreach ($query as $key => $value) 
		{
			if(!empty($value['questionID']))
			{
				$query[$key]['qtn_id'] = explode("==>", $value['questionID']);
			}else{
				$query[$key]['qtn_id'] = '';
			}

			if(!empty($value['question']))
			{
				$query[$key]['qtn'] = explode("==>", $value['question']);
			}else{
				$query[$key]['qtn'] = '';
			}

			if(!empty($value['answer_radio']))
			{
				$query[$key]['radio'] = explode("==>", $value['answer_radio']);
			}else{
				$query[$key]['radio'] = '';
			}

			if(!empty($value['answer_text']))
			{
				$query[$key]['txt'] = explode("==>", $value['answer_text']);
			}else{
				$query[$key]['txt'] = '';
			}
		}

		foreach ($query as $key => $val) 
		{
			debug($val);
			echo $val['category_id'];
			echo $val['question_category_id'];
			echo sizeof($val['qtn']);

			if(!empty($ID))
			{
				if($val['question_type']==0)
				{
					echo sizeof($val['radio']);
				}else{
					echo sizeof($val['txt']);
				}
				echo $val['question_category_id'].'<br>';
				if($val['category_id']==$val['question_category_id'])
				{
					echo $val['category_question'].'<br>';
					if($val['question_type']==0)
					{
						for ($i=0; $i < sizeof($val['qtn']) ; $i++) 
						{ 
							echo $val['qtn'][$i].' => '.$val['radio'][$i].'<br>';
						}
					}else{
						for ($i=0; $i < sizeof($val['qtn']) ; $i++) 
						{ 
							echo $val['qtn'][$i].' => '.$val['txt'][$i].'<br>';
						}
					}
					echo '<br><br>';
				}
			}else{
				if($val['category_id']==$val['question_category_id'])
				{
					echo '<br>'.$val['category_question'].'<br>';
					if($val['question_type']==0)
					{
						for ($i=0; $i < sizeof($val['qtn']) ; $i++) 
						{ 
							echo $val['qtn'][$i].'<br>';
						}
					}else{
						for ($i=0; $i < sizeof($val['qtn']) ; $i++) 
						{ 
							echo $val['qtn'][$i].'<br>';
						}
					}
					echo '<br><br>';
				}
			}
		}
	}
	
	public function test(){
		$data['title'] = 'listing aku';
		$data['page_setup'] = 'page setup';
		$data['colHeader'] = array(array('title'=>'Makan',
									'align'=>'text-center',
									'label'=>'makanan'),
									array('title'=>'Minuman',
									'align'=>'text-left',
									'label'=>'minuman'),
									array('title'=>'Lauk',
									'align'=>'text-right',
									'label'=>'lauk'),
									);
		$data['rsData'] = 
		$this->load->view('bi/listing', $data);
	}

	function sv_summary_report()
	{
		$this->load->model('hr/model_form');

		$input 			= $this->input->post();
		$booking_form 	= array();
		$title_year 	= date('Y');
		$title_month	= '';
		
		if($input)
		{
			$select = array
			(
				'a.title',
				'a.category',
				'a.department_id',
				'a.department_name',
				'a.requested_date',
				// '(SELECT ifnull(count(id), 0) FROM view__service_form WHERE status = "Pending" AND YEAR(requested_date) = YEAR(a.requested_date) AND ifnull(department_id,0) = a.department_id AND title = a.title) as total_pending',
				// '(SELECT ifnull(count(id), 0) FROM view__service_form WHERE status = "In-progress" AND YEAR(requested_date) = YEAR(a.requested_date) AND ifnull(department_id,0) = a.department_id AND title = a.title) as total_in_progress',
				// '(SELECT ifnull(count(id), 0) FROM view__service_form WHERE status = "Approved" AND YEAR(requested_date) = YEAR(a.requested_date) AND ifnull(department_id,0) = a.department_id AND title = a.title) as total_approved',
				// '(SELECT ifnull(count(id), 0) FROM view__service_form WHERE status = "Verified" AND YEAR(requested_date) = YEAR(a.requested_date) AND ifnull(department_id,0) = a.department_id AND title = a.title) as total_verified',
				// '(SELECT ifnull(count(id), 0) FROM view__service_form WHERE status = "Cancel" AND YEAR(requested_date) = YEAR(a.requested_date) AND ifnull(department_id,0) = a.department_id AND title = a.title) as total_cancel',
				// '(SELECT ifnull(count(id), 0) FROM view__service_form WHERE status = "Rejected" AND YEAR(requested_date) = YEAR(a.requested_date) AND ifnull(department_id,0) = a.department_id AND title = a.title) as total_rejected',
				'count(a.status) as total',
			);
			if(($input['sv_summary_filter_form'] != 'all')) 
			{
				$this->session->set_userdata('sv_summary_filter_title',$input['sv_summary_filter_form']);
				$where['a.id'] = $input['sv_summary_filter_form'];
			}else{
				$this->session->set_userdata('sv_summary_filter_title',$input['sv_summary_filter_form']);
			}

			if(($input['sv_summary_filter_year'] > 0)) 
			{
				$this->session->set_userdata('sv_summary_filter_year',$input['sv_summary_filter_year']);
				$where['YEAR(a.requested_date)'] = $input['sv_summary_filter_year'];
				$title_year = $input['sv_summary_filter_year'];
			}else{
				$this->session->set_userdata('sv_summary_filter_year',date('Y'));
				$where['YEAR(a.requested_date)'] = date('Y');
			}
			
			if((!empty($input['sv_summary_filter_month'])) && ($input['sv_summary_filter_month'] > 0)) 
			{
				$this->session->set_userdata('sv_summary_filter_month',$input['sv_summary_filter_month']);
				$where['MONTH(a.requested_date)'] = $input['sv_summary_filter_month'];
				$title_month = $input['sv_summary_filter_month'];
			}else{
				$this->session->unset_userdata('sv_summary_filter_month');
			}

			// $where_in['a.status'] = array('In-progress','Approved','Verified');

			// $join = array
			// (
			// 	array('sv__ref_form_price b','b.form_id = a.id and b.status = 1 and b.is_delete = 0 and now() >= b.affective_date','left'),
			// );

			$order_by = array('department_id'=>'asc','title'=>'asc');
			$group_by = array('department_id','title','YEAR(requested_date)');

			$booking_form = $this->model_form->sv__filter('view__service_form a', $select, $where, null, $order_by, $group_by, null, null, null, null);

			// debug($this->db->last_query());
			// die();
			if($booking_form)
			{
				$this->session->set_flashdata('success',"Successfully filtering data.");
			}else{
				$this->session->set_flashdata('warning',"No data found! Please try again.");
			}

		}else{
			if(!empty(($this->session->userdata('sv_summary_filter_title')))) $this->session->unset_userdata('sv_summary_filter_title');
			if(!empty(($this->session->userdata('sv_summary_filter_year')))) $this->session->unset_userdata('sv_summary_filter_year');
			if(!empty(($this->session->userdata('sv_summary_filter_month')))) $this->session->unset_userdata('sv_summary_filter_month');
		}

		$data = array
		(
			'page_setup'		=> $this->template->pageSetup('Service Form', '', 'Service Form Report'),
			'getBookingName'	=> $this->model_form->getBookingName('view__service_form'),
			'booking_form'		=> $booking_form,
			'title_month'		=> $title_month,
			'title_year'		=> $title_year,
		);
			// debug($this->db->last_query());

		$this->template->view('hr/policyprocedure/report/report_summary', $data);
	}
}
