<?php
class StudentFeesRecDetailMgmt
{
	public $feesreceivedetail_id;
	public $feesreceive_id;
	public $college_id;
	public $head_id;
	public $recdetail_amt;
	public $login_id;
	public $createdon;

	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$this->feesrec_count = 0;

		$qry = "SELECT sf.*,sd.* FROM cms_feeshead sf,cms_feesreceivedetail sd
				where sd.college_id= '" . $_SESSION["VedantnrCollegeId"] . "' 
				and sf.head_id = sd.head_id 
				and sf.college_id = sd.college_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->feesrec_count = dbRows($out);
			return $out;
		}

		return $out;
	}

	function add()
	{
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "feesreceive_id='" . Escape($this->feesreceive_id) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "head_id='" . Escape($this->head_id) . "',";
		$Qry1 .= "recdetail_amt='" . Escape($this->recdetail_amt) . "',";
		$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_feesreceivedetail set " . $Qry1 . " ";
			//	echo $qry;
			dbQuery($qry);
			$this->feesrec_id = dbInsertedId();
		}
	}

	function edit()
	{
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "feesreceive_id='" . Escape($this->feesreceive_id) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
			$Qry1 .= "head_id='"		.Escape($this->head_id)."',";		
		$Qry1 .= "recdetail_amt='" . Escape($this->recdetail_amt) . "',";
		$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_feesreceivedetail set " . $Qry1 . " where feesreceive_id=" . $this->feesreceive_id;
			dbQuery($qry);
		}
	}

	function delete()
	{
		$qry = "delete from  cms_feesreceivedetail 
             	where feesreceive_id  in (" . $this->feesreceive_id . ") 
				and college_id='" . $_SESSION["VedantnrCollegeId"] . "'";

		dbQuery($qry);
	}
	function getRecivedfees($student_id,$head_id, $condition)
	{
		$qry = "";
		/* start new try */

		$qry = "SELECT SUM(frd.recdetail_amt) AS recdetail_amt FROM cms_feesreceivemaster fm ,cms_feesreceivedetail frd WHERE fm.feesreceive_id = frd.feesreceive_id and fm.student_id = $student_id and frd.head_id = '$head_id'";

		if ($condition != "") {
			$qry .= $condition;
		}
		//echo $qry;
		$out = dbQuery($qry);
		return $out;
	}
	function getStudenthead($head_id)
	{

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