IMMREX7
<?php
namespace App\Http\Controllers\School;
use Illuminate\Http\Request;
use App\Http\Requests\StudentRequest;
use Session;
use DB;
use Auth;
class AdmissionEntryController extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
$curr_no = \App\NoGenerator::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->where('type', '=', 'admno')->first();
if ($curr_no) {
$next_no = $curr_no->no + 1;
} else {
$next_no = 1;
}
$sch = substr($school->schoolName, 0, 4);
$adm_no = $sch . '000' . $next_no;
$fys = \App\FinancialYear::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
//->where('idFinancialYear', '=', Session::get('idFinancialYear'))
// ->orderBy('financialYearName')
->pluck('financialYearName', 'idFinancialYear')->toArray();
if($school->idCountry == 1)
$states = ['' => '-- Select State --'] + \App\State::orderBy('stateName')->get()->pluck('stateName', 'idState')->toArray();
else $states = ['' => '-- Select State --'] + DB::table('states_qatar')->orderBy('stateName')->get()->pluck('stateName', 'idState')->toArray();
$classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$categories = ['' => '--Select--'] + DB::table('studentCategory')->where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('categoryName', 'categoryName')->toArray();
return view('schools.admentries.index', compact('classes', 'states', 'fys', 'adm_no', 'categories','school'));
}
/**
* 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(StudentRequest $request) {
// dd($request->all());
$checkEcno = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->where('ecNo',$request->ecNo)->first();
if($checkEcno != null){
if ($request->ajax()) {
return response()->json(['message' => "The given data was invalid.", 'errors' => [ 'ecNo' => ["The ec no has already been taken."] ]], 422, ['app-status' => 'success']);
}
flash('Duplicate EC No. found cannot be saved !!');
return redirect()->back();
}
$school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
$student = new \App\AdmEntry();
$student->fill($request->all());
$student->idSchool = $school->idSchool;
$password = 123456;
$next_no = next_admno();
$sch = substr($school->schoolName, 0, 4);
$adm_no = $sch . '000' . $next_no;
$student->admissionNo = $adm_no;
DB::beginTransaction();
if(!isset($request->bloodGroup)){
$student->bloodGroup = "";
}
$student->save();
if ($request->hasFile('photo')) {
$photo = 'photo_' . $student->idStudent . '.' . $request->file('photo')->getClientOriginalExtension();
$request->file('photo')->storeAs('public/schools/' . Auth::guard('school')->user()->idSchool . '/students/', $photo);
$student->photo = $photo;
}
$student->update();
// Update parent login credentials
$parent1 = \App\Parents::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('mobile', '=', $request->father_mobile)->first();
if (!$parent1) {
$parent1 = new \App\Parents();
$parent1->idSchool = Auth::guard('school')->user()->idSchool;
$parent1->mobile = $request->father_mobile;
$parent1->pwd = $password;
$parent1->password = bcrypt($password);
$parent1->save();
}
$parent2 = \App\Parents::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('mobile', '=', $request->mother_mobile)->first();
if (!$parent2) {
$parent2 = new \App\Parents();
$parent2->idSchool = Auth::guard('school')->user()->idSchool;
$parent2->mobile = $request->mother_mobile;
$parent2->pwd = $password;
$parent2->password = bcrypt($password);
$parent2->save();
}
if (count($request->siblings) > 0) {
foreach ($request->siblings as $key => $value) {
if ($value['fName'] != null) {
$sibling = new \App\StudentSibling();
$sibling->fill($request->all());
$sibling->idStudent = $student->idStudent;
$sibling->fName = $value['fName'];
$sibling->lName = $value['lName'];
$sibling->age = $value['age'];
$sibling->education = $value['education'];
$sibling->schoolName = $value['schoolName'];
$sibling->save();
}
}
}
DB::commit();
flash('Student has been saved successfully !!');
if ($request->ajax()) {
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
return redirect('school/students');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {
$school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
$student = \App\AdmEntry::where('idStudent', '=', $id)->first();
return view('schools.admentries.viewstudent', compact('student','school'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {
$student = \App\AdmEntry::where('idStudent', '=', $id)->first();
$fys = \App\FinancialYear::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('idFinancialYear', '=', Session::get('idFinancialYear'))->orderBy('financialYearName', 'desc')
->pluck('financialYearName', 'idFinancialYear')->toArray();
$school = \App\School::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->first();
if($school->idCountry == 1)
$states = ['' => '-- Select State --'] + \App\State::orderBy('stateName')->get()->pluck('stateName', 'idState')->toArray();
else $states = ['' => '-- Select State --'] + DB::table('states_qatar')->orderBy('stateName')->get()->pluck('stateName', 'idState')->toArray();
$classes = ['' => '--Select--'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$section = \App\Section::where('idSection', '=', $student->idSection)->get()->pluck('sectionName', 'idSection')->toArray();
$categories = ['' => '--Select--'] + DB::table('studentCategory')->where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('categoryName', 'categoryName')->toArray();
$paidfees = \App\StudentTransaction::join('student_transaction_details', 'student_transaction.idTransaction', '=', 'student_transaction_details.idTransaction')->where('student_transaction.idStudent', '=', $student->idStudent)
->where('student_transaction.idFinancialYear', '=', Session::get('idFinancialYear'))->get();
$lesserfees = \App\LesserTransaction::join('lesser_transaction_details', 'lesser_transaction_details.idLesserTransaction', '=', 'lesser_transaction.idLesserTransaction')->where('lesser_transaction.idStudent', '=', $student->idStudent)
->where('lesser_transaction.idFinancialYear', '=', Session::get('idFinancialYear'))->get();
return view('schools.admentries.index', compact('classes', 'states', 'fys', 'student', 'section', 'categories','lesserfees','paidfees','school'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(StudentRequest $request, $id) {
//dd($request->all());
$checkEcno = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->where('idFinancialYear', '=', Session::get('idFinancialYear'))->where('ecNo',$request->ecNo)->where('idStudent','!=',$id)->first();
if($checkEcno != null){
if ($request->ajax()) {
//return response()->json(['message' => "The given data was invalid.", 'errors' => [ 'ecNo' => ["The ec no has already been taken."] ]], 422, ['app-status' => 'success']);
}
//flash('Duplicate EC No. found cannot be saved !!');
//return redirect()->back();
}
DB::beginTransaction();
if(isset($request->feeheader)){
if(is_array($request->feeheader)){
if(count($request->feeheader) > 0){
foreach ($request->feeheader as $key => $value) {
if(isset($value["old"]) && isset($value["new"])){
if($value["type"] == "full"){
DB::table('student_transaction_details')
->where('idStudent', $id)
->where('idFeehead', $value["old"])
->update(['idFeehead' => $value["new"]]);
}else{
DB::table('lesser_transaction_details')
->where('idStudent', $id)
->where('idFeehead', $value["old"])
->update(['idFeehead' => $value["new"]]);
}
}
}
}
}
}
$student = \App\AdmEntry::where('idStudent', '=', $id)->first();
if($student->idSection != $request->idSection) {
flash('Student Updated Failed.');
return redirect('school/students');
}
$parent1 = \App\Parents::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('mobile', '=', $student->father_mobile)->delete();
$parent2 = \App\Parents::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('mobile', '=', $student->mother_mobile)->delete();
$student->fill($request->all());
if ($request->hasFile('photo')) {
$photo = 'photo_' . $student->idStudent . '.' . $request->file('photo')->getClientOriginalExtension();
$request->file('photo')->storeAs('public/schools/' . Auth::guard('school')->user()->idSchool . '/students/', $photo);
$student->photo = $photo;
}
$student->update();
$password = 123456;
$parent1 = new \App\Parents();
$parent1->idSchool = Auth::guard('school')->user()->idSchool;
$parent1->mobile = $request->father_mobile;
$parent1->pwd = $password;
$parent1->password = bcrypt($password);
$parent1->save();
$parent2 = new \App\Parents();
$parent2->idSchool = Auth::guard('school')->user()->idSchool;
$parent2->mobile = $request->mother_mobile;
$parent2->pwd = $password;
$parent2->password = bcrypt($password);
$parent2->save();
// if (count($request->siblings) > 0) {
// foreach ($request->siblings as $key => $value) {
// $sibling = new \App\StudentSibling();
// $sibling->fill($request->all());
// $sibling->idStudent = $student->idStudent;
// $sibling->fName = $value['fName'];
// $sibling->lName = $value['lName'];
// $sibling->age = $value['age'];
// $sibling->education = $value['education'];
// $sibling->schoolName = $value['schoolName'];
// $sibling->save();
// }
// }
DB::commit();
flash('Student Updated Successfully');
return redirect('school/students');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$student = \App\AdmEntry::where('idStudent', '=', $id)->first();
$student->delete();
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
public function activateStudent($id) {
$student = \App\AdmEntry::where('idStudent', '=', $id)->first();
$student->isActive = 'Y';
$student->update();
return redirect('school/studentlist');
}
public function deactivateStudent($id) {
$student = \App\AdmEntry::where('idStudent', '=', $id)->first();
$student->isActive = 'N';
$student->update();
return redirect('school/studentlist');
}
public function printStudentData($id) {
$student = \App\AdmEntry::where('idStudent', '=', $id)->first();
return view('schools.admentries.printapplication', compact('student'));
}
public function imageUploadform(Request $request) {
$students = \App\AdmEntry::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('isActive', '=', 'Y')
->whereNull('photo')
->orderBy('idStudent');
if ($request->has('idFinancialYear')) {
$students = $students->where('idFinancialYear', '=', $request->idFinancialYear)
->get();
} else {
$students = $students->where('idFinancialYear', '=', Session::get('idFinancialYear'))
->get();
}
return view('schools.students.imageupload', compact('students'));
}
public function imageUpload(Request $request) {
// dd($request->idStudent);
$rules = ['photo' => 'required|max:400|mimes:jpg,jpeg,png'];
$this->validate($request, $rules);
$student = \App\AdmEntry::where('idStudent', '=', $request->idStudent)->first();
if ($request->hasFile('photo')) {
$photo = 'photo_' . $student->idStudent . '.' . $request->file('photo')->getClientOriginalExtension();
$request->file('photo')->storeAs('public/schools/' . Auth::guard('school')->user()->idSchool . '/students/', $photo);
$student->photo = $photo;
}
$student->update();
if ($request->ajax()) {
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
}
public function updtStatus(Request $request) {
//dd($request->all());
$student = \App\AdmEntry::where('idStudent', '=', $request->idStudent)->first();
$student->fill($request->all());
$student->deactivationDate = today_date();
$student->update();
if($request->isActive == "Y"){
DB::table('school_logs')->insert([
'idSchool' => Auth::guard('school')->user()->idSchool,
'idFinancialYear' => Session::get('idFinancialYear'),
'idUser' => Auth::guard('school')->user()->idSchoolUser,
'action_details' => 'Student Active',
'idStudent' => $request->idStudent,
'action_remarks' => $request->remarks.' - '.$request->isActive
]);
}else{
DB::table('school_logs')->insert([
'idSchool' => Auth::guard('school')->user()->idSchool,
'idFinancialYear' => Session::get('idFinancialYear'),
'idUser' => Auth::guard('school')->user()->idSchoolUser,
'action_details' => 'Student Inactive',
'idStudent' => $request->idStudent,
'action_remarks' => $request->remarks.' - '.$request->isActive
]);
}
return redirect('school/studentlist');
}
}
Copyright © 2021 -