<?php

/* $Id: SelectCustomer.php 7133 2015-02-07 03:23:51Z daintree $*/

include('includes/session.inc');
$Title = _('HRMS');
include('includes/header.inc');


include('includes/SQL_CommonFunctions.inc');
echo '<link href="' . $RootPath . '/css/evergreen2'.'/default.css" rel="stylesheet" type="text/css" media="screen"/>';


//echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/maintenance.png"> </p>';
      
	echo '<div class="col-sm-9">';
		
    include('xcrud/xcrud.php');
    $xcrud = Xcrud::get_instance();
	$xcrud->table('rostering');
	
	$xcrud->order_by('rosterid','desc');
	

//second level table configurations
	$rostering_timesheet = $xcrud->nested_table('rostering_timesheet','rosterid','rosteringtimesheet','rosterid'); 
	       $pool = $xcrud->nested_table('pool','patrol_location','approved_guards','clientid'); 

              $pool->relation('employeeid','employeemaster','employeeid',array('first_name','last_name','employeeid'));


$cem = $xcrud->nested_table('cem','rosterid','cemtimesheet','rosterid'); 
$cem->relation('employeeid','employeemaster','employeeid',array('first_name','last_name','employeeid'));
$cem->load_view('list','cemlist.php');
$cem->load_view('edit','cemedit.php');
$cem->load_view('create','cemedit.php');
$cem->load_view('view','cemedit.php');


$pool->unset_print();
$pool->unset_csv();
    
$pool->unset_remove();
$pool->unset_view();

$pool->unset_add();
$pool->unset_edit();


	$pool->column_name('clientid','Patrol location ID/clientID');
	$pool->column_name('employeeid','Security Guards');

$pool->table_name('Approved Pool Guards','Pool guards','icon-leaf');
	 //$rostering_timesheet->columns('employeeid,mon_shift,mon_hrs,tues_shift,tues_hrs,wed_shift,wed_hrs,thurs_shift,thurs_hrs,fri_shift,fri_hrs,sat_shift,sat_hrs,sun_shift,sun_hrs,total_hrs');
	 
   //$rostering_timesheet->fields('employeeid,mon_shift,mon_hrs,tues_shift,tues_hrs,wed_shift,wed_hrs,thurs_shift,thurs_hrs,fri_shift,fri_hrs,sat_shift,sat_hrs,sun_shift,sun_hrs,total_hrs');
	
	  //employee id and name
	  
	
	$rostering_timesheet->relation('employeeid','poolguards','employeeid',array('first_name','last_name','employeeid'),array('rostered' => '0'));



//$rostering_timesheet->pass_default(array('mon_date' => 'Joe', 'tues_date' => 'Boston'));
//$rostering_timesheet->relation('mon_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('mon_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('tues_shift','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('tues_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('wed_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('wed_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('thurs_shift','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('thurs_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('fri_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('fri_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('sat_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('sat_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('sun_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('sun_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('mon_shift_2','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('mon_shift_2_2','shifts','shiftid','shiftplushours');
	 //$rostering_timesheet->change_type('mon_shift','select','3pm-7pm','3pm-7pm,9am-12pm');
	 
 
	
	
     //$rostering_timesheet->relation('mon_hrs','shifts','shiftid','hours','','','','','','shiftid','mon_shift');
	 
	 
	 //$rostering_timesheet->before_insert('gridcolor');
	//$rostering_timesheet->before_update('gridcolor');
	
	//$rostering_timesheet->pass_var('montime_in', 'NOW()');
    //$rostering_timesheet->no_quotes('montime_in');
	
	
	$rostering_timesheet->label('employeeid','Employees');
	$rostering_timesheet->label('debtorno','Customer');
	$rostering_timesheet->column_name('debtorno','Customer');
	$rostering_timesheet->column_name('total_hrs','Total');
	$rostering_timesheet->column_name('mon_hrs,tues_hrs,wed_hrs,thurs_hrs,fri_hrs,sat_hrs,sun_hrs,mon_hrs_2,mon_hrs2,tues_hrs2,wed_hrs2,thurs_hrs2,fri_hrs2,sat_hrs2,sun_hrs2,mon_hrs_2_2','');
		$rostering_timesheet->column_width('debtorno','120px'); 
		$rostering_timesheet->column_width('location','150px'); 
	$rostering_timesheet->column_width('employeeid','500px'); 
