Dashboard sipadu mbip
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TaskController.php 15KB

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