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 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace App\Http\Controllers\Main;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Validator;
  7. use File;
  8. use Carbon\Carbon;
  9. use App\Model\Staff;
  10. use App\Model\StaffDetail;
  11. use App\Model\User;
  12. use App\Model\UserDetail;
  13. use App\Model\Module\Roles;
  14. use App\Model\Module\Department;
  15. use App\Model\Module\DeedLaw;
  16. use App\Model\Module\Faulty;
  17. use App\Model\Module\Compound;
  18. use App\Model\Module\CompoundInvestigation;
  19. use App\Model\Module\ConfidentialFile;
  20. use App\Model\Module\Investigation;
  21. use App\Model\Module\History;
  22. use App\Model\Module\SubHistory;
  23. use App\Model\Module\Memo;
  24. use App\Model\Module\Attachment;
  25. class InvestigationController extends Controller
  26. {
  27. /**
  28. * Create compound list interface controller.
  29. *
  30. * @return json
  31. */
  32. public function updateCompoundInvestigation(Request $request){
  33. $id = Auth::guard('sadmin')->id();
  34. $user = Staff::with('StaffDetail')->find($id);
  35. $validator = Validator::make($request->all(), [
  36. 'jumlah_kompaun' => 'numeric',
  37. ]);
  38. if ($validator->fails()) {
  39. return redirect()->back()->withInput()->withErrors($validator);
  40. }
  41. $save = false;
  42. $compound = Compound::with('CompoundInvestigation')->where('kpd',$request->kpd)->first();
  43. $file = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
  44. $now = Carbon::now();
  45. $gDate = $now->format('F Y');
  46. if(!empty($compound->CompoundInvestigation)){
  47. $compound->CompoundInvestigation->nama = $request->full_name;
  48. $compound->CompoundInvestigation->identity = $request->ic;
  49. $compound->CompoundInvestigation->nama_syarikat = $request->nama_syarikat;
  50. $compound->CompoundInvestigation->no_daftar_syarikat = $request->no_syarikat;
  51. $compound->CompoundInvestigation->alamat = $request->alamat;
  52. $compound->CompoundInvestigation->save();
  53. if($request->has('jumlah_kompaun')){
  54. $compound->jumlah_kemaskini_kompaun = $request->jumlah_kompaun;
  55. $compound->save();
  56. }
  57. $save = true;
  58. }else{
  59. $compoundData = [
  60. 'nama' => $request->full_name,
  61. 'identity' => $request->ic,
  62. 'nama_syarikat' => $request->nama_syarikat,
  63. 'no_daftar_syarikat' => $request->no_syarikat,
  64. 'alamat' => $request->alamat,
  65. ];
  66. $compound->compoundinvestigation()->create($compoundData);
  67. if($request->has('jumlah_kompaun')){
  68. $compound->jumlah_kemaskini_kompaun = $request->jumlah_kompaun;
  69. $compound->save();
  70. }
  71. $save = true;
  72. }
  73. if($save == true){
  74. $historyData = [
  75. 'tarikh_kumpulan' => $gDate,
  76. ];
  77. $subHistory = [
  78. 'no_siri' => $file->ConfidentialFile->no_siri,
  79. 'tajuk' => $user->StaffDetail->roles_access." ".$user->StaffDetail->full_name." mengemaskini data kompaun ".$request->kpd,
  80. 'huraian' => "Data kompaun ".$request->kpd." dikemaskini oleh ".$user->StaffDetail->roles_access." <a href='".url('/main/staff')."/".$user->_id."/profile'>".$user->StaffDetail->full_name."</a> di bawah kategori modul <b>Kertas Siasatan</b>",
  81. ];
  82. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  83. if(!empty($groupByDate)){
  84. $groupByDate->subhistory()->create($subHistory);
  85. $compound->ConfidentialFile->history()->attach($groupByDate);
  86. }else{
  87. $history = History::create($historyData);
  88. $history->subhistory()->create($subHistory);
  89. $compound->ConfidentialFile->history()->attach($history);
  90. }
  91. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> Rekod kompaun berjaya dikemaskini untuk siasatan');
  92. }
  93. }
  94. public function addAttachInvestigation(Request $request){
  95. $id = Auth::guard('sadmin')->id();
  96. $user = Staff::with('StaffDetail')->find($id);
  97. $validator = Validator::make($request->all(), [
  98. 'attachment' => 'mimes:pdf|max:2048',
  99. ]);
  100. if ($validator->fails()) {
  101. return redirect()->back()->withInput()->withErrors($validator);
  102. }
  103. $now = Carbon::now();
  104. $gDate = $now->format('F Y');
  105. $file = ConfidentialFile::where('no_siri', $request->nosiri)->first();
  106. if(!empty($file)){
  107. if($request->hasFile('attachment')) {
  108. $upload = [];
  109. $a = $request->file('attachment');
  110. $upload[] = [
  111. 'name' => 'attachment',
  112. 'contents' => fopen( $a->getPathname(), 'r' ),
  113. 'filename' => $a->getClientOriginalName()
  114. ];
  115. $upload [] = [
  116. 'name' => 'no_siri',
  117. 'contents' => $request->nosiri
  118. ];
  119. $upload [] = [
  120. 'name' => 'type',
  121. 'contents' => 'mbip'
  122. ];
  123. $client = new \GuzzleHttp\Client();
  124. $result = $client->request('POST', 'https://files.sipadu.my/api/upload/investigation/file', [
  125. 'multipart' => $upload
  126. ]);
  127. $response = json_decode($result->getBody()->getContents());
  128. if($response->success == true){
  129. $investigationData = [
  130. 'subjek' => $request->subjek,
  131. 'kategori' => $request->kategori,
  132. ];
  133. $invest = $file->investigation()->create($investigationData);
  134. $attach = new Attachment();
  135. $attach->path = $response->data;
  136. $invest->attachment()->save($attach);
  137. $historyData = [
  138. 'tarikh_kumpulan' => $gDate,
  139. ];
  140. $subHistory = [
  141. 'no_siri' => $file->no_siri,
  142. 'tajuk' => $user->StaffDetail->roles_access." ".$user->StaffDetail->full_name." memuat naik lampiran SSM / JPJ",
  143. 'huraian' => "Lampiran SSM/JPJ telah dimuat naik oleh ".$user->StaffDetail->roles_access." <b><a href='".url('/main/staff')."/".$user->_id."/profile'>".$user->StaffDetail->full_name."</a></b>",
  144. ];
  145. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  146. if(!empty($groupByDate)){
  147. $groupByDate->subhistory()->create($subHistory);
  148. $file->history()->attach($groupByDate);
  149. }else{
  150. $history = History::create($historyData);
  151. $history->subhistory()->create($subHistory);
  152. $file->history()->attach($history);
  153. }
  154. return redirect()->back()->with('success_msg', '<strong>Berjaya!</strong> Rekod lampiran berjaya di simpan');
  155. }else if($response->success == false){
  156. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> '.$response->message);
  157. }
  158. }else {
  159. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> Sila pastikan anda muat naik pdf sebelum hantar data');
  160. }
  161. }else{
  162. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> Rekod kompaun '.$request->kpd.' tidak ditemui');
  163. }
  164. }
  165. public function attachmentView($_id){
  166. $attach = Investigation::with('Attachment')->where('_id',$_id)->first();
  167. if(!empty($attach->Attachment)){
  168. $path = $attach->Attachment->first()->path;
  169. return \Response::make(file_get_contents($path), 200, [
  170. 'Content-Type' => 'application/pdf',
  171. 'Content-Disposition' => 'inline; filename=""'
  172. ]);
  173. }
  174. }
  175. }