<?php
/**
 * This is a class file used for Student operations.
 *
 * PHP version 5
 *
 * @category Admin_Tool
 * @package  Admin_Tool
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  CVS:1.0.1
 * @link     http://auminfosys.com/
 * @filesource
 */

/**
 * This is a class named StudentMgt.
 *
 * @category School Management System
 * @package  School Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */

class EmployeeSalaryMgmt
{

	/**
	 * @var public $employeesalary_id This is the employeesalary Id feteched from the database(sms_employeesalary).
	 */
	public $employeesalary_id;
	/**
	 * @var public $employee_id This is the employee Id feteched from the database(sms_employeemaster).
	 */
	public $employee_id;

	/**
	 * @var public $school_id This is the School Id feteched from the database(sms_employeesalary).
	 */
	public $school_id;

	/**
	 * @var public $year_id This is the session year .
	 */
	public $year_id;

	/**
	 * @var public $month This is the month of salary.
	 */
	public $month;

	/**
	 * @var public $salarydate This is the date of salary entry.
	 */
	public $salarydate;

	/**
	 * @var public $basic This is the basic salary.
	 */
	public $basic;

	//////Incomes

	/**
	 * @var public $da This is the daily Allowance.
	 */
	public $da;

	/**
	 * @var public $hra This is the House Rent Allowance.
	 */
	public $hra;

	/**
	 * @var public $medical_all This is the Medical Allowance.
	 */
	public $medical_all;

	/**
	 * @var public $cla This is  Allowance.
	 */
	public $cla;

	/**
	 * @var public $pta This is the  Allowance.
	 */
	public $pta;

	/**
	 * @var public $princi_all This is principal  Allowance.
	 */
	public $princi_all;

	/**
	 * @var public $sup_all This is the  Allowance.
	 */
	public $sup_all;

	/**
	 * @var public $hs_all This is the  Allowance.
	 */
	public $hs_all;

	/**
	 * @var public $wash_all This is the Allowance.
	 */
	public $wash_all;

	/**
	 * @var public $cash_all This is the cash Allowance.
	 */
	public $cash_all;

	/**
	 * @var public $handicap_all This is the handicap Allowance.
	 */
	public $handicap_all;

	/**
	 * @var public $ta This is the tour Allowance.
	 */
	public $ta;

	/**
	 * @var public $family_all This is the family Allowance.
	 */
	public $family_all;

	/**
	 * @var public $leaveencash This is the leave Encashment
	 */
	public $leaveencash;

	/**
	 * @var public $ltc This is the LTC  Allowance.
	 */
	public $ltc;

	/**
	 * @var public $sp_pay This is the  Allowance.
	 */
	public $sp_pay;

	/**
	 * @var public $bonus This is the bonus.
	 */
	public $bonus;

	/**
	 * @var public $arias_all This is the ariers.
	 */
	public $arias_all;

	/**
	 * @var public $add_da This is the additional daily Allowance.
	 */
	public $add_da;


	/**
	 * @var public $ir1 This is the  Allowance.
	 */
	public $ir1;


	/**
	 * @var public $oincome1 This is the other Income
	 */
	public $oincome1;


	////////////// Deductions

	/**
	 * @var public $gpf This is the General Provident Fund.
	 */
	public $gpf;

	/**
	 * @var public $cpf This is the CP Fund.
	 */
	public $cpf;

	/**
	 * @var public $gpfloan This is the GPF loan installment.
	 */
	public $gpfloan;

	/**
	 * @var public $cpfloan This is the CPF loan installment.
	 */
	public $cpfloan;

	/**
	 * @var public $houseloan This is the House loan installment.
	 */
	public $houseloan;

	/**
	 * @var public $pftax This is the Professional Tax.
	 */
	public $pftax;

	/**
	 * @var public $lic This is the Life Insurance Installment.
	 */
	public $lic;

