BBnepal-Accounts/application/models/Admin_model.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

4623 lines
140 KiB
PHP

<?php
defined('BASEPATH') or exit('No direct script access allowed');
use Nilambar\NepaliDate\NepaliDate;
require_once 'vendor/autoload.php';
class Admin_model extends CI_Model
{
private $nepaliDateObject;
private $nepali_current_date;
public function __construct()
{
$this->load->database();
$this->load->helper('common_helper');
$this->nepaliDateObject = new NepaliDate();
$this->nepali_current_date = cuurentNepaliDate($this->nepaliDateObject);
}
/**************************************** START of Admin Menu - Nandini ************************************/
function recursive_menue($parentId = 0)
{
$this->db->where('parent_id', $parentId);
$this->db->where('is_active', 'yes');
$this->db->order_by('order_number', 'ASC');
$query = $this->db->get('admin_menu');
$result = $query->result_array();
$adminMenu = array();
if (!empty($result)) {
foreach ($result as $res) {
array_push($adminMenu, $res);
}
}
// echo '<pre>';
// var_dump($adminMenu);
return $adminMenu;
}
function get_admin_menu($parentId = 0)
{
$zeroMenu = $this->recursive_menue(0);
$adminMenu = array();
if (!empty($zeroMenu)) {
foreach ($zeroMenu as $zero) {
$adminMenu[$zero['id']] = $zero;
$oneMenu = $this->recursive_menue($zero['id']);
if (!empty($oneMenu)) {
foreach ($oneMenu as $one) {
$adminMenu[$zero['id']][$zero['id']][$one['id']] = $one;
$twoMenu = $this->recursive_menue($one['id']);
if (!empty($twoMenu)) {
foreach ($twoMenu as $two) {
$adminMenu[$zero['id']][$zero['id']][$one['id']][$one['id']][$two['id']] = $two;
/*$threeMenu = $this->recursive_menue($two['id']);
if(!empty($threeMenu))
{
foreach($threeMenu as $three)
{
$adminMenu[$zero['id']][$zero['id']][$one['id']][$one['id']][$two['id']][$two['id']][$three['id']] = $three;
}
}*/
}
}
}
}
}
}
//echo '<pre>';print_r($adminMenu);
return $adminMenu;
}
public function get_admin_role_permissions($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('admin_role_permissions.id', 'DESC');
$query = $this->db->get('admin_role_permissions');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
/**************************************** END of Admin Menu - Nandini ************************************/
public function login($uname, $pwd)
{
$pwd = md5($pwd);
$sql = $this->db->query("SELECT * FROM admin WHERE email='$uname' AND password='$pwd'");
if ($sql->num_rows() > 0) {
return $sql->row_object();
} else {
return false;
}
}
public function getAdminId($id)
{
$result = $this->db->query('select id from teacher where teacherId = "' . $id . '"')->row_array();
return $result;
}
public function get_adminMenu()
{
// $this->db->order_by('id', 'ASC');
$this->db->select('*');
$this->db->from('admin_menu');
$this->db->where(array('is_active' => 'yes'));
$this->db->order_by('order_number');
$query = $this->db->get();
return $query->result_array();
}
public function get_logo()
{
$this->db->select('*');
$this->db->from('erisn_classroom_logo');
$query = $this->db->get();
return $query->row_array();
}
public function get_logo_from_setting()
{
$this->db->select('*');
$this->db->from('school_settings');
$query = $this->db->get();
return $query->row_array();
}
public function addedit_subject($s_id, $s_name, $s_icon, $sylabus)
{
$aid = $_SESSION['admin_id'];
if ($s_id == 0) {
$data_array = array(
'subject_name' => $s_name,
'subject_icon' => $s_icon,
'subject_syllabus' => $sylabus,
'created_by' => $aid,
'created_on' => date('Y-m-d H:i:s')
);
$this->db->select('subject_name');
$this->db->from('subject');
$this->db->where('subject_name', $s_name);
$query = $this->db->get();
if ($query->num_rows() == 0) {
$insert = $this->db->insert('subject', $data_array);
if ($insert) {
echo '1';
}
} else {
echo '0';
}
} else {
if ($sylabus != '') {
$data_array = array(
'subject_name' => $s_name,
'subject_icon' => $s_icon,
'subject_syllabus' => $sylabus,
'modified_by' => $aid,
'modified_on' => date('Y-m-d H:i:s')
);
} else {
$data_array = array(
'subject_name' => $s_name,
'subject_icon' => $s_icon,
'modified_by' => $aid,
'modified_on' => date('Y-m-d H:i:s')
);
}
$this->db->where('id', $s_id);
$update = $this->db->update('subject', $data_array);
if ($update) {
echo '2';
}
}
}
public function add_subject($s_name, $s_icon, $subcode)
{
$aid = $_SESSION['admin_id'];
$data_array = array(
'subject_name' => $s_name,
'subject_icon' => $s_icon,
'subject_code' => $subcode,
'created' => date('Y-m-d H:i:s')
);
$insert = $this->db->insert('subject', $data_array);
if ($insert) {
return 1;
} else {
return 0;
}
}
public function update_subject($sub_id, $s_name, $s_icon, $subcode, $is_acive)
{
$aid = $_SESSION['admin_id'];
$data_array = array(
'subject_name' => $s_name,
'subject_icon' => $s_icon,
'subject_code' => $subcode,
'is_active' => $is_acive,
'modified' => date('Y-m-d H:i:s')
);
$this->db->where('id', $sub_id);
$update = $this->db->update('subject', $data_array);
if ($update) {
return 1;
} else {
return 0;
}
}
public function get_subjects($sid = '')
{
$this->db->select('*');
$this->db->from('subject');
if ($sid != '') {
$this->db->where('id', $sid);
// $this->db->where('is_active', 'yes');
$query = $this->db->get();
return $query->row_array();
} else {
// $this->db->where('is_active', 'yes');
$query = $this->db->get();
return $query->result_array();
}
}
public function get_students($course_id = '', $batch='')
{
$school_info = $this->get_logo_from_setting();
$batch_id = $batch;
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('students');
$this->db->where('is_active', 'yes');
$course_id = (int)$course_id;
if (isset($course_id) && !empty($course_id))
$this->db->where('course', $course_id);
if (isset($batch_id) && !empty($batch_id))
$this->db->where('batch_id', $batch_id);
// if ($s_date != '' && $e_date != '') {
// $this->db->where('DATE(registered_on) >=', date('Y-m-d', strtotime($s_date)));
// $this->db->where('DATE(registered_on) <=', date('Y-m-d', strtotime($e_date)));
// } else {
// if ($s_date != '')
// $this->db->like('DATE(registered_on)', date('Y-m-d', strtotime($s_date)));
// else if ($e_date != '')
// $this->db->like('DATE(registered_on)', date('Y-m-d', strtotime($e_date)));
// }
// if($s_date !=''){
// $this->db->where("DATE(registered_on) >=", date('Y-m-d',strtotime($s_date)));
// }
// if ($e_date != ''){
// $this->db->where("DATE(registered_on) <=", date('Y-m-d',strtotime($e_date)));
// }
// if ($s_date != '' && isset($e_date) && !empty($s_date)){
// $s_date = date('Y-m-d', strtotime($s_date));
// $this->db->where("DATE(registered_on) >=", $s_date);
// }
// if ($e_date != '' && isset($e_date) && !empty($e_date)) {
// $e_date = date('Y-m-d', strtotime($e_date));
// $this->db->where("DATE(registered_on) <=", $e_date);
// }
$query = $this->db->get();
// $query = "SELECT * FROM students WHERE batch_id = $batch_id AND course = $course"
// var_dump($query);
// exit();
return $query->result_array();
}
public function get_delsubjects()
{
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('subject');
$this->db->where('flag', 'N');
$query = $this->db->get();
return $query->result_array();
}
public function get_delteacher()
{
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('teacher');
$this->db->where('flag', 'N');
$query = $this->db->get();
return $query->result_array();
}
public function delete_data($id, $table)
{
$query = $this->db->query(
'
SELECT teacher.id
FROM teacher
WHERE ' . $id . ' IN (SELECT teacher_id FROM questions where teacher_id=' . $id . ')
OR ' . $id . ' IN (SELECT teacher_id from classroom_teacher_subject where teacher_id=' . $id . ')
OR ' . $id . ' IN (SELECT teacher_id from assignment where teacher_id=' . $id . ')'
);
if ($query->num_rows() > 0) {
echo '0';
} else {
$update = $this->db->delete($table, array('id' => $id));
$delete = $this->db->delete('teacher_subjects', array('teacher_id' => $id));
if ($delete) {
echo '1';
}
}
}
public function delete_classroom($clsroomId)
{
$status = "exists";
$res1 = $this->get_general_result_details('student_batch', 'ASC', array('classroom_id' => $clsroomId));
if (count($res1) > 0) {
return $status;
} else {
$res2 = $this->get_general_result_details('classroom_teacher_subject', 'ASC', array('classroom_id' => $clsroomId));
if (count($res2) > 0) {
return $status;
} else {
$res3 = $this->get_general_result_details('student_attendence', 'ASC', array('classroom_id' => $clsroomId));
if (count($res3) > 0) {
return $status;
} else {
$res4 = $this->get_general_result_details('classroom_session', 'ASC', array('classroom_id' => $clsroomId));
if (count($res4) > 0) {
return $status;
} else {
$this->db->where('id', $clsroomId);
$del = $this->db->delete('classroom');
if ($del)
return $status = "no";
else
return $status;
}
}
}
}
}
public function delete_classroom_permanent($clsname, $table)
{
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('classroom_name', $clsname);
$query = $this->db->get();
// echo $this->db->last_query();
$res = $query->result_array();
$crouseId = array();
$k = 0;
foreach ($res as $r) {
$crouseId[$k] = $r['id'];
$k++;
}
$this->db->where('classroom_name', $clsname);
$this->db->delete($table);
$data = array(
'classroom' => 0
);
$this->db->where_in('classroom', $crouseId);
$update = $this->db->update('students', $data);
// echo $this->db->last_query();
if ($update) {
echo '1';
}
}
/**************************************** START of Batches - Nandini ************************************/
public function get_batches($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('batch.id', 'DESC');
$query = $this->db->get('batch');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
function check_batch_name_already_exists($idVal, $bname)
{
$query = $this->db->get_where('batch', array('b_name' => $bname));
if (!empty($query->row_array())) {
if ($idVal == 0)
return 'Duplicate'; //Duplicate
else {
if ($query->row(0)->id != $idVal)
return 'Duplicate'; //Duplicate
}
}
return 'No Duplicate'; //No duplicate
}
function add_edit_batch($id, $data)
{
if ($id == 0) {
$data['created'] = $this->nepali_current_date;
$data['modified'] = $this->nepali_current_date;
$this->db->insert('batch', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$data['modified'] = $this->nepali_current_date;
$this->db->where('id', $id);
$this->db->update('batch', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
/**************************************** END of Batches - Nandini ************************************/
public function delete_data_permanent($id, $table)
{
$this->db->where('id', $id);
$this->db->delete($table);
if ($table == 'subject') {
$data = array(
'flag' => 'N'
);
$this->db->where('subject_id', $id);
$update = $this->db->update('classroom', $data);
}
if ($table == 'teacher') {
$data = array(
'flag' => 'N'
);
$this->db->where('teacher_id', $id);
$update = $this->db->update('classroom', $data);
}
if ($table == 'classroom') {
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('id', $id);
$query = $this->db->get();
print_r($query);
$data = array(
'classroom' => 0
);
$this->db->where('classroom', $id);
$update = $this->db->update('students', $data);
}
// echo $this->db->last_query();
echo '1';
}
public function delete_installment($cid, $table)
{
$data = array(
'flag' => 'N'
);
$this->db->where('course_id', $cid);
$update = $this->db->update($table, $data);
if ($update) {
echo '1';
}
}
public function restore_installment($cid, $table)
{
$data = array(
'flag' => 'Y'
);
$this->db->where('course_id', $cid);
$update = $this->db->update($table, $data);
if ($update) {
echo '1';
}
}
public function restore_data($id, $table)
{
$data = array(
'flag' => 'Y'
);
$this->db->where('id', $id);
$update = $this->db->update($table, $data);
if ($update) {
echo '1';
}
}
//subject end
//course start
public function get_course($cid)
{
if (empty($cid)) {
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('course');
$this->db->where('is_active', 'yes');
$query = $this->db->get();
return $query->result_array();
} else {
$this->db->select('*');
$this->db->from('course');
$this->db->where('id', $cid);
$query = $this->db->get();
return $query->row_array();
}
}
//course start
public function get_install_batch()
{
$q = "Select b.id, b.b_name,b.b_from,b.b_end from course_fees cf inner join batch b on cf.batch_id = b.id GROUP BY b.b_name order by b.id DESC";
$res = $this->db->query($q);
return $res->result_array();
}
public function get_install_course()
{
$q = "Select c.id, c.course_name from course_fees cf inner join course c on cf.course_id = c.id GROUP BY c.course_name";
$res = $this->db->query($q);
return $res->result_array();
}
public function get_delcourse()
{
if (empty($cid)) {
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('course');
$this->db->where('flag', 'N');
$query = $this->db->get();
return $query->result_array();
}
}
public function get_delinstall()
{
$this->db->select('installment.id,course_name,payment_installment,payable_amount,installment.course_id,duedates');
$this->db->where('installment.flag', 'N');
$this->db->from('installment');
$this->db->join('course', 'installment.course_id = course.id');
$this->db->order_by('installment.course_id');
$query = $this->db->get();
return $query->result_array();
}
public function addedit_course($c_id, $data_array)
{
$aid = $_SESSION['admin_id'];
if ($c_id == 0) {
$this->db->select('course_name');
$this->db->from('course');
$this->db->where('course_name', $data_array['course_name']);
$query = $this->db->get();
if ($query->num_rows() == 0) {
$data_array['created_by'] = $aid;
$data_array['created_on'] = date('Y-m-d H:i:s');
$insert = $this->db->insert('course', $data_array);
if ($insert) {
echo '1';
}
} else {
echo '0';
}
} else {
$data_array['modified_by'] = $aid;
$data_array['modified_on'] = date('Y-m-d H:i:s');
$this->db->where('id', $c_id);
$update = $this->db->update('course', $data_array);
if ($update) {
echo '2';
}
}
}
public function get_subjectName($sids)
{
$where = "id IN($sids)";
$this->db->select('subject_name');
$this->db->from('subject');
$this->db->where($where);
$query = $this->db->get();
return $query->result_array();
}
//course end
//teacher start
public function get_teacher($tid, $token = '')
{
if (empty($tid)) {
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('teacher');
$this->db->where('is_active', 'yes');
$query = $this->db->get();
return $query->result_array();
}
//shankar code start here
else if ($token == 1) {
$this->db->select('s.id , subject_name, subject_icon,s.is_active,s.created,s.modified');
$this->db->from('subject s, teacher_subjects ts, teacher t');
$this->db->where('t.id', $tid);
$this->db->where('ts.teacher_id = t.id');
$this->db->where('s.id = ts.subject_id');
$this->db->where('s.is_active', 'yes');
$this->db->where('ts.is_active', 'yes');
$query = $this->db->get();
return $query->result_array();
}
//shankar code end here
else {
$this->db->select('*');
$this->db->from('teacher');
$this->db->where('id', $tid);
$query = $this->db->get();
return $query->row_array();
}
}
public function get_staff($tid, $token = '')
{
if (empty($tid)) {
// $this->db->order_by('id', 'DESC');
// $this->db->select('*');
// $this->db->from('teacher');
// $this->db->where('is_active', 'yes');
$q = "Select * from teacher WHERE role != 'teacher' ORDER BY id DESC";
$res = $this->db->query($q);
return $res->result_array();
// $query = $this->db->get();
// return $query->result_array();
} else {
$this->db->select('*');
$this->db->from('teacher');
$this->db->where('id', $tid);
$query = $this->db->get();
return $query->row_array();
}
}
public function addedit_teacher($t_id, $t_password, $profile_image, $data_array, $sub_list)
{
$aid = $_SESSION['admin_id'];
$pwd = base64_encode($t_password);
if ($t_id == 0) {
$this->db->select('*');
$this->db->from('teacher');
$this->db->where('email', $data_array['email']);
$query = $this->db->get();
if ($query->num_rows() == 0) {
$this->db->select_max('id');
$query = $this->db->get('teacher');
$res = $query->row_array();
$pid = $res['id'] + 1;
// if (strlen($pid) == 1)
// $pid = "000" . $pid;
// else if (strlen($pid) == 2)
// $pid = "00" . $pid;
// else if (strlen($pid) == 3)
// $pid = "0" . $pid;
$school_info = $this->get_logo_from_setting();
$school_prefix = (!empty($school_info['school_prefix_id'])) ? $school_info['school_prefix_id'] : 'BB';
$teacherId = $school_prefix . TEACHER_ID_PREFIX . date('Ymd', strtotime($this->nepali_current_date)) . '0' . $pid;
$data_array['teacherId'] = $teacherId;
$data_array['photo'] = $profile_image;
$data_array['password'] = $pwd;
$data_array['created_by'] = $aid;
$data_array['created_on'] = $this->nepali_current_date;
// $insert = $this->db->insert('teacher', $data_array);
// if($insert){
// echo '1';
// }
//shankar code start here
$this->db->insert('teacher', $data_array);
$last_id = $this->db->insert_id();
if ($last_id) {
for ($i = 0; $i < count($sub_list); $i++) {
$d_array = array(
'teacher_id' => $last_id,
'subject_id' => $sub_list[$i]
);
$assign_sub_t = $this->db->insert('teacher_subjects', $d_array);
}
return 1;
}
//shankar code end here
} else {
return 0;
}
} else {
if (!empty($pwd)) {
$data_array['password'] = $pwd;
}
if (!empty($profile_image)) {
$data_array['photo'] = $profile_image;
}
$data_array['modified_by'] = $aid;
$data_array['modified_on'] = $this->nepali_current_date;
$this->db->where('id', $t_id);
$update = $this->db->update('teacher', $data_array);
//shankar code start here
$update_rows = array('is_active' => 'no');
$this->db->where('teacher_id', $t_id);
$this->db->update('teacher_subjects', $update_rows);
$i = 0;
for ($i = 0; $i < count($sub_list); $i++) {
// echo '<pre>';
// var_dump('Subject Id ' . $i + 1 . '= ' . $sub_list[$i]);
$this->db->select('*');
$this->db->from('teacher_subjects');
$this->db->where('teacher_id', $t_id);
$this->db->where('subject_id', $sub_list[$i]);
$query = $this->db->get();
$d = $query->row_array();
if ($d) {
// echo '<pre> Teacher Subjects';
// var_dump($d);
$update_rows = array('is_active' => 'yes');
$this->db->where('teacher_id', $t_id);
$this->db->where('subject_id', $sub_list[$i]);
$this->db->update('teacher_subjects', $update_rows);
// echo '<pre>';
// print_r($this->db);
// // echo '<pre>';
// // print_r($this->db->get()->row_array());
} else {
$d_array = array(
'teacher_id' => $t_id,
'subject_id' => $sub_list[$i]
);
$this->db->insert('teacher_subjects', $d_array);
}
}
//shankar code end here
if ($update) {
return 2;
}
}
}
//teacher end
//classroom start
public function get_classroom($crid)
{
if (empty($crid)) {
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('flag', 'Y');
$query = $this->db->get();
return $query->result_array();
} else {
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('id', $crid);
$query = $this->db->get();
return $query->row_array();
}
}
//classroom start
public function get_delclassroom($crid)
{
if (empty($crid)) {
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('flag', 'N');
$query = $this->db->get();
return $query->result_array();
} else {
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('id', $crid);
$query = $this->db->get();
return $query->row_array();
}
}
public function get_coursesubject($cid)
{
$this->db->select('subject_id');
$this->db->from('course');
$this->db->where('id', $cid);
$query = $this->db->get();
$res = $query->row_array();
$s_id = $res['subject_id'];
$where = "id IN($s_id)";
$this->db->select('*');
$this->db->from('subject');
$this->db->where($where);
$query = $this->db->get();
return $query->result_array();
}
public function get_classroomsubject($classname)
{
$this->db->select('id,subject_id,teacher_id');
$this->db->from('classroom');
$this->db->where('classroom_name', $classname);
$this->db->order_by('teacher_id', 'desc');
$query = $this->db->get();
// echo $this->db->last_query();
return $query->result_array();
}
public function addedit_classroom($cr_id, $cr_name, $cr_batch_from, $cr_batch_to, $cr_course, $cr_subject, $cr_teacher)
{
$aid = $_SESSION['admin_id'];
if ($cr_id == 0) {
$this->db->select('classroom_name');
$this->db->from('classroom');
$this->db->where('classroom_name', $cr_name);
$query = $this->db->get();
if ($query->num_rows() == 0) {
for ($i = 0; $i < count($cr_subject); $i++) {
$crname = $cr_name;
$cbfrom = $cr_batch_from;
$cbto = $cr_batch_to;
$cbcourse = $cr_course;
$crsub = $cr_subject[$i];
$crtea = $cr_teacher[$i];
$data = array(
'course_id' => $cbcourse,
'subject_id' => $crsub,
'teacher_id' => $crtea,
'classroom_name' => $crname,
'batch_from' => $cbfrom,
'batch_to' => $cbto,
'created_by' => $aid,
'created_on' => date('Y-m-d H:i:s')
);
$insert = $this->db->insert('classroom', $data);
}
if ($insert) {
echo '1';
}
} else {
echo '0';
}
} else {
$this->db->where('classroom_name', $cr_name);
$this->db->delete('classroom');
//echo $this->db->last_query();
for ($i = 0; $i < count($cr_subject); $i++) {
$crname = $cr_name;
$cbfrom = $cr_batch_from;
$cbto = $cr_batch_to;
$cbcourse = $cr_course;
$crsub = $cr_subject[$i];
$crtea = $cr_teacher[$i];
$data = array(
'course_id' => $cbcourse,
'subject_id' => $crsub,
'teacher_id' => $crtea,
'classroom_name' => $crname,
'batch_from' => $cbfrom,
'batch_to' => $cbto,
'created_by' => $aid,
'created_on' => date('Y-m-d H:i:s')
);
$update = $this->db->insert('classroom', $data);
}
if ($update) {
echo '2';
} else {
echo '3';
}
}
}
//classroom end
//installment strat
public function get_coursefee($course, $installment, $start)
{
//get course fee
//SELECT * FROM `classroom`,course WHERE classroom.course_id = course.id group by classroom.course_id
$this->db->select('course_fee');
$this->db->from('course');
$this->db->where('course.id', $course);
$query_cf = $this->db->get();
// echo $this->db->last_query();
$result_cf = $query_cf->row_array();
// print_r($result_cf);
$course_fee = $result_cf['course_fee'];
$start = $start;
$html = '';
if ($installment == 1) {
$payment_method = 'Full Payment';
$duedate = $start;
$amount = $course_fee;
$html = '<tr id = "one">
<td><input type="text" name="payment_method[]" value="' . $payment_method . '"></td>
<td><input type="text" name="amount[]" value="' . $amount . '"></td>
<td><input type="text" name="duedate[]" value="' . $duedate . '"></td>
<td><a href = "#" id = "one" onclick = "alert(this.id)"><i class="fas fa-times-circle"></i></a></td>
</tr>';
} elseif ($installment == 2) {
$payment_method = 'Payable in 2 parts';
$duedate = $start . ',' . date('Y-m-d', strtotime("+6 months", strtotime($start)));
$amount = number_format((float)($course_fee / 2), 2, '.', '');
$html .= '<tr id = "two">
<td><input type="text" name="payment_method[]" value="' . $payment_method . '"></td>
<td><input type="text" name="amount[]" value="' . $amount . '"></td>
<td><input type="text" name="duedate[]" value="' . $duedate . '"></td>
<td><a href = "#" id = "one" onclick = "alert(this.id)"> <i class="fas fa-times-circle"></i></a></td>
</tr>';
} elseif ($installment == 4) {
$payment_method = 'Payable in 4 parts';
$duedate = $start . ',' . date('Y-m-d', strtotime("+3 months", strtotime($start))) . ',' . date('Y-m-d', strtotime("+6 months", strtotime($start))) . ',' . date('Y-m-d', strtotime("+9 months", strtotime($start)));
$amount = number_format((float)($course_fee / 4), 2, '.', '');
$html .= '<tr id = "three">
<td><input type="text" name="payment_method[]" value="' . $payment_method . '"></td>
<td><input type="text" name="amount[]" value="' . $amount . '"></td>
<td><input type="text" name="duedate[]" value="' . $duedate . '"></td>
<td><a href = "#" id = "one" onclick = "alert(this.id)"> <i class="fas fa-times-circle"></i></a></td>
</tr>';
} elseif ($installment == 6) {
$payment_method = 'Payable in 6 parts';
$duedate = $start . ',' . date('Y-m-d', strtotime("+2 months", strtotime($start))) . ',' . date('Y-m-d', strtotime("+4 months", strtotime($start))) . ',' . date('Y-m-d', strtotime("+6 months", strtotime($start))) . ',' . date('Y-m-d', strtotime("+8 months", strtotime($start))) . ',' . date('Y-m-d', strtotime("+10 months", strtotime($start)));
$amount = number_format((float)($course_fee / 6), 2, '.', '');
$html .= '<tr id = "four">
<td><input type="text" name="payment_method[]" value="' . $payment_method . '"></td>
<td><input type="text" name="amount[]" value="' . $amount . '"></td>
<td><input type="text" name="duedate[]" value="' . $duedate . '"></td>
<td><a href = "#" id = "one" onclick = "alert(this.id)" > <i class="fas fa-times-circle"></i></a></td>
</tr>';
}
echo $html;
}
//installment strat
public function get_duedates($course_fee, $installment, $start)
{
$this->db->select('amount');
$this->db->from('course_fees');
$this->db->where('course_fees.id', $course_fee);
$query_cf = $this->db->get();
$result_cf = $query_cf->row_array();
$course_fee = $result_cf['amount'];
$query_instal = array();
foreach ($installment as $key => $value) {
$this->db->select('*');
$this->db->from('payment_types');
$this->db->where('number_of_payment', $value);
$inst_quer = $this->db->get();
$query_instal[$key] = $inst_quer->row_array();
}
$start = $start;
$html = '';
for ($k = 0; $k < count($query_instal); $k++) {
if ($query_instal[$k]['number_of_payment'] == 1) {
$payment_method = $query_instal[$k]['payment_type_name'];
$payment_id = $query_instal[$k]['id'];
$duedate = $start;
$amount = $course_fee;
$html = '<tr id = "one">
<td class="installment_pm"><input type="hidden" readOnly name="payment_method[]" class="mb-2" value="' . $payment_id . '">' . $payment_method . '</td>
<td class="installment_amount"><input type="text" name="amount[one]" class="form-control amount-input mb-2" value="' . $amount . '"></td>
<td class="installment_due"><input type="text" name="duedate[one]" readOnly class="form-control np-datepicker installment_date mb-2" value="' . $duedate . '"></td>
</tr>';
$returnArr = array(
'payment_type' => $payment_method,
'total_amount' => $course_fee,
'html' => $html,
'due_date' => $duedate
);
}
if ($query_instal[$k]['number_of_payment'] == 2) {
$payment_method = $query_instal[$k]['payment_type_name'];
$payment_id = $query_instal[$k]['id'];
$dateArr = [];
$dateArr[] = $start;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+6 months", strtotime($AdDate)));
$BsDate = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDate;
$amount = number_format((float)($course_fee / 2), 2, '.', '');
$html .= '<tr id = "two">
<td class="installment_pm"><input type="hidden" readOnly name="payment_method[]" class="mb-2" value="' . $payment_id . '">' . $payment_method . '</td>';
$html .= '<td class="installment_amount">';
foreach ($dateArr as $key => $value) {
$html .= '<div><input type="text" name="amount[two][' . $key . ']" class="form-control amount-input mb-2" value="' . $amount . '"></div>';
}
$html .= '</td>';
$html .= '<td class="installment_due">';
foreach ($dateArr as $key => $value) {
$html .= '<div><input type="text" name="duedate[two][' . $key . ']" readOnly class="form-control np-datepicker installment_date mb-2" value="' . $value . '"></div>';
}
$html .= '</td>';
$html .= '</tr>';
$returnArr = array(
'payment_type' => $payment_method,
'total_amount' => $course_fee,
'html' => $html,
'due_dates' => $dateArr,
'id' => 'two'
);
}
if ($query_instal[$k]['number_of_payment'] == 4) {
$payment_method = $query_instal[$k]['payment_type_name'];
$payment_id = $query_instal[$k]['id'];
$dateArr = [];
$dateArr[] = $start;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+3 months", strtotime($AdDate)));
$BsDateOne = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateOne;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+6 months", strtotime($AdDate)));
$BsDateTwo = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateTwo;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+9 months", strtotime($AdDate)));
$BsDateThree = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateThree;
$amount = number_format((float)($course_fee / 4), 2, '.', '');
$html .= '<tr id = "four">
<td class="installment_pm"><input type="hidden" readOnly name="payment_method[]" class="mb-2" value="' . $payment_id . '">' . $payment_method . '</td>';
$html .= '<td class="installment_amount">';
foreach ($dateArr as $key => $value) {
$html .= '<div><input type="text" name="amount[four][' . $key . ']" class="form-control amount-input mb-2" value="' . $amount . '"></div>';
}
$html .= '</td>';
$html .= '<td class="installment_due">';
foreach ($dateArr as $key => $value) {
$html .= '<div><input type="text" name="duedate[four][' . $key . ']" readOnly class="form-control np-datepicker installment_date mb-2" value="' . $value . '"></div>';
}
$html .= '</td>';
$html .= '</tr>';
$returnArr = array(
'payment_type' => $payment_method,
'total_amount' => $course_fee,
'html' => $html,
'due_dates' => $dateArr,
'id' => 'three'
);
}
if ($query_instal[$k]['number_of_payment'] == 6) {
$payment_method = $query_instal[$k]['payment_type_name'];
$payment_id = $query_instal[$k]['id'];
$dateArr = [];
$dateArr[] = $start;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+2 months", strtotime($AdDate)));
$BsDateOne = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateOne;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+4 months", strtotime($AdDate)));
$BsDateTwo = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateTwo;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+6 months", strtotime($AdDate)));
$BsDateThree = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateThree;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+8 months", strtotime($AdDate)));
$BsDateFour = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateFour;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+10 months", strtotime($AdDate)));
$BsDateFive = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateFive;
$amount = number_format((float)($course_fee / 6), 2, '.', '');
$html .= '<tr id = "six">
<td class="installment_pm"><input type="hidden" readOnly name="payment_method[]" class="mb-2" value="' . $payment_id . '">' . $payment_method . '</td>';
$html .= '<td class="installment_amount">';
foreach ($dateArr as $key => $value) {
$html .= '<div><input type="text" class="form-control amount-input mb-2" name="amount[six][' . $key . ']" value="' . $amount . '"></div>';
}
$html .= '</td>';
$html .= '<td class="installment_due">';
foreach ($dateArr as $key => $value) {
$html .= '<div><input type="text" readOnly class="form-control np-datepicker installment_date mb-2" name="duedate[six][' . $key . ']" value="' . $value . '"></div>';
}
$html .= '</td>';
$html .= '</tr>';
$returnArr = array(
'payment_type' => $payment_method,
'total_amount' => $course_fee,
'html' => $html,
'due_dates' => $dateArr,
'id' => 'three'
);
}
if ($query_instal[$k]['number_of_payment'] == 12) {
$payment_method = $query_instal[$k]['payment_type_name'];
$payment_id = $query_instal[$k]['id'];
$dateArr = [];
$dateArr[] = $start;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+1 months", strtotime($AdDate)));
$BsDateOne = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateOne;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+2 months", strtotime($AdDate)));
$BsDateTwo = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateTwo;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+3 months", strtotime($AdDate)));
$BsDateThree = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateThree;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+4 months", strtotime($AdDate)));
$BsDateFour = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateFour;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+5 months", strtotime($AdDate)));
$BsDateFive = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateFive;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+6 months", strtotime($AdDate)));
$BsDateOne = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateOne;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+7 months", strtotime($AdDate)));
$BsDateTwo = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateTwo;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+8 months", strtotime($AdDate)));
$BsDateThree = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateThree;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+9 months", strtotime($AdDate)));
$BsDateFour = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateFour;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+10 months", strtotime($AdDate)));
$BsDateFive = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateFive;
$AdDate = convert_BSdate_to_ADdate($this->nepaliDateObject, $start);
$AdDate = date('Y-m-d', strtotime("+11 months", strtotime($AdDate)));
$BsDateFive = convert_ADdate_to_BSdate($this->nepaliDateObject, $AdDate);
$dateArr[] = $BsDateFive;
$amount = number_format((float)($course_fee / 12), 2, '.', '');
$html .= '<tr id = "six">
<td class="installment_pm"><input type="hidden" readOnly name="payment_method[]" class="mb-2" value="' . $payment_id . '">' . $payment_method . '</td>';
$html .= '<td class="installment_amount">';
foreach ($dateArr as $key => $value) {
$html .= '<div><input type="text" class="form-control amount-input mb-2" name="amount[six][' . $key . ']" value="' . $amount . '"></div>';
}
$html .= '</td>';
$html .= '<td class="installment_due">';
foreach ($dateArr as $key => $value) {
$html .= '<div><input type="text" readOnly class="form-control np-datepicker installment_date mb-2" name="duedate[six][' . $key . ']" value="' . $value . '"></div>';
}
$html .= '</td>';
$html .= '</tr>';
$returnArr = array(
'payment_type' => $payment_method,
'total_amount' => $course_fee,
'html' => $html,
'due_dates' => $dateArr,
'id' => 'three'
);
}
}
return $returnArr;
}
//installment strat
public function addedit_installment($details)
{
// print_r($details);
$length = sizeof($details['pay_method']);
for ($i = 0; $i < $length; $i++) {
$data_array = array(
'course_id' => $details['course_id'],
'payment_installment' => $details['pay_method'][$i],
'payable_amount' => $details['amount'][$i],
'duedates' => $details['duedate'][$i]
);
$insert = $this->db->insert('installment', $data_array);
}
if ($insert) {
echo '1';
} else {
echo '0';
}
}
public function get_feeinstallment()
{
$this->db->select('installment.id,course_name,payment_installment,payable_amount,installment.course_id,duedates');
$this->db->where('installment.flag', 'Y');
$this->db->from('installment');
$this->db->join('course', 'installment.course_id = course.id');
$this->db->order_by('installment.course_id');
$query = $this->db->get();
return $query->result_array();
}
public function get_coursefeeinstall($cid)
{
$this->db->select('installment.id,course_name,batch_from,payment_installment,payable_amount,installment.course_id,duedates');
// $this->db->where('installment.flag', 'Y');
$this->db->where('installment.course_id', $cid);
$this->db->from('installment');
$this->db->join('course', 'installment.course_id = course.id');
$this->db->order_by('installment.course_id');
$query = $this->db->get();
return $query->result_array();
}
public function get_application($start, $end, $course)
{
$this->db->select('applicationid,applications.id,course_name,b_name,b_from,b_end,photo,email,mobile,name,applications.registered_on,applications.gender');
$this->db->from('applications');
$this->db->join('course', 'applications.course = course.id');
$this->db->join('batch', 'applications.batch_id = batch.id');
$this->db->order_by('applications.id', 'desc');
$this->db->where('status', 'new');
// $this->db->where("registered_on BETWEEN '{$start}' AND '{$end}'");
$course = (int)$course;
if (isset($course) && !empty($course))
$this->db->where('applications.course', $course);
if ($start != '' && isset($start) && !empty($start))
$this->db->where("DATE_FORMAT(registered_on,'%Y-%m-%d') >=", $start);
if ($end != '' && isset($end) && !empty($end))
$this->db->where("DATE_FORMAT(registered_on,'%Y-%m-%d') <=", $end);
$this->db->order_by('applications.id', 'desc');
$query = $this->db->get();
// echo $this->db->last_query();
return $query->result_array();
}
public function get_rejected_application($start, $end, $course)
{
$this->db->select('applicationid,applications.id,course_name,b_name,b_from,b_end,photo,email,mobile,name,applications.registered_on,applications.gender');
$this->db->from('applications');
$this->db->join('course', 'applications.course = course.id');
$this->db->join('batch', 'applications.batch_id = batch.id');
$this->db->where('status', 'rejected');
$course = (int)$course;
if (isset($course) && !empty($course))
$this->db->where('applications.course', $course);
if ($start != '' && isset($start) && !empty($start))
$this->db->where("DATE_FORMAT(registered_on,'%Y-%m-%d') >=", $start);
if ($end != '' && isset($end) && !empty($end))
$this->db->where("DATE_FORMAT(registered_on,'%Y-%m-%d') <=", $end);
$this->db->order_by('applications.id', 'desc');
$query = $this->db->get();
// echo $this->db->last_query();
return $query->result_array();
}
public function get_approved_application($start, $end, $course)
{
$this->db->select('applicationid,applications.id,course_name,b_name,b_from,b_end,photo,email,mobile,name,applications.registered_on,applications.payment_status,applications.gender');
$this->db->from('applications');
$this->db->join('course', 'applications.course = course.id');
$this->db->join('batch', 'applications.batch_id = batch.id');
$this->db->where('status', 'approved');
$course = (int)$course;
if (isset($course) && !empty($course))
$this->db->where('applications.course', $course);
if ($start != '' && isset($start) && !empty($start))
$this->db->where("DATE_FORMAT(registered_on,'%Y-%m-%d') >=", $start);
if ($end != '' && isset($end) && !empty($end))
$this->db->where("DATE_FORMAT(registered_on,'%Y-%m-%d') <=", $end);
$this->db->order_by('applications.id', 'desc');
$query = $this->db->get();
// echo $this->db->last_query();
return $query->result_array();
}
//installment end
public function view_applicant($id)
{
$this->db->select('applicationid,applications.id,course_name,b_name,b_from,b_end,photo,email,mobile,name,registered_on,dob,gender,address1,address2,state,country,zipcode,exam_result,medical_cerificate,school_certificate');
$this->db->from('applications');
$this->db->join('course', 'applications.course = course.id');
$this->db->join('batch', 'applications.batch_id = batch.id');
$this->db->where('applications.id', $id);
$this->db->order_by('applications.id', 'desc');
$query = $this->db->get();
return $query->result_array();
}
public function process_application($id, $data)
{
// $application =
$this->db->where('id', $id);
$update = $this->db->update('applications', $data);
if ($update)
return 1;
else
return 0;
// echo $this->db->last_query();
}
public function get_allcourse()
{
$this->db->order_by('id', 'ASC');
$this->db->select('*');
$this->db->from('course');
$this->db->where('is_active', 'yes');
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result_array();
}
public function update_applicationdoc($data)
{
if (isset($data['photo']))
$data_array['photo'] = $data['photo'];
if (isset($data['exam_result']))
$data_array['exam_result'] = $data['exam_result'];
if (isset($data['medical_cerificate']))
$data_array['medical_cerificate'] = $data['medical_cerificate'];
if (isset($data['school_certificate']))
$data_array['school_certificate'] = $data['school_certificate'];
$id = $data['id'];
$this->db->where('id', $id);
$update = $this->db->update('applications', $data_array);
}
public function update_studentsdoc($data)
{
if (isset($data['photo']))
$data_array['photo'] = $data['photo'];
if (isset($data['exam_result']))
$data_array['exam_result'] = $data['exam_result'];
if (isset($data['medical_cerificate']))
$data_array['medical_cerificate'] = $data['medical_cerificate'];
if (isset($data['school_certificate']))
$data_array['school_certificate'] = $data['school_certificate'];
$id = $data['id'];
$data['modified'] = $this->nepali_current_date;
$this->db->where('id', $id);
$update = $this->db->update('students', $data_array);
}
public function view_student($id)
{
$this->db->select('students.batch_id,classroom.classroom_name,b_name, students.id,students.qr_code,students.iemis,students.father_name,students.mother_name,students.studentId,course_name,photo,email,mobile,name,registered_on,dob,gender,address1,address2,state,country,zipcode,exam_result,medical_cerificate,school_certificate,emergency_contact_name,emergency_contact_number,students.is_active,suspend_reason,has_sibling,parent_pan');
$this->db->from('students');
$this->db->join('course', 'students.course = course.id');
$this->db->join('student_batch', 'student_batch.student_id = students.id AND student_batch.batch_id = students.batch_id');
$this->db->join('classroom', 'student_batch.classroom_id = classroom.id');
$this->db->join('batch', 'students.batch_id = batch.id');
$this->db->where('students.id', $id);
$this->db->order_by('student_batch.id', 'desc');
$this->db->limit(1);
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result_array();
}
public function get_coursestudents($cid)
{
$this->db->order_by('id', 'DESC');
$this->db->select('students.id,course_name,photo,email,mobile,name,studentId');
$this->db->from('students');
$this->db->join('course', 'students.course = course.id');
$this->db->where('students.flag', 'Y');
$this->db->where('students.course', $cid);
$this->db->where('classroom', 0);
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result_array();
}
public function get_classstudents($clsid)
{
$this->db->order_by('id', 'DESC');
$this->db->select('students.id,course_name,photo,email,mobile,name,studentId');
$this->db->from('students');
$this->db->join('course', 'students.course = course.id');
$this->db->where('students.flag', 'Y');
$this->db->where('students.classroom', $clsid);
$query = $this->db->get();
return $query->result_array();
}
public function assign_clssroom($clsid, $id)
{
$data = array(
'classroom' => $clsid
);
$this->db->where('id', $id);
$update = $this->db->update("students", $data);
// echo $this->db->last_query();
if ($update) {
return 1;
}
}
//course start
public function get_studentcourse($sid)
{
$this->db->select('*');
$this->db->from('students');
$this->db->where('id', $sid);
$query = $this->db->get();
return $query->row_array();
}
public function get_removestudent($sid)
{
$data = array(
'classroom' => 0
);
$this->db->where('id', $sid);
$update = $this->db->update("students", $data);
// echo $this->db->last_query();
if ($update) {
echo '1';
}
}
/* public function get_classsubject($id){
$this->db->select('class_id,subject_id,subject_name');
$this->db->from('classroom_session');
$this->db->where('classroom_session.flag', 'Y');
$this->db->where('classroom_session.class_id', $id);
$this->db->join('classroom', 'classroom_session.class_id = classroom.id','left');
$this->db->join('subject', 'subject.id = classroom.subject_id','left');
$query = $this->db->get();
echo $this->db->last_query();
return $query->result_array();
}*/
public function get_classsubject($id)
{
$query = 'Select subject_id,subject_name
from classroom
left join subject
on subject.id = classroom.subject_id
WHERE course_id = (select course_id from classroom where classroom_name ="' . $id . '" group by classroom_name )
and classroom.flag = "Y"
group by subject_id';
$q = $this->db->query($query);
// echo $this->db->last_query();
return $q->result_array();
}
public function get_student_details($table_name, $condtion)
{
$this->db->select('name,email,applicationid');
$this->db->from('applications');
$this->db->where($condtion);
$query = $this->db->get();
return $query->row_array();
}
// Section Models 06/10/2021 - Afras Khan
public function get_section_details($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('section.id', 'DESC');
$query = $this->db->get('section');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
if (($query->num_rows() == 1))
return $query->row_array();
return $query->result_array();
}
public function deleteSection($id)
{
$this->db->where('id', $id);
$this->db->delete('section');
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
public function checkSectioninCourse($crid)
{
$this->db->select('*');
$this->db->from('course_sections');
$this->db->where('section_id', $crid);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$firstResult = $query->result_array();
$courseNames = array();
foreach ($firstResult as $key => $value) {
$courseId = $value['course_id'];
$courseQuery = $this->db->query("Select course_name from course WHERE id = '$courseId' GROUP BY id");
if ($courseQuery->num_rows() > 0) {
$res = $courseQuery->result_array();
foreach ($res as $key => $value) {
array_push($courseNames, $value['course_name']);
}
} else {
return 'Course Error';
}
}
return $courseNames;
} else {
return 'failed';
}
}
public function add_edit_section($id, $data)
{
if ($id == 0) {
$data['created'] = $this->nepali_current_date;
$data['modified'] = $this->nepali_current_date;
$this->db->insert('section', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
// $check_section_course = $this->db->query('Select * from course_sections where section_id = ' . $id);
// $check_section_class = $this->db->query('Select * from classroom where section_id = ' . $id);
// if ($check_section_course->num_rows() > 0 || $check_section_class->num_rows() > 0) {
// return 0;
// }
$check_section_in_classroom = $this->db->query("SELECT * FROM classroom WHERE section_id=$id")->result_array();
// $check_section_in_classroom = $this->Admin_model->get_table_info_row('classroom', array('section_id' => $id));
if (!empty($check_section_in_classroom)) {
// echo "<pre>";
// print_r($check_section_in_classroom);
foreach ($check_section_in_classroom as $each_section) {
$arr = explode(' - ', $each_section['classroom_name']);
$arr[1] = $_POST['section_name'];
$class_name = implode(' - ', $arr);
$this->db->set('classroom_name', $class_name)
->where('id', $each_section['id'])
->update('classroom');
// echo "<pre>";
// print_r($class_name);
}
// exit;
// $arr = explode(' - ', $check_section_in_classroom['classroom_name']);
// $arr[1] = $_POST['section_name'];
// $class_name = implode(' - ', $arr);
// $this->db->set('classroom_name', $class_name)
// ->where('section_id', $id)
// ->update('classroom');
}
$data['modified'] = $this->nepali_current_date;
$this->db->where('id', $id);
$this->db->update('section', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
// Section Models End 06/10/2021 - Afras Khan
// subject start by shivu
public function get_subject_details($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('subject.id', 'DESC');
$query = $this->db->get('subject');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
if (($query->num_rows() == 1))
return $query->row_array();
return $query->result_array();
}
public function add_edit_subject($id, $data)
{
if ($id == 0) {
$data['created'] = $this->nepali_current_date;
$data['modified'] = $this->nepali_current_date;
$this->db->insert('subject', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$data['modified'] = $this->nepali_current_date;
$this->db->where('id', $id);
$this->db->update('subject', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
public function check_subject($id)
{
$this->db->select('*');
$this->db->from('subject');
$this->db->where('id', $id);
$query = $this->db->get();
if ($query->num_rows() > 0)
return 1;
else
return 0;
}
public function get_general_details($table_name, $order_by, $where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by($table_name . '.id', $order_by);
$query = $this->db->get($table_name);
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
if (($query->num_rows() == 1))
return $query->row_array();
return $query->result_array();
}
public function get_query_result($sqlQry)
{
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
public function get_query_row($sqlQry)
{
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->row_array();
}
public function insert_update_data($data, $filename)
{
$whereClause = array('subject_id' => $data['subject_id'], 'course_id' => $data['course_id']);
$result = $this->get_general_details('subject_syllabus', 'DESC', $whereClause);
if (count($result) > 0) {
$update_data = array('syllabus' => $filename, 'modified' => date('Y-m-d H:i:s', strtotime($this->nepali_current_date)));
$this->db->where($whereClause);
$update_rst = $this->db->update('subject_syllabus', $update_data);
if ($update_rst)
return 1;
else
return 0;
} else {
$insertdata = array('subject_id' => $data['subject_id'], 'course_id' => $data['course_id'], 'syllabus' => $filename, 'created' => date('Y-m-d H:i:s', strtotime($this->nepali_current_date)), 'modified' => date('Y-m-d H:i:s', strtotime($this->nepali_current_date)));
$insert = $this->db->insert('subject_syllabus', $insertdata);
if ($insert)
return 2;
else
return 0;
}
}
// subject end by shivu
// Course Models 12-10-2021 Afras Khan
public function get_course_details($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('course.id', 'DESC');
$query = $this->db->get('course');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
if (($query->num_rows() == 1))
return $query->row_array();
return $query->result_array();
}
public function get_course_subject_section($sql)
{
$query = $this->db->query($sql);
if (($query->num_rows() == 0))
return 'failed';
return $query->result_array();
}
public function check_value_exists($table, $where, $id)
{
$query = $this->db->get_where($table, $where);
if (!empty($query->row_array())) {
if ($id == 0)
return false;
else {
if ($query->row(0)->id != $id)
return false;
}
}
return true;
}
public function add_edit_course($id, $data, $subsecid)
{
// $data['batch'] = $this->Admin_model->getBatch();
// echo '<pre>';
// var_dump($data['batch']);
// var_dump($data['batch'][0]['batch_id']);
// $currentBatch = $data['batch'][0]['batch_id'];
$currentBatch = $this->Admin_model->getBatch()[0]['batch_id'];
if ($id == 0) {
$this->db->insert('course', $data);
if ($this->db->affected_rows() > 0) {
$flag = false;
$last_id = $this->db->insert_id();
foreach ($subsecid['section'] as $key => $value) {
$insertSectionArr = array(
'course_id' => $last_id,
'section_id' => $value,
'created' => $this->nepali_current_date,
'modified' => $this->nepali_current_date
);
$this->db->trans_start();
$insertCourseSec = $this->db->insert('course_sections', $insertSectionArr);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
return FALSE;
} else {
$flag = true;
}
}
if (!$flag)
return false;
foreach ($subsecid['subject'] as $key => $value) {
$insertSubjectArr = array(
'course_id' => $last_id,
'subject_id' => $value,
'created' => $this->nepali_current_date,
'modified' => $this->nepali_current_date
);
$this->db->trans_start();
$insertCourseSub = $this->db->insert('course_subjects', $insertSubjectArr);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
$flag = false;
return FALSE;
} else {
$flag = true;
}
}
return $flag;
}
} else if ($id > 0) { // Checking ID == 0 Condition
$this->db->where('id', $id);
$this->db->update('course', $data);
if ($this->db->trans_status() === FALSE)
return 0;
}
}
public function get_course_sections($cid)
{
$cse_sql = "SELECT c.course_name, c.id,s.id as section_id, s.section_name from course c inner join course_sections ce on c.id = ce.course_id inner join section s on s.id = ce.section_id where c.id = '$cid' ";
$query = $this->db->query($cse_sql);
if (($query->num_rows() > 0))
return $query->result_array();
}
public function get_course_subjects($cid)
{
$cs_sql = "SELECT c.course_name, c.id,s.id as subject_id, s.subject_name from course c inner join course_subjects cs on c.id = cs.course_id inner join subject s on s.id = cs.subject_id where c.id = '$cid'";
$query = $this->db->query($cs_sql);
if (($query->num_rows() > 0))
return $query->result_array();
}
public function unselected_subject_section($dataArr, $item)
{
if ($item == 'section') {
$this->db->select('*');
$this->db->from('section');
foreach ($dataArr as $key => $value) {
$this->db->where($value);
}
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
}
} else if ($item == 'subject') {
$this->db->select('*');
$this->db->from('subject');
foreach ($dataArr as $key => $value) {
$this->db->where($value);
}
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
}
}
}
public function check_course_in_classroom($cid)
{
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('course_id', $cid);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$firstResult = $query->result_array();
$classroomNames = array();
foreach ($firstResult as $key => $value) {
$classId = $value['id'];
$classroomQuery = $this->db->query("Select classroom_name from classroom WHERE id = '$classId' GROUP BY classroom_name");
if ($classroomQuery->num_rows() > 0) {
$res = $classroomQuery->result_array();
foreach ($res as $key => $value) {
if (!in_array($value['classroom_name'], $classroomNames)) {
array_push($classroomNames, $value['classroom_name']);
}
}
} else {
return 'Classroom Error';
}
}
return $classroomNames;
} else {
return 'failed';
}
}
public function deleteCourse($cid)
{
$this->db->delete('course', array('id' => $cid));
$this->db->delete('course_sections', array('course_id' => $cid));
$this->db->delete('course_subjects', array('course_id' => $cid));
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
public function update_course_section($newSecId, $secIdArr, $cid)
{
if (!empty($secIdArr)) {
$where = '';
foreach ($secIdArr as $key => $value) {
if ($key == 0) {
$where .= "section_id = '$value'";
} else {
$where .= " or section_id = '$value'";
}
}
$this->db->select('c.id, c.classroom_name, c.section_id');
$this->db->from('classroom c');
$this->db->join('students s', 's.classroom = c.id');
$this->db->where("(" . $where . ")");
$this->db->where('c.course_id', $cid);
$this->db->where('c.id = s.classroom');
$query = $this->db->get();
if ($query->num_rows() > 0) {
$response['classroom-data'] = $query->result_array();
$classroomNamesArr = array_values(array_unique(array_column($response['classroom-data'], "classroom_name")));
dd($classroomNamesArr);
$secArr = array_values(array_unique(array_column($response['classroom-data'], "section_id")));
$secName_where = '';
foreach ($secArr as $key => $value) {
if ($key == 0) {
$secName_where .= "id = '$value'";
} else {
$secName_where .= " or id = '$value'";
}
}
$decQuery = "SELECT section_name from section where " . $secName_where . " GROUP BY section_name;";
$secNamesQuery = $this->get_section_details('', $decQuery);
$secNames = implode(', ', array_column($secNamesQuery, "section_name"));
if (count($secNamesQuery) == 1)
$secNames = $secNamesQuery['section_name'];
$classes = implode(', ', $classroomNamesArr);
if (count($classroomNamesArr) == 1)
$classes = $classroomNamesArr[0];
$response['class-name'] = $classes;
$response['status'] = 'failed';
$response['section-names'] = $secNames;
return $response;
}
}
$this->db->where('course_id', $cid);
$this->db->delete('course_sections');
if ($this->db->affected_rows()) {
foreach ($newSecId as $key => $value) {
$insertData[$key] = array(
'course_id' => $cid,
'section_id' => $value,
'created' => $this->nepali_current_date
);
}
$this->db->trans_start();
$insertUpdatedSections = $this->db->insert_batch('course_sections', $insertData);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
return false;
} else {
return true;
}
} else {
return false;
}
}
public function update_course_subject($newSubId, $cid)
{
$this->db->where('course_id', $cid);
$this->db->delete('course_subjects');
if ($this->db->affected_rows()) {
foreach ($newSubId as $key => $value) {
$insertData[$key] = array(
'course_id' => $cid,
'subject_id' => $value,
'created' => $this->nepali_current_date
);
}
$this->db->trans_start();
$insertUpdatedSubjects = $this->db->insert_batch('course_subjects', $insertData);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE) {
return false;
} else {
return true;
}
} else {
return false;
}
}
// Yogesh Update Offline Exam Is Active
public function update_course_offline_exam($newSubId, $offlineExams, $cid)
{
// echo '<pre>';
// print_r($newSubId);
// print_r('Course Id => ' . $cid);
// print_r($offlineExams);
$data['school_info'] = $this->Admin_model->get_logo_from_setting();
$currentBatch = $data['school_info']['batch_id'];
// print_r($_SESSION);
// Setting all subjects is_active in offline_exam_marks table to no
foreach ($offlineExams as $offlineExam) {
if ($cid == $offlineExam['course_id'] && $currentBatch == $offlineExam['batch_id']) {
$updateData = array(
'is_active' => 'no',
'modified_by' => $_SESSION['admin_id'],
'modified_on' => $this->nepali_current_date,
);
$this->db->where('id', $offlineExam['oem_id']);
$this->db->update('offline_exam_marks', $updateData);
}
}
foreach ($newSubId as $value) {
foreach ($offlineExams as $offlineExam) {
if ($value == $offlineExam['subject_id'] && $currentBatch == $offlineExam['batch_id'] && $cid == $offlineExam['course_id']) {
echo $value . ' => ' . $offlineExam['subject_id'] . ' => Batch ' . $offlineExam['batch_id'] . ' Offline Exam Mark Id = ' . $offlineExam['oem_id'] . ' <br/>';
$updateData = array(
'is_active' => 'yes',
'modified_by' => $_SESSION['admin_name'],
'modified_on' => $this->nepali_current_date,
);
$this->db->where('id', $offlineExam['oem_id']);
$this->db->update('offline_exam_marks', $updateData);
}
}
}
$offlineExams = $this->Admin_model->get_course_offfline_exam($cid);
// var_dump($offlineExams);
// $this->db->where('course_id', $cid);
// $this->db->delete('course_subjects');
// if ($this->db->affected_rows()) {
// foreach ($newSubId as $key => $value) {
// $insertData[$key] = array(
// 'course_id' => $cid,
// 'subject_id' => $value,
// 'created' => $this->nepali_current_date
// );
// }
// $this->db->trans_start();
// $insertUpdatedSubjects = $this->db->insert_batch('course_subjects', $insertData);
// $this->db->trans_complete();
// if ($this->db->trans_status() === FALSE) {
// return false;
// } else {
// return true;
// }
// } else {
// return false;
// }
}
// -- Yogesh
// Course Models Ends 12-10-2021 Afras Khan
// Notification Model 13-10-2021 Afras Khan
public function insertNotificationData($data)
{
$data['created_at'] = $this->nepali_current_date;
$insert_query = $this->db->insert('notifications', $data);
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
public function get_notification_details($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('notifications.notification_id', 'DESC');
$query = $this->db->get('notifications');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
public function getAllNotifications()
{
$this->db->order_by('notification_id', 'DESC');
$this->db->select('*');
$this->db->from('notifications');
$query = $this->db->get();
return $query->result_array();
}
public function getDistinctNotifications()
{
$classroom = $this->db->query('SELECT * FROM notifications GROUP BY student_classroom');
$teacher = $this->db->query('SELECT * FROM notifications GROUP BY teacher_id');
$title = $this->db->query('SELECT * FROM notifications GROUP BY notification_title');
$filterData = array(
'class' => $classroom->result_array(),
'teacher' => $teacher->result_array(),
'title' => $title->result_array(),
);
return $filterData;
}
public function deleteNotification($id)
{
$this->db->where('notification_id', $id);
$this->db->delete('notifications');
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
public function getSingleNotification($id)
{
$query = $this->db->query('SELECT * FROM notifications WHERE notification_id = ' . $id);
if ($query->num_rows() > 0) {
$result = $query->row();
return $result;
} else {
return 'failed';
}
}
public function get_classroomUnique($crid)
{
if (empty($crid)) {
$this->db->group_by('classroom_name');
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('classroom');
$query = $this->db->get();
return $query->result_array();
} else {
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('id', $crid);
$query = $this->db->get();
return $query->row_array();
}
}
public function get_teacherUnique($tid)
{
if (empty($tid)) {
$this->db->group_by('id');
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('teacher');
$this->db->where('is_active', 'yes');
$query = $this->db->get();
return $query->result_array();
} else {
$this->db->select('*');
$this->db->from('teacher');
$this->db->where('id', $tid);
$query = $this->db->get();
return $query->row_array();
}
}
public function getFilterNotifications($name, $class, $teacher, $date)
{
$query = $this->db->query('SELECT * FROM notifications WHERE notification_title = "' . $name . '" OR student_classroom = "' . $class . '" OR teacher_id = "' . $teacher . '" OR date(created_at) = "' . $date . '"');
if ($query->num_rows() > 0) {
$result = $query->result_array();
return $result;
} else {
return 'failed';
}
}
public function getNotificationAPI($id)
{
if (empty($id)) {
$this->db->order_by('notification_id', 'DESC');
$this->db->select('*');
$this->db->from('notifications');
$query = $this->db->get();
return $query->result_array();
} else {
$this->db->select('*');
$this->db->from('notifications');
$this->db->where('notification_id', $id);
$query = $this->db->get();
return $query->row_array();
}
}
public function notification_update_read($nId)
{
$sql = "SELECT * from notifications where notification_id = '$nId' AND notification_read = 'Yes'";
$result = $this->db->query($sql);
if (empty($result->result_array())) {
$data = array('notification_read' => 'Yes');
$this->db->where('notification_id', $nId);
$this->db->update('notifications', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
return true;
}
// Notification Model Ends 13-10-2021 Afras Khan
// shankar code for exam secton 13-10-21
public function get_exam_details($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('exam.id', 'DESC');
$query = $this->db->get('exam');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
public function deleteExam($id)
{
$query = $this->db->query(
'
SELECT exam.id
FROM exam
WHERE ' . $id . ' IN (SELECT exam_id FROM questions where exam_id=' . $id . ')'
);
if ($query->num_rows() > 0) {
return false;
} else {
$this->db->where('id', $id);
$this->db->delete('exam');
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
}
public function add_edit_exam($id, $data)
{
if ($id == 0) {
$this->db->insert('exam', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$this->db->where('id', $id);
$this->db->update('exam', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
// shankar code end for exam secton 13-10-21
/* Admin Role Model Starts 16-10-21 Afras Khan */
public function get_role_details($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('admin_roles.id', 'DESC');
$query = $this->db->get('admin_roles');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
public function add_edit_role($id, $data)
{
if ($id == 0) {
$this->db->insert('admin_roles', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$this->db->where('id', $id);
$this->db->update('admin_roles', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
public function add_edit_role_permissions($id, $data)
{
if ($id == 0) {
$data['modified'] = $this->nepali_current_date;
$this->db->insert('admin_role_permissions', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$checkifExists = $this->get_table_info('admin_role_permissions', array('admin_role_ids' => $id));
if (empty($checkifExists)) {
$permids = array(
'admin_role_ids' => $id,
'menu_ids' => $data['menu_ids']
);
$this->db->insert('admin_role_permissions', $permids);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$data['modified'] = $this->nepali_current_date;
$this->db->where('admin_role_ids', $id);
$this->db->update('admin_role_permissions', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
}
public function delete_role($id)
{
$this->db->delete('admin_roles', array('id' => $id));
$this->db->delete('admin_role_permissions', array('admin_role_ids' => $id));
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
public function get_table_info($table_name, $where = '', $sqlQry = '', $order = 'DESC', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by($table_name . '.id', $order);
$query = $this->db->get($table_name);
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
public function get_table_info_row($table_name, $where = '', $sqlQry = '', $order = 'DESC', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by($table_name . '.id', $order);
$query = $this->db->get($table_name);
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->row_array();
}
/* Admin Role Model Ends 16-10-21 Afras Khan */
/* General functions start for get deatils 18-102021 SHVIU-*/
public function get_general_row_details($table_name, $order_by = 'ASC', $where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by($table_name . '.id', $order_by);
$query = $this->db->get($table_name);
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
if (($query->num_rows() == 1))
return $query->row_array();
}
public function get_general_result_details($table_name, $order_by = 'ASC', $where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by($table_name . '.id', $order_by);
$query = $this->db->get($table_name);
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
return $query->result_array();
}
// General functions Ends for get deatils 18-102021 SHVIU
/* Class Room Start -Shivu */
// public function add_update_classroom($classroom_id, $data)
// {
// if ($classroom_id == 0) {
// $result = $this->db->insert('classroom', $data);
// if (!empty($result))
// return 1;
// else
// return 0;
// } else {
// $this->db->where('id', $classroom_id);
// $result = $this->db->update('classroom', $data);
// if (!empty($result))
// return 2;
// else
// return 0;
// }
// }
public function add_update_classroom($classroom_id, $data)
{
$pre_teacher_subject_info = array();
$flag = true;
if ($classroom_id == 0) {
$userdata = array('course_id' => $data['course_id'], 'section_id' => $data['section_id'], 'classroom_name' => $data['classroom_name'], 'created' => $this->nepali_current_date, 'modified' => $this->nepali_current_date);
$this->db->insert('classroom', $userdata);
$insert_id = $this->db->insert_id();
for ($i = 0; $i < count($data['classroom_subjects']); $i++) {
$subjects_teachers = array(
'classroom_id' => $insert_id,
'subject_id' => $data['classroom_subjects'][$i],
'teacher_id' => $data['classroom_teacher'][$i]
);
$exists = $this->db->get_where('classroom_teacher_subject', $subjects_teachers)->row();
if (empty($exists)) {
$subjects_teachers['created'] = $this->nepali_current_date;
$result = $this->db->insert('classroom_teacher_subject', $subjects_teachers);
if (!$result) {
$flag = false;
}
} else {
$pre_teacher_subject_info[] = $subjects_teachers;
}
}
if ($flag)
return 1;
else
return 0;
} else {
$userdata = array(
'course_id' => $data['course_id'],
'section_id' => $data['section_id'],
'classroom_name' => $data['classroom_name'],
'is_active' => $data['is_active'],
'modified' => $this->nepali_current_date
);
$afftectedRows = 0;
echo '<pre>';
for ($i = 0; $i < count($data['subject_id']); $i++) {
$teacher_arr = array('teacher_id' => $data['teacher_id'][$i]);
// if ($data['teacher_id'][$i] == $data['isClassTeacher'][0]) {
// $teacher_arr['is_class_teacher'] = 'yes';
// } else {
// $teacher_arr['is_class_teacher'] = 'no';
// }
$teacher_arr['modified'] = $this->nepali_current_date;
// print_r($data['teacher_id'][$i]);
// print_r($teacher_arr);
// exit();
$rowcount = $this->db->get_where('classroom_teacher_subject', array('classroom_id' => $classroom_id, 'subject_id' => $data['subject_id'][$i]))->result_array();
if (count($rowcount) > 0) {
$this->db->where(array(
'classroom_id' => $classroom_id, 'subject_id' => $data['subject_id'][$i]
));
$result = $this->db->update('classroom_teacher_subject', $teacher_arr);
} else {
$teacher_subject_arr = array('classroom_id' => $classroom_id, 'subject_id' => $data['subject_id'][$i], 'teacher_id' => $data['teacher_id'][$i], 'created' => $this->nepali_current_date, 'modified' => $this->nepali_current_date);
$result = $this->db->insert('classroom_teacher_subject', $teacher_subject_arr);
}
$afftectedRows = $this->db->affected_rows();
}
$this->db->where('id', $classroom_id);
$result = $this->db->update('classroom', $userdata);
$afftectedRows1 = $this->db->affected_rows();
$affected = ($afftectedRows1 != 0) ? $afftectedRows1 : $afftectedRows;
if ($affected > 0)
return 2;
else
return 3;
}
}
public function get_filterstudents()
{
$this->db->select('*')->from('students');
$this->db->where('is_active', 'yes');
$this->db->where('assign_status', 'no');
$this->db->order_by('id', 'desc');
$query = $this->db->get();
return $query->result_array();
}
public function insert_assign_classroom($insertData)
{
$insertData['created'] = $this->nepali_current_date;
$this->db->insert('student_batch', $insertData);
$insert_id = $this->db->insert_id();
return $insert_id;
}
/* classroom by shivu */
/* User Module Starts */
public function add_edit_users($id, $data)
{
if ($id == 0) {
$this->db->insert('admin', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$this->db->where('id', $id);
$this->db->update('admin', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
public function delete_user($id)
{
$this->db->delete('admin', array('id' => $id));
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
/* User Module Ends */
// SHANKAR CODE OF EXAM CREATION START FROM HERE 20-10-2021
public function get_exam_name()
{
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('exam');
$this->db->where('is_active', 'yes');
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result_array();
}
public function get_sections_from_classroom($id)
{
$this->db->select('section.id, section_name');
$this->db->from('course_sections ,section');
$this->db->where('course_sections.course_id', $id);
$this->db->where('course_sections.section_id = section.id');
$this->db->where('section.is_active', 'yes');
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result_array();
}
public function get_subject_teachers($subject_id)
{
// dd($subject_id);
$this->db->select('teacher.id, teacher_name');
$this->db->from('teacher ,teacher_subjects');
$this->db->where('teacher_subjects.subject_id', $subject_id);
$this->db->where('teacher_subjects.is_active', 'yes');
$query = $this->db->get();
$teacher_query = "SELECT ts.teacher_id ,ts.subject_id, ts.is_active FROM teacher_subjects ts WHERE ts.is_active='yes' AND ts.subject_id=$subject_id";
$teacherList = $this->Admin_model->get_query_result($teacher_query);
//echo $this->db->last_query();
// return $teacher_query->result_array();
return $teacherList;
}
public function get_subjects_from_course($course_id)
{
$this->db->select('subject.id, subject_name');
$this->db->from('subject ,course_subjects');
$this->db->where('course_subjects.course_id', $course_id);
$this->db->where('subject.id = course_subjects.subject_id');
$this->db->where('subject.is_active', 'yes');
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result_array();
}
public function get_teacher_from_subject($course_id, $sec_id, $sub_id)
{
$this->db->select('teacher.id, teacher_name');
$this->db->from('teacher ,classroom_teacher_subject, classroom');
$this->db->where('classroom.course_id', $course_id);
$this->db->where('classroom.section_id', $sec_id);
$this->db->where('classroom_teacher_subject.classroom_id = classroom.id');
$this->db->where('classroom_teacher_subject.subject_id', $sub_id);
$this->db->where('teacher.id = classroom_teacher_subject.teacher_id');
$this->db->where('teacher.is_active', 'yes');
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result_array();
}
// shankar code end
public function add_exam_exam_paper($id, $data)
{
if ($id == 0) {
$this->db->insert('questions', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$this->db->where('id', $id);
$this->db->update('questions', $data);
if ($this->db->trans_status() === FALSE) {
$this->db->where('exam_id', $id);
$this->db->delete('exam_questions');
if ($this->db->affected_rows())
return 0;
}
return true;
}
}
public function get_all_questions($s_date = '', $e_date = '', $course_id = '', $que_id = '')
{
$this->db->select('questions.id as question_id,course_name ,questions.section_id,questions.exam_duration, exam.e_name,classroom.classroom_name,subject.subject_name,teacher.teacher_name, questions.total_marks,questions.exam_date,questions.exam_starttime, questions.exam_endtime,questions.passing_marks, questions.exam_id, questions.course_id,questions.subject_id, questions.teacher_id,questions.exam_question_format');
$this->db->from('questions, classroom, subject, teacher, exam, course');
$this->db->where('questions.subject_id = subject.id');
$this->db->where('questions.teacher_id = teacher.id');
$this->db->where('questions.exam_id = exam.id');
// $this->db->where('questions.course_id = subject_syllabus.course_id');
// $this->db->where('questions.subject_id = subject_syllabus.subject_id');
$this->db->where('questions.course_id = classroom.course_id');
$this->db->where('questions.course_id = course.id');
if ($que_id != '' && !empty($que_id))
$this->db->where('questions.id', $que_id);
if (!empty($course_id) && $course_id != '')
$this->db->where('questions.course_id', $course_id);
if ($s_date != '' && $e_date == '')
$this->db->where('exam_date >', $s_date);
if ($e_date != '' && $s_date == '')
$this->db->where('exam_date <', $s_date);
if ($s_date != '' && $e_date != '') {
$this->db->where("exam_date BETWEEN '$s_date' AND '$e_date'");
}
$this->db->where('questions.is_active', 'yes');
$this->db->group_by('questions.id');
$this->db->order_by('questions.id', 'DESC');
$query = $this->db->get();
// echo $this->db->last_query();
if ($que_id != 0) {
return $query->row_array();
} else {
return $query->result_array();
}
}
// SHANKAR CODE OF EXAM CREATION END HERE 20-10-2021
/* Forgot Password Model - Afras Khan 23/10/2021 */
public function update_admin_password($id, $data)
{
$data['modified'] = $this->nepali_current_date;
$this->db->where('id', $id);
$this->db->update('admin', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
public function delete_row($table, $condtion)
{
$this->db->where($condtion);
$this->db->delete($table);
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
// SHANKAR CODE OF EXAM CREATION start HERE 27-10-2021
public function get_course_subjects_teacher($tid, $count = '')
{
$this->db->select('cts.teacher_id,cts.classroom_id, cl.classroom_name, cl.course_id, co.course_name, cts.subject_id, s.subject_name');
$this->db->from(' classroom cl,classroom_teacher_subject cts, subject s, course co');
$this->db->where('cts.teacher_id', $tid);
$this->db->where('cts.subject_id = s.id');
$this->db->where('cts.classroom_id = cl.id');
$this->db->where('cl.course_id = co.id');
if ($count == 1) {
$this->db->group_by('cl.classroom_name');
}
$query = $this->db->get();
// echo $this->db->last_query();
return $query->result_array();
}
// SHANKAR CODE OF EXAM CREATION END HERE 27-10-2021
// online session start by shivu
public function createMeetingLink($details)
{
$durationInMinute = $details['duration'];
$Byday = $details['day'];
$startTime = $details['start'];
$classroom_session_id = $details['sessid'];
$duration = date('H:i', strtotime('+' . $durationInMinute . 'minutes', strtotime($startTime)));
$teacherID = (!empty($details['sub_teacher_id'])) ? $details['sub_teacher_id'] : 0;
$today = date('Y-m-d', strtotime($this->nepali_current_date));
// (start >= '10:10' OR end <= '10:20')
$checkteacherResult = $this->db->query("SELECT sd.* FROM session_details sd JOIN classroom_session cs ON cs.id =sd.session_id WHERE (DATE('$today') BETWEEN cs.start_date AND cs.end_date) AND ('$startTime' BETWEEN sd.start AND sd.end) AND sd.day='$Byday' AND sd.teacher_id=$teacherID ")->result_array();
// $checkteacherResult=$this->db->query("SELECT sd.* FROM session_details sd JOIN classroom_session cs ON cs.id =sd.session_id WHERE (DATE('$today') BETWEEN cs.start_date AND cs.end_date) AND (sd.start >= '$startTime' OR sd.end <= '$duration') AND sd.day='$Byday' AND sd.teacher_id=$teacherID ")->result_array();
$checkTeacher = (!empty($checkteacherResult)) ? count($checkteacherResult) : 0;
if ($checkTeacher === 0) {
$sqlquery = "SELECT * FROM session_details WHERE ('$startTime' BETWEEN start AND end) AND day='$Byday' AND session_id='$classroom_session_id'";
$rst = $this->Admin_model->get_query_result($sqlquery);
$CheckClass = (isset($rst) && !empty($rst)) ? count($rst) : 0;
if ($CheckClass == 0) {
$details['end'] = $duration;
$data_array = array(
'session_id' => $details['sessid'],
'teacher_id' => $details['sub_teacher_id'],
'subject_id' => $details['subject'],
'start' => $details['start'],
'duration' => $details['duration'],
'join_link' => $details['join_link'],
'start_link' => $details['start_link'],
'day' => $details['day'],
'end' => $details['end'],
'password' => 'test'
);
$insert = $this->db->insert('session_details', $data_array);
$id = (!empty($insert)) ? $this->db->insert_id() : 0;
if ($id > 0)
return "success";
else
return "failed";
} else {
return "exists";
}
} else {
return "teacher_exists";
}
}
public function get_classroomlist()
{
$this->db->select('*');
$this->db->from('classroom');
$this->db->where('is_active', 'yes');
$this->db->group_by('classroom_name');
$query = $this->db->get();
return $query->result_array();
}
public function get_classsession($id)
{
$this->db->select('*');
$this->db->from('classroom_session');
$this->db->where('is_active', 'yes');
$this->db->where('id', $id);
$query = $this->db->get();
return $query->result_array();
}
public function get_classsessiononday($id, $day)
{
$this->db->select('*');
$this->db->from('session_details');
$this->db->where('session_id', $id);
$this->db->where('day', $day);
$this->db->order_by('start', 'ASC');
$query = $this->db->get();
$result = $query->result_array();
if ($result != '') {
return $result;
} else {
return 0;
}
}
public function get_allsession()
{
$this->db->select('cls.id,cls.start_date,cls.end_date,cls.number_session,cl.classroom_name,cls.batch_id');
$this->db->from('classroom_session as cls');
$this->db->join('classroom as cl', 'cl.id = cls.classroom_id', 'left');
$this->db->where('cls.is_active', 'yes');
$query = $this->db->get();
return $query->result_array();
}
public function add_classsession($details)
{
if ($details['id'] == 0) {
$details['created'] = $this->nepali_current_date;
$details['modified'] = $this->nepali_current_date;
$this->db->insert('classroom_session', $details);
$id = $this->db->insert_id();
return $id;
} else {
$details['modified'] = $this->nepali_current_date;
$this->db->where('id', $details['id']);
$this->db->update('classroom_session', $details);
if ($this->db->affected_rows() > 0) {
return $details['id'];
} else {
return 0;
}
}
}
public function updateMeetingLink($details)
{
$durationInMinute = $details['duration'];
$Byday = $details['day'];
$startTime = $details['start'];
$classroom_session_id = $details['sessid'];
$session_details_id = $details['mid'];
$duration = date('H:i', strtotime('+' . $durationInMinute . 'minutes', strtotime($startTime)));
// $duration = date('H:i', strtotime('+' . $durationInMinute . 'minutes', strtotime($startTime)));
$today = date('Y-m-d', strtotime($this->nepali_current_date));
$teacherID = (!empty($details['sub_teacher_id'])) ? $details['sub_teacher_id'] : 0;
// echo "SELECT sd.* FROM session_details sd JOIN classroom_session cs ON cs.id =sd.session_id WHERE (sd.id != $session_details_id AND (DATE('$today') BETWEEN cs.start_date AND cs.end_date)) AND (('$startTime' BETWEEN sd.start AND sd.end) AND sd.day='$Byday') AND sd.teacher_id=$teacherID";
// exit;
$checkteacherResult = $this->db->query("SELECT sd.* FROM session_details sd JOIN classroom_session cs ON cs.id =sd.session_id WHERE (sd.id != $session_details_id AND (DATE('$today') BETWEEN cs.start_date AND cs.end_date)) AND (('$startTime' BETWEEN sd.start AND sd.end) AND sd.day='$Byday') AND sd.teacher_id=$teacherID ")->result_array();
// dd($checkteacherResult);
$checkTeacher = (!empty($checkteacherResult)) ? count($checkteacherResult) : 0;
if ($checkTeacher === 0) {
$sqlquery = "SELECT * FROM session_details WHERE ('$startTime' BETWEEN start AND end) AND day='$Byday' AND session_id='$classroom_session_id' AND id !=$session_details_id";
$rst = $this->Admin_model->get_query_result($sqlquery);
$CheckClass = (isset($rst) && !empty($rst)) ? count($rst) : 0;
if ($CheckClass == 0) {
$details['end'] = $duration;
$data_array = array(
'subject_id' => $details['subject'],
'start' => $details['start'],
'teacher_id' => $details['sub_teacher_id'],
'duration' => $details['duration'],
'join_link' => $details['join_link'],
'start_link' => $details['start_link'],
'end' => $details['end'],
'password' => 'test'
);
$this->db->where(array('id' => $details['mid'], 'session_id' => $classroom_session_id, 'day' => $details['day']));
$result = $this->db->update('session_details', $data_array);
// print_r($result);
// die();
$id = (!empty($result)) ? $details['sessid'] : 0;
if ($id > 0)
return 'success';
else
return 'failed';
} else {
return 'exists';
}
} else {
return "teacher_exists";
}
}
public function get_teacher_onlinesession($teacher_id)
{
$sqlQry = "SELECT cl.classroom_name,cts.classroom_id,cts.subject_id,cts.teacher_id,s.subject_name,cls.id as cl_session_id, sd.* FROM classroom_teacher_subject cts
LEFT JOIN classroom_session cls ON cls.classroom_id=cts.classroom_id
LEFT JOIN classroom cl ON cl.id = cts.classroom_id
LEFT JOIN session_details sd ON sd.session_id=cls.id AND sd.subject_id=cts.subject_id
LEFT JOIN subject s ON s.id=cts.subject_id
WHERE cts.teacher_id=$teacher_id ORDER BY sd.start ASC";
$query = $this->db->query($sqlQry);
return $query->result_array();
}
// Fee Course - Afras Khan - 11/11/2021
public function add_edit_fee_course($id, $data)
{
if ($id == 0) {
$this->db->insert('course_fees', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$this->db->where('id', $id);
$this->db->update('course_fees', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
public function delete_course_fees($id)
{
$this->db->delete('course_fees', array('id' => $id));
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
// Fee Course End - Afras Khan - 11/11/2021
// delete subject by shivakumar -start
public function delete_subject($subject_id)
{
$status = '';
// $result = $this->get_general_result_details('subject_syllabus', 'ASC', array('subject_id' => $subject_id));
// if (count($result) != 0) {
// $status = "exists";
// } else {
$result1 = $this->get_general_result_details('course_subjects', 'ASC', array('subject_id' => $subject_id));
if (count($result1) != 0) {
$status = "exists";
} else {
$result2 = $this->get_general_result_details('classroom_teacher_subject', 'ASC', array('subject_id' => $subject_id));
if (count($result2) != 0) {
$status = "exists";
} else {
$rst = $this->db->delete('subject', array('id' => $subject_id));
if ($rst) {
$status = "success";
} else {
$status = "failed";
}
}
}
// }
return $status;
}
// delete subject by shivakumar -end
// Fee Installments - Afrs Khan - 11/17/21
public function add_edit_table($table, $id, $data)
{
if ($id == 0) {
$this->db->insert($table, $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$this->db->where('id', $id);
$this->db->update($table, $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
public function delete_course_installment($id)
{
$this->db->delete('installment', array('id' => $id));
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
// Fee Installments End - Afras Khan
// Students Files Update - Afras Khan
public function update_student_files($data, $id)
{
$this->db->where('id', $id);
$this->db->update('students', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
// Students Files Update - Afras Khan
// batch delete process - shivakumar -> start
public function delete_batch($batch_id)
{
$status = '';
$result1 = $this->get_general_result_details('applications', 'ASC', array('batch_id' => $batch_id));
if (count($result1) != 0) {
$status = "exists";
} else {
$result2 = $this->get_general_result_details('course_fees', 'ASC', array('batch_id' => $batch_id));
if (count($result2) != 0) {
$status = "exists";
} else {
$result3 = $this->get_general_result_details('student_batch', 'ASC', array('batch_id' => $batch_id));
if (count($result3) != 0) {
$status = "exists";
} else {
$rst = $this->db->delete('batch', array('id' => $batch_id));
if ($rst) {
$status = "success";
} else {
$status = "failed";
}
}
}
}
return $status;
}
// batch delete process -shivakumar -> end
// online session delete process by shivakumar start
public function delete_onlinesession($ClassroomSessionId)
{
$status = '';
$result1 = $this->get_general_result_details('session_details', 'ASC', array('session_id' => $ClassroomSessionId));
if (count($result1) != 0) {
$status = "exists";
} else {
$rst = $this->db->delete('classroom_session', array('id' => $ClassroomSessionId));
if ($rst) {
$status = "success";
} else {
$status = "failed";
}
}
return $status;
}
// online session delete process by shivakumar end
// Report section - start -by shivakumar
public function currentMonth_fee($start_date, $last_date, $feetype)
{
$sql = "Select s.id,s.name,s.batch_id,cf.course_id,cf.fees_type,cf.amount as fee_amount, (cf.amount * (SELECT COUNT(*) from students where course = s.course AND batch_id = s.batch_id)) as total_amount,DATE(cf.due_date) as cf_due_date, sop.payment_details from students s
INNER JOIN course_fees cf on s.batch_id = cf.batch_id
LEFT JOIN students_online_payments sop on sop.student_id = s.id AND sop.course_fee_id = cf.id
WHERE s.course = cf.course_id
AND cf.fees_type = $feetype
GROUP BY s.id";
$complete_query = $this->db->query($sql)->result_array();
if (!empty($complete_query)) {
// $total_amount = array_sum(array_unique(array_column($complete_query, 'total_amount')));
$paid_amount = 0;
$total_amount = 0;
$due_amount = 0;
foreach ($complete_query as $key => $value) {
if (!empty($value['payment_details'])) {
$decoded = json_decode($value['payment_details']);
// dd($decoded);
foreach ($decoded as $index => $ele) {
$monthStartDate = date('Y-m-d', strtotime($start_date));
$monthEndDate = date('Y-m-d', strtotime($last_date));
$paymentDate = date('Y-m-d', strtotime($ele->due_date));
if ($ele->payment_status == 'yes') {
if (($paymentDate >= $monthStartDate) && ($paymentDate <= $monthEndDate)) {
$paid_amount = $paid_amount + (int)$ele->paid_amount;
$total_amount = $total_amount + (int)$ele->paid_amount;
}
} else {
if ((date('Y-m-d', strtotime($ele->paid_date)) >= $monthStartDate) && (date('Y-m-d', strtotime($ele->paid_date)) <= $monthEndDate)) {
$due_amount = $due_amount + (int)$ele->paid_amount;
$total_amount = $total_amount + (int)$ele->paid_amount;
}
}
}
} else {
// $total_amount = $total_amount + $value['fee_amount'];
// $due_amount = $due_amount + $value['fee_amount'];
$present_month = date('m', strtotime($this->nepali_current_date));
$due_month = date('m', strtotime($value['cf_due_date']));
if ($present_month == $due_month) {
$total_amount = $total_amount + $value['fee_amount'];
$due_amount = $due_amount + $value['fee_amount'];
}
}
}
$res = array(
'total_course_fee' => $total_amount,
'pending_fee' => $due_amount,
'paid_amount' => $paid_amount
);
// dd($res);
return $res;
} else {
return $res = array(
'total_course_fee' => 0,
'pending_fee' => 0,
'paid_amount' => 0
);
}
}
public function get_monthdata($values, $start_date, $current_date)
{
$paid_array = array();
$due_array = array();
for ($i = $start_date; $i <= $current_date; $i += 86400) {
$find = date('Y-m-d', $i);
foreach ($values as $row_key => $row_value) {
$paid_date = date('Y-m-d', strtotime($row_value->paid_date));
$due_date = date('Y-m-d', strtotime($row_value->due_date));
if ($row_value->payment_status == 'yes') {
if ($paid_date == $find) {
$paid_array[] = $row_value;
}
} else {
if ($due_date == $find) {
$due_array[] = $row_value;
}
}
}
}
$data['paidamt'] = $paid_array;
$data['dueamt'] = $due_array;
return $data;
}
public function get_currentmonthfee($startdate, $enddate, $feetype_name, $table)
{
$sqlQuery = "SELECT SUM(payment_amt) as total_amt FROM $table WHERE DATE(payment_date) BETWEEN '$startdate' AND '$enddate' AND status='Completed' AND payment_for LIKE '$feetype_name'";
$result = $this->Admin_model->get_query_row($sqlQuery);
return (isset($result) && !empty($result)) ? $result['total_amt'] : 0;
}
public function get_application_fee($feeTypeName)
{
$sqlQuery = "SELECT stf.*,a.name,a.course,a.photo,a.payment_status FROM student_fee_online_transactions stf LEFT JOIN applications a ON stf.studentId = a.applicationid WHERE stf.payment_for LIKE '%$feeTypeName%' ORDER BY stf.id DESC";
return $this->get_query_result($sqlQuery);
}
public function get_student_fee($feeTypeName)
{
$sqlQuery = "SELECT stf.*,s.name,s.course,s.photo,s.payment_status FROM student_fee_online_transactions stf LEFT JOIN students s ON stf.studentId = s.studentId WHERE stf.payment_for LIKE '%$feeTypeName%' ORDER BY stf.id DESC";
return $this->get_query_result($sqlQuery);
}
public function get_payment_by_filter($search, $feesTypeName)
{
$courseId = (isset($search['course_id']) && !empty($search['course_id'])) ? $search['course_id'] : 0;
$start_date = (isset($search['start_date']) && !empty($search['start_date'])) ? $search['start_date'] : date('y-m-01');
$end_date = (isset($search['end_date']) && !empty($search['end_date'])) ? $search['end_date'] : date('y-m-t');
$by_payment_status = (isset($search['by_payment_status']) && !empty($search['by_payment_status'])) ? $search['by_payment_status'] : '';
// $feesTypeName = $this->db->get_where('fee_types', array('id' => $feesTypeId))->row()->feetype_name;
return $this->getapplicationFeesByFilter($feesTypeName, $courseId, $start_date, $end_date, $by_payment_status);
}
public function getapplicationFeesByFilter($feesTypeName, $courseId, $start_date = null, $end_date = null, $by_payment_status = null)
{
$q = "";
if ($courseId != 0)
$q .= " AND a.course='" . $courseId . "'";
if ($start_date != null && $end_date != null)
$q .= " AND date(stf.payment_date) BETWEEN '$start_date' AND '$end_date'";
if ($by_payment_status != null)
$q .= " AND stf.status='$by_payment_status'";
$sqlQuery = "SELECT stf.*,a.name,a.course,a.photo,a.payment_status FROM student_fee_online_transactions stf LEFT JOIN applications a ON stf.studentId = a.applicationid WHERE stf.payment_for LIKE '%$feesTypeName%' $q ORDER BY stf.id DESC";
return $this->get_query_result($sqlQuery);
}
public function get_payment_by_filter_student($search, $feesTypeName)
{
$courseId = (isset($search['course_id']) && !empty($search['course_id'])) ? $search['course_id'] : 0;
$start_date = (isset($search['start_date']) && !empty($search['start_date'])) ? $search['start_date'] : date('y-m-01');
$end_date = (isset($search['end_date']) && !empty($search['end_date'])) ? $search['end_date'] : date('y-m-t');
$by_payment_status = (isset($search['by_payment_status']) && !empty($search['by_payment_status'])) ? $search['by_payment_status'] : '';
return $this->getStudentFeesByFilter($feesTypeName, $courseId, $start_date, $end_date, $by_payment_status);
}
public function getStudentFeesByFilter($feesTypeName, $courseId, $start_date = null, $end_date = null, $by_payment_status = null)
{
$q = "";
if ($courseId != 0)
$q .= " AND s.course='" . $courseId . "'";
if ($start_date != null && $end_date != null)
$q .= " AND date(stf.payment_date) BETWEEN '$start_date' AND '$end_date'";
if ($by_payment_status != null) {
if ($by_payment_status == 'Completed')
$q .= " AND stf.status='Completed'";
else
$q .= " AND stf.status !='Completed'";
}
$sqlQuery = "SELECT stf.*,s.name,s.course,s.photo,s.payment_status FROM student_fee_online_transactions stf LEFT JOIN students s ON stf.studentId = s.studentId WHERE stf.payment_for LIKE '%$feesTypeName%' $q ORDER BY stf.id DESC";
return $this->get_query_result($sqlQuery);
}
public function getstudentRow($studentId)
{
$this->db->select('course.course_name,section.section_name,classroom.classroom_name,students.id,students.qr_code,students.emergency_contact_name,students.emergency_contact_number,students.studentId,course_name,photo,email,mobile,name,registered_on,dob,gender,address1,address2,state,country,zipcode,exam_result,medical_cerificate,school_certificate,students.batch_id');
$this->db->from('students');
$this->db->join('student_batch', 'student_batch.student_id=students.id AND student_batch.batch_id=students.batch_id');
$this->db->join('classroom', 'student_batch.classroom_id=classroom.id');
$this->db->join('course', 'classroom.course_id = course.id');
$this->db->join('section', 'classroom.section_id = section.id');
$this->db->where('students.id', $studentId);
$this->db->order_by("student_batch.id", "desc");
$query = $this->db->get();
return $query->row_array();
}
// Report section - end -by shivakumar
public function delete_test_exam_question($id)
{
$query = $this->db->query(
'
SELECT questions.id
FROM questions
WHERE ' . $id . ' IN (SELECT exam_id FROM exam_questions where exam_id=' . $id . ')'
);
if ($query->num_rows() > 0) {
return false;
} else {
$this->db->where('id', $id);
$this->db->delete('questions');
if ($this->db->affected_rows()) {
return true;
} else {
return false;
}
}
}
public function get_courses()
{
$this->db->select('*');
$this->db->from('course');
$this->db->where('is_active', 'yes');
$this->db->order_by('course_name', 'ASC');
$query = $this->db->get();
return $query->result_array();
}
//shankar code
public function get_batch()
{
$this->db->select('*');
$this->db->from('batch');
$this->db->where(array('is_active' => 'yes'));
$this->db->order_by('id', 'DESC');
$query = $this->db->get();
return $query->result_array();
}
//end shankar code
public function add_applicationinfo($data)
{
$inf = $data['sinfo'];
$photo = $data['photo'];
$medical = $data['medical'];
$school = $data['school'];
$exam = $data['exam'];
$this->db->select_max('id');
$query = $this->db->get('applications');
$res = $query->row_array();
$pid = $res['id'] + 1;
// if (strlen($pid) == 1)
// $pid = "000" . $pid;
// else if (strlen($pid) == 2)
// $pid = "00" . $pid;
// else if (strlen($pid) == 3)
// $pid = "0" . $pid;
// $applicationid = STUDENT_APPLICATION_PREFIX . date('Y',strtotime($this->nepali_current_date)) . $pid;
$school_info = $this->get_logo_from_setting();
$school_prefix = (!empty($school_info['school_prefix_id'])) ? $school_info['school_prefix_id'] : 'BB';
$applicationid = $school_prefix . STUDENT_APPLICATION_PREFIX . date('Ymd', strtotime($this->nepali_current_date)) . '0' . $pid;
$indata = array(
'name' => $inf['sfname'] . ' ' . $inf['ssname'],
'applicationid' => $applicationid,
'email' => $inf['semail'],
'mobile' => $inf['scontact'],
'password' => md5($inf['spaswd']),
'gender' => $inf['sgender'],
'dob' => $inf['sdob'],
'course' => $inf['scourse'],
'batch_id' => $inf['sbatch'],
'emergency_contact_name' => $inf['semfname'] . ' ' . $inf['semlname'],
'emergency_contact_number' => $inf['semphone'],
'country' => $inf['scountry'],
'state' => $inf['sstate'],
'address1' => $inf['saddress1'],
'address2' => $inf['saddress2'],
'zipcode' => $inf['szipcode'],
'school_certificate' => $school,
'exam_result' => $exam,
'photo' => $photo,
'medical_cerificate' => $medical,
'payment_method' => $inf['payment_method'],
'description' => (isset($inf['description']) && !empty($inf['description'])) ? $inf['description'] : '',
'registered_on' => date('Y-m-d', strtotime($this->nepali_current_date))
);
$insert = $this->db->insert('applications', $indata);
$newId = $this->db->insert_id();
$result = (!empty($newId)) ? $newId : 0;
return $result;
}
public function storefeeTransaction($data)
{
$data['created'] = $this->nepali_current_date;
$data['modified'] = $this->nepali_current_date;
$result = $this->db->insert('student_fee_online_transactions', $data);
if (!empty($result))
return $result;
else
return 0;
}
public function applications_get($data, $feestyId)
{
$courseId = (isset($data['course']) && !empty($data['course'])) ? $data['course'] : 0;
$batchId = (isset($data['batch_id']) && !empty($data['batch_id'])) ? $data['batch_id'] : 0;
$this->db->select('*');
$this->db->from('course_fees');
$this->db->where('course_id', $courseId);
$this->db->where('batch_id', $batchId);
$this->db->where('fees_type', $feestyId);
$query = $this->db->get();
return $query->row_array();
}
public function installment_get($course)
{
$this->db->select('*');
$this->db->from('installment');
$this->db->where('course_id', $course);
$query = $this->db->get();
return $query->result_array();
}
public function install_get($install_type_id)
{
$this->db->select('*');
$this->db->from('installment');
$this->db->where('id', $install_type_id);
$query = $this->db->get();
return $query->row_array();
}
// Moving application info to students -start - by shivakumar
public function applicationinfo_movingto_students($applicationId, $parentId = null)
{
$this->db->select('*');
$this->db->from('applications');
$this->db->where('applicationid', $applicationId);
$query = $this->db->get();
$res = $query->row_array();
$appdata = (!empty($res)) ? $res : 0;
if ($appdata != 0) {
if ($appdata['status'] == 'moved') {
return -1;
} else {
$this->db->select_max('id');
$query = $this->db->get('students');
$resid = $query->row_array();
$resid = (isset($resid['id']) && !empty($resid['id'])) ? $resid['id'] : 0;
$studentMaxId = $resid + 1;
$pid = date('Y', strtotime($this->nepali_current_date)) . '0' . $studentMaxId;
// if (strlen($studentMaxId) == 1)
// $pid = "00000" . $studentMaxId;
// else if (strlen($studentMaxId) == 2)
// $pid = "0000" . $studentMaxId;
// else if (strlen($studentMaxId) == 3)
// $pid = "000" . $studentMaxId;
// else if (strlen($studentMaxId) == 4)
// $pid = "00" . $studentMaxId;
// else if (strlen($studentMaxId) == 5)
// $pid = "00" . $studentMaxId;
$school_info = $this->get_logo_from_setting();
$school_prefix = (!empty($school_info['school_prefix_id'])) ? $school_info['school_prefix_id'] : 'BB';
$studentid = $school_prefix . STUDENT_PREFIX . $pid;
$parent_id = '';
if ($parentId) {
$parent_id = $parentId;
} else {
$parent_id = $school_prefix . STUDENT_PARENT_PREFIX . $pid;
}
$qr_path = $this->generate_qrcode($studentid);
$insertdata = array(
'id' => $studentMaxId,
'name' => $appdata['name'],
'studentId' => $studentid,
'course' => $appdata['course'],
'batch_id' => $appdata['batch_id'],
'email' => $appdata['email'],
'password' => $appdata['password'],
'mobile' => $appdata['mobile'],
'gender' => $appdata['gender'],
'dob' => $appdata['dob'],
'emergency_contact_name' => $appdata['emergency_contact_name'],
'emergency_contact_number' => $appdata['emergency_contact_number'],
'country' => $appdata['country'],
'state' => $appdata['state'],
'address1' => $appdata['address1'],
'address2' => $appdata['address2'],
'zipcode' => $appdata['zipcode'],
'photo' => $appdata['photo'],
'school_certificate' => $appdata['school_certificate'],
'exam_result' => $appdata['exam_result'],
'medical_cerificate' => $appdata['medical_cerificate'],
'payment_status' => $appdata['payment_status'],
'registered_on' => date('Y-m-d H:i:s', strtotime($this->nepali_current_date)),
'assign_status' => 'no',
'qr_code' => $qr_path,
'parent_username' => $parent_id,
'parent_password' => md5($parent_id),
'is_active' => 'yes',
'modified' => $this->nepali_current_date
);
$insert = $this->db->insert('students', $insertdata);
if ($insert) {
$update = array(
'status' => 'moved',
);
$this->db->where('applicationid', $applicationId);
$this->db->update('applications', $update);
return $studentMaxId;
} else {
return "failed";
}
}
}
}
public function generate_qrcode($studentID)
{
$hex_data = date('YmdHis') . '-' . $studentID;
$save_name = $hex_data . '.png';
$dir = 'assets_student/studentqrcode/';
if (!file_exists($dir)) {
mkdir($dir, 0775, true);
}
/* QR Configuration */
$config['cacheable'] = true;
$config['imagedir'] = $dir;
$config['quality'] = true;
$config['size'] = '1024';
$config['black'] = array(255, 255, 255);
$config['white'] = array(255, 255, 255);
$this->ciqrcode->initialize($config);
/* QR Data */
$params['data'] = $studentID;
$params['level'] = 'L';
$params['size'] = 10;
$params['savename'] = $config['imagedir'] . $save_name;
$result = $this->ciqrcode->generate($params);
return $result;
}
public function update_table($id, $data, $table)
{
$this->db->trans_start();
$this->db->where('id', $id);
$this->db->update($table, $data);
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
public function insert_data($table, $data)
{
$this->db->insert($table, $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
}
public function getbatchlist()
{
$sql = $this->db->query("SELECT * FROM batch WHERE is_active='yes' ORDER BY id DESC");
if ($sql->num_rows() > 0) {
$res = $sql->result_array();
}
return $res;
}
public function getclassroomlist()
{
$sql = $this->db->query("SELECT * FROM classroom WHERE is_active='yes' ORDER BY id DESC");
if ($sql->num_rows() > 0) {
$res = $sql->result_array();
}
return $res;
}
public function getcourselist()
{
$sql = $this->db->query("SELECT * FROM course WHERE is_active='yes' ORDER BY id DESC");
if ($sql->num_rows() > 0) {
$res = $sql->result_array();
}
return $res;
}
public function getexamlist()
{
$sql = $this->db->query("SELECT * FROM exam WHERE is_active='yes' ORDER BY id DESC");
if ($sql->num_rows() > 0) {
$res = $sql->result_array();
}
return $res;
}
public function getteacherRow($teacherId)
{
$sql = "SELECT * FROM teacher WHERE is_active='yes' AND id='$teacherId'";
return $this->get_query_row($sql);
}
public function get_students_suspend($s_date = '', $e_date = '', $course_id = '')
{
$this->db->order_by('id', 'DESC');
$this->db->select('*');
$this->db->from('students');
$this->db->where('is_active', 'no');
$course_id = (int)$course_id;
if (isset($course_id) && !empty($course_id))
$this->db->where('course', $course_id);
if ($s_date != '' && isset($e_date) && !empty($s_date)) {
$s_date = date('Y-m-d', strtotime($s_date));
$this->db->where("DATE(registered_on) >=", $s_date);
}
if ($e_date != '' && isset($e_date) && !empty($e_date)) {
$e_date = date('Y-m-d', strtotime($e_date));
$this->db->where("DATE(registered_on) <=", $e_date);
}
$query = $this->db->get();
return $query->result_array();
}
//application reupload images by shankar
public function application_update_studentsdoc($data)
{
if (isset($data['photo']))
$data_array['photo'] = $data['photo'];
if (isset($data['exam_result']))
$data_array['exam_result'] = $data['exam_result'];
if (isset($data['medical_cerificate']))
$data_array['medical_cerificate'] = $data['medical_cerificate'];
if (isset($data['school_certificate']))
$data_array['school_certificate'] = $data['school_certificate'];
$id = $data['id'];
$check_query = $this->db->get_where('applications', array('id' => $id))->row_array();
if (!empty($data_array)) {
if (strtolower($check_query['status']) == 'moved') {
$check_student = $this->db->get_where('students', array('name' => $check_query['name'], 'course' => $check_query['course'], 'batch_id' => $check_query['batch_id']))->row_array();
if ($check_student) {
if (isset($data_array['photo'])) {
$photo = 'assets_student/application/' . $check_student['photo'];
unlink($photo);
}
if (isset($data_array['exam_result'])) {
$exam_result = 'assets_student/application/$exam_result' . $check_student['exam_result'];
unlink($exam_result);
}
if (isset($data_array['medical_cerificate'])) {
$medical_cerificate = 'assets_student/application/$exam_result' . $check_student['medical_cerificate'];
unlink($medical_cerificate);
}
if (isset($data_array['school_certificate'])) {
$school_certificate = 'assets_student/application/$exam_result' . $check_student['school_certificate'];
unlink($school_certificate);
}
}
$data_array['modified'] = $this->nepali_current_date;
$update = $this->db->update('students', $data_array, array('name' => $check_query['name'], 'course' => $check_query['course'], 'batch_id' => $check_query['batch_id']));
} else {
if (isset($data_array['photo'])) {
$photo = 'assets_student/application/' . $check_query['photo'];
unlink($photo);
}
if (isset($data_array['exam_result'])) {
$exam_result = 'assets_student/application/$exam_result' . $check_query['exam_result'];
unlink($exam_result);
}
if (isset($data_array['medical_cerificate'])) {
$medical_cerificate = 'assets_student/application/$exam_result' . $check_query['medical_cerificate'];
unset($medical_cerificate);
}
if (isset($data_array['school_certificate'])) {
$school_certificate = 'assets_student/application/$exam_result' . $check_query['school_certificate'];
unlink($school_certificate);
}
$update = $this->db->update('applications', $data_array, array('id' => $id));
}
} else {
$update = 0;
}
return $update;
}
public function get_sections_from_course_id($id)
{
$this->db->select('section.id, section_name');
$this->db->from('classroom ,section');
$this->db->where('classroom.course_id', $id);
$this->db->where('classroom.section_id = section.id');
$this->db->where('section.is_active', 'yes');
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result_array();
}
public function delete_expenses($id)
{
$query_id = $this->db->get_where('expenses', array('id' => $id))->row()->id;
$image = $this->db->get_where('expenses', array('id' => $id))->row()->file_path;
if ($query_id) {
$this->db->where('id', $id);
$this->db->delete('expenses');
if ($this->db->affected_rows()) {
unlink($image);
return true;
} else {
return false;
}
} else {
return false;
}
}
function addNewStudent($studentdata, $parentId = null)
{
$studentinfo = $studentdata['sinfo'];
$photo = $studentdata['photo'];
$medical = $studentdata['medical'];
$school = $studentdata['school'];
$exam = $studentdata['exam'];
// dd($studentdata);
// $res = $this->db->query("SELECT count(id) as student_count FROM students WHERE email = '" . $studentinfo['semail'] . "' OR mobile = '" . $studentinfo['scontact'] . "'")->row_array();
// $exist_data = (isset($res['student_count']) && ($res['student_count'] != 0)) ? $res['student_count'] : 0;
// if ($exist_data === 0) {
$this->db->select_max('id');
$query = $this->db->get('students');
$resid = $query->row_array();
$resid = (isset($resid['id']) && !empty($resid['id'])) ? $resid['id'] : 0;
$studentMaxId = $resid + 1;
$pid = date('Y', strtotime($this->nepali_current_date)) . '0' . $studentMaxId;
// if (strlen($studentMaxId) == 1)
// $pid = "00000" . $studentMaxId;
// else if (strlen($studentMaxId) == 2)
// $pid = "0000" . $studentMaxId;
// else if (strlen($studentMaxId) == 3)
// $pid = "000" . $studentMaxId;
// else if (strlen($studentMaxId) == 4)
// $pid = "00" . $studentMaxId;
// else if (strlen($studentMaxId) == 5)
// $pid = "00" . $studentMaxId;
$school_info = $this->get_logo_from_setting();
$school_prefix = (!empty($school_info['school_prefix_id'])) ? $school_info['school_prefix_id'] : 'BB';
$studentid = $school_prefix . STUDENT_PREFIX . $pid;
$parent_id = '';
if ($parentId) {
$parent_id = $parentId;
} else {
$parent_id = $school_prefix . STUDENT_PARENT_PREFIX . $pid;
}
$school_info = $this->db->query("SELECT * FROM school_settings")->row_array();
$school_code = $school_info['code'];
$std_email = str_replace(' ', '_', strtolower($studentinfo['sname'])) . '@' . $school_code . '.com';
$emergency_c_name = '';
$emergency_c_number = '';
if (empty($studentinfo['slgcontact'])) {
if (!empty($studentinfo['sfcontact'])) {
$emergency_c_number = $studentinfo['sfcontact'];
} else if (!empty($studentinfo['smcontact'])) {
$emergency_c_number = $studentinfo['smcontact'];
} else {
$emergency_c_number = '0000000000';
}
} else {
$emergency_c_number = $studentinfo['slgcontact'];
}
if (empty($studentinfo['slgname'])) {
if (!empty($studentinfo['sfathername'])) {
$emergency_c_name = $studentinfo['sfathername'];
} else if (!empty($studentinfo['smothername'])) {
$emergency_c_name = $studentinfo['smothername'];
} else {
$emergency_c_name = '0000000000';
}
} else {
$emergency_c_name = $studentinfo['slgname'];
}
// dd($studentinfo);
$qr_path = $this->generate_qrcode($studentid);
$insertdata = array(
'id' => $studentMaxId,
'name' => $studentinfo['sname'],
'studentId' => $studentid,
'course' => $studentinfo['scourse'],
'batch_id' => $studentinfo['sbatch'],
'email' => $std_email,
'password' => md5($studentid),
'mobile' => $studentinfo['smobile'],
'gender' => $studentinfo['sgender'],
'dob' => $studentinfo['sdob'],
'father_name' => $studentinfo['sfathername'],
'mother_name' => $studentinfo['smothername'],
'father_contact_number' => $studentinfo['sfcontact'],
'mother_contact_number' => $studentinfo['smcontact'],
'emergency_contact_name' => $emergency_c_name,
'emergency_contact_number' => $emergency_c_number,
'emergency_contact_address' => $studentinfo['slgaddress'],
'country' => 'Nepal',
'state' => $studentinfo['p_province'],
'address1' => $studentinfo['p_ward_no'],
'address2' => $studentinfo['p_saddress1'],
'p_address1' => $studentinfo['p_ward_no'],
'p_address2' => $studentinfo['p_saddress1'],
'p_district' => $studentinfo['p_district'],
'p_province' => $studentinfo['p_province'],
't_address1' => $studentinfo['same_as_per_add'] == 'on' ? $studentinfo['p_ward_no'] : $studentinfo['t_ward_no'],
't_address2' => $studentinfo['same_as_per_add'] == 'on' ? $studentinfo['p_saddress1'] : $studentinfo['t_saddress'],
't_district' => $studentinfo['same_as_per_add'] == 'on' ? $studentinfo['p_district'] : $studentinfo['t_district'],
't_province' => $studentinfo['same_as_per_add'] == 'on' ? $studentinfo['p_province'] : $studentinfo['t_province'],
'photo' => $photo,
'school_certificate' => $school,
'exam_result' => $exam,
'medical_cerificate' => $medical,
'payment_status' => 'no',
'registered_on' => date('Y-m-d H:i:s', strtotime($this->nepali_current_date)),
'assign_status' => 'no',
'qr_code' => $qr_path,
'parent_username' => $parent_id,
'parent_password' => md5($parent_id),
'is_active' => 'yes',
'modified' => $this->nepali_current_date,
'parent_pan' => '',
'hostel' => 'no',
'hostel_plan_id' => 0,
'suspend_reason' => '',
'has_sibling' => '',
'bus_facility' => 'no',
'bus_routeid' => 0
);
// dd($insertdata);
$insert = $this->db->insert('students', $insertdata);
if ($insert) {
$sectionID = (isset($_POST['s_section']) && !empty($_POST['s_section'])) ? $_POST['s_section'] : 0;
if ($sectionID != 0) {
$courseID = (!empty($_POST['scourse'])) ? $_POST['scourse'] : 0;
$sbatchID = (!empty($_POST['sbatch'])) ? $_POST['sbatch'] : 0;
$classroomID = $this->db->get_where('classroom', array('course_id' => $courseID, 'section_id' => $sectionID, 'is_active' => 'yes'))->row()->id;
$classroomID = (isset($classroomID) && !empty($classroomID)) ? $classroomID : 0;
$roll_no = $this->db->query('select roll_no from student_batch where batch_id=' . $sbatchID . ' and classroom_id =' . $classroomID . ' and is_active ="yes" order by roll_no DESC')->row_array();
// dd($roll_no);
if (!empty($roll_no)) {
$in_data['roll_no'] = $roll_no['roll_no'] + 1;
} else {
$in_data['roll_no'] = 1;
}
$in_data['student_id'] = $studentMaxId;
$in_data['batch_id'] = $sbatchID;
$in_data['classroom_id'] = $classroomID;
$in_data['is_active'] = 'yes';
$in_data['created'] = date('Y-m-d H:i:s', strtotime($this->nepali_current_date));
$in_data['modified'] = date('Y-m-d H:i:s', strtotime($this->nepali_current_date));
$this->db->insert('student_batch', $in_data);
}
return $studentMaxId;
} else {
return 0;
}
// }
// else {
// return -1;
// }
}
public function get_fees_type()
{
$sql = "SELECT * FROM `fee_types` WHERE is_active='yes'";
$result = $this->get_query_result($sql);
if (count($result) > 0)
return $result;
else
return 0;
}
public function get_currentbatch_routes()
{
$BTSdb = $this->load->database('erisnClassroom_bts', TRUE);
$school_info = $this->get_logo_from_setting();
$batch_id = (isset($school_info['batch_id']) && !empty($school_info['batch_id'])) ? $school_info['batch_id'] : 0;
$route_data = array();
$result = $BTSdb->query('select * FROM bt_batch_routes WHERE batch_id=' . $batch_id)->row_array();
if ($result != '') {
$route_ids = explode(',', $result['route_ids']);
if (!empty($route_ids) || count($route_ids) > 0) {
foreach ($route_ids as $value) {
$value = (!empty($value)) ? $value : 0;
$rst = $BTSdb->query('SELECT * FROM `bt_routes` WHERE id=' . $value)->row_array();
$route_data[] = array(
'id' => $rst['id'],
'route_name' => $rst['route_name']
);
}
}
}
return $route_data;
}
// get Fees by Feestype - start
// Auth:Shivu
function getFeesByfeetypes($se_batch, $se_course, $student_id, $payment_status, $selected_ft_ids, $start_date, $end_date)
{
$student_id = 132;
$payment_con = 'WHERE 1';
$group_by = '';
$result = array();
if ($selected_ft_ids != '') {
$payment_con .= ' AND cf.fees_type IN (' . implode(',', $selected_ft_ids) . ') ';
}
if (!empty($payment_status)) {
if ($payment_status == 'paid') {
// $payment_con .=' AND sop.paid_amount > 0 ';
$group_by = 'GROUP BY cf.id HAVING paid_amount > 0';
} else if ($payment_status == 'due') {
$group_by = 'GROUP BY cf.id HAVING pending_amount > 0';
// $payment_con .=' AND sop.pending_amount > 0 ';
}
}
// if($start_date != null){
// $start_date=date('d-m-Y',strtotime($this->$start_date));
// }
// if($end_date != null){
// date('d-m-Y',strtotime($end_date));
// }
// echo "SELECT cf.id as coursefee_id,cf.fees_type,cf.amount as cf_total_amount,fas.id,ft.feetype_name,ft.id,IF(sop.id is null,0,sop.id) as sop_id,IF(sop.paid_amount is null,0,sop.paid_amount) as paid_amount,IF(sop.pending_amount is null,cf.amount,sop.pending_amount) as pending_amount,IF(sop.payment_details is null,0,sop.payment_details) as payment_detail FROM course_fees cf JOIN fee_assigned_students fas ON fas.course_fee_id=cf.id AND fas.student_id=$student_id JOIN fee_types ft on ft.id = cf.fees_type LEFT JOIN students_online_payments sop on cf.id = sop.course_fee_id AND sop.student_id = $student_id $payment_con $group_by";
// exit;
$fees_rst = $this->db->query("SELECT cf.id as coursefee_id,cf.fees_type,cf.amount as cf_total_amount,fas.id,ft.feetype_name,ft.id,IF(sop.id is null,0,sop.id) as sop_id,IF(sop.paid_amount is null,0,sop.paid_amount) as paid_amount,IF(sop.pending_amount is null,cf.amount,sop.pending_amount) as pending_amount,IF(sop.payment_details is null,0,sop.payment_details) as payment_detail FROM course_fees cf JOIN fee_assigned_students fas ON fas.course_fee_id=cf.id AND fas.student_id=$student_id JOIN fee_types ft on ft.id = cf.fees_type LEFT JOIN students_online_payments sop on cf.id = sop.course_fee_id AND sop.student_id = $student_id $payment_con $group_by")->result_array();
if (count($fees_rst) > 0) {
foreach ($fees_rst as $payment) {
$total_paid_amount = 0;
$total_pending_amount = 0;
$total_fine_amount = 0;
$total_deduction_amount = 0;
$total_amount = ($payment['cf_total_amount'] != 0 || $payment['cf_total_amount'] != '') ? $payment['cf_total_amount'] : 0;
$payment_detail = (isset($payment['payment_detail']) && $payment['payment_detail'] != 0 && $payment['payment_detail'] != '[]') ? json_decode($payment['payment_detail'], true) : 0;
if ($payment_detail != 0) {
foreach ($payment_detail as $pd_key => $pd_value) {
$paid_date = (isset($pd_value['paid_date']) && !empty($pd_value['paid_date'])) ? date('Y-m-d', strtotime($pd_value['paid_date'])) : '';
if ($start_date != '' && $end_date != '') {
if ($start_date <= $paid_date && $end_date >= $paid_date) {
$fine_amount = (isset($pd_value['fine_amount']) && !empty($pd_value['fine_amount'])) ? $pd_value['fine_amount'] : 0;
$deduction_amount = (isset($pd_value['deduction_amount']) && !empty($pd_value['deduction_amount'])) ? $pd_value['deduction_amount'] : 0;
$total_paid_amount += $pd_value['paid_amount'];
$total_fine_amount += $fine_amount;
$total_deduction_amount += $deduction_amount;
}
} else {
$fine_amount = (isset($pd_value['fine_amount']) && !empty($pd_value['fine_amount'])) ? $pd_value['fine_amount'] : 0;
$deduction_amount = (isset($pd_value['deduction_amount']) && !empty($pd_value['deduction_amount'])) ? $pd_value['deduction_amount'] : 0;
$total_paid_amount += $pd_value['paid_amount'];
$total_fine_amount += $fine_amount;
$total_deduction_amount += $deduction_amount;
}
}
$total_pending_amount = ($total_amount - ($total_paid_amount + $total_deduction_amount - $total_fine_amount));
// echo "Total paid - ".$total_paid_amount."<br>";
// echo "Total fine - ".$total_fine_amount."<br>";
// echo "Total deduction - ".$total_deduction_amount."<br>";
// echo "Assigned Amount -".$total_amount."<br>";
// echo "Total Due amount - ". $total_pending_amount = ($total_amount - ($total_paid_amount+$total_deduction_amount-$total_fine_amount))."<br><br>";
} else {
$total_pending_amount += $payment['pending_amount'];
}
$result[] = array(
'course_fee_id' => $payment['cf_total_amount'],
'fees_type' => $payment['fees_type'],
'cf_total_amount' => $payment['cf_total_amount'],
'total_paid_amount' => $total_paid_amount,
'total_fine_amount' => $total_fine_amount,
'total_deduction_amount' => $total_deduction_amount,
'total_pending_amount' => $total_pending_amount
);
}
}
// return $result;
}
// paid get Reports
function getFeesBy_status_feetypes($se_batch, $se_course, $student_id, $payment_status, $selected_ft_ids, $start_date, $end_date)
{
// $student_id=132;
$payment_con = 'WHERE 1';
$group_by = '';
$result = array();
if ($se_batch != '')
$payment_con .= ' AND cf.batch_id=' . $se_batch;
if ($se_course != '')
$payment_con .= ' AND cf.course_id=' . $se_course;
if ($selected_ft_ids != '') {
$payment_con .= ' AND cf.fees_type IN (' . implode(',', $selected_ft_ids) . ') ';
}
if (!empty($payment_status)) {
if ($payment_status == 'paid') {
// $payment_con .=' AND sop.paid_amount > 0 ';
$group_by = 'GROUP BY cf.id HAVING paid_amount > 0';
} else if ($payment_status == 'due') {
$group_by = 'GROUP BY cf.id HAVING pending_amount > 0';
// $payment_con .=' AND sop.pending_amount > 0 ';
}
}
if ($payment_status == 'paid') {
$fees_rst = $this->db->query("SELECT cf.id as coursefee_id,cf.fees_type,cf.amount as cf_total_amount,fas.id,ft.feetype_name,ft.id,ft.feetype_name,IF(sop.id is null,0,sop.id) as sop_id,IF(sop.paid_amount is null,0,sop.paid_amount) as paid_amount,IF(sop.pending_amount is null,cf.amount,sop.pending_amount) as pending_amount,IF(sop.payment_details is null,0,sop.payment_details) as payment_detail FROM course_fees cf JOIN fee_assigned_students fas ON fas.course_fee_id=cf.id AND fas.student_id=$student_id JOIN fee_types ft on ft.id = cf.fees_type LEFT JOIN students_online_payments sop on cf.id = sop.course_fee_id AND sop.student_id = $student_id $payment_con $group_by")->result_array();
if (count($fees_rst) > 0) {
foreach ($fees_rst as $payment) {
$total_paid_amount = 0;
$total_pending_amount = 0;
$total_fine_amount = 0;
$total_deduction_amount = 0;
$total_amount = ($payment['cf_total_amount'] != 0 || $payment['cf_total_amount'] != '') ? $payment['cf_total_amount'] : 0;
$payment_detail = (isset($payment['payment_detail']) && $payment['payment_detail'] != '' && $payment['payment_detail'] != '[]') ? json_decode($payment['payment_detail'], true) : '';
if ($payment_detail != '') {
foreach ($payment_detail as $pd_key => $pd_value) {
$paid_date = (isset($pd_value['paid_date']) && !empty($pd_value['paid_date'])) ? date('Y-m-d', strtotime($pd_value['paid_date'])) : '';
if ($start_date <= $paid_date && $end_date >= $paid_date) {
$fine_amount = (isset($pd_value['fine_amount']) && !empty($pd_value['fine_amount'])) ? $pd_value['fine_amount'] : 0;
$deduction_amount = (isset($pd_value['deduction_amount']) && !empty($pd_value['deduction_amount'])) ? $pd_value['deduction_amount'] : 0;
$total_paid_amount += $pd_value['paid_amount'];
$total_fine_amount += $fine_amount;
$total_deduction_amount += $deduction_amount;
$total_pending_amount = ($total_amount - ($total_paid_amount + $total_deduction_amount - $total_fine_amount));
}
}
} else {
$total_pending_amount = $payment['pending_amount'] - $payment['pending_amount'];
}
$result[] = array(
'course_fee_id' => $payment['cf_total_amount'],
'feetype_name' => $payment['feetype_name'],
'fees_type' => $payment['fees_type'],
'cf_total_amount' => $payment['cf_total_amount'],
'total_paid_amount' => $total_paid_amount,
'total_fine_amount' => $total_fine_amount,
'total_deduction_amount' => $total_deduction_amount,
'total_pending_amount' => $total_pending_amount
);
}
}
}
return $result;
}
// get_due_report
function getFeesBy_due_feetypes($se_batch, $se_course, $student_id, $payment_status, $selected_ft_ids, $start_date, $end_date)
{
$student_id = 132;
$payment_con = 'WHERE 1';
$group_by = '';
$result = array();
if ($selected_ft_ids != '') {
$payment_con .= ' AND cf.fees_type IN (' . implode(',', $selected_ft_ids) . ') ';
}
if (!empty($payment_status)) {
$group_by = 'GROUP BY cf.id HAVING pending_amount > 0';
}
$fees_rst = $this->db->query("SELECT cf.id as coursefee_id,cf.fees_type,cf.amount as cf_total_amount,fas.id,ft.feetype_name,ft.id,IF(sop.id is null,0,sop.id) as sop_id,IF(sop.paid_amount is null,0,sop.paid_amount) as paid_amount,IF(sop.pending_amount is null,cf.amount,sop.pending_amount) as pending_amount,IF(sop.payment_details is null,0,sop.payment_details) as payment_detail FROM course_fees cf JOIN fee_assigned_students fas ON fas.course_fee_id=cf.id AND fas.student_id=$student_id JOIN fee_types ft on ft.id = cf.fees_type LEFT JOIN students_online_payments sop on cf.id = sop.course_fee_id AND sop.student_id = $student_id $payment_con $group_by")->result_array();
if (count($fees_rst) > 0) {
foreach ($fees_rst as $payment) {
$total_paid_amount = 0;
$total_pending_amount = 0;
$total_fine_amount = 0;
$total_deduction_amount = 0;
$total_amount = ($payment['cf_total_amount'] != 0 || $payment['cf_total_amount'] != '') ? $payment['cf_total_amount'] : 0;
$payment_detail = (isset($payment['payment_detail']) && $payment['payment_detail'] != 0 && $payment['payment_detail'] != '[]') ? json_decode($payment['payment_detail'], true) : 0;
if ($payment_detail != 0) {
foreach ($payment_detail as $pd_key => $pd_value) {
$paid_date = (isset($pd_value['paid_date']) && !empty($pd_value['paid_date'])) ? date('Y-m-d', strtotime($pd_value['paid_date'])) : '';
if ($start_date <= $paid_date && $end_date >= $paid_date) {
$fine_amount = (isset($pd_value['fine_amount']) && !empty($pd_value['fine_amount'])) ? $pd_value['fine_amount'] : 0;
$deduction_amount = (isset($pd_value['deduction_amount']) && !empty($pd_value['deduction_amount'])) ? $pd_value['deduction_amount'] : 0;
$total_paid_amount += $pd_value['paid_amount'];
$total_fine_amount += $fine_amount;
$total_deduction_amount += $deduction_amount;
}
}
$total_pending_amount = ($total_amount - ($total_paid_amount + $total_deduction_amount - $total_fine_amount));
// echo "Total paid - ".$total_paid_amount."<br>";
// echo "Total fine - ".$total_fine_amount."<br>";
// echo "Total deduction - ".$total_deduction_amount."<br>";
// echo "Assigned Amount -".$total_amount."<br>";
// echo "Total Due amount - ". $total_pending_amount = ($total_amount - ($total_paid_amount+$total_deduction_amount-$total_fine_amount))."<br><br>";
} else {
$total_pending_amount += $payment['pending_amount'];
}
$result[] = array(
'course_fee_id' => $payment['cf_total_amount'],
'fees_type' => $payment['fees_type'],
'cf_total_amount' => $payment['cf_total_amount'],
'total_paid_amount' => $total_paid_amount,
'total_fine_amount' => $total_fine_amount,
'total_deduction_amount' => $total_deduction_amount,
'total_pending_amount' => $total_pending_amount
);
}
}
// return $result;
}
public function add_edit_offline_exam($id, $data)
{
if ($id == 0) {
$data['created'] = $this->nepali_current_date;
$data['modified'] = $this->nepali_current_date;
$this->db->insert('offline_exams', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$data['modified'] = $this->nepali_current_date;
$this->db->where('id', $id);
$this->db->update('offline_exams', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
function getBatch()
{
$res = array();
$sql = $this->db->query("SELECT id as batch_id,b_name,b_from,b_end FROM `batch` WHERE is_active='yes'");
if ($sql->num_rows() > 0) {
$res = $sql->result_array();
}
return $res;
}
function getClass()
{
$res = array();
$sql = $this->db->query("SELECT id as course_id,course_name FROM `course` WHERE is_active='yes'");
if ($sql->num_rows() > 0) {
$res = $sql->result_array();
}
return $res;
}
function getOfllineExams()
{
$res = array();
$sql = $this->db->query("SELECT id as offline_exam_id,exam_name FROM offline_exams WHERE is_active='yes'");
if ($sql->num_rows() > 0) {
$res = $sql->result_array();
}
return $res;
}
// Yogesh
public function get_course_offfline_exam($cid)
{
$cs_sql = "SELECT c.course_name, c.id as course_id,OEM.id as oem_id, OEM.batch_id, OEM.subject_id, OEM.is_active from course c inner join offline_exam_marks OEM on c.id = OEM.course_id where c.id = '$cid'";
$query = $this->db->query($cs_sql);
if (($query->num_rows() > 0))
return $query->result_array();
}
public function get_scholarship_type($where = '', $sqlQry = '', $limit = FALSE, $offset = FALSE)
{
if ($limit)
$this->db->limit($limit, $offset);
if ($where != '')
$this->db->where($where);
$this->db->order_by('scholarship_types.id', 'ASC');
$query = $this->db->get('scholarship_types');
if ($sqlQry != '')
$query = $this->db->query($sqlQry);
if (($query->num_rows() == 1))
return $query->row_array();
return $query->result_array();
}
public function add_edit_scholarship($id, $data)
{
if ($id == 0) {
$data['created'] = $this->nepali_current_date;
$data['modified'] = $this->nepali_current_date;
$this->db->insert('scholarship_types', $data);
if ($this->db->affected_rows() > 0)
return $insert_id = $this->db->insert_id();
else
return 0;
} else {
$data['modified'] = $this->nepali_current_date;
$this->db->where('id', $id);
$this->db->update('scholarship_types', $data);
if ($this->db->trans_status() === FALSE)
return 0;
return true;
}
}
public function get_unique_name($field_name, $field_value, $table_name)
{
$hr_db = $this->load->database('hr', TRUE);
$sql_query = "select * from " . $table_name . " WHERE " . $field_name . " = '" . $field_value . "'";
$query = $hr_db->query($sql_query);
$results = $query->result_array();
if (empty($results)) {
return true;
} else {
return false;
}
}
public function get_unique_name_main_db($field_name, $field_value, $table_name)
{
$sql_query = "select * from " . $table_name . " WHERE " . $field_name . " = '" . $field_value . "'";
$query = $this->db->query($sql_query);
$results = $query->result_array();
if (empty($results)) {
return true;
} else {
return false;
}
}
public function update_unique_name_main_db($field_name, $field_value, $table_name, $recId)
{
$sql_query = "select * from " . $table_name . " WHERE " . $field_name . " = '" . $field_value . "' AND id != " . $recId;
$query = $this->db->query($sql_query);
$results = $query->result_array();
if (empty($results)) {
return true;
} else {
return false;
}
}
}