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

<?php

namespace App\Http\Controllers\School;

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

class AssignOvertimeController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        $departments = ['' => '--Select--'] + \App\Department::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('departmentName')->get()->pluck('departmentName', 'idDepartment')->toArray();
        $shifts = \App\Shift::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->orderBy('shiftName')->get()->pluck('shiftName', 'idShift')->toArray();
        $assigned_overtime = \App\AssignOvertime::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idOvertime', 'desc');
        if ($request->has('idFinancialYear')) {
            $assigned_overtime = $assigned_overtime->where('idFinancialYear', '=', $request->idFinancialYear)->get();
        } else {
            $assigned_overtime = $assigned_overtime->where('idFinancialYear', '=', Session::get('idFinancialYear'))->get();
        }
        return view('schools.hrms.assign_overtime', compact('assigned_overtime', 'departments', 'shifts'));
    }

    /**
     * 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 = [
            'idDepartment' => 'required',
            'otAfter' => 'required',
            'otRatio' => 'required'
        ];
        if (count($request->designations) == 0) {
            $rules += ['idDesignation' => 'required'];
        }
        $messages = [
            'idDepartment.required' => 'Department must be selected.',
            'idDesignation.required' => 'At least one designation must be selected.'
        ];
        $this->validate($request, $rules, $messages);
        if ($request->has('employees')) {
            foreach ($request->employees as $key => $value) {
                $emp = \App\Employee::where('idEmployee', '=', $value)->first();
                $overtime = new \App\AssignOvertime();
                $overtime->fill($request->all());
                $overtime->idEmployee = $value;
                $overtime->idDesignation = $emp->idDesignation;
                $overtime->idSchool = Auth::guard('school')->user()->idSchool;
                $overtime->idFinancialYear = Session::get('idFinancialYear');
                $overtime->save();
            }
        } else {
            foreach ($request->designations as $key1 => $value1) {
                $overtime = new \App\AssignOvertime();
                $overtime->fill($request->all());
                $overtime->idDesignation = $value1;
                $overtime->idSchool = Auth::guard('school')->user()->idSchool;
                $overtime->idFinancialYear = Session::get('idFinancialYear');
                $overtime->save();
            }
        }
        flash('Overtime has been assigned successfully !!');
        if ($request->ajax()) {
            return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
        }
        return redirect('school/assignovertime');
    }

    /**
     * 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) {
        $departments = ['' => '--Select--'] + \App\Department::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('departmentName')->get()->pluck('departmentName', 'idDepartment')->toArray();
        $shifts = \App\Shift::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->orderBy('shiftName')->get()->pluck('shiftName', 'idShift')->toArray();
        $assigned_overtime = \App\AssignOvertime::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->orderBy('idOvertime', 'desc')->get();
        $overtime = \App\AssignOvertime::where('idOvertime', '=', $id)->first();
        $designations = \App\Designation::where('idDepartment', '=', $overtime->idDepartment)->get()->pluck('designationName', 'idDesignation')->toArray();
        $employees = ['' => 'Select'] + \App\Employee::where('idDesignation', '=', $overtime->idDesignation)->get()->pluck('name', 'idEmployee')->toArray();
        return view('schools.hrms.assign_overtime', compact('assigned_overtime', 'departments', 'shifts', 'overtime', 'employees', 'designations'));
    }

    /**
     * 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 = [
            'idDepartment' => 'required',
            'idDesignation' => 'required',
            'otAfter' => 'required',
            'otRatio' => 'required'
        ];
        $messages = [
            'idDepartment.required' => 'Department must be selected.',
            'idDesignation.required' => 'At least one designation must be selected.'
        ];
        $this->validate($request, $rules, $messages);
        $overtime = \App\AssignOvertime::where('idOvertime', '=', $id)->first();
        $overtime->fill($request->all());
        $overtime->update();
        return redirect('school/assignovertime');
    }

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

}

Copyright © 2021 - 2025 IMMREX7