IMMREX7

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

<?php

namespace App\Http\Controllers;

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

class SectionController extends Controller {

    public function index(Request $request) {
        $name = $request->get('name');
        switch($name){
            case "classes" : 
                return DB::table('classes')->select('idClass','className')->where('idSchool',$request->get('id'))->get()->pluck('className','idClass');
            case "section" : 
                return DB::table('sections')->select('idSection','sectionName')->where('idClass',$request->get('id'))->get()->pluck('sectionName','idSection');
            case "student" : 
                return DB::table('students')->select('idStudent',DB::raw('CONCAT(firstName,"-",ecNo) as name'))->where('idSection',$request->get('id'))->get()->pluck('name','idStudent');
        }

        return json_encode([]);
    }

    /**
     * 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) {   
        $transaction = 1;
        $student = DB::table('students')->select('idStudent','firstName','ecNo','idClass','idSection','idFinancialYear')->where('idStudent',$request->idStudent)->first();
        $updateClass = DB::table('classes')->select('idClass','className')->where('idClass',$request->idChangeClass)->first();
        $updateSection = DB::table('sections')->select('idSection','sectionName')->where('idSection',$request->idChangeSection)->first();
        $paidfees = \App\StudentTransaction::join('student_transaction_details', 'student_transaction.idTransaction', '=', 'student_transaction_details.idTransaction')->where('student_transaction.idStudent', '=', $student->idStudent)
        ->where('student_transaction.idFinancialYear', '=', $student->idFinancialYear)->get();
        $lesserfees = \App\LesserTransaction::join('lesser_transaction_details', 'lesser_transaction_details.idLesserTransaction', '=', 'lesser_transaction.idLesserTransaction')->where('lesser_transaction.idStudent', '=', $student->idStudent)
        ->where('lesser_transaction.idFinancialYear', '=', $student->idFinancialYear)->get();
        $ufeeheaders = $this->getStudentFeehead( $student->idStudent,$student->idFinancialYear, $request->idChangeClass,$request->idChangeSection);
        return view('superadmin.section', compact('transaction','paidfees','lesserfees','student','updateSection','updateClass','ufeeheaders'));
    }

    public function getStudentFeehead($id,$idFinancialYear, $idClass, $idSection) {
        $students = \App\AdmEntry::where('idStudent',$id)->where('idFinancialYear', '=',$idFinancialYear)->first();
        $feeheads = array();
        if( $students != null){
            if($students->idSchool == 25){
                $class_feeheads = \DB::table('feeheads')->where('idClass', '=', $idClass)
                    ->where('idSection', '=', $idSection)
                    ->where('idFinancialYear', '=', $students->idFinancialYear)
                    ->where('studentCategory', '=', $students->studentType)
                    ->whereNull('idStudent');
                $allcat_feeheads = \DB::table('feeheads')->where('idClass', '=', $idClass)
                    ->where('idSection', '=', $idSection)
                    ->where('studentCategory', '=', 'All')
                    ->where('idFinancialYear', '=', $students->idFinancialYear)
                    ->whereNull('idStudent');
                $outstanding = \DB::table('feeheads')->where('idClass', '=', $idClass)
                    ->where('idSection', '=', $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', '=', $idClass)
                        ->where('idSection', '=', $idSection)
                        ->where('idFinancialYear','=', $students->idFinancialYear)
                        ->where('studentCategory', '=', $students->studentType)
                        ->whereNull('idStudent');
                $allcat_feeheads = \DB::table('feeheads')->where('idClass', '=', $idClass)
                            ->where('idSection', '=', $idSection)
                            ->where('studentCategory', '=', 'All')
                            ->where('idFinancialYear','=', $students->idFinancialYear)
                            ->whereNull('idStudent');
                $feeheadsData = \DB::table('feeheads')->where('idStudent', '=', $students->idStudent)
                            ->where('idFinancialYear','=', $students->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','=',$idSection)->where('idClass','=',$idClass)->whereNull('idStudent')->whereIn('studentCategory',['All',$students->studentType])->get()->pluck('feeheadName','idFeehead')->toArray();
                foreach($feeheadsData as $key => $value){
                    $feeheads[$key] = $value;
                }
            }
            
            
        }
        return $feeheads;
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        //
        $schoolName = ['' => 'Select School']+DB::table('schools')->select('schoolName','idSchool')->where('idSchool',$id)->orderBy('schoolName','DESC')->get()->pluck('schoolName','idSchool')->toArray();
        return view('superadmin.section', compact('schoolName'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
       DB::beginTransaction();
       $student = \App\AdmEntry::where('idStudent', '=', $request->idStudent)->first();
       if($student != null){
            if(isset($request->feeheader)){
                if(is_array($request->feeheader)){
                    if(count($request->feeheader) > 0){
                        foreach ($request->feeheader as $key => $value) {
                            if(isset($value["old"]) && isset($value["new"])){
                                if($value["type"] == "full"){
                                    DB::table('student_transaction_details')
                                        ->where('idStudent', $id)
                                        ->where('idFeehead', $value["old"])
                                        ->update(['idFeehead' =>  $value["new"]]);
                                }else{
                                    DB::table('lesser_transaction_details')
                                        ->where('idStudent', $id)
                                        ->where('idFeehead', $value["old"])
                                        ->update(['idFeehead' =>  $value["new"]]);
                                }
                            
                            }
                        }
                    }
                }
            }

            $student->idClass = $request->idClass;
            $student->idSection = $request->idSection;
            $student->update();
       }
       DB::commit();
       flash('Student Updated Successfully');
       return redirect('admin');
    }

}

Copyright © 2021 - 2025 IMMREX7