<?php
    require "commonincludefiles.php";
		     
	if ($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])) {



$objEmployeeSalaryMgmt = new EmployeeSalaryMgmt();
$condition = "";
	if( $_REQUEST["employee_id"] != "")
	{$condition = " AND em.employee_id = ".$_REQUEST["employee_id"];}
	if( $_REQUEST["Year"] != "")
	{$condition .= " AND year_id = year_id";}
	if( $_REQUEST["month_id"] != "")
	{$condition .= " AND month = ".$_REQUEST["month_id"];}$temparray = array();
	 $result = $objEmployeeSalaryMgmt -> getAllRecords(0,0,$condition,"","");
	if	(dbRows($result)>0) 
		   {
				$temparray = array();
				while($row = dbArray($result)){
					$temparray["employeesalary_id"] = $row["employeesalary_id"];
				}
	}     
		    $objEmployeeSalaryMgmt->employee_id 		= $_REQUEST["employee_id"];
			$objEmployeeSalaryMgmt->year_id		= $_REQUEST["Year"];
			$objEmployeeSalaryMgmt->employeesalary_id = $temparray["employeesalary_id"];// 		= $_REQUEST["employeesalary_id"];
			$objEmployeeSalaryMgmt->month 			= $_REQUEST["month_id"];
			$objEmployeeSalaryMgmt->totaldays 			= $_REQUEST["totaldays"];
			$objEmployeeSalaryMgmt->presentdays 			= $_REQUEST["presentdays"];
			$objEmployeeSalaryMgmt->salarydate 		= $_REQUEST["Year"]."-".$_REQUEST["month_id"]."-"."01";
			$objEmployeeSalaryMgmt->basic 			= $_REQUEST["Basic"];
			$objEmployeeSalaryMgmt->da 				= $_REQUEST["DA"];
			$objEmployeeSalaryMgmt->hra 				= $_REQUEST["HRA"];
			$objEmployeeSalaryMgmt->medical_all 		= $_REQUEST["Medical"];
			$objEmployeeSalaryMgmt->cla 				= $_REQUEST["CCA/CLA"];
			$objEmployeeSalaryMgmt->pta 				= $_REQUEST["PTA"];
			$objEmployeeSalaryMgmt->princi_all 		= $_REQUEST["Principal_All"];
			$objEmployeeSalaryMgmt->sup_all 			= $_REQUEST["Supervisor_All"];
			$objEmployeeSalaryMgmt->hs_all 			= $_REQUEST["H_S_All"];
			$objEmployeeSalaryMgmt->wash_all 		= $_REQUEST["Wash_All"];
			$objEmployeeSalaryMgmt->cash_all 		= $_REQUEST["Cash_All"];
			$objEmployeeSalaryMgmt->handicap_all 	= $_REQUEST["Handicap_All"];
			$objEmployeeSalaryMgmt->ta 				= $_REQUEST["Transport_All"];
			$objEmployeeSalaryMgmt->family_all 		= $_REQUEST["All/Family_Planning"];
			$objEmployeeSalaryMgmt->leaveencash 		= $_REQUEST["Leave_Encash"];
			$objEmployeeSalaryMgmt->ltc 				= $_REQUEST["LTC"];
			$objEmployeeSalaryMgmt->sp_pay 			= $_REQUEST["Special_Pay"];
			$objEmployeeSalaryMgmt->bonus 			= $_REQUEST["Bonus"];
			$objEmployeeSalaryMgmt->arias_all 		= $_REQUEST["Arias"];
			$objEmployeeSalaryMgmt->add_da			= $_REQUEST["Additional_DA"];
			$objEmployeeSalaryMgmt->ir1				= $_REQUEST["IR"];
			$objEmployeeSalaryMgmt->oincome1			= $_REQUEST["Other"];
			$objEmployeeSalaryMgmt->gpf 				= $_REQUEST["GPF"];
			$objEmployeeSalaryMgmt->cpf 				= $_REQUEST["CPF"];
			$objEmployeeSalaryMgmt->gpfloan 			= $_REQUEST["GPF_Loan"];
			$objEmployeeSalaryMgmt->cpfloan 			= $_REQUEST["CPF_Loan"];
			$objEmployeeSalaryMgmt->houseloan 		= $_REQUEST["House_Loan"];
			$objEmployeeSalaryMgmt->pftax 			= $_REQUEST["Prof_Tax"];
			$objEmployeeSalaryMgmt->lic 				= $_REQUEST["LIC"];
			$objEmployeeSalaryMgmt->incometax 		= $_REQUEST["Income_Tax"];
			$objEmployeeSalaryMgmt->foodadv 			= $_REQUEST["Food_Adv"];
			$objEmployeeSalaryMgmt->festadv 			= $_REQUEST["Fest_Adv"];	
			$objEmployeeSalaryMgmt->society 			= $_REQUEST["Society"];
			$objEmployeeSalaryMgmt->society_2		= $_REQUEST["Society-2"];
			$objEmployeeSalaryMgmt->pli 				= $_REQUEST["PLI"];
			$objEmployeeSalaryMgmt->recadj 			= $_REQUEST["Recovery"];
			$objEmployeeSalaryMgmt->groupins 		= $_REQUEST["Group_Ins"];
			$objEmployeeSalaryMgmt->misec1 			= $_REQUEST["Mis_Rec_-1"];
			$objEmployeeSalaryMgmt->misrec2 			= $_REQUEST["Mis_Rec_-2"];
			$objEmployeeSalaryMgmt->odeduct1 		= $_REQUEST["OtherD"];
			$objEmployeeSalaryMgmt->grosspay 		= $_REQUEST["Gross_Income"];
			$objEmployeeSalaryMgmt->grossdeduction	= $_REQUEST["Gross_Deduction"];
			$objEmployeeSalaryMgmt->netpay 			= $_REQUEST["Net_Income"];
			$objEmployeeSalaryMgmt->dpay 			= $_REQUEST["Grade_Pay/Dp"];
			if($_REQUEST["month_id"] == 7)
			{
				$objEmployeeSalaryMgmt->july_increment	= $_REQUEST["julycount"];
				if($_REQUEST["julycount"] == 1)
				{
					$objEmployeeMgmt = new EmployeeMgmt();
					$objEmployeeMgmt->employee_id			  =	$_REQUEST['employee_id'];	
					$objEmployeeMgmt->employee_basicsalary			  =	$_REQUEST["Basic"];
					$objEmployeeMgmt->collehe_id 			  = $_SESSION['VedantnrCollegeId'];
					$objEmployeeMgmt -> updateBasic();
				}
			}
			else
			$objEmployeeSalaryMgmt->july_increment	= 0;
		if(	$objEmployeeSalaryMgmt->employeesalary_id=="") {
			// Add Part
				$objEmployeeSalaryMgmt->add();
			
			if(	$objEmployeeSalaryMgmt->employeesalary_id==0) {
				echo '{"success":"false","msg":"duplicate"}';		
			} else {
				echo '{"success":"true","msg":""}';	
			}		
		}
		else{
			// Edit Part
			$objEmployeeSalaryMgmt->edit();
			echo '{"success":"true","msg":""}';
		}
} 
else {
		echo '{"success":"false","msg":"session expiry"}';
}
?>