IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/School/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/School/StudentReportController.php

<?php

namespace App\Http\Controllers\School;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Auth;
use Session;
use PDF;
use Carbon;

class StudentReportController extends SchoolController {

    public function studentListForm() {
        $classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $categories = ['' => '--Select--'] + DB::table('studentCategory')->where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('categoryName', 'categoryName')->toArray();

        return view('schools.students.stdreport', compact('classes', 'categories'));
    }

    public function resetStudent($id){
        $student = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->where('idStudent',base64_decode($id))->first();
        if($student == null){
            $result = 0;
            return view('schools.students.pwd-reset', compact('result'));
        }else{
            $result = 1;
            $mother = \App\Parents::where('mobile',$student->mother_mobile)->first();
            $mother->password = bcrypt("123456");
            $mother->pwd = "123456";
            $mother->update();

            $father = \App\Parents::where('mobile',$student->father_mobile)->first();
            $father->password = bcrypt("123456");
            $father->pwd = "123456";
            $father->update();

            return view('schools.students.pwd-reset', compact('result','student'));
        }
    }

    public function studentAllRecord($request){
        $classes = DB::table('classes')->where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('className','idClass')->toArray();
        $states = DB::table('states')->get()->pluck('stateName','idState')->toArray();
        $section = DB::table('sections')->where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('sectionName','idSection')->toArray();
        $students = DB::table('students')->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool);
        if(isset($request->idFinancialYear)) $students->where('idFinancialYear', '=', $request->idFinancialYear);
        else  $students->where('idFinancialYear', '=', Session::get('idFinancialYear'));
        $students = $students->skip($request->current)->limit(60)->get();
        $data = array();
        if (!empty($students)) {
            foreach ($students as $var) {
                $parent = \App\Parents::whereIn('mobile',[$var->father_mobile,$var->mother_mobile])->whereNotNull('idFirebase')->first(); 
                $inactive = DB::table('school_logs')->where('idStudent',$var->idStudent)->where('action_details','Student Inactive')->orderBy('idLog','DESC')->first(); 
                if($parent != null) $nestedData['app_status'] = "Logged In";
                else $nestedData['app_status'] = "Never Use";
                $nestedData['ecNo'] = $var->ecNo;
                $nestedData['name'] = $var->firstName . " " . $var->middleName . " " . $var->lastName;
                $nestedData['father_name'] = $var->father_fname . " " . $var->father_lname;
                $nestedData['admissionNo'] = $var->admissionNo;
                $nestedData['contactPersonMobile'] = $var->contactPersonMobile;
                $nestedData['studentDob'] = $var->studentDob;
                $nestedData['gender'] = $var->gender;
                $nestedData['className'] = $classes[$var->idClass];
                $nestedData['sectionName'] = $section[$var->idSection];
                if($var->isActive == "Y"){
                    $nestedData['studentstatus'] = '
                    <form method = "post" action="/school/stdstatusupdate" "class" = "form-horizontal">
                        <input type="hidden" name="_token" id="csrf-token" value="' . Session::token() . '" />
                        <input type="hidden" name="idStudent" value="' . $var->idStudent . '">
                        <select onchange="showRemarks(' . $var->idStudent . ')" name="isActive">
                        <option value="Y" selected>ACTIVE</option>
                        <option value="N">NOT-ACTIVE</option></select>
                        <span id="remarks' . $var->idStudent . '" style="display:none;">
                        <input type="text" name="remarks" class="form-control" style="background-color: #fff;" placeholder="Enter Remarks" required>
                        <input type="text" name="deactivationDate" class="form-control datepicker_recurring_start" id="datepicker' . $var->idStudent . '" onkeyup="showDatepicker(' . $var->idStudent . ')" style="background-color: #fff;" placeholder="Deactivation Date">
                        <button class="btn btn-sm btn-success">Update</button>
                                    
                        </span>
                    </form>';
                }else{
                    $nestedData['studentstatus'] = '
                    <form method = "post" action="/school/stdstatusupdate" "class" = "form-horizontal">
                        <input type="hidden" name="_token" id="csrf-token" value="' . Session::token() . '" />
                        <input type="hidden" name="idStudent" value="' . $var->idStudent . '">
                        <select onchange="showRemarks(' . $var->idStudent . ')" name="isActive">
                        <option value="Y">ACTIVE</option>
                        <option value="N" selected>NOT-ACTIVE</option></select>
                        <span id="remarks' . $var->idStudent . '" style="display:none;">
                        <input type="text" name="remarks" class="form-control" style="background-color: #fff;" placeholder="Enter Remarks" required>
                        <input type="text" name="deactivationDate" class="form-control datepicker_recurring_start" id="datepicker' . $var->idStudent . '" onkeyup="showDatepicker(' . $var->idStudent . ')" style="background-color: #fff;" placeholder="Deactivation Date">
                        <button class="btn btn-sm btn-success">Update</button>
                                    
                        </span>
                    </form>';
                    if($inactive != null){
                        $user = \App\SchoolUser::where('idSchoolUser',$inactive->idUser)->first(); 
                        if($user != null)
                        $nestedData['studentstatus'] = $nestedData['studentstatus'].' by '.$user->name;
                    }
                }
                
                $nestedData['action'] = ' <a class="btn btn-info btn-sm" href="https://online-login.online/school/admentries/' . $var->idStudent . '" target="_blank">View</a><a class="btn btn-primary btn-sm" href="https://online-login.online/school/admentries/' . $var->idStudent . '/edit" target="_blank">Edit</a><button class="btn btn-warning btn-sm js-reset" data-id="'.base64_encode($var->idStudent).'" data-type="confirm">Reset Password</button><button class="btn btn-danger btn-sm js-sweetalert" data-id="'.$var->idStudent.'" data-type="confirm">DELETE</button><a class="btn btn-primary btn-sm" href="https://online-login.online/school/admentries/' . $var->idStudent . '/transfer" target="_blank">TC Cerificate</a><a class="btn btn-primary btn-sm" href="https://online-login.online/school/admentries/' . $var->idStudent . '/bonafide" target="_blank">Bonafide Certificate</a>';

                $nestedData['studentPob'] = $var->studentPob;
                $nestedData['aadhaarNo'] = $var->aadhaarNo;
                $nestedData['religion'] = $var->religion;
                $nestedData['studentType'] = $var->studentType;
                $nestedData['motherTounge'] = $var->motherTounge;
                $nestedData['bloodGroup'] = $var->bloodGroup;
                $nestedData['resAddress'] = $var->resAddress;
                $nestedData['resCity'] = $var->resCity;
                $nestedData['resPincode'] = $var->resPincode;
                $nestedData['landmark'] = $var->landmark;
                $nestedData['resstate'] = $states[$var->resState];
                $nestedData['resTelephone'] = $var->resTelephone;
                $nestedData['contactPerson'] = $var->contactPerson;
                $nestedData['contactPersonRelation'] = $var->contactPersonRelation;
                $nestedData['contactPersonMobile'] = $var->contactPersonMobile;
                $nestedData['father_qualification'] = $var->father_qualification;
                $nestedData['father_occupation'] = $var->father_occupation;
                $nestedData['father_designation'] = $var->father_designation;
                $nestedData['father_mobile'] = $var->father_mobile;
                $nestedData['mother_name'] = $var->mother_fname . " " . $var->mother_lname;
                $nestedData['mother_qualification'] = $var->mother_qualification;
                $nestedData['mother_occupation'] = $var->mother_occupation;
                $nestedData['mother_designation'] = $var->mother_designation;
                $nestedData['mother_mobile'] = $var->mother_mobile;
                $admissionNo = DB::table('students')->select('updated_at','created_at')->where('idStudent',$var->idStudent)->first();
                if($admissionNo->created_at != null)
                $nestedData['admission'] = Carbon\Carbon::parse($admissionNo->created_at)->format('d-m-Y');
                else if($admissionNo->updated_at != null)
                $nestedData['admission'] = Carbon\Carbon::parse($admissionNo->updated_at)->format('d-m-Y');
                else $nestedData['admission'] = "";

                $data[] = $nestedData;
            }
        }