	/**
	 * @var public $incometax This is the Income Tax.
	 */
	public $incometax;

	/**
	 * @var public $foodadv This is the Advances.
	 */
	public $foodadv;

	/**
	 * @var public $festadv This is the Festival Advances.
	 */
	public $festadv;

	/**
	 * @var public $society This is the society installment.
	 */
	public $society;

	/**
	 * @var public $society_2 This is the society installment.
	 */
	public $society_2;

	/**
	 * @var public $pli This is the PLI
	 */
	public $pli;

	/**
	 * @var public $recadj.
	 */
	public $recadj;

	/**
	 * @var public $groupins This is the Group Insurance.
	 */
	public $groupins;

	/**
	 * @var public $misec1.
	 */
	public $misec1;

	/**
	 * @var public $misrec2.
	 */
	public $misrec2;

	/**
	 * @var public $odeduct1 This is the other Deductions.
	 */
	public $odeduct1;

	/**
	 * @var public $grosspay This is the Gross pay.
	 */
	public $grosspay;

	/**
	 * @var public $grossdeduction This is the Gross Deductions.
	 */
	public $grossdeduction;

	/**
	 * @var public $netpay This is the Net Pay.
	 */
	public $netpay;

	/**
	 * @var public $dpay This is the D Pay.
	 */
	public $dpay;

	/**
	 * @var public $login_id This is the creator's id
	 */
	public $login_id;

	/**
	 * @var public $createdon This is the employeesalary created on.
	 */
	public $createdon;

	/**
	 * @var public $employeesalary_count This is a counter.
	 */
	public $employeesalary_count;
	/**
	 * @var public $deleteEmployeeSalary_Id List of Id's to be deleted.
	 */
	public $deleteEmployeeSalary_Id;
	/**
	 * @var public $bullet This is bullet.
	 */
	public $bullet;

	/**
	 * Constructor to inialize employeesalary_count to zero
	 *
	 */
	function EmployeeSalaryMgmt()
	{
		$this->bullet = "<font size='2'>&raquo;</font>";
		$this->bullet = htmlentities($this->bullet);
		$this->employeesalary_count = 0;
	}

