<?php 
require "../commonincludefiles.php";
if($_SESSION["VedantnrCollegeId"]!="" && isset($_SESSION["VedantnrCollegeId"]))
{
	$employee_id = $_REQUEST["employee_id"];
	$month_id = $_REQUEST["month_id"];
	$year_id = $_REQUEST["year"];
	
$objEmployeeSalaryMgmt = new EmployeeSalaryMgmt();
	$limit=0;
	$start=0;
	$condition=" AND es.employee_id=$employee_id AND es.year_id=$year_id AND es.month=".$month_id ;
	$order_field="es.year_id, es.month ";
	$order_type="DESC";
	$result = $objEmployeeSalaryMgmt->getAllRecords(0,0,$condition,$order_field,$order_type) ;
	$total = dbRows($result);
	$i=0;
	$salaryData = array("count" => $total, "rows" => array());
	if	(dbRows($result)==1) 
		   {
				$temparray = array();
				while($row = dbArray($result)){
					$temparray["employee_id"]  		= $row["employee_id"];
					$temparray["employeesalary_id"] = $row["employeesalary_id"];
					$temparray["month"] 	 		= $row["month"];
					$temparray["basic"]  			= $row["basic"];
					$temparray["da"]  				= $row["da"];
					$temparray["hra"] 				= $row["hra"];
					$temparray["medical_all"]  		= $row["medical_all"];
					$temparray["cla"]  				= $row["cla"];
					$temparray["pta"]  				= $row["pta"];
					$temparray["princi_all"]  		= $row["princi_all"];
					$temparray["sup_all"]  			= $row["sup_all"];
					$temparray["hs_all"]  			= $row["hs_all"];
					$temparray["wash_all"]  		= $row["wash_all"];
					$temparray["cash_all"]  		= $row["cash_all"];
					$temparray["handicap_all"]  	= $row["handicap_all"];
					$temparray["ta"]  				= $row["ta"];
					$temparray["family_all"]  		= $row["family_all"];
					$temparray["leaveencash"]  		= $row["leaveencash"];
					$temparray["ltc"]  				= $row["ltc"];
					$temparray["sp_pay"]  			= $row["sp_pay"];
					$temparray["bonus"]  			= $row["bonus"];
					$temparray["arias_all"]  		= $row["arias_all"];
					$temparray["add_da"]  			= $row["add_da"];
					$temparray["ir1"]  				= $row["ir1"];
					$temparray["oincome1"]  		= $row["oincome1"];		
					$temparray["gpf"]  				= $row["gpf"];
					$temparray["cpf"]  				= $row["cpf"];
					$temparray["gpfloan"]  			= $row["gpfloan"];
					$temparray["cpfloan"]  			= $row["cpfloan"];
					$temparray["houseloan"]  		= $row["houseloan"];
					$temparray["pftax"]  			= $row["pftax"];
					$temparray["lic"]  				= $row["lic"];
					$temparray["incometax"]  		= $row["incometax"];
					$temparray["foodadv"]  			= $row["foodadv"];
					$temparray["festadv"]  			= $row["festadv"];
					$temparray["society"]  			= $row["society"];
					$temparray["society_2"]  		= $row["society_2"];
					$temparray["pli"]  				= $row["pli"];
					$temparray["recadj"]  			= $row["recadj"];
					$temparray["groupins"]  		= $row["groupins"];
					$temparray["misec1"]  			= $row["misec1"];
					$temparray["misrec2"]  			= $row["misrec2"];
					$temparray["odeduct1"]  		= $row["odeduct1"];
					$temparray["grosspay"]  		= $row["grosspay"];
					$temparray["grossdeduction"]  	= $row["grossdeduction"];
					$temparray["netpay"]  			= $row["netpay"];
					$temparray["dpay"]  			= $row["dpay"];
					$temparray["july_increment"]  	= $row["july_increment"];
					
					$salaryData["rows"][$i] = $temparray;   
				$i++;
			}		
	}	
	else if	(dbRows($result)==0)
	{
		$limit=0;
		$start=0;
		$condition=" AND es.employee_id=$employee_id  AND es.year_id = $year_id ";
		$order_field="es.year_id, es.month ";
		$order_type="ASC";
		$result2 = $objEmployeeSalaryMgmt->getAllRecords(0,0,$condition,$order_field,$order_type) ;
		$total2 = dbRows($result2);
		$i=0;
		if	(dbRows($result2)> 0)
	   {
					$temparray = array();
					while($row = dbArray($result2)){
					$temparray["employee_id"]  		= $row["employee_id"];
					$temparray["employeesalary_id"] = $row["employeesalary_id"];
					$temparray["month"] 	 		= $row["month"];
					$temparray["basic"]  			= $row["basic"];
					$temparray["da"]  				= $row["da"];
					$temparray["hra"] 				= $row["hra"];
					$temparray["medical_all"]  		= $row["medical_all"];
					$temparray["cla"]  				= $row["cla"];
					$temparray["pta"]  				= $row["pta"];
					$temparray["princi_all"]  		= $row["princi_all"];
					$temparray["sup_all"]  			= $row["sup_all"];
					$temparray["hs_all"]  			= $row["hs_all"];
					$temparray["wash_all"]  		= $row["wash_all"];
					$temparray["cash_all"]  		= $row["cash_all"];
					$temparray["handicap_all"]  	= $row["handicap_all"];
					$temparray["ta"]  				= $row["ta"];
					$temparray["family_all"]  		= $row["family_all"];
					$temparray["leaveencash"]  		= $row["leaveencash"];
					$temparray["ltc"]  				= $row["ltc"];
					$temparray["sp_pay"]  			= $row["sp_pay"];
					$temparray["bonus"]  			= $row["bonus"];
					$temparray["arias_all"]  		= $row["arias_all"];
					$temparray["add_da"]  			= $row["add_da"];
					$temparray["ir1"]  				= $row["ir1"];
					$temparray["oincome1"]  		= $row["oincome1"];		
					$temparray["gpf"]  				= $row["gpf"];
					$temparray["cpf"]  				= $row["cpf"];
					$temparray["gpfloan"]  			= $row["gpfloan"];
					$temparray["cpfloan"]  			= $row["cpfloan"];
					$temparray["houseloan"]  		= $row["houseloan"];
					$temparray["pftax"]  			= $row["pftax"];
					$temparray["lic"]  				= $row["lic"];
					$temparray["incometax"]  		= $row["incometax"];
					$temparray["foodadv"]  			= $row["foodadv"];
					$temparray["festadv"]  			= $row["festadv"];
					$temparray["society"]  			= $row["society"];
					$temparray["society_2"]  		= $row["society_2"];
					$temparray["pli"]  				= $row["pli"];
					$temparray["recadj"]  			= $row["recadj"];
					$temparray["groupins"]  		= $row["groupins"];
					$temparray["misec1"]  			= $row["misec1"];
					$temparray["misrec2"]  			= $row["misrec2"];
					$temparray["odeduct1"]  		= $row["odeduct1"];
					$temparray["grosspay"]  		= $row["grosspay"];
					$temparray["grossdeduction"]  	= $row["grossdeduction"];
					$temparray["netpay"]  			= $row["netpay"];
					$temparray["dpay"]  			= $row["dpay"];
					$temparray["july_increment"]  	= $row["july_increment"];
					
						$salaryData["rows"][0] = $temparray;   
					
				}	
		}
		else
	{
		$limit=0;
		$start=0;
		$condition=" AND es.employee_id=$employee_id  AND es.year_id  < $year_id";
		$order_field="es.year_id, es.month ";
		$order_type="ASC";
		$result3 = $objEmployeeSalaryMgmt->getAllRecords(0,0,$condition,$order_field,$order_type) ;
		$total3 = dbRows($result3);
		$i=0;
		if	(dbRows($result3)> 0)
	   {
					$temparray = array();
					while($row = dbArray($result3)){
					$temparray["employee_id"]  		= $row["employee_id"];
					$temparray["employeesalary_id"] = $row["employeesalary_id"];
					$temparray["month"] 	 		= $row["month"];
					$temparray["basic"]  			= $row["basic"];
					$temparray["da"]  				= $row["da"];
					$temparray["hra"] 				= $row["hra"];
					$temparray["medical_all"]  		= $row["medical_all"];
					$temparray["cla"]  				= $row["cla"];
					$temparray["pta"]  				= $row["pta"];
					$temparray["princi_all"]  		= $row["princi_all"];
					$temparray["sup_all"]  			= $row["sup_all"];
					$temparray["hs_all"]  			= $row["hs_all"];
					$temparray["wash_all"]  		= $row["wash_all"];
					$temparray["cash_all"]  		= $row["cash_all"];
					$temparray["handicap_all"]  	= $row["handicap_all"];
					$temparray["ta"]  				= $row["ta"];
					$temparray["family_all"]  		= $row["family_all"];
					$temparray["leaveencash"]  		= $row["leaveencash"];
					$temparray["ltc"]  				= $row["ltc"];
					$temparray["sp_pay"]  			= $row["sp_pay"];
					$temparray["bonus"]  			= $row["bonus"];
					$temparray["arias_all"]  		= $row["arias_all"];
					$temparray["add_da"]  			= $row["add_da"];
					$temparray["ir1"]  				= $row["ir1"];
					$temparray["oincome1"]  		= $row["oincome1"];		
					$temparray["gpf"]  				= $row["gpf"];
					$temparray["cpf"]  				= $row["cpf"];
					$temparray["gpfloan"]  			= $row["gpfloan"];
					$temparray["cpfloan"]  			= $row["cpfloan"];
					$temparray["houseloan"]  		= $row["houseloan"];
					$temparray["pftax"]  			= $row["pftax"];
					$temparray["lic"]  				= $row["lic"];
					$temparray["incometax"]  		= $row["incometax"];
					$temparray["foodadv"]  			= $row["foodadv"];
					$temparray["festadv"]  			= $row["festadv"];
					$temparray["society"]  			= $row["society"];
					$temparray["society_2"]  		= $row["society_2"];
					$temparray["pli"]  				= $row["pli"];
					$temparray["recadj"]  			= $row["recadj"];
					$temparray["groupins"]  		= $row["groupins"];
					$temparray["misec1"]  			= $row["misec1"];
					$temparray["misrec2"]  			= $row["misrec2"];
					$temparray["odeduct1"]  		= $row["odeduct1"];
					$temparray["grosspay"]  		= $row["grosspay"];
					$temparray["grossdeduction"]  	= $row["grossdeduction"];
					$temparray["netpay"]  			= $row["netpay"];
					$temparray["dpay"]  			= $row["dpay"];
					$temparray["july_increment"]  	= 0;
					
						$salaryData["rows"][0] = $temparray;   
					
				}	
		}
		else
		{
		$temparray["basic"]  			= 0;
		$temparray["july_increment"] 	= 0;
		$salaryData["rows"][0] = $temparray;   
		}
	}
	}
				   		 
	echo json_encode($salaryData);										
}
else {
		echo '{"success":"false","msg":"session expiry"}';
}
?>