PayrollController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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\EmploymentDetail;
  8. use App\Models\EmployeeEducation;
  9. use App\Models\EmployeeDocument;
  10. use App\Models\EducationLevel;
  11. use App\Models\DocumentType;
  12. use App\Models\Grade;
  13. use App\Models\Designation;
  14. use App\Models\PayrollHead;
  15. use App\Models\GradeStructure;
  16. use App\Models\PayrollStructure;
  17. use App\Models\PayrollStructureDetail;
  18. use App\Models\AccountHead;
  19. use App\Models\PayrollHistory;
  20. use App\Models\PayrollHistoryDetail;
  21. use App\Models\PayrollTransection;
  22. use App\Models\Journal;
  23. class PayrollController extends Controller
  24. {
  25. public function index()
  26. {
  27. $data['title'] = "Employee Payroll";
  28. $data['all'] = PayrollStructure::with(['employee','designationName.designation','grade','psHead.head','due'])->where('type','!=',4)->get();
  29. return view('admin.payroll.index',$data);
  30. }
  31. public function create()
  32. {
  33. $data['title'] = "Employee Bill";
  34. $data['all'] = PayrollStructure::with(['employee','designationName.designation','grade','psHead.head','due'])->where('type','!=',4)->get();
  35. return view('admin.payroll.create',$data);
  36. }
  37. public function billCreate(Request $request)
  38. {
  39. $c_date = date('Y-m-d H:i:s');
  40. $user_id = \Auth::user()->id;
  41. $input = $request->all();
  42. $condition = $input['emp_id'];
  43. foreach ($condition as $key => $condition) {
  44. $ph_create = new PayrollHistory;
  45. $ph_create->employee_id = $input['emp_id'][$key];
  46. $ph_create->date = $c_date;
  47. $ph_create->gross_amount = $input['salary'][$key];
  48. $ph_create->status= 1;
  49. $ph_create->added_by = $user_id;
  50. $ph_create->save();
  51. $gethead = PayrollStructure::with(['psHead'])->where('employee_id',$input['emp_id'][$key])->first();
  52. foreach ($gethead->psHead as $key => $row) {
  53. $psd = new PayrollHistoryDetail;
  54. $psd->ph_id = $ph_create->id;
  55. $psd->head_id = $row->head_id;
  56. $psd->amount = $row->amount;
  57. $psd->save();
  58. }
  59. }
  60. return redirect('admin/payroll')->with('msg','Employee Bill Created Successfully.');
  61. }
  62. public function prUpdate($id)
  63. {
  64. $data['title'] = "Employee Payroll";
  65. $data['single'] = PayrollStructure::with(['employee','designationName.designation','grade','psHead.head','payableDue'])->find($id);
  66. $data['media'] = AccountHead::where('type_id',1)->orderBy('name','ASC')->get();
  67. return view('admin.payroll.edit',$data);
  68. }
  69. public function update(Request $request, $id)
  70. {
  71. //dd($request->all());
  72. $user_id = \Auth::user()->id;
  73. $c_date = date('Y-m-d H:i:s');
  74. $input = $request->all();
  75. $condition = $input['prh_id'];
  76. foreach ($condition as $key => $condition) {
  77. $journal = new Journal;
  78. $journal->ref_id = 1;
  79. $journal->debit_account = 1;
  80. $journal->credit_account =$request->media;
  81. $journal->description =$request->description;
  82. $journal->amount =$input['dues'][$key];
  83. $journal->is_approaved =0;
  84. $journal->client_id =0;
  85. $journal->office_id =1;
  86. $journal->save();
  87. $prh_id = $input['prh_id'][$key];
  88. $ph_create = PayrollHistory::find($prh_id);
  89. $old_due = $ph_create->paid_amount;
  90. $now_paid = $input['dues'][$key] + $old_due;
  91. $ph_create->paid_amount = $now_paid;
  92. $ph_create->save();
  93. $prt = new PayrollTransection;
  94. $prt->ph_id = $ph_create->id;
  95. $prt->journal_id = $journal->id;
  96. $prt->date = $c_date;
  97. $prt->save();
  98. }
  99. return redirect('admin/payroll')->with('msg','Employee Payment Successfully.');
  100. }
  101. public function destroy($id)
  102. {
  103. PayrollStructure::whereId($id)->delete();
  104. return redirect('admin/payroll_structure')->with('msg','Successfully Deleted!');
  105. }
  106. public function details($id)
  107. {
  108. $data['title'] = "Employee Payment History";
  109. $data['emp'] = Employee::find($id);
  110. $data['emp_details'] = EmploymentDetail::with(['designation','grade'])->where('employee_id',$id)->orderBy('id','DESC')->first();
  111. $data['all'] = PayrollHistory::where('employee_id',$id)->orderBy('id','DESC')->get();
  112. return view('admin.payroll.details',$data);
  113. }
  114. public function receipt($id , $pay_id)
  115. {
  116. $data['emp'] = Employee::find($id);
  117. $data['emp_details'] = EmploymentDetail::with(['designation','grade'])->where('employee_id',$id)->orderBy('id','DESC')->first();
  118. $data['pay'] = PayrollHistory::find($pay_id);
  119. $data['single'] = PayrollStructure::with(['employee','designationName.designation','grade','psHead.head','payableDue'])->where('employee_id',$id)->first();
  120. return view('admin.payroll.receipt',$data);
  121. }
  122. }