//$rostering_timesheet->column_width('mon_hrs,tues_hrs,wed_hrs,thurs_hrs,fri_hrs,sat_hrs,sun_hrs,mon_hrs_2,mon_hrs2,tues_hrs2,wed_hrs2,thurs_hrs2,fri_hrs2,sat_hrs2,sun_hrs2,mon_hrs_2_2','5px');
	//$rostering_timesheet->column_width('mon_shift,tues_shift,wed_shift,thurs_shift,fri_shift,sat_shift,sun_shift,mon_shift_2','95px');
	//$rostering_timesheet->column_width('total_hrs','20px');
	//$rostering_timesheet->fields('mon_hrs,mon_total,tues_hrs,tues_total,wed_hrs,wed_total,thurs_hrs,thurs_total,fri_hrs,fri_total,sat_hrs,sat_total,sun_hrs,sun_total,mon_hrs_2,mon2_total,mon_hrs2,tues_hrs2,wed_hrs2,thurs_hrs2,fri_hrs2,sat_hrs2,sun_hrs2,mon_hrs_2_2', true);
	//$rostering_timesheet->validation_required('employeeid');
	
	//check whether total hours doesnt exceel employees max hours allowed to work. checking with employeemaster database.

	
	//grid coloring based on shift table
	
	$rostering_timesheet->highlight('montime_in','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('montime_in','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('montime_in','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('montime_in','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('montime_in1','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('montime_in1','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('montime_in1','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('montime_in1','>=','15:00:00','#FFFF33');


		$rostering_timesheet->highlight('tuestime_in','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('tuestime_in','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('tuestime_in','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('tuestime_in','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('tuestime_in1','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('tuestime_in1','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('tuestime_in1','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('tuestime_in1','>=','15:00:00','#FFFF33');


	$rostering_timesheet->highlight('wedtime_in','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('wedtime_in','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('wedtime_in','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('wedtime_in','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('wedtime_in1','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('wedtime_in1','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('wedtime_in1','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('wedtime_in1','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('thurstime_in','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('thurstime_in','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('thurstime_in','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('thurstime_in','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('thurstime_in1','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('thurstime_in1','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('thurstime_in1','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('thurstime_in1','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('fritime_in','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('fritime_in','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('fritime_in','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('fritime_in','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('fritime_in1','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('fritime_in1','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('fritime_in1','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('fritime_in1','>=','15:00:00','#FFFF33');
	$rostering_timesheet->highlight('sattime_in','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('sattime_in','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('sattime_in','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('sattime_in','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('sattime_in1','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('sattime_in1','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('sattime_in1','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('sattime_in1','>=','15:00:00','#FFFF33');


	$rostering_timesheet->highlight('sunttime_in','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('sunttime_in','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('sunttime_in','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('sunttime_in','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('suntime_in1','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('suntime_in1','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('suntime_in1','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('suntime_in1','>=','15:00:00','#FFFF33');


	$rostering_timesheet->highlight('mon2time_in','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('mon2time_in','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('mon2time_in','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('mon2time_in','>=','15:00:00','#FFFF33');

	$rostering_timesheet->highlight('mon2time_in1','>=','00:00:00','white');
	
	$rostering_timesheet->highlight('mon2time_in1','>=','07:00:00','#00d8ff');

$rostering_timesheet->highlight('mon2time_in1','>=','12:00:00','#28B463');

$rostering_timesheet->highlight('mon2time_in1','>=','15:00:00','#FFFF33');





	//$rostering_timesheet->highlight('mon_hrs','=','{mon_hrs}',$mon_color);
	
	
//$rostering_timesheet->before_insert('gridcolor');
//$rostering_timesheet->before_update('gridcolor');
	
	
	//calculate total employee hours per week
//$rostering_timesheet->before_list('highlightcell');




$rostering_timesheet->before_insert('calculate_totalhoursperweek');
$rostering_timesheet->before_update('calculate_totalhoursperweek');

//$rostering_timesheet->field_callback('total_hrs','validate_maxhours');

//$rostering_timesheet->before_insert('validate_maxhours');
//$rostering_timesheet->before_update('validate_maxhours');

	//$rostering_timesheet->table_name('Employee Schedulling');
	
	//calculate total  hours per per each day
	
   $rostering_timesheet->sum('mon_total,tues_total,wed_total,thurs_total,fri_total,sat_total,sun_total,mon2_total,total_hrs,normal_hours,time_half_hours,double_hours');
   
   
   
	$rostering_timesheet->table_name('Employee scheduling');
	
	$rostering_timesheet->duplicate_button();
	$rostering_timesheet->disabled('rosterid,mon_hrs,mon_hrs2,mon_total,tues_hrs,tues_hrs2,tues_total,wed_hrs,wed_hrs2,wed_total,thurs_hrs,thurs_hrs2,thurs_total,fri_hrs,fri_hrs2,fri_total,sat_hrs,sat_hrs2,sat_total,sun_hrs,sun_hrs2,sun_total,mon_hrs_2,mon_hrs_2_2,mon2_total,total_hrs,normal_hours,time_half_hours,double_hours,mon_date,tues_date,wed_date,thurs_date,fri_date,sat_date,sun_date,mon2_date');
	//$rostering_timesheet->disabled('m_hrs');
	
	
	


	//$rostering_timesheet->highlight('mon_shift','=','{mon_shift}','{mon_color}');
	
	//1st level main table
	
$xcrud->relation('sectors','sectors','id','name');
  
		// $xcrud->relation('client','debtorsmaster','debtorno','name','','','','','','sectors','sectors');
  $xcrud->relation('patrol_location','guardforceclient','clientid',array('customername','patrollocation'),'','','','','','sectors','sectors');       
 //	 $xcrud->relation('account_number','guardforceclient','clientid','account_number','','','','','','clientid','patrol_location');
//$xcrud->relation('department','guardforceclient','clientid','department','','','','','','clientid','patrol_location');
	$xcrud->table_name('Guardforce Client Rostering Management','Employee Timesheet Scheduling','icon-leaf');
	
			
    $xcrud->change_type('status','select','pending','pending,approved,locked');
   
	
	//$approvedby=stripslashes($_SESSION['UsersRealName']);
	//$rostering_timesheet->columns('approved_by',true);
     
	//$rostering_timesheet->fields('approved_by',true);
	
	//$rostering_timesheet->validation_required(array('period' => 1,'start_date','end_date','cl'));
	$rostering_timesheet->duplicate_button();
		$rostering_timesheet->unset_print();
        $rostering_timesheet->unset_csv();
	$rostering_timesheet->benchmark(true);
	
	//validate max hours for employees
	
//$rostering_timesheet->after_insert('after');
//$rostering_timesheet->after_update('after');
	
	$xcrud->highlight('total_hrs','=',48,'#99FF66');
	$xcrud->highlight('total_hrs','>',48,'#ffe6f2');
	$xcrud->highlight('total_hrs','<',48,'#e6fff2');
	$xcrud->highlight_row('total_hrs','<',48,'white');
		$xcrud->pass_default('department','GFS');
	$xcrud->disabled('department,last_modified_by,lastupdate');
	//$xcrud->before_insert('displaydepartment','functionsguardforceclient.php');
	//$xcrud->before_update('displaydepartment','functionsguardforceclient.php');
    $xcrud->show_primary_ai_column(true);
    $xcrud->column_pattern('rosterid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{rosterid}">{value}</a>');
	//$xcrud->load_view('create','rostering.php'); 
   // $xcrud->load_view('edit','rostering.php');
	$rostering_timesheet->load_view('list','rosteringlist.php');
$rostering_timesheet->load_view('edit','rosteringedit.php');
$rostering_timesheet->load_view('create','rosteringedit.php');
$rostering_timesheet->load_view('view','rosteringedit.php');
$xcrud->unset_print();
$xcrud->unset_csv();
    $xcrud->duplicate_button();
//$xcrud->before_insert('poolguardcreation');
//$xcrud->before_update('poolguardcreation');


$userid = $_SESSION['UserID'];

$xcrud->pass_var('last_modified_by',$userid );

$timenow = date('Y-m-d H:i:s');

	$xcrud->pass_var('lastupdate',$timenow);

	echo $xcrud->render();



	

echo '</div>';
echo '</div>';

include('includes/footer.inc'); 

?>

