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

<?php

namespace App\Http\Controllers\School;

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

class ClassPromotionController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        $category = ['' => '--Select--'] + \App\StudentCategoryModel::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
        ->orderBy('categoryName')->get()->pluck('categoryName', 'categoryName')->toArray();
        $classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        return view('schools.students.class_promotion', compact('classes','category'));
    }

    /**
     * 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',
            'idSection' => 'required',
            'idClassPromoted' => 'required',
            'idSectionPromoted' => 'required'
        ];
        if ($request->has('students')) {
            if (count($request->students) == 0) {
                $rules += ['idStudent' => 'idStudent'];
            }
        } else {
            $rules += ['idStudent' => 'idStudent'];
        }
        $messages = [
            'idClass.required' => 'Select Class.',
            'idSection.required' => 'Select Section',
            'idClassPromoted.required' => 'Select Class to be Promoted',
            'idSectionPromoted.required' => 'Select Section to be Promoted',
            'idStudent.required' => 'Atleast One student must be selected.'
        ];
        $this->validate($request, $rules, $messages);
        //dd($request->all());
        foreach ($request->students as $key => $value) {
            $std = \App\AdmEntry::where('idStudent', '=', $value)->first();
            unset($std['created_at'], $std['updated_at']);
            $clone = $std->replicate();
            $clone->save();
         //   \App\AdmEntry::create($clone->toArray());
            if(isset($request->stdCategory)){
                $std->studentType = $request->stdCategory;
            }
            $std->idClass = $request->idClassPromoted;
            $std->idSection = $request->idSectionPromoted;
            $std->idFinancialYear = $request->idFinancialYear;
            $std->update();

            DB::table('student_transaction')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('student_transaction_details')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('lesser_transaction')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('lesser_transaction_details')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('student_discounts')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('student_transaction_extra')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('student_transaction_extra_details')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('bus_lesser_transaction')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('bus_lesser_transaction_details')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('bus_transaction')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('student_transport')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));

            DB::table('bus_transaction_details')
            ->where('idStudent', $std->idStudent)
            ->update(array('idStudent' => $clone->idStudent));
        }
        if ($request->ajax()) {
            return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
        }
        return redirect('school/stdstrength');
    }

    /**
     * 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) {
        //
    }

    /**
     * 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 stdStrength(Request $request) {
        $classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();

        if(Auth::guard('school')->user()->idSchool == 135 || Auth::guard('school')->user()->idSchool == 140){
            if ($request->has('idClass') && $request->idClass != null) {
                $students = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
                                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                                ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                                ->where('students.idClass', '=', $request->idClass)
                                ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                                ->where('isActive', '=', 'Y')
                                ->select(DB::raw("className,sectionName,sum(case when students.gender = 'Male' then 1 else 0 end) as boys,sum(case when students.gender = 'Female' then 1 else 0 end) as girls"),'studentType')
                                ->groupBy(DB::raw('1,2','studentType'))->orderBy('classes.idClass')->orderBy('sectionName')->get();
            } else if ($request->has('idSection') && $request->idSection != null) {
                $students = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
                                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                                ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                                ->where('students.idSection', '=', $request->idSection)
                                ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                                ->where('isActive', '=', 'Y')
                                ->select(DB::raw("className,sectionName,sum(case when students.gender = 'Male' then 1 else 0 end) as boys,sum(case when students.gender = 'Female' then 1 else 0 end) as girls"),'studentType')
                                ->groupBy(DB::raw('1,2','studentType'))->orderBy('classes.idClass')->orderBy('sectionName')->get();
            } else {
                $students = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
                                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                                ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                                ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                                ->where('isActive', '=', 'Y')
                                ->select(DB::raw("className,sectionName,sum(case when students.gender = 'Male' then 1 else 0 end) as boys,sum(case when students.gender = 'Female' then 1 else 0 end) as girls"),'studentType')
                                ->groupBy(DB::raw('1,2'),'studentType')->orderBy('classes.idClass')->orderBy('sectionName')->get();
            }
        }else{
            if ($request->has('idClass') && $request->idClass != null) {
                $students = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
                                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                                ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                                ->where('students.idClass', '=', $request->idClass)
                                ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                                ->where('isActive', '=', 'Y')
                                ->select(DB::raw("className,sectionName,sum(case when students.gender = 'Male' then 1 else 0 end) as boys,sum(case when students.gender = 'Female' then 1 else 0 end) as girls"))
                                ->groupBy(DB::raw('1,2'))->orderBy('classes.idClass')->orderBy('sectionName')->get();
            } else if ($request->has('idSection') && $request->idSection != null) {
                $students = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
                                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                                ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                                ->where('students.idSection', '=', $request->idSection)
                                ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                                ->where('isActive', '=', 'Y')
                                ->select(DB::raw("className,sectionName,sum(case when students.gender = 'Male' then 1 else 0 end) as boys,sum(case when students.gender = 'Female' then 1 else 0 end) as girls"))
                                ->groupBy(DB::raw('1,2'))->orderBy('classes.idClass')->orderBy('sectionName')->get();
            } else {
                $students = \App\AdmEntry::join('classes', 'students.idClass', '=', 'classes.idClass')
                                ->join('sections', 'students.idSection', '=', 'sections.idSection')
                                ->where('students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                                ->where('students.idFinancialYear', '=', Session::get('idFinancialYear'))
                                ->where('isActive', '=', 'Y')
                                ->select(DB::raw("className,sectionName,sum(case when students.gender = 'Male' then 1 else 0 end) as boys,sum(case when students.gender = 'Female' then 1 else 0 end) as girls"))
                                ->groupBy(DB::raw('1,2'))->orderBy('classes.idClass')->orderBy('sectionName')->get();
            }
            
        }

        //dd($students);
        $totals = ['boys' => 0, 'girls' => 0, 'total' => 0];
        foreach ($students as $value) {
            $totals['boys'] += $value->boys;
            $totals['girls'] += $value->girls;
            $totals['total'] += $value->boys + $value->girls;
        }

        $data = compact('students', 'totals') + ['sec_house' => 'section'];
        return view('schools.students.student_strength', $data, compact('classes'));
    }

}

Copyright © 2021 - 2025 IMMREX7