Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TaskController.php 17KB

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