IMMREX7
<?php
namespace App\Http\Controllers\School;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use DB;
use \App\Http\SendNotificationApi;
use Session;
class HrmsHolidayController extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$departments = ['' => '--Select--', 'All' => 'All'] + \App\Department::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('departmentName', 'idDepartment')->toArray();
$holidays = \App\HrmsHoliday::leftJoin('designations', 'holidays_hrms.designation', '=', 'designations.idDesignation')
->leftJoin('departments', 'holidays_hrms.department', '=', 'departments.idDepartment')
->leftJoin('employees', 'holidays_hrms.idEmployee', '=', 'employees.idEmployee')
->where('holidays_hrms.idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('holidays_hrms.idFinancialYear','=', Session::get('idFinancialYear'))->get();
return view('schools.holidays.hrms_index', compact('holidays','departments'));
}
/**
* 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 = [
'holidayName' => 'required',
'fromDate' => 'required|date',
'toDate' => 'required|date',
'type' => 'required'
];
$this->validate($request, $rules);
if (isset($request->employees)) {
foreach ($request->employees as $key => $value) {
$holiday = new \App\HrmsHoliday();
$holiday->fill($request->all());
$holiday->idEmployee = $value;
$holiday->idFinancialYear = Session::get('idFinancialYear');
$holiday->idSchool = Auth::guard('school')->user()->idSchool;
$holiday->save();
}
}else{
$holiday = new \App\HrmsHoliday();
$holiday->fill($request->all());
$holiday->idFinancialYear = Session::get('idFinancialYear');
$holiday->idSchool = Auth::guard('school')->user()->idSchool;
$holiday->save();
}
/*$reg_ids=DB::table('students')
->join('parents', 'students.father_mobile', '=', 'parents.mobile')
->select('parents.idFirebase')
->where('students.idSchool', Auth::guard('school')->user()->idSchool)
->get()->pluck('idFirebase')->toArray();
//SendNotificationApi::sendNotification( $reg_ids,"Event : ".$request->holidayName." from ".$request->fromDate." to ".$request->toDate);
$reg_ids=DB::table('students')
->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
->select('parents.idFirebase')
->where('students.idSchool', Auth::guard('school')->user()->idSchool)
->get()->pluck('idFirebase')->toArray();
//SendNotificationApi::sendNotification( $reg_ids,"Event : ".$request->holidayName." from ".$request->fromDate." to ".$request->toDate);
*/
return redirect('school/hrms-holidays');
}
/**
* 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) {
$departments = ['' => '--Select--', 'All' => 'All'] + \App\Department::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get()->pluck('departmentName', 'idDepartment')->toArray();
$holiday = \App\HrmsHoliday::where('idHoliday','=',$id)->first();
if(isset($holiday->designation))
$designation = ['' => '--Select--'] + \App\Designation::where('idDepartment', '=', $holiday->department)->get()->pluck('designationName', 'idDesignation')->toArray();
else
$designation = ['' => '--Select--'] + \App\Designation::get()->pluck('designationName', 'idDesignation')->toArray();
$employees = [''=>'Select'] + \App\Employee::where('idDesignation', '=',$holiday->designation)->get()->pluck('name', 'idEmployee')->toArray();
$holidays = \App\HrmsHoliday::leftJoin('employees', 'holidays_hrms.idEmployee', '=', 'employees.idEmployee')
->leftJoin('designations', 'holidays_hrms.designation', '=', 'designations.idDesignation')
->leftJoin('departments', 'holidays_hrms.department', '=', 'departments.idDepartment')
->where('holidays_hrms.idSchool', '=', Auth::guard('school')->user()->idSchool)
->where('holidays_hrms.idFinancialYear','=', Session::get('idFinancialYear'))->get();
return view('schools.holidays.hrms_index', compact('holidays','holiday','employees','departments','designation'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
$rules = [
'holidayName' => 'required',
'fromDate' => 'required|date',
'toDate' => 'required|date',
'type' => 'required'
];
$this->validate($request, $rules);
$holiday = \App\HrmsHoliday::where('idHoliday','=',$id)->first();
$holiday->fill($request->all());
$holiday->idSchool = Auth::guard('school')->user()->idSchool;
$holiday->update();
return redirect('school/hrms-holidays');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$holiday = \App\HrmsHoliday::where('idHoliday', '=', $id)->first();
$holiday->delete();
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
}
Copyright © 2021 -