GradeStructureController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Employee;
  7. use App\Models\EmployeeEducation;
  8. use App\Models\EmployeeDocument;
  9. use App\Models\EducationLevel;
  10. use App\Models\DocumentType;
  11. use App\Models\Grade;
  12. use App\Models\Designation;
  13. use App\Models\PayrollHead;
  14. use App\Models\GradeStructure;
  15. class GradeStructureController extends Controller
  16. {
  17. public function index()
  18. {
  19. $data['title'] = "Grade Structure List";
  20. $data['grade'] = Grade::with(['gradehead.head'])->orderBy('name','ASC')->get();
  21. $data['heads'] = PayrollHead::orderBy('name','ASC')->get();
  22. $data['all'] = GradeStructure::with(['grade','head'])->orderBy('grade_id','ASC')->get();
  23. return view('admin.grade_structure.index',$data);
  24. }
  25. public function edit($id)
  26. {
  27. $data['title'] = "Grade Structure Edit";
  28. $data['single'] = GradeStructure::with(['grade','head'])->where('grade_id',$id)->get();
  29. $data['heads'] = PayrollHead::orderBy('name','ASC')->get();
  30. $data['grade_id'] = Grade::find($id);
  31. return view('admin.grade_structure.edit',$data);
  32. }
  33. public function update(Request $request)
  34. {
  35. //dd($request->all());
  36. $user_id = \Auth::user()->id;
  37. $grade_id = $request->grade_id;
  38. $delete = GradeStructure::where('grade_id',$grade_id)->delete();
  39. if ($delete) {
  40. $input = $request->all();
  41. $condition = $input['head_id'];
  42. foreach ($condition as $key => $condition) {
  43. $gt = new GradeStructure;
  44. $gt->grade_id = $grade_id;
  45. $gt->head_id = $input['head_id'][$key];
  46. $gt->amount = $input['amount'][$key];
  47. $gt->status = 1;
  48. $gt->added_by = $user_id ;
  49. $gt->save();
  50. }
  51. }
  52. return redirect('admin/grade_structure')->with('msg','Data Update Successful!');
  53. }
  54. public function destroy($id)
  55. {
  56. GradeStructure::whereId($id)->delete();
  57. return redirect('admin/grade_structure')->with('msg','Successfully Deleted!');
  58. }
  59. public function statusUpdate($id)
  60. {
  61. $user_id = \Auth::user()->id;
  62. $ph_info = GradeStructure::find($id);
  63. if($ph_info->status == 0){
  64. $ph_info->status = 1;
  65. $status = 'published';
  66. }else{
  67. $ph_info->status = 0;
  68. $status = 'unpublished';
  69. }
  70. $ph_info->update();
  71. }
  72. }