Controller.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  4. use Illuminate\Foundation\Bus\DispatchesJobs;
  5. use Illuminate\Foundation\Validation\ValidatesRequests;
  6. use Illuminate\Routing\Controller as BaseController;
  7. use App\Model\SPP\StatusTagihan;
  8. use App\Model\Privillage\Role;
  9. use Auth;
  10. class Controller extends BaseController
  11. {
  12. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  13. protected function trimmedParameters($request)
  14. {
  15. $requestParameters = $request->all();
  16. if (!empty($requestParameters['_token'])) {
  17. unset($requestParameters['_token']);
  18. }
  19. return $requestParameters;
  20. }
  21. public function withParameters($route, $request, $is_route = false)
  22. {
  23. switch ($is_route) {
  24. case true:
  25. return redirect(route($route, $this->trimmedParameters($request)));
  26. break;
  27. case false:
  28. return redirect(url($route.'?'.http_build_query($this->trimmedParameters($request))));
  29. break;
  30. default:
  31. abort(400);
  32. break;
  33. }
  34. }
  35. private function emptyTable()
  36. {
  37. return datatables()->of((array)null)->make(true);
  38. }
  39. public function flashAlert($info = 'Title', $colors = 'green', $icons = 'clipboard-check', $alert = 'Message.')
  40. {
  41. Session::flash('info', $info);
  42. Session::flash('colors', $colors);
  43. Session::flash('icons', 'fas fa-'.$icons);
  44. Session::flash('alert', $alert);
  45. }
  46. public function paidDate($month = null, $year = null)
  47. {
  48. if (is_null($month)) {
  49. $month = date('n');
  50. }
  51. if (is_null($year)) {
  52. $year = date('Y');
  53. }
  54. $data['month'] = $month - 1;
  55. $data['year'] = $year;
  56. if ($month == 1) {
  57. $data['month'] = 12;
  58. $data['year']--;
  59. }
  60. return $data;
  61. }
  62. public function rtsPaid($array = [])
  63. {
  64. $rts_paid = new StatusTagihan;
  65. $rts_paid = $rts_paid->where('status', 'paid');
  66. $rts_paid = $rts_paid->where('status_izin', 'Perpanjangan');
  67. if (!empty($array['dataTerbayar'])) {
  68. $rts_paid = $rts_paid->whereMonth('bi_create_date', $array['dataTerbayar']);
  69. }
  70. if (!empty($array['fixYear'])) {
  71. $rts_paid = $rts_paid->whereYear('bi_create_date', $array['fixYear']);
  72. }
  73. if (!empty($array['jenis_st'])) {
  74. $rts_paid = $rts_paid->where('bi_type', $array['jenis_st']);
  75. }
  76. if (!empty($array['jenis_st_paid'])) {
  77. $rts_paid = $rts_paid->where('bi_type', $array['jenis_st_paid']);
  78. }
  79. if (!empty($array['getUptName'])) {
  80. $rts_paid = $rts_paid->where('upt', $array['getUptName']);
  81. }
  82. $rts_paid = $rts_paid->get();
  83. }
  84. public function isAdmin()
  85. {
  86. return Role::where('id',Auth::user()->role_id)->value('akses') == 'administrator';
  87. }
  88. }