Dashboard sipadu mbip
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CompoundController.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. namespace App\Http\Controllers\Officer;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Carbon\Carbon;
  7. use App\SiteSetting;
  8. use App\Model\Staff;
  9. use App\Model\StaffDetail;
  10. use App\Model\User;
  11. use App\Model\UserDetail;
  12. use App\Model\Module\Roles;
  13. use App\Model\Module\Department;
  14. use App\Model\Module\DeedLaw;
  15. use App\Model\Module\Faulty;
  16. use App\Model\Module\Compound;
  17. use App\Model\Module\CompoundInvestigation;
  18. use App\Model\Module\ConfidentialFile;
  19. use App\Model\Module\History;
  20. use App\Model\Module\SubHistory;
  21. use App\Model\Module\Memo;
  22. use App\Model\Module\Attachment;
  23. use App\Jobs\StoreCompound;
  24. use App\Jobs\StoreCompoundManual;
  25. use App\Jobs\UpdateCompoundPrice;
  26. class CompoundController extends Controller
  27. {
  28. public function returnDepartment($id){
  29. $department = StaffDetail::where("_id", $id)->first();
  30. return $department->department_ids;
  31. }
  32. public function returnCompound($modul,$id, $status){
  33. $department = $this->returnDepartment($id);
  34. if($status == 'Belum Bayar'){
  35. if($modul == '06-07'){
  36. $compound = Compound::where('modul','06')->orWhere('modul','07')->where('status','Belum Bayar')->get();
  37. }else{
  38. $compound = Compound::where('modul',$modul)->where('status','Belum Bayar')->get();
  39. }
  40. }else{
  41. $compound = Compound::where('status','Berbayar')->get();
  42. }
  43. $temp = [];
  44. foreach($compound as $c){
  45. if(in_array($c->jbkod, (array)$department)) {
  46. $temp[] = $c;
  47. }
  48. }
  49. return $temp;
  50. }
  51. /**
  52. * Create compound list interface controller.
  53. *
  54. * @return json
  55. */
  56. public function index(){
  57. $id = Auth::guard('ofr')->id();
  58. $user = Staff::with(['StaffDetail' => function($q){
  59. $q->with('Roles','Department');
  60. }])->find($id);
  61. $roles = $user->StaffDetail->Roles->toArray();
  62. $department = $user->StaffDetail->Department;
  63. $site = SiteSetting::first();
  64. $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
  65. $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
  66. $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
  67. $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
  68. $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
  69. $comp = count($this->returnCompound('', $id, 'Berbayar'));
  70. return view('officer.compound.compound_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
  71. }
  72. public function investigation_index(){
  73. $id = Auth::guard('ofr')->id();
  74. $user = Staff::with(['StaffDetail' => function($q){
  75. $q->with('Roles');
  76. }])->find($id);
  77. $roles = $user->StaffDetail->Roles->toArray();
  78. $department = $user->StaffDetail->Department;
  79. $site = SiteSetting::first();
  80. $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
  81. $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
  82. $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
  83. $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
  84. $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
  85. $comp = count($this->returnCompound('', $id, 'Berbayar'));
  86. return view('officer.compound.investigation_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
  87. }
  88. public function notice_index(){
  89. $id = Auth::guard('ofr')->id();
  90. $user = Staff::with(['StaffDetail' => function($q){
  91. $q->with('Roles');
  92. }])->find($id);
  93. $roles = $user->StaffDetail->Roles->toArray();
  94. $department = $user->StaffDetail->Department;
  95. $site = SiteSetting::first();
  96. $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
  97. $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
  98. $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
  99. $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
  100. $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
  101. $comp = count($this->returnCompound('', $id, 'Berbayar'));
  102. return view('officer.compound.notice_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
  103. }
  104. public function confiscated_index(){
  105. $id = Auth::guard('ofr')->id();
  106. $user = Staff::with(['StaffDetail' => function($q){
  107. $q->with('Roles');
  108. }])->find($id);
  109. $roles = $user->StaffDetail->Roles->toArray();
  110. $department = $user->StaffDetail->Department;
  111. $site = SiteSetting::first();
  112. $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
  113. $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
  114. $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
  115. $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
  116. $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
  117. $comp = count($this->returnCompound('', $id, 'Berbayar'));
  118. return view('officer.compound.confiscated_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
  119. }
  120. public function collapsed_index(){
  121. $id = Auth::guard('ofr')->id();
  122. $user = Staff::with(['StaffDetail' => function($q){
  123. $q->with('Roles');
  124. }])->find($id);
  125. $roles = $user->StaffDetail->Roles->toArray();
  126. $department = $user->StaffDetail->Department;
  127. $site = SiteSetting::first();
  128. $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
  129. $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
  130. $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
  131. $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
  132. $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
  133. $comp = count($this->returnCompound('', $id, 'Berbayar'));
  134. return view('officer.compound.collapsed_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
  135. }
  136. public function completed_index(){
  137. $id = Auth::guard('ofr')->id();
  138. $user = Staff::with(['StaffDetail' => function($q){
  139. $q->with('Roles');
  140. }])->find($id);
  141. $roles = $user->StaffDetail->Roles->toArray();
  142. $department = $user->StaffDetail->Department;
  143. $site = SiteSetting::first();
  144. $baru = count($this->returnCompound('03', $id,'Belum Bayar'));
  145. $invest = count($this->returnCompound('04', $id, 'Belum Bayar'));
  146. $notice = count($this->returnCompound('05', $id, 'Belum Bayar'));
  147. $inven = count($this->returnCompound('06-07', $id, 'Belum Bayar'));
  148. $collap = count($this->returnCompound('08', $id, 'Belum Bayar'));
  149. $comp = count($this->returnCompound('', $id, 'Berbayar'));
  150. return view('officer.compound.completed_index', compact('user','baru','invest','notice','inven','collap','comp','department','site','roles'));
  151. }
  152. public function viewCompoundHistoryDetail($kpd){
  153. $id = Auth::guard('ofr')->id();
  154. $user = Staff::with(['StaffDetail' => function($q){
  155. $q->with('Roles');
  156. }])->find($id);
  157. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  158. $file = ConfidentialFile::with('History','History.SubHistory')->where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  159. $role = Roles::where('kod',$compound->modul)->first();
  160. $site = SiteSetting::first();
  161. return view('officer.compound_detail.history_detail', compact('user','compound','file','role','site'));
  162. }
  163. public function viewCompoundDetail($kpd){
  164. $id = Auth::guard('ofr')->id();
  165. $user = Staff::with(['StaffDetail' => function($q){
  166. $q->with('Roles','Department');
  167. }])->find($id);
  168. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  169. $faulty = Faulty::with(['DeedLaw' => function($q){
  170. $q->with('Department');
  171. }])->where('_id',$compound->seksyen_kesalahan)->first();
  172. $role = Roles::where('kod',$compound->modul)->first();
  173. $total = ''; $enforcer = '';
  174. if($compound->jumlah_kemaskini_kompaun == ''){
  175. $total = $compound->jumlah_asal_kompaun;
  176. }else{
  177. $total = $compound->jumlah_kemaskini_kompaun;
  178. }
  179. $site = SiteSetting::first();
  180. $enforcer = Staff::with('StaffDetail')->where('_id',$compound->dikeluarkan)->first();
  181. return view('officer.compound_detail.compound_detail', compact('user','compound','akta','faulty','role','total','enforcer','site'));
  182. }
  183. public function viewCompoundMemoDetail($kpd){
  184. $id = Auth::guard('ofr')->id();
  185. $user = Staff::with(['StaffDetail' => function($q){
  186. $q->with('Roles');
  187. }])->find($id);
  188. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  189. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  190. $roles = Roles::all();
  191. $role = Roles::where('kod',$compound->modul)->first();
  192. $site = SiteSetting::first();
  193. return view('officer.compound_detail.memo_detail', compact('user','compound','file','roles','role','site'));
  194. }
  195. public function viewCompoundEditMemoDetail($kpd, $memo){
  196. $id = Auth::guard('ofr')->id();
  197. $user = Staff::with(['StaffDetail' => function($q){
  198. $q->with('Roles');
  199. }])->find($id);
  200. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  201. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  202. $memo = Memo::where('_id',$memo)->first();
  203. $roles = Roles::all();
  204. $site = SiteSetting::first();
  205. return view('officer.compound_detail.compound_memo_edit', compact('user','compound','file','roles','memo','site'));
  206. }
  207. public function viewCompoundInvestigationDetail($kpd){
  208. $id = Auth::guard('ofr')->id();
  209. $user = Staff::with(['StaffDetail' => function($q){
  210. $q->with('Roles');
  211. }])->find($id);
  212. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  213. $investigation = Compound::with('CompoundInvestigation')->where('kpd',$kpd)->first();
  214. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  215. $faulty = Faulty::where('_id',$compound->seksyen_kesalahan)->first();
  216. $akta = DeedLaw::where('akkod',$faulty->akkod)->first();
  217. $role = Roles::where('kod',$compound->modul)->first();
  218. $total = ''; $enforcer = '';
  219. if($compound->jumlah_kemaskini_kompaun == ''){
  220. $total = $compound->jumlah_asal_kompaun;
  221. }else{
  222. $total = $compound->jumlah_kemaskini_kompaun;
  223. }
  224. $site = SiteSetting::first();
  225. $enforcer = Staff::with('StaffDetail')->where('_id',$compound->dikeluarkan)->first();
  226. return view('officer.compound_detail.investigation_detail', compact('user','compound','investigation','file','akta','faulty','role','total','enforcer','site'));
  227. }
  228. public function viewCompoundNoticeDetail($kpd){
  229. $id = Auth::guard('ofr')->id();
  230. $user = Staff::with(['StaffDetail' => function($q){
  231. $q->with('Roles');
  232. }])->find($id);
  233. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  234. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  235. $role = Roles::where('kod',$compound->modul)->first();
  236. $site = SiteSetting::first();
  237. return view('officer.compound_detail.notice_detail', compact('user','compound','file','role','site'));
  238. }
  239. public function viewCompoundInventoryDetail($kpd){
  240. $id = Auth::guard('ofr')->id();
  241. $user = Staff::with(['StaffDetail' => function($q){
  242. $q->with('Roles');
  243. }])->find($id);
  244. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  245. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  246. $role = Roles::where('kod',$compound->modul)->first();
  247. $site = SiteSetting::first();
  248. return view('officer.compound_detail.inventory_detail', compact('user','compound','file','role','site'));
  249. }
  250. public function viewCompoundAuctionDetail($kpd){
  251. $id = Auth::guard('ofr')->id();
  252. $user = Staff::with(['StaffDetail' => function($q){
  253. $q->with('Roles');
  254. }])->find($id);
  255. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  256. $file = ConfidentialFile::where('no_siri',$compound->ConfidentialFile->no_siri)->first();
  257. $role = Roles::where('kod',$compound->modul)->first();
  258. $site = SiteSetting::first();
  259. return view('officer.compound_detail.auction_detail', compact('user','compound','file','role','site'));
  260. }
  261. public function viewTaskIndex($kpd){
  262. $id = Auth::guard('ofr')->id();
  263. $user = Staff::with(['StaffDetail' => function($q){
  264. $q->with('Roles');
  265. }])->find($id);
  266. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  267. $roles = Roles::all();
  268. $staffs = StaffDetail::where('roles_access','PenguatKuasa')->where('jbkod',$user->StaffDetail->jbkod)->get();
  269. $role = Roles::where('kod',$compound->modul)->first();
  270. $site = SiteSetting::first();
  271. $currentS = '';
  272. $s = StaffDetail::where('roles_access','PenguatKuasa')->where('no_badan',$compound->penguatkuasa)->first();
  273. if(!empty($s)){
  274. $currentS = '['.$s->no_badan.'] '.$s->full_name;
  275. }
  276. return view('officer.compound_detail.compound_job',compact('user','compound','roles','staffs','role','currentS','site'));
  277. }
  278. public function manualCompound(){
  279. $id = Auth::guard('ofr')->id();
  280. $user = Staff::with(['StaffDetail' => function($q){
  281. $q->with('Department');
  282. }])->find($id);
  283. $finalFaulty = [];
  284. $site = SiteSetting::first();
  285. $faulty = Faulty::with('Department');
  286. $department = $user->StaffDetail->department_ids;
  287. $faulty->whereHas('Department', function($q) use ($department) {
  288. $q->whereIn('_id', $department);
  289. });
  290. $akta = DeedLaw::orderBy('nama','ASC')->get();
  291. $staff = StaffDetail::whereHas('Department', function($q) use ($department) {
  292. $q->whereIn('_id', $department);
  293. })->where('roles_access', 'PenguatKuasa');
  294. $faulty = $faulty->get();
  295. $staff = $staff->get();
  296. return view('officer.compound.compound_form',compact('user','site','department','akta','faulty','staff'));
  297. }
  298. /**
  299. * Create generate kpd number controller.
  300. *
  301. * @return value
  302. */
  303. public function generateKPD($uniq_id,$range){
  304. $allowedNumbers = range(0, 9);
  305. shuffle($allowedNumbers);
  306. $digits = array_rand($allowedNumbers, $range);
  307. $number = '';
  308. foreach($digits as $d){
  309. $number .= $allowedNumbers[$d];
  310. }
  311. return $uniq_id.$number;
  312. }
  313. public function storemanualCompound(Request $request){
  314. $id = Auth::guard('ofr')->id();
  315. $user = Staff::with('StaffDetail')->find($id);
  316. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  317. if(!empty($faulty)){
  318. $kpd = 'KP' . $this->generateKPD($request->get('uniq_id'), 5);
  319. $no_siri = $this->generateKPD('', 5);
  320. $this->dispatch(new StoreCompoundManual($request->all(), $kpd, $request->staff, $no_siri));
  321. $data = array();
  322. $dataExist = false;
  323. do {
  324. $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  325. if(!empty($compound)){
  326. $tawaran = '';
  327. if($compound->jumlah_kemaskini_kompaun != ''){
  328. $tawaran = $compound->jumlah_kemaskini_kompaun;
  329. }else{
  330. $tawaran = $compound->jumlah_asal_kompaun;
  331. }
  332. array_push($data, array('kpd' => $kpd, 'jumlah_kompoun' => $tawaran));
  333. $dataExist = true;
  334. }
  335. }while(!$dataExist);
  336. return redirect()->back()->with('success_msg', 'Berjaya simpan rekod kompaun!');
  337. }else{
  338. return redirect()->back()->withInput()->with('error_msg', '<strong>Tidak Berjaya!</strong> Rekod seksyen kesalahan tidak ditemui!');
  339. }
  340. }
  341. }