PayrollStructureController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. use App\Models\PayrollStructure;
  16. use App\Models\PayrollStructureDetail;
  17. class PayrollStructureController extends Controller
  18. {
  19. public function index()
  20. {
  21. $data['title'] = "Employee Payroll Structure";
  22. $data['all'] = PayrollStructure::with(['psHead','employee','designationName.designation','grade','gradeHead.head'])->where('type','!=',4)->get();
  23. return view('admin.payroll_structure.index',$data);
  24. }
  25. public function psUpdate($id)
  26. {
  27. $data['title'] = "Payroll Structure Update";
  28. $data['single'] = PayrollStructure::with(['employee','designationName.designation','grade','psHead.head'])->find($id);
  29. $data['head'] = GradeStructure::with(['head'])->where('grade_id',$data['single']->grade_id)->get();
  30. return view('admin.payroll_structure.edit',$data);
  31. }
  32. public function update(Request $request, $id)
  33. {
  34. $user_id = \Auth::user()->id;
  35. $this->validate($request,[
  36. 'amount.*' => 'required'
  37. ],
  38. ['required' => 'Amount Field is Required.']);
  39. PayrollStructureDetail::where('structure_id',$id)->delete();
  40. $input = $request->all();
  41. $condition = $input['head'];
  42. foreach ($condition as $key => $condition) {
  43. $psd = new PayrollStructureDetail;
  44. $psd->structure_id = $id;
  45. $psd->head_id = $input['head'][$key];
  46. $psd->amount = $input['amount'][$key];
  47. $psd->added_by = $user_id ;
  48. $psd->save();
  49. }
  50. return redirect('admin/payroll_structure')->with('msg','Data Update Successful!');
  51. }
  52. public function destroy($id)
  53. {
  54. PayrollStructure::whereId($id)->delete();
  55. return redirect('admin/payroll_structure')->with('msg','Successfully Deleted!');
  56. }
  57. public function statusUpdate($id)
  58. {
  59. $user_id = \Auth::user()->id;
  60. $ph_info = PayrollStructure::find($id);
  61. if($ph_info->status == 0){
  62. $ph_info->status = 1;
  63. $status = 'published';
  64. }else{
  65. $ph_info->status = 0;
  66. $status = 'unpublished';
  67. }
  68. $ph_info->update();
  69. }
  70. }