IMMREX7
<?php
namespace App\Http\Controllers\School;
use Illuminate\Validation\Rule;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Auth;
use DB;
use Session;
class OutstandingController extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$fys = \App\OutstandingAmount::select('student_transaction_outstanding.*','className','sectionName','ecNo','firstName','middleName','lastName','financialYearName')->leftJoin('students', 'student_transaction_outstanding.idStudent', '=', 'students.idStudent')
->leftJoin('classes', 'students.idClass', '=', 'classes.idClass')
->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')
->leftJoin('financial_years', 'student_transaction_outstanding.forFy', '=', 'financial_years.idFinancialYear')
->where('student_transaction_outstanding.idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idOutstanding', 'desc')->get();
$classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$sessions = [ "" => "-- Select --" ]+\App\FinancialYear::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->orderBy('startDate','DESC')->get()->pluck('financialYearName', 'idFinancialYear')->toArray();
return view('schools.outstanding.index', compact('fys','sessions','classes'));
}
/**
* 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 = [
'forFy' => 'required',
'amount' => 'required'
];
$message = [
'forFy.required' => 'Next Session must be selected',
'amount.unique' => 'Amount is required',
];
$this->Validate($request, $rules, $message);
if(is_array($request->students)){
if(sizeof($request->students) > 0){
foreach($request->students as $key => $value)
$fy = new \App\OutstandingAmount();
$fy->fill($request->all());
$fy->idStudent = $value;
$fy->idSchool = Auth::guard('school')->user()->idSchool;
$fy->idFinancialYear = Session::get('idFinancialYear');
$fy->save();
}
}
return redirect('school/outstanding');
}
/**
* 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) {
$fys = [];
$classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$outstanding = \App\OutstandingAmount::select('student_transaction_outstanding.*','className','sectionName','ecNo','firstName','middleName','lastName','financialYearName')->leftJoin('students', 'student_transaction_outstanding.idStudent', '=', 'students.idStudent')
->leftJoin('classes', 'students.idClass', '=', 'classes.idClass')
->leftJoin('sections', 'students.idSection', '=', 'sections.idSection')
->leftJoin('financial_years', 'student_transaction_outstanding.forFy', '=', 'financial_years.idFinancialYear')
->where('idOutstanding', '=', $id)->first();
$sessions = [ "" => "-- Select --" ]+\App\FinancialYear::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->orderBy('startDate','DESC')->get()->pluck('financialYearName', 'idFinancialYear')->toArray();
return view('schools.outstanding.index', compact('outstanding', 'fys','sessions','classes'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
$fy = \App\OutstandingAmount::where('idOutstanding', '=', $id)->first();
$rules = [
'forFy' => 'required',
'amount' => 'required'
];
$message = [
'forFy.required' => 'Next Session must be selected',
'amount.unique' => 'Amount is required',
];
$this->Validate($request, $rules, $message);
$fy->fill($request->all());
$fy->update();
return redirect('school/outstanding');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$fy = \App\OutstandingAmount::where('idOutstanding', '=', $id)->first();
$fy->delete();
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
}
Copyright © 2021 -