<?php
class FeessetupMgmt
{
	public $setup_id;
	public $semester_id;
	public $head_id;
	public $college_id;
	public $fees_amount;
	public $year_id;

	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{

		$qry = "SELECT 
						fs.*,
						fh.head_name,
						fs.branch_id,
						fs.semester_id,
				fs.branchyear_id,
				fs.year_id,
				(SELECT branch_name FROM cms_branchmaster bm 
				WHERE bm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and fs.branch_id = bm.branch_id) AS branch_name,
	  		  	(SELECT year_name  FROM cms_yearmaster ym 
			     WHERE fs.year_id=ym.year_id ) AS year_name,
				 (SELECT semester_name FROM cms_semestermaster sm 
			     WHERE sm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND fs.semester_id = sm.semester_id ) AS semester_name,
				 (SELECT branchyear_name FROM cms_branchyear bry   
				WHERE  bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND fs.branchyear_id=bry.branchyear_id ) AS branchyear_name
					FROM 
						cms_feessetup fs,
						cms_feeshead fh
					WHERE 
						fs.head_id = fh.head_id AND
						fs.college_id = " . $_SESSION['VedantnrCollegeId'];

		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);


		return $out;
	}

	function add()
	{
		$Qry1 = "";

		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
		$Qry1 .= "year_id='" . Escape($this->year_id) . "',";
		$Qry1 .= "branchyear_id='" . Escape($this->branchyear_id) . "',";
		$Qry1 .= "semester_id='" . Escape($this->semester_id) . "',";
		$Qry1 .= "head_id='" . Escape($this->head_id) . "',";
		$Qry1 .= "fees_amount='" . Escape($this->fees_amount) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "login_id='" . Escape($_SESSION['aUserId']) . "',";
		$Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "insert into cms_feessetup set " . $Qry1 . " ";
			dbQuery($qry);
			$this->setup_id = dbInsertedId();
		}
	}

	function edit()
	{
		$Qry1 = "";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
		$Qry1 .= "year_id='" . Escape($this->year_id) . "',";
		$Qry1 .= "branchyear_id='" . Escape($this->branchyear_id) . "',";
		$Qry1 .= "semester_id='" . Escape($this->semester_id) . "',";
		$Qry1 .= "head_id='" . Escape($this->head_id) . "',";
		$Qry1 .= "fees_amount='" . Escape($this->fees_amount) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "login_id='" . Escape($_SESSION['aUserId']) . "',";
		$Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "update cms_feessetup set " . $Qry1 . " where setup_id=" . $this->setup_id;
			dbQuery($qry);
		}
	}

	function delete()
	{
		$qry = "delete from cms_feessetup where setup_id in (" . $this->setup_id . ") ";
		dbQuery($qry);
	}



	function getStudentSemester($semester_id)
	{


		$qry = "SELECT semester_id FROM cms_feessetup WHERE semester_id = $semester_id ";
		//echo $qry;
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}



	function getStudenthead($head_id)
	{

		$qry = "SELECT head_id FROM cms_feessetup WHERE head_id = $head_id "; //echo $qry;
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}


	function getStudentsetup($setup_id)
	{

		$qry = "
			SELECT
				frd.head_id
			FROM
				cms_feesreceivemaster frm,
				cms_feesreceivedetail frd,
				cms_feessetup fs
			WHERE
				fs.head_id = frd.head_id AND
				fs.semester_id = frm.semester_id AND
				frm.feesreceive_id = frd.feesreceive_id AND
				fs.setup_id = $setup_id";
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}

	function getfeessetup($head_name,$semester_name,$setup_id)
	{

		$qry ="SELECT * FROM cms_feessetup WHERE semester_id = '$semester_name' AND 
			              head_id = '$head_name' AND setup_id != '$setup_id' ";
		
		//echo $qry;
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}
}
?>