Dashboard sipadu mbip
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TaskController.php 18KB

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