IMMREX7

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

<?php

namespace App\Http\Controllers\School\Hostel;

use Illuminate\Http\Request;
use App\Http\Controllers\School\SchoolController;
use Auth;
use DB;
use App\Http\SendSmsApi;
use Carbon\Carbon;
use Session;

class HosteliteLeaveController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        $leaves = DB::table('hostelite_leaves')
                ->join('hostel_students', 'hostelite_leaves.idHostelite', '=', 'hostel_students.idHostelite')
                ->join('students', 'hostel_students.idStudent', '=', 'students.idStudent')
                ->where('hostelite_leaves.idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->select('ecNo', 'status', 'idHosteliteLeave', 'father_mobile', 'fromDate', 'toDate', 'hostelite_leaves.remarks', DB::raw('CONCAT(firstName, " ",lastName) as name'));
        if ($request->has('idFinancialYear')) {
            $leaves = $leaves->where('hostelite_leaves.idFinancialYear', '=', $request->idFinancialYear)->get();
        } else {
            $leaves = $leaves->where('hostelite_leaves.idFinancialYear', '=', Session::get('idFinancialYear'))->get();
        }
        return view('schools.hostel.hostelite_leaves', compact('leaves'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create() {
        $students = ['' => '---Select---'] + DB::table('hostel_students')
                        ->join('students', 'hostel_students.idStudent', '=', 'students.idStudent')
                        ->where('hostel_students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->select('idHostelite', DB::raw('CONCAT(ecno,"-",firstName, " ",lastName) as name'))
                        ->get()->pluck('name', 'idHostelite')->toArray();
        $leaves = DB::table('hostelite_leaves')
                ->join('hostel_students', 'hostelite_leaves.idHostelite', '=', 'hostel_students.idHostelite')
                ->join('students', 'hostel_students.idStudent', '=', 'students.idStudent')
                ->where('hostelite_leaves.idFinancialYear', '=', Session::get('idFinancialYear'))
                ->where('hostelite_leaves.idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->select('idHosteliteLeave', 'fromDate', 'toDate', 'hostelite_leaves.remarks', DB::raw('CONCAT(firstName, " ",lastName) as name'))
                ->get();
        return view('schools.hostel.leaves_application', compact('leaves', 'students'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) {
        $leave = new \App\HosteliteLeave();
        $leave->idSchool = Auth::guard('school')->user()->idSchool;
        $leave->idFinancialYear = Session::get('idFinancialYear');
        $leave->fill($request->all());
        $leave->applicationDate = today_date();
        $leave->save();
        return redirect('school/hostel-leaves/create');
    }

    /**
     * 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) {
        $students = DB::table('hostel_students')
                        ->join('students', 'hostel_students.idStudent', '=', 'students.idStudent')
                        ->where('hostel_students.idSchool', '=', Auth::guard('school')->user()->idSchool)
                        ->select('idHostelite', DB::raw('CONCAT(ecno,"-",firstName, " ",lastName) as name'))
                        ->get()->pluck('name', 'idHostelite')->toArray();
        $leaves = DB::table('hostelite_leaves')
                ->join('hostel_students', 'hostelite_leaves.idHostelite', '=', 'hostel_students.idHostelite')
                ->join('students', 'hostel_students.idStudent', '=', 'students.idStudent')
                ->where('hostelite_leaves.idSchool', '=', Auth::guard('school')->user()->idSchool)
                ->select('idHosteliteLeave', 'fromDate', 'toDate', 'hostelite_leaves.remarks', DB::raw('CONCAT(firstName, " ",lastName) as name'))
                ->get();
        $leave = \App\HosteliteLeave::where('idHosteliteLeave', '=', $id)->first();
        return view('schools.hostel.leaves_application', compact('leaves', 'students', 'leave'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
        $leave = \App\HosteliteLeave::where('idHosteliteLeave', '=', $id)->first();
        $leave->fill($request->all());
        $leave->update();
        return redirect('school/hostel-leaves/create');
    }

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

    public function approveLeave($id) {
        $leave = \App\HosteliteLeave::where('idHosteliteLeave', '=', $id)->first();
        $leave->status = 'Approved';
        $leave->update();
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

    public function sendSMS(Request $request) {
        //dd($request->all());
        $leave = \App\HosteliteLeave::where('idHosteliteLeave', '=', $request->id)->first();
        $hs = \App\Hostelite::where('idHostelite', '=', $leave->idHostelite)->first();
        $student = \App\AdmEntry::where('idStudent', '=', $hs->idStudent)->first();

        $school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
        $message = $request->remarks;
        $phone_number = $student->father_mobile;
        SendSmsApi::getUserNumber($phone_number, $message, $school);
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

}

Copyright © 2021 - 2025 IMMREX7