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 15KB

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