        $json_data = array(
            "draw" => count($data),
            "data" => $data
        );


        $students = json_encode($json_data);
        return $students;
    }

    public function studentList(Request $request) {

      ini_set('memory_limit', '512M');
      if($request->get('showall') == true){
            return $this->studentAllRecord($request);
      }
      $totaldata1 = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool);
        //$request->idFinancialYear = Session::get('idFinancialYear');
        if ($request->has('classes') && !empty($request->classes) && $request->has('sections') && !empty($request->sections) && $request->gender != null && $request->studentType != null) {
            $totalData = $totaldata1->whereIn('idClass', $request->classes)
                    ->whereIn('idSection', $request->sections)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->where('gender', '=', $request->gender)
                    ->where('studentType', '=', $request->studentType)
                    ->where('isActive', '=', $request->isActive)
                    ->count();
        } else if ($request->has('sections') && !empty($request->sections) && $request->gender != null && $request->studentType != null) {
            $totalData = $totaldata1->whereIn('idSection', $request->sections)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->where('gender', '=', $request->gender)
                    ->where('studentType', '=', $request->studentType)
                    ->where('isActive', '=', $request->isActive)
                    ->count();
        } else if ($request->gender != null && $request->studentType != null) {
            $totalData = $totaldata1->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->where('gender', '=', $request->gender)
                    ->where('studentType', '=', $request->studentType)->where('isActive', '=', $request->isActive)
                    ->count();
        } else if ($request->has('classes') && !empty($request->classes) && $request->has('sections') && !empty($request->sections)) {
            $totalData = $totaldata1->whereIn('idClass', $request->classes)->where('isActive', '=', $request->isActive)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->whereIn('idSection', $request->sections)
                    ->count();
        } else if ($request->gender != null && $request->has('classes') && !empty($request->classes)) {
            $totalData = $totaldata1->where('gender', '=', $request->gender)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->whereIn('idClass', $request->classes)->where('isActive', '=', $request->isActive)
                    ->count();
        } else if ($request->studentType != null && $request->has('classes') && !empty($request->classes)) {
            $totalData = $totaldata1->where('studentType', '=', $request->studentType)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->whereIn('idClass', $request->classes)->where('isActive', '=', $request->isActive)
                    ->count();
        } else if ($request->gender != null && $request->has('sections') && !empty($request->sections)) {
            $totalData = $totaldata1->where('gender', '=', $request->gender)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->where('isActive', '=', $request->isActive)
                    ->whereIn('idSection', $request->sections)
                    ->count();
        } else if ($request->studentType != null && $request->has('sections') && !empty($request->sections)) {
            $totalData = $totaldata1->where('studentType', '=', $request->studentType)->where('isActive', '=', $request->isActive)
                    ->whereIn('idSection', $request->sections)
                    ->count();
        } else if ($request->has('classes') && !empty($request->classes)) {
            $totalData = $totaldata1->whereIn('idClass', $request->classes)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->where('isActive', '=', $request->isActive)
                    ->count();
        } else if ($request->has('sections') && !empty($request->sections)) {
            $totalData = $totaldata1->whereIn('idSection', $request->sections)
                            ->where('idFinancialYear', '=', $request->idFinancialYear)
                            ->where('isActive', '=', $request->isActive)->count();
        } else if ($request->idFinancialYear != null) {
            $totalData = $totaldata1->where('idFinancialYear', '=', $request->idFinancialYear)
                            ->where('isActive', '=', $request->isActive)->count();
        } else if ($request->gender != null) {
            $totalData = $totaldata1->where('gender', '=', $request->gender)
                            ->where('idFinancialYear', '=', $request->idFinancialYear)
                            ->where('isActive', '=', $request->isActive)->count();
        } else if ($request->studentType != null) {
            $totalData = $totaldata1->where('studentType', '=', $request->studentType)
                            ->where('idFinancialYear', '=', $request->idFinancialYear)
                            ->where('isActive', '=', $request->isActive)->count();
        } else {
            $totalData = $totaldata1->where('isActive', '=', 'Y')
                    ->where('idFinancialYear', '=', Session::get('idFinancialYear'))
                    ->count();
        }
        // End OF Getting Total Data Filter wise
        $totalFiltered = $totalData;
        $limit = $request->input('length');
        $start = $request->input('start');
