Dashboard sipadu mbip
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

TaskController.php 17KB

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