FundRequestController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\User;
  7. use Auth;
  8. use App\Models\FundRequest;
  9. use App\Models\AccountHead;
  10. use App\Models\Journal;
  11. class FundRequestController extends Controller
  12. {
  13. function index()
  14. {
  15. $data['acc_head']=AccountHead::with('children')->where('type_id',2)->where('parent_head',24)->orderBy('name','asc')->get();
  16. $data['title']='Fund Request';
  17. return view('admin.fund_req.index',$data);
  18. }
  19. /**
  20. * save fund request
  21. *
  22. * @param Request $req
  23. *
  24. * @return redirect
  25. */
  26. function store(Request $req)
  27. {
  28. $this->validate($req,[
  29. 'purpose'=>'required',
  30. 'amount'=>'required|numeric'
  31. ]);
  32. $fund=new FundRequest();
  33. $fund->purpose=$req->get('purpose');
  34. $fund->description=$req->get('description');
  35. $fund->amount=$req->get('amount');
  36. $fund->due_date=$req->get('due_date',date('Y-m-d H:i:s'));
  37. $fund->request_by=\Auth::user()->id;
  38. $fund->is_approved=0;
  39. $fund->save();
  40. $req->session()->flash('success','Fund request send successfully !');
  41. return redirect('account/fund_req');
  42. }
  43. /**
  44. * change approval status
  45. *
  46. * @param Request $req
  47. *
  48. * @return string
  49. */
  50. function change_approval_status(Request $req)
  51. {
  52. if($req->get('status')==1)
  53. {
  54. $jrnl=new Journal();
  55. $jrnl->debit_account=$req->get('purpose');
  56. $jrnl->credit_account=5;
  57. $jrnl->description=$req->get('description');
  58. $jrnl->amount=$req->get('amount');
  59. $jrnl->is_approaved=0;
  60. $jrnl->created_by=\Auth::user()->id;
  61. $jrnl->save();
  62. }
  63. $fund=FundRequest::find($req->get('id'));
  64. $fund->is_approved=$req->get('status')?1:2;
  65. $fund->save();
  66. return "ok";
  67. }
  68. }