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.

CompoundResourceController.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Api\BaseController;
  5. use Carbon\Carbon;
  6. use App\Model\Staff;
  7. use App\Model\StaffDetail;
  8. use App\Model\Module\Compound;
  9. use App\Model\Module\Department;
  10. use App\Model\Module\DeedLaw;
  11. use App\Model\Module\Faulty;
  12. use App\Model\Module\ConfidentialFile;
  13. use App\Model\Module\History;
  14. use App\Model\Module\SubHistory;
  15. use App\Model\Module\Memo;
  16. use App\Model\Module\Attachment;
  17. use App\Jobs\StoreCompound;
  18. use App\Jobs\UpdateCompoundPrice;
  19. use App\Http\Resources\CompoundResource;
  20. class CompoundResourceController extends BaseController
  21. {
  22. /**
  23. * @var ServiceCategory
  24. */
  25. protected $compound;
  26. /**
  27. * ServiceController constructor.
  28. *
  29. * @param ServiceCategory $ServiceCategory
  30. */
  31. public function __construct(Compound $compound)
  32. {
  33. $this->compound = $compound;
  34. }
  35. /**
  36. * Display a listing of the resource.
  37. *
  38. * @return \Illuminate\Http\Response
  39. */
  40. private function searchCompoundAll($jenis,$modul,$status,$start_date,$end_date){
  41. $dateS = Carbon::createFromFormat('Y-m-d', $start_date);
  42. $start = $dateS->copy()->startOfDay();
  43. if($end_date != ''){
  44. $dateE = Carbon::createFromFormat('Y-m-d', $end_date);
  45. $end = $dateE->copy()->endOfDay();
  46. }else{
  47. $end = $dateS->copy()->endOfDay();
  48. }
  49. if($modul == '06-07'){
  50. $compound = Compound::where(function($q){
  51. $q->where(function($query){
  52. $query->where('modul', '06')->orWhere('modul','07');
  53. });
  54. })->where('status', $status)->where('jenis', $jenis)->whereBetween('created_at', array($start, $end));
  55. }else if($status != 'Berbayar'){
  56. if($status == 'All'){
  57. $compound = Compound::where('modul', $modul)->where('status','!=','Berbayar')->where('jenis', $jenis)
  58. ->whereBetween('created_at', array($start, $end));
  59. }else{
  60. $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis)
  61. ->whereBetween('created_at', array($start, $end));
  62. }
  63. // $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis)
  64. // ->whereBetween('created_at', array($start, $end));
  65. }else{
  66. $compound = Compound::where('status', $status)->where('jenis', $jenis)
  67. ->whereBetween('created_at', array($start, $end));
  68. }
  69. return $compound;
  70. }
  71. private function searchCompoundAllWithoutDate($jenis,$modul,$status){
  72. if($modul == '06-07'){
  73. $compound = Compound::where(function($q){
  74. $q->where(function($query){
  75. $query->where('modul', '06')->orWhere('modul','07');
  76. });
  77. })->where('status', $status)->where('jenis', $jenis);
  78. }else if($status != 'Berbayar'){
  79. if($status == 'All'){
  80. $compound = Compound::where('modul', $modul)->where('status','!=','Berbayar')->where('jenis', $jenis);
  81. }else{
  82. $compound = Compound::where('modul', $modul)->where('status', $status)->where('jenis', $jenis);
  83. }
  84. }else{
  85. $compound = Compound::where('status', $status)->where('jenis', $jenis);
  86. }
  87. return $compound;
  88. }
  89. private function filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date){
  90. if(!empty($start_date)){
  91. $compound = $this->searchCompoundAll($jenis,$modul,$status,$start_date,$end_date);
  92. }else{
  93. $compound = $this->searchCompoundAllWithoutDate($jenis,$modul,$status);
  94. }
  95. if($enforcer == 'All'){
  96. return $compound;
  97. }else {
  98. $compound = $compound->where('dikeluarkan', $enforcer);
  99. return $compound;
  100. }
  101. }
  102. private function filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date){
  103. $compound = $this->filterCompoundByEnforcer($enforcer,$jenis,$modul,$status,$start_date,$end_date);
  104. if($faulty == 'All'){
  105. return $compound;
  106. }else {
  107. $compound = $compound->where('seksyen_kesalahan', $faulty);
  108. return $compound;
  109. }
  110. }
  111. public function index(Request $request)
  112. {
  113. //
  114. $per_page = $request->per_page;
  115. $kpd = $request->kpd;
  116. $modul = $request->modul;
  117. $status = $request->status;
  118. $jenis = $request->type;
  119. $start_date = $request->start_date;
  120. $end_date = $request->end_date;
  121. $enforcer = $request->enforcer;
  122. $faulty = $request->faulty;
  123. $plate_no = strtolower($request->plate_no);
  124. $company_no = strtolower($request->company_no);
  125. $nric = $request->nric;
  126. $nested_data = array();
  127. if(!empty($plate_no)) {
  128. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  129. $compound = $compound->where('no_plate',$plate_no)->orderBy('created_at','ASC')->get();
  130. }else if(!empty($kpd)){
  131. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  132. $compound = $compound->where('kpd',$kpd)->orderBy('created_at','ASC')->get();
  133. }else if(!empty($company_no)){
  134. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  135. $compound = $compound->where('no_daftar_syarikat',$company_no)->orderBy('created_at','ASC')->get();
  136. }else if(!empty($nric)){
  137. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  138. $compound = $compound->where('identity',$nric)->orderBy('created_at','ASC')->get();
  139. }else{
  140. $compound = $this->filterCompoundByFaulty($enforcer,$faulty,$jenis,$modul,$status,$start_date,$end_date);
  141. $compound = $compound->orderBy('created_at','ASC')->get();
  142. }
  143. // return $compound;
  144. return \DataTables::of(CompoundResource::collection($compound))->addIndexColumn()
  145. ->addColumn('index', function($row) {
  146. $curr = Carbon::now();
  147. $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
  148. if($curr->diffInDays($dtC) <= 3){
  149. $html = 'New';
  150. }else{ $html = ''; }
  151. return $html;
  152. })->rawColumns(['index'])->make(true);
  153. }
  154. /**
  155. * Show the form for creating a new resource.
  156. *
  157. * @return \Illuminate\Http\Response
  158. */
  159. public function create()
  160. {
  161. //
  162. }
  163. /**
  164. * Store a newly created resource in storage.
  165. *
  166. * @param \Illuminate\Http\Request $request
  167. * @return \Illuminate\Http\Response
  168. */
  169. public function store(Request $request)
  170. {
  171. $staff = Staff::with('StaffDetail')->where('api_token',$request->api_token)->first();
  172. if(empty($staff)){
  173. return $this->sendError('Invalid', 'Staff not existed');
  174. }else {
  175. $faulty = Faulty::where('_id',$request->get('seksyen'))->first();
  176. if(!empty($faulty)){
  177. $data = array();
  178. $countKPD = $this->compound->withTrashed()->count();
  179. do {
  180. $countKPD = $countKPD + 1;
  181. } while (Compound::where("kpd", "=", 'KP'.$countKPD)->first() instanceof Compound);
  182. $kpd = 'KP' . $countKPD;
  183. $no_siri = date('yn').'-'.$countKPD;
  184. $fileData = [
  185. 'no_siri' => $no_siri,
  186. ];
  187. if($request->jenis != 'Pelbagai'){
  188. $compoundData = [
  189. 'jenis' => 'Parkir',
  190. 'kpd' => $kpd,
  191. 'nama' => '-',
  192. 'identity' => '-',
  193. 'alamat' => '-',
  194. "no_plate" => strtolower($request->no_plate),
  195. "no_cukai_jalan" => $request->noCukaijalan,
  196. "jenis_kenderaan" => $request->jenisKenderaan,
  197. "model_kenderaan" => $request->modelKenderaan,
  198. "warna_kenderaan" => $request->warnakenderaan,
  199. "nama_kawasan" => $request->namaKawasan,
  200. "nama_taman" => $request->namaTaman,
  201. "nama_jalan" => $request->namaJalan,
  202. "no_parking" => $request->noParking,
  203. "catatan" => $request->catatan,
  204. "lokasi_kejadian" => '-',
  205. 'latlong' => $request->Latlong,
  206. 'jbkod' => $request->jabatan,
  207. 'akta' => $faulty->deed_law_id,
  208. 'seksyen_kesalahan' => $faulty->_id,
  209. 'jumlah_asal_kompaun' => $faulty->amount,
  210. 'jumlah_kemaskini_kompaun' => '',
  211. 'dikeluarkan' => $staff->_id,
  212. "status" => 'Belum Bayar',
  213. "amount_payment" => '',
  214. "receipt" => '',
  215. "modul" => '03',
  216. "penguatkuasa" => '',
  217. ];
  218. }else{
  219. $compoundData = [
  220. 'jenis' => 'Pelbagai',
  221. 'kpd' => $kpd,
  222. 'nama' => $request->namaP,
  223. 'identity' => $request->noIc,
  224. 'nama_syarikat' => $request->namaS,
  225. 'no_daftar_syarikat' => strtolower($request->daftarNo),
  226. 'alamat' => $request->alamat,
  227. "no_plate" => $request->no_plate,
  228. "no_cukai_jalan" => $request->no_cukai_jalan,
  229. "catatan" => $request->catatan,
  230. "lokasi_kejadian" => $request->lokasi_kejadian,
  231. 'latlong' => $request->Latlong,
  232. 'jbkod' => $request->jabatan,
  233. 'akta' => $faulty->deed_law_id,
  234. 'seksyen_kesalahan' => $faulty->_id,
  235. 'jumlah_asal_kompaun' => $faulty->amount,
  236. 'jumlah_kemaskini_kompaun' => '',
  237. 'dikeluarkan' => $staff->_id,
  238. "status" => 'Belum Bayar',
  239. "amount_payment" => '',
  240. "receipt" => '',
  241. "modul" => '03',
  242. "penguatkuasa" => '',
  243. "no_telefon" => $request->tel,
  244. "no_akaun_lesen" => $request->lesen,
  245. "maklumat_tambahan" => $request->maklumat_tambahan,
  246. ];
  247. }
  248. $file = ConfidentialFile::create($fileData);
  249. $saved = $file->compound()->create($compoundData);
  250. if($saved){
  251. // $compound = Compound::with('ConfidentialFile')->where('kpd',$kpd)->first();
  252. // if(!empty($compound)){
  253. dispatch(new UpdateCompoundPrice($kpd));
  254. // $tawaran = '';
  255. // if($compound->jumlah_kemaskini_kompaun != ''){
  256. // $tawaran = $compound->jumlah_kemaskini_kompaun;
  257. // }else{
  258. // $tawaran = $compound->jumlah_asal_kompaun;
  259. // }
  260. $this->dispatch(new StoreCompound($request->all(), $kpd, $staff->_id, $no_siri));
  261. array_push($data, array('kpd' => $kpd));
  262. return $this->sendResponse($data, 'Berjaya simpan rekod kompaun!');
  263. // }
  264. }
  265. }
  266. }
  267. }
  268. /**
  269. * Display the specified resource.
  270. *
  271. * @param int $id
  272. * @return \Illuminate\Http\Response
  273. */
  274. public function show($id)
  275. {
  276. //
  277. }
  278. /**
  279. * Show the form for editing the specified resource.
  280. *
  281. * @param int $id
  282. * @return \Illuminate\Http\Response
  283. */
  284. public function edit($id)
  285. {
  286. //
  287. }
  288. /**
  289. * Update the specified resource in storage.
  290. *
  291. * @param \Illuminate\Http\Request $request
  292. * @param int $id
  293. * @return \Illuminate\Http\Response
  294. */
  295. public function update(Request $request, $id)
  296. {
  297. //
  298. }
  299. public function updateStatusPaymentViaDashboard(Request $request)
  300. {
  301. $compound = $this->compound::with('ConfidentialFile')->find($request->id);
  302. $staff = StaffDetail::find($request->current_id);
  303. if(!empty($compound) && !empty($staff)){
  304. if($staff->roles_access == "sysadmin" || $staff->roles_access == "Ketua Jabatan"){
  305. if($compound->status != $request->status){
  306. $compound->status = $request->status;
  307. $compound->catatan_dari_admin = $request->remark;
  308. $compound->amount_payment = $request->amount;
  309. $compound->update_by = $request->current_id;
  310. $saved = $compound->save();
  311. if($saved){
  312. $gDate = $compound->created_at->format('F Y');
  313. $historyData = [
  314. 'tarikh_kumpulan' => $gDate,
  315. ];
  316. $subHistory = [
  317. 'no_siri' => $compound->ConfidentialFile->no_siri,
  318. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  319. 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  320. ];
  321. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  322. if(!empty($groupByDate)){
  323. $groupByDate->subhistory()->create($subHistory);
  324. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  325. }else{
  326. $history = History::create($historyData);
  327. $history->subhistory()->create($subHistory);
  328. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  329. }
  330. if($request->status == "Berbayar"){
  331. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  332. }else{
  333. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  334. }
  335. }else{
  336. $response = [
  337. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  338. ];
  339. return response()->json($response, 200);
  340. }
  341. }else{
  342. if($request->remark != ''){
  343. $compound->catatan_dari_admin = $request->remark;
  344. $compound->update_by = $request->current_id;
  345. $compound->save();
  346. $saved = $compound->save();
  347. if($saved){
  348. $gDate = $compound->created_at->format('F Y');
  349. $historyData = [
  350. 'tarikh_kumpulan' => $gDate,
  351. ];
  352. $subHistory = [
  353. 'no_siri' => $compound->ConfidentialFile->no_siri,
  354. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  355. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  356. ];
  357. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  358. if(!empty($groupByDate)){
  359. $groupByDate->subhistory()->create($subHistory);
  360. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  361. }else{
  362. $history = History::create($historyData);
  363. $history->subhistory()->create($subHistory);
  364. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  365. }
  366. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  367. }else{
  368. $response = [
  369. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  370. ];
  371. return response()->json($response, 200);
  372. }
  373. }else{
  374. $response = [
  375. 'success' => false, 'message' => 'Tiada kemaskini!',
  376. ];
  377. return response()->json($response, 200);
  378. }
  379. }
  380. }else{
  381. if($compound->status != 'Berbayar' && $compound->status != $request->status){
  382. $compound->status = $request->status;
  383. $compound->catatan_dari_admin = $request->remark;
  384. $compound->amount_payment = $request->amount;
  385. $compound->update_by = $request->current_id;
  386. $saved = $compound->save();
  387. if($saved){
  388. $gDate = $compound->created_at->format('F Y');
  389. $historyData = [
  390. 'tarikh_kumpulan' => $gDate,
  391. ];
  392. $subHistory = [
  393. 'no_siri' => $compound->ConfidentialFile->no_siri,
  394. 'tajuk' => "Status pembayaran kompaun ".$compound->kpd. " telah dikemaskini",
  395. 'huraian' => "Status pembayaran kompaun (RM ".$request->amount.") telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  396. ];
  397. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  398. if(!empty($groupByDate)){
  399. $groupByDate->subhistory()->create($subHistory);
  400. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  401. }else{
  402. $history = History::create($historyData);
  403. $history->subhistory()->create($subHistory);
  404. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  405. }
  406. if($request->status == "Berbayar"){
  407. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun Dijelaskan" ');
  408. }else{
  409. return $this->sendResponse('', 'Berjaya kemaskini status. Sila rujuk kompaun ini di modul kategori "Kompaun DiBatalkan" ');
  410. }
  411. }else{
  412. $response = [
  413. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  414. ];
  415. return response()->json($response, 200);
  416. }
  417. }else{
  418. if($request->remark != ''){
  419. $compound->catatan_dari_admin = $request->remark;
  420. $compound->update_by = $request->current_id;
  421. $compound->save();
  422. $saved = $compound->save();
  423. if($saved){
  424. $gDate = $compound->created_at->format('F Y');
  425. $historyData = [
  426. 'tarikh_kumpulan' => $gDate,
  427. ];
  428. $subHistory = [
  429. 'no_siri' => $compound->ConfidentialFile->no_siri,
  430. 'tajuk' => "Catatan ".$compound->kpd. " telah ditambah/dikemaskini",
  431. 'huraian' => "Catatan kompaun ini telah dikemaskini melalui 'dashboard' oleh <a href='https://mdch.sipadu.my/main/staff/".$staff->_id."/profile'>".$staff->full_name."</a>",
  432. ];
  433. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  434. if(!empty($groupByDate)){
  435. $groupByDate->subhistory()->create($subHistory);
  436. $historySaved = $compound->ConfidentialFile->history()->attach($groupByDate);
  437. }else{
  438. $history = History::create($historyData);
  439. $history->subhistory()->create($subHistory);
  440. $historySaved = $compound->ConfidentialFile->history()->attach($history);
  441. }
  442. return $this->sendResponse('', 'Berjaya tambah catatan untuk kompaun ini');
  443. }else{
  444. $response = [
  445. 'success' => false, 'message' => 'Kompaun ini tidak berjaya dikemaskini',
  446. ];
  447. return response()->json($response, 200);
  448. }
  449. }else{
  450. $response = [
  451. 'success' => false, 'message' => 'Tiada kemaskini!',
  452. ];
  453. return response()->json($response, 200);
  454. }
  455. }
  456. }
  457. }else{
  458. $response = [
  459. 'success' => false,
  460. 'message' => 'Kompaun ini tidak dijumpai / staff tidak ditemui',
  461. ];
  462. return response()->json($response, 200);
  463. }
  464. }
  465. /**
  466. * Remove the specified resource from storage.
  467. *
  468. * @param int $id
  469. * @return \Illuminate\Http\Response
  470. */
  471. public function destroy($id)
  472. {
  473. //
  474. }
  475. }