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

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