IMMREX7

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

<?php

namespace App\Http\Controllers\School\Library;

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

class FineSettingController extends SchoolController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {
        $flat = DB::table('libraryfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
                ->where('idFinancialYear', Session::get('idFinancialYear'))
                ->where('isFlat', 1)
                ->first();
        $per = DB::table('libraryfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
                ->where('idFinancialYear', Session::get('idFinancialYear'))
                ->where('isFlat', 0)
                ->get();
        return view('schools.library.fine_setting', compact('flat', 'per'));
    }

    /**
     * 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) {
        $msg_success = '';
        if ($request->action == 'flat') {
            if (isset($request->flatfine)) {
                $flatID = DB::table('libraryfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
                        ->where('idFinancialYear', Session::get('idFinancialYear'))
                        ->where('isFlat', 1)
                        ->first();
                if (isset($flatID->idFine)) {
                    DB::table('libraryfines')->where('idFine', $flatID->idFine)
                            ->update(
                                    ['amount' => $request->flatfine,'freeAllocationDays'=>$request->freeAllocationDays]
                    );
                    $msg_success = 'Fine Updated Successfully';
                } else {
                    DB::table('libraryfines')->insert(
                            ['idSchool' => Auth::guard('school')->user()->idSchool, 'idFinancialYear' => Session::get('idFinancialYear'), 'isFlat' => '1', 'amount' => $request->flatfine,'freeAllocationDays'=>$request->freeAllocationDays]
                    );
                    $msg_success = 'Fine Added Successfully';
                }
            } else {
                $msg = 'Fine Amount is mandatory!!';
                return view('schools.library.fine_setting', compact('msg'));
            }
        } else if ($request->action == 'per') {
            foreach ($request->fine as $var) {
                $flatID = DB::table('libraryfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
                        ->where('idFinancialYear', Session::get('idFinancialYear'))
                        ->where('isFlat', 0)
                        ->where('days', $var['days'])
                        ->first();
                if (isset($flatID->idFine)) {
                    DB::table('libraryfines')->where('idFine', $flatID->idFine)
                            ->update(
                                    ['freeAllocationDays'=>$request->freeAllocationDays,'amount' => $var['amount']]
                    );
                    $msg_success = 'Fine Successfully Updated';
                } else {
                    DB::table('libraryfines')->insert(
                            ['idSchool' => Auth::guard('school')->user()->idSchool, 'idFinancialYear' => Session::get('idFinancialYear'), 'isFlat' => '0', 'freeAllocationDays'=>$request->freeAllocationDays,'amount' => $var['amount'], 'days' => $var['days']]
                    );
                    $msg_success = 'Fine Added Successfully';
                }
            }
        }

        $flat = DB::table('libraryfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
                ->where('idFinancialYear', Session::get('idFinancialYear'))
                ->where('isFlat', 1)
                ->first();
        $per = DB::table('libraryfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
                ->where('idFinancialYear', Session::get('idFinancialYear'))
                ->where('isFlat', 0)
                ->get();
        return view('schools.library.fine_setting', compact('flat', 'msg_success', 'per'));
    }

    /**
     * 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) {
        DB::table('libraryfines')->where('idFine', $id)->delete();
        return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
    }

}

Copyright © 2021 - 2025 IMMREX7