GIF89a; CRX
KBHT HEHE
Server IP : 172.26.0.195  /  Your IP : 18.119.125.240
Web Server : Apache
System : Linux 43-205-77-33.cprapid.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User : jnclnmuac ( 1026)
PHP Version : 8.0.30
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/jnclnmuac/public_html/web/../web/cgi-bin/../../cas/application/models/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jnclnmuac/public_html/web/../web/cgi-bin/../../cas/application/models/admin/FeeManagement.php
<?php

/**
 * Model For Handling All DB Operations Related To Fee
 *
 * @author Softpro India Pvt. Ltd.
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class FeeManagement extends CI_Model {

    function createNewFeeHead(array $newFeeHeadInfo) {
        $this->db->insert('fee_heads_mst', $newFeeHeadInfo);
        return $this->db->insert_id();
    }

    function getAllFeeHeads() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_mst FHM');
        $this->db->join('tbl_staff_members TSMA', 'FHM.fhm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FHM.fhm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->order_by("FHM.fhm_updated_on", "desc");
        return $this->db->get();
    }

    function getNonDeletedFeeHeads() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_mst FHM');
        $this->db->join('tbl_staff_members TSMA', 'FHM.fhm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FHM.fhm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHM.fhm_delete_status", "F");
        $this->db->order_by("FHM.fhm_name", "ASC");
        return $this->db->get();
    }

    function getFeeHeadInfoBy($fhm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_mst THM');
        $this->db->join('tbl_staff_members TSMA', 'THM.fhm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'THM.fhm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("THM.fhm_id", $fhm_id);
        return $this->db->get();
    }

    function getFeeHeadInfoByName($fhm_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_mst THM');
        $this->db->join('tbl_staff_members TSMA', 'THM.fhm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'THM.fhm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("THM.fhm_name", $fhm_name);
        return $this->db->get();
    }

    function getFeeHeadInfoByShortName($fhm_short_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_mst THM');
        $this->db->join('tbl_staff_members TSMA', 'THM.fhm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'THM.fhm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("THM.fhm_short_name", $fhm_short_name);
        return $this->db->get();
    }

    function isFeeHeadNameSafeUpdate($fhm_id, $fhm_name) {
        $this->db->select("*");
        $this->db->from('fee_heads_mst');
        $this->db->where('fhm_name', $fhm_name);
        $this->db->where('fhm_id != ' . $fhm_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function isFeeHeadShortNameSafeUpdate($fhm_id, $fhm_short_name) {
        $this->db->select("*");
        $this->db->from('fee_heads_mst');
        $this->db->where('fhm_short_name', $fhm_short_name);
        $this->db->where('fhm_id != ' . $fhm_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function updateFeeHeadInfo(array $feeHeadUpdatedInfo) {
        $this->db->where('fhm_id', $feeHeadUpdatedInfo['fhm_id']);
        return $this->db->update('fee_heads_mst', $feeHeadUpdatedInfo);
    }

    /* Functions For Optional Fee Heads */

    function createNewOptionalFeeHead(array $newOptionalFeeHeadInfo) {
        $this->db->insert('fee_heads_opt_mst', $newOptionalFeeHeadInfo);
        return $this->db->insert_id();
    }

    function getAllOptionalFeeHeads() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_opt_mst FHOM');
        $this->db->join('tbl_staff_members TSMA', 'FHOM.fhom_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FHOM.fhom_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->order_by("FHOM.fhom_updated_on", "desc");
        return $this->db->get();
    }

    function getNonDeletedOptionalFeeHeads() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_opt_mst FHOM');
        $this->db->join('tbl_staff_members TSMA', 'FHOM.fhom_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FHOM.fhom_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHOM.fhom_delete_status", "F");
        $this->db->order_by("FHOM.fhom_name", "ASC");
        return $this->db->get();
    }

    function getOptionalFeeHeadInfoBy($fhom_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_opt_mst FHOM');
        $this->db->join('tbl_staff_members TSMA', 'FHOM.fhom_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FHOM.fhom_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHOM.fhom_id", $fhom_id);
        return $this->db->get();
    }

    function getOptionalFeeHeadInfoByName($fhom_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_opt_mst FHOM');
        $this->db->join('tbl_staff_members TSMA', 'FHOM.fhom_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FHOM.fhom_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHOM.fhom_name", $fhom_name);
        return $this->db->get();
    }

    function getOptionalFeeHeadInfoByShortName($fhom_short_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_opt_mst FHOM');
        $this->db->join('tbl_staff_members TSMA', 'FHOM.fhom_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FHOM.fhom_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHOM.fhom_short_name", $fhom_short_name);
        return $this->db->get();
    }

    function isOptionalFeeHeadNameSafeUpdate($fhom_id, $fhom_name) {
        $this->db->select("*");
        $this->db->from('fee_heads_opt_mst');
        $this->db->where('fhom_name', $fhom_name);
        $this->db->where('fhom_id != ' . $fhom_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function isOptionalFeeHeadShortNameSafeUpdate($fhom_id, $fhom_short_name) {
        $this->db->select("*");
        $this->db->from('fee_heads_opt_mst');
        $this->db->where('fhom_short_name', $fhom_short_name);
        $this->db->where('fhom_id != ' . $fhom_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function updateOptionalFeeHeadInfo(array $feeHeadUpdatedInfo) {
        $this->db->where('fhom_id', $feeHeadUpdatedInfo['fhom_id']);
        return $this->db->update('fee_heads_opt_mst', $feeHeadUpdatedInfo);
    }

    /* Functions For Fee Structure */

    function createNewFeeStructureInfoMulti(array $newFeeStructureInfoBatch) {
        $this->db->insert_batch('fee_structure_mst', $newFeeStructureInfoBatch);
        return $this->db->insert_id();
    }

    function getAllFeeStructure() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_mst FSM');
        $this->db->join('tbl_course_master TCM', 'FSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'FSM.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_course_sub_master TCSM', 'TUCSM.sub_course_id = TCSM.tcsm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSM.fsm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSM.fsm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FSM.fsm_delete_status", "F");
        $this->db->order_by("FSM.fsm_added_on", "desc");
        return $this->db->get();
    }

    function getFeeStructureInfoById($fsm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_mst FSM');
        $this->db->join('tbl_course_master TCM', 'FSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'FSM.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_course_sub_master TCSM', 'TUCSM.sub_course_id = TCSM.tcsm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSSM.fssm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSSM.fssm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FSM.fsm_id", $fsm_id);
        return $this->db->get();
    }

    function getFeeStructureByCourseAndSession($course, $session, $ucsMapId = '', $semester = '', $category = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_mst FSM');
        $this->db->join('tbl_course_master TCM', 'FSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSM.fsm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSM.fsm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FSM.fsm_delete_status", "F");
        $this->db->where("FSM.course_id", $course);
        $this->db->where("FSM.session_id", $session);
        if ($ucsMapId != '') {
            $this->db->where("FSM.ucs_map_id", $ucsMapId);
        }
        if ($semester != '') {
            $this->db->where("FSM.fsm_semester", $semester);
        }
        if ($category != '') {
            $this->db->where("FSM.fsm_category", $category);
        }
        $this->db->order_by("FSM.fsm_semester", "ASC");
        return $this->db->get();
    }

    function getFeeStructureInfoBy($feeHead, $session, $ucsMapId, $semester, $category = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_mst FSM');
        $this->db->join('tbl_course_master TCM', 'FSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSM.fsm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSM.fsm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHM.fhm_id", $feeHead);
        $this->db->where("FSM.session_id", $session);
        $this->db->where("FSM.ucs_map_id", $ucsMapId);
        $this->db->where("FSM.fsm_semester", $semester);
        if ($category != '') {
            $this->db->where("FSM.fsm_category", $category);
        }
        $this->db->where("FSM.fsm_delete_status", "F");
        $this->db->order_by("FSM.fsm_updated_on", "desc");
        return $this->db->get();
    }

    function getFeeStructureForFeePaymentBy($session = '', $ucsMapId = '', $semester = '', $category = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_mst FSM');
        $this->db->join('tbl_course_master TCM', 'FSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSM.fsm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSM.fsm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        if ($session != '') {
            $this->db->where("FSM.session_id", $session);
        }
        if ($ucsMapId != '') {
            $this->db->where("FSM.ucs_map_id", $ucsMapId);
        }
        if ($semester != '') {
            $this->db->where("FSM.fsm_semester", $semester);
        }
        if ($category != '') {
            $this->db->where("FSM.fsm_category", $category);
        }
        $this->db->where("FSM.fsm_active_status", "T");
        $this->db->where("FSM.fsm_delete_status", "F");
        $this->db->where("FHM.fhm_active_status", "T");
        $this->db->where("FHM.fhm_delete_status", "F");
        $this->db->order_by("FSM.fsm_semester", "ASC");
        $this->db->order_by("FHM.fhm_id", "ASC");
        return $this->db->get();
    }

    function updateFeeStructureInfoMulti(array $feeStructureUpdateInfoBatch) {
        return $this->db->update_batch('fee_structure_mst', $feeStructureUpdateInfoBatch, 'fsm_id');
    }

    function setFeeStructureToDeletedInfoBy($session, $course, $semester, $category) {
        $this->db->where('session_id', $session);
        $this->db->where('course_id', $course);
        $this->db->where('fsm_semester', $semester);
        $this->db->where('fsm_category', $category);
        return $this->db->update('fee_structure_mst', array('fsm_delete_status' => 'T'));
    }

    /* Functions For Fee Structure (Student Specific) */

    function createNewFeeStructureOfStudentMulti(array $newStudentFeeStructureInfoBatch) {
        $this->db->insert_batch('fee_structure_student_mst', $newStudentFeeStructureInfoBatch);
        return $this->db->insert_id();
    }

    function getFeeStructureOfStudentBy($tspi_id, $semesterOrYear = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_student_mst FSSM');
        $this->db->join('tbl_course_master TCM', 'FSSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'FSSM.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_course_sub_master TCSM', 'TUCSM.sub_course_id = TCSM.tcsm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSSM.fssm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSSM.fssm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FSSM.fssm_delete_status", "F");
        $this->db->where("FSSM.tspi_id", $tspi_id);
        if (trim($semesterOrYear) != '') {
            $this->db->where("FSSM.fssm_semester", $semesterOrYear);
        }
        $this->db->order_by("FSSM.fssm_semester", "ASC");
        $this->db->order_by("FHM.fhm_id", "ASC");
        return $this->db->get();
    }

    function getFeeStructureDetailsOfStudentById($fssm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_student_mst FSSM');
        $this->db->join('tbl_course_master TCM', 'FSSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'FSSM.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_course_sub_master TCSM', 'TUCSM.sub_course_id = TCSM.tcsm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSSM.fssm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSSM.fssm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FSSM.fssm_id", $fssm_id);
        return $this->db->get();
    }

    function getFeeStructureDetailsOfStudentBy($tspi_id, $feeHead, $session, $ucsMapId, $semester) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_student_mst FSSM');
        $this->db->join('tbl_course_master TCM', 'FSSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSSM.fssm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSSM.fssm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHM.fhm_id", $feeHead);
        $this->db->where("FSSM.session_id", $session);
        $this->db->where("FSSM.ucs_map_id", $ucsMapId);
        $this->db->where("FSSM.fssm_semester", $semester);
        $this->db->where("FSSM.tspi_id", $tspi_id);
        $this->db->where("FSSM.fssm_delete_status", "F");
        $this->db->order_by("FSSM.fssm_updated_on", "desc");
        return $this->db->get();
    }

    function getFeeStructureOfStudentForFeePaymentBy($tspi_id, $session = '', $ucsMapId = '', $semester = '') {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_student_mst FSSM');
        $this->db->join('tbl_course_master TCM', 'FSSM.course_id = TCM.course_id');
        $this->db->join('tbl_session_master TSM', 'FSSM.session_id = TSM.session_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('tbl_staff_members TSMA', 'FSSM.fssm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSSM.fssm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        if ($session != '') {
            $this->db->where("FSSM.session_id", $session);
        }
        if ($ucsMapId != '') {
            $this->db->where("FSSM.ucs_map_id", $ucsMapId);
        }
        if ($semester != '') {
            $this->db->where("FSSM.fssm_semester", $semester);
        }
        $this->db->where("FSSM.tspi_id", $tspi_id);
        $this->db->where("FSSM.fssm_active_status", "T");
        $this->db->where("FSSM.fssm_delete_status", "F");
        $this->db->where("FHM.fhm_active_status", "T");
        $this->db->where("FHM.fhm_delete_status", "F");
        $this->db->order_by("FSSM.fssm_semester", "ASC");
        $this->db->order_by("FHM.fhm_id", "ASC");
        return $this->db->get();
    }

    function updateFeeStructureOfStudentMulti(array $studentFeeStructureUpdateInfoBatch) {
        return $this->db->update_batch('fee_structure_student_mst', $studentFeeStructureUpdateInfoBatch, 'fssm_id');
    }

    /* Functions For Fee Structure (Optional) */

    function createNewOptionalFeeStructureInfoMulti(array $newOptionalFeeStructureInfoBatch) {
        $this->db->insert_batch('fee_structure_opt_mst', $newOptionalFeeStructureInfoBatch);
        return $this->db->insert_id();
    }

    function getAllOptionalFeeStructure() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_opt_mst FSOM');
        $this->db->join('tbl_session_master TSM', 'FSOM.session_id = TSM.session_id');
        $this->db->join('fee_heads_opt_mst FHOM', 'FSOM.fhom_id = FHOM.fhom_id');
        $this->db->join('tbl_staff_members TSMA', 'FSOM.fsom_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSOM.fsom_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FSOM.fsom_delete_status", "F");
        $this->db->order_by("FSOM.fsom_updated_on", "desc");
        return $this->db->get();
    }

    function getOptionalFeeStructureInfoBy($optionalFeeHead, $session) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_structure_opt_mst FSOM');
        $this->db->join('tbl_session_master TSM', 'FSOM.session_id = TSM.session_id');
        $this->db->join('fee_heads_opt_mst FHOM', 'FSOM.fhom_id = FHOM.fhom_id');
        $this->db->join('tbl_staff_members TSMA', 'FSOM.fsom_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FSOM.fsom_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHOM.fhom_id", $optionalFeeHead);
        $this->db->where("FSOM.session_id", $session);
        $this->db->where("FSOM.fsom_delete_status", "F");
        $this->db->order_by("FSOM.fsom_updated_on", "desc");
        return $this->db->get();
    }

    function setOptionalFeeStructureToDeletedInfoBy($session) {
        $this->db->where('session_id', $session);
        return $this->db->update('fee_structure_opt_mst', array('fsom_delete_status' => 'T'));
    }

    function updateOptionalFeeStructureInfoMulti(array $studentOptionalFeeStructureUpdateInfoBatch) {
        return $this->db->update_batch('fee_structure_opt_mst', $studentOptionalFeeStructureUpdateInfoBatch, 'fsom_id');
    }

    /* Functions For Fee Modes And Related Stuffs */

    function createNewFeeMode(array $newFeeHeadInfo) {
        $this->db->insert('fee_modes_mst', $newFeeHeadInfo);
        return $this->db->insert_id();
    }

    function getAllFeeModes() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_modes_mst FMM');
        $this->db->join('tbl_staff_members TSMA', 'FMM.fmm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FMM.fmm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->order_by("FMM.fmm_updated_on", "desc");
        return $this->db->get();
    }

    function getNonDeletedActiveFeeModes() {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_modes_mst FMM');
        $this->db->join('tbl_staff_members TSMA', 'FMM.fmm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FMM.fmm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FMM.fmm_active_status", "T");
        $this->db->where("FMM.fmm_delete_status", "F");
        $this->db->order_by("FMM.fmm_short_name", "ASC");
        return $this->db->get();
    }

    function getFeeModeInfoBy($fmm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_modes_mst FMM');
        $this->db->join('tbl_staff_members TSMA', 'FMM.fmm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FMM.fmm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FMM.fmm_id", $fmm_id);
        return $this->db->get();
    }

    function getFeeModeInfoByName($fmm_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_modes_mst FMM');
        $this->db->join('tbl_staff_members TSMA', 'FMM.fmm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FMM.fmm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FMM.fmm_name", $fmm_name);
        return $this->db->get();
    }

    function getFeeModeInfoByShortName($fmm_short_name) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_modes_mst FMM');
        $this->db->join('tbl_staff_members TSMA', 'FMM.fmm_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FMM.fmm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FMM.fmm_short_name", $fmm_short_name);
        return $this->db->get();
    }

    function isFeeModeNameSafeUpdate($fmm_id, $fmm_name) {
        $this->db->select("*");
        $this->db->from('fee_modes_mst');
        $this->db->where('fmm_name', $fmm_name);
        $this->db->where('fmm_id != ' . $fmm_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function isFeeModeShortNameSafeUpdate($fmm_id, $fmm_short_name) {
        $this->db->select("*");
        $this->db->from('fee_modes_mst');
        $this->db->where('fmm_short_name', $fmm_short_name);
        $this->db->where('fmm_id != ' . $fmm_id);
        $result = $this->db->get()->result();
        if (sizeof($result)) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function updateFeeModeInfo(array $feeModeUpdatedInfo) {
        $this->db->where('fmm_id', $feeModeUpdatedInfo['fmm_id']);
        return $this->db->update('fee_modes_mst', $feeModeUpdatedInfo);
    }

    /* Functions For Fee Collection */

    function createFeeCollectionInfoMulti(array $newFeeCollectionInfoBatch) {
        $this->db->insert_batch('fee_collection_mst', $newFeeCollectionInfoBatch);
        return $this->db->insert_id();
    }

    function getPaidFeeDetailsByReceipt($frm_id) {
        $this->db->select("*");
        $this->db->from('fee_collection_mst FCM');
        $this->db->join('fee_structure_student_mst FSSM', 'FCM.fssm_id = FSSM.fssm_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('fee_modes_mst FMM', 'FCM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_mst FRM', 'FCM.frm_id = FRM.frm_id');
        $this->db->join('tbl_session_master TSM', 'FCM.session_id = TSM.session_id');
        $this->db->where('FRM.frm_id', $frm_id);
        return $this->db->get();
    }

    function getPaidFeeDetailsBy($tspi_id, $semester) {
        $this->db->select("*");
        $this->db->from('fee_collection_mst FCM');
        $this->db->join('fee_structure_student_mst FSSM', 'FCM.fssm_id = FSSM.fssm_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('fee_modes_mst FMM', 'FCM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_mst FRM', 'FCM.frm_id = FRM.frm_id');
        $this->db->where('FRM.frm_status', "A");
        $this->db->where('FCM.tspi_id', $tspi_id);
        $this->db->where('FCM.fcm_semester', $semester);
        return $this->db->get();
    }

    function getPaidFeeDetailsByStructure($tspi_id, $semester, $fssm_id) {
        $this->db->select("*");
        $this->db->from('fee_collection_mst FCM');
        $this->db->join('fee_structure_student_mst FSSM', 'FCM.fssm_id = FSSM.fssm_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('fee_modes_mst FMM', 'FCM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_mst FRM', 'FCM.frm_id = FRM.frm_id');
        $this->db->where('FRM.frm_status', "A");
        $this->db->where('FSSM.fssm_id', $fssm_id);
        $this->db->where('FCM.tspi_id', $tspi_id);
        $this->db->where('FCM.fcm_semester', $semester);
        return $this->db->get();
    }

    function getAllPaidFeeDetailsBy($tspi_id) {
        $this->db->select("*");
        $this->db->from('fee_collection_mst FCM');
        $this->db->join('fee_structure_student_mst FSSM', 'FCM.fssm_id = FSSM.fssm_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('fee_modes_mst FMM', 'FCM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_mst FRM', 'FCM.frm_id = FRM.frm_id');
        $this->db->where('FCM.tspi_id', $tspi_id);
        $this->db->where('FRM.frm_status', "A");
        $this->db->order_by('FCM.fcm_semester', 'ASC');
        return $this->db->get();
    }

    /* Functions For Fee Receipts */

    function createNewReceipt(array $newReceiptInfo) {
        $this->db->insert('fee_receipt_mst', $newReceiptInfo);
        return $this->db->insert_id();
    }

    function getFeeReceiptInfoById($frm_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_receipt_mst FRM');
        $this->db->join('tbl_staff_members TSMA', 'FRM.frm_generated_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FRM.frm_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where('FRM.frm_id', $frm_id);
        return $this->db->get();
    }

    function getFeeReceiptInfoBy($receipt_number = '', $formEnrollRollNumber = '', $course = '', $session = '', $ucs_map_id = '') {
        $this->db->select("*");
        $this->db->from('fee_collection_mst FCM');
        $this->db->join('fee_structure_student_mst FSSM', 'FCM.fssm_id = FSSM.fssm_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('fee_modes_mst FMM', 'FCM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_mst FRM', 'FCM.frm_id = FRM.frm_id');
        $this->db->join('tbl_student_personal_info TSPI', 'FCM.tspi_id = TSPI.tspi_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'TSPI.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_session_master TSM', 'TUCSM.session_id = TSM.session_id');
        $this->db->join('tbl_course_sub_master TSCM', 'TUCSM.sub_course_id = TSCM.tcsm_id');
        $this->db->join('tbl_course_master TCM', 'TSCM.course_id = TCM.course_id');
        $this->db->order_by("FRM.frm_generated_on", "DESC");
        //$this->db->group_by("FRM.frm_receipt_no");
        if ($receipt_number != "") {
            $this->db->where('FRM.frm_receipt_no', $receipt_number);
        }
        if ($formEnrollRollNumber != "") {
            $this->db->where("(TSPI.tspi_form_no = '" . $formEnrollRollNumber . "' OR TSPI.tspi_enrollment_no = '" . $formEnrollRollNumber . "' OR TSPI.tspi_rollNumber = '" . $formEnrollRollNumber . "')");
        }
        if ($course != "") {
            $this->db->where("TCM.course_id", $course);
        }
        if ($session != "") {
            $this->db->where("TSM.session_id", $session);
        }
        if ($ucs_map_id != "") {
            $this->db->where("TSPI.ucs_map_id", $ucs_map_id);
        }
        return $this->db->get();
    }

    function updateFeeReceiptInfo(array $feeReceiptUpdatedInfo) {
        $this->db->where('frm_id', $feeReceiptUpdatedInfo['frm_id']);
        return $this->db->update('fee_receipt_mst', $feeReceiptUpdatedInfo);
    }

    /* Functions For Councelling Fee */

    function createNewCouncellingFee(array $newCouncellingFeeInfo) {
        $this->db->insert('fee_councelling_mst', $newCouncellingFeeInfo);
        return $this->db->insert_id();
    }

    function getPaidCouncellingFeeDetailsByStudent($tspi_id) {
        $this->db->select("*");
        $this->db->from('fee_councelling_mst FCNM');
        $this->db->join('fee_modes_mst FMM', 'FCNM.fcnm_mode = FMM.fmm_id');
        $this->db->join('fee_receipt_mst FRM', 'FCNM.frm_id = FRM.frm_id');
        $this->db->where('FCNM.fcnm_status', "A");
        $this->db->where('FCNM.tspi_id', $tspi_id);
        return $this->db->get();
    }

    function getPaidCouncellingFeeDetailsBy($frm_id) {
        $this->db->select("*");
        $this->db->from('fee_councelling_mst FCNM');
        $this->db->join('fee_modes_mst FMM', 'FCNM.fcnm_mode = FMM.fmm_id');
        $this->db->join('fee_receipt_mst FRM', 'FCNM.frm_id = FRM.frm_id');
        $this->db->where('FCNM.fcnm_status', "A");
        $this->db->where('FCNM.frm_id', $frm_id);
        return $this->db->get();
    }

    function updateCounsellingFeeInfo(array $cousellingFeeUpdatedInfo) {
        $this->db->where('fcnm_id', $cousellingFeeUpdatedInfo['fcnm_id']);
        return $this->db->update('fee_councelling_mst', $cousellingFeeUpdatedInfo);
    }

    function updateCounsellingFeeInfoMulti(array $studentCounsellingFeeUpdateInfoBatch) {
        return $this->db->update_batch('fee_councelling_mst', $studentCounsellingFeeUpdateInfoBatch, 'fcnm_id');
    }

    /* Functions For Optional Fee Collection (Hostel) */

    function createNewOptionalReceipt(array $newReceiptInfo) {
        $this->db->insert('fee_receipt_opt_mst', $newReceiptInfo);
        return $this->db->insert_id();
    }

    function getNonDeletedOptionalFeeHeadsBy($fhom_type) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_heads_opt_mst FHOM');
        $this->db->join('tbl_staff_members TSMA', 'FHOM.fhom_added_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FHOM.fhom_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where("FHOM.fhom_delete_status", "F");
        $this->db->where("FHOM.fhom_type", $fhom_type);
        $this->db->order_by("FHOM.fhom_name", "ASC");
        return $this->db->get();
    }

    function getAllPaidFeesByFormNumber($formEnrlRollNo) {
        $this->db->select('*');
        $this->db->from('fee_collection_opt_mst FCOM');
        $this->db->join('fee_receipt_opt_mst FROM', "FROM.from_id=FCOM.from_id");
        $this->db->join('tbl_student_personal_info TSPI', 'TSPI.tspi_id=FCOM.tspi_id');
        $this->db->where("(TSPI.tspi_form_no = '" . $formEnrlRollNo . "' OR TSPI.tspi_rollNumber = '" . $formEnrlRollNo . "' OR TSPI.tspi_enrollment_no = '" . $formEnrlRollNo . "')");
        $this->db->where("FROM.from_status", "A");
        return $this->db->get();
    }

    function getPaidAndHeadFees($formEnrlRollNo) {
        $this->db->select('*');
        $this->db->from('fee_collection_opt_mst FCOM');
        $this->db->join('fee_receipt_opt_mst FROM', "FROM.from_id=FCOM.from_id");
        $this->db->join('fee_structure_opt_mst FSOM', 'FCOM.fsom_id=FSOM.fsom_id');
        $this->db->join('fee_heads_opt_mst FHOM', 'FHOM.fhom_id=FSOM.fhom_id');
        $this->db->join('tbl_student_personal_info TSPI', 'TSPI.tspi_id=FCOM.tspi_id');
        $this->db->where("( TSPI.tspi_form_no = '" . $formEnrlRollNo . "' OR TSPI.tspi_rollNumber = '" . $formEnrlRollNo . "' OR TSPI.tspi_enrollment_no = '" . $formEnrlRollNo . "')");
        $this->db->where("FROM.from_status", "A");
        return $this->db->get();
    }

    function updateOptionalFeeReceiptInfo(array $feeReceiptUpdatedInfo) {
        $this->db->where('from_id', $feeReceiptUpdatedInfo['from_id']);
        return $this->db->update('fee_receipt_opt_mst', $feeReceiptUpdatedInfo);
    }

    function createOptionalFeeCollectionInfo(array $newFeeCollectionInfoBatch) {
        $this->db->insert('fee_collection_opt_mst', $newFeeCollectionInfoBatch);
        return $this->db->insert_id();
    }

    /* Functions For Reporting */

    function getMiscellaneousFeeReport($receipt_number = '', $formEnrollRollNumber = '', $payment_mode = '', $fee_head = '', $course = '', $session = '', $ucsMapId = '', $collected_for_session = '', $operator = '', $startDate = '', $endDate = '', $rangeAppliedwith = '') {
        $this->db->select("*");
        $this->db->from('fee_collection_mst FCM');
        $this->db->join('fee_structure_student_mst FSSM', 'FCM.fssm_id = FSSM.fssm_id');
        $this->db->join('fee_heads_mst FHM', 'FSSM.fhm_id = FHM.fhm_id');
        $this->db->join('fee_modes_mst FMM', 'FCM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_mst FRM', 'FCM.frm_id = FRM.frm_id');
        $this->db->join('tbl_student_personal_info TSPI', 'FCM.tspi_id = TSPI.tspi_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'TSPI.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_session_master TSM', 'TUCSM.session_id = TSM.session_id');
        $this->db->join('tbl_course_sub_master TSCM', 'TUCSM.sub_course_id = TSCM.tcsm_id');
        $this->db->join('tbl_course_master TCM', 'TSCM.course_id = TCM.course_id');
        $this->db->where("FRM.frm_receipt_no LIKE '%" . $receipt_number . "%'");
        $this->db->where("(TSPI.tspi_form_no LIKE '%" . $formEnrollRollNumber . "%' OR TSPI.tspi_enrollment_no LIKE '%" . $formEnrollRollNumber . "%' OR TSPI.tspi_rollNumber LIKE '%" . $formEnrollRollNumber . "%')");
        /* Payment Mode Wise Filter */
        if ($payment_mode != '') {
            $this->db->where("FMM.fmm_id", $payment_mode);
        }
        /* Payment Mode Wise Filter */
        /* Fee Head Wise Filter */
        if ($fee_head != '') {
            $this->db->where("FHM.fhm_id", $fee_head);
        }
        /* Fee Head Wise Filter */
        /* Course/Session/Entry Type Combination */
        if ($ucsMapId != '') {
            $this->db->where("TUCSM.ucs_map_id", $ucsMapId);
        } else if ($course != '' && $session != '' && $ucsMapId == '') {
            $this->db->where("TCM.course_id", $course);
            $this->db->where("TSM.session_id", $session);
        } else if ($course != '' && $session == '' && $ucsMapId == '') {
            $this->db->where("TCM.course_id", $course);
        } else if ($course == '' && $session != '' && $ucsMapId == '') {
            $this->db->where("TSM.session_id", $session);
        }
        /* Course/Session/Entry Type Combination */
        /* Collection For Session Filter */
        if ($collected_for_session != '') {
            $this->db->where("FCM.session_id", $collected_for_session);
        }
        /* Collection For Session Filter */
        /* Collected By Operator Wise Filter */
        if ($operator != '') {
            $this->db->where("FRM.frm_generated_by =" . $operator);
        }
        /* Collected By Operator Wise Filter */
        /* Dates Combination */
        if ($startDate != '' && $endDate != '' && $rangeAppliedwith != '') {
            if ($rangeAppliedwith == "RCTDT") {
                $this->db->where("FRM.frm_receipt_date >= '" . $startDate . "' && FRM.frm_receipt_date <= '" . $endDate . "'");
            } else {
                $this->db->where("FRM.frm_generated_on >= '" . $startDate . "' && FRM.frm_generated_on <= '" . $endDate . "'");
            }
        } else if ($startDate == '' && $endDate != '' && $rangeAppliedwith != '') {
            if ($rangeAppliedwith == "RCTDT") {
                $this->db->where("FRM.frm_receipt_date <= '" . $endDate . "'");
            } else {
                $this->db->where("FRM.frm_generated_on <= '" . $endDate . "'");
            }
        } else if ($startDate != '' && $endDate == '' && $rangeAppliedwith != '') {
            if ($rangeAppliedwith == "RCTDT") {
                $this->db->where("FRM.frm_receipt_date >= '" . $startDate . "'");
            } else {
                $this->db->where("FRM.frm_generated_on >= '" . $startDate . "'");
            }
        }
        /* Dates Combination */
        return $this->db->get();
    }

    function getReimbursementCounsellingFeeReport($collected_for_session = '', $course = '', $cancelStatus = '', $if_reimbursed = '') {
        $this->db->select("*");
        $this->db->from('fee_councelling_mst FCNM');
        $this->db->join('fee_receipt_mst FRM', 'FCNM.frm_id = FRM.frm_id');
        $this->db->join('fee_modes_mst FMM', 'FCNM.fcnm_mode = FMM.fmm_id');
        $this->db->join('tbl_student_personal_info TSPI', 'FCNM.tspi_id = TSPI.tspi_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'TSPI.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_session_master TSM', 'TUCSM.session_id = TSM.session_id');
        $this->db->join('tbl_course_sub_master TSCM', 'TUCSM.sub_course_id = TSCM.tcsm_id');
        $this->db->join('tbl_course_master TCM', 'TSCM.course_id = TCM.course_id');
        /* Collection For Session Filter */
        if ($collected_for_session != '') {
            $this->db->where("FCNM.frm_id IN (SELECT DISTINCT(frm_id) FROM fee_collection_mst FCM WHERE session_id = " . $collected_for_session . ")");
        }
        /* Collection For Session Filter */
        /* Course Filter */
        if ($course != '') {
            $this->db->where("TCM.course_id", $course);
        }
        /* Course Filter */
        /* Cancel Status */
        if ($cancelStatus != '') {
            $this->db->where("FCNM.fcnm_status", $cancelStatus);
        }
        /* Cancel Status */
        /* If Reimbursed */
        if ($if_reimbursed != '') {
            if ($if_reimbursed == 'T') {
                $this->db->where("FCNM.fcnm_rem_date IS NOT NULL");
            } else {
                $this->db->where("FCNM.fcnm_rem_date IS NULL");
            }
        }
        /* If Reimbursed */
        $this->db->order_by("FCNM.fcnm_added_on", "DESC");
        return $this->db->get();
    }

    /* Function For Hostel Fee Receipt And Related Stuffs */

    function getHostelFeeReceiptInfoById($from_id) {
        $this->db->select("*,"
                . "CONCAT(TPRFLA.tprfl_firstname,' ',TPRFLA.tprfl_lastname) addedByAdmin,"
                . "CONCAT(TPRFLU.tprfl_firstname,' ',TPRFLU.tprfl_lastname) updatedByAdmin");
        $this->db->from('fee_receipt_opt_mst FROM');
        $this->db->join('tbl_staff_members TSMA', 'FROM.from_generated_by = TSMA.smember_id');
        $this->db->join('tbl_profile TPRFLA', 'TSMA.smember_id = TPRFLA.tprfl_id');
        $this->db->join('tbl_staff_members TSMU', 'FROM.from_updated_by = TSMU.smember_id');
        $this->db->join('tbl_profile TPRFLU', 'TSMU.smember_id = TPRFLU.tprfl_id');
        $this->db->where('FROM.from_id', $from_id);
        return $this->db->get();
    }

    function getPaidHostelFeeDetailsByReceipt($from_id) {
        $this->db->select("*");
        $this->db->from('fee_collection_opt_mst FCOM');
        $this->db->join('fee_structure_opt_mst FSOM', 'FCOM.fsom_id = FSOM.fsom_id');
        $this->db->join('fee_heads_opt_mst FHOM', 'FSOM.fhom_id = FHOM.fhom_id');
        $this->db->join('fee_modes_mst FMM', 'FCOM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_opt_mst FROM', 'FCOM.from_id = FROM.from_id');
        $this->db->join('tbl_session_master TSM', 'FROM.session_id = TSM.session_id');
        $this->db->where('FROM.from_id', $from_id);
        return $this->db->get();
    }

    function getHostelFeeDefaulterLIst($formEnrollRollNumber, $feeHead, $ucsMapId, $session, $course) {
        $this->db->select("(FSOM.fsom_amount - SUM(FCOM.fcom_amount)) as due,SUM(FCOM.fcom_amount) as total_paid,TSPI.tspi_id,TSPI.tspi_name,TSPI.tspi_rollNumber,TSPI.tspi_enrollment_no,TCM.course_name,SESS.session_name,TCSM.tcsm_course_type, FSOM.fsom_amount as total_amount,FHOM.fhom_name");
        $this->db->from('fee_collection_opt_mst FCOM');
        $this->db->join('fee_receipt_opt_mst FROM', 'FCOM.from_id = FROM.from_id');
        $this->db->join('fee_structure_opt_mst FSOM', 'FCOM.fsom_id = FSOM.fsom_id');
        $this->db->join('fee_heads_opt_mst FHOM', 'FSOM.fhom_id = FHOM.fhom_id');
        $this->db->join('fee_modes_mst FMM', 'FCOM.fmm_id = FMM.fmm_id');
        $this->db->join('tbl_student_personal_info TSPI', 'FCOM.tspi_id = TSPI.tspi_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'TSPI.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_session_master SESS', 'TUCSM.session_id = SESS.session_id');
        $this->db->join('tbl_course_sub_master TCSM', 'TUCSM.sub_course_id = TCSM.tcsm_id');
        $this->db->join('tbl_course_master TCM', 'TCSM.course_id = TCM.course_id');
        $this->db->where("(TSPI.tspi_form_no LIKE '%" . $formEnrollRollNumber . "%' OR TSPI.tspi_enrollment_no LIKE '%" . $formEnrollRollNumber . "%' OR TSPI.tspi_rollNumber LIKE '%" . $formEnrollRollNumber . "%')");
        /* Course/Session/Entry Type Combination */
        if ($ucsMapId != '') {
            $this->db->where("TUCSM.ucs_map_id", $ucsMapId);
        } else if ($course != '' && $session != '' && $ucsMapId == '') {
            $this->db->where("TCM.course_id", $course);
            $this->db->where("TSM.session_id", $session);
        } else if ($course != '' && $session == '' && $ucsMapId == '') {
            $this->db->where("TCM.course_id", $course);
        } else if ($course == '' && $session != '' && $ucsMapId == '') {
            $this->db->where("TSM.session_id", $session);
        }
        /* Course/Session/Entry Type Combination */
        if ($feeHead != '') {
            $this->db->where("FHOM.fhom_id", $feeHead);
        }
        $this->db->where("FROM.from_status ='A'");
        $this->db->group_by("TSPI.tspi_id,TSPI.tspi_name,TSPI.tspi_rollNumber,TSPI.tspi_enrollment_no,TCM.course_name,SESS.session_name,TCSM.tcsm_course_type, FSOM.fsom_amount, FHOM.fhom_name");
        $this->db->having("SUM(FCOM.fcom_amount) < FSOM.fsom_amount");
        return $this->db->get();
    }

    function getOptionalFeeReceiptInfoBy($receipt_number = '', $formEnrollRollNumber = '', $course = '', $session = '', $ucs_map_id = '') {
        $this->db->select("*");
        $this->db->from('fee_collection_opt_mst FCOM');
        $this->db->join('fee_structure_opt_mst FSOM', 'FCOM.fsom_id = FSOM.fsom_id');
        $this->db->join('fee_heads_opt_mst FHOM', 'FSOM.fhom_id = FHOM.fhom_id');
        $this->db->join('fee_modes_mst FMM', 'FCOM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_opt_mst FROM', 'FCOM.from_id = FROM.from_id');
        $this->db->join('tbl_student_personal_info TSPI', 'FCOM.tspi_id = TSPI.tspi_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'TSPI.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_session_master TSM', 'TSM.session_id = FROM.session_id');
        $this->db->join('tbl_course_sub_master TSCM', 'TUCSM.sub_course_id = TSCM.tcsm_id');
        $this->db->join('tbl_course_master TCM', 'TSCM.course_id = TCM.course_id');
        $this->db->order_by("FROM.from_generated_on", "DESC");
        if ($receipt_number != "") {
            $this->db->where('FROM.from_receipt_no', $receipt_number);
        }
        if ($formEnrollRollNumber != "") {
            $this->db->where("(TSPI.tspi_form_no = '" . $formEnrollRollNumber . "' OR TSPI.tspi_enrollment_no = '" . $formEnrollRollNumber . "' OR TSPI.tspi_rollNumber = '" . $formEnrollRollNumber . "')");
        }
        if ($course != "") {
            $this->db->where("TCM.course_id", $course);
        }
        if ($session != "") {
            $this->db->where("TSM.session_id", $session);
        }
        if ($ucs_map_id != "") {
            $this->db->where("TSPI.ucs_map_id", $ucs_map_id);
        }
        return $this->db->get();
    }

    function updateOptionalFeeReceiptInfoInBulk(array $feeReceiptUpdatedInfo) {
        return $this->db->update_batch('fee_receipt_opt_mst', $feeReceiptUpdatedInfo, "from_id");
    }

    function getOptionalFeeReceiptInfo($from_id) {
        $this->db->select("*");
        $this->db->from("fee_receipt_opt_mst FROM");
        $this->db->join("fee_collection_opt_mst FCOM", "FCOM.from_id=FROM.from_id");
        $this->db->where("FROM.from_id", $from_id);
        return $this->db->get();
    }

    /* Function For Hostel Fee Report */

    function getMiscellaneousHostelFeeReport($receipt_number = '', $formEnrollRollNumber = '', $payment_mode = '', $fee_head = '', $course = '', $session = '', $ucsMapId = '', $collected_for_session = '', $operator = '', $startDate = '', $endDate = '', $rangeAppliedwith = '') {
        $this->db->select("*");
        $this->db->from('fee_collection_opt_mst FCOM');
        $this->db->join('fee_structure_opt_mst FSOM', 'FCOM.fsom_id = FSOM.fsom_id');
        $this->db->join('fee_heads_opt_mst FHOM', 'FSOM.fhom_id = FHOM.fhom_id');
        $this->db->join('fee_modes_mst FMM', 'FCOM.fmm_id = FMM.fmm_id');
        $this->db->join('fee_receipt_opt_mst FROM', 'FCOM.from_id = FROM.from_id');
        $this->db->join('tbl_student_personal_info TSPI', 'FCOM.tspi_id = TSPI.tspi_id');
        $this->db->join('tbl_univ_course_session_mapping TUCSM', 'TSPI.ucs_map_id = TUCSM.ucs_map_id');
        $this->db->join('tbl_session_master TSM', 'TUCSM.session_id = TSM.session_id');
        $this->db->join('tbl_course_sub_master TSCM', 'TUCSM.sub_course_id = TSCM.tcsm_id');
        $this->db->join('tbl_course_master TCM', 'TSCM.course_id = TCM.course_id');
        $this->db->where("FROM.from_receipt_no LIKE '%" . $receipt_number . "%'");
        $this->db->where("(TSPI.tspi_form_no LIKE '%" . $formEnrollRollNumber . "%' OR TSPI.tspi_enrollment_no LIKE '%" . $formEnrollRollNumber . "%' OR TSPI.tspi_rollNumber LIKE '%" . $formEnrollRollNumber . "%')");
        /* Payment Mode Wise Filter */
        if ($payment_mode != '') {
            $this->db->where("FMM.fmm_id", $payment_mode);
        }
        /* Payment Mode Wise Filter */
        /* Fee Head Wise Filter */
        if ($fee_head != '') {
            $this->db->where("FHOM.fhom_id", $fee_head);
        }
        /* Fee Head Wise Filter */
        /* Course/Session/Entry Type Combination */
        if ($ucsMapId != '') {
            $this->db->where("TUCSM.ucs_map_id", $ucsMapId);
        } else if ($course != '' && $session != '' && $ucsMapId == '') {
            $this->db->where("TCM.course_id", $course);
            $this->db->where("TSM.session_id", $session);
        } else if ($course != '' && $session == '' && $ucsMapId == '') {
            $this->db->where("TCM.course_id", $course);
        } else if ($course == '' && $session != '' && $ucsMapId == '') {
            $this->db->where("TSM.session_id", $session);
        }
        /* Course/Session/Entry Type Combination */
        /* Collection For Session Filter */
        if ($collected_for_session != '') {
            $this->db->where("FROM.session_id", $collected_for_session);
        }
        /* Collection For Session Filter */
        /* Collected By Operator Wise Filter */
        if ($operator != '') {
            $this->db->where("FROM.from_generated_by =" . $operator);
        }
        /* Collected By Operator Wise Filter */
        /* Dates Combination */
        if ($startDate != '' && $endDate != '' && $rangeAppliedwith != '') {
            if ($rangeAppliedwith == "RCTDT") {
                $this->db->where("FROM.from_receipt_date >= '" . $startDate . "' && FROM.from_receipt_date <= '" . $endDate . "'");
            } else {
                $this->db->where("FROM.from_generated_on >= '" . $startDate . "' && FROM.from_generated_on <= '" . $endDate . "'");
            }
        } else if ($startDate == '' && $endDate != '' && $rangeAppliedwith != '') {
            if ($rangeAppliedwith == "RCTDT") {
                $this->db->where("FROM.from_receipt_date <= '" . $endDate . "'");
            } else {
                $this->db->where("FROM.from_generated_on <= '" . $endDate . "'");
            }
        } else if ($startDate != '' && $endDate == '' && $rangeAppliedwith != '') {
            if ($rangeAppliedwith == "RCTDT") {
                $this->db->where("FROM.from_receipt_date >= '" . $startDate . "'");
            } else {
                $this->db->where("FROM.from_generated_on >= '" . $startDate . "'");
            }
        }
        $this->db->where("FROM.from_status ='A'");
        /* Dates Combination */
        return $this->db->get();
    }

    /* Functions For Transaction Manager */

    function createNewTransaction(array $newTransactionInfo) {
        $this->db->insert('transaction_mst', $newTransactionInfo);
        return $this->db->insert_id();
    }

}

KBHT - 2023