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

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