<?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('timesheetwest');
	
	$xcrud->order_by('twestid','desc');
	

//second level table configurations
	$rostering_timesheet = $xcrud->nested_table('rostering_timesheet','twestid','timesheetwestdetails','twestid'); 
	 
	 //$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','employeemaster','employeeid',array('first_name','last_name','employeeid'),array('department' => 'GFW'));
$rostering_timesheet->relation('mon_shift','shifts','shiftid','shiftplushours');
	$rostering_timesheet->relation('tues_shift','shifts','shiftid','shiftplushours');
	$rostering_timesheet->relation('wed_shift','shifts','shiftid','shiftplushours');
	$rostering_timesheet->relation('thurs_shift','shifts','shiftid','shiftplushours');
	$rostering_timesheet->relation('fri_shift','shifts','shiftid','shiftplushours');
	$rostering_timesheet->relation('sat_shift','shifts','shiftid','shiftplushours');
	$rostering_timesheet->relation('sun_shift','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('mon_shift_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->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','');
		$rostering_timesheet->column_width('debtorno','120px'); 
		$rostering_timesheet->column_width('location','150px'); 
	$rostering_timesheet->column_width('employeeid','150px'); 
$rostering_timesheet->column_width('mon_hrs,tues_hrs,wed_hrs,thurs_hrs,fri_hrs,sat_hrs,sun_hrs','5px');
	$rostering_timesheet->column_width('mon_shift,tues_shift,wed_shift,thurs_shift,fri_shift,sat_shift,sun_shift','95px');
	$rostering_timesheet->column_width('total_hrs','20px');
	$rostering_timesheet->fields('mon_hrs,tues_hrs,wed_hrs,thurs_hrs,fri_hrs,sat_hrs,sun_hrs', 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('mon_shift','=','{mon_shift}',$mon_color);
	//$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','functionstimesheetwest.php');




$rostering_timesheet->before_insert('calculate_totalhoursperweek','functionstimesheetwest.php');
$rostering_timesheet->before_update('calculate_totalhoursperweek','functionstimesheetwest.php');

//$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_hrs,tues_hrs,wed_hrs,thurs_hrs,fri_hrs,sat_hrs,sun_hrs,total_hrs');
   
   
   
	$rostering_timesheet->table_name('Employee scheduling');
	
	$rostering_timesheet->duplicate_button();
	$rostering_timesheet->disabled('rosterid,mon_hrs,tues_hrs,wed_hrs,thurs_hrs,fri_hrs,sat_hrs,sun_hrs,total_hrs,normal_hours,time_half_hours,double_hours');
	//$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',array('airport' => 0));
  $xcrud->relation('patrol_location','guardforceclient','clientid','patrollocation','','','','','','debtorno','client');       
 	 $xcrud->relation('account_number','guardforceclient','clientid','account_number','','','','','','account_number','patrol_location');
//$xcrud->relation('department','guardforceclient','clientid','department','','','','','','clientid','patrol_location');
	$xcrud->table_name('Guardforce West Client Timesheet Management','Employee 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->disabled('department');
	$xcrud->before_update('displaydepartment','functionsguardforceclient.php');
	$xcrud->after_update('displaydepartment','functionsguardforceclient.php');
    $xcrud->show_primary_ai_column(true);
    $xcrud->column_pattern('rswestid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{twestid}">{value}</a>');
	//$xcrud->load_view('create','rostering.php'); 
   // $xcrud->load_view('edit','rostering.php');
	//$xcrud->load_view('view','rostering.php');
$xcrud->unset_print();
$xcrud->unset_csv();
    
	
	echo $xcrud->render();
	

	

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

include('includes/footer.inc'); 

?>

