Dashboard sipadu mbip
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TaskController.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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\Jobs\UpdateCompoundPrice;
  29. class TaskController extends Controller
  30. {
  31. /**
  32. * Create Task list controller.
  33. *
  34. * @return json
  35. */
  36. public function requestUpdateTask(Request $request){
  37. $id = Auth::guard('sadmin')->id();
  38. $user = Staff::with('StaffDetail')->find($id);
  39. $compound = Compound::with('ConfidentialFile')->where('kpd',$request->kpd)->first();
  40. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  41. $jbkod = $compound->jbkod;
  42. $now = Carbon::now();
  43. $gDate = $now->format('F Y');
  44. if($request->dashboard == "true"){
  45. $roles = Roles::where('kod', $request->kategori_modul)->first();
  46. if($compound->modul == $request->kategori_modul){
  47. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah berada di dalam kategori modul '.$roles->name);
  48. }else{
  49. $reg_id = array();
  50. if(!empty($roles->staff_detail_ids)){
  51. foreach($roles->staff_detail_ids as $s){
  52. $staff = Staff::with(['StaffDetail' => function($q) use($jbkod){
  53. $q->where('jbkod', $jbkod);
  54. }])->where('_id', $s)->first();
  55. if(!empty($staff->StaffDetail)){
  56. if($staff->token_firebase != ''){
  57. $reg_id[] = $staff->token_firebase;
  58. }
  59. }
  60. }
  61. }
  62. if(count($reg_id) > 0) {
  63. $client = new \GuzzleHttp\Client();
  64. $result = $client->request('POST', url('api/push/notification'), [
  65. 'verify' => false,
  66. 'form_params' => [
  67. 'title' => $roles->name.' '.$compound->kpd,
  68. 'msg' => 'Kompaun ini telah di pindahkan ke modul '.$roles->name,
  69. 'register_id' => $reg_id,
  70. ]
  71. ]);
  72. }
  73. $compound->modul = $request->kategori_modul;
  74. $compound->save();
  75. $historyData = [
  76. 'tarikh_kumpulan' => $gDate,
  77. ];
  78. $subHistory = [
  79. 'no_siri' => $compound->ConfidentialFile->no_siri,
  80. 'tajuk' => "Serahan Modul",
  81. 'huraian' => $compound->kpd. " / Fail Kulit (".$compound->ConfidentialFile->no_siri.") telah diserahkan ke modul ".$roles->name,
  82. ];
  83. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  84. if(!empty($groupByDate)){
  85. $groupByDate->subhistory()->create($subHistory);
  86. $compound->ConfidentialFile->history()->attach($groupByDate);
  87. }else{
  88. $history = History::create($historyData);
  89. $history->subhistory()->create($subHistory);
  90. $compound->ConfidentialFile->history()->attach($history);
  91. }
  92. return redirect()->back()->with('success_msg', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya diserahkan ke kategori modul '.$roles->name);
  93. }
  94. }else if($request->dashboard == "false"){
  95. if($compound->penguatkuasa == $request->penguatkuasa){
  96. $staff = StaffDetail::where('_id',$request->penguatkuasa)->first();
  97. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Kompaun ini sudah diserahkan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->full_name);
  98. }else{
  99. $staff = Staff::with('StaffDetail')->where('_id',$request->penguatkuasa)->where(function($q){
  100. $q->where('roles_access','PenguatKuasa')->orWhere('roles_access','PPenguatKuasa');
  101. })->first();
  102. $role = Roles::where('kod', $compound->modul)->first();
  103. if(!empty($staff)){
  104. if($staff->token_firebase != '') {
  105. $client = new \GuzzleHttp\Client();
  106. $result = $client->request('POST', url('api/push/notification'), [
  107. 'verify' => false,
  108. 'form_params' => [
  109. 'title' => $role->name.' '.$compound->kpd,
  110. 'msg' => 'Kompaun ini berada di ruangan '.$role->name,
  111. 'register_id[]' => $staff->token_firebase,
  112. ]
  113. ]);
  114. }
  115. $compound->penguatkuasa = $request->penguatkuasa;
  116. $compound->save();
  117. $historyData = [
  118. 'tarikh_kumpulan' => $gDate,
  119. ];
  120. $subHistory = [
  121. 'no_siri' => $compound->ConfidentialFile->no_siri,
  122. 'tajuk' => "Menugaskan Penguatkuasa ".$staff->StaffDetail->full_name,
  123. '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>.",
  124. ];
  125. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  126. if(!empty($groupByDate)){
  127. $groupByDate->subhistory()->create($subHistory);
  128. $compound->ConfidentialFile->history()->attach($groupByDate);
  129. }else{
  130. $history = History::create($historyData);
  131. $history->subhistory()->create($subHistory);
  132. $compound->ConfidentialFile->history()->attach($history);
  133. }
  134. return redirect()->back()->with('success_msg', '<strong>Berjaya Kemaskini!</strong> Kompaun ini berjaya ditugaskan kepada penguatkuasa ['.$staff->no_badan.'] '.$staff->StaffDetail->full_name);
  135. }else{
  136. return redirect()->back()->withInput()->with('error_msg','<strong>Tidak Berjaya!</strong> Data penguatkuasa tidak ditemui');
  137. }
  138. }
  139. }
  140. }
  141. public function requestViewAllPdf($kpd) {
  142. $ready_view_pdf = false;
  143. $availablePDF = array();
  144. $now = Carbon::now()->format('d/m/Y h:i:s A');
  145. $site = SiteSetting::first();
  146. $compound = Compound::with('ConfidentialFile','Attachment','CompoundInvestigation')->where('kpd', $kpd)->first();
  147. $file = ConfidentialFile::with(['Memo' => function($q){
  148. $q->orderBy('updated_at','ASC');
  149. }],['Investigation' => function($q){
  150. $q->with(['Attachment' => function($w){
  151. $w->first();
  152. }])->orderBy('updated_at','ASC');
  153. }],['ItemInventory' => function($w){
  154. $w->with('Barcode');
  155. }])->where('_id',$compound->ConfidentialFile->_id)->first();
  156. /**
  157. ** Compound
  158. **/
  159. $tawaran = '';
  160. if($compound->jumlah_kemaskini_kompaun == ''){
  161. $tawaran = $compound->jumlah_asal_kompaun;
  162. }else{
  163. $tawaran = $compound->jumlah_kemaskini_kompaun;
  164. }
  165. $staff = Staff::with('StaffDetail')->where('_id', $compound->dikeluarkan)->first();
  166. $faulty = Faulty::with('DeedLaw')->where('_id',$compound->seksyen_kesalahan)->first();
  167. $department = Department::where('_id', $compound->jbkod)->first();
  168. $upload [] = [ 'name' => 'compound', 'contents' => $compound ];
  169. $upload [] = [ 'name' => 'faulty', 'contents' => $faulty ];
  170. $upload [] = [ 'name' => 'staff', 'contents' => $staff ];
  171. $upload [] = [ 'name' => 'department', 'contents' => $department ];
  172. $upload [] = [ 'name' => 'tawaran', 'contents' => $tawaran ];
  173. $upload [] = [ 'name' => 'site', 'contents' => $site ];
  174. $upload [] = [ 'name' => 'type', 'contents' => 'mbip' ];
  175. $upload [] = [ 'name' => 'file', 'contents' => $file ];
  176. $upload [] = [ 'name' => 'now', 'contents' => $now ];
  177. $client = new \GuzzleHttp\Client();
  178. $result = $client->request('POST', 'https://files.sipadu.my/api/compound/pdf', [
  179. 'multipart' => $upload
  180. ]);
  181. $response = json_decode($result->getBody()->getContents());
  182. if($response->success == true){
  183. $compound->pdf_path = $response->data;
  184. $compound->save();
  185. }
  186. /**
  187. ** Investigation
  188. **/
  189. $upload [] = [ 'name' => 'file', 'contents' => $file ]; $temp = [];
  190. if(!empty($file->Investigation)){
  191. foreach($file->Investigation as $i => $in){
  192. $attach = Investigation::with('Attachment')->where('_id',$in->_id)->first();
  193. foreach ($attach->Attachment as $key => $p) {
  194. $temp[] = $p->path;
  195. }
  196. }
  197. $upload [] = [ 'name' => 'fileInvest', 'contents' => json_encode($temp)];
  198. }
  199. /**
  200. ** All Memo in file
  201. **/
  202. if(!empty($file->Memo)){
  203. $memoData = array();
  204. foreach($file->Memo as $i => $m){
  205. $memo = Memo::with('Attachment')->where('_id',$m->_id)->first();
  206. $staffD = Staff::with('StaffDetail')->where('_id',$memo->dikeluarkan)->first();
  207. $staffS = Staff::with('StaffDetail')->where('_id',$memo->disahkan)->first();
  208. $kesalahan = Faulty::where('itkod', $memo->itkod)->first();
  209. $dikeluarkan = ''; $disahkan = ''; $faulty = ''; $modul = '';
  210. if(!empty($staffD)){
  211. $dikeluarkan = $staffD->StaffDetail->full_name;
  212. }
  213. if(!empty($staffS)){
  214. $disahkan = $staffD->StaffDetail->full_name;
  215. }
  216. if(!empty($kesalahan)){
  217. $faulty ='['.$kesalahan->skter.'] '.$kesalahan->nama;
  218. }
  219. if($memo->modul != '-'){
  220. $r = Roles::where('kod',$memo->modul)->first();
  221. if(!empty($r)){
  222. $modul = $r->name;
  223. }
  224. }
  225. $update = Carbon::parse($memo->updated)->toDateTimeString();
  226. $mula = date('d/m/Y h:i a', strtotime($memo->tarikh_mula));
  227. $akhir = date('d/m/Y', strtotime($memo->tarikh_akhir));
  228. if($memo->jenis_data == "manual"){
  229. $dataM = [
  230. 'memo' => $memo,
  231. 'dikeluarkan' => $dikeluarkan,
  232. 'disahkan' => $disahkan,
  233. 'update' => $update,
  234. 'mula' => $mula,
  235. 'akhir' => $akhir,
  236. 'faulty' => $faulty,
  237. 'modul' => $modul,
  238. 'attachment' => [],
  239. ];
  240. $memoData[] = $dataM;
  241. }else if($memo->jenis_data == "pdf"){
  242. foreach($m->Attachment as $key => $a){
  243. $pdf[] = $a->path;
  244. }
  245. $dataM = [
  246. 'memo' => $memo,
  247. 'dikeluarkan' => $dikeluarkan,
  248. 'disahkan' => $disahkan,
  249. 'update' => $update,
  250. 'mula' => $mula,
  251. 'akhir' => $akhir,
  252. 'faulty' => $faulty,
  253. 'modul' => $modul,
  254. 'attachment' => $pdf,
  255. ];
  256. $memoData[] = $dataM;
  257. }
  258. }
  259. $upload [] = [ 'name' => 'memo', 'contents' => json_encode($memoData)];
  260. }
  261. /**
  262. ** Inventory
  263. **/
  264. if(count($file->ItemInventory) > 0){
  265. $dataItem = array();
  266. foreach ($file->ItemInventory as $key => $b) {
  267. $barcode = '';
  268. foreach ($b->Barcode as $key => $br) {
  269. $barcode .= ', '.$br->barcode_id;
  270. $data = [
  271. 'item' => $b,
  272. 'barcode' => $barcode,
  273. ];
  274. }
  275. $dataItem[] = $data;
  276. }
  277. $upload [] = [ 'name' => 'inventori', 'contents' => json_encode($dataItem)];
  278. }
  279. $client = new \GuzzleHttp\Client();
  280. $result = $client->request('POST', 'https://files.sipadu.my/api/store/compound/pdf', [
  281. 'multipart' => $upload
  282. ]);
  283. $response = json_decode($result->getBody()->getContents());
  284. if($response->success == true){
  285. return redirect($response->data);
  286. }else if($response->success == false){
  287. return response()->json($response->message);
  288. }
  289. }
  290. }