Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

InvestigationController.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\BaseController;
  5. use Validator;
  6. use Session;
  7. use Config;
  8. use File;
  9. use Carbon\Carbon;
  10. use App\Model\Staff;
  11. use App\Model\StaffDetail;
  12. use App\Model\User;
  13. use App\Model\UserDetail;
  14. use App\Model\Module\Roles;
  15. use App\Model\Module\Department;
  16. use App\Model\Module\DeedLaw;
  17. use App\Model\Module\Faulty;
  18. use App\Model\Module\Compound;
  19. use App\Model\Module\CompoundInvestigation;
  20. use App\Model\Module\ConfidentialFile;
  21. use App\Model\Module\Investigation;
  22. use App\Model\Module\History;
  23. use App\Model\Module\SubHistory;
  24. use App\Model\Module\Memo;
  25. use App\Model\Module\Attachment;
  26. class InvestigationController extends BaseController
  27. {
  28. /**
  29. * Create a investigation list controller.
  30. *
  31. * @return json
  32. */
  33. public function investigationAttachmentList($no_siri)
  34. {
  35. $nested_data = array();
  36. $file = ConfidentialFile::with(['Investigation' => function($q){
  37. $q->orderBy('updated_at', 'desc');
  38. }])->where('no_siri',$no_siri)->first();
  39. $curr = Carbon::now()->getTimestamp();
  40. if(!empty($file->Investigation)){
  41. foreach($file->Investigation as $a)
  42. {
  43. $n1 = '';
  44. $reg_time = $a->updated_at;
  45. $expiry_date = $reg_time->addDays(3);
  46. $expiry_date = $expiry_date->getTimestamp();
  47. if($curr < $expiry_date) {
  48. $n1 = "Baru/";
  49. }else{
  50. $n1 = "";
  51. }
  52. array_push($nested_data, array(
  53. 'tarikh' => $n1.$a->updated_at->format('d/m/Y'),
  54. 'masa' => $a->updated_at->format('h:i A'),
  55. 'subjek' => $a->subjek,
  56. 'kategori' => $a->kategori,
  57. 'tindakan' => $a->_id
  58. ));
  59. }
  60. }
  61. return \DataTables::of($nested_data)->make(true);
  62. }
  63. public function deleteAttachment(Request $request)
  64. {
  65. $staff = Staff::with('StaffDetail')->where('_id',$request->staff)->first();
  66. if(!empty($staff)){
  67. $attach = Investigation::with('Attachment')->where('_id',$request->id)->first();
  68. if(!empty($attach->Attachment)){
  69. foreach($attach->Attachment as $a){
  70. $a->delete();
  71. }
  72. $attach->delete();
  73. $file = ConfidentialFile::where('no_siri',$request->no_siri)->first();
  74. $now = Carbon::now();
  75. $gDate = $now->format('F Y');
  76. $historyData = [
  77. 'tarikh_kumpulan' => $gDate,
  78. ];
  79. $subHistory = [
  80. 'no_siri' => $file->no_siri,
  81. 'tajuk' => $staff->StaffDetail->roles_access." ".$staff->StaffDetail->full_name." mengemaskini pengesahan kompaun ".$request->kpd,
  82. 'huraian' => "Rekod lampiran ".$attach->kategori." (".$attach->subjek.") dikemaskini/di buang oleh ".$staff->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$staff->_id."/profile'>".$staff->StaffDetail->full_name."</a>.",
  83. ];
  84. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  85. if(!empty($groupByDate)){
  86. $groupByDate->subhistory()->create($subHistory);
  87. $file->history()->attach($groupByDate);
  88. }else{
  89. $history = History::create($historyData);
  90. $history->subhistory()->create($subHistory);
  91. $file->history()->attach($history);
  92. }
  93. return response()->json(['status' => 'true', 'desc' => 'Buang rekod lampiran ( '.$attach->subjek.' )']);
  94. }else{
  95. return response()->json(['status' => 'false', 'desc' => 'Buang rekod lampiran ( '.$attach->subjek.' )']);
  96. }
  97. }
  98. }
  99. }