Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RestfulapiController.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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\User;
  9. use App\Model\UserDetail;
  10. use App\Model\Module\Roles;
  11. use App\Model\Module\Compound;
  12. use App\Model\Module\Department;
  13. use App\Model\Module\DeedLaw;
  14. use App\Model\Module\Faulty;
  15. use App\Model\Module\ConfidentialFile;
  16. use App\Model\Module\History;
  17. use App\Model\Module\Memo;
  18. use App\Model\Module\Attachment;
  19. use App\Model\Module\ApiIntegration;
  20. use App\Jobs\StoreCompound;
  21. use App\Jobs\UpdateCompoundPrice;
  22. class RestfulapiController extends BaseController
  23. {
  24. /**
  25. * Create search compound by category controller.
  26. *
  27. * @return json
  28. */
  29. public function searchIdentity($request){
  30. $compound = Compound::with('Faulty','Department','DeedLaw')->where('identity',$request)->get();
  31. return $compound;
  32. }
  33. public function searchKpd($request){
  34. $compound = Compound::with('Faulty','Department','DeedLaw')->where('kpd','like',$request)->get();
  35. return $compound;
  36. }
  37. public function searchSyarikat($request){
  38. $compound = Compound::with('Faulty','Department','DeedLaw')->where('no_daftar_syarikat','like',$request)->get();
  39. return $compound;
  40. }
  41. public function searchPlate($request){
  42. $compound = Compound::with('Faulty','Department','DeedLaw')->where('no_plate','like',$request)->get();
  43. return $compound;
  44. }
  45. /**
  46. * Create search compound controller.
  47. *
  48. * @return json
  49. */
  50. public function viewCompoundPersonal(Request $request)
  51. {
  52. $compound = array();
  53. $search = $request->search;
  54. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  55. if(!empty($api_integrasi)){
  56. if($api_integrasi->status == 'active'){
  57. if($search != '' && $search != '-'){
  58. if(count($this->searchIdentity($search)) > 0){
  59. $compound = $this->searchIdentity($search);
  60. }
  61. if(count($this->searchKpd($search)) > 0){
  62. $compound = $this->searchKpd($search);
  63. }
  64. if(count($this->searchSyarikat($search)) > 0){
  65. $compound = $this->searchSyarikat($search);
  66. }
  67. if(count($this->searchPlate($search)) > 0){
  68. $compound = $this->searchPlate($search);
  69. }
  70. $data = array();
  71. if(count($compound) > 0){
  72. foreach($compound as $c){
  73. // $department = Department::where('_id',$c->jbkod)->first();
  74. // $faulty = Faulty::where('_id',$c->seksyen_kesalahan)->first();
  75. // $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  76. if($c->jenis == 'Pelbagai_KT'){
  77. array_push($data,array(
  78. "_id" => $c->_id,
  79. "jenis" => $c->jenis,
  80. "kpd"=> $c->kpd,
  81. "nama"=> $c->nama,
  82. "identity" => $c->identity,
  83. "nama_syarikat" => $c->nama_syarikat,
  84. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  85. "alamat" => $c->alamat,
  86. "no_plate" => strtoupper($c->no_plate),
  87. "no_cukai_jalan" => $c->no_cukai_jalan,
  88. "latlong" => $c->latlong,
  89. "nama_kawasan" => $c->nama_kawasan,
  90. "nama_taman" => $c->nama_taman,
  91. "nama_jalan" => $c->nama_jalan,
  92. "jbkod" => $c->Department->jnama,
  93. "akta" => $c->DeedLaw->nama,
  94. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  95. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  96. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  97. "amount_payment" => $c->amount_payment,
  98. "receipt" => $c->receipt,
  99. "dikeluarkan" => $c->dikeluarkan,
  100. "status" => $c->status,
  101. "updated_at" => $c->updated_at->toDateTimeString(),
  102. "created_at" => $c->created_at->toDateTimeString(),
  103. ));
  104. }else if($c->jenis == 'Pelbagai_JPB'){
  105. array_push($data,array(
  106. "_id" => $c->_id,
  107. "jenis" => $c->jenis,
  108. "kpd"=> $c->kpd,
  109. "nama"=> $c->nama,
  110. "identity" => $c->identity,
  111. "nama_syarikat" => $c->nama_syarikat,
  112. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  113. "alamat" => $c->alamat,
  114. "no_plate" => strtoupper($c->no_plate),
  115. "no_cukai_jalan" => $c->no_cukai_jalan,
  116. "latlong" => $c->latlong,
  117. "nama_kawasan" => $c->nama_kawasan,
  118. "nama_taman" => $c->nama_taman,
  119. "nama_jalan" => $c->nama_jalan,
  120. "jbkod" => $c->Department->jnama,
  121. "akta" => $c->DeedLaw->nama,
  122. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  123. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  124. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  125. "amount_payment" => $c->amount_payment,
  126. "receipt" => $c->receipt,
  127. "dikeluarkan" => $c->dikeluarkan,
  128. "status" => $c->status,
  129. "updated_at" => $c->updated_at->toDateTimeString(),
  130. "created_at" => $c->created_at->toDateTimeString(),
  131. ));
  132. }else if($c->jenis == 'Pelbagai_LESEN'){
  133. array_push($data,array(
  134. "_id" => $c->_id,
  135. "jenis" => $c->jenis,
  136. "kpd"=> $c->kpd,
  137. "nama"=> $c->nama,
  138. "identity" => $c->identity,
  139. "nama_syarikat" => $c->nama_syarikat,
  140. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  141. "alamat" => $c->alamat,
  142. "no_plate" => strtoupper($c->no_plate),
  143. "no_cukai_jalan" => $c->no_cukai_jalan,
  144. "latlong" => $c->latlong,
  145. "nama_kawasan" => $c->nama_kawasan,
  146. "nama_taman" => $c->nama_taman,
  147. "nama_jalan" => $c->nama_jalan,
  148. "jbkod" => $c->Department->jnama,
  149. "akta" => $c->DeedLaw->nama,
  150. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  151. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  152. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  153. "amount_payment" => $c->amount_payment,
  154. "receipt" => $c->receipt,
  155. "dikeluarkan" => $c->dikeluarkan,
  156. "status" => $c->status,
  157. "updated_at" => $c->updated_at->toDateTimeString(),
  158. "created_at" => $c->created_at->toDateTimeString(),
  159. ));
  160. }else if($c->jenis == 'Pelbagai_PA'){
  161. array_push($data,array(
  162. "_id" => $c->_id,
  163. "jenis" => $c->jenis,
  164. "kpd"=> $c->kpd,
  165. "nama"=> $c->nama,
  166. "identity" => $c->identity,
  167. "nama_syarikat" => $c->nama_syarikat,
  168. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  169. "alamat" => $c->alamat,
  170. "no_plate" => strtoupper($c->no_plate),
  171. "no_cukai_jalan" => $c->no_cukai_jalan,
  172. "latlong" => $c->latlong,
  173. "nama_kawasan" => $c->nama_kawasan,
  174. "nama_taman" => $c->nama_taman,
  175. "nama_jalan" => $c->nama_jalan,
  176. "jbkod" => $c->Department->jnama,
  177. "akta" => $c->DeedLaw->nama,
  178. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  179. "bil_haiwan" => $c->bil_haiwan,
  180. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  181. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  182. "amount_payment" => $c->amount_payment,
  183. "receipt" => $c->receipt,
  184. "dikeluarkan" => $c->dikeluarkan,
  185. "status" => $c->status,
  186. "updated_at" => $c->updated_at->toDateTimeString(),
  187. "created_at" => $c->created_at->toDateTimeString(),
  188. ));
  189. }else if($c->jenis == 'Parkir'){
  190. array_push($data,array(
  191. "_id" => $c->_id,
  192. "nama" => $c->nama,
  193. "identity" => $c->identity,
  194. "jenis" => $c->jenis,
  195. "kpd"=> $c->kpd,
  196. "no_plate" => strtoupper($c->no_plate),
  197. "no_cukai_jalan" => $c->no_cukai_jalan,
  198. "jenis_kenderaan" => $c->jenis_kenderaan,
  199. "model_kenderaan" => $c->model_kenderaan,
  200. "warna_kenderaan" => $c->warna_kenderaan,
  201. "nama_taman" => $c->nama_taman,
  202. "nama_jalan" => $c->nama_jalan,
  203. "no_parking" => $c->no_parking,
  204. "latlong" => $c->latlong,
  205. "jbkod" => $c->Department->jnama,
  206. "akta" => $c->DeedLaw->nama,
  207. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  208. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  209. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  210. "amount_payment" => $c->amount_payment,
  211. "receipt" => $c->receipt,
  212. "dikeluarkan" => $c->dikeluarkan,
  213. "status" => $c->status,
  214. "updated_at" => $c->updated_at->toDateTimeString(),
  215. "created_at" => $c->created_at->toDateTimeString(),
  216. ));
  217. }
  218. }
  219. return $this->sendResponse($data, 'Result Found');
  220. }else {
  221. return $this->sendResponse('', 'No Result');
  222. }
  223. }else{
  224. return $this->sendError('Search field is compulsory!', '');
  225. }
  226. }else{
  227. return $this->sendError('Invalid Api Key', '');
  228. }
  229. }else{
  230. return $this->sendError('Invalid Api Key', '');
  231. }
  232. }
  233. /**
  234. * Create update compound controller.
  235. *
  236. * @return json
  237. */
  238. public function updatePaymentIntegrasi(Request $request){
  239. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  240. if(!empty($api_integrasi)){
  241. if($api_integrasi->status == 'active'){
  242. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kp)->first();
  243. if(!empty($compound)){
  244. if($compound->status != 'Berbayar'){
  245. $compound->status = 'Berbayar';
  246. $compound->receipt = $request->receipt;
  247. $compound->amount_payment = $request->amount;
  248. $compound->save();
  249. $now = Carbon::now();
  250. $gDate = $now->format('F Y');
  251. $historyData = [
  252. 'tarikh_kumpulan' => $gDate,
  253. ];
  254. $subHistory = [
  255. 'no_siri' => $compound->ConfidentialFile->no_siri,
  256. 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
  257. 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
  258. ];
  259. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  260. if(!empty($groupByDate)){
  261. $groupByDate->subhistory()->create($subHistory);
  262. $compound->ConfidentialFile->history()->attach($groupByDate);
  263. }else{
  264. $history = History::create($historyData);
  265. $history->subhistory()->create($subHistory);
  266. $compound->ConfidentialFile->history()->attach($history);
  267. }
  268. $kpd = Compound::where('kpd', $request->kp)->first();
  269. $department = Department::where('_id',$kpd->jbkod)->first();
  270. $faulty = Faulty::where('_id',$kpd->seksyen_kesalahan)->first();
  271. $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  272. $data = [
  273. "_id" => $kpd->_id,
  274. "kpd"=> $kpd->kpd,
  275. "nama"=> $kpd->nama,
  276. "identity" => $kpd->identity,
  277. "nama_syarikat" => $kpd->nama_syarikat,
  278. "no_daftar_syarikat" => $kpd->no_daftar_syarikat,
  279. "alamat" => $kpd->alamat,
  280. "no_plate" => $kpd->no_plate,
  281. "latlong" => $kpd->latlong,
  282. "jbkod" => $department->jnama,
  283. "akta" => "[".$akta->akkod."] ".$akta->nama,
  284. "seksyen_kesalahan" => "[".$faulty->sketr."] ".$faulty->nama,
  285. "jumlah_asal_kompaun" => $kpd->jumlah_asal_kompaun,
  286. "jumlah_kemaskini_kompaun" => $kpd->jumlah_kemaskini_kompaun,
  287. "amount_payment" => $kpd->amount_payment,
  288. "receipt" => $kpd->receipt,
  289. "dikeluarkan" => $kpd->dikeluarkan,
  290. "status" => $kpd->status,
  291. "updated_at" => $kpd->updated_at->toDateTimeString(),
  292. "created_at" => $kpd->created_at->toDateTimeString(),
  293. ];
  294. return $this->sendResponse($data, 'Successfully update compound status');
  295. }else{
  296. return $this->sendResponse('', 'This compound already been paid');
  297. }
  298. }else{
  299. return $this->sendError('Record compound not found!', '');
  300. }
  301. }else{
  302. return $this->sendError('Invalid Api Key', '');
  303. }
  304. }else{
  305. return $this->sendError('Invalid Api Key', '');
  306. }
  307. }
  308. public function compoundToEPBT()
  309. {
  310. $compound = Compound::with('Department','DeedLaw','Faulty','StaffDetail')->where('jenis', 'Pelbagai_JPB')->get();
  311. dd($compound);
  312. if(!empty($compound))
  313. {
  314. $data = [];
  315. foreach ($compound as $key => $c)
  316. {
  317. if($c->jenis == 'Pelbagai_KT')
  318. {
  319. $data = [
  320. 'no_kom' => $c->kpd,
  321. 'jenis' => $c->jenis,
  322. 'nama' => $c->nama,
  323. 'no_ic' => $c->identity,
  324. 'no_tel' => $c->no_telefon,
  325. 'nama_syarikat' => $c->nama_syarikat,
  326. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  327. 'no_akaun_lesen' => $c->no_akaun_lesen,
  328. 'alamat' => $c->alamat,
  329. 'jabatan' => $c->Department->jnama,
  330. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  331. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  332. 'catatan' => $c->catatan,
  333. 'latlong' => $c->latlong,
  334. 'status' =>$c->status,
  335. 'amaun_bayar' => $c->amount_payment,
  336. 'receipt' => $c->receipt,
  337. ];
  338. }
  339. if($c->jenis == 'Pelbagai_JPB')
  340. {
  341. $data = [
  342. 'no_kom' => $c->kpd,
  343. 'jenis' => $c->jenis,
  344. 'nama' => $c->nama,
  345. 'no_ic' => $c->identity,
  346. 'no_tel' => $c->no_telefon,
  347. 'nama_syarikat' => $c->nama_syarikat,
  348. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  349. 'no_akaun_lesen' => $c->no_akaun_lesen,
  350. 'alamat' => $c->alamat,
  351. 'jabatan' => $c->Department->jnama,
  352. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  353. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  354. 'catatan' => $c->catatan,
  355. 'latlong' => $c->latlong,
  356. 'status' =>$c->status,
  357. 'amaun_bayar' => $c->amount_payment,
  358. 'receipt' => $c->receipt,
  359. ];
  360. }
  361. if($c->jenis == 'Pelbagai_PA')
  362. {
  363. $data = [
  364. 'no_kom' => $c->kpd,
  365. 'jenis' => $c->jenis,
  366. 'nama' => $c->nama,
  367. 'no_ic' => $c->identity,
  368. 'no_tel' => $c->no_telefon,
  369. 'nama_syarikat' => $c->nama_syarikat,
  370. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  371. 'no_akaun_lesen' => $c->no_akaun_lesen,
  372. 'alamat' => $c->alamat,
  373. 'jabatan' => $c->Department->jnama,
  374. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  375. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  376. 'bil_haiwan' => $c->bil_haiwan,
  377. 'catatan' => $c->catatan,
  378. 'latlong' => $c->latlong,
  379. 'status' =>$c->status,
  380. 'amaun_bayar' => $c->amount_payment,
  381. 'receipt' => $c->receipt,
  382. ];
  383. }
  384. if($c->jenis == 'Pelbagai_LESEN')
  385. {
  386. $data = [
  387. 'no_kom' => $c->kpd,
  388. 'jenis' => $c->jenis,
  389. 'nama' => $c->nama,
  390. 'no_ic' => $c->identity,
  391. 'no_tel' => $c->no_telefon,
  392. 'nama_syarikat' => $c->nama_syarikat,
  393. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  394. 'no_akaun_lesen' => $c->no_akaun_lesen,
  395. 'alamat' => $c->alamat,
  396. 'jabatan' => $c->Department->jnama,
  397. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  398. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  399. 'catatan' => $c->catatan,
  400. 'latlong' => $c->latlong,
  401. 'status' =>$c->status,
  402. 'amaun_bayar' => $c->amount_payment,
  403. 'receipt' => $c->receipt,
  404. ];
  405. }
  406. if($c->jenis == 'Parkir')
  407. {
  408. $data = [
  409. 'no_kom' => $c->kpd,
  410. 'jenis' => $c->jenis,
  411. 'nama' => $c->nama,
  412. 'no_ic' => $c->identity,
  413. 'no_tel' => $c->no_telefon,
  414. 'nama_syarikat' => $c->nama_syarikat,
  415. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  416. 'no_akaun_lesen' => $c->no_akaun_lesen,
  417. 'alamat' => $c->alamat,
  418. 'jabatan' => $c->Department->jnama,
  419. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  420. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  421. 'catatan' => $c->catatan,
  422. 'latlong' => $c->latlong,
  423. 'status' =>$c->status,
  424. 'amaun_bayar' => $c->amount_payment,
  425. 'receipt' => $c->receipt,
  426. ];
  427. }
  428. }
  429. return $this->sendResponse($data, 'Successfully update compound status');
  430. }
  431. }
  432. }