IMMREX7
<?php
namespace App\Http\Controllers\School;
use Illuminate\Http\Request;
use Auth;
use DB;
use Session;
class NorthFeeHeaderController extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request) {
$search_classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$htypes = ['fee' => 'Student Fee','bus' => 'Bus Fee','hostel' => 'Hostel Fee'];
$feeheads = array();
$heads = [''=>'---Select---'] + \App\Header::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('isActive','=','Y')
->get()->pluck('headerName','idHeader')->toArray();
/*$feeheads = \App\NorthFeeHead::join('northfeeheads as parent', 'parent.idFeehead', '=', 'northfeeheads.isParent')
->select('northfeeheads.feeheadName','parent.amount as totalAmount','parent.idFeehead as parentID','parent.feeheadName as demandName','parent.fromDate','parent.fine as fine','parent.idType as type')
->get();*/
$feeheads= \App\NorthFeeHead::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('idFinancialYear', '=', Session::get('idFinancialYear'))
->where('isParent', '=', 0)
->where('isActive','=','Y')
// ->select('feeheadName','amount','fromDate','toDate','idClass','fine','idType')
// ->distinct()
->orderBy('idFeehead', 'desc');
if ($request->has('studentCategory') && $request->studentCategory != null) {
$feeheads = $feeheads->whereIn('idSection', $request->sections)->get();
} elseif ($request->has('sections') && count($request->sections) > 0) {
$feeheads = $feeheads->whereIn('idSection', $request->sections)->get();
} elseif ($request->has('classes') && count($request->classes) > 0) {
$feeheads = $feeheads->whereIn('idClass', $request->classes)->get();
} else {
$feeheads = $feeheads->get();
}
$categories = \App\StudentCategoryModel::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('categoryName', 'categoryName')->toArray();
return view('schools.north.feeheads.index', compact('heads','feeheads', 'classes', 'categories', 'search_classes','htypes'));
}
/**
* 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) {
//dd($request->all());
$rules = [
'idClass' => 'required',
'demandName' => 'required',
'fromDate' => 'required|date',
'toDate' => 'required|date',
'amount' => 'required',
// 'ecNO' => 'required'
];
if (count($request->sections) == 0) {
$rules += ['idSection' => 'required'];
}
if (count($request->studentCategory) == 0) {
$rules += ['studentCategory' => 'required'];
}
if (count($request->students) == 0) {
$rules += ['students' => 'required'];
}
$messages = [
'idClass.required' => 'Class must be selected.',
'idSection.required' => 'Section must be selected.',
'studentCategory.required' => 'Category must be selected.',
'students.required' => 'Student must be selected.'
];
$this->Validate($request, $rules, $messages);
if ($request->has('students')) {
foreach ($request->students as $key => $value) {
$std = \App\AdmEntry::where('idStudent', '=', $value)->first();
//Create parent feeHeader
$feehead = new \App\NorthFeeHead();
$feehead->idSchool = Auth::guard('school')->user()->idSchool;
$feehead->idClass = $std->idClass;
$feehead->idStudent = $value;
$feehead->ecNO = $std->ecNo;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->idSection = $std->idSection;
$feehead->studentCategory = $std->studentType;
$feehead->fromDate = $request->fromDate;
$feehead->toDate = $request->toDate;
$feehead->fine=$request->idFine;
$feehead->idType= $request->idType;
$feehead->demandName=$request->demandName;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->amount = $request->amount;
$feehead->save();
$parentID=$feehead->idFeehead;
foreach ($request->header as $var) {
//Create Child feeHeader
$feehead = new \App\NorthFeeHead();
$feehead->fill($request->all());
$feehead->idStudent = $value;
$feehead->ecNO = $std->ecNo;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->idSection = $std->idSection;
$feehead->studentCategory = $std->studentType;
$feehead->fine = $request->fine;
$feehead->idSchool = Auth::guard('school')->user()->idSchool;
$feehead->idHeader=$var['idHeader'];
$feehead->amount =$var['amountName'];
$feehead->isParent = $parentID;
$feehead->save();
}
}
} else {
foreach ($request->sections as $key1 => $value1) {
//Create parent feeHeader
$feehead = new \App\NorthFeeHead();
$feehead->idSchool = Auth::guard('school')->user()->idSchool;
$feehead->idClass = $request->idClass;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->idSection = $value1;
$feehead->studentCategory = $std->studentType;
$feehead->fromDate = $request->fromDate;
$feehead->toDate = $request->toDate;
$feehead->fine=$request->idFine;
$feehead->idType= $request->idType;
$feehead->demandName=$request->demandName;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->amount = $request->amount;
$feehead->save();
$parentID=$feehead->idFeehead;
foreach ($request->header as $var) {
$feehead = new \App\NorthFeeHead();
//$feehead->fill($request->all());
// $feehead->demandName=null;
$feehead->idSection = $value1;
$feehead->idSchool = Auth::guard('school')->user()->idSchool;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->fine = $request->fine;
$feehead->idHeader=$var['idHeader'];
$feehead->amount =$var['amountName'];
$feehead->isParent = $parentID;
$feehead->save();
}
}
}
//flash('Fee-Header has been saved successfully !!');
if ($request->ajax()) {
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
//return redirect('school/feeheads');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
$feehead = \App\NorthFeeHead::findOrFail($id);
return json_encode($feehead);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {
$search_classes = \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$feehead = \App\NorthFeeHead::findOrFail($id);
$childheads=\App\NorthFeeHead::where('isParent', '=', $id)->get();
$sections = \App\Section::where('idClass', '=', $feehead->idClass)->get()->pluck('sectionName', 'idSection')->toArray();
$description = \App\NorthFeeHead::where('demandName','=',$feehead->demandName)->where('amount','=',$feehead->amount)->where('idClass','=',$feehead->idClass)->get()->pluck('ecNO')->toArray();
$students = \App\AdmEntry::whereIn('ecNo',$description)->get()->pluck('name', 'idStudent')->toArray();
$student = \App\AdmEntry::where('idSection', '=', $feehead->idSection)->get()->pluck('name', 'idStudent')->toArray();
$categories = array();
$htypes = ['fee' => 'Student Fee','bus' => 'Bus Fee','hostel' => 'Hostel Fee'];
$heads = [''=>'---Select---'] + \App\Header::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->get()->pluck('headerName','idHeader')->toArray();
return view('schools.north.feeheads.edit', compact('search_classes','heads','feehead', 'sections', 'classes', 'students','student', 'categories','childheads','htypes','description'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
// dd($request);
//
$rules = [
// 'idClass' => 'required',
'idSection' => 'required',
// 'feeheadName' => 'required',
'fromDate' => 'required|date',
'toDate' => 'required|date',
'amount' => 'required',
// 'fine' => 'required_without:flatFine',
// 'ecNO' => 'required'
];
$messages = [
'idClass.required' => 'Class must be selected.',
'idSection.required' => 'Section must be selected.'
];
$this->validate($request, $rules, $messages);
DB::beginTransaction();
$parentfeehead=\App\NorthFeeHead::findOrFail($request->demand_pv);
//update parent details
$parentfeehead->demandName=$request->demandName;
$parentfeehead->amount=$request->amount;
$parentfeehead->toDate= $request->toDate;
$parentfeehead->fromDate=$request->fromDate;
$parentfeehead->fine=$request->idFine;
$parentfeehead->update();
//get child details
$descriptions = \App\NorthFeeHead::where('isParent','=',$parentfeehead->idFeehead)->get();
$std = \App\AdmEntry::where('idStudent', '=', $parentfeehead->idStudent)->first();
foreach($descriptions as $headers){
foreach($request->header as $headersAdded)
{
if(isset($headersAdded['prevName'])){
if($headers->idHeader == $headersAdded['prevName'])
{
$headers->idHeader=$headersAdded['idHeader'];
$headers->amount=$headersAdded['amountName'];
$headers->update();
}
}
}
}
foreach($request->header as $headersAdded){
if(!isset($headersAdded['prevName'])){
$feehead = new \App\NorthFeeHead();
$feehead->fill($request->all());
$feehead->idClass = $std->idClass;
$feehead->idStudent = $std->idStudent;
$feehead->ecNO = $std->ecNo;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->idSection = $std->idSection;
$feehead->studentCategory = $std->studentType;
$feehead->fine = $request->fine;
$feehead->idSchool = Auth::guard('school')->user()->idSchool;
$feehead->idType= $parentfeehead->idType;
$feehead->idHeader=$headersAdded['idHeader'];
$feehead->amount =$headersAdded['amountName'];
$feehead->isParent = $parentfeehead->idFeehead;
$feehead->save();
}
}
DB::commit();
if ($request->has('students')) {
foreach ($request->students as $key => $value) {
$std = \App\AdmEntry::where('idStudent', '=', $value)->first();
//Create parent feeHeader
$feehead = new \App\NorthFeeHead();
$feehead->idSchool = Auth::guard('school')->user()->idSchool;
$feehead->idClass = $std->idClass;
$feehead->idStudent = $value;
$feehead->ecNO = $std->ecNo;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->idSection = $std->idSection;
$feehead->studentCategory = $std->studentType;
$feehead->fromDate = $request->fromDate;
$feehead->toDate = $request->toDate;
$feehead->fine=$request->idFine;
$feehead->idType= $feehead_prev->idType;
$feehead->demandName=$request->demandName;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->amount = $request->amount;
$feehead->save();
$parentID=$feehead->idFeehead;
foreach ($request->header as $var) {
//Create Child feeHeader
$feehead = new \App\NorthFeeHead();
$feehead->fill($request->all());
$feehead->idClass = $std->idClass;
$feehead->idStudent = $value;
$feehead->ecNO = $std->ecNo;
$feehead->idFinancialYear = Session::get('idFinancialYear');
$feehead->idSection = $std->idSection;
$feehead->studentCategory = $std->studentType;
$feehead->fine = $request->fine;
$feehead->idSchool = Auth::guard('school')->user()->idSchool;
$feehead->idType= $feehead_prev->idType;
$feehead->idHeader=$var['idHeader'];
$feehead->amount =$var['amountName'];
$feehead->isParent = $parentID;
$feehead->save();
}
}
}
return redirect('school/north/feeheads');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$childHeader=\App\NorthFeeHead::where('isParent', '=', $id)->get();
foreach($childHeader as $header){
$header->isActive = 'N';
}
$feehead = \App\NorthFeeHead::where('idFeehead', '=', $id)->first();
$feehead->isActive = 'N';
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
}
Copyright © 2021 -