	/**
	 * This function is used to get a particular record.
	 *
	 * @param integer $page_id This is the database banner id.
	 *
	 * @return array
	 */
	function getRecordById($employee_id)
	{
		$qry = "select * from cms_employeesalary where school_id= '" . $_SESSION["VedantnrSchoolId"] . "'";

		if ($employee_id != "") {
			$qry .= " and employee_id=$employee_id ";
		}

		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			$this->employeesalary_count = 1;

			$row = dbArray($out);
			extract($row);
			$this->employeesalary_id = ($employeesalary_id);
			$this->employee_id = ($employee_id);
			$this->school_id = ($school_id);
			$this->year_id = ($year_id);
			$this->month = ($month);
			$this->salarydate = ($salarydate);
			$this->basic = ($basic);
			$this->da = ($da);
			$this->hra = ($hra);
			$this->medical_all = ($medical_all);
			$this->cla = ($cla);
			$this->pta = ($pta);
			$this->princi_all = ($princi_all);
			$this->sup_all = ($sup_all);
			$this->hs_all = ($hs_all);
			$this->wash_all = ($wash_all);
			$this->cash_all = ($cash_all);
			$this->handicap_all = ($handicap_all);
			$this->ta = ($ta);
			$this->family_all = ($family_all);
			$this->leaveencash = ($leaveencash);
			$this->ltc = ($ltc);
			$this->sp_pay = ($sp_pay);
			$this->bonus = ($bonus);
			$this->arias_all = ($arias_all);
			$this->add_da = ($add_da);
			$this->ir1 = ($ir1);
			$this->oincome1 = ($oincome1);
			$this->gpf = ($gpf);
			$this->cpf = ($cpf);
			$this->gpfloan = ($gpfloan);
			$this->cpfloan = ($cpfloan);
			$this->houseloan = ($houseloan);
			$this->pftax = ($pftax);
			$this->lic = ($lic);
			$this->incometax = ($incometax);
			$this->foodadv = ($foodadv);
			$this->festadv = ($festadv);
			$this->society = ($society);
			$this->society_2 = ($society_2);
			$this->pli = ($pli);
			$this->recadj = ($recadj);
			$this->groupins = ($groupins);
			$this->misec1 = ($misec1);
			$this->misrec2 = ($misrec2);
			$this->odeduct1 = ($odeduct1);
			$this->grosspay = ($grosspay);
			$this->grossdeduction = ($grossdeduction);
			$this->netpay = ($netpay);
			$this->dpay = ($dpay);
			$this->july_increment = ($july_increment);
			$this->login_id = ($login_id);
			$this->createdon = ($createdon);

			dbResult($out);
		}
	}

	/**
	 * This is a function for getting the total no of records with/without condition
	 *
	 * @param integer $limit This is the limit of number or records.
	 * @param integer $start This is the starting location of records.
	 * @param string  $condition This is the condition for fetching records.	 
	 * @param string  $order_field This is the field for fetching records orderby.	 
	 * @param string  $order_type This is the order direction to fetch records orderby.	 	 
	 *
	 * @return Total Records Found
	 */
	function getCountRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$this->employeesalary_count = 0;

		$qry = "SELECT Count(*) AS Count FROM cms_employeesalary where school_id= '" . $_SESSION["VedantnrSchoolId"] . "' ";

		if ($condition != "") {
			$qry .= $condition;
		}

		if ($order_field != "" && $order_type != "") {
			$qry .= " order by $order_field $order_type";
		}

		if (intval($limit) > 0 && intval($start) >= 0) {
			$qry .= " Limit $start , $limit";
		}
		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			$row = dbArray($out);
			extract($row);
			$this->employeesalary_count = $Count;
			dbResult($out);
		}
		return $this->employeesalary_count;
	}

	/**
	 * This is a function for getting the all records with/without condition
	 *
	 * @param integer $limit This is the limit of number or records.
	 * @param integer $start This is the starting location of records.
	 * @param string  $condition This is the condition for fetching records.	 
	 * @param string  $order_field This is the field for fetching records orderby.	 
	 * @param string  $order_type This is the order direction to fetch records orderby.	 	 
	 *
	 * @return Mix Result Set
	 */
	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$this->employeesalary_count = 0;

		$qry = "SELECT es.*,em.* 
				FROM cms_employeesalary es,cms_employeemaster as em 
				WHERE es.employee_id=em.employee_id  ";

		if ($condition != "") {
			$qry .= $condition;
		}

		if ($order_field != "" && $order_type != "") {
			$qry .= " order by $order_field $order_type";
		}

		if (intval($limit) > 0 && intval($start) >= 0) {
			$qry .= " Limit $start , $limit";
		}
		//echo $qry; 
		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			$this->employeesalary_count = dbRows($out);
			return $out;
		}

		return $out;
	}

	/**
	 * This is a function for getting the all records with/without condition
	 *
	 * @param integer $limit This is the limit of number or records.
	 * @param integer $start This is the starting location of records.
	 * @param string  $condition This is the condition for fetching records.	 
	 * @param string  $order_field This is the field for fetching records orderby.	 
	 * @param string  $order_type This is the order direction to fetch records orderby.	 	 
	 *
	 * @return Mix Result Set
	 */
	function getAllEmployeesalaryRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$this->employeesalary_count = 0;

		$qry = "SELECT  em.employee_name,em.employee_schooljoindate,
					 (SELECT sd.designation_nameeng 
					 FROM cms_designation sd 
					 WHERE sd.designation_id=em.employee_designation ) AS employee_designation,
					 em.employee_no,
					 es.*		 
				  FROM cms_employeesalary es, 
					   cms_employeemaster em 
				  WHERE es.college_id='" . $_SESSION["VedantnrCollegeId"] . "'  and 					
						em.college_id= '" . $_SESSION["VedantnrCollegeId"] . "' and					
						es.employee_id = em.employee_id  ";

		if ($condition != "") {
			$qry .= $condition;
		}

		if ($order_field != "" && $order_type != "") {
			$qry .= " order by $order_field $order_type";
		}

		if (intval($limit) > 0 && intval($start) >= 0) {
			$qry .= " Limit $start , $limit";
		}
		// echo $qry; exit;

		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			$this->employeesalary_count = dbRows($out);
			return $out;
		}

		return $out;
	}



	/**
	 * This is a function for adding new record for Student.
	 *
	 * @return void The redirect file name and the message are passed.
	 *
	 */
	function add()
	{


		$Qry1 = "";

		$Qry1 .= "employee_id='" . Escape($this->employee_id) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "year_id='" . Escape($this->year_id) . "',";
		$Qry1 .= "month='" . Escape($this->month) . "',";
		$Qry1 .= "totaldays='" . Escape($this->totaldays) . "',";
		$Qry1 .= "presentdays='" . Escape($this->presentdays) . "',";

		$Qry1 .= "salarydate='" . Escape($this->salarydate) . "',";
		$Qry1 .= "basic='" . Escape($this->basic) . "',";
		$Qry1 .= "da='" . Escape($this->da) . "',";
		$Qry1 .= "hra='" . Escape($this->hra) . "',";

		$Qry1 .= "medical_all='" . Escape($this->medical_all) . "',";
		$Qry1 .= "cla='" . Escape($this->cla) . "',";

		$Qry1 .= "pta='" . Escape($this->pta) . "',";
		$Qry1 .= "princi_all='" . Escape($this->princi_all) . "',";
		$Qry1 .= "july_increment='" . Escape($this->july_increment) . "',";
		$Qry1 .= "sup_all='" . Escape($this->sup_all) . "',";
		$Qry1 .= "hs_all='" . Escape($this->hs_all) . "',";
		$Qry1 .= "wash_all='" . Escape($this->wash_all) . "',";
		$Qry1 .= "cash_all='" . Escape($this->cash_all) . "',";
		$Qry1 .= "handicap_all='" . Escape($this->handicap_all) . "',";

		$Qry1 .= "ta='" . Escape($this->ta) . "',";
		$Qry1 .= "family_all='" . Escape($this->family_all) . "',";

		$Qry1 .= "leaveencash='" . Escape($this->leaveencash) . "',";
		$Qry1 .= "ltc='" . Escape($this->ltc) . "',";
		$Qry1 .= "sp_pay='" . Escape($this->sp_pay) . "',";
		$Qry1 .= "bonus='" . Escape($this->bonus) . "',";
		$Qry1 .= "arias_all='" . Escape($this->arias_all) . "',";
		$Qry1 .= "add_da='" . Escape($this->add_da) . "',";

		$Qry1 .= "ir1='" . Escape($this->ir1) . "',";
		$Qry1 .= "oincome1='" . Escape($this->oincome1) . "',";
		$Qry1 .= "gpf='" . Escape($this->gpf) . "',";
		$Qry1 .= "cpf='" . Escape($this->cpf) . "',";
		$Qry1 .= "gpfloan='" . Escape($this->gpfloan) . "',";

		$Qry1 .= "cpfloan='" . Escape($this->cpfloan) . "',";
		$Qry1 .= "houseloan='" . Escape($this->houseloan) . "',";

		$Qry1 .= "pftax='" . Escape($this->pftax) . "',";
		$Qry1 .= "lic='" . Escape($this->lic) . "',";
		$Qry1 .= "incometax='" . Escape($this->incometax) . "',";
		$Qry1 .= "foodadv='" . Escape($this->foodadv) . "',";

		$Qry1 .= "festadv='" . Escape($this->festadv) . "',";
		$Qry1 .= "society='" . Escape($this->society) . "',";
		$Qry1 .= "society_2='" . Escape($this->society_2) . "',";
		$Qry1 .= "pli='" . Escape($this->pli) . "',";

		$Qry1 .= "recadj='" . Escape($this->recadj) . "',";
		$Qry1 .= "groupins='" . Escape($this->groupins) . "',";
		$Qry1 .= "misec1='" . Escape($this->misec1) . "',";
		$Qry1 .= "misrec2='" . Escape($this->misrec2) . "',";
		$Qry1 .= "odeduct1='" . Escape($this->odeduct1) . "',";

		$Qry1 .= "grosspay='" . Escape($this->grosspay) . "',";
		$Qry1 .= "grossdeduction='" . Escape($this->grossdeduction) . "',";
		$Qry1 .= "netpay='" . Escape($this->netpay) . "',";

		$Qry1 .= "dpay='" . Escape($this->dpay) . "',";

		$Qry1 .= "login_id='" . Escape($_SESSION['aUserId']) . "',";
		$Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";
		$Qry1 .= "blnBackup = '0',";

		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "insert into cms_employeesalary set " . $Qry1 . " ";

			//   echo $qry; exit;
			dbQuery($qry);
			$this->employeesalary_id = dbInsertedId();
		}
	}


	function edit()
	{

		$Qry1 = "";

		$Qry1 .= "employee_id='" . Escape($this->employee_id) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "year_id='" . Escape($this->year_id) . "',";
		$Qry1 .= "month='" . Escape($this->month) . "',";
		$Qry1 .= "totaldays='" . Escape($this->totaldays) . "',";
		$Qry1 .= "presentdays='" . Escape($this->presentdays) . "',";
		
		$Qry1 .= "salarydate='" . Escape($this->salarydate) . "',";
		$Qry1 .= "basic='" . Escape($this->basic) . "',";
		$Qry1 .= "da='" . Escape($this->da) . "',";
		$Qry1 .= "hra='" . Escape($this->hra) . "',";

		$Qry1 .= "medical_all='" . Escape($this->medical_all) . "',";
		$Qry1 .= "cla='" . Escape($this->cla) . "',";
		$Qry1 .= "pta='" . Escape($this->pta) . "',";
		$Qry1 .= "princi_all='" . Escape($this->princi_all) . "',";
		$Qry1 .= "july_increment='" . Escape($this->july_increment) . "',";
		$Qry1 .= "sup_all='" . Escape($this->sup_all) . "',";
		$Qry1 .= "hs_all='" . Escape($this->hs_all) . "',";
		$Qry1 .= "wash_all='" . Escape($this->wash_all) . "',";
		$Qry1 .= "cash_all='" . Escape($this->cash_all) . "',";
		$Qry1 .= "handicap_all='" . Escape($this->handicap_all) . "',";

		$Qry1 .= "ta='" . Escape($this->ta) . "',";
		$Qry1 .= "family_all='" . Escape($this->family_all) . "',";

		$Qry1 .= "leaveencash='" . Escape($this->leaveencash) . "',";
		$Qry1 .= "ltc='" . Escape($this->ltc) . "',";
		$Qry1 .= "sp_pay='" . Escape($this->sp_pay) . "',";
		$Qry1 .= "bonus='" . Escape($this->bonus) . "',";

		$Qry1 .= "arias_all='" . Escape($this->arias_all) . "',";
		$Qry1 .= "add_da='" . Escape($this->add_da) . "',";


		$Qry1 .= "ir1='" . Escape($this->ir1) . "',";
		$Qry1 .= "oincome1='" . Escape($this->oincome1) . "',";
		$Qry1 .= "gpf='" . Escape($this->gpf) . "',";
		$Qry1 .= "cpf='" . Escape($this->cpf) . "',";
		$Qry1 .= "gpfloan='" . Escape($this->gpfloan) . "',";

		$Qry1 .= "cpfloan='" . Escape($this->cpfloan) . "',";
		$Qry1 .= "houseloan='" . Escape($this->houseloan) . "',";

		$Qry1 .= "pftax='" . Escape($this->pftax) . "',";
		$Qry1 .= "lic='" . Escape($this->lic) . "',";
		$Qry1 .= "incometax='" . Escape($this->incometax) . "',";
		$Qry1 .= "foodadv='" . Escape($this->foodadv) . "',";

		$Qry1 .= "festadv='" . Escape($this->festadv) . "',";
		$Qry1 .= "society='" . Escape($this->society) . "',";
		$Qry1 .= "society_2='" . Escape($this->society_2) . "',";
		$Qry1 .= "pli='" . Escape($this->pli) . "',";

		$Qry1 .= "recadj='" . Escape($this->recadj) . "',";
		$Qry1 .= "groupins='" . Escape($this->groupins) . "',";
		$Qry1 .= "misec1='" . Escape($this->misec1) . "',";
		$Qry1 .= "misrec2='" . Escape($this->misrec2) . "',";
		$Qry1 .= "odeduct1='" . Escape($this->odeduct1) . "',";

		$Qry1 .= "grosspay='" . Escape($this->grosspay) . "',";
		$Qry1 .= "grossdeduction='" . Escape($this->grossdeduction) . "',";
		$Qry1 .= "netpay='" . Escape($this->netpay) . "',";

		$Qry1 .= "login_id='" . Escape($_SESSION['aUserId']) . "',";
		$Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";
		$Qry1 .= "blnBackup = '0',";

		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "update cms_employeesalary set " . $Qry1 . " where employeesalary_id=" . $this->employeesalary_id;
			dbQuery($qry);
		}
	}

	/**
	 * This is a function for deleting the Student record.
	 *
	 * @return void The redirect file name and the message are passed.
	 *
	 */
	function delete()
	{
		$qry = "delete from  cms_employeesalary 
             	where employeesalary_id in (" . $this->deleteEmployeeSalary_Id . ") 
				and college_id='" . $_SESSION["VedantnrCollegeId"] . "'";
		dbQuery($qry);

	}

	function GetSalaryDetail($employee_id, $head, $year, $month)
	{
		$total = 0;
		$netPay = 0;
		$qry = "SELECT $head, netpay
			  		FROM cms_employeesalary es 
					where es.college_id= '" . $_SESSION["VedantnrCollegeId"] . "' AND 
							es.year_id= '" . $year . "'  AND 
							es.employee_id= '" . $employee_id . "'  AND 
							es.month= '" . $month . "' ";

		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			while ($row = dbArray($out)) {
				$total = $row["$head"];
				$netPay = $row["netpay"];
			}
			dbResult($out);
		}

		return $total . "," . $netPay;
	}

//report-form-employee-salary-slip-monthwise-result.php
	function getAllEmployeesalary($condition)	{
	
		$qry = "SELECT  
	 				em.*,
					es.*  ,
					  bm.branch_id,ed.*,
					ps.*  
					  
				  FROM cms_employeesalary es, 
					   cms_employeemaster em, 
				  	cms_designation ed,
				  	cms_branchmaster bm,
				  	cms_payscalemaster  ps
				  
				  WHERE es.college_id='1' and 					
						em.college_id= '1' and
						bm.branch_id=em.branch_id and
						ps. payscale_id =em.employee_payscale and
						ed.designation_id = em.employee_designation and		
						es.employee_id = em.employee_id "; 

		if ($condition != "") {
			$qry .= $condition;
		}

		
		// echo $qry; exit;

		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			$this->employeesalary_count = dbRows($out);
			return $out;
		}

		return $out;
	}

}
?>