<? include("si_confi.php"); ?>
<? include("ad_head.php"); ?>

  <div class="container">
  
<? include("mn_option.php");
  date_default_timezone_set("Asia/Kolkata");
?>
<?

if(isset($_REQUEST['submit_emp']))
{  
     $salary=$_REQUEST['salary'];
	 $username=$_REQUEST['empid'];
	 $expl=explode(",",$username);
	 $emid=$expl[0];
	 $emname=$expl[1];
	 
	  $salary2=$_REQUEST['salary2'];
	  $advance=$_REQUEST['advance'];
	  $payable=$_REQUEST['payable'];
	  
	  if($payable>$salary2)
	  {
		   $mbaln=$payable-$salary2;
	  }
	  else
	  {
		   $mbaln=0;
	  }
	 	
	 $daset=date_default_timezone_set('Asia/Kolkata');
	 $mnth=$_REQUEST['month'];
	 $crddate=date('Y-m-d');
	 $year=date('Y');
	 
	 $mnt=mysql_query("select * from `monthlysalary` ");
	 $numr=mysql_num_rows($mnt);
	 
	 if($numr==0)
	 {
		 $numr=$numr+1;
		}
		else
		 {$numr=$numr+1;
		 
		 }
	 
	   $advance=$_REQUEST['advance'];
	   $detection=$_REQUEST['detection'];
	 
	 
 $insert_employeee_details=mysql_query("insert into `monthlysalary` (`empid`,`name`,`salary`,`amount`,`balance`,`month`,`year`,`date`,`sidd`,`detection`,`advance`)values('$emid','$emname','$salary','$salary2','$balance','$mnth','$year','$crddate','$numr','$detection','$advance')");

	 $selcmadv33=mysql_query("update `employee_mng` set `balance`='$mbaln' where emp_id='$emid'");
	 
	  $selcmadv33=mysql_query("update `advance` set `code`='1',sidd='$numr' where empid='$emid' and code='0' and status='1'");
	 
?>
<script>window.location="ad_monthlysalary.php?ad=suc";</script>
<?
}
?>
<? if($_REQUEST['ad']=='suc'){ ?>
<div class="success" style="width:92%;margin:0 auto;margin-top:9px;">Salary details added successfully...</div><? } ?>

<link type="text/css" href="calender/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="calender/jquery.min.js"></script>
<script type="text/javascript" src="calender/jquery.datepick.js"></script>
<script type="text/javascript">
$nocal=$.noConflict();
$nocal(function() {
	$nocal('#popupDatepicker').datepick();
	$nocal('#inlineDatepicker').datepick({onSelect: showDate});
});
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>
<script type="text/javascript">
$nocal(function() {
	$nocal('#popupDatepicker2').datepick();
	$nocal('#inlineDatepicker2').datepick({onSelect: showDate});
});
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>


<script type="text/javascript">
function showbrandname(str)
{
	var mnt=document.getElementById("mnt").value;
	
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHintbrand").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","advn.php?q="+str+"&mnt="+mnt,true);
xmlhttp.send();
}
</script>


   <div style="border:groove;margin-top:10px;border-width:thin;padding:20px;border-radius:4px;border-color:#cccccc;box-shadow: 10px 9px 90px #000;">
   <h2>Add Salary Details </h2>
 
  <form method="post" enctype="multipart/form-data" name="form" id="add_certi" autocomplete="off" action="<?php echo $_SERVER['PHP_SELF']; ?>">
		<script type="text/javascript" src="prototype.js"></script>
        <script type="text/javascript" src="validation.js"></script>
        <table cellpadding="9" id="add_certi">
        
        <tr>
        <td valign="top">Select Month</td>
        <td>
        <select name="month" class="validate-selection" id="mnt" autofocus>
        <option value="" hidden="">Select Month</option>
        <?  for($m=1; $m<=12; ++$m)
		{
        ?>
<option value="<?  echo date('F', mktime(0, 0, 0, $m, 1)); ?>"><? echo  date('F', mktime(0, 0, 0, $m, 1)); ?> </option>
		<? } ?>
        </select>
        </td>  
        </tr>
        
        <tr>
        <td valign="top">Employee ID</td>
        <td>
        <div  style="height:40px;">
        <select name="empid" class="validate-selection" autofocus onChange="showbrandname(this.value)"> 
        <option value="" hidden="">Select</option>
        <? $seleect_employee=mysql_query("select * from `employee_mng`");
		while($fetch_employee=mysql_fetch_array($seleect_employee)){  ?>
        <option value="<? echo $fetch_employee['emp_id']; ?>,<? echo $fetch_employee['name']; ?>">
        <? echo ucwords($fetch_employee['name']); ?> - <? echo ucwords($fetch_employee['emp_id']); ?>
        </option>
		<? } ?>
        </select>
        </div>
        <div id="txtHintbrand"> </div>
        </td>  
        </tr>
        
        <tr>
        <td valign="top">Salary</td>
        <td><input type="text" name="salary2" class="required" ></td>
        </tr>
        <!-- <tr>
        <td valign="top">Time</td>
        <td><input type="text" name="time_allocation" value="<? echo date("g:i a"); ?>" readonly style="background:#CCC;" class="required"></td>
        </tr>-->
        <td valign="top">&nbsp;</td>
        <td><input type="submit" name="submit_emp" onClick="return confirm('Are you sure you want to confirm add Details ?');"></td>
        </tr>
        </table>
			
		</form>
         <script type="text/javascript">
						function formCallback(result, form) 
						{window.status = "valiation callback for form '" + form.id + "': result = " + result;}
						var valid = new Validation('add_certi', {immediate : true, onFormValidate : formCallback});
					</script>
  </div>
</div><!-- container -->
  </body>
</html>