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/StudentController.php

<?php

namespace App\Http\Controllers\School;

use Illuminate\Http\Request;
use App\Http\Requests\StudentDocRequest;
use Auth;
use DB;
use Session;

class StudentController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        // 
        $classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $fys = ['' => '--Select--'] + \App\FinancialYear::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idFinancialYear')->get()->pluck('financialYearName', 'idFinancialYear')->toArray();
        $students = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->where('idFinancialYear', '=', Session::get('idFinancialYear'))
                ->orderBy('idStudent');
        if ($request->has('classes') && count($request->classes) > 0 && $request->has('sections') && count($request->sections) > 0 && $request->idFinancialYear != null && $request->gender != null && $request->studentType != null) {
            $students = $students->whereIn('idClass', $request->classes)
                    ->whereIn('idSection', $request->sections)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->where('gender', '=', $request->gender)
                    ->where('studentType', '=', $request->studentType)
                    ->where('isActive', '=', $request->isActive)
                    ->get();
        } else if ($request->has('sections') && count($request->sections) > 0 && $request->idFinancialYear != null && $request->gender != null && $request->studentType != null) {
            $students = $students->whereIn('idSection', $request->sections)
                    ->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->where('gender', '=', $request->gender)
                    ->where('studentType', '=', $request->studentType)
                    ->where('isActive', '=', $request->isActive)
                    ->get();
        } else if ($request->idFinancialYear != null && $request->gender != null && $request->studentType != null) {
            $students = $students->where('idFinancialYear', '=', $request->idFinancialYear)
                    ->where('gender', '=', $request->gender)
                    ->where('studentType', '=', $request->studentType)->where('isActive', '=', $request->isActive)
                    ->get();
        } else if ($request->has('classes') && count($request->classes) > 0 && $request->has('sections') && count($request->sections) > 0) {
            $students = $students->whereIn('idClass', $request->classes)->where('isActive', '=', $request->isActive)
                    ->whereIn('idSection', $request->sections)
                    ->get();
        } else if ($request->gender != null && $request->has('classes') && count($request->classes) > 0) {
            $students = $students->where('gender', '=', $request->gender)
                    ->whereIn('idClass', $request->classes)->where('isActive', '=', $request->isActive)
                    ->get();
        } else if ($request->studentType != null && $request->has('classes') && count($request->classes) > 0) {
            $students = $students->where('studentType', '=', $request->studentType)
                    ->whereIn('idClass', $request->classes)->where('isActive', '=', $request->isActive)
                    ->get();
        } else if ($request->gender != null && $request->has('sections') && count($request->sections) > 0) {
            $students = $students->where('gender', '=', $request->gender)->where('isActive', '=', $request->isActive)
                    ->whereIn('idSection', $request->sections)
                    ->get();
        } else if ($request->studentType != null && $request->has('sections') && count($request->sections) > 0) {
            $students = $students->where('studentType', '=', $request->studentType)->where('isActive', '=', $request->isActive)
                    ->whereIn('idSection', $request->sections)
                    ->get();
        } else if ($request->has('classes') && count($request->classes) > 0) {
            $students = $students->whereIn('idClass', $request->classes)->where('isActive', '=', $request->isActive)->get();
        } else if ($request->has('sections') && count($request->sections) > 0) {
            $students = $students->whereIn('idSection', $request->sections)->where('isActive', '=', $request->isActive)->get();
        } else if ($request->idFinancialYear != null) {
            $students = $students->where('idFinancialYear', '=', $request->idFinancialYear)->where('isActive', '=', $request->isActive)->get();
        } else if ($request->gender != null) {
            $students = $students->where('gender', '=', $request->gender)->where('isActive', '=', $request->isActive)->get();
        } else if ($request->studentType != null) {
            $students = $students->where('studentType', '=', $request->studentType)->where('isActive', '=', $request->isActive)->get();
        } else {
            $students = $students->where('isActive', '=', 'Y')->get();
        }
        
        $categories =  ['' => '--Select--'] +DB::table('studentCategory')->where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('categoryName','categoryName')->toArray();  
        
        $studentsData=array();
        $i = 1; 
        foreach($students as $value){
           $scope = "";
           $sec = "";
           if(isset($value->classM)){
                $scope = $value->classM->className;
           } 
           if(isset($value->section)){
            $sec = $value->section->sectionName;
           } 
           array_push($studentsData,array(
                $i,
                '',
                $value->ecNo,
                $value->firstName." ".$value->middleName." ".$value->lastName,
                $value->father_fname." ".$value->father_lname,
                $value->contactPersonMobile,
                $value->studentDob,
                $value->gender,
                $scope,
                $sec,
                "",
                '<form method = "post" action="/schoolmis/school/stdstatusupdate" "class" = "form-horizontal">
                    <input type="hidden" name="_token" id="csrf-token" value="'. Session::token() .'" />
                    <input type="hidden" name="idStudent" value="'.$value->idStudent.'">
                    <select onchange="showRemarks('.$value->idStudent.')" name="isActive">
                    <option value="A">ACTIVE</option>
                    <option value="N">NOT-ACTIVE</option></select>
                    <span id="remarks'.$value->idStudent.'" style="display:none;">
                    <input type="text" name="remarks" class="form-control" style="background-color: #fff;" placeholder="Enter Remarks">
                    <button class="btn btn-sm btn-success">Update</button>
                                
                    </span>
                </form>',
                ' <a class="btn btn-info btn-sm" href="https://online-login.online/school/admentries/'.$value->idStudent.'">View</a><a class="btn btn-primary btn-sm" href="https://online-login.online/school/admentries/'.$value->idStudent.'/edit">Edit</a><button class="btn btn-danger btn-sm js-sweetalert" data-id="{{$value->idStudent}}" data-type="confirm">DELETE</button>'
               /* $value->ecNo,
                $value->firstName." ".$value->middleName." ".$value->lastName,
                $value->admissionNo,
                $value->classM->className,
                $value->section->sectionName,
                $value->studentDob,
                $value->gender,
                $value->studentPob,
                $value->admissionNo,
                $value->aadhaarNo,
                $value->religion,
                $value->studentType,
                $value->studentUID,
                $value->motherTounge,
                $value->grNo,
                $value->saralNo,
                $value->bloodGroup,
                preg_replace("/\r|\n/", "",trim($value->resAddress)),
                $value->resCity,
                $value->resPincode,
                $value->landmark,
                $value->state->stateName,
                $value->resTelephone,
                $value->lastSchool,
                $value->board,
                $value->percentage,
                $value->lastSchoolAddress,
                $value->lastSchoolCity,
                $value->lastSchoolPhone,
                $value->lastSchoolPincode,
                "",
                $value->reasonForChange,
                $value->contactPerson,
                $value->contactPersonAddress,
                $value->contactPersonRelation,
                $value->contactPersonMobile,
                $value->father_fname." ".$value->father_lname,
                $value->father_dob,
                $value->father_qualification,
                $value->father_occupation,
                $value->father_designation,
                $value->father_company,
                $value->father_workloc,
                $value->father_panno,
                $value->father_telephone,
                $value->father_mobile,
                $value->father_aadhaar,
                $value->father_email,
                $value->mother_fname." ".$value->mother_lname,
                $value->mother_dob,
                $value->mother_qualification,
                $value->mother_occupation,
                $value->mother_designation,
                $value->mother_company,
                $value->mother_workloc,
                $value->mother_panno,
                $value->mother_telephone,
                $value->mother_mobile,
                $value->mother_aadhaar,
                $value->mother_email,
                $value->food,
                $value->transport,
                $value->learningDisability,*/
                ));
            $i++;
        }
        
        return view('schools.students.student_list', compact('studentsData','students', 'classes', 'fys','categories'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create() {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        //
        $student = \App\AdmEntry::where('idStudent', '=', $id)->first(['firstName', 'lastName']);
        return json_encode($student);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id) {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        //
    }

    public function getStudentDocForm(Request $request) {
        $stddocs = DB::table('student_documents')
                ->join('document_types', 'student_documents.idDocType', '=', 'document_types.idDocType')
                ->join('students', 'student_documents.idStudent', '=', 'students.idStudent')
                ->join('classes', 'students.idClass', '=', 'classes.idClass')
                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->select('student_documents.idFinancialYear','ecNo', 'firstName', 'middleName', 'lastName', 'documentType', 'idStdDocument', 'className', 'sectionName', 'student_documents.updated_at');
        if ($request->has('idFinancialYear')) {
            $stddocs = $stddocs->where('student_documents.idFinancialYear','=',$request->idFinancialYear)
                    ->get();
        } else {
            $stddocs = $stddocs->where('student_documents.idFinancialYear','=', Session::get('idFinancialYear'))
                    ->get();
        }
        $classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $doctypes = ['' => '--Select Document Type--'] + \App\DocumentType::where('type', '=', 'Student')->where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idDocType', 'desc')->get()->pluck('documentType', 'idDocType')->toArray();
                        
        return view('schools.students.stddocs', compact('classes', 'doctypes', 'stddocs'));
    }

    public function saveStudentDocs(StudentDocRequest $request) {
//        dd($request->all());
        $dtype = \App\DocumentType::where('idDocType', '=', $request->idDocType)->first();
        $student = \App\AdmEntry::where('idStudent', '=', $request->idStudent)->first();
        $isExist = \App\StudentDocument::where('idDocType', '=', $request->idDocType)->where('idStudent', '=', $request->idStudent)->first();
        if($isExist != null){
            flash('Same document cannot be uploaded twice.');
            return redirect('school/stddocs');
        }

        $stddoc = new \App\StudentDocument();
        $stddoc->fill($request->all());
        $stddoc->idFinancialYear = Session::get('idFinancialYear');
        if ($request->hasFile('document')) {
            $doc = $dtype->documentType . '_' . $student->idStudent . '.' . $request->file('document')->getClientOriginalExtension();
            $request->file('document')->storeAs('public/schools/' . Auth::guard('school')->user()->idSchool . '/students/', $doc);
            $stddoc->document = $doc;
        }
        $stddoc->save();
        return redirect('school/stddocs');
    }

    public function viewStdDoc($id) {
        $stddoc = \App\StudentDocument::where('idStdDocument', '=', $id)->first();
        $student = \App\AdmEntry::where('idStudent', '=', $stddoc->idStudent)->first();
        $path = storage_path('app/public/schools/' . $student->idSchool . '/students/' . $stddoc->document);
        return response()->file($path);
    }

    public function deleteStdDoc($id) {
        $stddoc = \App\StudentDocument::where('idStdDocument', '=', $id)->first();
        $stddoc->delete();
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

    public function assignBusForm() {
        $classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $busroutes = ['' => '--Select--'] + \App\Route::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->where('idFinancialYear', '=', Session::get('idFinancialYear'))
                        ->orderBy('idRoute')->get()->pluck('routeName', 'idRoute')->toArray();

        return view('schools.buses.assign_busroute', compact('classes', 'busroutes'));
    }

    public function saveStudentRoute($idStudent, $idRoute, $idStop){
        if(\App\StudentTransport::where('idSchool',Auth::guard('school')->user()->idSchool)->where('idFinancialYear',Session::get('idFinancialYear'))->where('idStudent',$idStudent)->first() == null){
            $std_busroute = new \App\StudentTransport();
            $std_busroute->idSchool = Auth::guard('school')->user()->idSchool;
            $std_busroute->idFinancialYear = Session::get('idFinancialYear');
            $std_busroute->idStudent =$idStudent;
            $std_busroute->idRoute = $idRoute;
            $std_busroute->idStop = $idStop;
            //if(isset($var['idBus']))
            //$std_busroute->idBus = $var['idBus'];
            $std_busroute->save();
        }
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

    public function assignBus(Request $request) {
        $rules = [
            'idClass' => 'required',
            'idSection' => 'required',
        ];
        $messages = [
            'idClass.required' => 'Select Class',
            'idSection.required' => 'Select Section',
        ];
        $this->validate($request, $rules, $messages);
        foreach ($request->routes as $key => $var) {
            if (($var['idRoute'] != null) && ($var['idStop'] != null)) {
                if(\App\StudentTransport::where('idSchool',Auth::guard('school')->user()->idSchool)->where('idFinancialYear',Session::get('idFinancialYear'))->where('idStudent',$key)->first() == null){
                    $std_busroute = new \App\StudentTransport();
                    $std_busroute->fill($request->all());
                    $std_busroute->idSchool = Auth::guard('school')->user()->idSchool;
                    $std_busroute->idFinancialYear = Session::get('idFinancialYear');
                    $std_busroute->idStudent = $key;
                    $std_busroute->idRoute = $var['idRoute'];
                    $std_busroute->idStop = $var['idStop'];
                    if(isset($var['idBus']))
                    $std_busroute->idBus = $var['idBus'];
                    $std_busroute->save();
                }
            }
        }
        flash('Stop has been Assigned Successfully !');
        return redirect('school/assignbus');
    }

    public function getStudentList($classid, $secid) {
        if ($secid = 'All') {
            $stdroute = DB::table('student_transport')
                            ->join('students', 'student_transport.idStudent', '=', 'students.idStudent')
                            ->where('student_transport.idSchool', '=', Auth::guard('school')->user()->idSchool)
                            ->where('student_transport.idFinancialYear', '=', Session::get('idFinancialYear'))
                            ->where('students.idClass', '=', $classid)
                            ->get()->pluck('idStudent')->toArray();
            $students = DB::table('students')
                    ->join('classes', 'students.idClass', '=', 'classes.idClass')
                    ->join('sections','students.idSection','=','sections.idSection')
                    ->select('idStudent', 'className', 'admissionNo', 'ecNo','sectionName' ,'firstName', DB::raw('COALESCE(middleName,"") as middleName'), DB::raw('COALESCE(lastName,"") as lastName'))
                    ->where('students.idClass', '=', $classid)
                    ->whereNotIn('students.idStudent', $stdroute)
                    ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                    ->get();
        } else {
            $stdroute = DB::table('student_transport')
                            ->join('students', 'student_transport.idStudent', '=', 'students.idStudent')
                            ->where('student_transport.idSchool', '=', Auth::guard('school')->user()->idSchool)
                            ->where('student_transport.idFinancialYear', '=', Session::get('idFinancialYear'))
                            ->where('students.idSection', '=', $secid)
                            ->get()->pluck('idStudent')->toArray();
            $students = DB::table('students')
                    ->join('classes', 'students.idClass', '=', 'classes.idClass')
                    ->join('sections','students.idSection','=','sections.idSection')
                    ->select('idStudent', 'className', 'admissionNo','sectionName' , 'ecNo', 'firstName', DB::raw('COALESCE(middleName,"") as middleName'), DB::raw('COALESCE(lastName,"") as lastName'))
                    ->where('students.idSection', '=', $secid)
                    ->whereNotIn('students.idStudent', $stdroute)
                    ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                    ->get();
        }
        return json_encode($students);
    }

    public function inactiveStudents(Request $request) {
        $students = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->where('isActive', '=', 'N');
        if ($request->has('idFinancialYear')) {
            $students = $students->where('idFinancialYear', '=', $request->idFinancialYear)->get();
        } else {
            $students = $students->where('idFinancialYear', '=', Session::get('idFinancialYear'))->get();
        }
        return view('schools.students.inactive_students', compact('students'));
    }

}

Copyright © 2021 - 2025 IMMREX7