Dashboard sipadu mbip
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TaskController.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace App\Http\Controllers\Officer;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use LynX39\LaraPdfMerger\Facades\PdfMerger;
  7. use File;
  8. use Carbon\Carbon;
  9. use PDF;
  10. use App\SiteSetting;
  11. use App\Model\Staff;
  12. use App\Model\StaffDetail;
  13. use App\Model\User;
  14. use App\Model\UserDetail;
  15. use App\Model\Module\Roles;
  16. use App\Model\Module\Department;
  17. use App\Model\Module\DeedLaw;
  18. use App\Model\Module\Faulty;
  19. use App\Model\Module\Compound;
  20. use App\Model\Module\CompoundInvestigation;
  21. use App\Model\Module\ConfidentialFile;
  22. use App\Model\Module\Investigation;
  23. use App\Model\Module\ItemInventory;
  24. use App\Model\Module\History;
  25. use App\Model\Module\SubHistory;
  26. use App\Model\Module\Memo;
  27. use App\Model\Module\Attachment;
  28. use App\Jobs\UpdateCompoundPrice;
  29. class TaskController extends Controller
  30. {
  31. /**
  32. * Create Task list controller.
  33. *
  34. * @return json
  35. */
  36. public function requestUpdateTask(Request $request){
  37. $id = Auth::guard('ofr')->id();
  38. $user = Staff::with('StaffDetail')->find($id);
  39. $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
  40. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  41. $jbkod = $compound->jbkod;
  42. $now = Carbon::now();
  43. $gDate = $now->format('F Y');
  44. if($request->dashboard == "true"){
  45. $roles = Roles::where('kod', $request->kategori_modul)->first();
  46. if($compound->modul == $request->kategori_modul){
  47. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah berada di dalam kategori modul '.$roles->name);
  48. }else{
  49. $reg_id = array();
  50. if(count($roles->staff_detail_ids) > 0){
  51. foreach($roles->staff_detail_ids as $s){
  52. $staff = Staff::with(['StaffDetail' => function($q) use($jbkod){
  53. $q->where('jbkod', $jbkod);
  54. }])->where('_id', $s)->first();
  55. if(!empty($staff->StaffDetail)){
  56. if($staff->token_firebase != ''){
  57. $reg_id[] = $staff->token_firebase;
  58. }
  59. }
  60. }
  61. }
  62. if(count($reg_id) > 0) {
  63. $client = new \GuzzleHttp\Client();
  64. $result = $client->request('POST', url('api/push/notification'), [
  65. 'verify' => false,
  66. 'form_params' => [
  67. 'title' => $roles->name.' '.$compound->kpd,
  68. 'msg' => 'Kompaun ini telah di pindahkan ke modul '.$roles->name,
  69. 'register_id' => $reg_id,
  70. ]
  71. ]);
  72. }
  73. $compound->modul = $request->kategori_modul;
  74. $compound->save();
  75. $historyData = [
  76. 'tarikh_kumpulan' => $gDate,
  77. ];
  78. $subHistory = [
  79. 'no_siri' => $compound->ConfidentialFile->no_siri,
  80. 'tajuk' => "Serahan Modul",
  81. 'huraian' => $compound->kpd. " / Fail Kulit (".$compound->ConfidentialFile->no_siri.") telah diserahkan ke modul ".$roles->name,
  82. ];
  83. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  84. if(!empty($groupByDate)){
  85. $groupByDate->subhistory()->create($subHistory);
  86. $compound->ConfidentialFile->history()->attach($groupByDate);
  87. }else{
  88. $history = History::create($historyData);
  89. $history->subhistory()->create($subHistory);
  90. $compound->ConfidentialFile->history()->attach($history);
  91. }
  92. return redirect()->back()->with('success_msg', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya diserahkan ke kategori modul '.$roles->name);
  93. }
  94. }else if($request->dashboard == "false"){
  95. if($compound->penguatkuasa == $request->penguatkuasa){
  96. $staff = StaffDetail::where('_id',$request->penguatkuasa)->first();
  97. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah diserahkan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->full_name);
  98. }else{
  99. $staff = Staff::with('StaffDetail')->where('_id',$request->penguatkuasa)->where(function($q){
  100. $q->where('roles_access','PenguatKuasa')->orWhere('roles_access','PPenguatKuasa');
  101. })->first();
  102. $role = Roles::where('kod', $compound->modul)->first();
  103. if(!empty($staff)){
  104. if($staff->token_firebase != '') {
  105. $client = new \GuzzleHttp\Client();
  106. $result = $client->request('POST', url('api/push/notification'), [
  107. 'verify' => false,
  108. 'form_params' => [
  109. 'title' => $role->name.' '.$compound->kpd,
  110. 'msg' => 'Kompaun ini berada di ruangan '.$role->name,
  111. 'register_id[]' => $staff->token_firebase,
  112. ]
  113. ]);
  114. }
  115. $compound->penguatkuasa = $request->penguatkuasa;
  116. $compound->save();
  117. $historyData = [
  118. 'tarikh_kumpulan' => $gDate,
  119. ];
  120. $subHistory = [
  121. 'no_siri' => $compound->ConfidentialFile->no_siri,
  122. 'tajuk' => "Menugaskan Penguatkuasa ".$staff->StaffDetail->full_name,
  123. 'huraian' => $compound->kpd. " / Fail Kulit (".$compound->ConfidentialFile->no_siri.") telah ditugaskan kepada penguatkuasa <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
  124. ];
  125. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  126. if(!empty($groupByDate)){
  127. $groupByDate->subhistory()->create($subHistory);
  128. $compound->ConfidentialFile->history()->attach($groupByDate);
  129. }else{
  130. $history = History::create($historyData);
  131. $history->subhistory()->create($subHistory);
  132. $compound->ConfidentialFile->history()->attach($history);
  133. }
  134. return redirect()->back()->with('success_msg', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya ditugaskan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->StaffDetail->full_name);
  135. }else{
  136. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Data penguatkuasa tidak ditemui');
  137. }
  138. }
  139. }
  140. }
  141. }