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 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. "jbkod" => $c->Department->jnama,
  90. "akta" => $c->DeedLaw->nama,
  91. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  92. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  93. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  94. "amount_payment" => $c->amount_payment,
  95. "receipt" => $c->receipt,
  96. "dikeluarkan" => $c->dikeluarkan,
  97. "status" => $c->status,
  98. "updated_at" => $c->updated_at->toDateTimeString(),
  99. "created_at" => $c->created_at->toDateTimeString(),
  100. ));
  101. }else if($c->jenis == 'Pelbagai_JPB'){
  102. array_push($data,array(
  103. "_id" => $c->_id,
  104. "jenis" => $c->jenis,
  105. "kpd"=> $c->kpd,
  106. "nama"=> $c->nama,
  107. "identity" => $c->identity,
  108. "nama_syarikat" => $c->nama_syarikat,
  109. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  110. "alamat" => $c->alamat,
  111. "no_plate" => strtoupper($c->no_plate),
  112. "no_cukai_jalan" => $c->no_cukai_jalan,
  113. "latlong" => $c->latlong,
  114. "jbkod" => $c->Department->jnama,
  115. "akta" => $c->DeedLaw->nama,
  116. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  117. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  118. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  119. "amount_payment" => $c->amount_payment,
  120. "receipt" => $c->receipt,
  121. "dikeluarkan" => $c->dikeluarkan,
  122. "status" => $c->status,
  123. "updated_at" => $c->updated_at->toDateTimeString(),
  124. "created_at" => $c->created_at->toDateTimeString(),
  125. ));
  126. }else if($c->jenis == 'Pelbagai_LESEN'){
  127. array_push($data,array(
  128. "_id" => $c->_id,
  129. "jenis" => $c->jenis,
  130. "kpd"=> $c->kpd,
  131. "nama"=> $c->nama,
  132. "identity" => $c->identity,
  133. "nama_syarikat" => $c->nama_syarikat,
  134. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  135. "alamat" => $c->alamat,
  136. "no_plate" => strtoupper($c->no_plate),
  137. "no_cukai_jalan" => $c->no_cukai_jalan,
  138. "latlong" => $c->latlong,
  139. "jbkod" => $c->Department->jnama,
  140. "akta" => $c->DeedLaw->nama,
  141. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  142. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  143. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  144. "amount_payment" => $c->amount_payment,
  145. "receipt" => $c->receipt,
  146. "dikeluarkan" => $c->dikeluarkan,
  147. "status" => $c->status,
  148. "updated_at" => $c->updated_at->toDateTimeString(),
  149. "created_at" => $c->created_at->toDateTimeString(),
  150. ));
  151. }else if($c->jenis == 'Pelbagai_PA'){
  152. array_push($data,array(
  153. "_id" => $c->_id,
  154. "jenis" => $c->jenis,
  155. "kpd"=> $c->kpd,
  156. "nama"=> $c->nama,
  157. "identity" => $c->identity,
  158. "nama_syarikat" => $c->nama_syarikat,
  159. "no_daftar_syarikat" => strtoupper($c->no_daftar_syarikat),
  160. "alamat" => $c->alamat,
  161. "no_plate" => strtoupper($c->no_plate),
  162. "no_cukai_jalan" => $c->no_cukai_jalan,
  163. "latlong" => $c->latlong,
  164. "jbkod" => $c->Department->jnama,
  165. "akta" => $c->DeedLaw->nama,
  166. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  167. "bil_haiwan" => $c->bil_haiwan,
  168. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  169. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  170. "amount_payment" => $c->amount_payment,
  171. "receipt" => $c->receipt,
  172. "dikeluarkan" => $c->dikeluarkan,
  173. "status" => $c->status,
  174. "updated_at" => $c->updated_at->toDateTimeString(),
  175. "created_at" => $c->created_at->toDateTimeString(),
  176. ));
  177. }else if($c->jenis == 'Parkir'){
  178. array_push($data,array(
  179. "_id" => $c->_id,
  180. "nama" => $c->nama,
  181. "identity" => $c->identity,
  182. "jenis" => $c->jenis,
  183. "kpd"=> $c->kpd,
  184. "no_plate" => strtoupper($c->no_plate),
  185. "no_cukai_jalan" => $c->no_cukai_jalan,
  186. "jenis_kenderaan" => $c->jenis_kenderaan,
  187. "model_kenderaan" => $c->model_kenderaan,
  188. "warna_kenderaan" => $c->warna_kenderaan,
  189. "nama_taman" => $c->nama_taman,
  190. "nama_jalan" => $c->nama_jalan,
  191. "no_parking" => $c->no_parking,
  192. "latlong" => $c->latlong,
  193. "jbkod" => $c->Department->jnama,
  194. "akta" => $c->DeedLaw->nama,
  195. "seksyen_kesalahan" => "[".$c->Faulty->sketr."] ".$c->Faulty->nama,
  196. "jumlah_asal_kompaun" => $c->jumlah_asal_kompaun,
  197. "jumlah_kemaskini_kompaun" => $c->jumlah_kemaskini_kompaun,
  198. "amount_payment" => $c->amount_payment,
  199. "receipt" => $c->receipt,
  200. "dikeluarkan" => $c->dikeluarkan,
  201. "status" => $c->status,
  202. "updated_at" => $c->updated_at->toDateTimeString(),
  203. "created_at" => $c->created_at->toDateTimeString(),
  204. ));
  205. }
  206. }
  207. return $this->sendResponse($data, 'Result Found');
  208. }else {
  209. return $this->sendResponse('', 'No Result');
  210. }
  211. }else{
  212. return $this->sendError('Search field is compulsory!', '');
  213. }
  214. }else{
  215. return $this->sendError('Invalid Api Key', '');
  216. }
  217. }else{
  218. return $this->sendError('Invalid Api Key', '');
  219. }
  220. }
  221. /**
  222. * Create update compound controller.
  223. *
  224. * @return json
  225. */
  226. public function updatePaymentIntegrasi(Request $request){
  227. $api_integrasi = ApiIntegration::where('key', $request->key)->first();
  228. if(!empty($api_integrasi)){
  229. if($api_integrasi->status == 'active'){
  230. $compound = Compound::with('ConfidentialFile')->where('kpd', $request->kp)->first();
  231. if(!empty($compound)){
  232. if($compound->status != 'Berbayar'){
  233. $compound->status = 'Berbayar';
  234. $compound->receipt = $request->receipt;
  235. $compound->amount_payment = $request->amount;
  236. $compound->save();
  237. $now = Carbon::now();
  238. $gDate = $now->format('F Y');
  239. $historyData = [
  240. 'tarikh_kumpulan' => $gDate,
  241. ];
  242. $subHistory = [
  243. 'no_siri' => $compound->ConfidentialFile->no_siri,
  244. 'tajuk' => "Pembayaran kompaun ".$request->orderid." telah dibuat secara 'online'",
  245. 'huraian' => "Pembayaran kompaun ".$request->orderid." telah dijelaskan pada hari ini.",
  246. ];
  247. $groupByDate = History::where('tarikh_kumpulan', $gDate)->first();
  248. if(!empty($groupByDate)){
  249. $groupByDate->subhistory()->create($subHistory);
  250. $compound->ConfidentialFile->history()->attach($groupByDate);
  251. }else{
  252. $history = History::create($historyData);
  253. $history->subhistory()->create($subHistory);
  254. $compound->ConfidentialFile->history()->attach($history);
  255. }
  256. $kpd = Compound::where('kpd', $request->kp)->first();
  257. $department = Department::where('_id',$kpd->jbkod)->first();
  258. $faulty = Faulty::where('_id',$kpd->seksyen_kesalahan)->first();
  259. $akta = DeedLaw::where('_id',$faulty->deed_law_id)->first();
  260. $data = [
  261. "_id" => $kpd->_id,
  262. "kpd"=> $kpd->kpd,
  263. "nama"=> $kpd->nama,
  264. "identity" => $kpd->identity,
  265. "nama_syarikat" => $kpd->nama_syarikat,
  266. "no_daftar_syarikat" => $kpd->no_daftar_syarikat,
  267. "alamat" => $kpd->alamat,
  268. "no_plate" => $kpd->no_plate,
  269. "latlong" => $kpd->latlong,
  270. "jbkod" => $department->jnama,
  271. "akta" => "[".$akta->akkod."] ".$akta->nama,
  272. "seksyen_kesalahan" => "[".$faulty->sketr."] ".$faulty->nama,
  273. "jumlah_asal_kompaun" => $kpd->jumlah_asal_kompaun,
  274. "jumlah_kemaskini_kompaun" => $kpd->jumlah_kemaskini_kompaun,
  275. "amount_payment" => $kpd->amount_payment,
  276. "receipt" => $kpd->receipt,
  277. "dikeluarkan" => $kpd->dikeluarkan,
  278. "status" => $kpd->status,
  279. "updated_at" => $kpd->updated_at->toDateTimeString(),
  280. "created_at" => $kpd->created_at->toDateTimeString(),
  281. ];
  282. return $this->sendResponse($data, 'Successfully update compound status');
  283. }else{
  284. return $this->sendResponse('', 'This compound already been paid');
  285. }
  286. }else{
  287. return $this->sendError('Record compound not found!', '');
  288. }
  289. }else{
  290. return $this->sendError('Invalid Api Key', '');
  291. }
  292. }else{
  293. return $this->sendError('Invalid Api Key', '');
  294. }
  295. }
  296. public function compoundToEPBT()
  297. {
  298. $compound = Compound::with('Department','DeedLaw','Faulty','StaffDetail')->where('jenis', 'Pelbagai_JPB')->get();
  299. dd($compound);
  300. if(!empty($compound))
  301. {
  302. $data = [];
  303. foreach ($compound as $key => $c)
  304. {
  305. if($c->jenis == 'Pelbagai_KT')
  306. {
  307. $data = [
  308. 'no_kom' => $c->kpd,
  309. 'jenis' => $c->jenis,
  310. 'nama' => $c->nama,
  311. 'no_ic' => $c->identity,
  312. 'no_tel' => $c->no_telefon,
  313. 'nama_syarikat' => $c->nama_syarikat,
  314. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  315. 'no_akaun_lesen' => $c->no_akaun_lesen,
  316. 'alamat' => $c->alamat,
  317. 'jabatan' => $c->Department->jnama,
  318. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  319. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  320. 'catatan' => $c->catatan,
  321. 'latlong' => $c->latlong,
  322. 'status' =>$c->status,
  323. 'amaun_bayar' => $c->amount_payment,
  324. 'receipt' => $c->receipt,
  325. ];
  326. }
  327. if($c->jenis == 'Pelbagai_JPB')
  328. {
  329. $data = [
  330. 'no_kom' => $c->kpd,
  331. 'jenis' => $c->jenis,
  332. 'nama' => $c->nama,
  333. 'no_ic' => $c->identity,
  334. 'no_tel' => $c->no_telefon,
  335. 'nama_syarikat' => $c->nama_syarikat,
  336. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  337. 'no_akaun_lesen' => $c->no_akaun_lesen,
  338. 'alamat' => $c->alamat,
  339. 'jabatan' => $c->Department->jnama,
  340. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  341. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  342. 'catatan' => $c->catatan,
  343. 'latlong' => $c->latlong,
  344. 'status' =>$c->status,
  345. 'amaun_bayar' => $c->amount_payment,
  346. 'receipt' => $c->receipt,
  347. ];
  348. }
  349. if($c->jenis == 'Pelbagai_PA')
  350. {
  351. $data = [
  352. 'no_kom' => $c->kpd,
  353. 'jenis' => $c->jenis,
  354. 'nama' => $c->nama,
  355. 'no_ic' => $c->identity,
  356. 'no_tel' => $c->no_telefon,
  357. 'nama_syarikat' => $c->nama_syarikat,
  358. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  359. 'no_akaun_lesen' => $c->no_akaun_lesen,
  360. 'alamat' => $c->alamat,
  361. 'jabatan' => $c->Department->jnama,
  362. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  363. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  364. 'bil_haiwan' => $c->bil_haiwan,
  365. 'catatan' => $c->catatan,
  366. 'latlong' => $c->latlong,
  367. 'status' =>$c->status,
  368. 'amaun_bayar' => $c->amount_payment,
  369. 'receipt' => $c->receipt,
  370. ];
  371. }
  372. if($c->jenis == 'Pelbagai_LESEN')
  373. {
  374. $data = [
  375. 'no_kom' => $c->kpd,
  376. 'jenis' => $c->jenis,
  377. 'nama' => $c->nama,
  378. 'no_ic' => $c->identity,
  379. 'no_tel' => $c->no_telefon,
  380. 'nama_syarikat' => $c->nama_syarikat,
  381. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  382. 'no_akaun_lesen' => $c->no_akaun_lesen,
  383. 'alamat' => $c->alamat,
  384. 'jabatan' => $c->Department->jnama,
  385. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  386. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  387. 'catatan' => $c->catatan,
  388. 'latlong' => $c->latlong,
  389. 'status' =>$c->status,
  390. 'amaun_bayar' => $c->amount_payment,
  391. 'receipt' => $c->receipt,
  392. ];
  393. }
  394. if($c->jenis == 'Parkir')
  395. {
  396. $data = [
  397. 'no_kom' => $c->kpd,
  398. 'jenis' => $c->jenis,
  399. 'nama' => $c->nama,
  400. 'no_ic' => $c->identity,
  401. 'no_tel' => $c->no_telefon,
  402. 'nama_syarikat' => $c->nama_syarikat,
  403. 'no_daftar_syarikat' => $c->no_daftar_syarikat,
  404. 'no_akaun_lesen' => $c->no_akaun_lesen,
  405. 'alamat' => $c->alamat,
  406. 'jabatan' => $c->Department->jnama,
  407. 'seksyen' => '['.$c->DeedLaw->akkod.'] ' . $c->DeedLaw->nama,
  408. 'kesalahan'=> '['.$c->Faulty->sketr.'] ' . $c->Faulty->nama,
  409. 'catatan' => $c->catatan,
  410. 'latlong' => $c->latlong,
  411. 'status' =>$c->status,
  412. 'amaun_bayar' => $c->amount_payment,
  413. 'receipt' => $c->receipt,
  414. ];
  415. }
  416. }
  417. return $this->sendResponse($data, 'Successfully update compound status');
  418. }
  419. }
  420. }