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

<?php

namespace App\Http\Controllers\School;

use Illuminate\Http\Request;
use Auth;
use Session;
class SectionController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        $classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $sections = \App\Section::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idSection', 'desc')->get();
        return view('schools.sections.index', compact('sections', '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 = [
            'idClass' => 'required',
            'sectionName' => 'required|unique:sections,sectionName,NULL,idSection,idClass,' . $request->idClass,
         //   'sectionName' => 'required',
        ];
        $messages = [
            'idClass.required' => 'Class must be selected.'
        ];
        $this->validate($request, $rules, $messages);
        $section = new \App\Section();
        $section->fill($request->all());
        $section->idSchool = Auth::guard('school')->user()->idSchool;
        $section->save();
        return redirect('school/sections');
    }

    /**
     * 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 = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $sections = \App\Section::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idSection', 'desc')->get();
        $section = \App\Section::findOrFail($id);
        return view('schools.sections.index', compact('classes', 'section', 'sections'));
    }

    /**
     * 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 = [
            'idClass' => 'required',
            'sectionName' => 'required',
        ];
        $messages = [
            'idClass.required' => 'Class must be selected.'
        ];
        $this->validate($request, $rules, $messages);
        $section = \App\Section::findOrFail($id);
        $section->fill($request->all());
        $section->update();
        return redirect('school/sections');
    }

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

    public function getStudents($id) {
        $students = \App\AdmEntry::where('idSection','=',$id)
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                ->get()->pluck('name','idStudent')->toArray();
        return json_encode($students);
    }

    public function getPromotionStudents($id,$year) {
        $students = \App\AdmEntry::where('idSection','=',$id)
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                ->get()->pluck('name','idStudent')->toArray(); 
        foreach ($students as $key => $value) {
            $ecNo = substr(explode("(",$value)[1],0,-1);
            if(\App\AdmEntry::where('idFinancialYear','=', $year)
                ->where('idStudent','=',$key)
                ->exists()){
             $students[$key] =  $value . '<span style="color:red;"> Promoted<span>';
           }
        }               
        return json_encode($students);
    }
    
    public function getFeeheads($id) {
        $feeheads = \App\FeeHead::where('idSection','=',$id)->get()->pluck('feeheadName','idFeehead')->toArray();
        return json_encode($feeheads);
    }

    public function getStudentFeehead($id) {
        $students = \App\AdmEntry::where('idStudent',$id)->where('idFinancialYear', '=', Session::get('idFinancialYear'))->first();
        $feeheads = array();
        if( $students != null){
            if($students->idSchool == 25){
                $class_feeheads = \DB::table('feeheads')->where('idClass', '=', $students->idClass)
                    ->where('idSection', '=', $students->idSection)
                    ->where('idFinancialYear', '=', $students->idFinancialYear)
                    ->where('studentCategory', '=', $students->studentType)
                    ->whereNull('idStudent');
                $allcat_feeheads = \DB::table('feeheads')->where('idClass', '=', $students->idClass)
                    ->where('idSection', '=', $students->idSection)
                    ->where('studentCategory', '=', 'All')
                    ->where('idFinancialYear', '=', $students->idFinancialYear)
                    ->whereNull('idStudent');
                $outstanding = \DB::table('feeheads')->where('idClass', '=', $students->idClass)
                    ->where('idSection', '=', $students->idSection)
                    ->where('studentCategory', '=', 'All')
                    ->where('idFinancialYear', '=', $students->idFinancialYear)
                    ->where('feeheadName', 'LIKE','Outstanding Payment%')
                    ->whereNull('feeheadLabel')
                    ->where('idStudent', '=', $students->idStudent);
                $feeheads = \DB::table('feeheads')->where('idStudent', '=', $students->idStudent)
                    ->where('idFinancialYear', '=', $students->idFinancialYear)
                    ->union($class_feeheads)
                    ->union($allcat_feeheads)
                    ->union($outstanding)
                    ->orderBy('idFeehead', 'ASC')
                    ->orderBy('toDate')
                    ->get()->pluck('feeheadName','idFeehead')->toArray();

                foreach($feeheads as $key => $value){
                    $feeheads[$key] = $value;
                }
            }else if($students->idSchool == 140 || $students->idSchool == 135){
                $class_feeheads = \DB::table('feeheads')->where('idClass', '=', $students->idClass)
                        ->where('idSection', '=', $students->idSection)
                        ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                        ->where('studentCategory', '=', $students->studentType)
                        ->whereNull('idStudent');
                $allcat_feeheads = \DB::table('feeheads')->where('idClass', '=', $students->idClass)
                            ->where('idSection', '=', $students->idSection)
                            ->where('studentCategory', '=', 'All')
                            ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                            ->whereNull('idStudent');
                $feeheadsData = \DB::table('feeheads')->where('idStudent', '=', $students->idStudent)
                            ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                            ->union($class_feeheads)
                            ->union($allcat_feeheads)
                            ->orderBy('toDate')
                            ->get()->pluck('feeheadName','idFeehead')->toArray();;
                foreach($feeheadsData as $key => $value){
                    $feeheads[$key] = $value;
                }
            }else{
                $feeheadsStudent = \App\FeeHead::where('idStudent','=',$id)->get()->pluck('feeheadName','idFeehead')->toArray();
                foreach($feeheadsStudent as $key => $value){
                    $feeheads[$key] = $value;
                }
                $feeheadsData = \App\FeeHead::where('idSection','=',$students->idSection)->where('idClass','=',$students->idClass)->whereNull('idStudent')->whereIn('studentCategory',['All',$students->studentType])->get()->pluck('feeheadName','idFeehead')->toArray();
                foreach($feeheadsData as $key => $value){
                    $feeheads[$key] = $value;
                }
            }
            
            
        }
        return json_encode($feeheads);
    }
    
    public function getSectionsStudents($id) {
        $sections_ids = array_map('intval', explode(',', $id));
        $students = \App\AdmEntry::whereIn('idSection',$sections_ids)
                ->where('idFinancialYear', '=', Session::get('idFinancialYear'))
                ->get()->pluck('name','idStudent')->toArray();
        return json_encode($students);
    }
    public function getCatwiseStudents($id,$type) {
        $sections_ids = array_map('intval', explode(',', $id));
        $students = \App\AdmEntry::whereIn('idSection',$sections_ids)
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                ->where('studentType','=',$type)
                ->get()->pluck('name','idStudent')->toArray();
        return json_encode($students);
    }
    
    public function getCategorywiseStudents($id,$type) {
        $sections_ids = array_map('intval', explode(',', $id));
        $cat_ids = explode(',', $type);
        if(sizeof($cat_ids)>1)
        {
            $students = \App\AdmEntry::whereIn('idSection',$sections_ids)
                 ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                ->whereIn('studentType',$cat_ids)
                ->get()->pluck('name','idStudent')->toArray();
        }
        else 
        $students = \App\AdmEntry::whereIn('idSection',$sections_ids)
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))
                ->where('studentType','=',$type)
                ->get()->pluck('name','idStudent')->toArray();
                
        return json_encode($students);
    }
}

Copyright © 2021 - 2025 IMMREX7