IMMREX7
<?php
namespace App\Http\Controllers\School;
use Illuminate\Http\Request;
use Auth;
use DB;
use Session;
class NorthFineMaster extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request) {
$flat=DB::table('northfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
->where('idFinancialYear', Session::get('idFinancialYear'))
->where('isFlat', 1)
->first();
$per=DB::table('northfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
->where('idFinancialYear', Session::get('idFinancialYear'))
->where('isFlat', 0)
->get();
return view('schools.north.assign_fine', compact('flat','per'));
}
public function store(Request $request) {
$msg_success='';
if($request->action=='flat'){
if(isset($request->flatfine)){
$flatID=DB::table('northfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
->where('idFinancialYear', Session::get('idFinancialYear'))
->where('isFlat', 1)
->first();
if(isset($flatID->idFine)){
DB::table('northfines')->where('idFine', $flatID->idFine)
->update(
['amount'=>$request->flatfine]
);
$msg_success='Fine Updated Successfully';
}else{
DB::table('northfines')->insert(
['idSchool' => Auth::guard('school')->user()->idSchool, 'idFinancialYear' => Session::get('idFinancialYear'),'isFlat'=>'1','amount'=>$request->flatfine]
);
$msg_success='Fine Added Successfully';
}
}else{
$msg='Fine Amount is mandatory!!';
return view('schools.north.assign_fine', compact('msg'));
}
}else if($request->action=='per'){
foreach ($request->fine as $var) {
$flatID=DB::table('northfines')->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('northfines')->where('idFine', $flatID->idFine)
->update(
['amount'=>$var['amount']]
);
$msg_success='Fine Successfully Updated';
}else{
DB::table('northfines')->insert(
['idSchool' => Auth::guard('school')->user()->idSchool, 'idFinancialYear' => Session::get('idFinancialYear'),'isFlat'=>'0','amount'=>$var['amount'],'days'=>$var['days']]
);
$msg_success='Fine Added Successfully';
}
}
}
$flat=DB::table('northfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
->where('idFinancialYear', Session::get('idFinancialYear'))
->where('isFlat', 1)
->first();
$per=DB::table('northfines')->where('idSchool', Auth::guard('school')->user()->idSchool)
->where('idFinancialYear', Session::get('idFinancialYear'))
->where('isFlat', 0)
->get();
return view('schools.north.assign_fine', compact('flat','msg_success','per'));
}
public function destroy($id) {
DB::table('northfines')->where('idFine', $id)->delete();
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
}
Copyright © 2021 -