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

class Serviceform_report 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');
			$this->load->model('hr/model_approval');

		}else{
			redirect(base_url());
		}

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

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

        $date = date("d-m-Y");

        if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin')
        {
	        if(!empty($this->session->userdata('sv__stationery')))
	        {
	        	if(!empty($ID)){
					$data['stationeryRequestList_new'] = $this->model_stationery->getStationeryList_new($ID);
	        	}else{
	        		$data['stationeryRequestList_new'] = $this->session->userdata('sv__stationery');
	        	}
	        }else{
	        	if(!empty($ID)){
					$data['stationeryRequestList_new'] = $this->model_stationery->getStationeryList_new($ID);
	        	}else{
					$data['stationeryRequestList_new'] = $this->model_stationery->getStationeryList_new();
	        	}
	        }
        }else{
        	 if(!empty($this->session->userdata('sv__stationery')))
	        {
	        	if(!empty($ID)){
					$data['stationeryRequestList_new'] = $this->model_stationery->getStationeryList_new($ID);
	        	}else{
	        		$data['stationeryRequestList_new'] = $this->session->userdata('sv__stationery');
	        	}
	        }else{
	        	if(!empty($ID)){
					$data['stationeryRequestList_new'] = $this->model_stationery->getStationeryList_new($ID);
	        	}else{
					$data['stationeryRequestList_new'] = $this->model_stationery->getStationeryList_new(null,$this->logged_user['employment_id']);
	        	}
	        }
        }

        if(!empty($this->session->userdata('sv_stationery_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_stationery_filter_dept'));
		}

        if(!empty($ID)){
			$data['title']	= 'STATIONERY REQUEST DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'STATIONERY REQUEST LIST AS AT ' . $date;

		}

		if(is_array($this->session->userdata('sv__stationery'))) foreach ($data['stationeryRequestList_new'] as $key => $value) 
		{
			if(!empty($value['quantity']))
			{ 
				$data['stationeryRequestList_new'][$key]['qty'] = explode(',',$value['quantity']); 
			}else{
				$data['stationeryRequestList_new'][$key]['qty'] = '';
			}

			if(!empty($value['description']))
			{ 
				$data['stationeryRequestList_new'][$key]['desc'] = explode(',',$value['description']); 
			}else{
				$data['stationeryRequestList_new'][$key]['desc'] = '';
			}

			if(!empty($value['package']))
			{ 
				$data['stationeryRequestList_new'][$key]['pck'] = explode(',',$value['package']); 
			}else{
				$data['stationeryRequestList_new'][$key]['pck'] = '';
			}
		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__stationery','a.id_table'=>$ID));
            
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

        $this->load->view('hr/policyprocedure/report/header.php');
        $this->load->view('hr/policyprocedure/report/stationery_list_report.php',$data);
        $this->load->view('hr/policyprocedure/report/footer.php');
    }

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

        $date = date("d-m-Y");

        if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin')
        {
	        if(!empty($this->session->userdata('sv__maintenance')))
	        {
	        	if(!empty($ID))
	        	{
					$data['MaintenanceListDetail'] 	= $this->model_maintenance->getMaintenanceDetails($ID);
	        	}else{
	        		$data['MaintenanceList'] 		= $this->session->userdata('sv__maintenance');
	        	}
	        }else{
	        	if(!empty($ID))
	        	{
					$data['MaintenanceListDetail'] 	= $this->model_maintenance->getMaintenanceDetails($ID);
	        	}else{
	        		$data['MaintenanceList'] 		= $this->model_maintenance->getMaintenanceRequestList();
	        	}
	        }
		}else{
			if(!empty($this->session->userdata('sv__maintenance')))
	        {
	        	if(!empty($ID))
	        	{
					$data['MaintenanceListDetail'] 	= $this->model_maintenance->getMaintenanceDetails($ID);
	        	}else{
	        		$data['MaintenanceList'] 		= $this->session->userdata('sv__maintenance');
	        	}
	        }else{
	        	if(!empty($ID))
	        	{
					$data['MaintenanceListDetail'] 	= $this->model_maintenance->getMaintenanceDetails($ID);
	        	}else{
	        		$data['MaintenanceList'] 		= $this->model_maintenance->getMaintenanceRequestList(null,$this->logged_user['employment_id']);
	        	}
	        }
		}

		if(!empty($this->session->userdata('sv_maintenance_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_maintenance_filter_dept'));
		}

        if(!empty($ID)){
			$data['title']	= 'MAINTENANCE REQUEST DETAIL AS AT ' . $date;
			$data['ID'] = $ID;
		} else {
			$data['title']	= 'MAINTENANCE REQUEST LIST AS AT ' . $date;
		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__maintenance','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

        $this->load->view('hr/policyprocedure/report/header.php');
        $this->load->view('hr/policyprocedure/report/maintenance_list_report.php',$data);
        $this->load->view('hr/policyprocedure/report/footer.php');
    }

	function meeting_room_print($ID = null)
	{
		$this->load->model('hr/model_booking_meeting','room');

		$date = date("d-m-Y");

		if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin')
		{
			if(!empty($this->session->userdata('sv__booking__room')))
			{
				if(!empty($ID)){
					$data['booking_room'] = $this->room->getBookingRoom($ID);
				}else{
					$data['booking_room'] = $this->session->userdata('sv__booking__room');
				}
			}else{
				if(!empty($ID)){
					$data['booking_room'] = $this->room->getBookingRoom($ID);
				}else{
					$data['booking_room'] = $this->room->getBookingRoom();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__booking__room')))
			{
				if(!empty($ID)){
					$data['booking_room'] = $this->room->getBookingRoom($ID);
				}else{
					$data['booking_room'] = $this->session->userdata('sv__booking__room');
				}
			}else{
				if(!empty($ID)){
					$data['booking_room'] = $this->room->getBookingRoom($ID);
				}else{
					$data['booking_room'] = $this->room->getBookingRoom(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_room_booking_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_room_booking_filter_dept'));
		}
		
		if(!empty($this->session->userdata('sv_room_booking_filter_room')))
		{
			$data['room']	= $this->room->getBookingRoomType($this->session->userdata('sv_room_booking_filter_room'));
		}

		if(!empty($ID)){
			$data['title']	= 'MEETING ROOM BOOKING DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'MEETING ROOM BOOKING LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__booking__room','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/meeting_list_report.php',$data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

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

		$date = date("d-m-Y");
		
		if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin')
		{
			if(!empty($this->session->userdata('sv__car_booking')))
			{
				if(!empty($ID)){
					$data['rsCarBookingList'] = $this->model_car_booking->getCarRequestList($ID);
				}else{
					$data['rsCarBookingList'] = $this->session->userdata('sv__car_booking');
				}
			}else{
				if(!empty($ID)){
					$data['rsCarBookingList'] = $this->model_car_booking->getCarRequestList($ID);
				}else{
					$data['rsCarBookingList'] = $this->model_car_booking->getCarRequestList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__car_booking')))
			{
				if(!empty($ID)){
					$data['rsCarBookingList'] = $this->model_car_booking->getCarRequestList($ID);
				}else{
					$data['rsCarBookingList'] = $this->session->userdata('sv__car_booking');
				}
			}else{
				if(!empty($ID)){
					$data['rsCarBookingList'] = $this->model_car_booking->getCarRequestList($ID);
				}else{
					$data['rsCarBookingList'] = $this->model_car_booking->getCarRequestList(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_carbooking_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_carbooking_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'CAR BOOKING DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'CAR BOOKING LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__car_booking','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

        $this->load->view('hr/policyprocedure/report/header.php');
        $this->load->view('hr/policyprocedure/report/car_booking_list_report.php',$data);
        $this->load->view('hr/policyprocedure/report/footer.php');
    }

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

		$date = date("d-m-Y");

        //$data['title'] = 'MEETING CRM BOOKING LIST AS AT ' . $date;
		
		//$data['meetingCrmList'] = $this->model_booking_meeting->getBookingMeetingCrmList();

		$data = array
		(
			'meetingCrmList' 	=> $this->model_booking_meeting->getBookingMeetingCrmList($ID),
            'attendListName' 	=> $this->model_booking_meeting->getattendListName(),
		);

		if(!empty($this->session->userdata('sv_meetingcrm_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_meetingcrm_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'MEETING REPORT AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'MEETING REPORT LIST AS AT ' . $date;

		}

		// die(debug($data['meetingCrmList']));

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/meeting_crm_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

	function hotel_print($ID = null)
	{
		$this->load->model('hr/model_hotel');
		//$data['rsHotelList'] = $this->model_hotel->getHotelBookingList();

		$date = date("d-m-Y");

		if($this->logged_module['role']=='admin')
		{
			if(!empty($this->session->userdata('sv__hotel')))
			{
				if(!empty($ID))
				{
					$data['rsHotelList'] = $this->model_hotel->getHotelBookingList($ID);
				}else{
					$data['rsHotelList'] = $this->session->userdata('sv__hotel');
				}
			}else{
				if(!empty($ID))
				{
					$data['rsHotelList'] = $this->model_hotel->getHotelBookingList($ID);
				}else{
					$data['rsHotelList'] = $this->model_hotel->getHotelBookingList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__hotel')))
			{
				if(!empty($ID))
				{
					$data['rsHotelList'] = $this->model_hotel->getHotelBookingList($ID);
				}else{
					$data['rsHotelList'] = $this->session->userdata('sv__hotel');
				}
			}else{
				if(!empty($ID))
				{
					$data['rsHotelList'] = $this->model_hotel->getHotelBookingList($ID);
				}else{
					$data['rsHotelList'] = $this->model_hotel->getHotelBookingList(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_hotel_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_hotel_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'HOTEL DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'HOTEL LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__hotel','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/hotel_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

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

        $date = date("d-m-Y");
        
		if($this->logged_module['role']=='admin')
		{
	        if(!empty($this->session->userdata('sv__flight__booking')))
			{
				if(!empty($ID))
				{
					$data['listFlightBooking'] = $this->model_flight_booking->getListFlightBooking($ID);
				}else{
					$data['listFlightBooking'] = $this->session->userdata('sv__flight__booking');
				}
			}else{
				if(!empty($ID))
				{
					$data['listFlightBooking'] = $this->model_flight_booking->getListFlightBooking($ID);
				}else{
					$data['listFlightBooking'] = $this->model_flight_booking->getListFlightBooking();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__flight__booking')))
			{
				if(!empty($ID))
				{
					$data['listFlightBooking'] = $this->model_flight_booking->getListFlightBooking($ID);
				}else{
					$data['listFlightBooking'] = $this->session->userdata('sv__flight__booking');
				}
			}else{
				if(!empty($ID))
				{
					$data['listFlightBooking'] = $this->model_flight_booking->getListFlightBooking($ID);
				}else{
					$data['listFlightBooking'] = $this->model_flight_booking->getListFlightBooking(null,$this->logged_user['employment_id']);
				}
			}
		}
        
        if(!empty($this->session->userdata('sv_flight_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_flight_filter_dept'));
			//$data['gname'] = $this->model_flight_booking->getListFlightBooking(null, $this->session->userdata('sv_flight_filter_gname'));
		}

		if(!empty($ID)){
			$data['title']	= 'FLIGHT DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'FLIGHT LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__flight__booking','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/flight_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
    }

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

		$date = date("d-m-Y");

	    if($this->logged_module['role']=='admin')
	    {
	        if(!empty($this->session->userdata('sv__training_request')))
			{
				if(!empty($ID))
				{
					$data['listTrainingRequest'] = $this->model_training_request->getListTrainingRequest($ID);
				}else{
					$data['listTrainingRequest'] = $this->session->userdata('sv__training_request');
				}
			}else{
				if(!empty($ID))
				{
					$data['listTrainingRequest'] = $this->model_training_request->getListTrainingRequest($ID);
				}else{
					$data['listTrainingRequest'] = $this->model_training_request->getListTrainingRequest();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__training_request')))
			{
				if(!empty($ID))
				{
					$data['listTrainingRequest'] = $this->model_training_request->getListTrainingRequest($ID);
				}else{
					$data['listTrainingRequest'] = $this->session->userdata('sv__training_request');
				}
			}else{
				if(!empty($ID))
				{
					$data['listTrainingRequest'] = $this->model_training_request->getListTrainingRequest($ID);
				}else{
					$data['listTrainingRequest'] = $this->model_training_request->getListTrainingRequest(null,$this->logged_user['employment_id']);
				}
			}
		}
        
        if(!empty($this->session->userdata('sv_request_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_request_dept'));
        }
        
        if(!empty($this->session->userdata('sv_request_business')))
		{
			$data['business_entity']	= $this->model_company->getBusinesses(null,$this->session->userdata('sv_request_business'));
		}

		if(!empty($ID)){
			$data['title']	= 'TRAINING REQUEST DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'TRAINING REQUEST LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__training_request','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/request_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

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

		$date = date("d-m-Y");

		if($this->logged_module['role']=='admin')
		{
			if(!empty($this->session->userdata('sv__evaluation__answer')))
			{
				if(!empty($ID)){
					$data['listTrainingEvaluation']	= $this->model_training_evaluation->getAllEvaluationDetails_new($ID);
				}else{
					$data['trainingEvaluation'] = $this->session->userdata('sv__evaluation__answer');
				}
			}else{
				if(!empty($ID)){
					$data['listTrainingEvaluation']	= $this->model_training_evaluation->getAllEvaluationDetails_new($ID);
				}else{
					// $data['listTrainingEvaluation']	= $this->model_training_evaluation->getAllEvaluationDetails_new();
					$data['trainingEvaluation']	= $this->model_training_evaluation->getListTrainingEvaluation();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__evaluation__answer')))
			{
				if(!empty($ID)){
					$data['listTrainingEvaluation']	= $this->model_training_evaluation->getAllEvaluationDetails_new($ID);
				}else{
					$data['listTrainingEvaluation'] = $this->session->userdata('sv__evaluation__answer');
				}
			}else{
				if(!empty($ID)){
					$data['listTrainingEvaluation']	= $this->model_training_evaluation->getAllEvaluationDetails_new($ID);
				}else{
					$data['trainingEvaluation']	= $this->model_training_evaluation->getListTrainingEvaluation($this->logged_user['employment_id']);
				}
			}
		}

		// debug($data['listTrainingEvaluation']);

		if(!empty($this->session->userdata('sv_evaluation_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_evaluation_filter_dept'));
		}

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

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

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

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

			$data['title']	= 'TRAINING EVALUATION DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'TRAINING EVALUATION LIST AS AT ' . $date;

		}

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/evaluation_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

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

		$date = date("d-m-Y");

		if($this->logged_user['division_id'] == 19)
		{
			if(!empty($this->session->userdata('sv__it__equipment')))
			{
				if(!empty($ID))
				{
					$data['equipment_list'] = $this->model_av_it->getEquipmentList($ID);
				}else{
					$data['equipment_list'] = $this->session->userdata('sv__it__equipment');
				}
			}else{
				if(!empty($ID))
				{
					$data['equipment_list'] = $this->model_av_it->getEquipmentList($ID);
				}else{
					$data['equipment_list'] = $this->model_av_it->getEquipmentList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__it__equipment')))
			{
				if(!empty($ID))
				{
					$data['equipment_list'] = $this->model_av_it->getEquipmentList($ID);
				}else{
					$data['equipment_list'] = $this->session->userdata('sv__it__equipment');
				}
			}else{
				if(!empty($ID))
				{
					$data['equipment_list'] = $this->model_av_it->getEquipmentList($ID);
				}else{
					$data['equipment_list'] = $this->model_av_it->getEquipmentList(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_equipment_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_equipment_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'AV / IT EQUIPMENT REQUEST DETAIL AS AT ' . $date;
			$data['ID']				= $ID;
		} else {
			$data['title']	= 'AV / IT EQUIPMENT REQUEST LIST AS AT ' . $date;
		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__it__equipment','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/it_equipment_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

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

		$date = date("d-m-Y");

		if($this->logged_user['division_id'] == 19)
		{
			if(!empty($this->session->userdata('sv__it_service')))
			{
				if(!empty($ID))
				{
					$data['rsServiceList'] = $this->model_it_service->getServiceList($ID);
				}else{
					$data['rsServiceList'] = $this->session->userdata('sv__it_service');
				}
			}else{
				if(!empty($ID))
				{
					$data['rsServiceList'] = $this->model_it_service->getServiceList($ID);
				}else{
					$data['rsServiceList'] = $this->model_it_service->getServiceList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__it_service')))
			{
				if(!empty($ID))
				{
					$data['rsServiceList'] = $this->model_it_service->getServiceList($ID);
				}else{
					$data['rsServiceList'] = $this->session->userdata('sv__it_service');
				}
			}else{
				if(!empty($ID))
				{
					$data['rsServiceList'] 	= $this->model_it_service->getServiceList($ID);
				}else{
					$data['rsServiceList'] = $this->model_it_service->getServiceList(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_service_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_service_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'AV / IT SERVICE REQUEST DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'AV / IT SERVICE REQUEST LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__it_service','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/it_service_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

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

		$date = date("d-m-Y");

		if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin')
		{
			if($this->session->userdata('sv__police_report'))
			{
				if(!empty($ID))
				{
					$data['listPoliceReport'] = $this->model_police_report->getListPoliceReport($ID);
				}else{
					$data['listPoliceReport'] = $this->session->userdata('sv__police_report');
				}
			}else{
				if(!empty($ID))
				{
					$data['listPoliceReport'] = $this->model_police_report->getListPoliceReport($ID);
				}else{
					$data['listPoliceReport'] = $this->model_police_report->getListPoliceReport();
				}
			}
		}else{
			if($this->session->userdata('sv__police_report'))
			{
				if(!empty($ID))
				{
					$data['listPoliceReport'] = $this->model_police_report->getListPoliceReport($ID);
				}else{
					$data['listPoliceReport'] = $this->session->userdata('sv__police_report');
				}
			}else{
				if(!empty($ID))
				{
					$data['listPoliceReport'] = $this->model_police_report->getListPoliceReport($ID);
				}else{
					$data['listPoliceReport'] = $this->model_police_report->getListPoliceReport(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_police_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_police_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'POLICE REPORT DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'POLICE REPORT LIST AS AT ' . $date;

		}


		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/policereport_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

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

		$date = date("d-m-Y");

		if($this->logged_user['division_id'] == 19)
		{
			if($this->session->userdata('sv__system'))
			{
				if(!empty($ID))
				{
					$data['rsSystem'] = $this->model_service_form->getSystemList($ID);
				}else{
					$data['rsSystem'] = $this->session->userdata('sv__system');
				}
			}else{
				if(!empty($ID))
				{
					$data['rsSystem'] = $this->model_service_form->getSystemList($ID);
				}else{
					$data['rsSystem'] = $this->model_service_form->getSystemList();
				}
			}
		}else{
			if($this->session->userdata('sv__system'))
			{
				if(!empty($ID))
				{
					$data['rsSystem'] = $this->model_service_form->getSystemList($ID);
				}else{
					$data['rsSystem'] = $this->session->userdata('sv__system');
				}
			}else{
				if(!empty($ID))
				{
					$data['rsSystem'] = $this->model_service_form->getSystemList($ID);
				}else{
					$data['rsSystem'] = $this->model_service_form->getSystemList(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_system_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_system_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'IT SYSTEM SUPPORT DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'IT SYSTEM SUPPORT LIST AS AT ' . $date;
		}


		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/it_system_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

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

        $date = date("d-m-Y");
        
		if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin')
		{
	        if(!empty($this->session->userdata('sv__delivery')))
			{
				if(!empty($ID))
				{
					$data['listDeliveryRequest'] = $this->model_delivery->getDeliveryList($ID);
				}else{
					$data['listDeliveryRequest'] = $this->session->userdata('sv__delivery');
				}
			}else{
				if(!empty($ID))
				{
					$data['listDeliveryRequest'] = $this->model_delivery->getDeliveryList($ID);
				}else{
					$data['listDeliveryRequest'] = $this->model_delivery->getDeliveryList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__delivery')))
			{
				if(!empty($ID))
				{
					$data['listDeliveryRequest'] = $this->model_delivery->getDeliveryList($ID);
				}else{
					$data['listDeliveryRequest'] = $this->session->userdata('sv__delivery');
				}
			}else{
				if(!empty($ID))
				{
					$data['listDeliveryRequest'] = $this->model_delivery->getDeliveryList($ID);
				}else{
					$data['listDeliveryRequest'] = $this->model_delivery->getDeliveryList(null,$this->logged_user['id']);
				}
			}
		}
        // debug($this->session->userdata());
        if(!empty($this->session->userdata('sv_delivery_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_delivery_filter_dept'));
			//$data['gname'] = $this->model_flight_booking->getListFlightBooking(null, $this->session->userdata('sv_flight_filter_gname'));
		}

		if(!empty($ID)){
			$data['title']	= 'DELIVERY REQUEST DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'DELIVERY REQUEST LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__delivery','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/delivery_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
    }

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

        $date = date("d-m-Y");
        
		if($this->logged_module['role']=='admin')
		{
	        if(!empty($this->session->userdata('sv__qr_code')))
			{
				if(!empty($ID))
				{
					$data['listQRCodeRequest'] = $this->model_qr_code->getQRCodeList($ID);
				}else{
					$data['listQRCodeRequest'] = $this->session->userdata('sv__qr_code');
				}
			}else{
				if(!empty($ID))
				{
					$data['listQRCodeRequest'] = $this->model_qr_code->getQRCodeList($ID);
				}else{
					$data['listQRCodeRequest'] = $this->model_qr_code->getQRCodeList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__qr_code')))
			{
				if(!empty($ID))
				{
					$data['listQRCodeRequest'] = $this->model_qr_code->getQRCodeList($ID);
				}else{
					$data['listQRCodeRequest'] = $this->session->userdata('sv__qr_code');
				}
			}else{
				if(!empty($ID))
				{
					$data['listQRCodeRequest'] = $this->model_qr_code->getQRCodeList($ID);
				}else{
					$data['listQRCodeRequest'] = $this->model_qr_code->getQRCodeList(null, $this->logged_user['id']);
				}
			}
		}
        // debug($this->session->userdata());
        if(!empty($this->session->userdata('sv_qr_code_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_qr_code_filter_dept'));
			//$data['gname'] = $this->model_flight_booking->getListFlightBooking(null, $this->session->userdata('sv_flight_filter_gname'));
		}

		if(!empty($ID)){
			$data['title']	= 'QR CODE CPD REQUEST DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'QR CODE CPD REQUEST LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__qr_code','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/qr_code_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
    }

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

		$data['finance_staff'] = $this->model_user->getUsersByFilter(array('d.id'=>$this->logged_user['id'],'d.division_id'=>8));

        $date = date("d-m-Y");
        
		if($data['finance_staff'])
		{
	        if(!empty($this->session->userdata('sv__invoice')))
			{
				if(!empty($ID))
				{
					$data['listInvoiceRequest'] = $this->model_invoice->getInvoiceList($ID);
				}else{
					$data['listInvoiceRequest'] = $this->session->userdata('sv__invoice');
				}
			}else{
				if(!empty($ID))
				{
					$data['listInvoiceRequest'] = $this->model_invoice->getInvoiceList($ID);
				}else{
					$data['listInvoiceRequest'] = $this->model_invoice->getInvoiceList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__invoice')))
			{
				if(!empty($ID))
				{
					$data['listInvoiceRequest'] = $this->model_invoice->getInvoiceList($ID);
				}else{
					$data['listInvoiceRequest'] = $this->session->userdata('sv__invoice');
				}
			}else{
				if(!empty($ID))
				{
					$data['listInvoiceRequest'] = $this->model_invoice->getInvoiceList($ID);
				}else{
					$data['listInvoiceRequest'] = $this->model_invoice->getInvoiceList(null, $this->logged_user['id']);
				}
			}
		}

        if(!empty($this->session->userdata('sv_invoice_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_invoice_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']		 = 'INVOICE REQUEST DETAIL AS AT ' . $date;
			$data['ID']			 = $ID;
			$data['entity_logo'] = ($data['listInvoiceRequest'])?$this->model_company->getBusinesses('',$data['listInvoiceRequest'][0]['business_entity_id'])['short_name']:'';
		} else {
			$data['title']	= 'INVOICE REQUEST LIST AS AT ' . $date;

		}

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/invoice_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
    }

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

		$data['finance_staff'] = $this->model_user->getUsersByFilter(array('d.id'=>$this->logged_user['id'],'d.division_id'=>8));

        $date = date("d-m-Y");
        
		if($data['finance_staff'])
		{
	        if(!empty($this->session->userdata('sv__credit_note')))
			{
				if(!empty($ID))
				{
					$data['listCreditNoteRequest'] = $this->model_credit_note->getCreditNoteList($ID);
				}else{
					$data['listCreditNoteRequest'] = $this->session->userdata('sv__credit_note');
				}
			}else{
				if(!empty($ID))
				{
					$data['listCreditNoteRequest'] = $this->model_credit_note->getCreditNoteList($ID);
				}else{
					$data['listCreditNoteRequest'] = $this->model_credit_note->getCreditNoteList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__credit_note')))
			{
				if(!empty($ID))
				{
					$data['listCreditNoteRequest'] = $this->model_credit_note->getCreditNoteList($ID);
				}else{
					$data['listCreditNoteRequest'] = $this->session->userdata('sv__credit_note');
				}
			}else{
				if(!empty($ID))
				{
					$data['listCreditNoteRequest'] = $this->model_credit_note->getCreditNoteList($ID);
				}else{
					$data['listCreditNoteRequest'] = $this->model_credit_note->getCreditNoteList(null, $this->logged_user['id']);
				}
			}
		}

        if(!empty($this->session->userdata('sv_credit_note_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_credit_note_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']		 = 'CREDIT NOTE REQUEST DETAIL AS AT ' . $date;
			$data['ID']			 = $ID;
			$data['entity_logo'] = ($data['listCreditNoteRequest'])?$this->model_company->getBusinesses('',$data['listCreditNoteRequest'][0]['business_entity_id'])['short_name']:'';
		} else {
			$data['title']	= 'CREDIT NOTE REQUEST LIST AS AT ' . $date;

		}

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/credit_note_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
    }

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

		$data['finance_staff'] = $this->model_user->getUsersByFilter(array('d.id'=>$this->logged_user['id'],'d.division_id'=>8));

        $date = date("d-m-Y");
        
		if($data['finance_staff'])
		{
	        if(!empty($this->session->userdata('sv__petty_cash_advance')))
			{
				if(!empty($ID))
				{
					$data['listPettyCashAdvance'] = $this->model_petty_cash_advance->getPettyCashAdvanceList($ID);
				}else{
					$data['listPettyCashAdvance'] = $this->session->userdata('sv__petty_cash_advance');
				}
			}else{
				if(!empty($ID))
				{
					$data['listPettyCashAdvance'] = $this->model_petty_cash_advance->getPettyCashAdvanceList($ID);
				}else{
					$data['listPettyCashAdvance'] = $this->model_petty_cash_advance->getPettyCashAdvanceList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__petty_cash_advance')))
			{
				if(!empty($ID))
				{
					$data['listPettyCashAdvance'] = $this->model_petty_cash_advance->getPettyCashAdvanceList($ID);
				}else{
					$data['listPettyCashAdvance'] = $this->session->userdata('sv__petty_cash_advance');
				}
			}else{
				if(!empty($ID))
				{
					$data['listPettyCashAdvance'] = $this->model_petty_cash_advance->getPettyCashAdvanceList($ID);
				}else{
					$data['listPettyCashAdvance'] = $this->model_petty_cash_advance->getPettyCashAdvanceList(null, $this->logged_user['id']);
				}
			}
		}

        if(!empty($this->session->userdata('sv_petty_cash_advance_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_petty_cash_advance_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'PETTY CASH / ADVANCE DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
			$data['entity_logo'] = ($data['listPettyCashAdvance'])?$this->model_company->getBusinesses('',$data['listPettyCashAdvance'][0]['business_entity_id'])['short_name']:'';			
		} else {
			$data['title']	= 'PETTY CASH / ADVANCE LIST AS AT ' . $date;

		}

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/petty_cash_advance_list_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
    }

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

		$input 				= $this->input->post();
		$booking_form 		= array();
		$title_year 		= date('Y');
		$title_month		= '';
		$title_form			= '';
		$title_department 	= '';
		$module_access 		= array();

		if(!empty($_SESSION['all_modules_access']))
		{
			if($this->logged_module['role'] == 'admin' || $_SESSION['user']['division_id'] == 5)
			{
				array_push($module_access,1); // hr
			}

			if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin' || $_SESSION['user']['division_id'] == 4)
			{
				array_push($module_access,7); // admin
			}

			if($_SESSION['user']['division_id'] == 8 || $_SESSION['user']['division_id'] == 10)
			{
				array_push($module_access,9); // finance
			}

			if($_SESSION['user']['division_id'] == 19 || $_SESSION['user']['division_id'] == 10)
			{
				array_push($module_access,3); // it admin
			}
		}

		// $where_in['a.category'] = $module_access;
		// $getBookingName = $this->model_form->getBookingName('view__service_form',$where_in);
		$getBookingName = $this->model_service_form->getServiceForm(array('a.status'=>0), array('b.id' => $module_access));

		if($input)
		{
			if($input['sv_summary_filter_form'] == 20) $select = array('a.*','a.pax as total');
			else $select = array('a.*','count(a.department_id) as total');
			// $select = array('a.title','a.department_id','a.department_name','a.requested_date', 'a.type','a.price','b.affective_date','count(a.department_id) as total');
			if(($input['sv_summary_filter_form'] != 'all')) 
			{
				$this->session->set_userdata('sv_summary_fee_filter_title',$input['sv_summary_filter_form']);
				$where['a.id'] = $input['sv_summary_filter_form'];
			}else{
				$this->session->set_userdata('sv_summary_fee_filter_title',$input['sv_summary_filter_form']);
			}

			if(($input['sv_summary_filter_year'] > 0)) 
			{
				$this->session->set_userdata('sv_summary_fee_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_fee_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_fee_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_fee_filter_month');
			}

			if((!empty($input['sv_summary_filter_department'])) && ($input['sv_summary_filter_department'] > 0)) 
			{
				$this->session->set_userdata('sv_summary_fee_filter_department',$input['sv_summary_filter_department']);
				$where['a.department_id'] = $input['sv_summary_filter_department'];
				$title_department = $input['sv_summary_filter_department'];
			}else{
				$this->session->unset_userdata('sv_summary_fee_filter_department');
			}

			$where_in['a.cat_id'] = $module_access;
			$where_in['a.status'] = array('In_progress','Approved','Verified','Completed');

			$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');
			if($input['sv_summary_filter_form'] == 20)
			{
				$group_by = array('a.department_id','type','YEAR(requested_date)','MONTH(requested_date)');
			}else{
				$group_by = array('department_id','title','YEAR(requested_date)');
			}
	
			// $finance_division	=> $this->model_user->getUsersByFilter(array('a.id' => $this->logged_user['id'],'d.division_id' => 8))[0],

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

			// debug($this->db->last_query());
			// die();

			if($booking_form)
			{
				$title_form = $booking_form[0]['title'];
				$this->session->set_flashdata('success',"Successfully filtering data.");
			}else{
				$this->session->set_flashdata('error',"No data found! Please try again.");
			}
		}else{
			if(!empty(($this->session->userdata('sv_summary_fee_filter_title')))) $this->session->unset_userdata('sv_summary_fee_filter_title');
			if(!empty(($this->session->userdata('sv_summary_fee_filter_year')))) $this->session->unset_userdata('sv_summary_fee_filter_year');
			if(!empty(($this->session->userdata('sv_summary_fee_filter_month')))) $this->session->unset_userdata('sv_summary_fee_filter_month');
			if(!empty(($this->session->userdata('sv_summary_fee_filter_department')))) $this->session->unset_userdata('sv_summary_fee_filter_department');
		}


		$data = array
		(
			'page_setup'		=> $this->template->pageSetup('Service Form', '', 'Service Form Report'),
			'booking_form'		=> $booking_form,
			'title_month'		=> $title_month,
			'title_year'		=> $title_year,
			'title_form'		=> $title_form,
			'getBookingName'	=> $getBookingName,
			'department'		=> $this->model_company->getDepartments(),
		);

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

	function summary_print($mode = null)
	{
		if(isset($mode) && !empty($mode))
		{
		    $sv_filter = 'sv_summary_fee';
		}else{
		    $sv_filter = 'sv_summary';
		}

		$summary_year 			= $this->session->userdata($sv_filter.'_filter_year');
		$summary_month 			= $this->session->userdata($sv_filter.'_filter_month');
		$summary_title 			= $this->session->userdata($sv_filter.'_filter_title');
		$summary_department 	= $this->session->userdata($sv_filter.'_filter_department');

		$module_access = array();
		if(!empty($_SESSION['all_modules_access']))
		{
			if($this->logged_module['role'] == 'admin' || $_SESSION['user']['division_id'] == 5)
			{
				array_push($module_access,1); // hr
			}

			if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin' || $_SESSION['user']['division_id'] == 4)
			{
				array_push($module_access,7); // admin
			}

			if($_SESSION['user']['division_id'] == 8 || $_SESSION['user']['division_id'] == 10)
			{
				array_push($module_access,9); // finance
			}

			if($_SESSION['user']['division_id'] == 19 || $_SESSION['user']['division_id'] == 10)
			{
				array_push($module_access,3); // it admin
			}
		}

		$where_in['a.cat_id'] = $module_access;

		if(!empty($summary_month))
		{
			$month = $summary_month;
		}else{
			$month = date('m');
		}

		if(!empty($summary_year))
		{
			$year = $summary_year;
		}else{
			$year = date('Y');
		}

		$date = $month.'-'.$year;

		if((empty($summary_title)) || ($summary_title == 'all'))
		{
			$data['title']	= 'BOOKING FORM AS AT '.$date;
		}else{
			$data['title']	= $summary_title.' AS AT '. $date;
		}


		/* query */
		// $select = array('a.title','a.department_id','a.department_name','a.requested_date','b.price','b.affective_date','count(a.department_id) as total');
		$select = array('a.id','a.title','a.department_id','a.department_name','a.requested_date', 'a.type','a.price','count(a.department_id) as total');

		if(($summary_title != 'all')) 
		{
			$this->session->set_userdata($sv_filter.'_filter_title',$summary_title);
			$where['a.id'] = $summary_title;
		}else{
			$this->session->unset_userdata($sv_filter.'_filter_title',$summary_title);
		}

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

		if(($summary_department != '') && ($summary_department > 0)) 
		{
			$where['a.department_id'] = $summary_department;
		}else{
			$this->session->unset_userdata($sv_filter.'_filter_department',$summary_department);
		}
		
		$where_in['a.status'] = array('In_progress','Approved','Verified','Completed');

		$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)');
		if($where['a.id'] == 20)
		{
			$group_by = array('id_table','title','YEAR(requested_date)');
		}else{
			$group_by = array('department_id','title','YEAR(requested_date)');
		}

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

		$data['sv_filter']		= $sv_filter;
		$data['mode']			= $mode;
		$data['booking_form']	= $booking_form;
		$data['department']		= $this->model_company->getDepartments('',$summary_department);

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/report_summary_print', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

	function update_form_value()
	{
		$input = $this->input->post();
		$form_id 	= $input['form_id'];
		$form_value = $input['form_value'];
		$value_type = $input['value_type_id'];


		if($value_type == 2)
		{
			$form_value = $form_value/100;
		}


		$data = array
		(
			'price'			=> $form_value,
			'type'			=> $value_type,
			'updatedBY'		=> $this->logged_user['id'],
			'updatedTS'		=> date('Y-m-d H:i:s')
		);

		$existing_data = $this->db->where('form_id',$form_id)->get('sv__ref_form_price')->result_array();


		if($existing_data)
		{
			$where = array('form_id' => $form_id);
			$formValue = $this->model_general->update('sv__ref_form_price',$data,$where);
		}else{
			$data['form_id'] = $form_id;
			$formValue = $this->model_general->insert('sv__ref_form_price',$data);
		}

		if($formValue)
		{
			$this->session->set_flashdata('success',"Successfully update booking form value.");
		}else{
			$this->session->set_flashdata('falied',"Failed to update booking form value.");
		}
		
		redirect(base_url('hr/serviceform_report/sv_summary_fee_report'));
	}

	function get_current_form_value()
	{
		$this->load->model('hr/model_form');
		$form_id = $this->input->post('form_id');
		
		$booking_form_value = $this->model_form->sv__filter('sv__ref_form_price', array('*'), array('form_id' => $form_id));
		$query = $this->db->last_query();
		
		if($booking_form_value)
		{
			print json_encode(array(
				"status" 	=> "Success",
				"result" 	=> $booking_form_value,
				"query"		=> $query,
			)); 
		}
		else
		{
			print json_encode(array(
				"status" 	=> "Error",
				"result" 	=> "No value found",
				"query"		=> $query,
			));
		}	
	}

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

		$input 				= $this->input->post();
		$booking_form 		= array();
		$title_year 		= date('Y');
		$title_month		= '';
		$module_access 		= array();

		if(!empty($_SESSION['all_modules_access']))
		{
			if($this->logged_module['role'] == 'admin' || $_SESSION['user']['division_id'] == 5)
			{
				array_push($module_access,1); // hr
			}

			if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin' || $_SESSION['user']['division_id'] == 4)
			{
				array_push($module_access,7); // admin
			}

			if($_SESSION['user']['division_id'] == 8 || $_SESSION['user']['division_id'] == 10)
			{
				array_push($module_access,9); // finance
			}

			if($_SESSION['user']['division_id'] == 19 || $_SESSION['user']['division_id'] == 10)
			{
				array_push($module_access,3); // it admin
			}
		}
		
		// $where_in['a.category'] = $module_access;
		$getBookingName = $this->model_service_form->getServiceForm(array('a.status'=>0), array('b.id' => $module_access));

		if($input)
		{
			$select = array('a.title','a.department_id','a.department_name','a.requested_date', 'a.type', 'a.price', 'count(a.department_id) as total');
			// $select = array('a.title','a.department_id','a.department_name','a.requested_date', 'a.type','a.price','b.affective_date','count(a.department_id) 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.cat_id'] = $module_access;
			$where_in['a.status'] = array('In_progress','Approved','Verified','Completed');

			$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('a.department_id'=>'asc','a.cat_id'=>'asc','a.id'=>'asc');
			if($input['sv_summary_filter_form'] == 20)
			{
				$group_by = array('department_id','id','title','YEAR(requested_date)');
			}else{
				$group_by = array('department_id','title','YEAR(requested_date)');
			}
	
			// $finance_division	=> $this->model_user->getUsersByFilter(array('a.id' => $this->logged_user['id'],'d.division_id' => 8))[0],

			$booking_form = $this->model_form->sv__filter('view__service_form a', $select, $where, $join, $order_by, $group_by, null, null, null, $where_in);
			// debug($this->db->last_query());
			// die();

			if($booking_form)
			{
				$this->session->set_flashdata('success',"Successfully filtering data.");
			}else{
				$this->session->set_flashdata('error',"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'),
			'booking_form'		=> $booking_form,
			'title_month'		=> $title_month,
			'title_year'		=> $title_year,
			'getBookingName'	=> $getBookingName,
		);

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

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

		$date = date("d-m-Y");
		
		if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin')
		{
			if(!empty($this->session->userdata('sv__zoom_booking')))
			{
				if(!empty($ID)){
					$data['zoomBookingList'] = $this->model_zoom_booking->getZoomRequestList($ID);
				}else{
					$data['zoomBookingList'] = $this->session->userdata('sv__zoom_booking');
				}
			}else{
				if(!empty($ID)){
					$data['zoomBookingList'] = $this->model_zoom_booking->getZoomRequestList($ID);
				}else{
					$data['zoomBookingList'] = $this->model_zoom_booking->getZoomRequestList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__zoom_booking')))
			{
				if(!empty($ID)){
					$data['zoomBookingList'] = $this->model_zoom_booking->getZoomRequestList($ID);
				}else{
					$data['zoomBookingList'] = $this->session->userdata('sv__zoom_booking');
				}
			}else{
				if(!empty($ID)){
					$data['zoomBookingList'] = $this->model_zoom_booking->getZoomRequestList($ID);
				}else{
					$data['zoomBookingList'] = $this->model_zoom_booking->getZoomRequestList(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_zoom_booking_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_zoom_booking_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'ZOOM BOOKING DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'ZOOM BOOKING LIST AS AT ' . $date;

		}

		$data['account_list'] = (!empty($this->session->userdata('sv_zoom_booking_filter_account')) && $this->session->userdata('sv_zoom_booking_filter_account') != 'ALL')?$this->model_zoom_booking->getZoomAccountList($this->session->userdata('sv_zoom_booking_filter_account'))[0]:$this->session->userdata('sv_zoom_booking_filter_account');

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__zoom_booking','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

        $this->load->view('hr/policyprocedure/report/header.php');
        $this->load->view('hr/policyprocedure/report/zoom_booking_list_report.php',$data);
        $this->load->view('hr/policyprocedure/report/footer.php');
    }

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

		$date = date("d-m-Y");

		if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin')
		{
			if(!empty($this->session->userdata('sv__talent_referral')))
			{
				if(!empty($ID)){
					$data['talentReferralList'] = $this->model_talent_referral->getTalentReferralList($ID);
				}else{
					$data['talentReferralList'] = $this->session->userdata('sv__talent_referral');
				}
			}else{
				if(!empty($ID)){
					$data['talentReferralList'] = $this->model_talent_referral->getTalentReferralList($ID);
				}else{
					$data['talentReferralList'] = $this->model_talent_referral->getTalentReferralList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__talent_referral')))
			{
				if(!empty($ID)){
					$data['talentReferralList'] = $this->model_talent_referral->getTalentReferralList($ID);
				}else{
					$data['talentReferralList'] = $this->session->userdata('sv__talent_referral');
				}
			}else{
				if(!empty($ID)){
					$data['talentReferralList'] = $this->model_talent_referral->getTalentReferralList($ID);
				}else{
					$data['talentReferralList'] = $this->model_talent_referral->getTalentReferralList(null,$this->logged_user['id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_talent_referral_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_talent_referral_filter_dept'));
		}

		if(!empty($ID)){
			$data['title']	= 'TALENT REFERRAL PROGRAM FORM DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'TALENT REFERRAL PROGRAM FORM LIST AS AT ' . $date;

		}

        $this->load->view('hr/policyprocedure/report/header.php');
        $this->load->view('hr/policyprocedure/report/talent_referral_list_report.php',$data);
        $this->load->view('hr/policyprocedure/report/footer.php');
    }

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

		$date = date("d-m-Y");
		
		if($_SESSION['all_modules_access'][1]['access_lvl'] == 'admin')
		{
			if(!empty($this->session->userdata('sv__job_request')))
			{
				if(!empty($ID)){
					$data['jobRequestList'] = $this->model_job_request->getJobRequestList($ID);
				}else{
					$data['jobRequestList'] = $this->session->userdata('sv__job_request');
				}
			}else{
				if(!empty($ID)){
					$data['jobRequestList'] = $this->model_job_request->getJobRequestList($ID);
				}else{
					$data['jobRequestList'] = $this->model_job_request->getJobRequestList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__job_request')))
			{
				if(!empty($ID)){
					$data['jobRequestList'] = $this->model_job_request->getJobRequestList($ID);
				}else{
					$data['jobRequestList'] = $this->session->userdata('sv__job_request');
				}
			}else{
				if(!empty($ID)){
					$data['jobRequestList'] = $this->model_job_request->getJobRequestList($ID);
				}else{
					$data['jobRequestList'] = $this->model_job_request->getJobRequestList(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_job_request_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_job_request_filter_dept'));
		}

		if(!empty($this->session->userdata('sv_job_request_filter_client_id')))
		{
			$data['client']	= $this->model_crm->getCustomerDetail(array('a.id'=>$this->session->userdata('sv_job_request_filter_client_id')));
		}

		if(!empty($ID)){
			$data['title']	= 'JOB REQUEST DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'JOB REQUEST LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__job_request','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

        $this->load->view('hr/policyprocedure/report/header.php');
        $this->load->view('hr/policyprocedure/report/job_request_list_report.php',$data);
        $this->load->view('hr/policyprocedure/report/footer.php');
    }

    function client_new_resignation_print($ID = null)
    {
        $this->load->model('crm/model_crm');
        $this->load->model('hr/model_client_new_resignation');

		$date = date("d-m-Y");
		
		if($_SESSION['all_modules_access'][1]['access_lvl'] == 'admin')
		{
			if(!empty($this->session->userdata('sv__client_new_resignation')))
			{
				if(!empty($ID)){
					$data['request_list'] = $this->model_client_new_resignation->getClientNewResignationList($ID);
				}else{
					$data['request_list'] = $this->session->userdata('sv__client_new_resignation');
				}
			}else{
				if(!empty($ID)){
					$data['request_list'] = $this->model_client_new_resignation->getClientNewResignationList($ID);
				}else{
					$data['request_list'] = $this->model_client_new_resignation->getClientNewResignationList();
				}
			}
		}else{
			if(!empty($this->session->userdata('sv__client_new_resignation')))
			{
				if(!empty($ID)){
					$data['request_list'] = $this->model_client_new_resignation->getClientNewResignationList($ID);
				}else{
					$data['request_list'] = $this->session->userdata('sv__client_new_resignation');
				}
			}else{
				if(!empty($ID)){
					$data['request_list'] = $this->model_client_new_resignation->getClientNewResignationList($ID);
				}else{
					$data['request_list'] = $this->model_client_new_resignation->getClientNewResignationList(null,$this->logged_user['employment_id']);
				}
			}
		}

		if(!empty($this->session->userdata('sv_client_new_resignation_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_client_new_resignation_filter_dept'));
		}

		if(!empty($this->session->userdata('sv_client_new_resignation_filter_client_id')))
		{
			$data['client']	= $this->model_crm->getCustomerDetail(array('a.id'=>$this->session->userdata('sv_client_new_resignation_filter_client_id')))[0];
		}
		
		if(!empty($ID)){
			$data['title']	= 'NEW CLIENT / RESIGNATION DETAIL AS AT ' . $date;
			$data['ID']		= $ID;
		} else {
			$data['title']	= 'NEW CLIENT / RESIGNATION LIST AS AT ' . $date;

		}

		if(!empty($ID)){
            $data_approval['rsApproval'] = $this->model_approval->getApproval(array('a.table_name'=>'sv__client_new_resignation','a.id_table'=>$ID));
            if(!empty($data_approval['rsApproval'])){
            	$data['approval'] = $this->load->view('hr/policyprocedure/report/approval_report',$data_approval,true);
            }else{
            	$data['approval'] = '';
            }
        }

        $this->load->view('hr/policyprocedure/report/header.php');
        $this->load->view('hr/policyprocedure/report/client_new_resignation_report.php',$data);
        $this->load->view('hr/policyprocedure/report/footer.php');
    }

	public function complaint_print($id)
	{
		$this->load->model('hr/model_complaint');

		$data = array('title' => 'Complaint Details',
			'data_method'	=> $this->model_general->fetchAll('_ref__complaint_method', array('*'), null, null, array('id' => 'ASC')),
			'data_about'	=> $this->model_general->fetchAll('_ref__complaint_about', array('*'), null, null, array('id' => 'ASC'))
		);

		$data['data_complaint']			= $this->model_complaint->getComplaintListByID($id);
		$data['data_complaint_contact']	= $this->model_general->fetchAll('customer__contact', array('*'), array('is_delete' => 0, 'customer_id' => $data['data_complaint'][0]->client_id), null, array('name' => 'ASC'));
		$data['data_complaint_method']	= $this->model_general->fetchAll('sv__complaint_method', array('*'), array('is_delete' => 0, 'complaint_id' => $data['data_complaint'][0]->id), null, array('id' => 'ASC'));
		$data['data_complaint_about']	= $this->model_general->fetchAll('sv__complaint_about', array('*'), array('is_delete' => 0, 'complaint_id' => $data['data_complaint'][0]->id), null, array('id' => 'ASC'));
		$data['department_staff']		= $this->model_general->fetchAll('user__employment_detail', array('*'), array('is_delete' => 0, 'status' => 0, 'department_id' => $data['data_complaint'][0]->dept_id), null, array('name' => 'ASC'));
		$data['data_complaint_time']	= $this->model_general->fetchAll('sv__complaint_time_promise', array('*'), array('is_delete' => 0, 'complaint_id' => $data['data_complaint'][0]->id), null, array('id' => 'ASC'));
		$data['date_promise']			= $this->model_general->fetchAll('sv__complaint_time_promise', array('date_promise'), array('is_delete' => 0, 'complaint_id' => $data['data_complaint'][0]->id, 'time_id' => 2), null, array('id' => 'ASC'));

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/complaint_report', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}

	public function complaint_print_all()
	{
		$this->load->model('hr/model_complaint');
		$this->load->model('crm/model_crm');

		$date = date("d-m-Y");

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

		$data['title']			= 'COMPLAINT LIST AS AT ' . $date;
		$data['complaint_list']	= $this->model_complaint->getComplaintListAdmin();

		if(!empty($this->session->userdata('sv_complaint_filter_dept')))
		{
			$data['department']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_complaint_filter_dept'));
		}

		if(!empty($this->session->userdata('sv_complaint_filter_client')))
		{
			if($this->session->userdata('sv_complaint_filter_type') == '0'){
				$data['client']	= $this->model_company->getDepartments(null,$this->session->userdata('sv_complaint_filter_client'));
			} else if($this->session->userdata('sv_complaint_filter_type') == '1') {
				$data['client']	= $this->model_crm->getCustomer($this->session->userdata('sv_complaint_filter_client'));
			}
		}

		$this->load->view('hr/policyprocedure/report/header.php');
		$this->load->view('hr/policyprocedure/report/complaint_report_all', $data);
		$this->load->view('hr/policyprocedure/report/footer.php');
	}
}
?>