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

<?php

namespace App\Http\Controllers\School;

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

class BusFeeDiscountController extends SchoolController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        //
        $stddiscounts = \App\BusFeeDiscount::leftJoin('school_users', 'busfee_discounts.created_by', '=', 'school_users.idSchoolUser')->select('busfee_discounts.*','school_users.name')
                       ->where('busfee_discounts.idSchool', '=', Auth::guard('school')->user()->idSchool)
                       ->orderBy('idBusFeeDiscount', 'desc');
        if($request->has('idFinancialYear')){
            $stddiscounts = $stddiscounts->where('idFinancialYear','=',$request->idFinancialYear)->get();
        }else{
            $stddiscounts = $stddiscounts->where('idFinancialYear','=', Session::get('idFinancialYear'))->get();
        }
        $classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $feeheads = [''=>'--Select--'] + \App\BusFeehead::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))->get()->pluck('feeheadName','idBusFeehead')->toArray();
        return view('schools.buses.assign_discount', compact('classes', 'stddiscounts','feeheads'));
    }

    /**
     * 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',
            'idStudent' => 'required',
            'idBusFeehead' => 'required',
            'amount' => 'required_without:percentage'
        ];
        $messages = [
            'idClass.required' => 'Class must be selected',
            'idSection.required' => 'Section must be selected',
            'idBusFeehead.required' => 'Select Fee Header in which you want to assign discount',
            'idStudent.required' => 'Select Students Enrollment no.'
        ];
        $this->validate($request, $rules, $messages);
        $discount = new \App\BusFeeDiscount();
        $discount->fill($request->all());
        $discount->idSchool = Auth::guard('school')->user()->idSchool;
        $discount->idFinancialYear = Session::get('idFinancialYear');
        $discount->isActive = 'Y';
        $discount->created_by = Auth::guard('school')->user()->idSchoolUser;
        $discount->save();
        return redirect('school/busfeediscount');
    }

    /**
     * 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) {
        $stddiscounts = \App\BusFeeDiscount::leftJoin('school_users', 'busfee_discounts.created_by', '=', 'school_users.idSchoolUser')
                        ->select('busfee_discounts.*','school_users.name')
                        ->where('busfee_discounts.idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->where('idFinancialYear', '=', Session::get('idFinancialYear'))
                        ->orderBy('idBusFeeDiscount', 'desc')->get();
        $classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
        $discount = \App\BusFeeDiscount::where('idBusFeeDiscount', '=', $id)->first();
        $feeheads = [''=>'--Select--'] + \App\BusFeehead::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))->get()->pluck('feeheadName','idBusFeehead')->toArray();
//        $class =  \App\ClassM::where('idClass', '=', $discount->student->classM->idClass)->get()->pluck('className', 'idSection')->toArray();

        return view('schools.buses.assign_discount', compact('classes', 'stddiscounts','feeheads', 'discount'));
    }

    /**
     * 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',
//            'idSection' => 'required',
//            'idStudent' => 'required',
            'idBusFeehead' => 'required',
            'amount' => 'required_without:percentage'
        ];
        $messages = [
            'idClass.required' => 'Class must be selected',
            'idSection.required' => 'Section must be selected',
            'idBusFeehead.required' => 'Select Fee Header in which you want to assign discount',
            'idStudent.required' => 'Select Students Enrollment no.'
        ];
        $this->validate($request, $rules, $messages);
        $discount = \App\BusFeeDiscount::where('idBusFeeDiscount', '=', $id)->first();
        $discount->fill($request->all());
        $discount->updated_by = Auth::guard('school')->user()->idSchoolUser;
        $discount->update();
        return redirect('school/busfeediscount');
    }

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

    public function activateDiscount($id) {
        $discount = \App\BusFeeDiscount::where('idBusFeeDiscount', '=', $id)->first();
        $discount->isActive = 'Y';
        $discount->update();
        return redirect('school/busfeediscount');
    }

    public function deactivateDiscount($id) {
        $discount = \App\BusFeeDiscount::where('idBusFeeDiscount', '=', $id)->first();
        $discount->isActive = 'N';
        $discount->update();
        return redirect('school/busfeediscount');
    }
    
    public function getBusFeehead($id) {
        $stdtransport = \App\StudentTransport::where('idStudent','=',$id)
                ->where('idFinancialYear','=', Session::get('idFinancialYear'))->first();
        $feehead = \App\BusFeehead::where('idStop','=',$stdtransport->idStop)
                ->get()->pluck('feeheadName','idBusFeehead')->toArray();
        return json_encode($feehead);
        
    }
}

Copyright © 2021 - 2025 IMMREX7