<?php
class StudentScholarshipMgmt
{
    public $studentscholarship_id;
    public $scholarship_id;
    public $college_id;
    public $semester_id;
    public $year_id;
    public $student_id;
    public $branch_id;
    public $branchyear_id;
    public $financial_year;
    public $formfill_date;
    public $scholarshipaprove_date;
    public $scholarshiprecive_date;
    public $scholarshiprecive_price;
    public $collegerecive_date;
    public $collegerecive_price;

    function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
    {
        $qry = "";
        $qry = "SELECT *,(SELECT branch_name 
             FROM cms_branchmaster sec 
             WHERE sec.college_id = '" . $_SESSION["VedantnrCollegeId"] . "' and sec.branch_id = sd.branch_id) AS branch_name,
            
			(SELECT year_name 
             FROM cms_yearmaster year 
             WHERE year.year_id = sd.year_id) AS year_name,
			 
             (SELECT scholarship_name 
             FROM scholarship_master ss
             WHERE ss.scholarship_id = sd.scholarship_id) AS scholarship_name,
			
             (SELECT 
             CONCAT(sm.student_surname , ' ' , sm.student_firstname , ' ' ,sm.student_lastname) AS student_name
             FROM cms_studentmaster sm 
             WHERE sm.college_id = '" . $_SESSION["VedantnrCollegeId"] . "' AND sm.student_id = sd.student_id) AS student_name,
			 
			 (SELECT semester_name 
             FROM cms_semestermaster sem 
             WHERE sem.college_id = '" . $_SESSION["VedantnrCollegeId"] . "' AND sem.semester_id = sd.semester_id) AS semester_name,
			 
			 (SELECT branchyear_name 
             FROM cms_branchyear bry 
             WHERE bry.college_id = '" . $_SESSION["VedantnrCollegeId"] . "' AND bry.branchyear_id = sd.branchyear_id) AS branchyear_name
             FROM 
             cms_studentscholarship sd
              WHERE 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";
        }

        $out = dbQuery($qry);

        if (dbRows($out) > 0) {
            return $out;
        }
        return $out;

    }
    function add()
    {
        global $SQLDateFormat;
        $Qry1 = "";
        $Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
        $Qry1 .= "scholarship_id='" . Escape($this->scholarship_id) . "',";
        $Qry1 .= "student_id='" . Escape($this->student_id) . "',";
        $Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
        $Qry1 .= "semester_id='" . Escape($this->semester_id) . "',";
        $Qry1 .= "year_id='" . Escape($this->year_id) . "',";
        $Qry1 .= "branchyear_id='" . Escape($this->branchyear_id) . "',";
        $Qry1 .= "financial_year='" . Escape($this->financial_year) . "',";

        $Qry1 .= "formfill_date = STR_TO_DATE('" . Escape($this->formfill_date) . "','$SQLDateFormat'),";
        $Qry1 .= "scholarshipaprove_date = STR_TO_DATE('" . Escape($this->scholarshipaprove_date) . "','$SQLDateFormat'),";
        $Qry1 .= "scholarshiprecive_date = STR_TO_DATE('" . Escape($this->scholarshiprecive_date) . "','$SQLDateFormat'),";
        $Qry1 .= "scholarshiprecive_price='" . Escape($this->scholarshiprecive_price) . "',";
        $Qry1 .= "collegerecive_date = STR_TO_DATE('" . Escape($this->collegerecive_date) . "','$SQLDateFormat'),";
        $Qry1 .= "collegerecive_price='" . Escape($this->collegerecive_price) . "',";


        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "INSERT INTO cms_studentscholarship SET " . $Qry1 . " ";

            dbQuery($qry);
            $this->studentscholarship_id = dbInsertedId();
        }
    }
    function edit()
    {
        global $SQLDateFormat;
        $Qry1 = "";
        $Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
        $Qry1 .= "scholarship_id='" . Escape($this->scholarship_id) . "',";
        $Qry1 .= "student_id='" . Escape($this->student_id) . "',";
        $Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
        $Qry1 .= "semester_id='" . Escape($this->semester_id) . "',";
        $Qry1 .= "year_id='" . Escape($this->year_id) . "',";
        $Qry1 .= "branchyear_id='" . Escape($this->branchyear_id) . "',";
        $Qry1 .= "financial_year='" . Escape($this->financial_year) . "',";
        $Qry1 .= "formfill_date = STR_TO_DATE('" . Escape($this->formfill_date) . "','$SQLDateFormat'),";
        $Qry1 .= "scholarshipaprove_date = STR_TO_DATE('" . Escape($this->scholarshipaprove_date) . "','$SQLDateFormat'),";
        $Qry1 .= "scholarshiprecive_date = STR_TO_DATE('" . Escape($this->scholarshiprecive_date) . "','$SQLDateFormat'),";
        $Qry1 .= "scholarshiprecive_price='" . Escape($this->scholarshiprecive_price) . "',";
        $Qry1 .= "collegerecive_date = STR_TO_DATE('" . Escape($this->collegerecive_date) . "','$SQLDateFormat'),";
        $Qry1 .= "collegerecive_price='" . Escape($this->collegerecive_price) . "',";


        if ($Qry1 != "") {
            $Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
            $qry = "UPDATE cms_studentscholarship SET " . $Qry1 . " 
                        WHERE studentscholarship_id ='" . Escape($this->studentscholarship_id) . "' ";
            dbQuery($qry);


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

    //report-scholarship.php
    		function getstudentscholarship($condition)
	{
		$qry = "SELECT 
			sm.student_id,
			sd.cur_semesterid,
			sd.cur_branchid,
			sd.cur_branchyearid,
			sd.year_id,
			CONCAT(student_surname,' ',student_firstname,' ',student_lastname,'') AS student_name,
			student_gturegno,
			student_category,
			sm.student_admby,
			sd.student_rollno,
			student_birthdate,
			ss.scholarship_name,
			sss.financial_year,
			sss.formfill_date,
			sss.scholarshipaprove_date,
			sss.scholarshiprecive_date,
			sss.scholarshiprecive_price,
			sss.collegerecive_date,
			sss.collegerecive_price,
			(SELECT branch_name FROM cms_branchmaster sec WHERE sec.branch_id = sd.cur_branchid) AS branch_name,
			
	  		(SELECT year_name FROM cms_yearmaster ym  WHERE ym.year_id = sd.year_id) AS year_name,
			(SELECT semester_name FROM cms_semestermaster sem  WHERE sem.semester_id = sd.cur_semesterid) AS semester_name,
			(SELECT branchyear_name FROM cms_branchyear bry 
			     WHERE   bry.branchyear_id = sd.cur_branchyearid) AS branchyear_name
		FROM
		   cms_studentscholarship sss,
			cms_studentmaster sm,
			scholarship_master ss,
			cms_studentdetail sd
			
		WHERE 
		ss.scholarship_id = sss.scholarship_id AND 
			sm.college_id  = '" . $_SESSION["VedantnrCollegeId"] . "' 
				AND sm.student_id=sd.student_id
				AND sm.student_id=sss.student_id
				AND sm.student_active= 1";
		if ($condition != "") {
			$qry .= $condition;
		}
		//echo $qry;
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}
}
?>