Dashboard sipadu mbip
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TaskController.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. if(empty($compound))
  148. {
  149. $kpd = (int)$kpd;
  150. $compound = Compound::with('ConfidentialFile','Attachment','CompoundInvestigation')->where('kpd', $kpd)->first();
  151. }
  152. $file = ConfidentialFile::with(['Memo' => function($q){
  153. $q->orderBy('updated_at','ASC');
  154. }],['Investigation' => function($q){
  155. $q->with(['Attachment' => function($w){
  156. $w->first();
  157. }])->orderBy('updated_at','ASC');
  158. }],['ItemInventory' => function($w){
  159. $w->with('Barcode');
  160. }])->where('_id',$compound->ConfidentialFile->_id)->first();
  161. /**
  162. ** Compound
  163. **/
  164. $tawaran = '';
  165. if($compound->jumlah_kemaskini_kompaun == ''){
  166. $tawaran = $compound->jumlah_asal_kompaun;
  167. }else{
  168. $tawaran = $compound->jumlah_kemaskini_kompaun;
  169. }
  170. $staff = Staff::with('StaffDetail')->where('_id', $compound->dikeluarkan)->first();
  171. $faulty = Faulty::with('DeedLaw')->where('_id',$compound->seksyen_kesalahan)->first();
  172. $department = Department::where('_id', $compound->jbkod)->first();
  173. $upload [] = [ 'name' => 'compound', 'contents' => $compound ];
  174. $upload [] = [ 'name' => 'faulty', 'contents' => $faulty ];
  175. $upload [] = [ 'name' => 'staff', 'contents' => $staff ];
  176. $upload [] = [ 'name' => 'department', 'contents' => $department ];
  177. $upload [] = [ 'name' => 'tawaran', 'contents' => $tawaran ];
  178. $upload [] = [ 'name' => 'site', 'contents' => $site ];
  179. $upload [] = [ 'name' => 'type', 'contents' => 'mbip' ];
  180. $upload [] = [ 'name' => 'file', 'contents' => $file ];
  181. $upload [] = [ 'name' => 'now', 'contents' => $now ];
  182. $client = new \GuzzleHttp\Client();
  183. $result = $client->request('POST', 'https://files.sipadu.my/api/compound/pdf', [
  184. 'multipart' => $upload
  185. ]);
  186. $response = json_decode($result->getBody()->getContents());
  187. if($response->success == true){
  188. $compound->pdf_path = $response->data;
  189. $compound->save();
  190. }
  191. /**
  192. ** Investigation
  193. **/
  194. $upload [] = [ 'name' => 'file', 'contents' => $file ]; $temp = [];
  195. if(!empty($file->Investigation)){
  196. foreach($file->Investigation as $i => $in){
  197. $attach = Investigation::with('Attachment')->where('_id',$in->_id)->first();
  198. foreach ($attach->Attachment as $key => $p) {
  199. $temp[] = $p->path;
  200. }
  201. }
  202. $upload [] = [ 'name' => 'fileInvest', 'contents' => json_encode($temp)];
  203. }
  204. /**
  205. ** All Memo in file
  206. **/
  207. if(!empty($file->Memo)){
  208. $memoData = array();
  209. foreach($file->Memo as $i => $m){
  210. $memo = Memo::with('Attachment')->where('_id',$m->_id)->first();
  211. $staffD = Staff::with('StaffDetail')->where('_id',$memo->dikeluarkan)->first();
  212. $staffS = Staff::with('StaffDetail')->where('_id',$memo->disahkan)->first();
  213. $kesalahan = Faulty::where('itkod', $memo->itkod)->first();
  214. $dikeluarkan = ''; $disahkan = ''; $faulty = ''; $modul = '';
  215. if(!empty($staffD)){
  216. $dikeluarkan = $staffD->StaffDetail->full_name;
  217. }
  218. if(!empty($staffS)){
  219. $disahkan = $staffD->StaffDetail->full_name;
  220. }
  221. if(!empty($kesalahan)){
  222. $faulty ='['.$kesalahan->skter.'] '.$kesalahan->nama;
  223. }
  224. if($memo->modul != '-'){
  225. $r = Roles::where('kod',$memo->modul)->first();
  226. if(!empty($r)){
  227. $modul = $r->name;
  228. }
  229. }
  230. $update = Carbon::parse($memo->updated)->toDateTimeString();
  231. $mula = date('d/m/Y h:i a', strtotime($memo->tarikh_mula));
  232. $akhir = date('d/m/Y', strtotime($memo->tarikh_akhir));
  233. if($memo->jenis_data == "manual"){
  234. $dataM = [
  235. 'memo' => $memo,
  236. 'dikeluarkan' => $dikeluarkan,
  237. 'disahkan' => $disahkan,
  238. 'update' => $update,
  239. 'mula' => $mula,
  240. 'akhir' => $akhir,
  241. 'faulty' => $faulty,
  242. 'modul' => $modul,
  243. 'attachment' => [],
  244. ];
  245. $memoData[] = $dataM;
  246. }else if($memo->jenis_data == "pdf"){
  247. foreach($m->Attachment as $key => $a){
  248. $pdf[] = $a->path;
  249. }
  250. $dataM = [
  251. 'memo' => $memo,
  252. 'dikeluarkan' => $dikeluarkan,
  253. 'disahkan' => $disahkan,
  254. 'update' => $update,
  255. 'mula' => $mula,
  256. 'akhir' => $akhir,
  257. 'faulty' => $faulty,
  258. 'modul' => $modul,
  259. 'attachment' => $pdf,
  260. ];
  261. $memoData[] = $dataM;
  262. }
  263. }
  264. $upload [] = [ 'name' => 'memo', 'contents' => json_encode($memoData)];
  265. }
  266. /**
  267. ** Inventory
  268. **/
  269. if(count($file->ItemInventory) > 0){
  270. $dataItem = array();
  271. foreach ($file->ItemInventory as $key => $b) {
  272. $barcode = '';
  273. foreach ($b->Barcode as $key => $br) {
  274. $barcode .= ', '.$br->barcode_id;
  275. $data = [
  276. 'item' => $b,
  277. 'barcode' => $barcode,
  278. ];
  279. }
  280. $dataItem[] = $data;
  281. }
  282. $upload [] = [ 'name' => 'inventori', 'contents' => json_encode($dataItem)];
  283. }
  284. $client = new \GuzzleHttp\Client();
  285. $result = $client->request('POST', 'https://files.sipadu.my/api/store/compound/pdf', [
  286. 'multipart' => $upload
  287. ]);
  288. $response = json_decode($result->getBody()->getContents());
  289. if($response->success == true){
  290. return redirect($response->data);
  291. }else if($response->success == false){
  292. return response()->json($response->message);
  293. }
  294. }
  295. }