
<?php   
$PageSecurity = 1;
include('includes/AccountGroupMaster_Class.php');
include('includes/PaginationClass.php');
include('includes/fun-HRClass.php');
include('includes/fun-php.php');
$table='bil_chamber';


$config_hr=$s->GetFieldValue("config_hr_compensition","CompanyId='".$_SESSION['ACGCompanyId']."'","compensation");


if($_REQUEST['Save'] && $_REQUEST['action']!='Edit')
{
$data['chamber']=$_REQUEST['Chamber'];
$data['chamber_code']=$_REQUEST['chamber_code'];
$data['CompanyId']=$_SESSION['ACGCompanyId'];
$data['Created_date']=date('Y-m-d');
$data['Created_by']=$_SESSION['UserID'];
$s->RecordInsert($table,$data);
//$s->pageLocation('index.php?route=Voucher_Master&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}
	
if(!$_REQUEST['Save'] &&   $_REQUEST['action']=='Edit')
{
	$condition="id='".$_REQUEST['VoucherType']."'";
	$allready=$s->GetRecord($table,  $condition);
	$Select=DB_query($allready,$db);
	$RData=DB_fetch_array($Select);		
	$chamber_code=$RData['chamber_code'];
	$Chamber=$RData['chamber'];
	
}	
if($_REQUEST['Save'] && $_REQUEST['action']=='Edit')
{
 $data['chamber']=$_REQUEST['Chamber'];
 $data['chamber_code']=$_REQUEST['chamber_code'];
 $data['Modified_date']=date('Y-m-d');
 $data['Modified_by']=$_SESSION['UserID'];
  $cond="id='".$_REQUEST['VoucherType']."'";
	$update= $s->EditRecord($table, $data, $cond);
	$row=DB_query($update,$db);
	if(!$row)
	{
	   die('Error'.DB_error());
	}
  prnMsg( _('Record Updated successfully'),'success');
}

if($_REQUEST['action']=='del')
{
	$condition="id='".$_REQUEST['VoucherType']."'";
	$s->DeleteRecord($table,$condition);
	prnMsg( _('Record deleted successfully'),'success');
	$s->pageLocation('index.php?route=Billing/Masters/chamber_master&modid='.$_REQUEST['modid'].'&frmid='.$_REQUEST['frmid'].'');
}

if($_REQUEST['proceed']!='')
{
 	 $s->pageLocation($target."&month=".$_REQUEST['month']."&years=".$_REQUEST['years']."&site=".$_REQUEST['site']."&empcode=".$_REQUEST['employee_code']);
         echo $_REQUEST['empcode'];
}


?>
<link rel="stylesheet" href="css/new_mxerp1.css">
<script src="js/jquery10.js" type="text/javascript"></script>
<script src="js/settings.js" type="text/javascript"></script>
<script>
function check_selectedEmployee()
{
	if(document.getElementById("site").value=='0')
	{
		alert("Please Select The Branch First !");
		return false;
	}
	/*if(document.getElementById("employee_code").value=='')
	{
		alert("Please Select The Employee First !");
		return false;
	}*/
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		var chkemp=xmlhttp.responseText;
		if(chkemp=='1')
		{
			alert("You Cannot Proceed As DOJ Is Greater Than Current Month");
			return false;
		}
		else
		{
			document.myform.submit();
		}
	 //return false;
		//document.getElementById("div_id").innerHTML=xmlhttp.responseText;
	}
	}
	var current_month=parseInt(document.getElementById("month").value);
	var current_years=parseInt(document.getElementById("years").value);
	var EmpId=document.getElementById("employee_code").value;
	xmlhttp.open("GET","CheckDateOfJoiningForEmp.php?EMPID="+EmpId+"&CurrSAMonth="+current_month+"&CurrSAYear="+current_years,true);
	xmlhttp.send();
}

function getEmployeeList()
{
          if($('#empType').val()=='')
          {
          	alert('Please select Employee type.');
          	return false;
          }
          if($('#site').val()==0)
          {
          	alert('Please select branch.');
          	return false;
          }
           
 $.ajax({
						url : "get_valid-emp.php",
						type : "POST",
						data : {
					    employeeType:$('#empType').val(),
						branch:$('#site').val()
						},
						success : function(data) {//alert(data);
							
						 $('#employee_code').html(data);	
 
													}
					});
}
</script>
<?php
// WO CALCULATE

?>
<div class="body_contain">
    <div class="tab_div">
    	<h1>Compensation Leave Details</h1>
       <form action="" method="post" name="myform">
