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

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