<?php
session_start();
include 'dbc.php';

date_default_timezone_set("Asia/Karachi");
$today=date("Y-m-d");
$month = date("m",strtotime($today));
		$year = date("Y",strtotime($today));
		 $month_name = date("F", mktime(0, 0, 0, $month, 10));
		 $my=$month_name . " " . $year;
$username=$_SESSION["username"];
$userid=$_SESSION["userid"];
$saldate=$_POST["saldate"];
$month_name=$_POST["month_name"];
$sess1=$_POST["sess1"];

$size = count($_POST['tdays']);
$i = 0;
while ($i < $size) {
$teacher_id= $_POST['teacher_id'][$i];
	$tech_name = $_POST['tech_name'][$i];
	 $status = $_POST['status'][$i];
	  $class_name = $_POST['class_name'][$i];
	  $monthly_salary = $_POST['monthly_salary'][$i];


	$tdays= $_POST['tdays'][$i];
	$adays = $_POST['adays'][$i];
	$perdaysal= $monthly_salary / $tdays;
	$pdays=$tdays - $adays;
	
	$absentded= $adays * $perdaysal;
	
	 $advded = $_POST['advded'][$i];
	  $secded = $_POST['secded'][$i];
	  $oded = $_POST['oded'][$i];
	 $totalded= $absentded + $advded + $secded + $oded;
	  
	  $gsalary= $monthly_salary - $totalded;
	  
	  $leaveallow = $_POST['leaveallow'][$i];
	  $dailyallow = $_POST['dailyallow'][$i];
	  $oallow = $_POST['oallow'][$i];
	  $fallow = $_POST['fallow'][$i];
	  $callow = $_POST['callow'][$i];
	  $pallow = $_POST['pallow'][$i];
	  $secret = $_POST['secret'][$i];
	  $adm_date = $_POST['adm_date'][$i];
	  $idate = $_POST['idate'][$i];
	 $totalallow= $leaveallow + $dailyallow + $oallow + $fallow + $callow + $pallow + $secret;
   
   $netsalary= $gsalary + $totalallow;			
	$sql = "Insert into paidsalary (id,date,month_name,sess1,teacher_id,tech_name,father_name,class_name,monthly_salary,tdays,adays,pdays,absentded,advded,secded,oded,totalded,gsalary,leaveallow,dailyallow,oallow,secret,totalallow,netsalary,user_id,adm_date,idate,fallow,callow,pallow,status) values (null,'$saldate','$month_name','$sess1','$teacher_id','$tech_name','$father_name','$class_name','$monthly_salary','$tdays','$adays','$pdays','$absentded','$advded','$secded','$oded','$totalded','$gsalary','$leaveallow','$dailyallow','$oallow','$secret','$totalallow','$netsalary','$userid','$adm_date','$idate','$fallow','$callow','$pallow','$status')";
$conn->query($sql);
$sql2 = "SELECT * FROM teacher where teacher_id = '$teacher_id' and  user_id='$userid'";
$result2=$conn->query($sql2);
$row2 = $result2->fetch_assoc();

$loan=$row2['loan'] ;
$security=$row2['security'] ;


$remloan= $loan - $advded;
$remsecurity= $security - $secret;
	$sql1 = "update teacher set 
loan='$remloan' , security='$remsecurity', securityded='$secded'where teacher_id='$teacher_id'";
$conn->query($sql1);
	++$i;

// do the update and print out some info just to provide some visual feedback


} 

echo "Record Update";
//echo"<td> <a href ='open_customers.php?areaname=$party_area'>Click to Main Dashboard</a>";
echo"<td> <a href ='Genrate_Salary.php'>Back</a>";
?>
