Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TaskController.php 14KB

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