<table width="100%" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td class="tabledata1"><strong>For Month</strong></td>
	<td><select name="month" id="month" style="width:150px;">
	<?php $amonth=array(1=>'Jan','Feb','March','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
	  for($i=1;$i<=count($amonth) ;$i++)
	  {
	   $p='';
	   if($_REQUEST['month']==$i)
	   $p='selected';
	   
	    echo "<option value='".$i."' $p>$amonth[$i]</option>";
	  }
	?></select></td>
	<td class="tabledata1"><strong>Year</strong></td>
	<td><select name="years" id="years" style="width:150px;">
	<?php for($i=date('Y');$i>=2000;$i--){
	  $p='';
	   if($_REQUEST['years']==$i)
	   $p='selected';
	    echo "<option value='".$i."' $p>$i</option>";
	  }?>
	  </select></td>
	 <td class="tabledata1"><strong>Employee Type</strong></td><td><select name="empType" id="empType">
	 <option value="">Select Type</option>
	 <option value="Permanent" <?php echo ($_REQUEST['empType']=='Permanent')?'selected="selected"':''; ?>>Permanent</option>
	 <option value="Temporary" <?php echo ($_REQUEST['empType']=='Temporary')?'selected="selected"':''; ?>>Temporary</option>
	</select></td>
	<td class="tabledata1"><strong>Branch</strong></td>
	<td><select name="site" id="site" style="width:150px;" onchange="getEmployeeList()" >
	<option value="0">Select</option>
	<?php 
	$site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$db);
	while($site_row=DB_fetch_array($site_sql))
	{
	?>
	<option value="<?php echo $site_row['loccode'];?>"<?php echo ($_REQUEST['site']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
<?php }?>
	</select></td>
	<?php 
     $emp_query = "SELECT id,emp_name FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' AND emp_site='".$_REQUEST['site']."' and employment_type='".$_REQUEST['empType']."'  ORDER BY emp_name ASC";     
       $sqlExec2=DB_query($emp_query,$db);  
	 ?>
    <td class="tabledata1"><strong>Employee List</strong></td>
	<td><div id='hid_lstemp'>
	<select name="employee_code" id="employee_code"  style="width:150px;">
	<option value="">All</option>
  <?php
      while($RowData1 = DB_fetch_array($sqlExec2))
       {?>
 <option value="<?php echo $RowData1['id'];  ?>" <?php echo ($_REQUEST['employee_code']==$RowData1['id'])?'selected="selected"':''; ?>><?php echo $RowData1['emp_name']; ?></option>
  <?php } ?>
	</select>
 	</div>
	</td>
	
  </tr>
  <tr><td colspan="4"></td><td><input type="button" name="proceed" class="search" value="Search" onclick="return check_selectedEmployee()" /></td></tr>
</table>
           <br/>


<?php
if($_REQUEST['site']!='')
{

?>
<table width="100%" cellspacing="0" cellpadding="3" border="1">
        <tr class="row1">
        <td rowspan="2"><strong>Sr No.</strong></td>
        <td rowspan="2"><strong>Employee Code</strong></td>	
        <td rowspan="2"><strong>Employee Name</strong></td>        
        <td colspan="3"><center><strong>Complesation Details</strong></center></td>        
        <td  rowspan="2" colspan="2"><strong>Action</strong></td>          
           
    </tr>
     <tr class="row1">        
        <td><strong>Total</strong></td>
        <td><strong>Taken</strong></td>
        <td><strong>Pending</strong></td> 
    </tr>
    <?php   
   	//*****************************************************   Manual Adjust **********************************************************************//
    
    $daily=DB_query("select distinct(employee) as id from daily_attendance where month(attendance_date)='".$_REQUEST['month']."'
     and year(attendance_date)='".$_REQUEST['years']."' 
      and site='".$_REQUEST['site']."'",$db);
    while($row1=DB_fetch_array($daily))
    {
      $employeeid[]=$row1['id'];
    }


	$subEmpQuery='';
    if($_REQUEST['employee_code']!='')
   	$subEmpQuery=" and id='".$_REQUEST['employee_code']."'";
    $empdatesArr=array();
     $emp_query = "SELECT id,emp_name FROM empmaster WHERE CompanyId='".$_SESSION['ACGCompanyId']."' 
      AND emp_site='".$_REQUEST['site']."' ".$subEmpQuery." and employment_type='".$_REQUEST['empType']."'
        ORDER BY emp_name ASC";
     $i=0;
       $sqlExec1=DB_query($emp_query,$db); 
      while($RowData = DB_fetch_array($sqlExec1))
      {
      $processsal=$s->GetFieldValue("master_process_salary","payslip_month='".$_REQUEST['month']."' and payslip_year='".$_REQUEST['years']."'
      and emp_id='".$RowData['id']."'","id");
     if($processsal=='' && !empty($employeeid) && in_array($RowData['id'],$employeeid))
     {  

     $total_compensation=$s->GetFieldValue("attendance_complesation","month='".$_REQUEST['month']."' and year='".$_REQUEST['years']."' 
      and emp_id='".$RowData['id']."'","count(*)"); 
      $pending_compensation=$s->GetFieldValue("attendance_complesation","month='".$_REQUEST['month']."' and year='".$_REQUEST['years']."' 
      and emp_id='".$RowData['id']."' and com_status='N'","count(*)");     
      $compensation=$s->GetFieldValue("attendance_complesation","month='".$_REQUEST['month']."' and year='".$_REQUEST['years']."' 
      and emp_id='".$RowData['id']."' and com_status='Y'","count(*)");    
 
    ?>
       <tr class="row">
        <td><?php echo ($i+1); ?></td>
        <td><?php echo $s->GetFieldValue('empmaster'," id='".$RowData['id']."' " ,'emp_code'); ?></td>
        <td><?php echo $s->GetFieldValue('empmaster'," id='".$RowData['id']."' " ,'emp_name'); ?></td>
        <td><?php echo $total_compensation; ?></td>
        <td><?php echo $compensation; ?></td>
        <td><?php echo $pending_compensation; ?></td>      
        <td><?php if($pending_compensation!=0) {?>
          <a onclick="popup('comp_apply.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $RowData['id'];?>&month=<?php echo $_REQUEST['month']?>&year=<?php echo $_REQUEST['years']?>',800,400)" style="color:#FF0000;" title="Apply For Leave" href="#" >Adjust</a><?php } else { ?>No Permission<?php } ?></td>      
        <td><a onclick="popup('create_comp_apply.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $RowData['id'];?>&month=<?php echo $_REQUEST['month']?>&year=<?php echo $_REQUEST['years']?>',800,400)" style="color:#FF0000;" title="Apply For Leave" href="#" >Create Compensation</a></td> 
    </tr>    

       <?php $i++; } }  ?>
</table>
<?php }   $_SESSION['empDates']=$empdatesArr; ?>
</form></div></div>

<?php 

function getEmp_week_off($emp_id,$month,$years)
{
global $s;
 
 	$emp_weekly_off=$s->GetFieldValue('empmaster'," id='".$emp_id."' " ,'emp_weekly_off');
  /* $month=$_REQUEST['month'];
   $years=$_REQUEST['years'];
    $emp_id=$_REQUEST['employee_code'];*/
    $dateofjoining=$s->GetFieldValue('empmaster'," id='".$emp_id."' " ,'doj');
    
  //$workingdays= cal_days_in_month(CAL_GREGORIAN, $month, $years);	
 
if($month==1){ $mnthName='January';}
elseif($month==2){ $mnthName='February'; }
elseif($month==3){ $mnthName='March'; }
elseif($month==4){ $mnthName='April'; }
elseif($month==5){ $mnthName='May'; }
elseif($month==6){ $mnthName='June'; }
elseif($month==7){ $mnthName='July'; }
elseif($month==8){ $mnthName='August'; }
elseif($month==9){ $mnthName='September'; }
elseif($month==10){ $mnthName='October'; }
elseif($month==11){ $mnthName='November'; }
elseif($month==12){ $mnthName='December'; }

if($emp_weekly_off==1){ $week='Monday';}
elseif($emp_weekly_off==2){ $week='Tuesday'; }
elseif($emp_weekly_off==3){ $week='Wednesday'; }
elseif($emp_weekly_off==4){ $week='Thursday'; }
elseif($emp_weekly_off==5){ $week='Friday'; }
elseif($emp_weekly_off==6){ $week='Saturday'; }
elseif($emp_weekly_off==7){ $week='Sunday'; }
//echo $week;
$ts = strtotime($mnthName.' '.$years);
$startDate=date('Y-m-01', $ts);
$endDate=date('Y-m-t', $ts);

$startDateNew = strtotime( 'next '.$week, strtotime($startDate) );
$endDateNew=date('Y-m-d', strtotime($endDate. ' + 1 days'));
$endDateNew=strtotime($endDateNew. ' + 1 days');

// Output all Tuesdays prior to our end date
while ($startDateNew < $endDateNew) {

      $weeklypfArray[]= date('Y-m-d', $startDateNew );

    // Get next Tuesday relative to last Tuesday
    $startDateNew = strtotime( 'next '.$week, $startDateNew );
}

//print_r($weeklypfArray);
if($weeklypfArray)
{
    $_SESSION['WEEKLYOFF']=$weeklypfArray;
    $weekOffStr=implode("','", $weeklypfArray);
}
return $weekOffStr;
}
?>

