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.

TaskController.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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 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\Model\Module\CodeMukim;
  29. use App\Jobs\StoreCompoundEPBT;
  30. use App\Jobs\UpdateCompoundPrice;
  31. class TaskController extends Controller
  32. {
  33. /**
  34. * Create Task list controller.
  35. *
  36. * @return json
  37. */
  38. public function requestUpdateTask(Request $request){
  39. $id = Auth::guard('sadmin')->id();
  40. $user = Staff::with('StaffDetail')->find($id);
  41. $file = ConfidentialFile::where('no_siri',$request->confidential)->first();
  42. $now = Carbon::now();
  43. $gDate = $now->format('F Y');
  44. if($request->dashboard == "true"){
  45. $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
  46. $faulty = Faulty::with('DeedLaw', 'Department') ->where('_id', $compound->seksyen_kesalahan)
  47. ->orWhere('_id', $compound->seksyen_kesalahan_n)->first();
  48. $jbkod = $compound->jbkod;
  49. $roles = Roles::where('kod', $request->kategori_modul)->first();
  50. if($compound->modul == $request->kategori_modul){
  51. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah berada di dalam kategori modul '.$roles->name);
  52. }else{
  53. $reg_id = array();
  54. if(!empty($roles->staff_detail_ids)){
  55. foreach($roles->staff_detail_ids as $s){
  56. $staff = Staff::with(['StaffDetail' => function($q) use($jbkod){
  57. $q->where('jbkod', $jbkod);
  58. }])->where('_id', $s)->first();
  59. if(!empty($staff->StaffDetail)){
  60. if($staff->token_firebase != ''){
  61. $reg_id[] = $staff->token_firebase;
  62. }
  63. }
  64. }
  65. }
  66. if(count($reg_id) > 0) {
  67. $client = new \GuzzleHttp\Client();
  68. $result = $client->request('POST', url('api/push/notification'), [
  69. 'verify' => false,
  70. 'form_params' => [
  71. 'title' => $roles->name.' '.$compound->kpd,
  72. 'msg' => 'Kompaun ini telah di pindahkan ke modul '.$roles->name,
  73. 'register_id' => $reg_id,
  74. ]
  75. ]);
  76. }
  77. if(!($request->kategori_modul == '03' && $compound->modul == '02'))
  78. {
  79. $compound->modul = $request->kategori_modul;
  80. $compound->save();
  81. }
  82. $historyData = [
  83. 'tarikh_kumpulan' => $gDate,
  84. ];
  85. $subHistory = [
  86. 'no_siri' => $compound->ConfidentialFile->no_siri,
  87. 'tajuk' => "Serahan Modul",
  88. 'huraian' => $compound->kpd. " / Fail Kulit (".$compound->ConfidentialFile->no_siri.") telah diserahkan ke modul ".$roles->name,
  89. ];
  90. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  91. if(!empty($groupByDate)){
  92. $groupByDate->subhistory()->create($subHistory);
  93. $compound->ConfidentialFile->history()->attach($groupByDate);
  94. }else{
  95. $history = History::create($historyData);
  96. $history->subhistory()->create($subHistory);
  97. $compound->ConfidentialFile->history()->attach($history);
  98. }
  99. return redirect()->back()->with('success_msg', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya diserahkan ke kategori modul '.$roles->name);
  100. }
  101. }else if($request->dashboard == "false"){
  102. $compound = Compound::with('ConfidentialFile')->where('confidential_file_id',$request->confidential)->first();
  103. $data = array();
  104. $kpd = '';
  105. if($compound->penguatkuasa == $request->penguatkuasa){
  106. $staff = StaffDetail::where('_id',$request->penguatkuasa)->first();
  107. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah diserahkan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->full_name);
  108. }else{
  109. $staff = Staff::with('StaffDetail')->where('_id',$request->penguatkuasa)->where(function($q){
  110. $q->where('roles_access','PenguatKuasa')->orWhere('roles_access','PPenguatKuasa');
  111. })->first();
  112. $role = Roles::where('kod', $compound->modul)->first();
  113. if($compound->modul == '02')
  114. {
  115. $compound = Compound::with('ConfidentialFile')->where('non',$request->non)->first();
  116. $faulty = Faulty::where('_id', $compound->seksyen_kesalahan_n)->first();
  117. $department = Department::where('_id', $compound->jbkod)->first();
  118. $deedlaw = DeedLaw::where('_id', $compound->akta_n)->first();
  119. $jbkod = $compound->jbkod;
  120. $kpd = $compound->non;
  121. // dd($faulty);
  122. array_push($data, array(
  123. 'non' => $compound->non,
  124. 'jenis' => $compound->jenis_n,
  125. 'nama' => $compound->nama,
  126. 'identity' => $compound->identity,
  127. 'alamat' => $compound->alamat,
  128. 'nama_kawasan' =>$compound->nama_kawasan,
  129. 'nama_taman' => $compound->nama_taman,
  130. 'nama_jalan' =>$compound->nama_jalan,
  131. 'catatan' => $compound->butiran_kesalahan_n,
  132. 'lokasi_kejadian' => $compound->lokasi_kejadian,
  133. 'no_daftar_syarikat' =>$compound->no_daftar_syarikat,
  134. 'nama_syarikat' => $compound->nama_syarikat,
  135. 'lesen' => $compound->no_akaun_lesen,
  136. // 'latlong' => $compound->latlong,
  137. // 'jabatan' => $department->jnama,
  138. 'akta' => $deedlaw->nama,
  139. 'seksyen' => $faulty->nama,
  140. // 'tempoh' => $compound->tempoh,
  141. // 'tindakan' => $compound->tindakan ?? "",
  142. 'created_n' => $compound->created_n,
  143. ));
  144. }
  145. else{
  146. $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
  147. $faulty = Faulty::with('DeedLaw', 'Department') ->where('_id', $compound->seksyen_kesalahan)->first();
  148. $jbkod = $compound->jbkod;
  149. $kpd = $compound->kpd;
  150. }
  151. // if($compound->modul == '02')
  152. // {
  153. // $this->dispatch(new StoreCompoundEPBT($request->all(), $compound->kpd, $user->StaffDetail->full_name, $user->StaffDetail->no_badan, $compound->seksyen_kesalahan));
  154. // dd($faulty);
  155. // array_push($data, array(
  156. // 'non' => $compound->non,
  157. // 'jenis' => $compound->jenis_n,
  158. // 'nama' => $compound->nama,
  159. // 'identity' => $compound->identity,
  160. // 'alamat' => $compound->alamat,
  161. // 'nama_kawasan' =>$compound->nama_kawasan,
  162. // 'nama_taman' => $compound->nama_taman,
  163. // 'nama_jalan' =>$compound->nama_jalan,
  164. // 'catatan' => $compound->catatan,
  165. // 'latlong' => $compound->latlong,
  166. // 'jabatan' => $faulty['Department']['jnama'],
  167. // 'akta' => $faulty['DeedLaw']['nama'],
  168. // 'tempoh' => $compound->tempoh,
  169. // 'tindakan' => $compound->tindakan ?? "",
  170. // 'created_n' => $compound->created_n,
  171. // ));
  172. // }
  173. info(json_encode($data));
  174. if(!empty($staff)){
  175. if($staff->token_firebase != '') {
  176. $client = new \GuzzleHttp\Client();
  177. $result = $client->request('POST', url('api/push/notification'), [
  178. 'verify' => false,
  179. 'form_params' => [
  180. 'title' => $role->name.' '.$kpd,
  181. 'msg' => 'Kompaun ini berada di ruangan '.$role->name ,
  182. 'data' => json_encode($data),
  183. 'register_id[]' => $staff->token_firebase,
  184. ]
  185. ]);
  186. }
  187. $compound->penguatkuasa = $request->penguatkuasa;
  188. $compound->save();
  189. $historyData = [
  190. 'tarikh_kumpulan' => $gDate,
  191. ];
  192. $subHistory = [
  193. 'no_siri' => $compound->ConfidentialFile->no_siri,
  194. 'tajuk' => "Menugaskan Penguatkuasa ".$staff->StaffDetail->full_name,
  195. '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>.",
  196. ];
  197. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  198. if(!empty($groupByDate)){
  199. $groupByDate->subhistory()->create($subHistory);
  200. $compound->ConfidentialFile->history()->attach($groupByDate);
  201. }else{
  202. $history = History::create($historyData);
  203. $history->subhistory()->create($subHistory);
  204. $compound->ConfidentialFile->history()->attach($history);
  205. }
  206. return redirect()->back()->with('success_msg', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya ditugaskan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->StaffDetail->full_name);
  207. }else{
  208. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Data penguatkuasa tidak ditemui');
  209. }
  210. }
  211. }
  212. }
  213. public function requestUpdateToCourt(Request $request)
  214. {
  215. $id = Auth::guard('sadmin')->id();
  216. $user = Staff::with('StaffDetail')->find($id);
  217. $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
  218. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  219. $jbkod = $compound->jbkod;
  220. $now = Carbon::now();
  221. $gDate = $now->format('F Y');
  222. if($request->dashboard == "true"){
  223. if(!isset($compound->tarikh_mahkamah) )
  224. {
  225. $compound->tarikh_mahkamah = $request->start_date;
  226. $compound->save();
  227. $historyData = [
  228. 'tarikh_kumpulan' => $gDate,
  229. ];
  230. $subHistory = [
  231. 'no_siri' => $compound->ConfidentialFile->no_siri,
  232. 'tajuk' => "Serahan Tarikh Mahkamah",
  233. 'huraian' => $compound->kpd. " diserahkan ke mahkamah pada ".$request->start_date,
  234. ];
  235. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  236. if(!empty($groupByDate)){
  237. $groupByDate->subhistory()->create($subHistory);
  238. $compound->ConfidentialFile->history()->attach($groupByDate);
  239. }else{
  240. $history = History::create($historyData);
  241. $history->subhistory()->create($subHistory);
  242. $compound->ConfidentialFile->history()->attach($history);
  243. }
  244. return redirect()->back()->with('success_msg', 'Berjaya kemaskini tarikh serahan ke mahkamah untuk kompaun ' . $compound->kpd);
  245. }
  246. else{
  247. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Pindahan tarikh ke mahkamah telah dilakukan untuk kompaun ini!');
  248. }
  249. }
  250. }
  251. public function requestViewAllPdf($kpd) {
  252. $ready_view_pdf = false;
  253. $availablePDF = array();
  254. $now = Carbon::now()->format('d/m/Y h:i:s A');
  255. $site = SiteSetting::first();
  256. $compound = Compound::with('ConfidentialFile','Attachment','CompoundInvestigation')->where('kpd', $kpd)->orWhere('non', $kpd)->first();
  257. if(empty($compound))
  258. {
  259. $kpd = (int)$kpd;
  260. $compound = Compound::with('ConfidentialFile','Attachment','CompoundInvestigation')->where('kpd', $kpd)->orWhere('non', $kpd)->first();
  261. }
  262. $file = ConfidentialFile::with(['Memo' => function($q){
  263. $q->orderBy('updated_at','ASC');
  264. }],['Investigation' => function($q){
  265. $q->with(['Attachment' => function($w){
  266. $w->first();
  267. }])->orderBy('updated_at','ASC');
  268. }],['ItemInventory' => function($w){
  269. $w->with('Barcode');
  270. }])->where('_id',$compound->ConfidentialFile->_id)->first();
  271. /**
  272. ** Compound
  273. **/
  274. $tawaran = '';
  275. if($compound->jumlah_kemaskini_kompaun == ''){
  276. $tawaran = $compound->jumlah_asal_kompaun;
  277. }else{
  278. $tawaran = $compound->jumlah_kemaskini_kompaun;
  279. }
  280. $staff = Staff::with('StaffDetail')->where('_id', $compound->dikeluarkan)->first();
  281. $staffN = Staff::with('StaffDetail')->where('_id', $compound->dikeluarkan_n)->first();
  282. $faulty = Faulty::with('DeedLaw')->where('_id',$compound->seksyen_kesalahan)->first();
  283. $faultyN = Faulty::with('DeedLaw')->where('_id', $compound->seksyen_kesalahan_n)->first();
  284. $department = Department::where('_id', $compound->jbkod)->first();
  285. $departmentN = Department::where('_id', $compound->jbkod)->first();
  286. info($faultyN);
  287. $upload [] = [ 'name' => 'compound', 'contents' => $compound ];
  288. $upload [] = [ 'name' => 'faulty', 'contents' => $faulty ];
  289. $upload [] = [ 'name' => 'faultyN', 'contents' => $faultyN ];
  290. $upload [] = [ 'name' => 'staff', 'contents' => $staff ];
  291. $upload [] = [ 'name' => 'staffN', 'contents' => $staffN ];
  292. $upload [] = [ 'name' => 'department', 'contents' => $department ];
  293. $upload [] = [ 'name' => 'departmentN', 'contents' => $departmentN ];
  294. $upload [] = [ 'name' => 'tawaran', 'contents' => $tawaran ];
  295. $upload [] = [ 'name' => 'site', 'contents' => $site ];
  296. $upload [] = [ 'name' => 'type', 'contents' => 'mbip' ];
  297. $upload [] = [ 'name' => 'file', 'contents' => $file ];
  298. $upload [] = [ 'name' => 'now', 'contents' => $now ];
  299. $client = new \GuzzleHttp\Client();
  300. $result = $client->request('POST', 'https://files.sipadu.my/api/compound/pdf', [
  301. 'multipart' => $upload
  302. ]);
  303. $response = json_decode($result->getBody()->getContents());
  304. if($response->success == true){
  305. $compound->pdf_path = $response->data;
  306. $compound->save();
  307. }
  308. /**
  309. ** Investigation
  310. **/
  311. $upload [] = [ 'name' => 'file', 'contents' => $file ]; $temp = [];
  312. if(!empty($file->Investigation)){
  313. foreach($file->Investigation as $i => $in){
  314. $attach = Investigation::with('Attachment')->where('_id',$in->_id)->first();
  315. foreach ($attach->Attachment as $key => $p) {
  316. $temp[] = $p->path;
  317. }
  318. }
  319. $upload [] = [ 'name' => 'fileInvest', 'contents' => json_encode($temp)];
  320. }
  321. /**
  322. ** All Memo in file
  323. **/
  324. if(!empty($file->Memo)){
  325. $memoData = array();
  326. foreach($file->Memo as $i => $m){
  327. $memo = Memo::with('Attachment')->where('_id',$m->_id)->first();
  328. $staffD = Staff::with('StaffDetail')->where('_id',$memo->dikeluarkan)->first();
  329. $staffS = Staff::with('StaffDetail')->where('_id',$memo->disahkan)->first();
  330. $kesalahan = Faulty::where('itkod', $memo->itkod)->first();
  331. $dikeluarkan = ''; $disahkan = ''; $faulty = ''; $modul = '';
  332. if(!empty($staffD)){
  333. $dikeluarkan = $staffD->StaffDetail->full_name;
  334. }
  335. if(!empty($staffS)){
  336. $disahkan = $staffD->StaffDetail->full_name;
  337. }
  338. if(!empty($kesalahan)){
  339. $faulty ='['.$kesalahan->skter.'] '.$kesalahan->nama;
  340. }
  341. if($memo->modul != '-'){
  342. $r = Roles::where('kod',$memo->modul)->first();
  343. if(!empty($r)){
  344. $modul = $r->name;
  345. }
  346. }
  347. $update = Carbon::parse($memo->updated)->toDateTimeString();
  348. $mula = date('d/m/Y h:i a', strtotime($memo->tarikh_mula));
  349. $akhir = date('d/m/Y', strtotime($memo->tarikh_akhir));
  350. if($memo->jenis_data == "manual"){
  351. $dataM = [
  352. 'memo' => $memo,
  353. 'dikeluarkan' => $dikeluarkan,
  354. 'disahkan' => $disahkan,
  355. 'update' => $update,
  356. 'mula' => $mula,
  357. 'akhir' => $akhir,
  358. 'faulty' => $faulty,
  359. 'modul' => $modul,
  360. 'attachment' => [],
  361. ];
  362. $memoData[] = $dataM;
  363. }else if($memo->jenis_data == "pdf"){
  364. foreach($m->Attachment as $key => $a){
  365. $pdf[] = $a->path;
  366. }
  367. $dataM = [
  368. 'memo' => $memo,
  369. 'dikeluarkan' => $dikeluarkan,
  370. 'disahkan' => $disahkan,
  371. 'update' => $update,
  372. 'mula' => $mula,
  373. 'akhir' => $akhir,
  374. 'faulty' => $faulty,
  375. 'modul' => $modul,
  376. 'attachment' => $pdf,
  377. ];
  378. $memoData[] = $dataM;
  379. }
  380. }
  381. $upload [] = [ 'name' => 'memo', 'contents' => json_encode($memoData)];
  382. }
  383. /**
  384. ** Inventory
  385. **/
  386. if(count($file->ItemInventory) > 0){
  387. $dataItem = array();
  388. foreach ($file->ItemInventory as $key => $b) {
  389. $barcode = '';
  390. foreach ($b->Barcode as $key => $br) {
  391. $barcode .= ', '.$br->barcode_id;
  392. $data = [
  393. 'item' => $b,
  394. 'barcode' => $barcode,
  395. ];
  396. }
  397. $dataItem[] = $data;
  398. }
  399. $upload [] = [ 'name' => 'inventori', 'contents' => json_encode($dataItem)];
  400. }
  401. $client = new \GuzzleHttp\Client();
  402. $result = $client->request('POST', 'https://files.sipadu.my/api/store/compound/pdf', [
  403. 'multipart' => $upload
  404. ]);
  405. $response = json_decode($result->getBody()->getContents());
  406. if($response->success == true){
  407. return redirect($response->data);
  408. }else if($response->success == false){
  409. return response()->json($response->message);
  410. }
  411. }
  412. public function insertdata()
  413. {
  414. $roads = CodeMukim::all()->toArray();
  415. $response = json_decode(file_get_contents(public_path(). '/mukim_kawasan_jalan_mbip.json'));
  416. $temp = [];
  417. if($response->success == true){
  418. foreach ($response->data as $key => $r)
  419. {
  420. // search value in db COde Mukim, if none, add to array
  421. if(!in_array($r->_id, array_column($roads, '_id')))
  422. {
  423. $com = new CodeMukim();
  424. $com->_id = new \MongoDB\BSON\ObjectID($r->_id);
  425. $com->JLN_MKKOD = $r->JLN_MKKOD;
  426. $com->MKM_MNAMA = $r->MKM_MNAMA;
  427. $com->JLN_KWKOD = $r->JLN_KWKOD;
  428. $com->KWS_KNAMA = $r->KWS_KNAMA;
  429. $com->JLN_JNAMA = $r->JLN_JNAMA;
  430. $com->save();
  431. if(!$com)
  432. {
  433. $temp[] = $r;
  434. }
  435. }
  436. }
  437. return 'data not inserted : ' . json_encode($temp);
  438. }
  439. }
  440. }