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

<?php

namespace App\Http\Controllers\School;

use Illuminate\Http\Request;
use Session;
use Auth;

class ClassMController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        //
        $classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->orderBy('idClass','desc')->get();
        return view('schools.classes.index', compact('classes'));
    }

    /**
     * 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) {
        $rules = [
                 'className' => 'required|unique:classes,className,NULL,idClass,idSchool,' . Auth::guard('school')->user()->idSchool,
        ];
        $this->validate($request, $rules);
        $class = new \App\ClassM();
        $class->fill($request->all());
        $class->idSchool = Auth::guard('school')->user()->idSchool;
        $class->save();
        return redirect('school/classes');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id) {
        $classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->orderBy('idClass','desc')->get();
        $class = \App\ClassM::findOrFail($id);
        return view('schools.classes.index', compact('classes', 'class'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
        $rules = [
              'className' => 'required'
        ];
        $this->validate($request, $rules);
        $class = \App\ClassM::findOrFail($id);
        $class->fill($request->all());
        $class->update();
        return redirect('school/classes');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        $class = \App\ClassM::where('idClass', '=', $id)->first();
        $class->delete();
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

    public function getSections($id) {
        $sections =  \App\Section::where('idClass', '=', $id)->get()->pluck('sectionName', 'idSection')->toArray();
        return json_encode($sections);
    }

    public function getExams($id,$idSec,Request $request) {
        $exams =  \App\MarkExams::join('marks_exam_type', 'marks_exam.idType', '=', 'marks_exam_type.idType')->select('name','marks_exam_type.idType')->where('idClass',$id)->where('marks_exam_type.idFinancialYear', Session::get('idFinancialYear'))->whereRaw('idSection IS NULL OR idSection IN  (?)', [$idSec])->groupBy('idType','name')->get()->pluck('name','idType')->toArray();
        return json_encode($exams);
    }
    
    public function getSubjects($id) {
        $subjects = \App\Subject::where('idClass', '=', $id)->where('idFinancialYear','=', Session::get('idFinancialYear'))->get()->pluck('subjectName', 'idSubject')->toArray();
        return json_encode($subjects);
    }

    public function getStudentFees($id,$idSection,$idStudent){
        $student = \App\AdmEntry::where('idStudent', '=', $idStudent)->first();
        $class_feeheads = \DB::table('feeheads')->where('idClass', '=', $id)
                ->where('idSection', '=', $idSection)
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                ->where('studentCategory', '=', $student->studentType)
                ->whereNull('idStudent');
        $allcat_feeheads = \DB::table('feeheads')->where('idClass', '=', $id)
                ->where('idSection', '=', $idSection)
                ->where('studentCategory', '=', 'All')
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                ->whereNull('idStudent');
        $feeheads = \DB::table('feeheads')->where('idStudent', '=', $student->idStudent)
       			 ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                ->union($class_feeheads)
                ->union($allcat_feeheads)
                ->orderBy('toDate')
                ->get()->pluck('feeheadName', 'idFeehead')->toArray();
        return json_encode($feeheads);         
    }
    
    public function getDropdownSections($id) {
        $class_ids = array_map('intval', explode(',', $id));
        $sections =  \App\Section::whereIn('idClass',$class_ids)->get()->pluck('sectionName', 'idSection')->toArray();
        return json_encode($sections);
    }

}

Copyright © 2021 - 2025 IMMREX7