//        $order = $columns[$request->input('order.0.column')] or '';
        $dir = $request->input('order.0.dir');

        // Get Data according to search value    
        if (empty($request->input('search.value'))) {
            if ($limit == '-1') {
                $students = DB::table('students')
                        ->leftJoin('classes', 'students.idClass', '=', 'classes.idClass')
                        ->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')
                        ->leftJoin('states', 'students.resState', '=', 'states.idState')

//                        ->offset($start)
 //                       ->limit($limit)
//                        ->orderBy($order, $dir)
                        ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool);
            } else {
                $students = DB::table('students')
                        ->leftJoin('classes', 'students.idClass', '=', 'classes.idClass')
                        ->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')
                        ->leftJoin('states', 'students.resState', '=', 'states.idState')
                        ->offset($start)
                        ->limit($limit)
//                        ->orderBy($order, $dir)
                        ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool);
            }
            if ($request->has('classes') && !empty($request->classes) && $request->has('sections') && !empty($request->sections) && $request->idFinancialYear != null && $request->gender != null && $request->studentType != null) {

                $students = $students->whereIn('students.idClass', $request->classes)
                        ->whereIn('students.idSection', $request->sections)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('gender', '=', $request->gender)
                        ->where('studentType', '=', $request->studentType)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
            } else if ($request->has('sections') && !empty($request->sections) && $request->gender != null && $request->studentType != null) {
                $students = $students->whereIn('students.idSection', $request->sections)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('gender', '=', $request->gender)
                        ->where('studentType', '=', $request->studentType)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
            } else if ($request->gender != null && $request->studentType != null) {
                $students = $students->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('gender', '=', $request->gender)
                        ->where('studentType', '=', $request->studentType)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
            } else if ($request->has('classes') && !empty($request->classes) && $request->has('sections') && !empty($request->sections)) {
                $students = $students->whereIn('students.idClass', $request->classes)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->whereIn('students.idSection', $request->sections)
                        ->get();
            } else if ($request->gender != null && $request->has('classes') && !empty($request->classes)) {
                $students = $students->where('gender', '=', $request->gender)
                        ->whereIn('students.idClass', $request->classes)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
            } else if ($request->studentType != null && $request->has('classes') && !empty($request->classes)) {
                $students = $students->where('studentType', '=', $request->studentType)
                        ->whereIn('students.idClass', $request->classes)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
            } else if ($request->gender != null && $request->has('sections') && !empty($request->sections)) {
                $students = $students->where('gender', '=', $request->gender)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->whereIn('students.idSection', $request->sections)
                        ->get();
            } else if ($request->studentType != null && $request->has('sections') && !empty($request->sections)) {
                $students = $students->where('studentType', '=', $request->studentType)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->whereIn('students.idSection', $request->sections)
                        ->get();
            } else if ($request->has('classes') && !empty($request->classes)) {
                $students = $students->whereIn('students.idClass', $request->classes)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get();
            } else if ($request->has('sections') && !empty($request->sections)) {
                $students = $students->whereIn('students.idSection', $request->sections)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get();
            } else if ($request->idFinancialYear != null) {
                $students = $students->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get();
            } else if ($request->gender != null) {
                $students = $students->where('gender', '=', $request->gender)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get();
            } else if ($request->studentType != null) {
                $students = $students->where('studentType', '=', $request->studentType)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get();
            } else {
                $students = $students->where('isActive', '=', 'Y')->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))->get();
            }
        } else {
            $search = $request->input('search.value');
            if ($limit == '-1') {
                $students = DB::table('students')
                        ->leftJoin('classes', 'students.idClass', '=', 'classes.idClass')
                        ->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')
                        ->leftJoin('states', 'students.resState', '=', 'states.idState')
//                        ->orderBy($order, $dir)
                        ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->where(function ($query) use ($search) {
                    $query->where(DB::raw('CONCAT(firstName, " ",lastName)'), 'LIKE', "%{$search}%")
                    ->orWhere('firstName', 'LIKE', "%{$search}%")
                    ->orWhere('lastName', 'LIKE', "%{$search}%")
                    ->orWhere('middleName', 'LIKE', "%{$search}%")
                    ->orWhere('ecNo', 'LIKE', "%{$search}%")
                    ->orWhere('className', 'LIKE', "%{$search}%")
                    ->orWhere('sectionName', 'LIKE', "%{$search}%")
                    ->orWhere('father_fname', 'LIKE', "%{$search}%")
                    ->orWhere('studentDob', 'LIKE', "%{$search}%")
                    ->orWhere('contactPersonMobile', 'LIKE', "%{$search}%");
                });
            } else {
                $students = DB::table('students')
                        ->leftJoin('classes', 'students.idClass', '=', 'classes.idClass')
                        ->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')
                        ->leftJoin('states', 'students.resState', '=', 'states.idState')
//                        ->offset($start)
                        ->limit($limit)
//                        ->orderBy($order, $dir)
                        ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->where(function ($query) use ($search) {
                    $query->where(DB::raw('CONCAT(firstName, " ",lastName)'), 'LIKE', "%{$search}%")
                    ->orWhere('firstName', 'LIKE', "%{$search}%")
                    ->orWhere('lastName', 'LIKE', "%{$search}%")
                    ->orWhere('middleName', 'LIKE', "%{$search}%")
                    ->orWhere('ecNo', 'LIKE', "%{$search}%")
                    ->orWhere('className', 'LIKE', "%{$search}%")
                    ->orWhere('sectionName', 'LIKE', "%{$search}%")
                    ->orWhere('father_fname', 'LIKE', "%{$search}%")
                    ->orWhere('studentDob', 'LIKE', "%{$search}%")
                    ->orWhere('contactPersonMobile', 'LIKE', "%{$search}%");
                });
            }
            $totalFiltered = DB::table('students')
                    ->join('classes', 'students.idClass', '=', 'classes.idClass')
                    ->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')
                    ->rightJoin('states', 'students.resState', '=', 'states.idState')
                    ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                    ->where(function ($query) use ($search) {
                $query->where(DB::raw('CONCAT(firstName, " ",lastName)'), 'LIKE', "%{$search}%")
                ->orWhere('firstName', 'LIKE', "%{$search}%")
                ->orWhere('lastName', 'LIKE', "%{$search}%")
                ->orWhere('middleName', 'LIKE', "%{$search}%")
                ->orWhere('ecNo', 'LIKE', "%{$search}%")
                ->orWhere('className', 'LIKE', "%{$search}%")
                ->orWhere('sectionName', 'LIKE', "%{$search}%")
                ->orWhere('father_fname', 'LIKE', "%{$search}%")
                ->orWhere('studentDob', 'LIKE', "%{$search}%")
                ->orWhere('contactPersonMobile', 'LIKE', "%{$search}%");
            });
            if ($request->has('classes') && !empty($request->classes) && $request->has('sections') && !empty($request->sections) && $request->idFinancialYear != null && $request->gender != null && $request->studentType != null) {
                $students = $students->whereIn('students.idClass', $request->classes)
                        ->whereIn('students.idSection', $request->sections)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('gender', '=', $request->gender)
                        ->where('studentType', '=', $request->studentType)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
                $totalFiltered = $totalFiltered->whereIn('students.idClass', $request->classes)
                                ->whereIn('students.idSection', $request->sections)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('gender', '=', $request->gender)
                                ->where('studentType', '=', $request->studentType)
                                ->where('isActive', '=', $request->isActive)
                                ->get()->count();
            } else if ($request->has('sections') && !empty($request->sections) && $request->idFinancialYear != null && $request->gender != null && $request->studentType != null) {
                $students = $students->whereIn('students.idSection', $request->sections)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('gender', '=', $request->gender)
                        ->where('studentType', '=', $request->studentType)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
                $totalFiltered = $totalFiltered->whereIn('students.idSection', $request->sections)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('gender', '=', $request->gender)
                                ->where('studentType', '=', $request->studentType)
                                ->where('isActive', '=', $request->isActive)
                                ->get()->count();
            } else if ($request->idFinancialYear != null && $request->gender != null && $request->studentType != null) {
                $students = $students->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('gender', '=', $request->gender)
                        ->where('studentType', '=', $request->studentType)->where('isActive', '=', $request->isActive)
                        ->get();
                $totalFiltered = $totalFiltered->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('gender', '=', $request->gender)
                                ->where('studentType', '=', $request->studentType)->where('isActive', '=', $request->isActive)
                                ->get()->count();
            } else if ($request->has('classes') && !empty($request->classes) && $request->has('sections') && !empty($request->sections)) {
                $students = $students->whereIn('students.idClass', $request->classes)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->whereIn('students.idSection', $request->sections)
                        ->get();
                $totalFiltered = $totalFiltered->whereIn('students.idClass', $request->classes)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)
                                ->whereIn('students.idSection', $request->sections)
                                ->get()->count();
            } else if ($request->gender != null && $request->has('classes') && !empty($request->classes)) {
                $students = $students->where('gender', '=', $request->gender)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->whereIn('students.idClass', $request->classes)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
                $totalFiltered = $totalFiltered->where('gender', '=', $request->gender)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->whereIn('students.idClass', $request->classes)
                                ->where('isActive', '=', $request->isActive)
                                ->get()->count();
            } else if ($request->studentType != null && $request->has('classes') && !empty($request->classes)) {
                $students = $students->where('studentType', '=', $request->studentType)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->whereIn('students.idClass', $request->classes)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
            } else if ($request->gender != null && $request->has('sections') && !empty($request->sections)) {
                $students = $students->where('gender', '=', $request->gender)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->whereIn('students.idSection', $request->sections)
                        ->get();
                $totalFiltered = $totalFiltered->where('gender', '=', $request->gender)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)
                                ->whereIn('students.idSection', $request->sections)
                                ->get()->count();
            } else if ($request->studentType != null && $request->has('sections') && !empty($request->sections)) {
                $students = $students->where('studentType', '=', $request->studentType)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->whereIn('students.idSection', $request->sections)
                        ->get();
                $totalFiltered = $totalFiltered->where('studentType', '=', $request->studentType)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)
                                ->whereIn('students.idSection', $request->sections)
                                ->get()->count();
            } else if ($request->has('classes') && !empty($request->classes)) {
                $students = $students->whereIn('students.idClass', $request->classes)
                        ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                        ->where('isActive', '=', $request->isActive)
                        ->get();
                $totalFiltered = $totalFiltered->whereIn('students.idClass', $request->classes)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)
                                ->get()->count();
            } else if ($request->has('sections') && !empty($request->sections)) {
                $students = $students->whereIn('students.idSection', $request->sections)->where('isActive', '=', $request->isActive)->get();
                $totalFiltered = $totalFiltered->whereIn('students.idSection', $request->sections)->where('isActive', '=', $request->isActive)->get()->count();
            } else if ($request->idFinancialYear != null) {
                $students = $students->where('students.idFinancialYear', '=', $request->idFinancialYear)->where('isActive', '=', $request->isActive)->get();
                $totalFiltered = $totalFiltered->where('students.idFinancialYear', '=', $request->idFinancialYear)->where('isActive', '=', $request->isActive)->get()->count();
            } else if ($request->gender != null) {
                $students = $students->where('gender', '=', $request->gender)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get();
                $totalFiltered = $totalFiltered->where('gender', '=', $request->gender)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get()->count();
            } else if ($request->studentType != null) {
                $students = $students->where('studentType', '=', $request->studentType)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get();
                $totalFiltered = $totalFiltered->where('studentType', '=', $request->studentType)
                                ->where('students.idFinancialYear', '=', $request->idFinancialYear)
                                ->where('isActive', '=', $request->isActive)->get()->count();
            } else {
                $students = $students->where('isActive', '=', 'Y')
                        ->where('students.idFinancialYear', '=',Session::get('idFinancialYear'))
                        ->get();
                $totalFiltered = $totalFiltered->where('isActive', '=', 'Y')
                                ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                                ->get()->count();
            }
        }


        $data = array();
        if (!empty($students)) {
            foreach ($students as $var) {
                $parent = \App\Parents::whereIn('mobile',[$var->father_mobile,$var->mother_mobile])->whereNotNull('idFirebase')->first(); 
                $inactive = DB::table('school_logs')->where('idStudent',$var->idStudent)->where('action_details','Student Inactive')->orderBy('idLog','DESC')->first(); 
                if($parent != null) $nestedData['app_status'] = "Logged In";
                else $nestedData['app_status'] = "Never Use";
                $nestedData['ecNo'] = $var->ecNo;
                $nestedData['name'] = $var->firstName . " " . $var->middleName . " " . $var->lastName;
                $nestedData['father_name'] = $var->father_fname . " " . $var->father_lname;
                $nestedData['admissionNo'] = $var->admissionNo;
                $nestedData['contactPersonMobile'] = $var->contactPersonMobile;
                $nestedData['studentDob'] = $var->studentDob;
                $nestedData['gender'] = $var->gender;
                $nestedData['className'] = $var->className;
                $nestedData['sectionName'] = $var->sectionName;
                if($var->isActive == "Y"){
                    $nestedData['studentstatus'] = '
                    <form method = "post" action="/school/stdstatusupdate" "class" = "form-horizontal">
                        <input type="hidden" name="_token" id="csrf-token" value="' . Session::token() . '" />
                        <input type="hidden" name="idStudent" value="' . $var->idStudent . '">
                        <select onchange="showRemarks(' . $var->idStudent . ')" name="isActive">
                        <option value="Y" selected>ACTIVE</option>
                        <option value="N">NOT-ACTIVE</option></select>
                        <span id="remarks' . $var->idStudent . '" style="display:none;">
                        <input type="text" name="remarks" class="form-control" style="background-color: #fff;" placeholder="Enter Remarks" required>
                        <input type="text" name="deactivationDate" class="form-control datepicker_recurring_start" id="datepicker' . $var->idStudent . '" onkeyup="showDatepicker(' . $var->idStudent . ')" style="background-color: #fff;" placeholder="Deactivation Date">
                        <button class="btn btn-sm btn-success">Update</button>
                                    
                        </span>
                    </form>';
                }else{
                    $nestedData['studentstatus'] = '
                    <form method = "post" action="/school/stdstatusupdate" "class" = "form-horizontal">
                        <input type="hidden" name="_token" id="csrf-token" value="' . Session::token() . '" />
                        <input type="hidden" name="idStudent" value="' . $var->idStudent . '">
                        <select onchange="showRemarks(' . $var->idStudent . ')" name="isActive">
                        <option value="Y">ACTIVE</option>
                        <option value="N" selected>NOT-ACTIVE</option></select>
                        <span id="remarks' . $var->idStudent . '" style="display:none;">
                        <input type="text" name="remarks" class="form-control" style="background-color: #fff;" placeholder="Enter Remarks" required>
                        <input type="text" name="deactivationDate" class="form-control datepicker_recurring_start" id="datepicker' . $var->idStudent . '" onkeyup="showDatepicker(' . $var->idStudent . ')" style="background-color: #fff;" placeholder="Deactivation Date">
                        <button class="btn btn-sm btn-success">Update</button>
                                    
                        </span>
                    </form>';
                    if($inactive != null){
                        $user = \App\SchoolUser::where('idSchoolUser',$inactive->idUser)->first(); 
                        if($user != null)
                        $nestedData['studentstatus'] = $nestedData['studentstatus'].' by '.$user->name;
                    }
                }
                
                $nestedData['action'] = ' <a class="btn btn-info btn-sm" href="https://online-login.online/school/admentries/' . $var->idStudent . '" target="_blank">View</a><a class="btn btn-primary btn-sm" href="https://online-login.online/school/admentries/' . $var->idStudent . '/edit" target="_blank">Edit</a><button class="btn btn-warning btn-sm js-reset" data-id="'.base64_encode($var->idStudent).'" data-type="confirm">Reset Password</button><button class="btn btn-danger btn-sm js-sweetalert" data-id="'.$var->idStudent.'" data-type="confirm">DELETE</button><a class="btn btn-primary btn-sm" href="https://online-login.online/school/admentries/' . $var->idStudent . '/transfer" target="_blank">TC Cerificate</a><a class="btn btn-primary btn-sm" href="https://online-login.online/school/admentries/' . $var->idStudent . '/bonafide" target="_blank">Bonafide Certificate</a>';

                $nestedData['studentPob'] = $var->studentPob;
                $nestedData['aadhaarNo'] = $var->aadhaarNo;
                $nestedData['religion'] = $var->religion;
                $nestedData['studentType'] = $var->studentType;
//                $nestedData['studentUID'] = $var->studentUID;
                $nestedData['motherTounge'] = $var->motherTounge;
//                $nestedData['grNo'] = $var->grNo;
//                $nestedData['saralNo'] = $var->saralNo;
                $nestedData['bloodGroup'] = $var->bloodGroup;
                $nestedData['resAddress'] = $var->resAddress;
                $nestedData['resCity'] = $var->resCity;
                $nestedData['resPincode'] = $var->resPincode;
                $nestedData['landmark'] = $var->landmark;
                $nestedData['resstate'] = $var->stateName;
                $nestedData['resTelephone'] = $var->resTelephone;
//                $nestedData['lastSchool'] = $var->lastSchool;
//                $nestedData['board']    = $var->board;    
//                $nestedData['percentage'] = $var->percentage;
//                $nestedData['lastSchoolAddress'] = $var->lastSchoolAddress;
//                $nestedData['lastSchoolCity'] = $var->lastSchoolCity;
//                $nestedData['lastSchoolPhone'] = $var->lastSchoolPhone;
//                $nestedData['lastSchoolPincode'] = $var->lastSchoolPincode;
//                $nestedData['lastschool_state'] = $var->stateName;
//                $nestedData['reasonForChange'] = $var->reasonForChange;
                $nestedData['contactPerson'] = $var->contactPerson;
//                $nestedData['contactPersonAddress'] = $var->contactPersonAddress;
                $nestedData['contactPersonRelation'] = $var->contactPersonRelation;
                $nestedData['contactPersonMobile'] = $var->contactPersonMobile;
//                $nestedData['father_dob'] = $var->father_dob;
                $nestedData['father_qualification'] = $var->father_qualification;
                $nestedData['father_occupation'] = $var->father_occupation;
                $nestedData['father_designation'] = $var->father_designation;
//                $nestedData['father_company'] = $var->father_company;
//                $nestedData['father_workloc'] = $var->father_workloc;
//                $nestedData['father_panno'] = $var->father_panno;
//                $nestedData['father_telephone'] = $var->father_telephone;
                $nestedData['father_mobile'] = $var->father_mobile;
//                $nestedData['father_aadhaar']= $var->father_aadhaar;
//                $nestedData['father_email'] = $var->father_email;
                $nestedData['mother_name'] = $var->mother_fname . " " . $var->mother_lname;
//                $nestedData['mother_dob'] = $var->mother_dob;
                $nestedData['mother_qualification'] = $var->mother_qualification;
                $nestedData['mother_occupation'] = $var->mother_occupation;
                $nestedData['mother_designation'] = $var->mother_designation;
//                $nestedData['mother_company'] = $var->mother_company;
//                $nestedData['mother_workloc'] = $var->mother_workloc;
//                $nestedData['mother_panno'] = $var->mother_panno;
//                $nestedData['mother_telephone'] = $var->mother_telephone;
                $nestedData['mother_mobile'] = $var->mother_mobile;
//                $nestedData['mother_aadhaar'] = $var->mother_aadhaar;
//                $nestedData['mother_email'] = $var->mother_email;
//                $nestedData['food'] = $var->food;
//                $nestedData['transport'] = $var->transport;
                $admissionNo = DB::table('students')->select('updated_at','created_at')->where('idStudent',$var->idStudent)->first();
                if($admissionNo->created_at != null)
                $nestedData['admission'] = Carbon\Carbon::parse($admissionNo->created_at)->format('d-m-Y');
                else if($admissionNo->updated_at != null)
                $nestedData['admission'] = Carbon\Carbon::parse($admissionNo->updated_at)->format('d-m-Y');
                else $nestedData['admission'] = "";

                $data[] = $nestedData;
            }
        }

        $json_data = array(
            "draw" => intval($request->input('draw')),
            "recordsTotal" => intval($totalData),
            "recordsFiltered" => intval($totalFiltered),
            "data" => $data
        );


        $students = json_encode($json_data);
        return $students;
    }


    public function bonafied($id){
        $student = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
        ->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)->where('students.idStudent',$id)->first();
        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
        if($school->idSchool == 189){
            $pdf = Pdf::loadView('schools.students.bonafide_certificate_template',compact('school','student'));
        }elseif($school->idSchool == 25){
            $pdf = Pdf::loadView('schools.students.bonafide_certificate_royal',compact('school','student'));
        }else{
            $pdf = Pdf::loadView('schools.students.bonafide_certificate',compact('school','student'));
            $pdf->mpdf->SetWatermarkImage('https://online-login.online/storage/schools/'.$school->idSchool.'/'.$school->schoolLogo);
            $pdf->mpdf->showWatermarkImage = true;
        }
        return $pdf->stream('Bonafide Certificate.pdf');
    }


    public function transferForm($id){
        $student = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
        ->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)->where('students.idStudent',$id)->first();
        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
        if($school->idSchool == 189){
            $pdf = PDF::loadView('schools.students.transfer_certificate_template',compact('school','student'));
        }else if($school->idSchool == 135 || $school->idSchool == 140 || $school->idSchool == 159 || $school->idSchool == 160 || $school->idSchool == 181 ){
           $saved = \App\SchoolLeavingCertificate::where('idStudent',$id)->where('idFinancialYear',Session::get('idFinancialYear'))->first();
            return view('schools.students.transfer_form_mhws',compact('student','school','id','saved'));
        }else{ 
            $saved = \App\SchoolLeavingCertificate::where('idStudent',$id)->where('idFinancialYear',Session::get('idFinancialYear'))->first();
            return view('schools.students.transfer_form',compact('student','school','id','saved'));
        }
    }

    public function saveTransfer(Request $request){
        $data = $request->validate([
            'student_id' => 'nullable|string',
            'affiliation_no' => 'nullable|string',
            'school_code' => 'nullable|string',
            'udise_no' => 'nullable|string',
            'book_no' => 'nullable|string',
            'sr_no' => 'nullable|string',
            'admission_no' => 'nullable|string',
            'name_of_pupil' => 'nullable|string',
            'mother_name' => 'nullable|string',
            'father_name' => 'nullable|string',
            'dob_figures' => 'nullable|string',
            'dob_words' => 'nullable|string',
            'nationality' => 'nullable|string',
            'belongs_sc_st_obc' => 'nullable|string',
            'first_admission_date_class' => 'nullable|string',
            'last_class_figures' => 'nullable|string',
            'last_class_words' => 'nullable|string',
            'last_exam_result' => 'nullable|string',
            'failed_info' => 'nullable|in:Yes,No',
            'promotion_class_figures' => 'nullable|string',
            'promotion_class_words' => 'nullable|string',
            'dues_paid_upto' => 'nullable|string',
            'fee_concession' => 'nullable|string',
            'school_leaving_date' => 'nullable|string',
            'total_working_days' => 'nullable|integer',
            'working_days_present' => 'nullable|integer',
            'ncc_scout_guide' => 'nullable|string',
            'extra_curricular' => 'nullable|string',
            'general_conduct' => 'nullable|string',
            'application_date' => 'nullable|date',
            'certificate_issue_date' => 'nullable|date',
            'reason_for_leaving' => 'nullable|string',
            'remarks' => 'nullable|string',
            'class_teacher_signature' => 'nullable|string',
            'checked_by' => 'nullable|string',
            'principal_signature' => 'nullable|string',
        ]);
        $data['created_by'] = Auth::guard('school')->user()->idSchoolUser;
        $checkUser = \App\SchoolLeavingCertificate::where('idStudent',$request->idStudent)->where('idFinancialYear',Session::get('idFinancialYear'))->first();
        if($checkUser == null)
        {
            $data['idStudent'] = $request->idStudent;
            $data['idSchool'] = Auth::guard('school')->user()->idSchool;
            $data['idFinancialYear'] = Session::get('idFinancialYear');
            \App\SchoolLeavingCertificate::create($data);
        }
        else {
            $data['subjects_studied'] = json_encode($request->subjects_studied);
            DB::table('student_tc')->where('id',$checkUser->id)->update($data);
        }
        return redirect('/school/admentries/'.$request->idStudent.'/transfer-print');
    }

    public function transfer($id){
        $student = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
        ->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)->where('students.idStudent',$id)->first();
        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
        if($school->idSchool == 189){
            $pdf = PDF::loadView('schools.students.transfer_certificate_template',compact('school','student'));
        }else if($school->idSchool == 135 || $school->idSchool == 140 || $school->idSchool == 159 || $school->idSchool == 160  || $school->idSchool == 181 ){
            $saved = \App\SchoolLeavingCertificate::where('idStudent',$id)->where('idFinancialYear',Session::get('idFinancialYear'))->first();
            if($saved == null) return redirect('/school/admentries/'.$id.'/transfer');
            $pdf = PDF::loadView('schools.students.transfer_certificate_mhws',compact('school','student','saved'));
        }else{
            $saved = \App\SchoolLeavingCertificate::where('idStudent',$id)->where('idFinancialYear',Session::get('idFinancialYear'))->first();
            if($saved == null) return redirect('/school/admentries/'.$id.'/transfer');
            $pdf = PDF::loadView('schools.students.transfer_certificate',compact('school','student','saved'));
            $pdf->mpdf->SetWatermarkImage('https://online-login.online/storage/bg_royal.jpg');
            $pdf->mpdf->showWatermarkImage = true;
        }
        return $pdf->stream('Transfer Certificate.pdf');
    }

}

Copyright © 2021 - 2025 IMMREX7